[PATCH] perf pmu: add loaded_json_aliases for non-core pmu when get total events number

From: Xu Yang
Date: Mon Nov 27 2023 - 01:29:02 EST


After pmu_read_sysfs(), event aliases in json may be loaded for non-core
pmu. And pmu->event_table is NULL for non-core pmu.
If perf_pmu__num_events() didn't add loaded_json_aliases to the total
number, perf list will show below error:

Unexpected event imx8_ddr0/imx8_ddr0/write-command//
...

This is because perf_pmu__num_events() didn't count correct events number.
This will allow perf_pmu__num_events() to get corrent events number.

Signed-off-by: Xu Yang <xu.yang_2@xxxxxxx>
---
tools/perf/util/pmu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index d3c9aa4326be..646cf3351883 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -1631,8 +1631,8 @@ size_t perf_pmu__num_events(struct perf_pmu *pmu)

nr = pmu->sysfs_aliases;

- if (pmu->cpu_aliases_added)
- nr += pmu->loaded_json_aliases;
+ if (pmu->cpu_aliases_added || pmu->is_uncore)
+ nr += pmu->loaded_json_aliases;
else if (pmu->events_table)
nr += pmu_events_table__num_events(pmu->events_table, pmu) - pmu->loaded_json_aliases;

--
2.34.1