public inbox for linux-perf-users@vger.kernel.org
 help / color / mirror / Atom feed
From: Francesco Nigro <nigro.fra@gmail.com>
To: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, acme@kernel.org,
	irogers@google.com, kan.liang@linux.intel.com,
	namhyung@kernel.org, peterz@infradead.org, mingo@redhat.com,
	jolsa@kernel.org, Francesco Nigro <nigro.fra@gmail.com>
Subject: [PATCH] perf metricgroup: Fix Default metric group lookup for non-Intel CPUs
Date: Sun, 22 Mar 2026 16:31:55 +0100	[thread overview]
Message-ID: <20260322153155.205405-1-nigro.fra@gmail.com> (raw)

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


             reply	other threads:[~2026-03-22 15:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-22 15:31 Francesco Nigro [this message]
2026-03-22 16:27 ` [PATCH] perf metricgroup: Fix Default metric group lookup for non-Intel CPUs Ian Rogers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260322153155.205405-1-nigro.fra@gmail.com \
    --to=nigro.fra@gmail.com \
    --cc=acme@kernel.org \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox