diff options
| author | Joshua Bakita <jbakita@cs.unc.edu> | 2021-03-08 21:49:53 -0500 |
|---|---|---|
| committer | Joshua Bakita <jbakita@cs.unc.edu> | 2021-03-08 21:49:53 -0500 |
| commit | 103b615bbee63502d8a6a3acb408ea1e1cf0bc20 (patch) | |
| tree | 33b88c730a9d5dc8966088f467d6b9c474201e84 | |
| parent | 99eccfd1169d35fc3a2fda5b58a6f7fe3da71aa4 (diff) | |
Fix the random_walk benchmark so that it builds when LITMUS is enabledrtas20-wip
| -rw-r--r-- | dis/random_walk.c | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/dis/random_walk.c b/dis/random_walk.c index 9f907bb..6282487 100644 --- a/dis/random_walk.c +++ b/dis/random_walk.c | |||
| @@ -16,7 +16,7 @@ | |||
| 16 | #include "common.h" | 16 | #include "common.h" |
| 17 | */ | 17 | */ |
| 18 | /* CPU time consumed so far in seconds */ | 18 | /* CPU time consumed so far in seconds */ |
| 19 | double cputime(void) | 19 | double rw_cputime(void) |
| 20 | { | 20 | { |
| 21 | struct timespec ts; | 21 | struct timespec ts; |
| 22 | int err; | 22 | int err; |
| @@ -27,7 +27,7 @@ double cputime(void) | |||
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | /* wall-clock time in seconds */ | 29 | /* wall-clock time in seconds */ |
| 30 | double wctime(void) | 30 | double rw_wctime(void) |
| 31 | { | 31 | { |
| 32 | struct timeval tv; | 32 | struct timeval tv; |
| 33 | gettimeofday(&tv, NULL); | 33 | gettimeofday(&tv, NULL); |
| @@ -43,25 +43,25 @@ void bail_out(const char* msg) | |||
| 43 | #include "extra.h" | 43 | #include "extra.h" |
| 44 | 44 | ||
| 45 | #define PAGE_SIZE (4096) | 45 | #define PAGE_SIZE (4096) |
| 46 | #define CACHELINE_SIZE 64 | 46 | #define RW_CACHELINE_SIZE 64 |
| 47 | #define INTS_IN_CACHELINE (CACHELINE_SIZE/sizeof(int)) | 47 | #define INTS_IN_RW_CACHELINE (RW_CACHELINE_SIZE/sizeof(int)) |
| 48 | #define CACHELINES_IN_1KB (1024 / sizeof(cacheline_t)) | 48 | #define RW_CACHELINES_IN_1KB (1024 / sizeof(rw_cacheline_t)) |
| 49 | #define INTS_IN_1KB (1024 / sizeof(int)) | 49 | #define INTS_IN_1KB (1024 / sizeof(int)) |
| 50 | 50 | ||
| 51 | typedef struct cacheline | 51 | typedef struct rw_cacheline |
| 52 | { | 52 | { |
| 53 | int line[INTS_IN_CACHELINE]; | 53 | int line[INTS_IN_RW_CACHELINE]; |
| 54 | } __attribute__((aligned(CACHELINE_SIZE))) cacheline_t; | 54 | } __attribute__((aligned(RW_CACHELINE_SIZE))) rw_cacheline_t; |
| 55 | 55 | ||
| 56 | static volatile cacheline_t* arena = NULL; | 56 | static volatile rw_cacheline_t* arena = NULL; |
| 57 | 57 | ||
| 58 | #define UNCACHE_DEV "/dev/litmus/uncache" | 58 | #define UNCACHE_DEV "/dev/litmus/uncache" |
| 59 | #define FAKE_DEV "/dev/litmus/fakedev0" | 59 | #define FAKE_DEV "/dev/litmus/fakedev0" |
| 60 | 60 | ||
| 61 | static cacheline_t* alloc_arena(size_t size, int use_huge_pages, int use_uncache_pages) | 61 | static rw_cacheline_t* alloc_arena(size_t size, int use_huge_pages, int use_uncache_pages) |
| 62 | { | 62 | { |
| 63 | int flags = MAP_PRIVATE | MAP_POPULATE; | 63 | int flags = MAP_PRIVATE | MAP_POPULATE; |
| 64 | cacheline_t* arena = NULL; | 64 | rw_cacheline_t* arena = NULL; |
| 65 | int fd; | 65 | int fd; |
| 66 | 66 | ||
| 67 | if(use_huge_pages) | 67 | if(use_huge_pages) |
| @@ -80,7 +80,7 @@ static cacheline_t* alloc_arena(size_t size, int use_huge_pages, int use_uncache | |||
| 80 | flags |= MAP_ANONYMOUS; | 80 | flags |= MAP_ANONYMOUS; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | arena = (cacheline_t*)mmap(0, size, PROT_READ | PROT_WRITE, flags, fd, 0); | 83 | arena = (rw_cacheline_t*)mmap(0, size, PROT_READ | PROT_WRITE, flags, fd, 0); |
| 84 | 84 | ||
| 85 | if(use_uncache_pages) | 85 | if(use_uncache_pages) |
| 86 | close(fd); | 86 | close(fd); |
| @@ -90,7 +90,7 @@ static cacheline_t* alloc_arena(size_t size, int use_huge_pages, int use_uncache | |||
| 90 | return arena; | 90 | return arena; |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | static void dealloc_arena(cacheline_t* arena, size_t size) | 93 | static void dealloc_arena(rw_cacheline_t* arena, size_t size) |
| 94 | { | 94 | { |
| 95 | int ret = munmap((void*)arena, size); | 95 | int ret = munmap((void*)arena, size); |
| 96 | if(ret != 0) | 96 | if(ret != 0) |
| @@ -116,17 +116,17 @@ static int randrange(int min, int max) | |||
| 116 | return retval;*/ | 116 | return retval;*/ |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | static void init_arena(volatile cacheline_t* arena, size_t size) | 119 | static void init_arena(volatile rw_cacheline_t* arena, size_t size) |
| 120 | { | 120 | { |
| 121 | int i; | 121 | int i; |
| 122 | size_t num_arena_elem = size / sizeof(cacheline_t); | 122 | size_t num_arena_elem = size / sizeof(rw_cacheline_t); |
| 123 | 123 | ||
| 124 | /* Generate a cycle among the cache lines using Sattolo's algorithm. | 124 | /* Generate a cycle among the cache lines using Sattolo's algorithm. |
| 125 | Every int in the cache line points to the same cache line. | 125 | Every int in the cache line points to the same cache line. |
| 126 | Note: Sequential walk doesn't care about these values. */ | 126 | Note: Sequential walk doesn't care about these values. */ |
| 127 | for (i = 0; i < num_arena_elem; i++) { | 127 | for (i = 0; i < num_arena_elem; i++) { |
| 128 | int j; | 128 | int j; |
| 129 | for(j = 0; j < INTS_IN_CACHELINE; j++) | 129 | for(j = 0; j < INTS_IN_RW_CACHELINE; j++) |
| 130 | arena[i].line[j] = i; | 130 | arena[i].line[j] = i; |
| 131 | arena[i].line[1] = 0; | 131 | arena[i].line[1] = 0; |
| 132 | } | 132 | } |
| @@ -138,7 +138,7 @@ static void init_arena(volatile cacheline_t* arena, size_t size) | |||
| 138 | }*/ | 138 | }*/ |
| 139 | for (int j = 0; j < num_arena_elem-1; j++) { | 139 | for (int j = 0; j < num_arena_elem-1; j++) { |
| 140 | int k = randrange(j+1, num_arena_elem); | 140 | int k = randrange(j+1, num_arena_elem); |
| 141 | cacheline_t temp = arena[j]; | 141 | rw_cacheline_t temp = arena[j]; |
| 142 | arena[j] = arena[k]; | 142 | arena[j] = arena[k]; |
| 143 | arena[k] = temp; | 143 | arena[k] = temp; |
| 144 | } | 144 | } |
| @@ -147,14 +147,14 @@ static void init_arena(volatile cacheline_t* arena, size_t size) | |||
| 147 | /* Random walk around the arena in cacheline-sized chunks. | 147 | /* Random walk around the arena in cacheline-sized chunks. |
| 148 | Cacheline-sized chucks ensures the same utilization of each | 148 | Cacheline-sized chucks ensures the same utilization of each |
| 149 | hit line as sequential read. (Otherwise, our utilization | 149 | hit line as sequential read. (Otherwise, our utilization |
| 150 | would only be 1/INTS_IN_CACHELINE.) */ | 150 | would only be 1/INTS_IN_RW_CACHELINE.) */ |
| 151 | static int random_walk(volatile cacheline_t *mem, int wss, int write_cycle) | 151 | static int random_walk(volatile rw_cacheline_t *mem, int wss, int write_cycle) |
| 152 | { | 152 | { |
| 153 | /* a random cycle among the cache lines was set up by init_arena(). */ | 153 | /* a random cycle among the cache lines was set up by init_arena(). */ |
| 154 | int sum, i, next; | 154 | int sum, i, next; |
| 155 | 155 | ||
| 156 | // Always do the same number of hops | 156 | // Always do the same number of hops |
| 157 | int numlines = 33554432 / CACHELINE_SIZE;//wss * CACHELINES_IN_1KB; | 157 | int numlines = 33554432 / RW_CACHELINE_SIZE;//wss * RW_CACHELINES_IN_1KB; |
| 158 | 158 | ||
| 159 | sum = 0; | 159 | sum = 0; |
| 160 | 160 | ||
| @@ -167,7 +167,7 @@ static int random_walk(volatile cacheline_t *mem, int wss, int write_cycle) | |||
| 167 | next = arena[next].line[0]; | 167 | next = arena[next].line[0]; |
| 168 | arena[next].line[1] = 1; // Record that we touched this line | 168 | arena[next].line[1] = 1; // Record that we touched this line |
| 169 | sum += next; | 169 | sum += next; |
| 170 | for (int j = 2; j < INTS_IN_CACHELINE; j++) | 170 | for (int j = 2; j < INTS_IN_RW_CACHELINE; j++) |
| 171 | arena[next].line[j]++; | 171 | arena[next].line[j]++; |
| 172 | } | 172 | } |
| 173 | } else { | 173 | } else { |
| @@ -187,9 +187,9 @@ static int random_walk(volatile cacheline_t *mem, int wss, int write_cycle) | |||
| 187 | return sum; | 187 | return sum; |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | volatile static cacheline_t* random_start(int wss) | 190 | volatile static rw_cacheline_t* random_start(int wss) |
| 191 | { | 191 | { |
| 192 | return arena + randrange(0, ((wss * 1024)/sizeof(cacheline_t))); | 192 | return arena + randrange(0, ((wss * 1024)/sizeof(rw_cacheline_t))); |
| 193 | } | 193 | } |
| 194 | /* | 194 | /* |
| 195 | static int sequential_walk(cacheline_t *_mem, int wss, int write_cycle) | 195 | static int sequential_walk(cacheline_t *_mem, int wss, int write_cycle) |
| @@ -217,7 +217,7 @@ static cacheline_t* sequential_start(int wss) | |||
| 217 | { | 217 | { |
| 218 | static int pos = 0; | 218 | static int pos = 0; |
| 219 | 219 | ||
| 220 | int num_cachelines = wss * CACHELINES_IN_1KB; | 220 | int num_cachelines = wss * RW_CACHELINES_IN_1KB; |
| 221 | 221 | ||
| 222 | cacheline_t *mem; | 222 | cacheline_t *mem; |
| 223 | 223 | ||
| @@ -245,7 +245,7 @@ static volatile int dont_optimize_me = 0; | |||
| 245 | #define RANDOM_WALK 1 | 245 | #define RANDOM_WALK 1 |
| 246 | static int loop_once(int wss, int write) | 246 | static int loop_once(int wss, int write) |
| 247 | { | 247 | { |
| 248 | volatile cacheline_t *mem; | 248 | volatile rw_cacheline_t *mem; |
| 249 | int temp; | 249 | int temp; |
| 250 | 250 | ||
| 251 | #ifdef RANDOM_WALK | 251 | #ifdef RANDOM_WALK |
| @@ -275,7 +275,7 @@ int main(int argc, char** argv) { | |||
| 275 | } | 275 | } |
| 276 | printf("random_walk: Using parameters: %ld, %lf, %d\n", wss, duration, write); | 276 | printf("random_walk: Using parameters: %ld, %lf, %d\n", wss, duration, write); |
| 277 | wss /= 1024; | 277 | wss /= 1024; |
| 278 | program_end = duration + wctime(); | 278 | program_end = duration + rw_wctime(); |
| 279 | // Initialize memory | 279 | // Initialize memory |
| 280 | size_t arena_sz = wss*1024; | 280 | size_t arena_sz = wss*1024; |
| 281 | arena = alloc_arena(arena_sz*2, 0, 0); | 281 | arena = alloc_arena(arena_sz*2, 0, 0); |
| @@ -285,23 +285,23 @@ int main(int argc, char** argv) { | |||
| 285 | while (1) { | 285 | while (1) { |
| 286 | double emergency_exit = program_end + 1; | 286 | double emergency_exit = program_end + 1; |
| 287 | 287 | ||
| 288 | if (wctime() > program_end) { | 288 | if (rw_wctime() > program_end) { |
| 289 | break; | 289 | break; |
| 290 | } else { | 290 | } else { |
| 291 | double last_loop = 0, loop_start; | 291 | double last_loop = 0, loop_start; |
| 292 | int tmp = 0; | 292 | int tmp = 0; |
| 293 | 293 | ||
| 294 | double start = cputime(); | 294 | double start = rw_cputime(); |
| 295 | double now = cputime(); | 295 | double now = rw_cputime(); |
| 296 | 296 | ||
| 297 | //while (now + last_loop < start) {// + exec_time) { | 297 | //while (now + last_loop < start) {// + exec_time) { |
| 298 | loop_start = now; | 298 | loop_start = now; |
| 299 | START_LOOP | 299 | START_LOOP |
| 300 | tmp += loop_once(wss, write); | 300 | tmp += loop_once(wss, write); |
| 301 | STOP_LOOP | 301 | STOP_LOOP |
| 302 | now = cputime(); | 302 | now = rw_cputime(); |
| 303 | last_loop = now - loop_start; | 303 | last_loop = now - loop_start; |
| 304 | if (emergency_exit && wctime() > emergency_exit) { | 304 | if (emergency_exit && rw_wctime() > emergency_exit) { |
| 305 | /* Oops --- this should only be possible if the execution time tracking | 305 | /* Oops --- this should only be possible if the execution time tracking |
| 306 | * is broken in the LITMUS^RT kernel. */ | 306 | * is broken in the LITMUS^RT kernel. */ |
| 307 | fprintf(stderr, "!!! rtspin/%d emergency exit!\n", getpid()); | 307 | fprintf(stderr, "!!! rtspin/%d emergency exit!\n", getpid()); |
| @@ -310,11 +310,11 @@ int main(int argc, char** argv) { | |||
| 310 | } | 310 | } |
| 311 | long sum = 0; | 311 | long sum = 0; |
| 312 | // Verify that we actually traversed the whole wss | 312 | // Verify that we actually traversed the whole wss |
| 313 | for (volatile cacheline_t* loc = arena; loc < arena + (wss*1024)/sizeof(cacheline_t); loc++) { | 313 | for (volatile rw_cacheline_t* loc = arena; loc < arena + (wss*1024)/sizeof(rw_cacheline_t); loc++) { |
| 314 | sum += loc->line[1]; | 314 | sum += loc->line[1]; |
| 315 | } | 315 | } |
| 316 | if (sum != wss * CACHELINES_IN_1KB) { | 316 | if (sum != wss * RW_CACHELINES_IN_1KB) { |
| 317 | fprintf(stderr, "We hopped the wrong number of times! Hops: %ld, should have been: %ld\n", sum, wss * CACHELINES_IN_1KB); | 317 | fprintf(stderr, "We hopped the wrong number of times! Hops: %ld, should have been: %ld\n", sum, wss * RW_CACHELINES_IN_1KB); |
| 318 | } | 318 | } |
| 319 | //} | 319 | //} |
| 320 | 320 | ||
| @@ -498,7 +498,7 @@ int main(int argc, char** argv) | |||
| 498 | else | 498 | else |
| 499 | set_page_color(config.cpu); | 499 | set_page_color(config.cpu); |
| 500 | 500 | ||
| 501 | start = wctime(); | 501 | start = rw_wctime(); |
| 502 | ret = task_mode(LITMUS_RT_TASK); | 502 | ret = task_mode(LITMUS_RT_TASK); |
| 503 | if (ret != 0) | 503 | if (ret != 0) |
| 504 | bail_out("could not become RT task"); | 504 | bail_out("could not become RT task"); |
| @@ -507,7 +507,7 @@ int main(int argc, char** argv) | |||
| 507 | ret = wait_for_ts_release(); | 507 | ret = wait_for_ts_release(); |
| 508 | if (ret != 0) | 508 | if (ret != 0) |
| 509 | bail_out("wait_for_ts_release()"); | 509 | bail_out("wait_for_ts_release()"); |
| 510 | start = wctime(); | 510 | start = rw_wctime(); |
| 511 | } | 511 | } |
| 512 | cp = get_ctrl_page(); | 512 | cp = get_ctrl_page(); |
| 513 | 513 | ||
| @@ -515,7 +515,7 @@ int main(int argc, char** argv) | |||
| 515 | if (verbose) { | 515 | if (verbose) { |
| 516 | get_job_no(&job_no); | 516 | get_job_no(&job_no); |
| 517 | fprintf(stderr, "rtspin/%d:%u @ %.4fms\n", gettid(), | 517 | fprintf(stderr, "rtspin/%d:%u @ %.4fms\n", gettid(), |
| 518 | job_no, (wctime() - start) * 1000); | 518 | job_no, (rw_wctime() - start) * 1000); |
| 519 | if (cp) { | 519 | if (cp) { |
| 520 | double deadline, current, release; | 520 | double deadline, current, release; |
| 521 | lt_t now = litmus_clock(); | 521 | lt_t now = litmus_clock(); |
