[PATCH v1 3/3] perf bench: Add 'bench sync ticket' subcommand

Yuzhuo Jing posted 3 patches 2 months, 1 week ago
[PATCH v1 3/3] perf bench: Add 'bench sync ticket' subcommand
Posted by Yuzhuo Jing 2 months, 1 week ago
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