aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/bench/futex-hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/bench/futex-hash.c')
-rw-r--r--tools/perf/bench/futex-hash.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c
index 58ae6ed8f38b..9aa3a674829b 100644
--- a/tools/perf/bench/futex-hash.c
+++ b/tools/perf/bench/futex-hash.c
@@ -24,9 +24,9 @@
24#include <subcmd/parse-options.h> 24#include <subcmd/parse-options.h>
25#include "bench.h" 25#include "bench.h"
26#include "futex.h" 26#include "futex.h"
27#include "cpumap.h"
27 28
28#include <err.h> 29#include <err.h>
29#include <sys/time.h>
30 30
31static unsigned int nthreads = 0; 31static unsigned int nthreads = 0;
32static unsigned int nsecs = 10; 32static unsigned int nsecs = 10;
@@ -118,11 +118,12 @@ static void print_summary(void)
118int bench_futex_hash(int argc, const char **argv) 118int bench_futex_hash(int argc, const char **argv)
119{ 119{
120 int ret = 0; 120 int ret = 0;
121 cpu_set_t cpu; 121 cpu_set_t cpuset;
122 struct sigaction act; 122 struct sigaction act;
123 unsigned int i, ncpus; 123 unsigned int i;
124 pthread_attr_t thread_attr; 124 pthread_attr_t thread_attr;
125 struct worker *worker = NULL; 125 struct worker *worker = NULL;
126 struct cpu_map *cpu;
126 127
127 argc = parse_options(argc, argv, options, bench_futex_hash_usage, 0); 128 argc = parse_options(argc, argv, options, bench_futex_hash_usage, 0);
128 if (argc) { 129 if (argc) {
@@ -130,14 +131,16 @@ int bench_futex_hash(int argc, const char **argv)
130 exit(EXIT_FAILURE); 131 exit(EXIT_FAILURE);
131 } 132 }
132 133
133 ncpus = sysconf(_SC_NPROCESSORS_ONLN); 134 cpu = cpu_map__new(NULL);
135 if (!cpu)
136 goto errmem;
134 137
135 sigfillset(&act.sa_mask); 138 sigfillset(&act.sa_mask);
136 act.sa_sigaction = toggle_done; 139 act.sa_sigaction = toggle_done;
137 sigaction(SIGINT, &act, NULL); 140 sigaction(SIGINT, &act, NULL);
138 141
139 if (!nthreads) /* default to the number of CPUs */ 142 if (!nthreads) /* default to the number of CPUs */
140 nthreads = ncpus; 143 nthreads = cpu->nr;
141 144
142 worker = calloc(nthreads, sizeof(*worker)); 145 worker = calloc(nthreads, sizeof(*worker));
143 if (!worker) 146 if (!worker)
@@ -163,10 +166,10 @@ int bench_futex_hash(int argc, const char **argv)
163 if (!worker[i].futex) 166 if (!worker[i].futex)
164 goto errmem; 167 goto errmem;
165 168
166 CPU_ZERO(&cpu); 169 CPU_ZERO(&cpuset);
167 CPU_SET(i % ncpus, &cpu); 170 CPU_SET(cpu->map[i % cpu->nr], &cpuset);
168 171
169 ret = pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpu); 172 ret = pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset);
170 if (ret) 173 if (ret)
171 err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); 174 err(EXIT_FAILURE, "pthread_attr_setaffinity_np");
172 175
@@ -217,6 +220,7 @@ int bench_futex_hash(int argc, const char **argv)
217 print_summary(); 220 print_summary();
218 221
219 free(worker); 222 free(worker);
223 free(cpu);
220 return ret; 224 return ret;
221errmem: 225errmem:
222 err(EXIT_FAILURE, "calloc"); 226 err(EXIT_FAILURE, "calloc");