From 55f99edea6810742e9b31bd8e104c6b96696aa99 Mon Sep 17 00:00:00 2001 From: Thomas Kim Date: Sat, 12 Dec 2015 17:58:02 -0500 Subject: [PATCH] locksmith.c: Added better cos swapping support clients/square_evictions.c: Added support for locksmith histogram rdtscp.h: Added fast log2 for square_evictions locksmith histogram array index calculation prep_system.c: git operations will no longer open less --- clients/square_evictions.c | 14 ++++++++++++++ locksmith.c | 35 +++++++++++++++++++++++------------ prep_system.c | 2 +- rdtscp.h | 8 ++++++++ 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/clients/square_evictions.c b/clients/square_evictions.c index c3c956a..15fb603 100644 --- a/clients/square_evictions.c +++ b/clients/square_evictions.c @@ -18,6 +18,11 @@ #define DEFAULT_PERCENT_CONTRACTED 80 #define DEFAULT_PERCENT_EXPANDED 220 +#define MAX_MEMREF_CYCLES_POW 17 +#define LOWER(x) (1 << x) +#define UPPER(x) (1 << (x+1)) +uint64_t histogram[MAX_MEMREF_CYCLES_POW] = {0}; + #define PERF_LOG_FILE_HEADER_LINE "realtime,cputime,instructions,bandwidth\n" static const struct perf_event_attr PERF_LOG_COUNTERS[] = { { @@ -203,6 +208,10 @@ static int square_evictions(int cache_line_size, int num_periods, int passes_per max_time = time; printf("Current max cycles for a memory access %lu\n", max_time); } + // Ignore the first 2 cycles due to memory fetch behavior + if(cycle < 2) { + ++histogram[logtwo(time)]; + } } } assert(!siz || seen_initial); @@ -429,5 +438,10 @@ int main(int argc, char *argv[]) { munmap(perfbuf, perfbuf->siz); if(perflog) fclose(perflog); + if(measure_all) { + for(int i = 0; i < MAX_MEMREF_CYCLES_POW; ++i) { + printf("Mem access cycles >= 2^%d: %lu\n", i, histogram[i]); + } + } return ret; } diff --git a/locksmith.c b/locksmith.c index fa7c73f..dca6e47 100644 --- a/locksmith.c +++ b/locksmith.c @@ -6,7 +6,9 @@ #include "bench_commands.h" #include "log.h" #include "prep_system.h" -#define LARGE_NUMBER "3" + +// Should be at least 2, on 1 it might measure memory fetches, 2+ will use definitely use cache +#define LARGE_NUMBER "2" #define COMMON_COS 1 #define OTHER_COS 2 @@ -14,7 +16,10 @@ #define READER_CORE 0 #define SWITCHER_CORE 1 -#define NUM_SWITCHES (1 << 25) +// 21 takes about 8 seconds +// 23 takes about 40 seconds +// 24 takes about 1 minute +#define NUM_SWITCHES (1 << 24) // TODO add flag to square_evictions for timing each memory access static test_prog_t progs[] = { @@ -42,8 +47,13 @@ static const struct pqos_l3ca COS_MASKS[] = { static const size_t NUM_COS_MASKS = sizeof COS_MASKS / sizeof *COS_MASKS; int main(int argc, char** argv) { - (void) argc; - (void) argv; + int swappy = 0; + /* lol */ + if(argc > 1) { + if(argv[1][0] == '-' && argv[1][1] == 's') + swappy = 1; + } + /* end lol */ if(prep_system(false, -1) < 0) { log_msg(LOG_FATAL, "Failed to complete initial setup\n"); return 1; @@ -65,16 +75,17 @@ int main(int argc, char** argv) { sleep(2); } run_benchmarks(progs, 1); - for(int i = 0; i < NUM_SWITCHES; ++i) { - if(pqos_l3ca_assoc_set(SWITCHER_CORE, OTHER_COS) != PQOS_RETVAL_OK) { - log_msg(LOG_FATAL, "Failed to switch Cos on switcher process\n"); + if(swappy) { + printf("Swapping CoSes\n"); + for(int i = 0; i < NUM_SWITCHES; ++i) { + if(pqos_l3ca_assoc_set(SWITCHER_CORE, OTHER_COS) != PQOS_RETVAL_OK) { + log_msg(LOG_FATAL, "Failed to switch Cos on switcher process\n"); + } } + /* Keep swapping COS of our other core */ + // TODO fix this + printf("Done swapping!\n"); } - /* Keep swapping COS of our other core */ - // TODO fix this - printf("Done swapping!\n"); - wait_benchmarks(); - run_benchmarks(progs, 1); wait_benchmarks(); cleanup_system(true); } diff --git a/prep_system.c b/prep_system.c index adf395c..f96f248 100644 --- a/prep_system.c +++ b/prep_system.c @@ -45,7 +45,7 @@ static bool rearrange_processes(bool multicore, int procs_go_where, #define GIT_LOG_CMD "git log --online -1" #define GIT_STATUS_CMD "git status -uno" -#define GIT_DIFF_CMD "git diff HEAD" +#define GIT_DIFF_CMD "git --no-pager diff HEAD" #define DELIM "===" // Purposely ignoring the usual style for pointers! // I don't know enough about PL to argue about it though! diff --git a/rdtscp.h b/rdtscp.h index 11e9f31..b709f08 100644 --- a/rdtscp.h +++ b/rdtscp.h @@ -16,4 +16,12 @@ static inline uint64_t rdtscp(void) { return ((uint64_t)cycles_high << 32 | cycles_low); } +static inline uint64_t logtwo(const uint64_t x) { + uint64_t y; + __asm volatile( "\tbsr %1, %0\n" + : "=r"(y) + : "r" (x) + ); + return y; +} #endif