[PATCH v1 0/3] Improve event groups for topdown, add X event modifier

Ian Rogers posted 3 patches 1 month, 1 week ago
tools/perf/Documentation/perf-list.txt |  1 +
tools/perf/arch/x86/util/evsel.c       | 62 ++++++++++++++++++++++++--
tools/perf/builtin-stat.c              | 48 +++++++++-----------
tools/perf/util/evsel.c                |  7 ++-
tools/perf/util/evsel.h                |  3 +-
tools/perf/util/parse-events.c         |  5 ++-
tools/perf/util/parse-events.h         |  1 +
tools/perf/util/parse-events.l         |  5 ++-
8 files changed, 94 insertions(+), 38 deletions(-)
[PATCH v1 0/3] Improve event groups for topdown, add X event modifier
Posted by Ian Rogers 1 month, 1 week ago
In:
https://lore.kernel.org/lkml/20250822082233.1850417-1-dapeng1.mi@linux.intel.com/#t
Dapeng Mi and Xudong Hao reported that Intel topdown events have
issues with parsing when events are duplicated. While some of that is
intended, things could be better. These patches:

1) give error messages specific to topdown event grouping constraints,
2) fail groups if non-leaders fail to open (this appears to be old tech debt),
3) adds an 'X' event modifier to allow events to opt-out of being regrouped.

The 'X' modifier should also give a means to side-step future issues
in parse_events__sort_events_and_fix_groups should they come up.

Ian Rogers (3):
  perf evsel: Give warning for broken Intel topdown event grouping
  perf stat: Don't skip failing group events
  perf parse-events: Add 'X' modifier to exclude an event from being
    regrouped

 tools/perf/Documentation/perf-list.txt |  1 +
 tools/perf/arch/x86/util/evsel.c       | 62 ++++++++++++++++++++++++--
 tools/perf/builtin-stat.c              | 48 +++++++++-----------
 tools/perf/util/evsel.c                |  7 ++-
 tools/perf/util/evsel.h                |  3 +-
 tools/perf/util/parse-events.c         |  5 ++-
 tools/perf/util/parse-events.h         |  1 +
 tools/perf/util/parse-events.l         |  5 ++-
 8 files changed, 94 insertions(+), 38 deletions(-)

-- 
2.51.0.261.g7ce5a0a67e-goog
Re: [PATCH v1 0/3] Improve event groups for topdown, add X event modifier
Posted by Mi, Dapeng 1 month, 1 week ago
On 8/26/2025 5:12 AM, Ian Rogers wrote:
> In:
> https://lore.kernel.org/lkml/20250822082233.1850417-1-dapeng1.mi@linux.intel.com/#t
> Dapeng Mi and Xudong Hao reported that Intel topdown events have
> issues with parsing when events are duplicated. While some of that is
> intended, things could be better. These patches:
>
> 1) give error messages specific to topdown event grouping constraints,
> 2) fail groups if non-leaders fail to open (this appears to be old tech debt),
> 3) adds an 'X' event modifier to allow events to opt-out of being regrouped.
>
> The 'X' modifier should also give a means to side-step future issues
> in parse_events__sort_events_and_fix_groups should they come up.
>
> Ian Rogers (3):
>   perf evsel: Give warning for broken Intel topdown event grouping
>   perf stat: Don't skip failing group events
>   perf parse-events: Add 'X' modifier to exclude an event from being
>     regrouped
>
>  tools/perf/Documentation/perf-list.txt |  1 +
>  tools/perf/arch/x86/util/evsel.c       | 62 ++++++++++++++++++++++++--
>  tools/perf/builtin-stat.c              | 48 +++++++++-----------
>  tools/perf/util/evsel.c                |  7 ++-
>  tools/perf/util/evsel.h                |  3 +-
>  tools/perf/util/parse-events.c         |  5 ++-
>  tools/perf/util/parse-events.h         |  1 +
>  tools/perf/util/parse-events.l         |  5 ++-
>  8 files changed, 94 insertions(+), 38 deletions(-)

The whole patch-set looks good to me.

Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>

Tested the patches on Intel Sapphire Rapids and Panther Lake, all results
are expected.

Tested-by: Dapeng Mi <dapeng1.mi@linux.intel.com>

Test results on Sapphire Rapids.

1. sudo ./perf stat -e slots,slots -a sleep 1

WARNING: events were regrouped to match PMUs
Error:
Topdown slots event can only be group leader in '{slots,slots}'.

2. sudo ./perf stat -e slots,slots:X -a sleep 1
 Performance counter stats for 'system wide':

    55,734,800,895      slots                                             
                     (49.99%)
    57,217,900,875      slots:X                                           
                     (50.01%)

       1.009697323 seconds time elapsed

3.  sudo ./perf stat -e slots,topdown-fe-bound,topdown-fe-bound -a sleep 1

WARNING: events were regrouped to match PMUs
Error:
Perf metric event 'topdown-fe-bound' is duplicated in the same group (only
one event is allowed) in '{slots,topdown-fe-bound,topdown-fe-bound}'.

4. Perf stats test

sudo ./perf test 100
100: perf stat tests                                                 : Ok

Test results on Panther Lake.

1. sudo ./perf stat -e slots,slots -a sleep 1
WARNING: events were regrouped to match PMUs
Error:
Topdown slots event can only be group leader in
'{cpu_core/slots/,cpu_core/slots/}'.

2. sudo ./perf stat -e slots,slots:X -a sleep 1

 Performance counter stats for 'system wide':

     1,592,899,478      cpu_core/slots/                                   
                     (49.98%)
     1,682,298,980      cpu_core/slots/X                                   
                    (50.02%)

       1.002821768 seconds time elapsed

3. sudo ./perf stat -e slots,topdown-fe-bound,topdown-fe-bound -a sleep 1
WARNING: events were regrouped to match PMUs
Error:
Perf metric event 'cpu_core/topdown-fe-bound/' is duplicated in the same
group (only one event is allowed) in
'{cpu_core/slots/,cpu_core/topdown-fe-bound/,cpu_core/topdown-fe-bound/},cpu_atom/topdown-fe-bound/,cpu_atom/topdown-fe-bound/'.

4. sudo ./perf test 99
 99: perf stat tests                                                 : Ok

Re: [PATCH v1 0/3] Improve event groups for topdown, add X event modifier
Posted by Arnaldo Carvalho de Melo 3 weeks ago
On Tue, Aug 26, 2025 at 10:30:10AM +0800, Mi, Dapeng wrote:
> On 8/26/2025 5:12 AM, Ian Rogers wrote:
> > Ian Rogers (3):
> >   perf evsel: Give warning for broken Intel topdown event grouping
> >   perf stat: Don't skip failing group events
> >   perf parse-events: Add 'X' modifier to exclude an event from being
> >     regrouped
 
> The whole patch-set looks good to me.
 
> Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
 
> Tested the patches on Intel Sapphire Rapids and Panther Lake, all results
> are expected.
 
> Tested-by: Dapeng Mi <dapeng1.mi@linux.intel.com>

Thanks, applied to perf-tools-next,

- Arnaldo