All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	James Yang <james.yang@arm.com>,
	Kim Phillips <kim.phillips@arm.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 12/36] perf bench futex: Sync waker threads
Date: Wed,  6 Dec 2017 11:40:51 -0300	[thread overview]
Message-ID: <20171206144115.15097-13-acme@kernel.org> (raw)
In-Reply-To: <20171206144115.15097-1-acme@kernel.org>

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

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 4488c27e8a43..69d8fdc87315 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 */
-- 
2.13.6

  parent reply	other threads:[~2017-12-06 14:49 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20171206144115.15097-1-acme@kernel.org>
2017-12-06 14:40 ` [PATCH 01/36] tools headers: Follow the upstream UAPI header version 100% differ from the kernel Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 02/36] perf test: Disable test cases 19 and 20 on s390x Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 03/36] perf record: Synthesize unit/scale/... in event update Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 04/36] perf record: Synthesize thread map and cpu map Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 05/36] perf script: Allow computing 'perf stat' style metrics Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 06/36] perf buildid-cache: Document for Node.js USDT Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 07/36] perf report: Fix -D output for user metadata events Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 08/36] perf intel-pt: Improve build messages for files that differ from the kernel Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 09/36] Documentation: Add Arnaldo Melo to list of enforcement statement endorsers Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 10/36] perf bench futex: Use cpumaps Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 11/36] tools build feature: Check if pthread_barrier_t is available Arnaldo Carvalho de Melo
2017-12-06 21:31   ` Philippe Ombredanne
2017-12-07 11:24     ` Arnaldo Carvalho de Melo
2017-12-06 14:40 ` Arnaldo Carvalho de Melo [this message]
2017-12-06 14:40 ` [PATCH 13/36] perf annotate: Fix unnecessary memory allocation for s390x Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 14/36] perf annotate: Fix objdump comment parsing for Intel mov dissassembly Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 15/36] perf rblist: Create rblist__exit() function Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 16/36] perf stat: Add rbtree node_delete op Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 17/36] perf thread_map: Add method to map all threads in the system Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 18/36] perf s390: Always build with -fPIC Arnaldo Carvalho de Melo
2017-12-07  8:09   ` Hendrik Brueckner
2017-12-28 15:34     ` [tip:perf/core] " tip-bot for Hendrik Brueckner
2017-12-06 14:40 ` [PATCH 19/36] perf pmu: Pass pmu as a parameter to get_cpuid_str() Arnaldo Carvalho de Melo
2017-12-06 14:40   ` Arnaldo Carvalho de Melo
2017-12-06 14:40 ` [PATCH 20/36] perf tools arm64: Add support for get_cpuid_str function Arnaldo Carvalho de Melo
2017-12-06 14:40   ` Arnaldo Carvalho de Melo
2017-12-06 14:40   ` Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 21/36] perf pmu: Add helper function is_pmu_core to detect PMU CORE devices Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 22/36] perf vendor events arm64: Add ThunderX2 implementation defined pmu core events Arnaldo Carvalho de Melo
2017-12-06 14:41   ` Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 23/36] perf pmu: Add check for valid cpuid in perf_pmu__find_map() Arnaldo Carvalho de Melo
2017-12-06 14:41   ` Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 24/36] perf tools: Fix up build in hardnened environments Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 25/36] perf evlist: Remove 'overwrite' parameter from perf_evlist__mmap Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 26/36] perf evlist: Remove 'overwrite' parameter from perf_evlist__mmap_ex Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 27/36] perf evlist: Remove evlist->overwrite Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 28/36] perf mmap: Remove overwrite from arguments list of perf_mmap__push Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 29/36] perf mmap: Remove overwrite and check_messup from mmap read Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 30/36] perf c2c: Add a tip about cacheline events Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 31/36] perf vendor events: Use more flexible pattern matching for CPU identification for mapfile.csv Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 32/36] x86/asm: Allow again using asm.h when building for the 'bpf' clang target Arnaldo Carvalho de Melo
2017-12-06 14:41   ` Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 33/36] perf report: Set browser mode right before setup_browser() Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 34/36] perf mmap: Fix perf backward recording Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 35/36] perf mmap: Don't discard prev in backward mode Arnaldo Carvalho de Melo
2017-12-06 14:41 ` [PATCH 36/36] perf tools: Rename 'backward' to 'overwrite' in evlist, mmap and record 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=20171206144115.15097-13-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=dave@stgolabs.net \
    --cc=james.yang@arm.com \
    --cc=kim.phillips@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@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.