public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Bug fixes on topdown metrics group leader selection
@ 2024-07-02 22:40 Dapeng Mi
  2024-07-02 22:40 ` [PATCH 1/4] perf topdown: Correct leader selection with sample_read enabled Dapeng Mi
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Dapeng Mi @ 2024-07-02 22:40 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Ian Rogers, Adrian Hunter, Alexander Shishkin,
	Kan Liang
  Cc: linux-perf-users, linux-kernel, Yanfei Xu, Dapeng Mi, Dapeng Mi

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
-- 
2.40.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-07-03 13:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-02 22:40 [PATCH 0/4] Bug fixes on topdown metrics group leader selection Dapeng Mi
2024-07-02 22:40 ` [PATCH 1/4] perf topdown: Correct leader selection with sample_read enabled Dapeng Mi
2024-07-02 16:05   ` Liang, Kan
2024-07-03  2:46     ` Mi, Dapeng
2024-07-03 13:50       ` Liang, Kan
2024-07-02 22:40 ` [PATCH 2/4] perf parse-events: Don't move topdown metrics events when sorting events Dapeng Mi
2024-07-02 22:40 ` [PATCH 3/4] perf parse-events: Don't move slots event when no topdwon metrics event Dapeng Mi
2024-07-02 18:03   ` Liang, Kan
2024-07-03  2:51     ` Mi, Dapeng
2024-07-02 22:40 ` [PATCH 4/4] perf tests: Add leader sampling test in record tests Dapeng Mi
2024-07-02 18:07   ` Liang, Kan
2024-07-03  2:53     ` Mi, Dapeng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox