Skip to contentSkip to conversation

perf-bench: introduce futex microbenchmarks

PATCH In review Davidlohr Bueso 6 participants 14 messages Dec 15, 2013 – Mar 18, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover perf-bench: introduce futex microbenchmarks

This patchset adds three programs that stress and measure different futex
operations: (i) uaddr hashing, (ii) wakeups and (iii) requeuing/waiting.

More details and usage examples in each individual patch, along with parameter descriptions in the code.

While the previous effort (https://lkml.org/lkml/2012/5/17/207) to add futex benchmarks to perf-bench failed, I strongly believe that perf is an ideal place for these kinds of programs. This patchset is different from Hitoshi's because it does not try to take over Darren's futextest suite, and only deals with finer grained aspects of the kernel's implementation, and thus mostly useful for kernel hacking. Furthermore, by being part of the kernel tree, it can get more attention and naturally evolve with time.

Thanks!

Davidlohr Bueso (3):
perf-bench: add futex-hash microbenchmark
perf-bench: add futex-wake microbenchmark
perf-bench: add futex-requeue microbenchmark

 tools/perf/Makefile.perf         |   3 +
 tools/perf/bench/bench.h         |   3 +
 tools/perf/bench/futex-hash.c    | 212 +++++++++++++++++++++++++++++++++++++++
 tools/perf/bench/futex-requeue.c | 211 ++++++++++++++++++++++++++++++++++++++
 tools/perf/bench/futex-wake.c    | 201 +++++++++++++++++++++++++++++++++++++
 tools/perf/bench/futex.h         |  71 +++++++++++++
 tools/perf/builtin-bench.c       |  12 ++-
 tools/perf/perf.h                |   6 ++
 8 files changed, 718 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/bench/futex-hash.c
 create mode 100644 tools/perf/bench/futex-requeue.c
 create mode 100644 tools/perf/bench/futex-wake.c
 create mode 100644 tools/perf/bench/futex.h
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 1/3 perf-bench: add futex-hash microbenchmark

Introduce futexes to perf-bench and add a program that stresses and measures the kernel's implementation of the hash table. This is a multi-threaded program that simply measures the amount of failed futex wait calls - we only want to deal with the hashing overhead, so a negative return of futex_wait_setup() is enough to do the trick. An example run:

$ perf bench futex hash -t 32
Run summary [PID 10989]: 32 threads, each operating on 1024 [private] futexes for 10 secs.
[thread  0] futexes: 0x19d9b10 ... 0x19dab0c [ 418713 ops/sec ]
[thread  1] futexes: 0x19daca0 ... 0x19dbc9c [ 469913 ops/sec ]
[thread  2] futexes: 0x19dbe30 ... 0x19dce2c [ 479744 ops/sec ]

...
[thread 31] futexes: 0x19fbb80 ... 0x19fcb7c [ 464179 ops/sec ]

Averaged 454310 operations/sec (+- 0.84%), total secs = 10

---
 tools/perf/Makefile.perf      |   1 +
 tools/perf/bench/bench.h      |   1 +
 tools/perf/bench/futex-hash.c | 212 ++++++++++++++++++++++++++++++++++++++++++
 tools/perf/bench/futex.h      |  48 ++++++++++
 tools/perf/builtin-bench.c    |  10 +-
 tools/perf/perf.h             |   6 ++
 6 files changed, 277 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/bench/futex-hash.c
 create mode 100644 tools/perf/bench/futex.h
tools/perf/Makefile.perf +1 -0
index 7fc8f17..c38cba4 100644
@@ -416,6 +416,7 @@ BUILTIN_OBJS += $(OUTPUT)bench/mem-memset-x86-64-asm.o
 endif
 BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o
 BUILTIN_OBJS += $(OUTPUT)bench/mem-memset.o
+BUILTIN_OBJS += $(OUTPUT)bench/futex-hash.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-diff.o
 BUILTIN_OBJS += $(OUTPUT)builtin-evlist.o
tools/perf/bench/bench.h +1 -0
index 0fdc852..34edb5c 100644
@@ -31,6 +31,7 @@ extern int bench_sched_pipe(int argc, const char **argv, const char *prefix);
 extern int bench_mem_memcpy(int argc, const char **argv,
 			    const char *prefix __maybe_unused);
 extern int bench_mem_memset(int argc, const char **argv, const char *prefix);
+extern int bench_futex_hash(int argc, const char **argv, const char *prefix);
 
 #define BENCH_FORMAT_DEFAULT_STR	"default"
 #define BENCH_FORMAT_DEFAULT		0
tools/perf/bench/futex-hash.c new file +212 -0

212 lines not on this page · raw message

tools/perf/bench/futex.h new file +48 -0

48 lines not on this page · raw message

tools/perf/builtin-bench.c +9 -1
index e47f90c..a8b0138 100644
@@ -12,6 +12,7 @@
  *  sched ... scheduler and IPC performance
  *  mem   ... memory access performance
  *  numa  ... NUMA scheduling and MM performance
+ *  futex ... Futex performance
  */
 #include "perf.h"
 #include "util/util.h"
@@ -54,6 +55,12 @@ static struct bench mem_benchmarks[] = {
 	{ NULL,		NULL,						NULL			}
 };
 
+static struct bench futex_benchmarks[] = {
+	{ "hash",	"Benchmark for futex hash table",               bench_futex_hash	},
+	{ "all",	"Test all futex benchmarks",			NULL			},
+	{ NULL,		NULL,						NULL			}
+};
+
 struct collection {
 	const char	*name;
 	const char	*summary;
@@ -61,11 +68,12 @@ struct collection {
 };
 
 static struct collection collections[] = {
-	{ "sched",	"Scheduler and IPC benchmarks",		sched_benchmarks	},
+	{ "sched",	"Scheduler and IPC benchmarks",			sched_benchmarks	},
 	{ "mem",	"Memory access benchmarks",			mem_benchmarks		},
 #ifdef HAVE_LIBNUMA_SUPPORT
 	{ "numa",	"NUMA scheduling and MM benchmarks",		numa_benchmarks		},
 #endif
+	{"futex",       "Futex stressing benchmarks",                   futex_benchmarks        },
 	{ "all",	"All benchmarks",				NULL			},
 	{ NULL,		NULL,						NULL			}
 };
tools/perf/perf.h +6 -0
index b079304..e97caee 100644
@@ -12,6 +12,9 @@
 #ifndef __NR_perf_event_open
 # define __NR_perf_event_open 336
 #endif
+#ifndef __NR_futex
+# define __NR_futex 240
+#endif
 #endif
 
 #if defined(__x86_64__)
@@ -23,6 +26,9 @@
 #ifndef __NR_perf_event_open
 # define __NR_perf_event_open 298
 #endif
+#ifndef __NR_futex
+# define __NR_futex 202
+#endif
 #endif
 
 #ifdef __powerpc__
Signature · 1 line
1.8.1.4
#2 lore raw

[tip:perf/core] perf bench: Add futex-hash microbenchmark

perf bench: Add futex-hash microbenchmark
Commit-ID:  a043971141f163f9845324a2f83502d15011485d
Gitweb:     http://git.kernel.org/tip/a043971141f163f9845324a2f83502d15011485d
Author:     Davidlohr Bueso <[email protected]>
AuthorDate: Sat, 14 Dec 2013 20:31:55 -0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 14 Mar 2014 11:20:43 -0300

perf bench: Add futex-hash microbenchmark

Introduce futexes to perf-bench and add a program that stresses and measures the kernel's implementation of the hash table.

This is a multi-threaded program that simply measures the amount of failed futex wait calls - we only want to deal with the hashing overhead, so a negative return of futex_wait_setup() is enough to do the trick.

An example run:

  $ perf bench futex hash -t 32
  Run summary [PID 10989]: 32 threads, each operating on 1024 [private] futexes for 10 secs.
  [thread  0] futexes: 0x19d9b10 ... 0x19dab0c [ 418713 ops/sec ]
  [thread  1] futexes: 0x19daca0 ... 0x19dbc9c [ 469913 ops/sec ]
  [thread  2] futexes: 0x19dbe30 ... 0x19dce2c [ 479744 ops/sec ]

...
[thread 31] futexes: 0x19fbb80 ... 0x19fcb7c [ 464179 ops/sec ]

Averaged 454310 operations/sec (+- 0.84%), total secs = 10

---
 tools/perf/Makefile.perf      |   1 +
 tools/perf/bench/bench.h      |   1 +
 tools/perf/bench/futex-hash.c | 212 ++++++++++++++++++++++++++++++++++++++++++
 tools/perf/bench/futex.h      |  48 ++++++++++
 tools/perf/builtin-bench.c    |  10 +-
 tools/perf/perf.h             |   6 ++
 6 files changed, 277 insertions(+), 1 deletion(-)
tools/perf/Makefile.perf +1 -0
index 1f7ec48..54ae547 100644
@@ -426,6 +426,7 @@ BUILTIN_OBJS += $(OUTPUT)bench/mem-memset-x86-64-asm.o
 endif
 BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o
 BUILTIN_OBJS += $(OUTPUT)bench/mem-memset.o
+BUILTIN_OBJS += $(OUTPUT)bench/futex-hash.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-diff.o
 BUILTIN_OBJS += $(OUTPUT)builtin-evlist.o
tools/perf/bench/bench.h +1 -0
index 0fdc852..34edb5c 100644
@@ -31,6 +31,7 @@ extern int bench_sched_pipe(int argc, const char **argv, const char *prefix);
 extern int bench_mem_memcpy(int argc, const char **argv,
 			    const char *prefix __maybe_unused);
 extern int bench_mem_memset(int argc, const char **argv, const char *prefix);
+extern int bench_futex_hash(int argc, const char **argv, const char *prefix);
 
 #define BENCH_FORMAT_DEFAULT_STR	"default"
 #define BENCH_FORMAT_DEFAULT		0
tools/perf/bench/futex-hash.c new file +212 -0

212 lines not on this page · raw message

tools/perf/bench/futex.h new file +48 -0

48 lines not on this page · raw message

tools/perf/builtin-bench.c +9 -1
index e47f90c..a8b0138 100644
@@ -12,6 +12,7 @@
  *  sched ... scheduler and IPC performance
  *  mem   ... memory access performance
  *  numa  ... NUMA scheduling and MM performance
+ *  futex ... Futex performance
  */
 #include "perf.h"
 #include "util/util.h"
@@ -54,6 +55,12 @@ static struct bench mem_benchmarks[] = {
 	{ NULL,		NULL,						NULL			}
 };
 
+static struct bench futex_benchmarks[] = {
+	{ "hash",	"Benchmark for futex hash table",               bench_futex_hash	},
+	{ "all",	"Test all futex benchmarks",			NULL			},
+	{ NULL,		NULL,						NULL			}
+};
+
 struct collection {
 	const char	*name;
 	const char	*summary;
@@ -61,11 +68,12 @@ struct collection {
 };
 
 static struct collection collections[] = {
-	{ "sched",	"Scheduler and IPC benchmarks",		sched_benchmarks	},
+	{ "sched",	"Scheduler and IPC benchmarks",			sched_benchmarks	},
 	{ "mem",	"Memory access benchmarks",			mem_benchmarks		},
 #ifdef HAVE_LIBNUMA_SUPPORT
 	{ "numa",	"NUMA scheduling and MM benchmarks",		numa_benchmarks		},
 #endif
+	{"futex",       "Futex stressing benchmarks",                   futex_benchmarks        },
 	{ "all",	"All benchmarks",				NULL			},
 	{ NULL,		NULL,						NULL			}
 };
tools/perf/perf.h +6 -0
index 6898ad0..e18a8b5 100644
@@ -12,6 +12,9 @@
 #ifndef __NR_perf_event_open
 # define __NR_perf_event_open 336
 #endif
+#ifndef __NR_futex
+# define __NR_futex 240
+#endif
 #endif
 
 #if defined(__x86_64__)
@@ -23,6 +26,9 @@
 #ifndef __NR_perf_event_open
 # define __NR_perf_event_open 298
 #endif
+#ifndef __NR_futex
+# define __NR_futex 202
+#endif
 #endif
 
 #ifdef __powerpc__
#3 lore raw

PATCH 2/3 perf-bench: add futex-wake microbenchmark

In reply to Davidlohr Bueso

Block a bunch of threads on a futex and wake them up, N at a time.

This program is particularly useful to measure the latency of nthread wakeups in non-error situations: all waiters are queued and all wake calls wakeup one or more tasks. An example run:

$ perf bench futex -t 512 -r 100
Run summary [PID 27823]: blocking on 512 threads (at futex 0x7e10d4), waking up 1 at a time.

[Run 1]: Wokeup 512 of 512 threads in 6.0080 ms
[Run 2]: Wokeup 512 of 512 threads in 5.2280 ms
[Run 3]: Wokeup 512 of 512 threads in 4.8300 ms
...
[Run 100]: Wokeup 512 of 512 threads in 5.0100 ms
Wokeup 512 of 512 threads in 5.0109 ms (+-2.25%)

---
 tools/perf/Makefile.perf      |   1 +
 tools/perf/bench/bench.h      |   1 +
 tools/perf/bench/futex-wake.c | 201 ++++++++++++++++++++++++++++++++++++++++++
 tools/perf/bench/futex.h      |  10 +++
 tools/perf/builtin-bench.c    |   1 +
 5 files changed, 214 insertions(+)
 create mode 100644 tools/perf/bench/futex-wake.c
tools/perf/Makefile.perf +1 -0
index c38cba4..f2e3536 100644
@@ -417,6 +417,7 @@ endif
 BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o
 BUILTIN_OBJS += $(OUTPUT)bench/mem-memset.o
 BUILTIN_OBJS += $(OUTPUT)bench/futex-hash.o
+BUILTIN_OBJS += $(OUTPUT)bench/futex-wake.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-diff.o
 BUILTIN_OBJS += $(OUTPUT)builtin-evlist.o
tools/perf/bench/bench.h +1 -0
index 34edb5c..6ac3f1d 100644
@@ -32,6 +32,7 @@ extern int bench_mem_memcpy(int argc, const char **argv,
 			    const char *prefix __maybe_unused);
 extern int bench_mem_memset(int argc, const char **argv, const char *prefix);
 extern int bench_futex_hash(int argc, const char **argv, const char *prefix);
+extern int bench_futex_wake(int argc, const char **argv, const char *prefix);
 
 #define BENCH_FORMAT_DEFAULT_STR	"default"
 #define BENCH_FORMAT_DEFAULT		0
tools/perf/bench/futex-wake.c new file +201 -0

201 lines not on this page · raw message

tools/perf/bench/futex.h +10 -0
index 7d0bda5..6ac4509 100644
@@ -45,4 +45,14 @@ futex_wait(u_int32_t *uaddr, u_int32_t val, struct timespec *timeout, int opflag
 	return futex(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags);
 }
 
+/**
+ * futex_wake() - wake one or more tasks blocked on uaddr
+ * @nr_wake:	wake up to this many tasks
+ */
+static inline int
+futex_wake(u_int32_t *uaddr, int nr_wake, int opflags)
+{
+	return futex(uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, opflags);
+}
+
 #endif /* _FUTEX_H */
tools/perf/builtin-bench.c +1 -0
index a8b0138..743a30a 100644
@@ -57,6 +57,7 @@ static struct bench mem_benchmarks[] = {
 
 static struct bench futex_benchmarks[] = {
 	{ "hash",	"Benchmark for futex hash table",               bench_futex_hash	},
+	{ "wake",	"Benchmark for futex wake calls",               bench_futex_wake	},
 	{ "all",	"Test all futex benchmarks",			NULL			},
 	{ NULL,		NULL,						NULL			}
 };
Signature · 1 line
1.8.1.4
maintainer
#4 lore raw

Re: [PATCH 2/3] perf-bench: add futex-wake microbenchmark

Hi Davidlohr,

Quoted 7 lines · Davidlohr Bueso

Block a bunch of threads on a futex and wake them up, N at a time.

This program is particularly useful to measure the latency of nthread wakeups in non-error situations: all waiters are queued and all wake calls wakeup one or more tasks. An example run:

$ perf bench futex -t 512 -r 100

Did you mean 'perf bench futex wake'?

Thanks,
Namhyung

#5 lore raw

Re: [PATCH 2/3] perf-bench: add futex-wake microbenchmark

Quoted 5 lines · Namhyung Kim

Hi Davidlohr,

Quoted 2 lines · Davidlohr Bueso

Block a bunch of threads on a futex and wake them up, N at a time.

Quoted 7 lines
Quoted 5 lines

This program is particularly useful to measure the latency of nthread wakeups in non-error situations: all waiters are queued and all wake calls wakeup one or more tasks. An example run:

$ perf bench futex -t 512 -r 100

Did you mean 'perf bench futex wake'?

Yes I did.

Thanks,
Davidlohr

#6 lore raw

[tip:perf/core] perf bench: Add futex-wake microbenchmark

In reply to Davidlohr Bueso
perf bench: Add futex-wake microbenchmark
Commit-ID:  27db78307481dbba68c5f3563c6cb694b25521d9
Gitweb:     http://git.kernel.org/tip/27db78307481dbba68c5f3563c6cb694b25521d9
Author:     Davidlohr Bueso <[email protected]>
AuthorDate: Sat, 14 Dec 2013 20:31:56 -0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 14 Mar 2014 11:20:43 -0300

perf bench: Add futex-wake microbenchmark

Block a bunch of threads on a futex and wake them up, N at a time.

This program is particularly useful to measure the latency of nthread wakeups in non-error situations: all waiters are queued and all wake calls wakeup one or more tasks.

An example run:

  $ perf bench futex wake -t 512 -r 100
  Run summary [PID 27823]: blocking on 512 threads (at futex 0x7e10d4), waking up 1 at a time.

[Run 1]: Wokeup 512 of 512 threads in 6.0080 ms [Run 2]: Wokeup 512 of 512 threads in 5.2280 ms [Run 3]: Wokeup 512 of 512 threads in 4.8300 ms
...
[Run 100]: Wokeup 512 of 512 threads in 5.0100 ms Wokeup 512 of 512 threads in 5.0109 ms (+-2.25%)

---
 tools/perf/Makefile.perf      |   1 +
 tools/perf/bench/bench.h      |   1 +
 tools/perf/bench/futex-wake.c | 201 ++++++++++++++++++++++++++++++++++++++++++
 tools/perf/bench/futex.h      |  10 +++
 tools/perf/builtin-bench.c    |   1 +
 5 files changed, 214 insertions(+)
tools/perf/Makefile.perf +1 -0
index 54ae547..6fa5d8b 100644
@@ -427,6 +427,7 @@ endif
 BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o
 BUILTIN_OBJS += $(OUTPUT)bench/mem-memset.o
 BUILTIN_OBJS += $(OUTPUT)bench/futex-hash.o
+BUILTIN_OBJS += $(OUTPUT)bench/futex-wake.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-diff.o
 BUILTIN_OBJS += $(OUTPUT)builtin-evlist.o
tools/perf/bench/bench.h +1 -0
index 34edb5c..6ac3f1d 100644
@@ -32,6 +32,7 @@ extern int bench_mem_memcpy(int argc, const char **argv,
 			    const char *prefix __maybe_unused);
 extern int bench_mem_memset(int argc, const char **argv, const char *prefix);
 extern int bench_futex_hash(int argc, const char **argv, const char *prefix);
+extern int bench_futex_wake(int argc, const char **argv, const char *prefix);
 
 #define BENCH_FORMAT_DEFAULT_STR	"default"
 #define BENCH_FORMAT_DEFAULT		0
tools/perf/bench/futex-wake.c new file +201 -0

201 lines not on this page · raw message

tools/perf/bench/futex.h +10 -0
index 7d0bda5..6ac4509 100644
@@ -45,4 +45,14 @@ futex_wait(u_int32_t *uaddr, u_int32_t val, struct timespec *timeout, int opflag
 	return futex(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags);
 }
 
+/**
+ * futex_wake() - wake one or more tasks blocked on uaddr
+ * @nr_wake:	wake up to this many tasks
+ */
+static inline int
+futex_wake(u_int32_t *uaddr, int nr_wake, int opflags)
+{
+	return futex(uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, opflags);
+}
+
 #endif /* _FUTEX_H */
tools/perf/builtin-bench.c +1 -0
index a8b0138..743a30a 100644
@@ -57,6 +57,7 @@ static struct bench mem_benchmarks[] = {
 
 static struct bench futex_benchmarks[] = {
 	{ "hash",	"Benchmark for futex hash table",               bench_futex_hash	},
+	{ "wake",	"Benchmark for futex wake calls",               bench_futex_wake	},
 	{ "all",	"Test all futex benchmarks",			NULL			},
 	{ NULL,		NULL,						NULL			}
 };
#7 lore raw

PATCH 3/3 perf-bench: add futex-requeue microbenchmark

In reply to Davidlohr Bueso

Block a bunch of threads on a futex and requeue them on another, N at a time.

This program is particularly useful to measure the latency of nthread requeues without waking up any tasks -- thus mimicking a regular futex_wait. An example run:

$ perf bench futex requeue -r 100 -t 64
Run summary [PID 151011]: Requeuing 64 threads (from 0x7d15c4 to 0x7d15c8), 1 at a time.

[Run 1]: Requeued 64 of 64 threads in 0.0400 ms
[Run 2]: Requeued 64 of 64 threads in 0.0390 ms
[Run 3]: Requeued 64 of 64 threads in 0.0400 ms
...
[Run 100]: Requeued 64 of 64 threads in 0.0390 ms
Requeued 64 of 64 threads in 0.0399 ms (+-0.37%)

---
 tools/perf/Makefile.perf         |   1 +
 tools/perf/bench/bench.h         |   1 +
 tools/perf/bench/futex-requeue.c | 211 +++++++++++++++++++++++++++++++++++++++
 tools/perf/bench/futex.h         |  13 +++
 tools/perf/builtin-bench.c       |   1 +
 5 files changed, 227 insertions(+)
 create mode 100644 tools/perf/bench/futex-requeue.c
tools/perf/Makefile.perf +1 -0
index f2e3536..9dd2c19 100644
@@ -418,6 +418,7 @@ BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o
 BUILTIN_OBJS += $(OUTPUT)bench/mem-memset.o
 BUILTIN_OBJS += $(OUTPUT)bench/futex-hash.o
 BUILTIN_OBJS += $(OUTPUT)bench/futex-wake.o
+BUILTIN_OBJS += $(OUTPUT)bench/futex-requeue.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-diff.o
 BUILTIN_OBJS += $(OUTPUT)builtin-evlist.o
tools/perf/bench/bench.h +1 -0
index 6ac3f1d..eba4670 100644
@@ -33,6 +33,7 @@ extern int bench_mem_memcpy(int argc, const char **argv,
 extern int bench_mem_memset(int argc, const char **argv, const char *prefix);
 extern int bench_futex_hash(int argc, const char **argv, const char *prefix);
 extern int bench_futex_wake(int argc, const char **argv, const char *prefix);
+extern int bench_futex_requeue(int argc, const char **argv, const char *prefix);
 
 #define BENCH_FORMAT_DEFAULT_STR	"default"
 #define BENCH_FORMAT_DEFAULT		0
tools/perf/bench/futex-requeue.c new file +211 -0

211 lines not on this page · raw message

tools/perf/bench/futex.h +13 -0
index 6ac4509..71f2844 100644
@@ -55,4 +55,17 @@ futex_wake(u_int32_t *uaddr, int nr_wake, int opflags)
 	return futex(uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, opflags);
 }
 
+/**
+* futex_cmp_requeue() - requeue tasks from uaddr to uaddr2
+* @nr_wake:        wake up to this many tasks
+* @nr_requeue:        requeue up to this many tasks
+*/
+static inline int
+futex_cmp_requeue(u_int32_t *uaddr, u_int32_t val, u_int32_t *uaddr2, int nr_wake,
+		 int nr_requeue, int opflags)
+{
+	return futex(uaddr, FUTEX_CMP_REQUEUE, nr_wake, nr_requeue, uaddr2,
+		 val, opflags);
+}
+
 #endif /* _FUTEX_H */
tools/perf/builtin-bench.c +1 -0
index 743a30a..f600b74 100644
@@ -58,6 +58,7 @@ static struct bench mem_benchmarks[] = {
 static struct bench futex_benchmarks[] = {
 	{ "hash",	"Benchmark for futex hash table",               bench_futex_hash	},
 	{ "wake",	"Benchmark for futex wake calls",               bench_futex_wake	},
+	{ "requeue",	"Benchmark for futex requeue calls",            bench_futex_requeue	},
 	{ "all",	"Test all futex benchmarks",			NULL			},
 	{ NULL,		NULL,						NULL			}
 };
Signature · 1 line
1.8.1.4
#8 lore raw

[tip:perf/core] perf bench: Add futex-requeue microbenchmark

perf bench: Add futex-requeue microbenchmark
Commit-ID:  0fb298cf95c0d8119557b7d4657724a146e0622e
Gitweb:     http://git.kernel.org/tip/0fb298cf95c0d8119557b7d4657724a146e0622e
Author:     Davidlohr Bueso <[email protected]>
AuthorDate: Sat, 14 Dec 2013 20:31:57 -0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 14 Mar 2014 11:20:44 -0300

perf bench: Add futex-requeue microbenchmark

Block a bunch of threads on a futex and requeue them on another, N at a time.

This program is particularly useful to measure the latency of nthread requeues without waking up any tasks -- thus mimicking a regular futex_wait.

An example run:

  $ perf bench futex requeue -r 100 -t 64
  Run summary [PID 151011]: Requeuing 64 threads (from 0x7d15c4 to 0x7d15c8), 1 at a time.

[Run 1]: Requeued 64 of 64 threads in 0.0400 ms [Run 2]: Requeued 64 of 64 threads in 0.0390 ms [Run 3]: Requeued 64 of 64 threads in 0.0400 ms
...
[Run 100]: Requeued 64 of 64 threads in 0.0390 ms Requeued 64 of 64 threads in 0.0399 ms (+-0.37%)

---
 tools/perf/Makefile.perf                           |   1 +
 tools/perf/bench/bench.h                           |   1 +
 tools/perf/bench/{futex-wake.c => futex-requeue.c} | 108 +++++++++++----------
 tools/perf/bench/futex.h                           |  13 +++
 tools/perf/builtin-bench.c                         |   1 +
 5 files changed, 75 insertions(+), 49 deletions(-)
tools/perf/Makefile.perf +1 -0
index 6fa5d8b..50d875d 100644
@@ -428,6 +428,7 @@ BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o
 BUILTIN_OBJS += $(OUTPUT)bench/mem-memset.o
 BUILTIN_OBJS += $(OUTPUT)bench/futex-hash.o
 BUILTIN_OBJS += $(OUTPUT)bench/futex-wake.o
+BUILTIN_OBJS += $(OUTPUT)bench/futex-requeue.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-diff.o
 BUILTIN_OBJS += $(OUTPUT)builtin-evlist.o
tools/perf/bench/bench.h +1 -0
index 6ac3f1d..eba4670 100644
@@ -33,6 +33,7 @@ extern int bench_mem_memcpy(int argc, const char **argv,
 extern int bench_mem_memset(int argc, const char **argv, const char *prefix);
 extern int bench_futex_hash(int argc, const char **argv, const char *prefix);
 extern int bench_futex_wake(int argc, const char **argv, const char *prefix);
+extern int bench_futex_requeue(int argc, const char **argv, const char *prefix);
 
 #define BENCH_FORMAT_DEFAULT_STR	"default"
 #define BENCH_FORMAT_DEFAULT		0
tools/perf/bench/futex-requeue.c renamed from tools/perf/bench/futex-wake.c +59 -49

192 lines not on this page · raw message

tools/perf/bench/futex.h +13 -0
index 6ac4509..71f2844 100644
@@ -55,4 +55,17 @@ futex_wake(u_int32_t *uaddr, int nr_wake, int opflags)
 	return futex(uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, opflags);
 }
 
+/**
+* futex_cmp_requeue() - requeue tasks from uaddr to uaddr2
+* @nr_wake:        wake up to this many tasks
+* @nr_requeue:        requeue up to this many tasks
+*/
+static inline int
+futex_cmp_requeue(u_int32_t *uaddr, u_int32_t val, u_int32_t *uaddr2, int nr_wake,
+		 int nr_requeue, int opflags)
+{
+	return futex(uaddr, FUTEX_CMP_REQUEUE, nr_wake, nr_requeue, uaddr2,
+		 val, opflags);
+}
+
 #endif /* _FUTEX_H */
tools/perf/builtin-bench.c +1 -0
index 743a30a..f600b74 100644
@@ -58,6 +58,7 @@ static struct bench mem_benchmarks[] = {
 static struct bench futex_benchmarks[] = {
 	{ "hash",	"Benchmark for futex hash table",               bench_futex_hash	},
 	{ "wake",	"Benchmark for futex wake calls",               bench_futex_wake	},
+	{ "requeue",	"Benchmark for futex requeue calls",            bench_futex_requeue	},
 	{ "all",	"Test all futex benchmarks",			NULL			},
 	{ NULL,		NULL,						NULL			}
 };
#9 lore raw
In reply to Davidlohr Bueso
Quoted 7 lines · Davidlohr Bueso

This patchset adds three programs that stress and measure different futex operations: (i) uaddr hashing, (ii) wakeups and (iii) requeuing/waiting.

More details and usage examples in each individual patch, along with parameter descriptions in the code.

Quoted 8 lines

While the previous effort (https://lkml.org/lkml/2012/5/17/207) to add futex benchmarks to perf-bench failed, I strongly believe that perf is an ideal place for these kinds of programs. This patchset is different from Hitoshi's because it does not try to take over Darren's futextest suite, and only deals with finer grained aspects of the kernel's implementation, and thus mostly useful for kernel hacking. Furthermore, by being part of the kernel tree, it can get more attention and naturally evolve with time.

Looks pretty useful!

Could the two approaches be merged?

Thanks,

Ingo

#10 lore raw
Quoted 18 lines · Ingo Molnar
Quoted 7 lines · Davidlohr Bueso

This patchset adds three programs that stress and measure different futex operations: (i) uaddr hashing, (ii) wakeups and (iii) requeuing/waiting.

More details and usage examples in each individual patch, along with parameter descriptions in the code.

Quoted 8 lines

While the previous effort (https://lkml.org/lkml/2012/5/17/207) to add futex benchmarks to perf-bench failed, I strongly believe that perf is an ideal place for these kinds of programs. This patchset is different from Hitoshi's because it does not try to take over Darren's futextest suite, and only deals with finer grained aspects of the kernel's implementation, and thus mostly useful for kernel hacking. Furthermore, by being part of the kernel tree, it can get more attention and naturally evolve with time.

Quoted 3 lines

Looks pretty useful!

Could the two approaches be merged?

Unless Darren doesn't want to, I don't see why not. I can resurrect Hitoshi's original patch if/after this series is applied.

Thanks,
Davidlohr

#11 lore raw
Quoted 19 lines · Davidlohr Bueso
Quoted 18 lines · Ingo Molnar
Quoted 15 lines · Davidlohr Bueso

This patchset adds three programs that stress and measure different futex operations: (i) uaddr hashing, (ii) wakeups and (iii) requeuing/waiting.

More details and usage examples in each individual patch, along with parameter descriptions in the code.

While the previous effort (https://lkml.org/lkml/2012/5/17/207) to add futex benchmarks to perf-bench failed, I strongly believe that perf is an ideal place for these kinds of programs. This patchset is different from Hitoshi's because it does not try to take over Darren's futextest suite, and only deals with finer grained aspects of the kernel's implementation, and thus mostly useful for kernel hacking. Furthermore, by being part of the kernel tree, it can get more attention and naturally evolve with time.

Quoted 6 lines
Quoted 3 lines

Looks pretty useful!

Could the two approaches be merged?

Unless Darren doesn't want to, I don't see why not. I can resurrect Hitoshi's original patch if/after this series is applied.

Apologies, I only am just now seeing this.

I agree that we should take whatever makes sense for perf out of futex-test and merge it with perf. It will see greater use and receive more review and improvements than it will in my obscure repository.

With trinity covering the fuzz testing and perf handling performance tests, I think futex-test can be reduced down to a functional test-suite, which is perfectly fine with me.

If there is still interest here, I'll support it.

Thanks,

Darren

#12 lore raw
Quoted 33 lines · Darren Hart
Quoted 19 lines · Davidlohr Bueso
Quoted 18 lines · Ingo Molnar
Quoted 15 lines · Davidlohr Bueso

This patchset adds three programs that stress and measure different futex operations: (i) uaddr hashing, (ii) wakeups and (iii) requeuing/waiting.

More details and usage examples in each individual patch, along with parameter descriptions in the code.

While the previous effort (https://lkml.org/lkml/2012/5/17/207) to add futex benchmarks to perf-bench failed, I strongly believe that perf is an ideal place for these kinds of programs. This patchset is different from Hitoshi's because it does not try to take over Darren's futextest suite, and only deals with finer grained aspects of the kernel's implementation, and thus mostly useful for kernel hacking. Furthermore, by being part of the kernel tree, it can get more attention and naturally evolve with time.

Quoted 6 lines
Quoted 3 lines

Looks pretty useful!

Could the two approaches be merged?

Unless Darren doesn't want to, I don't see why not. I can resurrect Hitoshi's original patch if/after this series is applied.

Apologies, I only am just now seeing this.

I agree that we should take whatever makes sense for perf out of futex-test and merge it with perf. It will see greater use and receive more review and improvements than it will in my obscure repository.

Quoted 5 lines

With trinity covering the fuzz testing and perf handling performance tests, I think futex-test can be reduced down to a functional test-suite, which is perfectly fine with me.

If there is still interest here, I'll support it.

Arnaldo, could you consider this for 3.15? I've also got some additional work for perf-bench but am waiting for this to get settled first.

Thanks,
Davidlohr

#13 lore raw

Em Mon, Jan 27, 2014 at 08:12:42PM -0800, Davidlohr Bueso escreveu:

Quoted 5 lines · Darren Hart
Quoted 3 lines

I agree that we should take whatever makes sense for perf out of futex-test and merge it with perf. It will see greater use and receive more review and improvements than it will in my obscure repository.

Quoted 8 lines
Quoted 5 lines

With trinity covering the fuzz testing and perf handling performance tests, I think futex-test can be reduced down to a functional test-suite, which is perfectly fine with me.

If there is still interest here, I'll support it.

Arnaldo, could you consider this for 3.15? I've also got some additional work for perf-bench but am waiting for this to get settled first.

Sure, I'll try applying it later today.

- Arnaldo