All of lore.kernel.org
 help / color / mirror / Atom feed
From: Davidlohr Bueso <dave@stgolabs.net>
To: acme@kernel.org
Cc: james.yang@arm.com, kim.phillips@arm.com, dave@stgolabs.net,
	linux-kernel@vger.kernel.org, Kim Phillips <Kim.Phillips@arm.com>,
	Davidlohr Bueso <dbueso@suse.de>
Subject: [PATCH 2/3] perf bench futex: Add --affine-wakers option to wake-parallel
Date: Sun, 26 Nov 2017 20:21:00 -0800	[thread overview]
Message-ID: <20171127042101.3659-3-dave@stgolabs.net> (raw)
In-Reply-To: <20171127042101.3659-1-dave@stgolabs.net>

From: James Yang <james.yang@arm.com>

The waker threads' processor affinity is not specified, so
the result has run-to-run variability as the scheduler
decides on which CPUs they are to run.  So we add a
-W/--affine-wakers flag to stripe the affinity of the
waker threads across the online CPUs instead of having
the scheduler place them.

Cc: Kim Phillips <Kim.Phillips@arm.com>
Signed-off-by: James Yang <james.yang@arm.com>
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
---
 tools/perf/bench/futex-wake-parallel.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c
index 979e303e4797..c04e207ea37c 100644
--- a/tools/perf/bench/futex-wake-parallel.c
+++ b/tools/perf/bench/futex-wake-parallel.c
@@ -39,6 +39,7 @@ static u_int32_t futex = 0;
 
 static pthread_t *blocked_worker;
 static bool done = false, silent = false, fshared = false;
+static bool affine_wakers = false;
 static unsigned int nblocked_threads = 0, nwaking_threads = 0;
 static pthread_mutex_t thread_lock;
 static pthread_cond_t thread_parent, thread_worker;
@@ -51,6 +52,7 @@ static const struct option options[] = {
 	OPT_UINTEGER('w', "nwakers", &nwaking_threads, "Specify amount of waking threads"),
 	OPT_BOOLEAN( 's', "silent",  &silent,   "Silent mode: do not display data/details"),
 	OPT_BOOLEAN( 'S', "shared",  &fshared,  "Use shared futexes instead of private ones"),
+	OPT_BOOLEAN( 'W', "affine-wakers", &affine_wakers, "Stripe affinity of waker threads across CPUs"),
 	OPT_END()
 };
 
@@ -78,7 +80,8 @@ static void *waking_workerfn(void *arg)
 	return NULL;
 }
 
-static void wakeup_threads(struct thread_data *td, pthread_attr_t thread_attr)
+static void wakeup_threads(struct thread_data *td, pthread_attr_t thread_attr,
+			   struct cpu_map *cpu)
 {
 	unsigned int i;
 
@@ -91,6 +94,17 @@ static void wakeup_threads(struct thread_data *td, pthread_attr_t thread_attr)
 		 * as it will affect the order to acquire the hb spinlock.
 		 * For now let the scheduler decide.
 		 */
+		if (affine_wakers) {
+			cpu_set_t cpuset;
+			CPU_ZERO(&cpuset);
+			CPU_SET(cpu->map[(i + 1) % cpu->nr], &cpuset);
+
+			if (pthread_attr_setaffinity_np(&thread_attr,
+							sizeof(cpu_set_t),
+							&cpuset))
+				err(EXIT_FAILURE, "pthread_attr_setaffinity_np");
+		}
+
 		if (pthread_create(&td[i].worker, &thread_attr,
 				   waking_workerfn, (void *)&td[i]))
 			err(EXIT_FAILURE, "pthread_create");
@@ -276,7 +290,7 @@ int bench_futex_wake_parallel(int argc, const char **argv)
 		usleep(100000);
 
 		/* Ok, all threads are patiently blocked, start waking folks up */
-		wakeup_threads(waking_worker, thread_attr);
+		wakeup_threads(waking_worker, thread_attr, cpu);
 
 		for (i = 0; i < nblocked_threads; i++) {
 			ret = pthread_join(blocked_worker[i], NULL);
-- 
2.13.6

  parent reply	other threads:[~2017-11-27  4:24 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 ` Davidlohr Bueso [this message]
2017-12-06 17:24   ` [PATCH 2/3] perf bench futex: Add --affine-wakers option to wake-parallel Davidlohr Bueso
2017-11-27  4:21 ` [PATCH 3/3] perf bench futex: sync waker threads Davidlohr Bueso
2017-12-06 16:35   ` [tip:perf/core] perf bench futex: Sync " tip-bot for James Yang
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=20171127042101.3659-3-dave@stgolabs.net \
    --to=dave@stgolabs.net \
    --cc=acme@kernel.org \
    --cc=dbueso@suse.de \
    --cc=james.yang@arm.com \
    --cc=kim.phillips@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.