linux/tools/perf
Thomas Richter c73a56ed3c perf test: Fix test case Leader sampling on s390
The subtest 'Leader sampling' some time fails on s390.
- for z/VM guest: Disable the test for z/VM guest. There is no
  CPU Measurement facility to run the test successfully.
- for LPAR: Use correct event names.

A detailed analysis follows here:
Now to the debugging and investigation:
1. With command
       perf record -e '{cycles,cycles}:S' -- ....
   the first cycles event starts sampling.
   On s390 this sets up sampling with a frequency of 4000 Hz.
   This translates to hardware sample rate of 1377000 instructions per
   micro-second to meet a frequency of 4000 HZ.

2. With first event cycles now sampling into a hardware buffer, an
   interrupt is triggered each time a sampling buffer gets full.
   The interrupt handler is then invoked and debug output shows the
   processing of samples.  The size of one hardware sample is 32 bytes.
   With an interrupt triggered when the hardware buffer page of 4KB
   gets full, the interrupt handler processes 128 samples.
   (This is taken from s390 specific fast debug data gathering)
   2025-11-07 14:35:51.977248  000003ffe013cbfa \
	   perf_event_count_update event->count 0x0 count 0x1502e8
   2025-11-07 14:35:51.977248  000003ffe013cbfa \
	   perf_event_count_update event->count 0x1502e8 count 0x1502e8
   2025-11-07 14:35:51.977248  000003ffe013cbfa \
	   perf_event_count_update event->count 0x2a05d0 count 0x1502e8
   2025-11-07 14:35:51.977252  000003ffe013cbfa \
	   perf_event_count_update event->count 0x3f08b8 count 0x1502e8
   2025-11-07 14:35:51.977252  000003ffe013cbfa \
	   perf_event_count_update event->count 0x540ba0 count 0x1502e8
   2025-11-07 14:35:51.977253  000003ffe013cbfa \
	   perf_event_count_update event->count 0x690e88 count 0x1502e8
   2025-11-07 14:35:51.977254  000003ffe013cbfa \
	   perf_event_count_update event->count 0x7e1170 count 0x1502e8
   2025-11-07 14:35:51.977254  000003ffe013cbfa \
	   perf_event_count_update event->count 0x931458 count 0x1502e8
   2025-11-07 14:35:51.977254  000003ffe013cbfa \
	   perf_event_count_update event->count 0xa81740 count 0x1502e8

3. The value is constantly increasing by the number of instructions
   executed to generate a sample entry.  This is the first line of the
   pairs of lines. count 0x1502e8 --> 1377000

   # perf script | grep 1377000 | wc -l
   214
   # perf script | wc -l
   428
   #
   That is 428 lines in total, and half of the lines contain value
   1377000.

4. The second event cycles is opened against the counting PMU, which
   is an independent PMU and is not interrupt driven.  Once enabled it
   runs in the background and keeps running, incrementing silently
   about 400+ counters. The counter values are read via assembly
   instructions.

   This second counter PMU's read call back function is called when the
   interrupt handler of the sampling facility processes each sample. The
   function call sequence is:

   perf_event_overflow()
   +--> __perf_event_overflow()
        +--> __perf_event_output()
               +--> perf_output_sample()
                    +--> perf_output_read()
                         +--> perf_output_read_group()
	                          for_each_sibling_event(sub, leader) {
		values[n++] = perf_event_count(sub, self);
		printk("%s sub %p values %#lx\n", __func__, sub, values[n-1]);
			          }

   The last function perf_event_count() is invoked on the second event
   cylces *on* the counting PMU. An added printk statement shows the
   following lines in the dmesg output:

   # dmesg|grep perf_output_read_group |head -10
   [  332.368620] perf_output_read_group sub 00000000d80b7c1f values 0x3a80917 (1)
   [  332.368624] perf_output_read_group sub 00000000d80b7c1f values 0x3a86c7f (2)
   [  332.368627] perf_output_read_group sub 00000000d80b7c1f values 0x3a89c15 (3)
   [  332.368629] perf_output_read_group sub 00000000d80b7c1f values 0x3a8c895 (4)
   [  332.368631] perf_output_read_group sub 00000000d80b7c1f values 0x3a8f569 (5)
   [  332.368633] perf_output_read_group sub 00000000d80b7c1f values 0x3a9204b
   [  332.368635] perf_output_read_group sub 00000000d80b7c1f values 0x3a94790
   [  332.368637] perf_output_read_group sub 00000000d80b7c1f values 0x3a9704b
   [  332.368638] perf_output_read_group sub 00000000d80b7c1f values 0x3a99888
   #

   This correlates with the output of
   # perf report -D | grep 'id 00000000000000'|head -10
   ..... id 0000000000000006, value 00000000001502e8, lost 0
   ..... id 000000000000000e, value 0000000003a80917, lost 0 --> line (1) above
   ..... id 0000000000000006, value 00000000002a05d0, lost 0
   ..... id 000000000000000e, value 0000000003a86c7f, lost 0 --> line (2) above
   ..... id 0000000000000006, value 00000000003f08b8, lost 0
   ..... id 000000000000000e, value 0000000003a89c15, lost 0 --> line (3) above
   ..... id 0000000000000006, value 0000000000540ba0, lost 0
   ..... id 000000000000000e, value 0000000003a8c895, lost 0 --> line (4) above
   ..... id 0000000000000006, value 0000000000690e88, lost 0
   ..... id 000000000000000e, value 0000000003a8f569, lost 0 --> line (5) above

Summary:
- Above command starts the CPU sampling facility, with runs interrupt
  driven when a 4KB page is full. An interrupt processes the 128 samples
  and calls eventually perf_output_read_group() for each sample to save it
  in the event's ring buffer.

- At that time the CPU counting facility is invoked to read the value of
  the event cycles. This value is saved as the second value in the
  sample_read structure.

- The first and odd lines in the perf script output displays the period
  value between 2 samples being created by hardware. It is the number
  of instructions executes before the hardware writes a sample.

- The second and even lines in the perf script output displays the number
  of CPU cycles needed to process each sample and save it in the event's
  ring buffer.
These 2 different values can never be identical on s390.

Since event leader sampling is not possible on s390 the perf tool will
return EOPNOTSUPP soon. Perpare the test case for that.

Suggested-by: James Clark <james.clark@linaro.org>
Reviewed-by: Jan Polensky <japo@linux.ibm.com>
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Tested-by: Jan Polensky <japo@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-02-06 18:40:24 -03:00
..
arch perf regs: Remove __weak attributive arch_sdt_arg_parse_op() function 2026-02-06 12:16:12 -03:00
bench perf tools: Switch printf("...%s", strerror(errno)) to printf("...%m") 2026-01-14 17:22:50 -03:00
check-header_ignore_hunks/lib perf tools: update expected diff for lib/list_sort.c 2024-11-05 17:12:33 -08:00
dlfilters perf tools: Simplify evsel__add_modifier() 2024-10-22 09:52:11 -07:00
Documentation perf sched stats: Fixes in man page 2026-01-28 15:18:41 -03:00
include/perf perf dso: Move build_id to dso_id 2025-07-25 10:37:56 -07:00
jvmti perf tools: Use const for variables receiving str{str,r?chr}() returns 2025-12-17 09:30:37 -03:00
pmu-events perf jevents: Validate that all names given an Event 2026-01-28 15:18:46 -03:00
python perf ilist: Be tolerant of reading a metric on the wrong CPU 2025-12-02 16:12:49 -08:00
scripts perf script: Fix script_fetch_insn for more than just x86 2026-01-27 01:35:22 -03:00
tests perf test: Fix test case Leader sampling on s390 2026-02-06 18:40:24 -03:00
trace tools headers: Sync linux/socket.h with kernel sources 2025-12-24 11:43:29 -08:00
ui perf disasm: Refactor arch__find and initialization of arch structs 2026-01-23 16:58:39 -03:00
util perf annotate: Fix register usage in data type profiling 2026-02-06 18:18:52 -03:00
.gitignore perf jevents: Build support for generating metrics from python 2026-01-28 15:18:44 -03:00
Build perf build: Specify shellcheck should use bash 2025-06-30 09:43:06 -07:00
builtin-annotate.c perf tool: Add the perf_tool argument to all callbacks 2025-11-07 13:25:05 -08:00
builtin-bench.c perf bench mem: Add mmap() workloads 2025-09-19 12:43:59 -03:00
builtin-buildid-cache.c perf symbol: Fix ENOENT case for filename__read_build_id 2025-12-17 07:30:51 -08:00
builtin-buildid-list.c perf machine: Explicitly pass in host perf_env 2025-07-25 10:37:57 -07:00
builtin-c2c.c perf c2c: Clean up some defensive gets and make asan clean 2025-12-03 11:07:46 -08:00
builtin-check.c perf build: Remove NO_AUXTRACE build option 2025-11-13 23:03:11 -08:00
builtin-config.c perf config: Add a function to set one variable in .perfconfig 2025-01-14 15:05:56 -03:00
builtin-daemon.c perf tools: Switch printf("...%s", strerror(errno)) to printf("...%m") 2026-01-14 17:22:50 -03:00
builtin-data.c perf data: Allow filtering conversion by time range 2026-01-06 19:20:02 -03:00
builtin-diff.c perf diff: Constify strchr() return variables 2025-12-17 09:30:37 -03:00
builtin-evlist.c perf tool: Add the perf_tool argument to all callbacks 2025-11-07 13:25:05 -08:00
builtin-ftrace.c perf: ftrace: add graph tracer options args/retval/retval-hex/retaddr 2025-07-22 17:47:22 -07:00
builtin-help.c perf help: Move common_cmds into builtin-help 2026-01-14 17:22:50 -03:00
builtin-inject.c perf inject: With --convert-callchain ignore the dummy event for dwarf stacks 2026-01-23 16:58:39 -03:00
builtin-kallsyms.c perf machine: Explicitly pass in host perf_env 2025-07-25 10:37:57 -07:00
builtin-kmem.c perf session: Add accessor for session->header.env 2025-07-25 10:37:56 -07:00
builtin-kvm.c perf session: Add e_flags to the e_machine helper 2026-02-03 18:01:27 -03:00
builtin-kwork.c perf tools kwork: Add missed memory allocation check and free 2025-10-02 15:30:30 -03:00
builtin-list.c Merge remote-tracking branch 'torvalds/master' into perf-tools-next 2026-01-26 17:03:53 -03:00
builtin-lock.c perf lock: Fix segfault due to missing kernel map 2025-11-13 17:17:41 -03:00
builtin-mem.c perf auxtrace: Remove errno.h from auxtrace.h and fix transitive dependencies 2025-11-13 23:03:11 -08:00
builtin-probe.c perf tools: Switch printf("...%s", strerror(errno)) to printf("...%m") 2026-01-14 17:22:50 -03:00
builtin-record.c perf record: Make logs more readable for event open failures 2026-02-06 11:53:10 -03:00
builtin-report.c perf session: Add e_flags to the e_machine helper 2026-02-03 18:01:27 -03:00
builtin-sched.c perf sched stats: Define macro for SEP_LEN 2026-01-28 15:18:39 -03:00
builtin-script.c perf session: Add e_flags to the e_machine helper 2026-02-03 18:01:27 -03:00
builtin-stat.c perf tools: Switch printf("...%s", strerror(errno)) to printf("...%m") 2026-01-14 17:22:50 -03:00
builtin-timechart.c perf timechart: Add record support for output perf.data path 2025-12-03 11:07:23 -08:00
builtin-top.c perf top: Use evlist__new_default when no events specified 2025-10-15 23:59:11 +09:00
builtin-trace.c perf thread: Add optional e_flags output argument to thread__e_machine 2026-01-26 18:21:20 -03:00
builtin-version.c perf check: Share the feature status printing routine with 'perf version' 2025-04-10 10:44:04 -03:00
builtin.h perf check: Allow showing a tip for opt-in features not built into perf 2025-04-10 10:44:42 -03:00
check-headers.sh tools headers: Don't check arm64's unistd.h 2026-01-26 17:09:31 -03:00
CREDITS
design.txt
Makefile perf tools: Fix wrong message when running "make JOBS=1" 2024-08-01 12:11:33 -03:00
Makefile.config perf kvm stat: Remove use of the arch directory 2026-02-03 18:01:27 -03:00
Makefile.perf perf build: Remove NO_LIBCAP that controls nothing 2026-02-03 11:32:16 -03:00
MANIFEST perf tools: Fix arm64 source package build 2025-05-13 17:26:35 -03:00
perf-archive.sh tools/perf: Add --exclude-buildids option to perf archive command 2025-06-26 15:40:19 -07:00
perf-completion.sh perf build: Add shellcheck to tools/perf scripts 2024-04-12 17:54:02 -03:00
perf-iostat.sh
perf-read-vdso.c
perf-sys.h
perf.c perf tools: Switch printf("...%s", strerror(errno)) to printf("...%m") 2026-01-14 17:22:50 -03:00
perf.h perf: Completely remove possibility to override MAX_NR_CPUS 2025-09-12 10:52:22 -03:00