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

perf tools: Add skip check in tool_pmu__event_to_str()

Some topdown related metrics may fail on hybrid machines.

$ perf stat -M tma_frontend_bound
Cannot resolve IDs for tma_frontend_bound:
cpu_atom@TOPDOWN_FE_BOUND.ALL@ / (8 * cpu_atom@CPU_CLK_UNHALTED.CORE@)

In the find_tool_events(), the tool_pmu__event_to_str() is used to
compare the tool_events. It only checks the event name, no PMU or arch.
So the tool_events[TOOL_PMU__EVENT_SLOTS] is set to true, because the
p-core Topdown metrics has "slots" event.
The tool_events is shared. So when parsing the e-core metrics, the
"slots" is automatically added.

The "slots" event as a tool event should only be available on arm64. It
has a different meaning on X86. The tool_pmu__skip_event() intends
handle the case. Apply it for tool_pmu__event_to_str() as well.

There is a lack of sanity check in the expr__get_id(). Add the check.

Closes: https://lore.kernel.org/lkml/608077bc-4139-4a97-8dc4-7997177d95c4@linux.intel.com/
Fixes: 069057239a67 ("perf tool_pmu: Move expr literals to tool_pmu")
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Cc: thomas.falcon@intel.com
Link: https://lore.kernel.org/r/20250207152844.302167-1-kan.liang@linux.intel.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Kan Liang and committed by
Namhyung Kim
ee8aef2d 1df4b33f

+4 -1
+2
tools/perf/util/expr.c
··· 215 215 int expr__get_id(struct expr_parse_ctx *ctx, const char *id, 216 216 struct expr_id_data **data) 217 217 { 218 + if (!ctx || !id) 219 + return -1; 218 220 return hashmap__find(ctx->ids, id, data) ? 0 : -1; 219 221 } 220 222
+2 -1
tools/perf/util/tool_pmu.c
··· 62 62 63 63 const char *tool_pmu__event_to_str(enum tool_pmu_event ev) 64 64 { 65 - if (ev > TOOL_PMU__EVENT_NONE && ev < TOOL_PMU__EVENT_MAX) 65 + if ((ev > TOOL_PMU__EVENT_NONE && ev < TOOL_PMU__EVENT_MAX) && 66 + !tool_pmu__skip_event(tool_pmu__event_names[ev])) 66 67 return tool_pmu__event_names[ev]; 67 68 68 69 return NULL;