linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf tool_pmu: Add skip check in tool_pmu__event_to_str()
@ 2025-02-07 15:28 kan.liang
  2025-02-07 16:52 ` Ian Rogers
  2025-02-12  1:39 ` Namhyung Kim
  0 siblings, 2 replies; 3+ messages in thread
From: kan.liang @ 2025-02-07 15:28 UTC (permalink / raw)
  To: acme, namhyung, irogers, linux-kernel, linux-perf-users
  Cc: peterz, mingo, thomas.falcon, Kan Liang

From: Kan Liang <kan.liang@linux.intel.com>

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>
---
 tools/perf/util/expr.c     | 2 ++
 tools/perf/util/tool_pmu.c | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c
index c221dcce6666..6413537442aa 100644
--- a/tools/perf/util/expr.c
+++ b/tools/perf/util/expr.c
@@ -215,6 +215,8 @@ int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref)
 int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
 		 struct expr_id_data **data)
 {
+	if (!ctx || !id)
+		return -1;
 	return hashmap__find(ctx->ids, id, data) ? 0 : -1;
 }
 
diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c
index 4fb097578479..3a68debe7143 100644
--- a/tools/perf/util/tool_pmu.c
+++ b/tools/perf/util/tool_pmu.c
@@ -62,7 +62,8 @@ int tool_pmu__num_skip_events(void)
 
 const char *tool_pmu__event_to_str(enum tool_pmu_event ev)
 {
-	if (ev > TOOL_PMU__EVENT_NONE && ev < TOOL_PMU__EVENT_MAX)
+	if ((ev > TOOL_PMU__EVENT_NONE && ev < TOOL_PMU__EVENT_MAX) &&
+	    !tool_pmu__skip_event(tool_pmu__event_names[ev]))
 		return tool_pmu__event_names[ev];
 
 	return NULL;
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf tool_pmu: Add skip check in tool_pmu__event_to_str()
  2025-02-07 15:28 [PATCH] perf tool_pmu: Add skip check in tool_pmu__event_to_str() kan.liang
@ 2025-02-07 16:52 ` Ian Rogers
  2025-02-12  1:39 ` Namhyung Kim
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Rogers @ 2025-02-07 16:52 UTC (permalink / raw)
  To: kan.liang
  Cc: acme, namhyung, linux-kernel, linux-perf-users, peterz, mingo,
	thomas.falcon

On Fri, Feb 7, 2025 at 7:28 AM <kan.liang@linux.intel.com> wrote:
>
> From: Kan Liang <kan.liang@linux.intel.com>
>
> 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>

Thanks Kan!

Reviewed-by: Ian Rogers <irogers@google.com>

Ian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf tool_pmu: Add skip check in tool_pmu__event_to_str()
  2025-02-07 15:28 [PATCH] perf tool_pmu: Add skip check in tool_pmu__event_to_str() kan.liang
  2025-02-07 16:52 ` Ian Rogers
@ 2025-02-12  1:39 ` Namhyung Kim
  1 sibling, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2025-02-12  1:39 UTC (permalink / raw)
  To: acme, irogers, linux-kernel, linux-perf-users, kan.liang
  Cc: peterz, mingo, thomas.falcon

On Fri, 07 Feb 2025 07:28:44 -0800, kan.liang@linux.intel.com wrote:
> 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.
> 
> [...]
Applied to perf-tools-next, thanks!

Best regards,
Namhyung



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-02-12  1:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-07 15:28 [PATCH] perf tool_pmu: Add skip check in tool_pmu__event_to_str() kan.liang
2025-02-07 16:52 ` Ian Rogers
2025-02-12  1:39 ` Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).