Skip to contentSkip to conversation

perf bench futex: Support parallel waker threads

PATCH Applied Davidlohr Bueso 3 participants 5 messages May 8, 2015 – May 10, 2015

Subsystems (2)
lore
Share & tools
lore

Davidlohr Bueso

author reviewer
#0 lore raw

PATCH 1/2 perf bench futex: Support parallel waker threads

The futex-wake benchmark only measures wakeups done within a single process. While this has value in its own, it does not really generate any hb->lock contention. A new benchmark 'wake-parallel' is added, by extending the futex-wake code such that we can measure parallel waker threads. The program output shows the avg per-thread latency in order to complete its share of wakeups:

Run summary [PID 13474]: blocking on 512 threads (at [private] futex 0xa88668), 8 threads waking up 64 at a time.

[Run 1]: Avg per-thread latency (waking 64/512 threads) in 0.6230 ms (+-15.31%) [Run 2]: Avg per-thread latency (waking 64/512 threads) in 0.5175 ms (+-29.95%) [Run 3]: Avg per-thread latency (waking 64/512 threads) in 0.7578 ms (+-18.03%) [Run 4]: Avg per-thread latency (waking 64/512 threads) in 0.8944 ms (+-12.54%) [Run 5]: Avg per-thread latency (waking 64/512 threads) in 1.1204 ms (+-23.85%) Avg per-thread latency (waking 64/512 threads) in 0.7826 ms (+-9.91%)

Naturally, different combinations of numbers of blocking and waker threads will exhibit different information.

---
 tools/perf/Documentation/perf-bench.txt |   3 +
 tools/perf/bench/Build                  |   1 +
 tools/perf/bench/bench.h                |   2 +
 tools/perf/bench/futex-wake-parallel.c  | 294 ++++++++++++++++++++++++++++++++
 tools/perf/builtin-bench.c              |   1 +
 5 files changed, 301 insertions(+)
 create mode 100644 tools/perf/bench/futex-wake-parallel.c
tools/perf/Documentation/perf-bench.txt +3 -0
index f6480cb..bf3d064 100644
@@ -210,6 +210,9 @@ Suite for evaluating hash tables.
 *wake*::
 Suite for evaluating wake calls.
 
+*wake-parallel*::
+Suite for evaluating parallel wake calls.
+
 *requeue*::
 Suite for evaluating requeue calls.
 
tools/perf/bench/Build +1 -0
index 5ce9802..c3ab760 100644
@@ -3,6 +3,7 @@ perf-y += sched-pipe.o
 perf-y += mem-memcpy.o
 perf-y += futex-hash.o
 perf-y += futex-wake.o
+perf-y += futex-wake-parallel.o
 perf-y += futex-requeue.o
 
 perf-$(CONFIG_X86_64) += mem-memcpy-x86-64-asm.o
tools/perf/bench/bench.h +2 -0
index 3c4dd44..70b2f71 100644
@@ -33,6 +33,8 @@ 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_wake_parallel(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"
tools/perf/bench/futex-wake-parallel.c new file +294 -0

294 lines not on this page · raw message

tools/perf/builtin-bench.c +1 -0
index b9a56fa..b5314e4 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	},
+	{ "wake-parallel", "Benchmark for parallel futex wake calls",   bench_futex_wake_parallel },
 	{ "requeue",	"Benchmark for futex requeue calls",            bench_futex_requeue	},
 	{ "all",	"Test all futex benchmarks",			NULL			},
 	{ NULL,		NULL,						NULL			}
Signature · 1 line
2.1.4
author reviewer
#1 lore raw

PATCH 2/2 perf bench futex: Handle spurious wakeups

Wrap futex_wait around a loop and catch for EINTR. Either a spurious wakeup occurred or a signal interrupted is, either way we need to block again.

---
 tools/perf/bench/futex-wake.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/perf/bench/futex-wake.c +6 -1
index 929f762..e5e41d3 100644
@@ -60,7 +60,12 @@ static void *workerfn(void *arg __maybe_unused)
 	pthread_cond_wait(&thread_worker, &thread_lock);
 	pthread_mutex_unlock(&thread_lock);
 
-	futex_wait(&futex1, 0, NULL, futex_flag);
+	while (1) {
+		if (futex_wait(&futex1, 0, NULL, futex_flag) != EINTR)
+			break;
+	}
+
+	pthread_exit(NULL);
 	return NULL;
 }
 
Signature · 1 line
2.1.4
#2 lore raw

[tip:perf/core] perf bench futex: Handle spurious wakeups

perf bench futex: Handle spurious wakeups
Commit-ID:  598adc5c9c1cfd3f154f6d9df72b38eda63e306e
Gitweb:     http://git.kernel.org/tip/598adc5c9c1cfd3f154f6d9df72b38eda63e306e
Author:     Davidlohr Bueso <[email protected]>
AuthorDate: Fri, 8 May 2015 11:38:00 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 8 May 2015 16:24:02 -0300

perf bench futex: Handle spurious wakeups

Wrap futex_wait around a loop and catch for EINTR.

Either a spurious wakeup occurred or a signal interrupted is, either way we need to block again.

---
 tools/perf/bench/futex-wake.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/perf/bench/futex-wake.c +6 -1
index 929f762..e5e41d3 100644
@@ -60,7 +60,12 @@ static void *workerfn(void *arg __maybe_unused)
 	pthread_cond_wait(&thread_worker, &thread_lock);
 	pthread_mutex_unlock(&thread_lock);
 
-	futex_wait(&futex1, 0, NULL, futex_flag);
+	while (1) {
+		if (futex_wait(&futex1, 0, NULL, futex_flag) != EINTR)
+			break;
+	}
+
+	pthread_exit(NULL);
 	return NULL;
 }
 
maintainer Applied
#3 lore raw
In reply to Davidlohr Bueso

Em Fri, May 08, 2015 at 11:37:59AM -0700, Davidlohr Bueso escreveu:

Quoted 9 lines

The futex-wake benchmark only measures wakeups done within a single process. While this has value in its own, it does not really generate any hb->lock contention. A new benchmark 'wake-parallel' is added, by extending the futex-wake code such that we can measure parallel waker threads. The program output shows the avg per-thread latency in order to complete its share of wakeups:

Run summary [PID 13474]: blocking on 512 threads (at [private] futex 0xa88668), 8 threads waking up 64 at a time.

Thanks, applied both to perf/core.

- Arnaldo

#4 lore raw
In reply to Davidlohr Bueso
perf bench futex: Support parallel waker threads
Commit-ID:  d65817b4e707068c2dd3e002e87c2a0294aabc2c
Gitweb:     http://git.kernel.org/tip/d65817b4e707068c2dd3e002e87c2a0294aabc2c
Author:     Davidlohr Bueso <[email protected]>
AuthorDate: Fri, 8 May 2015 11:37:59 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 8 May 2015 16:23:50 -0300

perf bench futex: Support parallel waker threads

The futex-wake benchmark only measures wakeups done within a single process. While this has value in its own, it does not really generate any hb->lock contention.

A new benchmark 'wake-parallel' is added, by extending the futex-wake code such that we can measure parallel waker threads. The program output shows the avg per-thread latency in order to complete its share of wakeups:

Run summary [PID 13474]: blocking on 512 threads (at [private] futex 0xa88668), 8 threads waking up 64 at a time.

[Run 1]: Avg per-thread latency (waking 64/512 threads) in 0.6230 ms (+-15.31%) [Run 2]: Avg per-thread latency (waking 64/512 threads) in 0.5175 ms (+-29.95%) [Run 3]: Avg per-thread latency (waking 64/512 threads) in 0.7578 ms (+-18.03%) [Run 4]: Avg per-thread latency (waking 64/512 threads) in 0.8944 ms (+-12.54%) [Run 5]: Avg per-thread latency (waking 64/512 threads) in 1.1204 ms (+-23.85%) Avg per-thread latency (waking 64/512 threads) in 0.7826 ms (+-9.91%)

Naturally, different combinations of numbers of blocking and waker threads will exhibit different information.

---
 tools/perf/Documentation/perf-bench.txt |   3 +
 tools/perf/bench/Build                  |   1 +
 tools/perf/bench/bench.h                |   2 +
 tools/perf/bench/futex-wake-parallel.c  | 294 ++++++++++++++++++++++++++++++++
 tools/perf/builtin-bench.c              |   1 +
 5 files changed, 301 insertions(+)
tools/perf/Documentation/perf-bench.txt +3 -0
index f6480cb..bf3d064 100644
@@ -210,6 +210,9 @@ Suite for evaluating hash tables.
 *wake*::
 Suite for evaluating wake calls.
 
+*wake-parallel*::
+Suite for evaluating parallel wake calls.
+
 *requeue*::
 Suite for evaluating requeue calls.
 
tools/perf/bench/Build +1 -0
index 5ce9802..c3ab760 100644
@@ -3,6 +3,7 @@ perf-y += sched-pipe.o
 perf-y += mem-memcpy.o
 perf-y += futex-hash.o
 perf-y += futex-wake.o
+perf-y += futex-wake-parallel.o
 perf-y += futex-requeue.o
 
 perf-$(CONFIG_X86_64) += mem-memcpy-x86-64-asm.o
tools/perf/bench/bench.h +2 -0
index 3c4dd44..70b2f71 100644
@@ -33,6 +33,8 @@ 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_wake_parallel(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"
tools/perf/bench/futex-wake-parallel.c new file +294 -0

294 lines not on this page · raw message

tools/perf/builtin-bench.c +1 -0
index b9a56fa..b5314e4 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	},
+	{ "wake-parallel", "Benchmark for parallel futex wake calls",   bench_futex_wake_parallel },
 	{ "requeue",	"Benchmark for futex requeue calls",            bench_futex_requeue	},
 	{ "all",	"Test all futex benchmarks",			NULL			},
 	{ NULL,		NULL,						NULL			}