blob: e938ccf3dea13ad1a72937fe3956902ee8d1df34 [file] [log] [blame]
Andrew Geissler7eb438a2020-11-30 19:53:16 -06001From df35e878d0a51755fb500e2e8e29c7ebb0239756 Mon Sep 17 00:00:00 2001
2From: Arnaldo Carvalho de Melo <acme@redhat.com>
3Date: Mon, 2 Mar 2020 12:09:38 -0300
4Subject: [PATCH] perf bench: Share some global variables to fix build with gcc
5 10
6
7commit e4d9b04b973b2dbce7b42af95ea70d07da1c936d upstream.
8
9Noticed with gcc 10 (fedora rawhide) that those variables were not being
10declared as static, so end up with:
11
12 ld: /tmp/build/perf/bench/epoll-wait.o:/git/perf/tools/perf/bench/epoll-wait.c:93: multiple definition of `end'; /tmp/build/perf/bench/futex-hash.o:/git/perf/tools/perf/bench/futex-hash.c:40: first defined here
13 ld: /tmp/build/perf/bench/epoll-wait.o:/git/perf/tools/perf/bench/epoll-wait.c:93: multiple definition of `start'; /tmp/build/perf/bench/futex-hash.o:/git/perf/tools/perf/bench/futex-hash.c:40: first defined here
14 ld: /tmp/build/perf/bench/epoll-wait.o:/git/perf/tools/perf/bench/epoll-wait.c:93: multiple definition of `runtime'; /tmp/build/perf/bench/futex-hash.o:/git/perf/tools/perf/bench/futex-hash.c:40: first defined here
15 ld: /tmp/build/perf/bench/epoll-ctl.o:/git/perf/tools/perf/bench/epoll-ctl.c:38: multiple definition of `end'; /tmp/build/perf/bench/futex-hash.o:/git/perf/tools/perf/bench/futex-hash.c:40: first defined here
16 ld: /tmp/build/perf/bench/epoll-ctl.o:/git/perf/tools/perf/bench/epoll-ctl.c:38: multiple definition of `start'; /tmp/build/perf/bench/futex-hash.o:/git/perf/tools/perf/bench/futex-hash.c:40: first defined here
17 ld: /tmp/build/perf/bench/epoll-ctl.o:/git/perf/tools/perf/bench/epoll-ctl.c:38: multiple definition of `runtime'; /tmp/build/perf/bench/futex-hash.o:/git/perf/tools/perf/bench/futex-hash.c:40: first defined here
18 make[4]: *** [/git/perf/tools/build/Makefile.build:145: /tmp/build/perf/bench/perf-in.o] Error 1
19
20Prefix those with bench__ and add them to bench/bench.h, so that we can
21share those on the tools needing to access those variables from signal
22handlers.
23
24Acked-by: Thomas Gleixner <tglx@linutronix.de>
25Cc: Adrian Hunter <adrian.hunter@intel.com>
26Cc: Davidlohr Bueso <dave@stgolabs.net>
27Cc: Jiri Olsa <jolsa@kernel.org>
28Cc: Namhyung Kim <namhyung@kernel.org>
29Link: http://lore.kernel.org/lkml/20200303155811.GD13702@kernel.org
30Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
31Cc: Ben Hutchings <ben@decadent.org.uk>
32Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33---
34 tools/perf/bench/bench.h | 4 ++++
35 tools/perf/bench/epoll-ctl.c | 7 +++----
36 tools/perf/bench/epoll-wait.c | 11 +++++------
37 tools/perf/bench/futex-hash.c | 12 ++++++------
38 tools/perf/bench/futex-lock-pi.c | 11 +++++------
39 5 files changed, 23 insertions(+), 22 deletions(-)
40
41diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h
42index fddb3ce..4aa6de1 100644
43--- a/tools/perf/bench/bench.h
44+++ b/tools/perf/bench/bench.h
45@@ -2,6 +2,10 @@
46 #ifndef BENCH_H
47 #define BENCH_H
48
49+#include <sys/time.h>
50+
51+extern struct timeval bench__start, bench__end, bench__runtime;
52+
53 /*
54 * The madvise transparent hugepage constants were added in glibc
55 * 2.13. For compatibility with older versions of glibc, define these
56diff --git a/tools/perf/bench/epoll-ctl.c b/tools/perf/bench/epoll-ctl.c
57index bb617e5..a7526c0 100644
58--- a/tools/perf/bench/epoll-ctl.c
59+++ b/tools/perf/bench/epoll-ctl.c
60@@ -35,7 +35,6 @@
61
62 static unsigned int nthreads = 0;
63 static unsigned int nsecs = 8;
64-struct timeval start, end, runtime;
65 static bool done, __verbose, randomize;
66
67 /*
68@@ -94,8 +93,8 @@ static void toggle_done(int sig __maybe_unused,
69 {
70 /* inform all threads that we're done for the day */
71 done = true;
72- gettimeofday(&end, NULL);
73- timersub(&end, &start, &runtime);
74+ gettimeofday(&bench__end, NULL);
75+ timersub(&bench__end, &bench__start, &bench__runtime);
76 }
77
78 static void nest_epollfd(void)
79@@ -361,7 +360,7 @@ int bench_epoll_ctl(int argc, const char **argv)
80
81 threads_starting = nthreads;
82
83- gettimeofday(&start, NULL);
84+ gettimeofday(&bench__start, NULL);
85
86 do_threads(worker, cpu);
87
88diff --git a/tools/perf/bench/epoll-wait.c b/tools/perf/bench/epoll-wait.c
89index 7af6944..d1c5cb5 100644
90--- a/tools/perf/bench/epoll-wait.c
91+++ b/tools/perf/bench/epoll-wait.c
92@@ -90,7 +90,6 @@
93
94 static unsigned int nthreads = 0;
95 static unsigned int nsecs = 8;
96-struct timeval start, end, runtime;
97 static bool wdone, done, __verbose, randomize, nonblocking;
98
99 /*
100@@ -276,8 +275,8 @@ static void toggle_done(int sig __maybe_unused,
101 {
102 /* inform all threads that we're done for the day */
103 done = true;
104- gettimeofday(&end, NULL);
105- timersub(&end, &start, &runtime);
106+ gettimeofday(&bench__end, NULL);
107+ timersub(&bench__end, &bench__start, &bench__runtime);
108 }
109
110 static void print_summary(void)
111@@ -287,7 +286,7 @@ static void print_summary(void)
112
113 printf("\nAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n",
114 avg, rel_stddev_stats(stddev, avg),
115- (int) runtime.tv_sec);
116+ (int)bench__runtime.tv_sec);
117 }
118
119 static int do_threads(struct worker *worker, struct perf_cpu_map *cpu)
120@@ -479,7 +478,7 @@ int bench_epoll_wait(int argc, const char **argv)
121
122 threads_starting = nthreads;
123
124- gettimeofday(&start, NULL);
125+ gettimeofday(&bench__start, NULL);
126
127 do_threads(worker, cpu);
128
129@@ -519,7 +518,7 @@ int bench_epoll_wait(int argc, const char **argv)
130 qsort(worker, nthreads, sizeof(struct worker), cmpworker);
131
132 for (i = 0; i < nthreads; i++) {
133- unsigned long t = worker[i].ops/runtime.tv_sec;
134+ unsigned long t = worker[i].ops / bench__runtime.tv_sec;
135
136 update_stats(&throughput_stats, t);
137
138diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c
139index 8ba0c33..2177686 100644
140--- a/tools/perf/bench/futex-hash.c
141+++ b/tools/perf/bench/futex-hash.c
142@@ -37,7 +37,7 @@ static unsigned int nfutexes = 1024;
143 static bool fshared = false, done = false, silent = false;
144 static int futex_flag = 0;
145
146-struct timeval start, end, runtime;
147+struct timeval bench__start, bench__end, bench__runtime;
148 static pthread_mutex_t thread_lock;
149 static unsigned int threads_starting;
150 static struct stats throughput_stats;
151@@ -103,8 +103,8 @@ static void toggle_done(int sig __maybe_unused,
152 {
153 /* inform all threads that we're done for the day */
154 done = true;
155- gettimeofday(&end, NULL);
156- timersub(&end, &start, &runtime);
157+ gettimeofday(&bench__end, NULL);
158+ timersub(&bench__end, &bench__start, &bench__runtime);
159 }
160
161 static void print_summary(void)
162@@ -114,7 +114,7 @@ static void print_summary(void)
163
164 printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n",
165 !silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg),
166- (int) runtime.tv_sec);
167+ (int)bench__runtime.tv_sec);
168 }
169
170 int bench_futex_hash(int argc, const char **argv)
171@@ -161,7 +161,7 @@ int bench_futex_hash(int argc, const char **argv)
172
173 threads_starting = nthreads;
174 pthread_attr_init(&thread_attr);
175- gettimeofday(&start, NULL);
176+ gettimeofday(&bench__start, NULL);
177 for (i = 0; i < nthreads; i++) {
178 worker[i].tid = i;
179 worker[i].futex = calloc(nfutexes, sizeof(*worker[i].futex));
180@@ -204,7 +204,7 @@ int bench_futex_hash(int argc, const char **argv)
181 pthread_mutex_destroy(&thread_lock);
182
183 for (i = 0; i < nthreads; i++) {
184- unsigned long t = worker[i].ops/runtime.tv_sec;
185+ unsigned long t = worker[i].ops / bench__runtime.tv_sec;
186 update_stats(&throughput_stats, t);
187 if (!silent) {
188 if (nfutexes == 1)
189diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c
190index d0cae81..30d9712 100644
191--- a/tools/perf/bench/futex-lock-pi.c
192+++ b/tools/perf/bench/futex-lock-pi.c
193@@ -37,7 +37,6 @@ static bool silent = false, multi = false;
194 static bool done = false, fshared = false;
195 static unsigned int nthreads = 0;
196 static int futex_flag = 0;
197-struct timeval start, end, runtime;
198 static pthread_mutex_t thread_lock;
199 static unsigned int threads_starting;
200 static struct stats throughput_stats;
201@@ -64,7 +63,7 @@ static void print_summary(void)
202
203 printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n",
204 !silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg),
205- (int) runtime.tv_sec);
206+ (int)bench__runtime.tv_sec);
207 }
208
209 static void toggle_done(int sig __maybe_unused,
210@@ -73,8 +72,8 @@ static void toggle_done(int sig __maybe_unused,
211 {
212 /* inform all threads that we're done for the day */
213 done = true;
214- gettimeofday(&end, NULL);
215- timersub(&end, &start, &runtime);
216+ gettimeofday(&bench__end, NULL);
217+ timersub(&bench__end, &bench__start, &bench__runtime);
218 }
219
220 static void *workerfn(void *arg)
221@@ -185,7 +184,7 @@ int bench_futex_lock_pi(int argc, const char **argv)
222
223 threads_starting = nthreads;
224 pthread_attr_init(&thread_attr);
225- gettimeofday(&start, NULL);
226+ gettimeofday(&bench__start, NULL);
227
228 create_threads(worker, thread_attr, cpu);
229 pthread_attr_destroy(&thread_attr);
230@@ -211,7 +210,7 @@ int bench_futex_lock_pi(int argc, const char **argv)
231 pthread_mutex_destroy(&thread_lock);
232
233 for (i = 0; i < nthreads; i++) {
234- unsigned long t = worker[i].ops/runtime.tv_sec;
235+ unsigned long t = worker[i].ops / bench__runtime.tv_sec;
236
237 update_stats(&throughput_stats, t);
238 if (!silent)
239--
2402.7.4
241