hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/tools/perf/bench/futex-lock-pi.c
....@@ -12,10 +12,12 @@
1212 #include <subcmd/parse-options.h>
1313 #include <linux/compiler.h>
1414 #include <linux/kernel.h>
15
+#include <linux/zalloc.h>
1516 #include <errno.h>
17
+#include <internal/cpumap.h>
18
+#include <perf/cpumap.h>
1619 #include "bench.h"
1720 #include "futex.h"
18
-#include "cpumap.h"
1921
2022 #include <err.h>
2123 #include <stdlib.h>
....@@ -35,7 +37,6 @@
3537 static bool done = false, fshared = false;
3638 static unsigned int nthreads = 0;
3739 static int futex_flag = 0;
38
-struct timeval start, end, runtime;
3940 static pthread_mutex_t thread_lock;
4041 static unsigned int threads_starting;
4142 static struct stats throughput_stats;
....@@ -62,7 +63,7 @@
6263
6364 printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n",
6465 !silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg),
65
- (int) runtime.tv_sec);
66
+ (int)bench__runtime.tv_sec);
6667 }
6768
6869 static void toggle_done(int sig __maybe_unused,
....@@ -71,8 +72,8 @@
7172 {
7273 /* inform all threads that we're done for the day */
7374 done = true;
74
- gettimeofday(&end, NULL);
75
- timersub(&end, &start, &runtime);
75
+ gettimeofday(&bench__end, NULL);
76
+ timersub(&bench__end, &bench__start, &bench__runtime);
7677 }
7778
7879 static void *workerfn(void *arg)
....@@ -115,7 +116,7 @@
115116 }
116117
117118 static void create_threads(struct worker *w, pthread_attr_t thread_attr,
118
- struct cpu_map *cpu)
119
+ struct perf_cpu_map *cpu)
119120 {
120121 cpu_set_t cpuset;
121122 unsigned int i;
....@@ -149,16 +150,17 @@
149150 unsigned int i;
150151 struct sigaction act;
151152 pthread_attr_t thread_attr;
152
- struct cpu_map *cpu;
153
+ struct perf_cpu_map *cpu;
153154
154155 argc = parse_options(argc, argv, options, bench_futex_lock_pi_usage, 0);
155156 if (argc)
156157 goto err;
157158
158
- cpu = cpu_map__new(NULL);
159
+ cpu = perf_cpu_map__new(NULL);
159160 if (!cpu)
160161 err(EXIT_FAILURE, "calloc");
161162
163
+ memset(&act, 0, sizeof(act));
162164 sigfillset(&act.sa_mask);
163165 act.sa_sigaction = toggle_done;
164166 sigaction(SIGINT, &act, NULL);
....@@ -183,7 +185,7 @@
183185
184186 threads_starting = nthreads;
185187 pthread_attr_init(&thread_attr);
186
- gettimeofday(&start, NULL);
188
+ gettimeofday(&bench__start, NULL);
187189
188190 create_threads(worker, thread_attr, cpu);
189191 pthread_attr_destroy(&thread_attr);
....@@ -209,7 +211,8 @@
209211 pthread_mutex_destroy(&thread_lock);
210212
211213 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;
213216
214217 update_stats(&throughput_stats, t);
215218 if (!silent)
....@@ -217,12 +220,13 @@
217220 worker[i].tid, worker[i].futex, t);
218221
219222 if (multi)
220
- free(worker[i].futex);
223
+ zfree(&worker[i].futex);
221224 }
222225
223226 print_summary();
224227
225228 free(worker);
229
+ perf_cpu_map__put(cpu);
226230 return ret;
227231 err:
228232 usage_with_options(bench_futex_lock_pi_usage, options);