Skip to content

Bug fixes on topdown metrics group leader selection

Dapeng Mi linux-perf-users lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 7 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4perf topdown: Correct leader selection with sample_read enabledtools/perf/arch/x86/util/topdown.c+14 -23 replies
2/4perf parse-events: Don't move topdown metrics events when sorting eventstools/perf/arch/x86/util/evlist.c+0 -50 replies
3/4perf parse-events: Don't move slots event when no topdwon metrics eventtools/perf/arch/x86/util/evlist.c tools/perf/util/evlist.h tools/perf/util/parse-events.c+31 -172 replies
4/4perf tests: Add leader sampling test in record teststools/perf/tests/shell/record.sh+28 -02 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/4] Bug fixes on topdown metrics group leader selection

when counting/sampling topdown slots and metrics events, the following issues are found.

a. incorrect sampling leader selection if group only contains topdown slots event without topdown metrics event, such as

perf record -e '{slots,branches}:S' -c 10000 -vv sleep 1

In this case, the slots event should be sampled as leader but the branches event is sampled in fact like the verbose output shows.

perf_event_attr:

  type                             4 (cpu)
  size                             168
  config                           0x400 (slots)
  sample_type                      IP|TID|TIME|READ|CPU|IDENTIFIER
  read_format                      ID|GROUP|LOST
  disabled                         1
  sample_id_all                    1
  exclude_guest                    1

------------------------------------------------------------
sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 5
------------------------------------------------------------
perf_event_attr:

  type                             0 (PERF_TYPE_HARDWARE)
  size                             168
  config                           0x4 (PERF_COUNT_HW_BRANCH_INSTRUCTIONS)
  { sample_period, sample_freq }   10000
  sample_type                      IP|TID|TIME|READ|CPU|IDENTIFIER
  read_format                      ID|GROUP|LOST
  sample_id_all                    1
  exclude_guest                    1

b. Fail to run the perf command

perf record -e "{slots,instructions,topdown-retiring}:S" -vv -C0 sleep 1

------------------------------------------------------------
perf_event_attr:

  type                             4 (cpu)
  size                             168
  config                           0x400 (slots)
  sample_type                      IP|TID|TIME|READ|CPU|PERIOD|IDENTIFIER
  read_format                      ID|GROUP|LOST
  disabled                         1
  sample_id_all                    1
  exclude_guest                    1

------------------------------------------------------------
sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 5
------------------------------------------------------------
perf_event_attr:

  type                             4 (cpu)
  size                             168
  config                           0x8000 (topdown-retiring)
  { sample_period, sample_freq }   4000
  sample_type                      IP|TID|TIME|READ|CPU|PERIOD|IDENTIFIER
  read_format                      ID|GROUP|LOST
  freq                             1
  sample_id_all                    1
  exclude_guest                    1

------------------------------------------------------------
sys_perf_event_open: pid -1 cpu 0 group_fd 5 flags 0x8 sys_perf_event_open failed, error -22

Error:
The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (topdown-retiring).

Perf tool tries to regroup the events and move topdown-retiring event closely after slots event and leads to topdown-retiring event is select to sample. This is incorrect.

c. unnecessary events regroup for the group which only has slots event but without topdown metrics events, such as

perf stat -e "{instructions,slots}" -C 0 sleep 1
WARNING: events were regrouped to match PMUs

Performance counter stats for 'CPU(s) 0':

        27,581,148      slots
         8,390,827      instructions

       1.045546595 seconds time elapsed

Obviously, this events regroup is unnecessary.

The patches 1-3 separately fixes the above 3 issues in order and the patch 4/4 adds a new perf test to verify the leader sampling.

Dapeng Mi (4):
perf topdown: Correct leader selection with sample_read enabled perf parse-events: Don't move topdown metrics events when sorting
events
perf parse-events: Don't move slots event when no topdwon metrics
event
perf tests: Add leader sampling test in record tests

 tools/perf/arch/x86/util/evlist.c  | 11 ++++------
 tools/perf/arch/x86/util/topdown.c | 16 ++++++++++++--
 tools/perf/tests/shell/record.sh   | 28 ++++++++++++++++++++++++
 tools/perf/util/evlist.h           |  7 +++++-
 tools/perf/util/parse-events.c     | 35 ++++++++++++++++++------------
 5 files changed, 73 insertions(+), 24 deletions(-)

base-commit: 73e931504f8e0d42978bfcda37b323dbbd1afc08

Signature · 1 line
2.40.1