Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf test pmu-events: Fake PMU metric workaround

We test metrics with fake events with fake values. The fake values may
yield division by zero and so we count both up and down to try to
avoid this. Unfortunately this isn't sufficient for some metrics and
so don't fail the test for them.

Add the metric name to debug output.

Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Kan Liang <kan.liang@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221215064755.1620246-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
ed4c1778 ad9ef9eb

+11 -6
+11 -6
tools/perf/tests/pmu-events.c
··· 959 959 { "(imx8_ddr0@read\\-cycles@ + imx8_ddr0@write\\-cycles@)", }, 960 960 }; 961 961 962 - static int metric_parse_fake(const char *str) 962 + static int metric_parse_fake(const char *metric_name, const char *str) 963 963 { 964 964 struct expr_parse_ctx *ctx; 965 965 struct hashmap_entry *cur; ··· 968 968 size_t bkt; 969 969 int i; 970 970 971 - pr_debug("parsing '%s'\n", str); 971 + pr_debug("parsing '%s': '%s'\n", metric_name, str); 972 972 973 973 ctx = expr__ctx_new(); 974 974 if (!ctx) { ··· 1006 1006 hashmap__for_each_entry(ctx->ids, cur, bkt) 1007 1007 expr__add_id_val(ctx, strdup(cur->pkey), i--); 1008 1008 if (expr__parse(&result, ctx, str)) { 1009 - pr_err("expr__parse failed\n"); 1010 - ret = -1; 1009 + pr_err("expr__parse failed for %s\n", metric_name); 1010 + /* The following have hard to avoid divide by zero. */ 1011 + if (!strcmp(metric_name, "tma_clears_resteers") || 1012 + !strcmp(metric_name, "tma_mispredicts_resteers")) 1013 + ret = 0; 1014 + else 1015 + ret = -1; 1011 1016 } 1012 1017 } 1013 1018 ··· 1028 1023 if (!pe->metric_expr) 1029 1024 return 0; 1030 1025 1031 - return metric_parse_fake(pe->metric_expr); 1026 + return metric_parse_fake(pe->metric_name, pe->metric_expr); 1032 1027 } 1033 1028 1034 1029 /* ··· 1042 1037 int err = 0; 1043 1038 1044 1039 for (size_t i = 0; i < ARRAY_SIZE(metrics); i++) { 1045 - err = metric_parse_fake(metrics[i].str); 1040 + err = metric_parse_fake("", metrics[i].str); 1046 1041 if (err) 1047 1042 return err; 1048 1043 }