Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757459AbcJPTIX (ORCPT ); Sun, 16 Oct 2016 15:08:23 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:35218 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755684AbcJPTIW (ORCPT ); Sun, 16 Oct 2016 15:08:22 -0400 From: Sebastian Andrzej Siewior To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Ingo Molnar , linux-kernel@vger.kernel.org, Davidlohr Bueso , Sebastian Andrzej Siewior Subject: [PATCH 1/2] perf bench futex: cache align the worer struct Date: Sun, 16 Oct 2016 21:08:02 +0200 Message-Id: <20161016190803.3392-1-bigeasy@linutronix.de> X-Mailer: git-send-email 2.9.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1214 Lines: 35 It popped up in perf testing that the worker consumes some amount of CPU. It boils down to the increment of `ops` which causes cache line bouncing between the individual threads. The patch aligns the struct by 256 bytes to ensure that not a cache line is shared among CPUs. 128 byte is the x86 worst case and grep says that L1_CACHE_SHIFT is set to 8 on s390. Signed-off-by: Sebastian Andrzej Siewior --- tools/perf/bench/futex-hash.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c index 8024cd5febd2..d9e5e80bb4d0 100644 --- a/tools/perf/bench/futex-hash.c +++ b/tools/perf/bench/futex-hash.c @@ -39,12 +39,15 @@ static unsigned int threads_starting; static struct stats throughput_stats; static pthread_cond_t thread_parent, thread_worker; =20 +#define SMP_CACHE_BYTES 256 +#define __cacheline_aligned __attribute__ ((aligned (SMP_CACHE_BYTES))) + struct worker { int tid; u_int32_t *futex; pthread_t thread; unsigned long ops; -}; +} __cacheline_aligned; =20 static const struct option options[] =3D { OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"), --=20 2.9.3