Commit 8a4859c5 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf metrics: Be PMU specific in event match

Ids/events from a metric are turned into an event string and parsed;
setup_metric_events matches the id back to the parsed evsel. With
hybrid the same event may exist on both PMUs with the same name and be
being used by metrics at the same time. A metric on cpu_core therefore
shouldn't match against evsels on cpu_atom, or the metric will compute
the wrong value. Make the matching sensitive to the PMU being parsed.
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Tested-by: default avatarKan Liang <kan.liang@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ahmad Yasin <ahmad.yasin@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Edward Baker <edward.baker@intel.com>
Cc: Florian Fischer <florian.fischer@muhq.space>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kang Minchul <tegongkang@gmail.com>
Cc: Leo Yan <leo.yan@linaro.org>
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: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Samantha Alt <samantha.alt@intel.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Link: https://lore.kernel.org/r/20230502223851.2234828-43-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent d6b7dd11
...@@ -274,7 +274,7 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids, ...@@ -274,7 +274,7 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids,
const char *metric_id; const char *metric_id;
struct evsel *ev; struct evsel *ev;
size_t ids_size, matched_events, i; size_t ids_size, matched_events, i;
bool all_pmus = !strcmp(pmu, "all"); bool all_pmus = !strcmp(pmu, "all") || !perf_pmu__is_hybrid(pmu);
*out_metric_events = NULL; *out_metric_events = NULL;
ids_size = hashmap__size(ids); ids_size = hashmap__size(ids);
...@@ -287,7 +287,10 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids, ...@@ -287,7 +287,10 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids,
evlist__for_each_entry(metric_evlist, ev) { evlist__for_each_entry(metric_evlist, ev) {
struct expr_id_data *val_ptr; struct expr_id_data *val_ptr;
if (!all_pmus && strcmp(ev->pmu_name, pmu)) /* Don't match events for the wrong hybrid PMU. */
if (!all_pmus && ev->pmu_name &&
perf_pmu__is_hybrid(ev->pmu_name) &&
strcmp(ev->pmu_name, pmu))
continue; continue;
/* /*
* Check for duplicate events with the same name. For * Check for duplicate events with the same name. For
...@@ -304,6 +307,7 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids, ...@@ -304,6 +307,7 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids,
* about this event. * about this event.
*/ */
if (hashmap__find(ids, metric_id, &val_ptr)) { if (hashmap__find(ids, metric_id, &val_ptr)) {
pr_debug("Matched metric-id %s to %s\n", metric_id, evsel__name(ev));
metric_events[matched_events++] = ev; metric_events[matched_events++] = ev;
if (matched_events >= ids_size) if (matched_events >= ids_size)
...@@ -1592,7 +1596,7 @@ static int parse_groups(struct evlist *perf_evlist, ...@@ -1592,7 +1596,7 @@ static int parse_groups(struct evlist *perf_evlist,
ret = setup_metric_events(fake_pmu ? "all" : m->pmu, m->pctx->ids, ret = setup_metric_events(fake_pmu ? "all" : m->pmu, m->pctx->ids,
metric_evlist, &metric_events); metric_evlist, &metric_events);
if (ret) { if (ret) {
pr_debug("Cannot resolve IDs for %s: %s\n", pr_err("Cannot resolve IDs for %s: %s\n",
m->metric_name, m->metric_expr); m->metric_name, m->metric_expr);
goto out; goto out;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment