.. | .. |
---|
12 | 12 | #include <subcmd/parse-options.h> |
---|
13 | 13 | #include <linux/compiler.h> |
---|
14 | 14 | #include <linux/kernel.h> |
---|
| 15 | +#include <linux/zalloc.h> |
---|
15 | 16 | #include <errno.h> |
---|
| 17 | +#include <internal/cpumap.h> |
---|
| 18 | +#include <perf/cpumap.h> |
---|
16 | 19 | #include "bench.h" |
---|
17 | 20 | #include "futex.h" |
---|
18 | | -#include "cpumap.h" |
---|
19 | 21 | |
---|
20 | 22 | #include <err.h> |
---|
21 | 23 | #include <stdlib.h> |
---|
.. | .. |
---|
35 | 37 | static bool done = false, fshared = false; |
---|
36 | 38 | static unsigned int nthreads = 0; |
---|
37 | 39 | static int futex_flag = 0; |
---|
38 | | -struct timeval start, end, runtime; |
---|
39 | 40 | static pthread_mutex_t thread_lock; |
---|
40 | 41 | static unsigned int threads_starting; |
---|
41 | 42 | static struct stats throughput_stats; |
---|
.. | .. |
---|
62 | 63 | |
---|
63 | 64 | printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n", |
---|
64 | 65 | !silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg), |
---|
65 | | - (int) runtime.tv_sec); |
---|
| 66 | + (int)bench__runtime.tv_sec); |
---|
66 | 67 | } |
---|
67 | 68 | |
---|
68 | 69 | static void toggle_done(int sig __maybe_unused, |
---|
.. | .. |
---|
71 | 72 | { |
---|
72 | 73 | /* inform all threads that we're done for the day */ |
---|
73 | 74 | done = true; |
---|
74 | | - gettimeofday(&end, NULL); |
---|
75 | | - timersub(&end, &start, &runtime); |
---|
| 75 | + gettimeofday(&bench__end, NULL); |
---|
| 76 | + timersub(&bench__end, &bench__start, &bench__runtime); |
---|
76 | 77 | } |
---|
77 | 78 | |
---|
78 | 79 | static void *workerfn(void *arg) |
---|
.. | .. |
---|
115 | 116 | } |
---|
116 | 117 | |
---|
117 | 118 | static void create_threads(struct worker *w, pthread_attr_t thread_attr, |
---|
118 | | - struct cpu_map *cpu) |
---|
| 119 | + struct perf_cpu_map *cpu) |
---|
119 | 120 | { |
---|
120 | 121 | cpu_set_t cpuset; |
---|
121 | 122 | unsigned int i; |
---|
.. | .. |
---|
149 | 150 | unsigned int i; |
---|
150 | 151 | struct sigaction act; |
---|
151 | 152 | pthread_attr_t thread_attr; |
---|
152 | | - struct cpu_map *cpu; |
---|
| 153 | + struct perf_cpu_map *cpu; |
---|
153 | 154 | |
---|
154 | 155 | argc = parse_options(argc, argv, options, bench_futex_lock_pi_usage, 0); |
---|
155 | 156 | if (argc) |
---|
156 | 157 | goto err; |
---|
157 | 158 | |
---|
158 | | - cpu = cpu_map__new(NULL); |
---|
| 159 | + cpu = perf_cpu_map__new(NULL); |
---|
159 | 160 | if (!cpu) |
---|
160 | 161 | err(EXIT_FAILURE, "calloc"); |
---|
161 | 162 | |
---|
| 163 | + memset(&act, 0, sizeof(act)); |
---|
162 | 164 | sigfillset(&act.sa_mask); |
---|
163 | 165 | act.sa_sigaction = toggle_done; |
---|
164 | 166 | sigaction(SIGINT, &act, NULL); |
---|
.. | .. |
---|
183 | 185 | |
---|
184 | 186 | threads_starting = nthreads; |
---|
185 | 187 | pthread_attr_init(&thread_attr); |
---|
186 | | - gettimeofday(&start, NULL); |
---|
| 188 | + gettimeofday(&bench__start, NULL); |
---|
187 | 189 | |
---|
188 | 190 | create_threads(worker, thread_attr, cpu); |
---|
189 | 191 | pthread_attr_destroy(&thread_attr); |
---|
.. | .. |
---|
209 | 211 | pthread_mutex_destroy(&thread_lock); |
---|
210 | 212 | |
---|
211 | 213 | for (i = 0; i < nthreads; i++) { |
---|
212 | | - unsigned long t = worker[i].ops/runtime.tv_sec; |
---|
| 214 | + unsigned long t = bench__runtime.tv_sec > 0 ? |
---|
| 215 | + worker[i].ops / bench__runtime.tv_sec : 0; |
---|
213 | 216 | |
---|
214 | 217 | update_stats(&throughput_stats, t); |
---|
215 | 218 | if (!silent) |
---|
.. | .. |
---|
217 | 220 | worker[i].tid, worker[i].futex, t); |
---|
218 | 221 | |
---|
219 | 222 | if (multi) |
---|
220 | | - free(worker[i].futex); |
---|
| 223 | + zfree(&worker[i].futex); |
---|
221 | 224 | } |
---|
222 | 225 | |
---|
223 | 226 | print_summary(); |
---|
224 | 227 | |
---|
225 | 228 | free(worker); |
---|
| 229 | + perf_cpu_map__put(cpu); |
---|
226 | 230 | return ret; |
---|
227 | 231 | err: |
---|
228 | 232 | usage_with_options(bench_futex_lock_pi_usage, options); |
---|