public inbox for linux-perf-users@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf metricgroup: Fix Default metric group lookup for non-Intel CPUs
@ 2026-03-22 15:31 Francesco Nigro
  2026-03-22 16:27 ` Ian Rogers
  0 siblings, 1 reply; 2+ messages in thread
From: Francesco Nigro @ 2026-03-22 15:31 UTC (permalink / raw)
  To: linux-perf-users
  Cc: linux-kernel, acme, irogers, kan.liang, namhyung, peterz, mingo,
	jolsa, Francesco Nigro

metricgroup__has_metric_or_groups() only searches the CPU-specific
metrics table returned by pmu_metrics_table__find(). The "Default"
metric group (used by 'perf stat' when no events are specified) is
defined in the common/arch-independent metrics table, not in
CPU-specific tables.

For AMD CPUs (e.g. Zen4), the CPU-specific metrics table contains
metrics for groups like PipelineL1, l2_cache, etc., but not "Default".
This causes bare 'perf stat <command>' to fail with "No supported
events found" because add_default_events() never adds any events.

Other code paths like metricgroup__for_each_metric() (used by
'perf list' and 'perf stat -M Default') correctly search both the
CPU-specific table and the common/default table via
pmu_metrics_table__default(), which is why 'perf stat -M Default'
works while bare 'perf stat' does not.

Fix metricgroup__has_metric_or_groups() to also search the default
metrics table as a fallback, consistent with
metricgroup__for_each_metric().

Tested on AMD Ryzen 9 7950X (Zen4, family 25h) with kernel 6.18.13
and perf built from 6.19.8 source.

Before the fix:
  $ perf stat true
  Error: No supported events found.

After the fix:
  $ perf stat true
  Performance counter stats for 'true':
    0      context-switches        #  0.0 cs/sec
   55      page-faults             #  ...
    0.22 msec task-clock           #  0.0 CPUs utilized

Fixes: b0a9e8f81fc4 ("perf stat,jevents: Introduce Default tags for the default mode")
Signed-off-by: Francesco Nigro <nigro.fra@gmail.com>
---
 tools/perf/util/metricgroup.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index a21f2d4969c5..670b650f86fe 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -1606,9 +1606,15 @@ bool metricgroup__has_metric_or_groups(const char *pmu, const char *metric_or_gr
 		.metric_or_groups = metric_or_groups,
 	};
 
-	return pmu_metrics_table__for_each_metric(table,
-						  metricgroup__has_metric_or_groups_callback,
-						  &data)
+	if (pmu_metrics_table__for_each_metric(table,
+					       metricgroup__has_metric_or_groups_callback,
+					       &data))
+		return true;
+
+	table = pmu_metrics_table__default();
+	return table && pmu_metrics_table__for_each_metric(table,
+							   metricgroup__has_metric_or_groups_callback,
+							   &data)
 		? true : false;
 }
 
-- 
2.53.0


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

end of thread, other threads:[~2026-03-22 16:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-22 15:31 [PATCH] perf metricgroup: Fix Default metric group lookup for non-Intel CPUs Francesco Nigro
2026-03-22 16:27 ` Ian Rogers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox