From: Davidlohr Bueso <davidlohr@hp.com>
To: acme@kernel.org, jolsa@kernel.org
Cc: mitake@dcl.info.waseda.ac.jp, davidlohr@hp.com, aswin@hp.com,
linux-kernel@vger.kernel.org
Subject: [PATCH 9/9] perf bench: futex: Support operations for shared futexes
Date: Mon, 16 Jun 2014 11:14:27 -0700 [thread overview]
Message-ID: <1402942467-10671-10-git-send-email-davidlohr@hp.com> (raw)
In-Reply-To: <1402942467-10671-1-git-send-email-davidlohr@hp.com>
Unlike futex-hash, requeuing and wakeup benchmarks do not support
shared futexes, limiting the usefulness of the programs. Correct
this, and allow using the local -S parameter. The default remains
using private futexes.
Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
---
tools/perf/bench/futex-hash.c | 7 +++++--
tools/perf/bench/futex-requeue.c | 22 ++++++++++++++--------
tools/perf/bench/futex-wake.c | 15 ++++++++++-----
3 files changed, 29 insertions(+), 15 deletions(-)
diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c
index 14791eb..5175171 100644
--- a/tools/perf/bench/futex-hash.c
+++ b/tools/perf/bench/futex-hash.c
@@ -26,6 +26,7 @@ static unsigned int nsecs = 10;
/* amount of futexes per thread */
static unsigned int nfutexes = 1024;
static bool fshared = false, done = false;
+static int futex_flag = 0;
struct timeval start, end, runtime;
static pthread_mutex_t thread_lock;
@@ -74,8 +75,7 @@ static void *workerfn(void *arg)
* such as internal waitqueue handling, thus enlarging
* the critical region protected by hb->lock.
*/
- ret = futex_wait(&w->futex[i], 1234, NULL,
- fshared ? 0 : FUTEX_PRIVATE_FLAG);
+ ret = futex_wait(&w->futex[i], 1234, NULL, futex_flag);
if (bench_format == BENCH_FORMAT_DEFAULT &&
(!ret || errno != EAGAIN || errno != EWOULDBLOCK))
warn("Non-expected futex return call");
@@ -147,6 +147,9 @@ int bench_futex_hash(int argc, const char **argv,
if (!worker)
goto errmem;
+ if (!fshared)
+ futex_flag = FUTEX_PRIVATE_FLAG;
+
if (bench_format == BENCH_FORMAT_DEFAULT) {
printf("Run summary [PID %d]: %d threads, each operating on %d [%s] futexes for %d secs.\n\n",
getpid(), nthreads, nfutexes, fshared ? "shared":"private", nsecs);
diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c
index 7b211c1..197537b 100644
--- a/tools/perf/bench/futex-requeue.c
+++ b/tools/perf/bench/futex-requeue.c
@@ -30,15 +30,17 @@ static u_int32_t futex1 = 0, futex2 = 0;
static unsigned int nrequeue = 1;
static pthread_t *worker;
-static bool done = 0;
+static bool done = false, fshared = false;
static pthread_mutex_t thread_lock;
static pthread_cond_t thread_parent, thread_worker;
static struct stats requeuetime_stats, requeued_stats;
static unsigned int ncpus, threads_starting, nthreads = 0;
+static int futex_flag = 0;
static const struct option options[] = {
OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"),
OPT_UINTEGER('q', "nrequeue", &nrequeue, "Specify amount of threads to requeue at once"),
+ OPT_BOOLEAN('S', "shared", &fshared, "Use shared futexes instead of private ones"),
OPT_END()
};
@@ -80,7 +82,7 @@ static void *workerfn(void *arg __maybe_unused)
pthread_cond_wait(&thread_worker, &thread_lock);
pthread_mutex_unlock(&thread_lock);
- futex_wait(&futex1, 0, NULL, FUTEX_PRIVATE_FLAG);
+ futex_wait(&futex1, 0, NULL, futex_flag);
return NULL;
}
@@ -137,10 +139,13 @@ int bench_futex_requeue(int argc, const char **argv,
if (!worker)
err(EXIT_FAILURE, "calloc");
+ if (!fshared)
+ futex_flag = FUTEX_PRIVATE_FLAG;
+
if (bench_format == BENCH_FORMAT_DEFAULT) {
- printf("Run summary [PID %d]: Requeuing %d threads (from %p to %p), "
- "%d at a time.\n\n",
- getpid(), nthreads, &futex1, &futex2, nrequeue);
+ printf("Run summary [PID %d]: Requeuing %d threads (from [%s] futex %p to %p), "
+ "%d at a time.\n\n", getpid(), nthreads,
+ fshared ? "shared":"private", &futex1, &futex2, nrequeue);
}
init_stats(&requeued_stats);
@@ -173,8 +178,9 @@ int bench_futex_requeue(int argc, const char **argv,
* Do not wakeup any tasks blocked on futex1, allowing
* us to really measure futex_wait functionality.
*/
- futex_cmp_requeue(&futex1, 0, &futex2, 0, nrequeue,
- FUTEX_PRIVATE_FLAG);
+ futex_cmp_requeue(&futex1, 0, &futex2, 0,
+ nrequeue, futex_flag);
+
gettimeofday(&end, NULL);
timersub(&end, &start, &runtime);
@@ -187,7 +193,7 @@ int bench_futex_requeue(int argc, const char **argv,
}
/* everybody should be blocked on futex2, wake'em up */
- nrequeued = futex_wake(&futex2, nthreads, FUTEX_PRIVATE_FLAG);
+ nrequeued = futex_wake(&futex2, nthreads, futex_flag);
if (nthreads != nrequeued)
warnx("couldn't wakeup all tasks (%d/%d)", nrequeued, nthreads);
diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c
index eae6d09..08f62eb 100644
--- a/tools/perf/bench/futex-wake.c
+++ b/tools/perf/bench/futex-wake.c
@@ -31,15 +31,17 @@ static u_int32_t futex1 = 0;
static unsigned int nwakes = 1;
pthread_t *worker;
-static bool done = false;
+static bool done = false, fshared = false;
static pthread_mutex_t thread_lock;
static pthread_cond_t thread_parent, thread_worker;
static struct stats waketime_stats, wakeup_stats;
static unsigned int ncpus, threads_starting, nthreads = 0;
+static int futex_flag = 0;
static const struct option options[] = {
OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"),
OPT_UINTEGER('w', "nwakes", &nwakes, "Specify amount of threads to wake at once"),
+ OPT_BOOLEAN('S', "shared", &fshared, "Use shared futexes instead of private ones"),
OPT_END()
};
@@ -57,7 +59,7 @@ static void *workerfn(void *arg __maybe_unused)
pthread_cond_wait(&thread_worker, &thread_lock);
pthread_mutex_unlock(&thread_lock);
- futex_wait(&futex1, 0, NULL, FUTEX_PRIVATE_FLAG);
+ futex_wait(&futex1, 0, NULL, futex_flag);
return NULL;
}
@@ -140,10 +142,13 @@ int bench_futex_wake(int argc, const char **argv,
if (!worker)
err(EXIT_FAILURE, "calloc");
+ if (!fshared)
+ futex_flag = FUTEX_PRIVATE_FLAG;
+
if (bench_format == BENCH_FORMAT_DEFAULT)
- printf("Run summary [PID %d]: blocking on %d threads (at futex %p), "
+ printf("Run summary [PID %d]: blocking on %d threads (at [%s] futex %p), "
"waking up %d at a time.\n\n",
- getpid(), nthreads, &futex1, nwakes);
+ getpid(), nthreads, fshared ? "shared":"private", &futex1, nwakes);
init_stats(&wakeup_stats);
init_stats(&waketime_stats);
@@ -171,7 +176,7 @@ int bench_futex_wake(int argc, const char **argv,
/* Ok, all threads are patiently blocked, start waking folks up */
gettimeofday(&start, NULL);
while (nwoken != nthreads)
- nwoken += futex_wake(&futex1, nwakes, FUTEX_PRIVATE_FLAG);
+ nwoken += futex_wake(&futex1, nwakes, futex_flag);
gettimeofday(&end, NULL);
timersub(&end, &start, &runtime);
--
1.8.1.4
next prev parent reply other threads:[~2014-06-16 18:15 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-16 18:14 [PATCH 0/9] perf bench: Updates for 3.17 Davidlohr Bueso
2014-06-16 18:14 ` [PATCH 1/9] perf bench: Add --repeat option Davidlohr Bueso
2014-06-19 6:14 ` Namhyung Kim
2014-06-19 11:45 ` Davidlohr Bueso
2014-06-19 23:51 ` Namhyung Kim
2014-06-20 3:03 ` Davidlohr Bueso
2014-06-24 5:54 ` Namhyung Kim
2014-06-25 5:51 ` [tip:perf/core] " tip-bot for Davidlohr Bueso
2014-06-16 18:14 ` [PATCH 2/9] perf bench: sched-messaging: Redo runtime output Davidlohr Bueso
2014-06-19 19:30 ` Arnaldo Carvalho de Melo
2014-06-16 18:14 ` [PATCH 3/9] perf bench: sched-messaging: Support multiple runs Davidlohr Bueso
2014-06-16 18:14 ` [PATCH 4/9] perf bench: sched-messaging: Plug memleak Davidlohr Bueso
2014-06-19 6:20 ` Namhyung Kim
2014-06-25 5:51 ` [tip:perf/core] perf bench " tip-bot for Davidlohr Bueso
2014-06-16 18:14 ` [PATCH 5/9] perf bench: futex: Use global --repeat option Davidlohr Bueso
2014-06-25 5:51 ` [tip:perf/core] perf bench " tip-bot for Davidlohr Bueso
2014-06-16 18:14 ` [PATCH 6/9] perf bench: futex: Replace --silent option with global --format Davidlohr Bueso
2014-06-19 16:38 ` Arnaldo Carvalho de Melo
2014-06-19 17:01 ` Davidlohr Bueso
2014-06-16 18:14 ` [PATCH 7/9] perf bench: mem: -o and -n options are mutually exclusive Davidlohr Bueso
2014-06-25 5:52 ` [tip:perf/core] perf bench mem: The " tip-bot for Davidlohr Bueso
2014-06-16 18:14 ` [PATCH 8/9] perf bench: sched-messaging: Drop barf() Davidlohr Bueso
2014-06-25 5:52 ` [tip:perf/core] perf bench " tip-bot for Davidlohr Bueso
2014-06-16 18:14 ` Davidlohr Bueso [this message]
2014-06-19 16:41 ` [PATCH 9/9] perf bench: futex: Support operations for shared futexes Arnaldo Carvalho de Melo
2014-06-19 16:43 ` Davidlohr Bueso
2014-06-19 17:05 ` Arnaldo Carvalho de Melo
2014-06-19 19:48 ` Darren Hart
2014-06-25 17:07 ` Davidlohr Bueso
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=1402942467-10671-10-git-send-email-davidlohr@hp.com \
--to=davidlohr@hp.com \
--cc=acme@kernel.org \
--cc=aswin@hp.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mitake@dcl.info.waseda.ac.jp \
/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
all inboxes | Powered by JetHome®