[PATCH v1 0/3] perf bench: Add ticket spinlock benchmark

From: Yuzhuo Jing
Date: Tue Jul 29 2025 - 04:14:02 EST


This patch series adds benchmark for the kernel's ticket spinlock
implementation.

This series depends on a preceding patch series that introduces the
'perf bench sync' benchmark infrastructure.
Link: https://lore.kernel.org/lkml/20250729022640.3134066-1-yuzhuo@xxxxxxxxxx/

In a quick test, on a 48C 96T x86 VM, ticket spinlock performs better on
2-6 threads, and qspinlock performs better on 1 thread or >=8 threads.

$ # set 't' variable, and then
$ ./perf bench sync qspinlock -t$t; sleep 1; ./perf bench sync ticket -t$t

'sync/qspinlock' benchmarks:
Lock-unlock latency of 1 threads: 8.5779 ns.
Lock-unlock latency of 2 threads: 187.1022 ns.
...
Lock-unlock latency of 6 threads: 1202.8312 ns.
...
Lock-unlock latency of 8 threads: 1541.566 ns.
Lock-unlock latency of 96 threads: 44140.8765 ns.

'sync/ticket' benchmarks:
Lock-unlock latency of 1 threads: 12.1888 ns.
Lock-unlock latency of 2 threads: 168.1132 ns.
...
Lock-unlock latency of 6 threads: 1033.2760 ns.
....
Lock-unlock latency of 8 threads: 1667.1647 ns.
Lock-unlock latency of 96 threads: 66915.8949 ns.

Yuzhuo Jing (3):
tools: Import atomic_fetch_{and,add,sub}
perf bench: Import ticket_spinlock from kerne
perf bench: Add 'bench sync ticket' subcommand

tools/arch/x86/include/asm/atomic.h | 17 ++++
tools/arch/x86/include/asm/cmpxchg.h | 11 +++
tools/include/asm-generic/atomic-gcc.h | 51 ++++++++++
tools/perf/bench/bench.h | 1 +
tools/perf/bench/include/ticket_spinlock.h | 107 +++++++++++++++++++++
tools/perf/bench/sync.c | 17 ++++
tools/perf/builtin-bench.c | 1 +
tools/perf/check-headers.sh | 3 +
8 files changed, 208 insertions(+)
create mode 100644 tools/perf/bench/include/ticket_spinlock.h

--
2.50.1.487.gc89ff58d15-goog