[PATCH v1] perf jevents: Allow duplicate metrics with different PMUs

Ian Rogers posted 1 patch 10 months, 1 week ago
tools/perf/pmu-events/jevents.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH v1] perf jevents: Allow duplicate metrics with different PMUs
Posted by Ian Rogers 10 months, 1 week ago
On hybrid machines the same metric may appear for cpu_atom and
cpu_core as well as being referenced from other metrics. The same
named metrics are required but on differing PMUs are required. Update
the jevents.py to handle this.

On (hybrid) Alderlake before:
```
$ perf stat -M tma_fp_divider -a sleep 1
event syntax error: '.._ACTIVE!3/,tma_core_bound/metric-id=tma_core_bound/,tma_backend_bound/metric-id=tma_..'
                                  \___ Bad event or PMU
```

After:
```
$ perf stat -M tma_fp_divider -a sleep 1

 Performance counter stats for 'system wide':

     1,257,833,472      cpu_core/TOPDOWN.SLOTS/          #      0.0 %  tma_fp_divider
            45,870      cpu_core/ARITH.FPDIV_ACTIVE/
       187,096,541      cpu_core/topdown-retiring/
       199,533,380      cpu_core/topdown-mem-bound/
       107,164,806      cpu_core/topdown-bad-spec/
       214,281,782      cpu_core/CPU_CLK_UNHALTED.THREAD/
         1,588,539      cpu_core/ARITH.DIV_ACTIVE/
       538,842,818      cpu_core/topdown-fe-bound/
       431,005,264      cpu_core/topdown-be-bound/
```

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/pmu-events/jevents.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index 36a5e5fa2a54..89f1ace2a697 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -481,7 +481,8 @@ def add_events_table_entries(item: os.DirEntry, topic: str) -> None:
   for e in read_json_events(item.path, topic):
     if e.name:
       _pending_events.append(e)
-    if e.metric_name and not any(e.metric_name == x.metric_name for x in _pending_metrics):
+    if e.metric_name and not any(e.metric_name == x.metric_name and
+                                 e.pmu == x.pmu for x in _pending_metrics):
       _pending_metrics.append(e)
 
 
-- 
2.49.0.504.g3bcea36a83-goog
Re: [PATCH v1] perf jevents: Allow duplicate metrics with different PMUs
Posted by Ian Rogers 10 months, 1 week ago
On Wed, Apr 2, 2025 at 11:38 AM Ian Rogers <irogers@google.com> wrote:
>
> On hybrid machines the same metric may appear for cpu_atom and
> cpu_core as well as being referenced from other metrics. The same
> named metrics are required but on differing PMUs are required. Update
> the jevents.py to handle this.
>
> On (hybrid) Alderlake before:
> ```
> $ perf stat -M tma_fp_divider -a sleep 1
> event syntax error: '.._ACTIVE!3/,tma_core_bound/metric-id=tma_core_bound/,tma_backend_bound/metric-id=tma_..'
>                                   \___ Bad event or PMU
> ```
>
> After:
> ```
> $ perf stat -M tma_fp_divider -a sleep 1
>
>  Performance counter stats for 'system wide':
>
>      1,257,833,472      cpu_core/TOPDOWN.SLOTS/          #      0.0 %  tma_fp_divider
>             45,870      cpu_core/ARITH.FPDIV_ACTIVE/
>        187,096,541      cpu_core/topdown-retiring/
>        199,533,380      cpu_core/topdown-mem-bound/
>        107,164,806      cpu_core/topdown-bad-spec/
>        214,281,782      cpu_core/CPU_CLK_UNHALTED.THREAD/
>          1,588,539      cpu_core/ARITH.DIV_ACTIVE/
>        538,842,818      cpu_core/topdown-fe-bound/
>        431,005,264      cpu_core/topdown-be-bound/
> ```
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/pmu-events/jevents.py | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
> index 36a5e5fa2a54..89f1ace2a697 100755
> --- a/tools/perf/pmu-events/jevents.py
> +++ b/tools/perf/pmu-events/jevents.py
> @@ -481,7 +481,8 @@ def add_events_table_entries(item: os.DirEntry, topic: str) -> None:
>    for e in read_json_events(item.path, topic):
>      if e.name:
>        _pending_events.append(e)
> -    if e.metric_name and not any(e.metric_name == x.metric_name for x in _pending_metrics):
> +    if e.metric_name and not any(e.metric_name == x.metric_name and
> +                                 e.pmu == x.pmu for x in _pending_metrics):

This was triggered by this patch carried in Google's tree but not yet
merged into perf-tools-next:
https://lore.kernel.org/lkml/20240926173554.404411-10-irogers@google.com/
So please ignore.

Thanks,
Ian

>        _pending_metrics.append(e)
>
>
> --
> 2.49.0.504.g3bcea36a83-goog
>