Skip to content

Commit bca0807

Browse files
committed
runtime: track heap/handle table churn
1 parent f351689 commit bca0807

File tree

7 files changed

+60
-33
lines changed

7 files changed

+60
-33
lines changed

runtime/core/Localizer.cpp

+22-18
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,26 @@ namespace alaska {
5151
for (size_t i = 0; i < count; i++) {
5252
auto hid = handle_ids[i];
5353
if (hid == 0) continue;
54-
auto handle = reinterpret_cast<void *>((1LU << 63) | ((uint64_t)hid << ALASKA_SIZE_BITS));
55-
auto *m = alaska::Mapping::from_handle_safe(handle);
56-
bool moved = false;
57-
if (m == NULL or m->is_free() or m->is_pinned()) {
58-
moved = false;
59-
} else {
60-
void *ptr = m->get_pointer();
61-
auto *source_page = rt.heap.pt.get_unaligned(m->get_pointer());
62-
moved = tc.localize(*m, rt.localization_epoch);
63-
}
64-
auto size = tc.get_size(handle);
65-
bytes_reach += size;
66-
if (moved) {
67-
moved_objects++;
68-
bytes_in_dump += size;
69-
} else {
70-
unmoved_objects++;
71-
}
54+
this->seen_handles.add(hid);
55+
// printf("%3d: %x\n", i, hid);
56+
// auto handle = reinterpret_cast<void *>((1LU << 63) | ((uint64_t)hid << ALASKA_SIZE_BITS));
57+
// auto *m = alaska::Mapping::from_handle_safe(handle);
58+
// bool moved = false;
59+
// if (m == NULL or m->is_free() or m->is_pinned()) {
60+
// moved = false;
61+
// } else {
62+
// void *ptr = m->get_pointer();
63+
// auto *source_page = rt.heap.pt.get_unaligned(m->get_pointer());
64+
// moved = tc.localize(*m, rt.localization_epoch);
65+
// }
66+
// auto size = tc.get_size(handle);
67+
// bytes_reach += size;
68+
// if (moved) {
69+
// moved_objects++;
70+
// bytes_in_dump += size;
71+
// } else {
72+
// unmoved_objects++;
73+
// }
7274
}
7375
// rt.heap.compact_locality_pages();
7476
// rt.heap.compact_sizedpages();
@@ -77,6 +79,8 @@ namespace alaska {
7779
// printf("moved:%5lu unmoved:%5lu bytes:%12lu reach:%12lu\n", moved_objects, unmoved_objects,
7880
// bytes_in_dump, bytes_reach);
7981

82+
alaska::printf("seen handles: %zu\n", this->seen_handles.size());
83+
8084
// Push the buffer back to the queue of buffers
8185
struct buffer *buf = reinterpret_cast<struct buffer *>(handle_ids);
8286
buf->next = buffers;

runtime/core/Runtime.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ namespace alaska {
6666
#undef xstr
6767
#undef str
6868

69-
fprintf(stream, "barriers: %zu, rate:%.1f/s\n", stat_barriers.read(), stat_barriers.digest());
69+
fprintf(stream, "barriers: %zu (%.1f/s)\n", stat_barriers.read(), stat_barriers.digest());
7070

7171
for (auto *tc : this->tcs) {
72-
fprintf(stream, "tc%d allocations:%zu, rate:%.1f/s", tc->id, tc->allocation_rate.read(),
72+
fprintf(stream, "tc%d allocations:%zu (%.1f/s)", tc->id, tc->allocation_rate.read(),
7373
tc->allocation_rate.digest());
74-
fprintf(stream, " frees:%zu, rate:%.1f/s", tc->free_rate.read(), tc->free_rate.digest());
74+
fprintf(stream, " frees:%zu (%.1f/s)", tc->free_rate.read(), tc->free_rate.digest());
75+
fprintf(stream, " heap_churn:%zu (%.1f/s)", tc->heap_churn.read(), tc->heap_churn.digest());
76+
fprintf(stream, " ht_churn:%zu (%.1f/s)", tc->handle_table_churn.read(),
77+
tc->handle_table_churn.digest());
7578
fprintf(stream, "\n");
7679
}
7780
// handle_table.dump(stream);

runtime/core/ThreadCache.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ namespace alaska {
3333
: id(id)
3434
, runtime(rt)
3535
, localizer(rt.config, *this) {
36+
37+
handle_table_churn++;
3638
handle_slab = runtime.handle_table.new_slab(this);
3739
}
3840

@@ -45,7 +47,9 @@ namespace alaska {
4547
ptr = ::malloc(size);
4648
#else
4749
SizedPage *page = size_classes[cls];
48-
if (unlikely(page == nullptr)) page = new_sized_page(cls);
50+
if (unlikely(page == nullptr)) {
51+
page = new_sized_page(cls);
52+
}
4953
ptr = page->alloc(m, size);
5054
if (unlikely(ptr == nullptr)) {
5155
// OOM?
@@ -90,6 +94,7 @@ namespace alaska {
9094

9195

9296
SizedPage *ThreadCache::new_sized_page(int cls) {
97+
heap_churn++;
9398
// Get a new heap
9499
auto *heap = runtime.heap.get_sizedpage(alaska::class_to_size(cls), this);
95100

@@ -106,6 +111,7 @@ namespace alaska {
106111

107112

108113
LocalityPage *ThreadCache::new_locality_page(size_t required_size) {
114+
heap_churn++;
109115
// Get a new heap
110116
auto *lp = runtime.heap.get_localitypage(required_size, this);
111117

@@ -208,6 +214,7 @@ namespace alaska {
208214
auto m = handle_slab->alloc();
209215

210216
if (unlikely(m == NULL)) {
217+
handle_table_churn++; // record that we are looking for a new handle table slab.
211218
auto new_handle_slab = runtime.handle_table.new_slab(this);
212219
this->handle_slab->set_owner(NULL);
213220
this->handle_slab = new_handle_slab;

runtime/include/alaska/Localizer.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <alaska/alaska.hpp>
1515
#include <alaska/Configuration.hpp>
16+
#include <ck/set.h>
1617

1718
namespace alaska {
1819

@@ -32,6 +33,8 @@ namespace alaska {
3233

3334
struct buffer *buffers = nullptr;
3435

36+
ck::set<handle_id_t> seen_handles;
37+
3538
public:
3639
Localizer(alaska::Configuration &config, alaska::ThreadCache &tc);
3740

runtime/include/alaska/ThreadCache.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ namespace alaska {
9999
alaska::RateCounter allocation_rate;
100100
alaska::RateCounter free_rate;
101101

102+
103+
// How often are we getting a new heap or handle table?
104+
alaska::RateCounter heap_churn;
105+
alaska::RateCounter handle_table_churn;
106+
102107
// Each thread cache has a localizer, which can be fed with
103108
// "localization data" to improve object locality
104109
alaska::Localizer localizer;

runtime/rt/sim.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#include <semaphore.h>
1515

1616

17-
#define L1_ENTS 96
18-
#define L1_SETS 24
17+
#define L1_ENTS 16
18+
#define L1_SETS 4
1919
#define L1_WAYS (L1_ENTS / L1_SETS)
2020

2121
#define L2_WAYS 16

runtime/yukon/yukon.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ static void setup_signal_handlers(void) {
108108
assert(sigaction(SIGUSR2, &sa, NULL) == 0);
109109

110110

111-
if (getenv("YUKON_DUMP") == NULL) {
112-
int dump_interval_ms = 10;
111+
if (getenv("YUKON_DUMP") != NULL) {
112+
int dump_interval_ms = atoi(getenv("YUKON_DUMP"));
113+
113114
useconds_t dump_interval = dump_interval_ms * 1000;
114115
signal(SIGALRM, alarm_handler);
115116
// now that we have sigalarm configured, setup a ualarm for
@@ -159,16 +160,22 @@ namespace yukon {
159160
void dump_htlb(alaska::ThreadCache *tc) {
160161
auto size = 576;
161162
auto *space = tc->localizer.get_hotness_buffer(size);
162-
memset(space, 0, size * sizeof(alaska::handle_id_t));
163-
163+
// memset(space, 0, size * sizeof(alaska::handle_id_t));
164+
// Fence after we have a valid space for the dump
164165
asm volatile("fence" ::: "memory");
165166

166167
auto start = read_cycle_counter();
168+
169+
// Fire off the dump..
167170
write_csr(CSR_HTDUMP, (uint64_t)space);
171+
// ..and wait for it to finish
168172
wait_for_csr_zero(CSR_HTDUMP);
169173
auto end = read_cycle_counter();
174+
// fence so we have ordering
170175
asm volatile("fence" ::: "memory");
176+
// Feed the buffer to the localizer to do it's work
171177
tc->localizer.feed_hotness_buffer(size, space);
178+
// Fence again... for some reason
172179
asm volatile("fence" ::: "memory");
173180
// printf("Dumping htlb took %lu cycles\n", end - start);
174181
}
@@ -235,11 +242,9 @@ void __attribute__((constructor(102))) alaska_init(void) {
235242
unsetenv("LD_PRELOAD"); // make it so we don't run alaska in subprocesses!
236243
yukon::get_tc();
237244

238-
atexit([]() {
239-
printf("Setting ht addr to zero!\n");
240-
yukon::set_handle_table_base(NULL);
241-
printf("set!\n");
242-
});
245+
// atexit([]() {
246+
// yukon::set_handle_table_base(NULL);
247+
// });
243248
}
244249

245250
void __attribute__((destructor)) alaska_deinit(void) {}

0 commit comments

Comments
 (0)