8
8
#include < alaska/Runtime.hpp>
9
9
#include < alaska/sim/HTLB.hpp>
10
10
#include " alaska/config.h"
11
+ #include " alaska/sim/StatisticsManager.hpp"
12
+ #include < sys/time.h>
11
13
#include < semaphore.h>
12
14
13
15
19
21
#define L2_SETS 32
20
22
#define TOTAL_ENTRIES (L1_WAYS * L1_SETS + L2_WAYS * L2_SETS)
21
23
22
- #define RATE 1 '000'000
24
+ #define RATE 10 '000'000UL
23
25
24
26
static long access_count = 0 ;
25
27
static alaska::sim::HTLB *g_htlb = NULL ;
@@ -41,43 +43,76 @@ static alaska::sim::HTLB &get_htlb(void) {
41
43
return *g_htlb;
42
44
}
43
45
46
+
47
+ static uint64_t time_ms (void ) {
48
+ struct timeval tp;
49
+ gettimeofday (&tp, NULL );
50
+ uint64_t ms = tp.tv_sec * 1000 + tp.tv_usec / 1000 ;
51
+ return ms;
52
+ }
44
53
static pthread_t sim_background_thread;
45
54
static void *sim_background_thread_func (void *) {
46
55
track_on_this_thread = false ;
47
56
48
57
alaska::wait_for_initialization ();
58
+ auto &rt = alaska::Runtime::get ();
59
+ auto *tc = rt.new_threadcache ();
60
+
61
+ FILE *log = fopen (" out.csv" , " w" );
62
+ fprintf (log , " trial,hitrate_baseline\n " );
63
+
49
64
50
- while (true ) {
65
+
66
+ for (long trial = 0 ; true ; trial++) {
51
67
pthread_mutex_lock (&dump_mutex);
52
68
pthread_cond_wait (&dump_cond, &dump_mutex);
53
69
70
+ unsigned long moved_objects = 0 ;
71
+ unsigned long unmoved_objects = 0 ;
72
+ unsigned long bytes_in_dump = 0 ;
73
+ // ck::set<uint64_t> pages;
74
+
75
+ // rt.with_barrier([&]() {
76
+ // rt.heap.compact_locality_pages();
77
+ // // unsigned long c = rt.heap.compact_sizedpages();
78
+ // // printf("compacted %lu\n", c);
79
+
80
+
81
+ // for (int i = 0; i < TOTAL_ENTRIES; i++) {
82
+ // if (dump_buf[i] == 0) continue;
83
+ // auto handle = (void *)(dump_buf[i] << ALASKA_SIZE_BITS);
84
+ // auto *m = alaska::Mapping::from_handle_safe(handle);
54
85
55
- // // Got a dump!
56
- auto &rt = alaska::Runtime::get ();
57
-
58
- rt.with_barrier ([&]() {
59
- // unsigned long c = rt.heap.jumble();
60
- // printf("jumbled %lu objects\n", c);
61
- unsigned long c = rt.heap .compact_sizedpages ();
62
- printf (" compacted %lu\n " , c);
63
- return ;
64
-
65
-
66
- unsigned long moved_objects = 0 ;
67
- for (int i = 0 ; i < TOTAL_ENTRIES; i++) {
68
- if (dump_buf[i] == 0 ) continue ;
69
- uint64_t val = dump_buf[i] << ALASKA_SIZE_BITS;
70
- if (get_tc ()->localize ((void *)val, rt.localization_epoch )) {
71
- moved_objects++;
72
- }
73
- }
74
- auto sm = get_htlb ().get_stats ();
75
- sm.compute ();
76
- // sm.dump();
77
- rt.localization_epoch ++;
78
- printf (" Objects moved: %lu\n " , moved_objects);
79
- printf (" TLB Hitrates: %f%% %f%%\n " , sm.l1_tlb_hr , sm.l2_tlb_hr );
80
- });
86
+
87
+ // bool moved = false;
88
+ // if (m == NULL or m->is_free() or m->is_pinned()) {
89
+ // moved = false;
90
+ // } else {
91
+ // void *ptr = m->get_pointer();
92
+ // // pages.add((uint64_t)ptr >> 12);
93
+ // auto *source_page = rt.heap.pt.get_unaligned(m->get_pointer());
94
+ // moved = tc->localize(*m, rt.localization_epoch);
95
+ // }
96
+
97
+ // if (moved) {
98
+ // moved_objects++;
99
+ // bytes_in_dump += tc->get_size(handle);
100
+ // } else {
101
+ // unmoved_objects++;
102
+ // }
103
+ // }
104
+ // });
105
+
106
+ rt.localization_epoch ++;
107
+
108
+ auto &sm = get_htlb ().get_stats ();
109
+ sm.compute ();
110
+ auto hr = sm.l1_tlb_hr ;
111
+ sm.reset ();
112
+
113
+ fprintf (log , " %lu,%f\n " , trial, hr);
114
+
115
+ fflush (log );
81
116
pthread_mutex_unlock (&dump_mutex);
82
117
}
83
118
@@ -90,29 +125,39 @@ static void __attribute__((constructor)) sim_init(void) {
90
125
}
91
126
92
127
128
+ void alaska_htlb_sim_invalidate (uintptr_t maybe_handle) {
129
+ if (not alaska::is_initialized ()) return ;
130
+ ck::scoped_lock l (htlb_lock);
131
+ auto m = alaska::Mapping::from_handle_safe ((void *)maybe_handle);
132
+ auto &htlb = get_htlb ();
133
+ if (m) {
134
+ htlb.invalidate_htlb (*m);
135
+ }
136
+ }
137
+
93
138
94
139
void alaska_htlb_sim_track (uintptr_t maybe_handle) {
95
140
if (not alaska::is_initialized ()) return ;
96
141
ck::scoped_lock l (htlb_lock);
97
142
auto m = alaska::Mapping::from_handle_safe ((void *)maybe_handle);
98
143
auto &htlb = get_htlb ();
144
+ access_count++;
99
145
if (m) {
100
146
htlb.access (*m);
101
- access_count++;
147
+ } else {
148
+ htlb.access_non_handle ((void *)maybe_handle);
149
+ }
102
150
103
- if (access_count > RATE) {
104
- access_count = 0 ;
151
+ if (access_count > RATE) {
152
+ access_count = 0 ;
105
153
106
- // dump, and notify the movement thread!
107
- pthread_mutex_lock (&dump_mutex);
154
+ // dump, and notify the movement thread!
155
+ pthread_mutex_lock (&dump_mutex);
108
156
109
- htlb.dump_entries (dump_buf);
110
- // htlb.reset();
157
+ htlb.dump_entries (dump_buf);
158
+ // htlb.reset();
111
159
112
- pthread_cond_signal (&dump_cond);
113
- pthread_mutex_unlock (&dump_mutex);
114
- }
115
- } else {
116
- htlb.access_non_handle ((void *)maybe_handle);
160
+ pthread_cond_signal (&dump_cond);
161
+ pthread_mutex_unlock (&dump_mutex);
117
162
}
118
163
}
0 commit comments