This commit is contained in:
Gregory Burd 2024-04-10 23:23:02 -04:00
parent 5460ef87b7
commit 5d5c7f1584
2 changed files with 22 additions and 19 deletions

View file

@ -27,21 +27,23 @@ tsc(void)
return ((uint64_t)high << 32) | low; return ((uint64_t)high << 32) | low;
} }
static static uint64_t
uint64_t get_tsc_frequency() { get_tsc_frequency()
uint32_t high, low; {
__asm__ volatile("rdtsc" : "=a" (low), "=d" (high)); uint32_t high, low;
__asm__ volatile("rdtsc"); __asm__ volatile("rdtsc" : "=a"(low), "=d"(high));
return ((uint64_t)high << 32) | low; __asm__ volatile("rdtsc");
return ((uint64_t)high << 32) | low;
} }
double double
tsc_ticks_to_ns(uint64_t tsc_ticks) { tsc_ticks_to_ns(uint64_t tsc_ticks)
static uint64_t tsc_freq = 0; {
if (tsc_freq == 0) { static uint64_t tsc_freq = 0;
tsc_freq = get_tsc_frequency(); if (tsc_freq == 0) {
} tsc_freq = get_tsc_frequency();
return (double)tsc_ticks / (double)tsc_freq * 1e9; }
return (double)tsc_ticks / (double)tsc_freq * 1e9;
} }
void void

View file

@ -696,8 +696,8 @@ test_perf_span_solo(const MunitParameter params[], void *data)
} }
} }
uint64_t est = EST_MEDIAN_GET(solo); uint64_t est = EST_MEDIAN_GET(solo);
fprintf(stdout, "median time %zu or %f ns\n", est, tsc_ticks_to_ns(est)); // measured 228 // fprintf(stdout, "median time %zu or %f ns\n", est, tsc_ticks_to_ns(est)); // measured 228
assert_true(EST_MEDIAN_GET(solo) < 500); assert_true(est < 500);
fflush(stdout); fflush(stdout);
return MUNIT_OK; return MUNIT_OK;
@ -743,15 +743,16 @@ test_perf_span_tainted(const MunitParameter params[], void *data)
if (located_at >= placed_at) if (located_at >= placed_at)
logf("b: i = %d, j = %d\tplaced_at %d located_at %d\n", i, j, placed_at, located_at); logf("b: i = %d, j = %d\tplaced_at %d located_at %d\n", i, j, placed_at, located_at);
// assert_true(located_at >= placed_at); // assert_true(located_at >= placed_at);
//start = tsc(); // start = tsc();
//located_at = sparsemap_span(map, (placed_at < j ? 0 : placed_at / 2), i); // located_at = sparsemap_span(map, (placed_at < j ? 0 : placed_at / 2), i);
//stop = tsc(); // stop = tsc();
//EST_MEDIAN_ADD(solo, stop - start); // EST_MEDIAN_ADD(solo, stop - start);
// assert_true(placed_at == located_at); // assert_true(placed_at == located_at);
} }
} }
uint64_t est = EST_MEDIAN_GET(tainted); uint64_t est = EST_MEDIAN_GET(tainted);
fprintf(stdout, "median time %zu or %f ns\n", est, tsc_ticks_to_ns(est)); // measured 228 // fprintf(stdout, "median time %zu or %f ns\n", est, tsc_ticks_to_ns(est)); // measured 228
assert_true(est < 500);
return MUNIT_OK; return MUNIT_OK;
} }