linux/tools/perf/bench
Breno Leitao b52ba22c70 perf bench: Add --write-size option to sched pipe
The default ping-pong uses sizeof(int) (4 bytes) per iteration, which
exercises only the pipe-buffer merge path and keeps allocation entirely
out of the picture. That makes the bench a useful scheduler / context-
switch latency probe but unable to surface anything from the pipe
page-allocation hot path.

Add a -s/--write-size option that sets the bytes written and read per
ping-pong iteration. The buffer is allocated for each side via struct
thread_data and replaces the on-stack int previously used. The default
remains sizeof(int) so existing invocations are unchanged.

With --write-size set above PAGE_SIZE the bench drives anon_pipe_write()
through alloc_page() (or the bulk pre-alloc, if the relevant patch is
applied), which is what we want when measuring pipe locking and page
allocation work.

The bench is a ping-pong: both sides call write() before read(), so a
single write_size payload must fit entirely in the pipe buffer or both
sides deadlock waiting for the other to drain.

Resize the pipe via F_SETPIPE_SZ to match write_size (skipped at the
sizeof(int) default), and error out cleanly when the request exceeds
/proc/sys/fs/pipe-max-size.

Committer testing:

  ⬢ [acme@toolbx perf-tools-next]$ perf bench sched pipe
  # Running 'sched/pipe' benchmark:
  # Executed 1000000 pipe operations between two processes

     Total time: 0.915 [sec]

       0.915493 usecs/op
        1092307 ops/sec
  ⬢ [acme@toolbx perf-tools-next]$ perf bench sched pipe --write-size 1024
  # Running 'sched/pipe' benchmark:
  # Executed 1000000 pipe operations between two processes

     Total time: 0.891 [sec]

       0.891915 usecs/op
        1121183 ops/sec
  ⬢ [acme@toolbx perf-tools-next]$ perf bench sched pipe --write-size 4096
  # Running 'sched/pipe' benchmark:
  # Executed 1000000 pipe operations between two processes

     Total time: 1.366 [sec]

       1.366073 usecs/op
         732025 ops/sec
  ⬢ [acme@toolbx perf-tools-next]$ strace -e fcntl perf bench sched pipe --write-size 4096
  # Running 'sched/pipe' benchmark:
  fcntl(4, F_SETPIPE_SZ, 4096)            = 4096
  fcntl(6, F_SETPIPE_SZ, 4096)            = 4096
  ^Cstrace: Process 17840 detached

  ⬢ [acme@toolbx perf-tools-next]$ strace -e fcntl perf bench sched pipe --write-size 1024
  # Running 'sched/pipe' benchmark:
  fcntl(4, F_SETPIPE_SZ, 1024)            = 4096
  fcntl(6, F_SETPIPE_SZ, 1024)            = 4096
  ^Cstrace: Process 17845 detached

  ⬢ [acme@toolbx perf-tools-next]$ strace -e fcntl perf bench sched pipe
  # Running 'sched/pipe' benchmark:
  ^Cstrace: Process 17851 detached

  ⬢ [acme@toolbx perf-tools-next]$
  ⬢ [acme@toolbx perf-tools-next]$ perf bench sched pipe --write-size 1048577
  # Running 'sched/pipe' benchmark:
  --write-size 1048577 exceeds /proc/sys/fs/pipe-max-size
  ⬢ [acme@toolbx perf-tools-next]$ cat /proc/sys/fs/pipe-max-size
  1048576
  ⬢ [acme@toolbx perf-tools-next]$
  acme@number:~/git/perf-tools-next$

Signed-off-by: Breno Leitao <leitao@debian.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-06-04 10:11:04 -03:00
..
bpf_skel perf build: Move BPF skeleton generation out of Makefile.perf 2026-05-20 17:46:45 -03:00
bench.h perf bench mem: Add mmap() workloads 2025-09-19 12:43:59 -03:00
breakpoint.c perf tools: Make more global variables static 2026-04-08 19:21:04 -07:00
Build perf build: Move BPF skeleton generation out of Makefile.perf 2026-05-20 17:46:45 -03:00
epoll-ctl.c tools/perf: Fix perf bench epoll to enable the run when some CPU's are offline 2024-06-13 21:27:26 -07:00
epoll-wait.c perf bench: Fix undefined behavior in cmpworker() 2025-01-18 10:14:36 -08:00
evlist-open-close.c perf auxtrace: Remove errno.h from auxtrace.h and fix transitive dependencies 2025-11-13 23:03:11 -08:00
find-bit-bench.c x86/asm: Remove code depending on __GCC_ASM_FLAG_OUTPUTS__ 2025-09-08 15:38:06 +02:00
futex-hash.c perf bench futex: Remove support for IMMUTABLE 2025-07-11 16:02:01 +02:00
futex-lock-pi.c perf bench futex: Remove support for IMMUTABLE 2025-07-11 16:02:01 +02:00
futex-requeue.c perf bench futex: Remove support for IMMUTABLE 2025-07-11 16:02:01 +02:00
futex-wake-parallel.c perf bench futex: Remove support for IMMUTABLE 2025-07-11 16:02:01 +02:00
futex-wake.c perf bench futex: Remove support for IMMUTABLE 2025-07-11 16:02:01 +02:00
futex.c perf auxtrace: Remove errno.h from auxtrace.h and fix transitive dependencies 2025-11-13 23:03:11 -08:00
futex.h perf bench futex: Add missing stdbool.h 2025-10-02 15:08:44 -03:00
inject-buildid.c perf event: Fix size of synthesized sample with branch stacks 2026-05-20 16:11:30 -03:00
kallsyms-parse.c perf bench: Add kallsyms parsing 2020-05-05 16:35:32 -03:00
mem-functions.c perf tools: Make more global variables static 2026-04-08 19:21:04 -07:00
mem-memcpy-arch.h perf bench mem: Pull out init/fini logic 2025-09-19 12:43:01 -03:00
mem-memcpy-x86-64-asm-def.h perf bench mem: Pull out init/fini logic 2025-09-19 12:43:01 -03:00
mem-memcpy-x86-64-asm.S tools headers: Update the copy of x86's mem{cpy,set}_64.S used in 'perf bench' 2023-05-17 10:42:19 -03:00
mem-memset-arch.h perf bench mem: Pull out init/fini logic 2025-09-19 12:43:01 -03:00
mem-memset-x86-64-asm-def.h perf bench mem: Pull out init/fini logic 2025-09-19 12:43:01 -03:00
mem-memset-x86-64-asm.S tools headers: Update the copy of x86's mem{cpy,set}_64.S used in 'perf bench' 2023-05-17 10:42:19 -03:00
numa.c perf tools: Use calloc() where applicable 2026-04-08 19:21:05 -07:00
pmu-scan.c perf auxtrace: Remove errno.h from auxtrace.h and fix transitive dependencies 2025-11-13 23:03:11 -08:00
sched-messaging.c perf tools: Use calloc() where applicable 2026-04-08 19:21:05 -07:00
sched-pipe.c perf bench: Add --write-size option to sched pipe 2026-06-04 10:11:04 -03:00
sched-seccomp-notify.c perf bench sched-seccomp-notify: Fix spelling mistake "synchronious" -> "synchronous" 2023-12-05 15:48:52 -03:00
synthesize.c perf auxtrace: Remove errno.h from auxtrace.h and fix transitive dependencies 2025-11-13 23:03:11 -08:00
syscall.c perf bench: Fix perf bench syscall loop count 2025-03-05 09:19:23 -08:00
uprobe.c perf build: Move BPF skeleton generation out of Makefile.perf 2026-05-20 17:46:45 -03:00