Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf stat: Fix non-uniquified hybrid legacy events

Legacy hybrid events have attr.type == PERF_TYPE_HARDWARE, so they look
like plain legacy events if we only look at attr.type. But legacy events
should still be uniquified if they were opened on a non-legacy PMU. Fix
it by checking if the evsel is hybrid and forcing needs_uniquify
before looking at the attr.type.

This restores PMU names on hybrid systems and also changes "perf stat
metrics (shadow stat) test" from a FAIL back to a SKIP (on hybrid). The
test was gated on "cycles" appearing alone which doesn't happen on
here.

Before:
$ perf stat -- true
...
<not counted> instructions:u (0.00%)
162,536 instructions:u # 0.58 insn per cycle
...

After:
$ perf stat -- true
...
<not counted> cpu_atom/instructions/u (0.00%)
162,541 cpu_core/instructions/u # 0.62 insn per cycle
...

Fixes: 357b965deba9 ("perf stat: Changes to event name uniquification")
Suggested-by: Ian Rogers <irogers@google.com>
Signed-off-by: James Clark <james.clark@linaro.org>
Tested-by: Thomas Falcon <thomas.falcon@intel.com>
Link: https://lore.kernel.org/r/20250226145526.632380-1-james.clark@linaro.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

James Clark and committed by
Namhyung Kim
be9f3e95 7788ad59

+6 -6
+6 -6
tools/perf/util/stat-display.c
··· 1688 1688 return; 1689 1689 } 1690 1690 1691 + if (!config->hybrid_merge && evsel__is_hybrid(counter)) { 1692 + /* Unique hybrid counters necessary. */ 1693 + counter->needs_uniquify = true; 1694 + return; 1695 + } 1696 + 1691 1697 if (counter->core.attr.type < PERF_TYPE_MAX && counter->core.attr.type != PERF_TYPE_RAW) { 1692 1698 /* Legacy event, don't uniquify. */ 1693 1699 return; ··· 1707 1701 1708 1702 if (config->aggr_mode == AGGR_NONE) { 1709 1703 /* Always unique with no aggregation. */ 1710 - counter->needs_uniquify = true; 1711 - return; 1712 - } 1713 - 1714 - if (!config->hybrid_merge && evsel__is_hybrid(counter)) { 1715 - /* Unique hybrid counters necessary. */ 1716 1704 counter->needs_uniquify = true; 1717 1705 return; 1718 1706 }