[PATCH] perf metricgroup: Fix Default metric group lookup for non-Intel CPUs

Francesco Nigro posted 1 patch 1 week, 5 days ago
tools/perf/util/metricgroup.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
[PATCH] perf metricgroup: Fix Default metric group lookup for non-Intel CPUs
Posted by Francesco Nigro 1 week, 5 days ago
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
Re: [PATCH] perf metricgroup: Fix Default metric group lookup for non-Intel CPUs
Posted by Ian Rogers 1 week, 5 days ago
On Sun, Mar 22, 2026 at 8:32 AM Francesco Nigro <nigro.fra@gmail.com> wrote:
>
> 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>

Sorry for the issue. I believe this is already fixed but there are
issues getting it into Linus' tree:
https://lore.kernel.org/lkml/20260207004956.610458-1-irogers@google.com/

Thanks,
Ian

> ---
>  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
>