diff options
Diffstat (limited to 'tools/perf/bench/futex-lock-pi.c')
-rw-r--r-- | tools/perf/bench/futex-lock-pi.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c index 08653ae8a8c4..8e9c4753e304 100644 --- a/tools/perf/bench/futex-lock-pi.c +++ b/tools/perf/bench/futex-lock-pi.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <errno.h> | 15 | #include <errno.h> |
16 | #include "bench.h" | 16 | #include "bench.h" |
17 | #include "futex.h" | 17 | #include "futex.h" |
18 | #include "cpumap.h" | ||
18 | 19 | ||
19 | #include <err.h> | 20 | #include <err.h> |
20 | #include <stdlib.h> | 21 | #include <stdlib.h> |
@@ -32,7 +33,7 @@ static struct worker *worker; | |||
32 | static unsigned int nsecs = 10; | 33 | static unsigned int nsecs = 10; |
33 | static bool silent = false, multi = false; | 34 | static bool silent = false, multi = false; |
34 | static bool done = false, fshared = false; | 35 | static bool done = false, fshared = false; |
35 | static unsigned int ncpus, nthreads = 0; | 36 | static unsigned int nthreads = 0; |
36 | static int futex_flag = 0; | 37 | static int futex_flag = 0; |
37 | struct timeval start, end, runtime; | 38 | struct timeval start, end, runtime; |
38 | static pthread_mutex_t thread_lock; | 39 | static pthread_mutex_t thread_lock; |
@@ -113,9 +114,10 @@ static void *workerfn(void *arg) | |||
113 | return NULL; | 114 | return NULL; |
114 | } | 115 | } |
115 | 116 | ||
116 | static void create_threads(struct worker *w, pthread_attr_t thread_attr) | 117 | static void create_threads(struct worker *w, pthread_attr_t thread_attr, |
118 | struct cpu_map *cpu) | ||
117 | { | 119 | { |
118 | cpu_set_t cpu; | 120 | cpu_set_t cpuset; |
119 | unsigned int i; | 121 | unsigned int i; |
120 | 122 | ||
121 | threads_starting = nthreads; | 123 | threads_starting = nthreads; |
@@ -130,10 +132,10 @@ static void create_threads(struct worker *w, pthread_attr_t thread_attr) | |||
130 | } else | 132 | } else |
131 | worker[i].futex = &global_futex; | 133 | worker[i].futex = &global_futex; |
132 | 134 | ||
133 | CPU_ZERO(&cpu); | 135 | CPU_ZERO(&cpuset); |
134 | CPU_SET(i % ncpus, &cpu); | 136 | CPU_SET(cpu->map[i % cpu->nr], &cpuset); |
135 | 137 | ||
136 | if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpu)) | 138 | if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset)) |
137 | err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); | 139 | err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); |
138 | 140 | ||
139 | if (pthread_create(&w[i].thread, &thread_attr, workerfn, &worker[i])) | 141 | if (pthread_create(&w[i].thread, &thread_attr, workerfn, &worker[i])) |
@@ -147,19 +149,22 @@ int bench_futex_lock_pi(int argc, const char **argv) | |||
147 | unsigned int i; | 149 | unsigned int i; |
148 | struct sigaction act; | 150 | struct sigaction act; |
149 | pthread_attr_t thread_attr; | 151 | pthread_attr_t thread_attr; |
152 | struct cpu_map *cpu; | ||
150 | 153 | ||
151 | argc = parse_options(argc, argv, options, bench_futex_lock_pi_usage, 0); | 154 | argc = parse_options(argc, argv, options, bench_futex_lock_pi_usage, 0); |
152 | if (argc) | 155 | if (argc) |
153 | goto err; | 156 | goto err; |
154 | 157 | ||
155 | ncpus = sysconf(_SC_NPROCESSORS_ONLN); | 158 | cpu = cpu_map__new(NULL); |
159 | if (!cpu) | ||
160 | err(EXIT_FAILURE, "calloc"); | ||
156 | 161 | ||
157 | sigfillset(&act.sa_mask); | 162 | sigfillset(&act.sa_mask); |
158 | act.sa_sigaction = toggle_done; | 163 | act.sa_sigaction = toggle_done; |
159 | sigaction(SIGINT, &act, NULL); | 164 | sigaction(SIGINT, &act, NULL); |
160 | 165 | ||
161 | if (!nthreads) | 166 | if (!nthreads) |
162 | nthreads = ncpus; | 167 | nthreads = cpu->nr; |
163 | 168 | ||
164 | worker = calloc(nthreads, sizeof(*worker)); | 169 | worker = calloc(nthreads, sizeof(*worker)); |
165 | if (!worker) | 170 | if (!worker) |
@@ -180,7 +185,7 @@ int bench_futex_lock_pi(int argc, const char **argv) | |||
180 | pthread_attr_init(&thread_attr); | 185 | pthread_attr_init(&thread_attr); |
181 | gettimeofday(&start, NULL); | 186 | gettimeofday(&start, NULL); |
182 | 187 | ||
183 | create_threads(worker, thread_attr); | 188 | create_threads(worker, thread_attr, cpu); |
184 | pthread_attr_destroy(&thread_attr); | 189 | pthread_attr_destroy(&thread_attr); |
185 | 190 | ||
186 | pthread_mutex_lock(&thread_lock); | 191 | pthread_mutex_lock(&thread_lock); |