aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorDavidlohr Bueso <dave@stgolabs.net>2016-10-24 16:56:52 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-10-25 08:50:47 -0400
commite2e1680fda1573ebfdd6bba5d58f978044746993 (patch)
treebb48b64d2f133ca7ea7b3a84305b3bdb4cb03b5a /tools/perf
parent76e2d2617d767c445498c4c4b1162eb2201cdd77 (diff)
perf bench futex: Avoid worker cacheline bouncing
Sebastian noted that overhead for worker thread ops (throughput) accounting was producing 'perf' to appear in the profiles, consuming a non-trivial (i.e. 13%) amount of CPU. This is due to cacheline bouncing due to the increment of w->ops. We can easily fix this by just working on a local copy and updating the actual worker once done running, and ready to show the program summary. There is no danger of the worker being concurrent, so we can trust that no stale value is being seen by another thread. This also gets rid of the unnecessary cache alignment hack; its not worth it. Reported-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Davidlohr Bueso <dbueso@suse.de> Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Link: http://lkml.kernel.org/r/1477342613-9938-2-git-send-email-dave@stgolabs.net Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/bench/futex-hash.c11
-rw-r--r--tools/perf/bench/futex-lock-pi.c4
2 files changed, 8 insertions, 7 deletions
diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c
index d9e5e80bb4d0..da04b8c5568a 100644
--- a/tools/perf/bench/futex-hash.c
+++ b/tools/perf/bench/futex-hash.c
@@ -39,15 +39,12 @@ static unsigned int threads_starting;
39static struct stats throughput_stats; 39static struct stats throughput_stats;
40static pthread_cond_t thread_parent, thread_worker; 40static pthread_cond_t thread_parent, thread_worker;
41 41
42#define SMP_CACHE_BYTES 256
43#define __cacheline_aligned __attribute__ ((aligned (SMP_CACHE_BYTES)))
44
45struct worker { 42struct worker {
46 int tid; 43 int tid;
47 u_int32_t *futex; 44 u_int32_t *futex;
48 pthread_t thread; 45 pthread_t thread;
49 unsigned long ops; 46 unsigned long ops;
50} __cacheline_aligned; 47};
51 48
52static const struct option options[] = { 49static const struct option options[] = {
53 OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"), 50 OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"),
@@ -66,8 +63,9 @@ static const char * const bench_futex_hash_usage[] = {
66static void *workerfn(void *arg) 63static void *workerfn(void *arg)
67{ 64{
68 int ret; 65 int ret;
69 unsigned int i;
70 struct worker *w = (struct worker *) arg; 66 struct worker *w = (struct worker *) arg;
67 unsigned int i;
68 unsigned long ops = w->ops; /* avoid cacheline bouncing */
71 69
72 pthread_mutex_lock(&thread_lock); 70 pthread_mutex_lock(&thread_lock);
73 threads_starting--; 71 threads_starting--;
@@ -77,7 +75,7 @@ static void *workerfn(void *arg)
77 pthread_mutex_unlock(&thread_lock); 75 pthread_mutex_unlock(&thread_lock);
78 76
79 do { 77 do {
80 for (i = 0; i < nfutexes; i++, w->ops++) { 78 for (i = 0; i < nfutexes; i++, ops++) {
81 /* 79 /*
82 * We want the futex calls to fail in order to stress 80 * We want the futex calls to fail in order to stress
83 * the hashing of uaddr and not measure other steps, 81 * the hashing of uaddr and not measure other steps,
@@ -91,6 +89,7 @@ static void *workerfn(void *arg)
91 } 89 }
92 } while (!done); 90 } while (!done);
93 91
92 w->ops = ops;
94 return NULL; 93 return NULL;
95} 94}
96 95
diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c
index 936d89d30483..7032e4643c65 100644
--- a/tools/perf/bench/futex-lock-pi.c
+++ b/tools/perf/bench/futex-lock-pi.c
@@ -75,6 +75,7 @@ static void toggle_done(int sig __maybe_unused,
75static void *workerfn(void *arg) 75static void *workerfn(void *arg)
76{ 76{
77 struct worker *w = (struct worker *) arg; 77 struct worker *w = (struct worker *) arg;
78 unsigned long ops = w->ops;
78 79
79 pthread_mutex_lock(&thread_lock); 80 pthread_mutex_lock(&thread_lock);
80 threads_starting--; 81 threads_starting--;
@@ -103,9 +104,10 @@ static void *workerfn(void *arg)
103 if (ret && !silent) 104 if (ret && !silent)
104 warn("thread %d: Could not unlock pi-lock for %p (%d)", 105 warn("thread %d: Could not unlock pi-lock for %p (%d)",
105 w->tid, w->futex, ret); 106 w->tid, w->futex, ret);
106 w->ops++; /* account for thread's share of work */ 107 ops++; /* account for thread's share of work */
107 } while (!done); 108 } while (!done);
108 109
110 w->ops = ops;
109 return NULL; 111 return NULL;
110} 112}
111 113