diff options
Diffstat (limited to 'dis')
| -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 | |||
