From: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
alexander.shishkin@linux.intel.com,
xinhui.pan@linux.vnet.ibm.com, jpoimboe@redhat.com,
dave@stgolabs.net
Subject: [PATCH RFC] perf bench futex: Support running benchmark while some cpus are offline
Date: Mon, 10 Oct 2016 12:13:57 -0400 [thread overview]
Message-ID: <1476116037-44459-1-git-send-email-xinhui.pan@linux.vnet.ibm.com> (raw)
i%ncpus might not be the correct cpu number which we want to set. If we run
command "perf bench futex all" while some cpus are not online. We will fail to
create pthreads.
Lets fix this by adding int cpu_at_index(int i) which just do a simple traverse
on the cpu_set. And return the correct cpu number.
Signed-off-by: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
---
tools/perf/bench/futex-hash.c | 2 +-
tools/perf/bench/futex-lock-pi.c | 2 +-
tools/perf/bench/futex-requeue.c | 2 +-
tools/perf/bench/futex-wake-parallel.c | 2 +-
tools/perf/bench/futex-wake.c | 2 +-
tools/perf/bench/futex.h | 29 +++++++++++++++++++++++++++++
6 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c
index 8024cd5..3861168 100644
--- a/tools/perf/bench/futex-hash.c
+++ b/tools/perf/bench/futex-hash.c
@@ -161,7 +161,7 @@ int bench_futex_hash(int argc, const char **argv,
goto errmem;
CPU_ZERO(&cpu);
- CPU_SET(i % ncpus, &cpu);
+ CPU_SET(cpu_at_index(i), &cpu);
ret = pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpu);
if (ret)
diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c
index 936d89d..c5548f5 100644
--- a/tools/perf/bench/futex-lock-pi.c
+++ b/tools/perf/bench/futex-lock-pi.c
@@ -127,7 +127,7 @@ static void create_threads(struct worker *w, pthread_attr_t thread_attr)
worker[i].futex = &global_futex;
CPU_ZERO(&cpu);
- CPU_SET(i % ncpus, &cpu);
+ CPU_SET(cpu_at_index(i), &cpu);
if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpu))
err(EXIT_FAILURE, "pthread_attr_setaffinity_np");
diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c
index f96e22e..d4531da 100644
--- a/tools/perf/bench/futex-requeue.c
+++ b/tools/perf/bench/futex-requeue.c
@@ -90,7 +90,7 @@ static void block_threads(pthread_t *w,
/* create and block all threads */
for (i = 0; i < nthreads; i++) {
CPU_ZERO(&cpu);
- CPU_SET(i % ncpus, &cpu);
+ CPU_SET(cpu_at_index(i), &cpu);
if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpu))
err(EXIT_FAILURE, "pthread_attr_setaffinity_np");
diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c
index 4a2ecd7..9821df0 100644
--- a/tools/perf/bench/futex-wake-parallel.c
+++ b/tools/perf/bench/futex-wake-parallel.c
@@ -126,7 +126,7 @@ static void block_threads(pthread_t *w, pthread_attr_t thread_attr)
/* create and block all threads */
for (i = 0; i < nblocked_threads; i++) {
CPU_ZERO(&cpu);
- CPU_SET(i % ncpus, &cpu);
+ CPU_SET(cpu_at_index(i), &cpu);
if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpu))
err(EXIT_FAILURE, "pthread_attr_setaffinity_np");
diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c
index 87d8f4f..f8eba6d 100644
--- a/tools/perf/bench/futex-wake.c
+++ b/tools/perf/bench/futex-wake.c
@@ -96,7 +96,7 @@ static void block_threads(pthread_t *w,
/* create and block all threads */
for (i = 0; i < nthreads; i++) {
CPU_ZERO(&cpu);
- CPU_SET(i % ncpus, &cpu);
+ CPU_SET(cpu_at_index(i), &cpu);
if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpu))
err(EXIT_FAILURE, "pthread_attr_setaffinity_np");
diff --git a/tools/perf/bench/futex.h b/tools/perf/bench/futex.h
index b2e06d1..c7a70f0 100644
--- a/tools/perf/bench/futex.h
+++ b/tools/perf/bench/futex.h
@@ -86,6 +86,35 @@ futex_cmp_requeue(u_int32_t *uaddr, u_int32_t val, u_int32_t *uaddr2, int nr_wak
val, opflags);
}
+static inline int cpu_at_index(int i)
+{
+ static cpu_set_t cpu_set;
+ static int first_time = 1;
+ static int total_cpu;
+ int j = -1;
+
+ if (first_time) {
+ CPU_ZERO(&cpu_set);
+
+ if (sched_getaffinity(0, sizeof(cpu_set), &cpu_set) < 0)
+ return -1;
+
+ first_time = 0;
+ total_cpu = CPU_COUNT(&cpu_set);
+ }
+
+ i = i % total_cpu;
+
+ do {
+ j++;
+ if (CPU_ISSET(j, &cpu_set))
+ i--;
+ } while (i >= 0);
+
+ return j;
+}
+
+
#ifndef HAVE_PTHREAD_ATTR_SETAFFINITY_NP
#include <pthread.h>
static inline int pthread_attr_setaffinity_np(pthread_attr_t *attr,
--
2.4.11
reply other threads:[~2016-10-10 12:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1476116037-44459-1-git-send-email-xinhui.pan@linux.vnet.ibm.com \
--to=xinhui.pan@linux.vnet.ibm.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=dave@stgolabs.net \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.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 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®