Skip to content

Commit e4d9b04

Browse files
committed
perf bench: Share some global variables to fix build with gcc 10
Noticed with gcc 10 (fedora rawhide) that those variables were not being declared as static, so end up with: 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 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 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 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 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 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 make[4]: *** [/git/perf/tools/build/Makefile.build:145: /tmp/build/perf/bench/perf-in.o] Error 1 Prefix those with bench__ and add them to bench/bench.h, so that we can share those on the tools needing to access those variables from signal handlers. Acked-by: Thomas Gleixner <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 7125f20 commit e4d9b04

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

tools/perf/bench/bench.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#ifndef BENCH_H
33
#define BENCH_H
44

5+
#include <sys/time.h>
6+
7+
extern struct timeval bench__start, bench__end, bench__runtime;
8+
59
/*
610
* The madvise transparent hugepage constants were added in glibc
711
* 2.13. For compatibility with older versions of glibc, define these

tools/perf/bench/epoll-ctl.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
static unsigned int nthreads = 0;
3737
static unsigned int nsecs = 8;
38-
struct timeval start, end, runtime;
3938
static bool done, __verbose, randomize;
4039

4140
/*
@@ -94,8 +93,8 @@ static void toggle_done(int sig __maybe_unused,
9493
{
9594
/* inform all threads that we're done for the day */
9695
done = true;
97-
gettimeofday(&end, NULL);
98-
timersub(&end, &start, &runtime);
96+
gettimeofday(&bench__end, NULL);
97+
timersub(&bench__end, &bench__start, &bench__runtime);
9998
}
10099

101100
static void nest_epollfd(void)
@@ -361,7 +360,7 @@ int bench_epoll_ctl(int argc, const char **argv)
361360

362361
threads_starting = nthreads;
363362

364-
gettimeofday(&start, NULL);
363+
gettimeofday(&bench__start, NULL);
365364

366365
do_threads(worker, cpu);
367366

tools/perf/bench/epoll-wait.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090

9191
static unsigned int nthreads = 0;
9292
static unsigned int nsecs = 8;
93-
struct timeval start, end, runtime;
9493
static bool wdone, done, __verbose, randomize, nonblocking;
9594

9695
/*
@@ -276,8 +275,8 @@ static void toggle_done(int sig __maybe_unused,
276275
{
277276
/* inform all threads that we're done for the day */
278277
done = true;
279-
gettimeofday(&end, NULL);
280-
timersub(&end, &start, &runtime);
278+
gettimeofday(&bench__end, NULL);
279+
timersub(&bench__end, &bench__start, &bench__runtime);
281280
}
282281

283282
static void print_summary(void)
@@ -287,7 +286,7 @@ static void print_summary(void)
287286

288287
printf("\nAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n",
289288
avg, rel_stddev_stats(stddev, avg),
290-
(int) runtime.tv_sec);
289+
(int)bench__runtime.tv_sec);
291290
}
292291

293292
static int do_threads(struct worker *worker, struct perf_cpu_map *cpu)
@@ -479,7 +478,7 @@ int bench_epoll_wait(int argc, const char **argv)
479478

480479
threads_starting = nthreads;
481480

482-
gettimeofday(&start, NULL);
481+
gettimeofday(&bench__start, NULL);
483482

484483
do_threads(worker, cpu);
485484

@@ -519,7 +518,7 @@ int bench_epoll_wait(int argc, const char **argv)
519518
qsort(worker, nthreads, sizeof(struct worker), cmpworker);
520519

521520
for (i = 0; i < nthreads; i++) {
522-
unsigned long t = worker[i].ops/runtime.tv_sec;
521+
unsigned long t = worker[i].ops / bench__runtime.tv_sec;
523522

524523
update_stats(&throughput_stats, t);
525524

tools/perf/bench/futex-hash.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static unsigned int nfutexes = 1024;
3737
static bool fshared = false, done = false, silent = false;
3838
static int futex_flag = 0;
3939

40-
struct timeval start, end, runtime;
40+
struct timeval bench__start, bench__end, bench__runtime;
4141
static pthread_mutex_t thread_lock;
4242
static unsigned int threads_starting;
4343
static struct stats throughput_stats;
@@ -103,8 +103,8 @@ static void toggle_done(int sig __maybe_unused,
103103
{
104104
/* inform all threads that we're done for the day */
105105
done = true;
106-
gettimeofday(&end, NULL);
107-
timersub(&end, &start, &runtime);
106+
gettimeofday(&bench__end, NULL);
107+
timersub(&bench__end, &bench__start, &bench__runtime);
108108
}
109109

110110
static void print_summary(void)
@@ -114,7 +114,7 @@ static void print_summary(void)
114114

115115
printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n",
116116
!silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg),
117-
(int) runtime.tv_sec);
117+
(int)bench__runtime.tv_sec);
118118
}
119119

120120
int bench_futex_hash(int argc, const char **argv)
@@ -161,7 +161,7 @@ int bench_futex_hash(int argc, const char **argv)
161161

162162
threads_starting = nthreads;
163163
pthread_attr_init(&thread_attr);
164-
gettimeofday(&start, NULL);
164+
gettimeofday(&bench__start, NULL);
165165
for (i = 0; i < nthreads; i++) {
166166
worker[i].tid = i;
167167
worker[i].futex = calloc(nfutexes, sizeof(*worker[i].futex));
@@ -204,7 +204,7 @@ int bench_futex_hash(int argc, const char **argv)
204204
pthread_mutex_destroy(&thread_lock);
205205

206206
for (i = 0; i < nthreads; i++) {
207-
unsigned long t = worker[i].ops/runtime.tv_sec;
207+
unsigned long t = worker[i].ops / bench__runtime.tv_sec;
208208
update_stats(&throughput_stats, t);
209209
if (!silent) {
210210
if (nfutexes == 1)

tools/perf/bench/futex-lock-pi.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ static bool silent = false, multi = false;
3737
static bool done = false, fshared = false;
3838
static unsigned int nthreads = 0;
3939
static int futex_flag = 0;
40-
struct timeval start, end, runtime;
4140
static pthread_mutex_t thread_lock;
4241
static unsigned int threads_starting;
4342
static struct stats throughput_stats;
@@ -64,7 +63,7 @@ static void print_summary(void)
6463

6564
printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n",
6665
!silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg),
67-
(int) runtime.tv_sec);
66+
(int)bench__runtime.tv_sec);
6867
}
6968

7069
static void toggle_done(int sig __maybe_unused,
@@ -73,8 +72,8 @@ static void toggle_done(int sig __maybe_unused,
7372
{
7473
/* inform all threads that we're done for the day */
7574
done = true;
76-
gettimeofday(&end, NULL);
77-
timersub(&end, &start, &runtime);
75+
gettimeofday(&bench__end, NULL);
76+
timersub(&bench__end, &bench__start, &bench__runtime);
7877
}
7978

8079
static void *workerfn(void *arg)
@@ -185,7 +184,7 @@ int bench_futex_lock_pi(int argc, const char **argv)
185184

186185
threads_starting = nthreads;
187186
pthread_attr_init(&thread_attr);
188-
gettimeofday(&start, NULL);
187+
gettimeofday(&bench__start, NULL);
189188

190189
create_threads(worker, thread_attr, cpu);
191190
pthread_attr_destroy(&thread_attr);
@@ -211,7 +210,7 @@ int bench_futex_lock_pi(int argc, const char **argv)
211210
pthread_mutex_destroy(&thread_lock);
212211

213212
for (i = 0; i < nthreads; i++) {
214-
unsigned long t = worker[i].ops/runtime.tv_sec;
213+
unsigned long t = worker[i].ops / bench__runtime.tv_sec;
215214

216215
update_stats(&throughput_stats, t);
217216
if (!silent)

0 commit comments

Comments
 (0)