diff options
Diffstat (limited to 'tools/perf/bench/futex-wake.c')
-rw-r--r-- | tools/perf/bench/futex-wake.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c index 8c5c0b6b5c97..e8181ad7d088 100644 --- a/tools/perf/bench/futex-wake.c +++ b/tools/perf/bench/futex-wake.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> |
@@ -89,19 +90,19 @@ static void print_summary(void) | |||
89 | } | 90 | } |
90 | 91 | ||
91 | static void block_threads(pthread_t *w, | 92 | static void block_threads(pthread_t *w, |
92 | pthread_attr_t thread_attr) | 93 | pthread_attr_t thread_attr, struct cpu_map *cpu) |
93 | { | 94 | { |
94 | cpu_set_t cpu; | 95 | cpu_set_t cpuset; |
95 | unsigned int i; | 96 | unsigned int i; |
96 | 97 | ||
97 | threads_starting = nthreads; | 98 | threads_starting = nthreads; |
98 | 99 | ||
99 | /* create and block all threads */ | 100 | /* create and block all threads */ |
100 | for (i = 0; i < nthreads; i++) { | 101 | for (i = 0; i < nthreads; i++) { |
101 | CPU_ZERO(&cpu); | 102 | CPU_ZERO(&cpuset); |
102 | CPU_SET(i % ncpus, &cpu); | 103 | CPU_SET(cpu->map[i % cpu->nr], &cpuset); |
103 | 104 | ||
104 | if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpu)) | 105 | if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset)) |
105 | err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); | 106 | err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); |
106 | 107 | ||
107 | if (pthread_create(&w[i], &thread_attr, workerfn, NULL)) | 108 | if (pthread_create(&w[i], &thread_attr, workerfn, NULL)) |
@@ -122,6 +123,7 @@ int bench_futex_wake(int argc, const char **argv) | |||
122 | unsigned int i, j; | 123 | unsigned int i, j; |
123 | struct sigaction act; | 124 | struct sigaction act; |
124 | pthread_attr_t thread_attr; | 125 | pthread_attr_t thread_attr; |
126 | struct cpu_map *cpu; | ||
125 | 127 | ||
126 | argc = parse_options(argc, argv, options, bench_futex_wake_usage, 0); | 128 | argc = parse_options(argc, argv, options, bench_futex_wake_usage, 0); |
127 | if (argc) { | 129 | if (argc) { |
@@ -129,7 +131,9 @@ int bench_futex_wake(int argc, const char **argv) | |||
129 | exit(EXIT_FAILURE); | 131 | exit(EXIT_FAILURE); |
130 | } | 132 | } |
131 | 133 | ||
132 | ncpus = sysconf(_SC_NPROCESSORS_ONLN); | 134 | cpu = cpu_map__new(NULL); |
135 | if (!cpu) | ||
136 | err(EXIT_FAILURE, "calloc"); | ||
133 | 137 | ||
134 | sigfillset(&act.sa_mask); | 138 | sigfillset(&act.sa_mask); |
135 | act.sa_sigaction = toggle_done; | 139 | act.sa_sigaction = toggle_done; |
@@ -161,7 +165,7 @@ int bench_futex_wake(int argc, const char **argv) | |||
161 | struct timeval start, end, runtime; | 165 | struct timeval start, end, runtime; |
162 | 166 | ||
163 | /* create, launch & block all threads */ | 167 | /* create, launch & block all threads */ |
164 | block_threads(worker, thread_attr); | 168 | block_threads(worker, thread_attr, cpu); |
165 | 169 | ||
166 | /* make sure all threads are already blocked */ | 170 | /* make sure all threads are already blocked */ |
167 | pthread_mutex_lock(&thread_lock); | 171 | pthread_mutex_lock(&thread_lock); |