diff options
Diffstat (limited to 'tools/perf/bench/futex-requeue.c')
-rw-r--r-- | tools/perf/bench/futex-requeue.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c index 1058c194608a..fc692efa0c05 100644 --- a/tools/perf/bench/futex-requeue.c +++ b/tools/perf/bench/futex-requeue.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <errno.h> | 22 | #include <errno.h> |
23 | #include "bench.h" | 23 | #include "bench.h" |
24 | #include "futex.h" | 24 | #include "futex.h" |
25 | #include "cpumap.h" | ||
25 | 26 | ||
26 | #include <err.h> | 27 | #include <err.h> |
27 | #include <stdlib.h> | 28 | #include <stdlib.h> |
@@ -40,7 +41,7 @@ static bool done = false, silent = false, fshared = false; | |||
40 | static pthread_mutex_t thread_lock; | 41 | static pthread_mutex_t thread_lock; |
41 | static pthread_cond_t thread_parent, thread_worker; | 42 | static pthread_cond_t thread_parent, thread_worker; |
42 | static struct stats requeuetime_stats, requeued_stats; | 43 | static struct stats requeuetime_stats, requeued_stats; |
43 | static unsigned int ncpus, threads_starting, nthreads = 0; | 44 | static unsigned int threads_starting, nthreads = 0; |
44 | static int futex_flag = 0; | 45 | static int futex_flag = 0; |
45 | 46 | ||
46 | static const struct option options[] = { | 47 | static const struct option options[] = { |
@@ -83,19 +84,19 @@ static void *workerfn(void *arg __maybe_unused) | |||
83 | } | 84 | } |
84 | 85 | ||
85 | static void block_threads(pthread_t *w, | 86 | static void block_threads(pthread_t *w, |
86 | pthread_attr_t thread_attr) | 87 | pthread_attr_t thread_attr, struct cpu_map *cpu) |
87 | { | 88 | { |
88 | cpu_set_t cpu; | 89 | cpu_set_t cpuset; |
89 | unsigned int i; | 90 | unsigned int i; |
90 | 91 | ||
91 | threads_starting = nthreads; | 92 | threads_starting = nthreads; |
92 | 93 | ||
93 | /* create and block all threads */ | 94 | /* create and block all threads */ |
94 | for (i = 0; i < nthreads; i++) { | 95 | for (i = 0; i < nthreads; i++) { |
95 | CPU_ZERO(&cpu); | 96 | CPU_ZERO(&cpuset); |
96 | CPU_SET(i % ncpus, &cpu); | 97 | CPU_SET(cpu->map[i % cpu->nr], &cpuset); |
97 | 98 | ||
98 | if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpu)) | 99 | if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset)) |
99 | err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); | 100 | err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); |
100 | 101 | ||
101 | if (pthread_create(&w[i], &thread_attr, workerfn, NULL)) | 102 | if (pthread_create(&w[i], &thread_attr, workerfn, NULL)) |
@@ -116,19 +117,22 @@ int bench_futex_requeue(int argc, const char **argv) | |||
116 | unsigned int i, j; | 117 | unsigned int i, j; |
117 | struct sigaction act; | 118 | struct sigaction act; |
118 | pthread_attr_t thread_attr; | 119 | pthread_attr_t thread_attr; |
120 | struct cpu_map *cpu; | ||
119 | 121 | ||
120 | argc = parse_options(argc, argv, options, bench_futex_requeue_usage, 0); | 122 | argc = parse_options(argc, argv, options, bench_futex_requeue_usage, 0); |
121 | if (argc) | 123 | if (argc) |
122 | goto err; | 124 | goto err; |
123 | 125 | ||
124 | ncpus = sysconf(_SC_NPROCESSORS_ONLN); | 126 | cpu = cpu_map__new(NULL); |
127 | if (!cpu) | ||
128 | err(EXIT_FAILURE, "cpu_map__new"); | ||
125 | 129 | ||
126 | sigfillset(&act.sa_mask); | 130 | sigfillset(&act.sa_mask); |
127 | act.sa_sigaction = toggle_done; | 131 | act.sa_sigaction = toggle_done; |
128 | sigaction(SIGINT, &act, NULL); | 132 | sigaction(SIGINT, &act, NULL); |
129 | 133 | ||
130 | if (!nthreads) | 134 | if (!nthreads) |
131 | nthreads = ncpus; | 135 | nthreads = cpu->nr; |
132 | 136 | ||
133 | worker = calloc(nthreads, sizeof(*worker)); | 137 | worker = calloc(nthreads, sizeof(*worker)); |
134 | if (!worker) | 138 | if (!worker) |
@@ -156,7 +160,7 @@ int bench_futex_requeue(int argc, const char **argv) | |||
156 | struct timeval start, end, runtime; | 160 | struct timeval start, end, runtime; |
157 | 161 | ||
158 | /* create, launch & block all threads */ | 162 | /* create, launch & block all threads */ |
159 | block_threads(worker, thread_attr); | 163 | block_threads(worker, thread_attr, cpu); |
160 | 164 | ||
161 | /* make sure all threads are already blocked */ | 165 | /* make sure all threads are already blocked */ |
162 | pthread_mutex_lock(&thread_lock); | 166 | pthread_mutex_lock(&thread_lock); |