[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250729081256.3433892-4-yuzhuo@google.com>
Date: Tue, 29 Jul 2025 01:12:56 -0700
From: Yuzhuo Jing <yuzhuo@...gle.com>
To: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>, Namhyung Kim <namhyung@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>, Jiri Olsa <jolsa@...nel.org>,
Ian Rogers <irogers@...gle.com>, Adrian Hunter <adrian.hunter@...el.com>,
Liang Kan <kan.liang@...ux.intel.com>, Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>, Albert Ou <aou@...s.berkeley.edu>,
Alexandre Ghiti <alex@...ti.fr>, Yuzhuo Jing <yzj@...ch.edu>, Yuzhuo Jing <yuzhuo@...gle.com>,
Guo Ren <guoren@...nel.org>, Andrea Parri <parri.andrea@...il.com>,
Leonardo Bras <leobras@...hat.com>, linux-kernel@...r.kernel.org,
linux-perf-users@...r.kernel.org, linux-riscv@...ts.infradead.org
Subject: [PATCH v1 3/3] perf bench: Add 'bench sync ticket' subcommand
Benchmark kernel ticket spinlock implementation in user space.
In resolution of arch_spin_* redefinition conflicts due to importing
qspinlock and ticket spinlock together, the sync.c defines
__no_arch_spinlock_redefine, following the usage in
arch/riscv/include/asm/spinlock.h.
Signed-off-by: Yuzhuo Jing <yuzhuo@...gle.com>
---
tools/perf/bench/bench.h | 1 +
tools/perf/bench/sync.c | 17 +++++++++++++++++
tools/perf/builtin-bench.c | 1 +
3 files changed, 19 insertions(+)
diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h
index dd6c8b6126d3..42c0696b05fb 100644
--- a/tools/perf/bench/bench.h
+++ b/tools/perf/bench/bench.h
@@ -23,6 +23,7 @@ int bench_sched_messaging(int argc, const char **argv);
int bench_sched_pipe(int argc, const char **argv);
int bench_sched_seccomp_notify(int argc, const char **argv);
int bench_sync_qspinlock(int argc, const char **argv);
+int bench_sync_ticket(int argc, const char **argv);
int bench_syscall_basic(int argc, const char **argv);
int bench_syscall_getpgid(int argc, const char **argv);
int bench_syscall_fork(int argc, const char **argv);
diff --git a/tools/perf/bench/sync.c b/tools/perf/bench/sync.c
index c85e9853c72a..581835451e5f 100644
--- a/tools/perf/bench/sync.c
+++ b/tools/perf/bench/sync.c
@@ -17,7 +17,9 @@
#include "bench.h"
#include "../util/tsc.h"
+#define __no_arch_spinlock_redefine
#include "include/qspinlock.h"
+#include "include/ticket_spinlock.h"
#define NS 1000000000ull
#define CACHELINE_SIZE 64
@@ -67,6 +69,7 @@ static const struct option options[] = {
static const char *const bench_sync_usage[] = {
"perf bench sync qspinlock <options>",
+ "perf bench sync ticket <options>",
NULL
};
@@ -106,6 +109,20 @@ int bench_sync_qspinlock(int argc, const char **argv)
return bench_sync_lock_generic(&ops, argc, argv);
}
+/*
+ * Benchmark of linux kernel ticket spinlock in user land.
+ */
+int bench_sync_ticket(int argc, const char **argv)
+{
+ arch_spinlock_t lock = __ARCH_SPIN_LOCK_UNLOCKED;
+ struct lock_ops ops = {
+ .lock = (lock_fn)ticket_spin_lock,
+ .unlock = (lock_fn)ticket_spin_unlock,
+ .data = &lock,
+ };
+ return bench_sync_lock_generic(&ops, argc, argv);
+}
+
/*
* A busy loop to acquire and release the given lock N times.
*/
diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c
index cfe6f6dc6ed4..8d945b846321 100644
--- a/tools/perf/builtin-bench.c
+++ b/tools/perf/builtin-bench.c
@@ -54,6 +54,7 @@ static struct bench sched_benchmarks[] = {
static struct bench sync_benchmarks[] = {
{ "qspinlock", "Benchmark for queued spinlock", bench_sync_qspinlock },
+ { "ticket", "Benchmark for ticket spinlock", bench_sync_ticket },
{ "all", "Run all synchronization benchmarks", NULL },
{ NULL, NULL, NULL }
};
--
2.50.1.487.gc89ff58d15-goog
Powered by blists - more mailing lists