diff options
author | Christopher Kenna <cjk@cs.unc.edu> | 2012-04-26 11:11:52 -0400 |
---|---|---|
committer | Christopher Kenna <cjk@cs.unc.edu> | 2012-04-26 11:11:52 -0400 |
commit | 7bd1ec8308f63bffda37127d02a178c5fc91dac3 (patch) | |
tree | 9d5967e272cff0948f76d6fca06a228313493120 | |
parent | 27a8f2048c6c9aebb2230d2903aa71e456c68a84 (diff) |
Track different perf counters. Colorbench: random in the entire arena.
-rw-r--r-- | bin/colorbench.c | 107 | ||||
-rw-r--r-- | bin/perfcounters.c | 12 |
2 files changed, 88 insertions, 31 deletions
diff --git a/bin/colorbench.c b/bin/colorbench.c index de7189a..c91b731 100644 --- a/bin/colorbench.c +++ b/bin/colorbench.c | |||
@@ -16,7 +16,7 @@ | |||
16 | #include "litmus.h" | 16 | #include "litmus.h" |
17 | 17 | ||
18 | #define DEBUG 1 | 18 | #define DEBUG 1 |
19 | #define NR_LOOPS 100 | 19 | #define NR_LOOPS 10 |
20 | 20 | ||
21 | /* Pound */ | 21 | /* Pound */ |
22 | #define NR_CPUS 4 | 22 | #define NR_CPUS 4 |
@@ -76,7 +76,8 @@ static pthread_barrier_t barrier; | |||
76 | static int nr_threads; | 76 | static int nr_threads; |
77 | static int arena_size; | 77 | static int arena_size; |
78 | static int color_shift; | 78 | static int color_shift; |
79 | static int *page_line_order; | 79 | //static int *page_line_order; |
80 | static int *arena_line_order; | ||
80 | static struct perf_counter perf_counters[NR_CPUS * NR_PERF_COUNTERS]; | 81 | static struct perf_counter perf_counters[NR_CPUS * NR_PERF_COUNTERS]; |
81 | 82 | ||
82 | #ifdef DEBUG | 83 | #ifdef DEBUG |
@@ -137,6 +138,7 @@ void sattolo(int *items, const int len) | |||
137 | * Starting at position 0 in the page_line_order means the cycle ends with 0. | 138 | * Starting at position 0 in the page_line_order means the cycle ends with 0. |
138 | * We use 0 in the arena to signify that we are done reading. | 139 | * We use 0 in the arena to signify that we are done reading. |
139 | */ | 140 | */ |
141 | #if 0 | ||
140 | static void init_arena_page_line_order(int *arena) | 142 | static void init_arena_page_line_order(int *arena) |
141 | { | 143 | { |
142 | int cur_page; | 144 | int cur_page; |
@@ -166,6 +168,22 @@ static void init_arena_page_line_order(int *arena) | |||
166 | } | 168 | } |
167 | } | 169 | } |
168 | } | 170 | } |
171 | #endif | ||
172 | static void init_arena_line_order(int *arena) | ||
173 | { | ||
174 | int cur_line; | ||
175 | for (cur_line = 0; cur_line < ARENA_LINES; cur_line++) { | ||
176 | const int idx = LINE_INTS * cur_line; | ||
177 | const int next_line = arena_line_order[cur_line]; | ||
178 | int next_idx = LINE_INTS * next_line; | ||
179 | |||
180 | if (0 == next_line) { | ||
181 | /* special case: cycle end */ | ||
182 | next_idx = 0; | ||
183 | } | ||
184 | arena[idx] = next_idx; | ||
185 | } | ||
186 | } | ||
169 | 187 | ||
170 | static void setup_colors(struct pthread_state *state) | 188 | static void setup_colors(struct pthread_state *state) |
171 | { | 189 | { |
@@ -194,6 +212,30 @@ static int loop_once(struct pthread_state *state) | |||
194 | return j; | 212 | return j; |
195 | } | 213 | } |
196 | 214 | ||
215 | static void print_perf_counters(void) | ||
216 | { | ||
217 | uint64_t val; | ||
218 | int err, cpu, i; | ||
219 | const char *name; | ||
220 | |||
221 | for (cpu = 0; cpu < NR_CPUS; cpu++) { | ||
222 | printf("CPU %d\n", cpu); | ||
223 | for (i = 0; i < NR_PERF_COUNTERS; i++) { | ||
224 | const int idx = cpu * NR_PERF_COUNTERS + i; | ||
225 | name = get_perf_name(&perf_counters[idx]); | ||
226 | err = read_perf_counter(&perf_counters[idx], &val); | ||
227 | if (err) | ||
228 | printf("%50s: ERROR\n", name); | ||
229 | else | ||
230 | #if 0 | ||
231 | printf("%50s: %10.3f\n", name, | ||
232 | ((double)val) / NR_LOOPS); | ||
233 | #endif | ||
234 | printf("%50s: %lu\n", name, val); | ||
235 | } | ||
236 | } | ||
237 | } | ||
238 | |||
197 | int thread_init(struct pthread_state *state) | 239 | int thread_init(struct pthread_state *state) |
198 | { | 240 | { |
199 | const int cpu = THREAD_CPU(state->tid); | 241 | const int cpu = THREAD_CPU(state->tid); |
@@ -220,7 +262,8 @@ int thread_init(struct pthread_state *state) | |||
220 | goto out; | 262 | goto out; |
221 | } | 263 | } |
222 | 264 | ||
223 | init_arena_page_line_order(state->arena); | 265 | //init_arena_page_line_order(state->arena); |
266 | init_arena_line_order(state->arena); | ||
224 | 267 | ||
225 | err = mlockall(MCL_CURRENT|MCL_FUTURE); | 268 | err = mlockall(MCL_CURRENT|MCL_FUTURE); |
226 | if (err) | 269 | if (err) |
@@ -241,6 +284,17 @@ static void change_counters(const int request) | |||
241 | } | 284 | } |
242 | } | 285 | } |
243 | 286 | ||
287 | static void reset_counters(void) | ||
288 | { | ||
289 | int cpu, counter; | ||
290 | for (cpu = 0; cpu < NR_CPUS; cpu++) { | ||
291 | for (counter = 0; counter < NR_PERF_COUNTERS; counter++) { | ||
292 | const int ctr_idx = cpu * NR_PERF_COUNTERS + counter; | ||
293 | ioctl(perf_counters[ctr_idx].fd, PERF_EVENT_IOC_RESET); | ||
294 | } | ||
295 | } | ||
296 | } | ||
297 | |||
244 | void * thread_start(void *data) | 298 | void * thread_start(void *data) |
245 | { | 299 | { |
246 | struct pthread_state *state = (struct pthread_state*) data; | 300 | struct pthread_state *state = (struct pthread_state*) data; |
@@ -252,14 +306,20 @@ void * thread_start(void *data) | |||
252 | 306 | ||
253 | pthread_barrier_wait(&barrier); | 307 | pthread_barrier_wait(&barrier); |
254 | 308 | ||
309 | #if 0 | ||
255 | if (0 == state->tid) | 310 | if (0 == state->tid) |
256 | change_counters(PERF_EVENT_IOC_ENABLE); | 311 | change_counters(PERF_EVENT_IOC_ENABLE); |
257 | 312 | ||
258 | pthread_barrier_wait(&barrier); | 313 | pthread_barrier_wait(&barrier); |
314 | #endif | ||
315 | |||
316 | change_counters(PERF_EVENT_IOC_ENABLE); | ||
259 | 317 | ||
260 | for (i = 0; i < NR_LOOPS; ++i) { | 318 | for (i = 0; i < NR_LOOPS; ++i) { |
261 | loop_once(state); | 319 | loop_once(state); |
262 | pthread_barrier_wait(&barrier); | 320 | //pthread_barrier_wait(&barrier); |
321 | print_perf_counters(); | ||
322 | reset_counters(); | ||
263 | } | 323 | } |
264 | 324 | ||
265 | if (0 == state->tid) | 325 | if (0 == state->tid) |
@@ -304,27 +364,6 @@ out: | |||
304 | return ret; | 364 | return ret; |
305 | } | 365 | } |
306 | 366 | ||
307 | static void print_perf_counters(void) | ||
308 | { | ||
309 | uint64_t val; | ||
310 | int err, cpu, i; | ||
311 | const char *name; | ||
312 | |||
313 | for (cpu = 0; cpu < NR_CPUS; cpu++) { | ||
314 | printf("CPU %d\n", cpu); | ||
315 | for (i = 0; i < NR_PERF_COUNTERS; i++) { | ||
316 | const int idx = cpu * NR_PERF_COUNTERS + i; | ||
317 | name = get_perf_name(&perf_counters[idx]); | ||
318 | err = read_perf_counter(&perf_counters[idx], &val); | ||
319 | if (err) | ||
320 | printf("%50s: ERROR\n", name); | ||
321 | else | ||
322 | printf("%50s: %10.3f\n", name, | ||
323 | ((double)val) / NR_LOOPS); | ||
324 | } | ||
325 | } | ||
326 | } | ||
327 | |||
328 | #define CHECK(fun, ...) { \ | 367 | #define CHECK(fun, ...) { \ |
329 | int err = fun(__VA_ARGS__); \ | 368 | int err = fun(__VA_ARGS__); \ |
330 | if (err) { \ | 369 | if (err) { \ |
@@ -366,8 +405,10 @@ int main(int argc, char **argv) | |||
366 | } | 405 | } |
367 | 406 | ||
368 | pthread_state = malloc(nr_threads * sizeof(*pthread_state)); | 407 | pthread_state = malloc(nr_threads * sizeof(*pthread_state)); |
369 | page_line_order = malloc(PAGE_LINES * sizeof(*page_line_order)); | 408 | //page_line_order = malloc(PAGE_LINES * sizeof(*page_line_order)); |
370 | if (!pthread_state || !page_line_order) { | 409 | arena_line_order = malloc(ARENA_LINES * sizeof(*arena_line_order)); |
410 | //if (!pthread_state || !page_line_order) { | ||
411 | if (!pthread_state || !arena_line_order) { | ||
371 | debug_print("could not malloc\n"); | 412 | debug_print("could not malloc\n"); |
372 | ret = 1; | 413 | ret = 1; |
373 | goto out; | 414 | goto out; |
@@ -379,7 +420,8 @@ int main(int argc, char **argv) | |||
379 | CHECK(pthread_attr_setdetachstate, &attr, PTHREAD_CREATE_JOINABLE); | 420 | CHECK(pthread_attr_setdetachstate, &attr, PTHREAD_CREATE_JOINABLE); |
380 | CHECK(pthread_barrier_init, &barrier, NULL, nr_threads); | 421 | CHECK(pthread_barrier_init, &barrier, NULL, nr_threads); |
381 | 422 | ||
382 | sattolo(page_line_order, PAGE_LINES); | 423 | //sattolo(page_line_order, PAGE_LINES); |
424 | sattolo(arena_line_order, ARENA_LINES); | ||
383 | //sequential(page_line_order, PAGE_LINES); | 425 | //sequential(page_line_order, PAGE_LINES); |
384 | 426 | ||
385 | for (i = 0; i < nr_threads; i++) { | 427 | for (i = 0; i < nr_threads; i++) { |
@@ -405,8 +447,13 @@ int main(int argc, char **argv) | |||
405 | CHECK(pthread_barrier_destroy, &barrier); | 447 | CHECK(pthread_barrier_destroy, &barrier); |
406 | CHECK(pthread_attr_destroy, &attr); | 448 | CHECK(pthread_attr_destroy, &attr); |
407 | 449 | ||
408 | printf("arena pages: %d\n", ARENA_PAGES); | 450 | printf("arena size: %d\n", arena_size); |
409 | print_perf_counters(); | 451 | printf("color shift: %d\n", color_shift); |
452 | printf("arena pages: %d\n", ARENA_PAGES); | ||
453 | printf("arena lines: %d\n", ARENA_LINES); | ||
454 | printf("use colors: %d\n", USE_COLORS); | ||
455 | printf("contiguous colors: %d\n", CONTIG_COLORS); | ||
456 | //print_perf_counters(); | ||
410 | 457 | ||
411 | out: | 458 | out: |
412 | return ret; | 459 | return ret; |
diff --git a/bin/perfcounters.c b/bin/perfcounters.c index 402e047..6302164 100644 --- a/bin/perfcounters.c +++ b/bin/perfcounters.c | |||
@@ -68,7 +68,6 @@ static struct perf_counter_setup perf_setup[NR_PERF_COUNTERS] = { | |||
68 | .type = PERF_TYPE_RAW, | 68 | .type = PERF_TYPE_RAW, |
69 | .config = ATTR_CONFIG(0x0f, 0x20), | 69 | .config = ATTR_CONFIG(0x0f, 0x20), |
70 | }, | 70 | }, |
71 | #endif | ||
72 | { | 71 | { |
73 | .name = "L2_RQSTS.PREFETCH_HIT", | 72 | .name = "L2_RQSTS.PREFETCH_HIT", |
74 | .type = PERF_TYPE_RAW, | 73 | .type = PERF_TYPE_RAW, |
@@ -79,6 +78,17 @@ static struct perf_counter_setup perf_setup[NR_PERF_COUNTERS] = { | |||
79 | .type = PERF_TYPE_RAW, | 78 | .type = PERF_TYPE_RAW, |
80 | .config = ATTR_CONFIG(0x24, 0x80), | 79 | .config = ATTR_CONFIG(0x24, 0x80), |
81 | }, | 80 | }, |
81 | #endif | ||
82 | { | ||
83 | .name = "MEM_LOAD_RETIRED.OTHER_CORE_L2_HIT_HITM", | ||
84 | .type = PERF_TYPE_RAW, | ||
85 | .config = ATTR_CONFIG(0xcb, 0x08), | ||
86 | }, | ||
87 | { | ||
88 | .name = "MEM_LOAD_RETIRED.L3_UNSHARED_HIT", | ||
89 | .type = PERF_TYPE_RAW, | ||
90 | .config = ATTR_CONFIG(0xcb, 0x04), | ||
91 | }, | ||
82 | { | 92 | { |
83 | .name = "MEM_LOAD_RETIRED.L3_MISS", | 93 | .name = "MEM_LOAD_RETIRED.L3_MISS", |
84 | .type = PERF_TYPE_RAW, | 94 | .type = PERF_TYPE_RAW, |