From 49f20d723e25a221fbcf1cbf4e51bb2942326e4f Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Thu, 6 Sep 2012 14:55:44 -0300 Subject: [PATCH] perf test: Add roundtrip test for hardware cache events That nicely catches the problem reported by Joel Uckelman in http://permalink.gmane.org/gmane.linux.kernel.perf.user/1016 : [root@sandy ~]# perf test 1: vmlinux symtab matches kallsyms: Ok 2: detect open syscall event: Ok 3: detect open syscall event on all cpus: Ok 4: read samples using the mmap interface: Ok 5: parse events tests: Ok 6: x86 rdpmc test: Ok 7: Validate PERF_RECORD_* events & perf_sample fields: Ok 8: Test perf pmu format parsing: Ok 9: Test dso data interface: Ok 10: roundtrip evsel->name check: FAILED! [root@sandy ~]# perf test -v 10 10: roundtrip evsel->name check: --- start --- L1-dcache-misses != L1-dcache-load-misses L1-dcache-misses != L1-dcache-store-misses L1-dcache-misses != L1-dcache-prefetch-misses L1-icache-misses != L1-icache-load-misses L1-icache-misses != L1-icache-prefetch-misses LLC-misses != LLC-load-misses LLC-misses != LLC-store-misses LLC-misses != LLC-prefetch-misses dTLB-misses != dTLB-load-misses dTLB-misses != dTLB-store-misses dTLB-misses != dTLB-prefetch-misses iTLB-misses != iTLB-load-misses branch-misses != branch-load-misses node-misses != node-load-misses node-misses != node-store-misses node-misses != node-prefetch-misses ---- end ---- roundtrip evsel->name check: FAILED! [root@sandy ~]# Now lemme apply Jiri's fix and try it again... Cc: David Ahern Cc: Frederic Weisbecker Cc: Joel Uckelman Cc: Jiri Olsa Cc: Mike Galbraith Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-bbewtxw0rfipp5qy1j3jtg5d@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-test.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c index ba94fbe..cf33e50 100644 --- a/tools/perf/builtin-test.c +++ b/tools/perf/builtin-test.c @@ -1092,6 +1092,63 @@ static int test__perf_pmu(void) return perf_pmu__test(); } +static int perf_evsel__roundtrip_cache_name_test(void) +{ + char name[128]; + int type, op, err = 0, ret = 0, i, idx; + struct perf_evsel *evsel; + struct perf_evlist *evlist = perf_evlist__new(NULL, NULL); + + if (evlist == NULL) + return -ENOMEM; + + for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { + for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { + /* skip invalid cache type */ + if (!perf_evsel__is_cache_op_valid(type, op)) + continue; + + for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { + __perf_evsel__hw_cache_type_op_res_name(type, op, i, + name, sizeof(name)); + err = parse_events(evlist, name, 0); + if (err) + ret = err; + } + } + } + + idx = 0; + evsel = perf_evlist__first(evlist); + + for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { + for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { + /* skip invalid cache type */ + if (!perf_evsel__is_cache_op_valid(type, op)) + continue; + + for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { + __perf_evsel__hw_cache_type_op_res_name(type, op, i, + name, sizeof(name)); + if (evsel->idx != idx) + continue; + + ++idx; + + if (strcmp(perf_evsel__name(evsel), name)) { + pr_debug("%s != %s\n", perf_evsel__name(evsel), name); + ret = -1; + } + + evsel = perf_evsel__next(evsel); + } + } + } + + perf_evlist__delete(evlist); + return ret; +} + static int __perf_evsel__name_array_test(const char *names[], int nr_names) { int i, err; @@ -1138,6 +1195,10 @@ static int perf_evsel__roundtrip_name_test(void) if (err) ret = err; + err = perf_evsel__roundtrip_cache_name_test(); + if (err) + ret = err; + return ret; } -- 2.7.4