hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/tools/perf/bench/futex-hash.c
....@@ -18,13 +18,15 @@
1818 #include <stdlib.h>
1919 #include <linux/compiler.h>
2020 #include <linux/kernel.h>
21
+#include <linux/zalloc.h>
2122 #include <sys/time.h>
23
+#include <internal/cpumap.h>
24
+#include <perf/cpumap.h>
2225
2326 #include "../util/stat.h"
2427 #include <subcmd/parse-options.h>
2528 #include "bench.h"
2629 #include "futex.h"
27
-#include "cpumap.h"
2830
2931 #include <err.h>
3032
....@@ -35,7 +37,7 @@
3537 static bool fshared = false, done = false, silent = false;
3638 static int futex_flag = 0;
3739
38
-struct timeval start, end, runtime;
40
+struct timeval bench__start, bench__end, bench__runtime;
3941 static pthread_mutex_t thread_lock;
4042 static unsigned int threads_starting;
4143 static struct stats throughput_stats;
....@@ -101,8 +103,8 @@
101103 {
102104 /* inform all threads that we're done for the day */
103105 done = true;
104
- gettimeofday(&end, NULL);
105
- timersub(&end, &start, &runtime);
106
+ gettimeofday(&bench__end, NULL);
107
+ timersub(&bench__end, &bench__start, &bench__runtime);
106108 }
107109
108110 static void print_summary(void)
....@@ -112,7 +114,7 @@
112114
113115 printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n",
114116 !silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg),
115
- (int) runtime.tv_sec);
117
+ (int)bench__runtime.tv_sec);
116118 }
117119
118120 int bench_futex_hash(int argc, const char **argv)
....@@ -123,7 +125,7 @@
123125 unsigned int i;
124126 pthread_attr_t thread_attr;
125127 struct worker *worker = NULL;
126
- struct cpu_map *cpu;
128
+ struct perf_cpu_map *cpu;
127129
128130 argc = parse_options(argc, argv, options, bench_futex_hash_usage, 0);
129131 if (argc) {
....@@ -131,10 +133,11 @@
131133 exit(EXIT_FAILURE);
132134 }
133135
134
- cpu = cpu_map__new(NULL);
136
+ cpu = perf_cpu_map__new(NULL);
135137 if (!cpu)
136138 goto errmem;
137139
140
+ memset(&act, 0, sizeof(act));
138141 sigfillset(&act.sa_mask);
139142 act.sa_sigaction = toggle_done;
140143 sigaction(SIGINT, &act, NULL);
....@@ -159,7 +162,7 @@
159162
160163 threads_starting = nthreads;
161164 pthread_attr_init(&thread_attr);
162
- gettimeofday(&start, NULL);
165
+ gettimeofday(&bench__start, NULL);
163166 for (i = 0; i < nthreads; i++) {
164167 worker[i].tid = i;
165168 worker[i].futex = calloc(nfutexes, sizeof(*worker[i].futex));
....@@ -202,7 +205,8 @@
202205 pthread_mutex_destroy(&thread_lock);
203206
204207 for (i = 0; i < nthreads; i++) {
205
- unsigned long t = worker[i].ops/runtime.tv_sec;
208
+ unsigned long t = bench__runtime.tv_sec > 0 ?
209
+ worker[i].ops / bench__runtime.tv_sec : 0;
206210 update_stats(&throughput_stats, t);
207211 if (!silent) {
208212 if (nfutexes == 1)
....@@ -214,7 +218,7 @@
214218 &worker[i].futex[nfutexes-1], t);
215219 }
216220
217
- free(worker[i].futex);
221
+ zfree(&worker[i].futex);
218222 }
219223
220224 print_summary();