hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
From 5c4552ed28c6c1dba16d8d6c15a5597200dcfb24 Mon Sep 17 00:00:00 2001
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Mon, 2 Mar 2020 12:09:38 -0300
Subject: [PATCH 3/7] 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 <tglx@linutronix.de>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lore.kernel.org/lkml/20200303155811.GD13702@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
(cherry picked from commit e4d9b04b973b2dbce7b42af95ea70d07da1c936d)
 
Conflicts:
   tools/perf/bench/epoll-ctl.c
   tools/perf/bench/epoll-wait.c
 
Change-Id: I20356d0219c99797b1fc1c4ccd072ed6748ea986
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
 tools/perf/bench/bench.h         |  4 ++++
 tools/perf/bench/futex-hash.c    | 12 ++++++------
 tools/perf/bench/futex-lock-pi.c | 11 +++++------
 3 files changed, 15 insertions(+), 12 deletions(-)
 
diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h
index a50df86f2b9b..e758896f4995 100644
--- a/tools/perf/bench/bench.h
+++ b/tools/perf/bench/bench.h
@@ -1,6 +1,10 @@
 #ifndef BENCH_H
 #define BENCH_H
 
+#include <sys/time.h>
+
+extern struct timeval bench__start, bench__end, bench__runtime;
+
 /*
  * The madvise transparent hugepage constants were added in glibc
  * 2.13. For compatibility with older versions of glibc, define these
diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c
index fc9bebd2cca0..7e21cb74906e 100644
--- a/tools/perf/bench/futex-hash.c
+++ b/tools/perf/bench/futex-hash.c
@@ -28,7 +28,7 @@ static unsigned int nfutexes = 1024;
 static bool fshared = false, done = false, silent = false;
 static int futex_flag = 0;
 
-struct timeval start, end, runtime;
+struct timeval bench__start, bench__end, bench__runtime;
 static pthread_mutex_t thread_lock;
 static unsigned int threads_starting;
 static struct stats throughput_stats;
@@ -92,8 +92,8 @@ static void toggle_done(int sig __maybe_unused,
 {
     /* inform all threads that we're done for the day */
     done = true;
-    gettimeofday(&end, NULL);
-    timersub(&end, &start, &runtime);
+    gettimeofday(&bench__end, NULL);
+    timersub(&bench__end, &bench__start, &bench__runtime);
 }
 
 static void print_summary(void)
@@ -103,7 +103,7 @@ static void print_summary(void)
 
     printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n",
            !silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg),
-           (int) runtime.tv_sec);
+           (int)bench__runtime.tv_sec);
 }
 
 int bench_futex_hash(int argc, const char **argv,
@@ -148,7 +148,7 @@ int bench_futex_hash(int argc, const char **argv,
 
     threads_starting = nthreads;
     pthread_attr_init(&thread_attr);
-    gettimeofday(&start, NULL);
+    gettimeofday(&bench__start, NULL);
     for (i = 0; i < nthreads; i++) {
         worker[i].tid = i;
         worker[i].futex = calloc(nfutexes, sizeof(*worker[i].futex));
@@ -191,7 +191,7 @@ int bench_futex_hash(int argc, const char **argv,
     pthread_mutex_destroy(&thread_lock);
 
     for (i = 0; i < nthreads; i++) {
-        unsigned long t = worker[i].ops/runtime.tv_sec;
+        unsigned long t = worker[i].ops / bench__runtime.tv_sec;
         update_stats(&throughput_stats, t);
         if (!silent) {
             if (nfutexes == 1)
diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c
index bc6a16adbca8..246ac8fde596 100644
--- a/tools/perf/bench/futex-lock-pi.c
+++ b/tools/perf/bench/futex-lock-pi.c
@@ -29,7 +29,6 @@ static bool silent = false, multi = false;
 static bool done = false, fshared = false;
 static unsigned int ncpus, nthreads = 0;
 static int futex_flag = 0;
-struct timeval start, end, runtime;
 static pthread_mutex_t thread_lock;
 static unsigned int threads_starting;
 static struct stats throughput_stats;
@@ -56,7 +55,7 @@ static void print_summary(void)
 
     printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n",
            !silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg),
-           (int) runtime.tv_sec);
+           (int)bench__runtime.tv_sec);
 }
 
 static void toggle_done(int sig __maybe_unused,
@@ -65,8 +64,8 @@ static void toggle_done(int sig __maybe_unused,
 {
     /* inform all threads that we're done for the day */
     done = true;
-    gettimeofday(&end, NULL);
-    timersub(&end, &start, &runtime);
+    gettimeofday(&bench__end, NULL);
+    timersub(&bench__end, &bench__start, &bench__runtime);
 }
 
 static void *workerfn(void *arg)
@@ -172,7 +171,7 @@ int bench_futex_lock_pi(int argc, const char **argv,
 
     threads_starting = nthreads;
     pthread_attr_init(&thread_attr);
-    gettimeofday(&start, NULL);
+    gettimeofday(&bench__start, NULL);
 
     create_threads(worker, thread_attr);
     pthread_attr_destroy(&thread_attr);
@@ -198,7 +197,7 @@ int bench_futex_lock_pi(int argc, const char **argv,
     pthread_mutex_destroy(&thread_lock);
 
     for (i = 0; i < nthreads; i++) {
-        unsigned long t = worker[i].ops/runtime.tv_sec;
+        unsigned long t = worker[i].ops / bench__runtime.tv_sec;
 
         update_stats(&throughput_stats, t);
         if (!silent)
-- 
2.20.1