lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:   Mon, 10 Oct 2016 12:13:57 -0400
From:   Pan Xinhui <xinhui.pan@...ux.vnet.ibm.com>
To:     linux-kernel@...r.kernel.org
Cc:     peterz@...radead.org, mingo@...hat.com, acme@...nel.org,
        alexander.shishkin@...ux.intel.com, xinhui.pan@...ux.vnet.ibm.com,
        jpoimboe@...hat.com, dave@...olabs.net
Subject: [PATCH RFC] perf bench futex: Support running benchmark while some cpus are offline

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@...ux.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ