linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf/test: Skip leader sampling for s390
@ 2025-02-28  6:22 Thomas Richter
  2025-03-01  0:12 ` Namhyung Kim
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas Richter @ 2025-02-28  6:22 UTC (permalink / raw)
  To: linux-kernel, linux-s390, linux-perf-users, acme, namhyung
  Cc: agordeev, gor, sumanthk, hca, Thomas Richter

In tree linux-next
the perf test case 114 'perf record tests' has a subtest
named 'Basic leader sampling test' which always fails on s390.
Root cause is this invocation

 # perf record -vv -e '{cycles,cycles}:Su' -- perf test -w brstack

 ...
 In the debug output the following 2 event are installed:

 ------------------------------------------------------------
 perf_event_attr:
  type                             0 (PERF_TYPE_HARDWARE)
  size                             136
  config                           0 (PERF_COUNT_HW_CPU_CYCLES)
  { sample_period, sample_freq }   4000
  sample_type                      IP|TID|TIME|READ|CPU|PERIOD|IDENTIFIER
  read_format                      ID|GROUP|LOST
  disabled                         1
  exclude_kernel                   1
  exclude_hv                       1
  freq                             1
  sample_id_all                    1
 ------------------------------------------------------------
 sys_perf_event_open: pid -1  cpu 0  group_fd -1  flags 0x8 = 5
 ------------------------------------------------------------
 perf_event_attr:
  type                             0 (PERF_TYPE_HARDWARE)
  size                             136
  config                           0 (PERF_COUNT_HW_CPU_CYCLES)
  sample_type                      IP|TID|TIME|READ|CPU|PERIOD|IDENTIFIER
  read_format                      ID|GROUP|LOST
  exclude_kernel                   1
  exclude_hv                       1
  sample_id_all                    1
 ------------------------------------------------------------
 sys_perf_event_open: pid -1  cpu 0  group_fd 5  flags 0x8 = 6
 ...

The first event is the group leader and is installed as sampling event.
The secound one is group member and is installed as counting event.

Namhyung Kim confirms this observation:
> Yep, the syntax '{event1,event2}:S' is for group leader sampling which
> reduces the overhead of PMU interrupts.  The idea is that those events
> are scheduled together so sampling is enabled only for the leader
> (usually the first) event and it reads counts from the member events
> using PERF_SAMPLE_READ.
>
> So they should have the same counts if it uses the same events in a
> group.

However this does not work on s390. s390 has one dedicated sampling PMU
which supports only one event. A different PMU is used for counting.
Both run concurrently using different setups and frequencies.

On s390x a sampling event is setup using a preset trigger and a large
buffer. The hardware
 - writes a samples (64 bytes) into this buffer
   when a given number of CPU instructions has been executed.
 - and triggers an interrupt when the buffer gets full.
The trigger has just a few possible values.

On s390x the counting event cycles is used to read out the numer of
CPU cycles executed.

On s390 above invocation created 2 events executed on 2 different
PMU and the result are diffent values from two independently running
PMUs which do not match in a consistent and reliably as on Intel:

 # ./perf record  -e '{cycles,cycles}:Su' -- perf test -w brstack
   ...
 # ./perf script
   perf 2799437 92568.845118:  5508000 cycles:  3ffbcb898b6 do_lookup_x+0x196
   perf 2799437 92568.845119:  1377000 cycles:  3ffbcb898b6 do_lookup_x+0x196
   perf 2799437 92568.845120:  4131000 cycles:  3ffbcb897e8 do_lookup_x+0xc8
   perf 2799437 92568.845121:  1377000 cycles:  3ffbcb8a37c _dl_lookup_symbol
   perf 2799437 92568.845122:  1377000 cycles:  3ffbcb89558 check_match+0x18
   perf 2799437 92568.845123:  2754000 cycles:  3ffbcb89b2a do_lookup_x+0x40a
   perf 2799437 92568.845124:  1377000 cycles:  3ffbcb89b1e do_lookup_x+0x3fe

As can be seen the result match very often but not all the time
make this test on s390 failing very, very often.

This patch bypasses this test on s390.

Output before:
 # ./perf test 114
 114: perf record tests                       : FAILED!
 #

Output after:
 # ./perf test 114
 114: perf record tests                       : Ok
 #

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
---
 tools/perf/tests/shell/record.sh | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/record.sh
index ba8d873d3ca7..98b69820bc5f 100755
--- a/tools/perf/tests/shell/record.sh
+++ b/tools/perf/tests/shell/record.sh
@@ -231,6 +231,12 @@ test_cgroup() {
 
 test_leader_sampling() {
   echo "Basic leader sampling test"
+  if [ "$(uname -m)" = s390x ]
+  then
+    echo "Leader sampling skipped"
+    ((skipped+=1))
+    return
+  fi
   if ! perf record -o "${perfdata}" -e "{cycles,cycles}:Su" -- \
     perf test -w brstack 2> /dev/null
   then
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread
* Re: [PATCH] perf/test: Skip leader sampling for s390
@ 2025-09-18 21:11 Anubhav Shelat
  0 siblings, 0 replies; 7+ messages in thread
From: Anubhav Shelat @ 2025-09-18 21:11 UTC (permalink / raw)
  To: eranian
  Cc: Arnaldo Carvalho de Melo, agordeev, ctshao, gor, hca, Ian Rogers,
	linux-kernel, linux-perf-users, linux-s390, Namhyung Kim, peterz,
	sumanthk, tmricht, Michael Petlan

I believe this issue is causing perf record tests to fail leader
samping on aarch64 machines. The important commands from the test:

# ./perf record -e "{cycles,cycles}:Su" -- ./perf test -w brstack
Lowering default frequency rate from 4000 to 1400.
Please consider tweaking /proc/sys/kernel/perf_event_max_sample_rate.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.019 MB perf.data (210 samples) ]
# ./perf script -i perf.data | grep brstack
            perf   98281 184091.292956:     621736 cycles:
53b844 brstack_bench+0x40 (/root/linux/tools/perf/perf)
            perf   98281 184091.292956:     621765 cycles:
53b844 brstack_bench+0x40 (/root/linux/tools/perf/perf)
            perf   98281 184091.293346:     611236 cycles:
53b784 brstack_bar+0x24 (/root/linux/tools/perf/perf)
            perf   98281 184091.293346:     611266 cycles:
53b784 brstack_bar+0x24 (/root/linux/tools/perf/perf)
            perf   98281 184091.293734:     587649 cycles:
53b844 brstack_bench+0x40 (/root/linux/tools/perf/perf)
            perf   98281 184091.293734:     587678 cycles:
53b844 brstack_bench+0x40 (/root/linux/tools/perf/perf)
            perf   98281 184091.294155:     648439 cycles:
53b780 brstack_bar+0x20 (/root/linux/tools/perf/perf)
            perf   98281 184091.294155:     648469 cycles:
53b780 brstack_bar+0x20 (/root/linux/tools/perf/perf)
            perf   98281 184091.294588:     716679 cycles:
53b844 brstack_bench+0x40 (/root/linux/tools/perf/perf)
            perf   98281 184091.294588:     716709 cycles:
53b844 brstack_bench+0x40 (/root/linux/tools/perf/perf)
            perf   98281 184091.295050:     779147 cycles:
53b814 brstack_bench+0x10 (/root/linux/tools/perf/perf)
            perf   98281 184091.295050:     779177 cycles:
53b814 brstack_bench+0x10 (/root/linux/tools/perf/perf)
            perf   98281 184091.295545:     842413 cycles:
53b8b8 brstack_bench+0xb4 (/root/linux/tools/perf/perf)
            perf   98281 184091.295545:     842443 cycles:
53b8b8 brstack_bench+0xb4 (/root/linux/tools/perf/perf)
            perf   98281 184091.296191:     899736 cycles:
53b77c brstack_bar+0x1c (/root/linux/tools/perf/perf)
            perf   98281 184091.296191:     899766 cycles:
53b77c brstack_bar+0x1c (/root/linux/tools/perf/perf)
            perf   98281 184091.296721:     914623 cycles:
53b794 brstack_bar+0x34 (/root/linux/tools/perf/perf)
            perf   98281 184091.296721:     914652 cycles:
53b794 brstack_bar+0x34 (/root/linux/tools/perf/perf)
            perf   98281 184091.297255:     926741 cycles:
53b7a8 brstack_bar+0x48 (/root/linux/tools/perf/perf)
            perf   98281 184091.297255:     926770 cycles:
53b7a8 brstack_bar+0x48 (/root/linux/tools/perf/perf)
            perf   98281 184091.297813:     966974 cycles:
53b778 brstack_bar+0x18 (/root/linux/tools/perf/perf)
            perf   98281 184091.297813:     967003 cycles:
53b778 brstack_bar+0x18 (/root/linux/tools/perf/perf)
            perf   98281 184091.298394:    1007743 cycles:
53b784 brstack_bar+0x24 (/root/linux/tools/perf/perf)
            perf   98281 184091.298394:    1007772 cycles:
53b784 brstack_bar+0x24 (/root/linux/tools/perf/perf)
            perf   98281 184091.298991:    1043010 cycles:
53b794 brstack_bar+0x34 (/root/linux/tools/perf/perf)
            perf   98281 184091.298991:    1043039 cycles:
53b794 brstack_bar+0x34 (/root/linux/tools/perf/perf)
            perf   98281 184091.299604:    1072961 cycles:
53b794 brstack_bar+0x34 (/root/linux/tools/perf/perf)
            perf   98281 184091.299604:    1072990 cycles:
53b794 brstack_bar+0x34 (/root/linux/tools/perf/perf)
            perf   98281 184091.300234:    1099175 cycles:
53b768 brstack_bar+0x8 (/root/linux/tools/perf/perf)
            perf   98281 184091.300234:    1099204 cycles:
53b768 brstack_bar+0x8 (/root/linux/tools/perf/perf)
            perf   98281 184091.300870:    1121830 cycles:
53b898 brstack_bench+0x94 (/root/linux/tools/perf/perf)
            perf   98281 184091.300870:    1121860 cycles:
53b898 brstack_bench+0x94 (/root/linux/tools/perf/perf)
            perf   98281 184091.301515:    1140634 cycles:
53b788 brstack_bar+0x28 (/root/linux/tools/perf/perf)
            perf   98281 184091.301515:    1140664 cycles:
53b788 brstack_bar+0x28 (/root/linux/tools/perf/perf)
            perf   98281 184091.302174:    1158251 cycles:
53b7f0 brstack_foo+0x40 (/root/linux/tools/perf/perf)
            perf   98281 184091.302174:    1158281 cycles:
53b7f0 brstack_foo+0x40 (/root/linux/tools/perf/perf)
            perf   98281 184091.302838:    1173750 cycles:
53b774 brstack_bar+0x14 (/root/linux/tools/perf/perf)
            perf   98281 184091.302838:    1173780 cycles:
53b774 brstack_bar+0x14 (/root/linux/tools/perf/perf)
            perf   98281 184091.303504:    1186018 cycles:
53b794 brstack_bar+0x34 (/root/linux/tools/perf/perf)
            perf   98281 184091.303504:    1186048 cycles:
53b794 brstack_bar+0x34 (/root/linux/tools/perf/perf)
            perf   98281 184091.304185:    1197272 cycles:
53b7fc brstack_foo+0x4c (/root/linux/tools/perf/perf)
            perf   98281 184091.304185:    1197302 cycles:
53b7fc brstack_foo+0x4c (/root/linux/tools/perf/perf)
            perf   98281 184091.304864:    1208165 cycles:
53b768 brstack_bar+0x8 (/root/linux/tools/perf/perf)
            perf   98281 184091.304864:    1208194 cycles:
53b768 brstack_bar+0x8 (/root/linux/tools/perf/perf)
            perf   98281 184091.306794:    1215537 cycles:
53b914 brstack+0x58 (/root/linux/tools/perf/perf)
            perf   98281 184091.306794:    3426542 cycles:
53b914 brstack+0x58 (/root/linux/tools/perf/perf)

Usually the difference between the leader and sibling counts is about
30 cycles, but occasionally there's a really big difference. When
running the perf record with '-e "{cycles,cycles,cycles}:Su"' the two
sibling events have the same cycle count.
There is no difference between the leader and sibling when running on
x86 systems using the cycles event, but when using the task-clock
event, the results were similar to Thomas' on both x86 and aarch64.

Any advice would be appreciated.

Thanks,
Anubhav


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

end of thread, other threads:[~2025-09-18 21:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-28  6:22 [PATCH] perf/test: Skip leader sampling for s390 Thomas Richter
2025-03-01  0:12 ` Namhyung Kim
2025-03-01  0:36   ` Ian Rogers
2025-03-03  5:53     ` Thomas Richter
2025-03-28 18:27       ` Chun-Tse Shao
2025-03-28 20:05         ` Stephane Eranian
  -- strict thread matches above, loose matches on Subject: below --
2025-09-18 21:11 Anubhav Shelat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).