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

perf pmu: Fix alias events list

Commit 0e0ae8742207c3b4 ("perf list: Display hybrid PMU events with cpu
type") changes the event list for uncore PMUs or arm64 heterogeneous CPU
systems, such that duplicate aliases are incorrectly listed per PMU
(which they should not be), like:

# perf list
...
unc_cbo_cache_lookup.any_es
[Unit: uncore_cbox L3 Lookup any request that access cache and found
line in E or S-state]
unc_cbo_cache_lookup.any_es
[Unit: uncore_cbox L3 Lookup any request that access cache and found
line in E or S-state]
unc_cbo_cache_lookup.any_i
[Unit: uncore_cbox L3 Lookup any request that access cache and found
line in I-state]
unc_cbo_cache_lookup.any_i
[Unit: uncore_cbox L3 Lookup any request that access cache and found
line in I-state]
...

Notice how the events are listed twice.

The named commit changed how we remove duplicate events, in that events
for different PMUs are not treated as duplicates. I suppose this is to
handle how "Each hybrid pmu event has been assigned with a pmu name".

Fix PMU alias listing by restoring behaviour to remove duplicates for
non-hybrid PMUs.

Fixes: 0e0ae8742207c3b4 ("perf list: Display hybrid PMU events with cpu type")
Signed-off-by: John Garry <john.garry@huawei.com>
Tested-by: Zhengjun Xing <zhengjun.xing@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/1640103090-140490-1-git-send-email-john.garry@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

John Garry and committed by
Arnaldo Carvalho de Melo
e0257a01 0f80bfbf

+17 -6
+17 -6
tools/perf/util/pmu.c
··· 1659 1659 return !strcmp(name, "cpu") || is_arm_pmu_core(name); 1660 1660 } 1661 1661 1662 + static bool pmu_alias_is_duplicate(struct sevent *alias_a, 1663 + struct sevent *alias_b) 1664 + { 1665 + /* Different names -> never duplicates */ 1666 + if (strcmp(alias_a->name, alias_b->name)) 1667 + return false; 1668 + 1669 + /* Don't remove duplicates for hybrid PMUs */ 1670 + if (perf_pmu__is_hybrid(alias_a->pmu) && 1671 + perf_pmu__is_hybrid(alias_b->pmu)) 1672 + return false; 1673 + 1674 + return true; 1675 + } 1676 + 1662 1677 void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag, 1663 1678 bool long_desc, bool details_flag, bool deprecated, 1664 1679 const char *pmu_name) ··· 1759 1744 qsort(aliases, len, sizeof(struct sevent), cmp_sevent); 1760 1745 for (j = 0; j < len; j++) { 1761 1746 /* Skip duplicates */ 1762 - if (j > 0 && !strcmp(aliases[j].name, aliases[j - 1].name)) { 1763 - if (!aliases[j].pmu || !aliases[j - 1].pmu || 1764 - !strcmp(aliases[j].pmu, aliases[j - 1].pmu)) { 1765 - continue; 1766 - } 1767 - } 1747 + if (j > 0 && pmu_alias_is_duplicate(&aliases[j], &aliases[j - 1])) 1748 + continue; 1768 1749 1769 1750 if (name_only) { 1770 1751 printf("%s ", aliases[j].name);