From: Yuzhuo Jing <yuzhuo@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Liang Kan <kan.liang@linux.intel.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>, Yuzhuo Jing <yzj@umich.edu>,
Yuzhuo Jing <yuzhuo@google.com>, Guo Ren <guoren@kernel.org>,
Andrea Parri <parri.andrea@gmail.com>,
Leonardo Bras <leobras@redhat.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
linux-riscv@lists.infradead.org
Subject: [PATCH v1 3/3] perf bench: Add 'bench sync ticket' subcommand
Date: Tue, 29 Jul 2025 01:12:56 -0700 [thread overview]
Message-ID: <20250729081256.3433892-4-yuzhuo@google.com> (raw)
In-Reply-To: <20250729081256.3433892-1-yuzhuo@google.com>
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@google.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
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
prev parent reply other threads:[~2025-07-29 8:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-29 8:12 [PATCH v1 0/3] perf bench: Add ticket spinlock benchmark Yuzhuo Jing
2025-07-29 8:12 ` [PATCH v1 1/3] tools: Import atomic_fetch_{and,add,sub} Yuzhuo Jing
2025-07-29 8:12 ` [PATCH v1 2/3] perf bench: Import ticket_spinlock from kerne Yuzhuo Jing
2025-07-29 8:12 ` Yuzhuo Jing [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250729081256.3433892-4-yuzhuo@google.com \
--to=yuzhuo@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alex@ghiti.fr \
--cc=alexander.shishkin@linux.intel.com \
--cc=aou@eecs.berkeley.edu \
--cc=guoren@kernel.org \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=leobras@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=palmer@dabbelt.com \
--cc=parri.andrea@gmail.com \
--cc=paul.walmsley@sifive.com \
--cc=peterz@infradead.org \
--cc=yzj@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox