From: tip-bot for James Yang <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: hpa@zytor.com, kim.phillips@arm.com, james.yang@arm.com,
mingo@kernel.org, tglx@linutronix.de, acme@redhat.com,
linux-kernel@vger.kernel.org, dave@stgolabs.net
Subject: [tip:perf/core] perf bench futex: Sync waker threads
Date: Wed, 6 Dec 2017 08:35:40 -0800 [thread overview]
Message-ID: <tip-8085e5ab41dadce558808b4186a6ea9d0862d3c0@git.kernel.org> (raw)
In-Reply-To: <20171127042101.3659-4-dave@stgolabs.net>
Commit-ID: 8085e5ab41dadce558808b4186a6ea9d0862d3c0
Gitweb: https://git.kernel.org/tip/8085e5ab41dadce558808b4186a6ea9d0862d3c0
Author: James Yang <james.yang@arm.com>
AuthorDate: Sun, 26 Nov 2017 20:21:01 -0800
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 5 Dec 2017 10:23:44 -0300
perf bench futex: Sync waker threads
Waker threads in the futex wake-parallel benchmark are started by a loop
using pthread_create(). However, there is no synchronization for when
the waker threads wake the waiting threads. Comparison of the waker
threads' measurement timestamps show they are not all running
concurrently because older waker threads finish their task before newer
waker threads even start.
This patch uses a barrier to better synchronize the waker threads.
Signed-off-by: James Yang <james.yang@arm.com
Cc: Kim Phillips <kim.phillips@arm.com>
Link: http://lkml.kernel.org/r/20171127042101.3659-4-dave@stgolabs.net
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
[ Disable the wake-parallel test for systems without pthread_barrier_t ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/bench/futex-wake-parallel.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c
index 4488c27..69d8fdc 100644
--- a/tools/perf/bench/futex-wake-parallel.c
+++ b/tools/perf/bench/futex-wake-parallel.c
@@ -7,7 +7,17 @@
* for each individual thread to service its share of work. Ultimately
* it can be used to measure futex_wake() changes.
*/
+#include "bench.h"
+#include <linux/compiler.h>
+#include "../util/debug.h"
+#ifndef HAVE_PTHREAD_BARRIER
+int bench_futex_wake_parallel(int argc __maybe_unused, const char **argv __maybe_unused)
+{
+ pr_err("%s: pthread_barrier_t unavailable, disabling this test...\n", __func__);
+ return 0;
+}
+#else /* HAVE_PTHREAD_BARRIER */
/* For the CLR_() macros */
#include <string.h>
#include <pthread.h>
@@ -15,11 +25,9 @@
#include <signal.h>
#include "../util/stat.h"
#include <subcmd/parse-options.h>
-#include <linux/compiler.h>
#include <linux/kernel.h>
#include <linux/time64.h>
#include <errno.h>
-#include "bench.h"
#include "futex.h"
#include "cpumap.h"
@@ -43,6 +51,7 @@ static bool done = false, silent = false, fshared = false;
static unsigned int nblocked_threads = 0, nwaking_threads = 0;
static pthread_mutex_t thread_lock;
static pthread_cond_t thread_parent, thread_worker;
+static pthread_barrier_t barrier;
static struct stats waketime_stats, wakeup_stats;
static unsigned int threads_starting;
static int futex_flag = 0;
@@ -65,6 +74,8 @@ static void *waking_workerfn(void *arg)
struct thread_data *waker = (struct thread_data *) arg;
struct timeval start, end;
+ pthread_barrier_wait(&barrier);
+
gettimeofday(&start, NULL);
waker->nwoken = futex_wake(&futex, nwakes, futex_flag);
@@ -85,6 +96,8 @@ static void wakeup_threads(struct thread_data *td, pthread_attr_t thread_attr)
pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE);
+ pthread_barrier_init(&barrier, NULL, nwaking_threads + 1);
+
/* create and block all threads */
for (i = 0; i < nwaking_threads; i++) {
/*
@@ -97,9 +110,13 @@ static void wakeup_threads(struct thread_data *td, pthread_attr_t thread_attr)
err(EXIT_FAILURE, "pthread_create");
}
+ pthread_barrier_wait(&barrier);
+
for (i = 0; i < nwaking_threads; i++)
if (pthread_join(td[i].worker, NULL))
err(EXIT_FAILURE, "pthread_join");
+
+ pthread_barrier_destroy(&barrier);
}
static void *blocked_workerfn(void *arg __maybe_unused)
@@ -303,3 +320,4 @@ int bench_futex_wake_parallel(int argc, const char **argv)
free(blocked_worker);
return ret;
}
+#endif /* HAVE_PTHREAD_BARRIER */
next prev parent reply other threads:[~2017-12-06 16:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-27 4:20 [PATCH -tip 0/3] perf bench futex: Improvements Davidlohr Bueso
2017-11-27 4:20 ` [PATCH 1/3] perf bench futex: Use cpumaps Davidlohr Bueso
2017-12-06 16:34 ` [tip:perf/core] " tip-bot for Davidlohr Bueso
2017-11-27 4:21 ` [PATCH 2/3] perf bench futex: Add --affine-wakers option to wake-parallel Davidlohr Bueso
2017-12-06 17:24 ` Davidlohr Bueso
2017-11-27 4:21 ` [PATCH 3/3] perf bench futex: sync waker threads Davidlohr Bueso
2017-12-06 16:35 ` tip-bot for James Yang [this message]
2017-11-28 3:20 ` [PATCH -tip 0/3] perf bench futex: Improvements Kim Phillips
2017-11-30 17:00 ` Arnaldo Carvalho de Melo
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=tip-8085e5ab41dadce558808b4186a6ea9d0862d3c0@git.kernel.org \
--to=tipbot@zytor.com \
--cc=acme@redhat.com \
--cc=dave@stgolabs.net \
--cc=hpa@zytor.com \
--cc=james.yang@arm.com \
--cc=kim.phillips@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
/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
Powered by JetHome