perf metricgroup: Fix Default metric group lookup for non-Intel CPUs
PATCH 1/1 perf metricgroup: Fix Default metric group lookup for non-Intel CPUs
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--- tools/perf/util/metricgroup.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
tools/perf/util/metricgroup.c +9 -3
@@ -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; }
Signature · 1 line
2.53.0
Ian Rogers
reviewerQuoted 30 lines · Francesco Nigro
metricgroup__has_metric_or_groups()only searches the CPU-specific metrics table returned bypmu_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" becauseadd_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 viapmu_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 withmetricgroup__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:
Quoted 8 lines
$ 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 utilizedFixes b0a9e8f81fc4 ("perf stat,jevents: Introduce Default tags for the default mode")Signed-off-by Francesco Nigro <[email protected]>
Sorry for the issue. I believe this is already fixed but there are issues getting it into Linus' tree:
https://lore.kernel.org/lkml/[email protected]/
Thanks,
Ian
Quoted 30 lines
--- tools/perf/util/metricgroup.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)tools/perf/util/metricgroup.c +9
-4@@ -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