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

Message ID 20231127063415.996831-1-xu.yang_2@nxp.com
State New
Headers
Series perf pmu: add loaded_json_aliases for non-core pmu when get total events number |

Commit Message

Xu Yang Nov. 27, 2023, 6:34 a.m. UTC
  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@nxp.com>
---
 tools/perf/util/pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Xu Yang Nov. 27, 2023, 6:33 a.m. UTC | #1
> 
> 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.

Not sure how, but previous thread about this issue is disconnected.
You can refer to: https://lore.kernel.org/all/20231010065738.2536751-1-xu.yang_2@nxp.com/

Thanks,
Xu Yang

> 
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> ---
>  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
  

Patch

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;