Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S942172AbcJSR7s (ORCPT ); Wed, 19 Oct 2016 13:59:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:34725 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753397AbcJSR7p (ORCPT ); Wed, 19 Oct 2016 13:59:45 -0400 Date: Wed, 19 Oct 2016 10:59:33 -0700 From: Davidlohr Bueso To: Sebastian Andrzej Siewior Cc: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: [PATCH] perf/bench-futex: Avoid worker cacheline bouncing Message-ID: <20161019175933.GA28074@linux-80c1.suse> References: <20161016190803.3392-1-bigeasy@linutronix.de> <20161018010949.GD29373@linux-80c1.suse> <20161019130722.t7viruflpg2xu5sx@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20161019130722.t7viruflpg2xu5sx@linutronix.de> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2594 Lines: 77 Sebastian noted that overhead for worker thread ops (throughput) accounting was producing 'perf' to appear in the profiles, consuming a non-trivial (ie 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. Reported-by: Sebastian Andrzej Siewior Signed-off-by: Davidlohr Bueso --- This is an updated version as I noticed lock-pi was also doing this. acme, could you please pick up if no objection? Thanks. tools/perf/bench/futex-hash.c | 6 ++++-- tools/perf/bench/futex-lock-pi.c | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c index 8024cd5febd2..da04b8c5568a 100644 --- a/tools/perf/bench/futex-hash.c +++ b/tools/perf/bench/futex-hash.c @@ -63,8 +63,9 @@ static const char * const bench_futex_hash_usage[] = { static void *workerfn(void *arg) { int ret; - unsigned int i; struct worker *w = (struct worker *) arg; + unsigned int i; + unsigned long ops = w->ops; /* avoid cacheline bouncing */ pthread_mutex_lock(&thread_lock); threads_starting--; @@ -74,7 +75,7 @@ static void *workerfn(void *arg) pthread_mutex_unlock(&thread_lock); do { - for (i = 0; i < nfutexes; i++, w->ops++) { + for (i = 0; i < nfutexes; i++, ops++) { /* * We want the futex calls to fail in order to stress * the hashing of uaddr and not measure other steps, @@ -88,6 +89,7 @@ static void *workerfn(void *arg) } } while (!done); + w->ops = ops; return NULL; } 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, static void *workerfn(void *arg) { struct worker *w = (struct worker *) arg; + unsigned long ops = w->ops; pthread_mutex_lock(&thread_lock); threads_starting--; @@ -103,9 +104,10 @@ static void *workerfn(void *arg) if (ret && !silent) warn("thread %d: Could not unlock pi-lock for %p (%d)", w->tid, w->futex, ret); - w->ops++; /* account for thread's share of work */ + ops++; /* account for thread's share of work */ } while (!done); + w->ops = ops; return NULL; } -- 2.6.6