|
| 1 | +From 62b75df5f013d9f7b5b47ff5369dd4b3143ab965 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Gleb Mazovetskiy <glex.spb@gmail.com> |
| 3 | +Date: Mon, 25 Jan 2021 00:52:10 +0000 |
| 4 | +Subject: [PATCH 02/12] perf bench: Share some global variables to fix build |
| 5 | + with gcc 10 |
| 6 | + |
| 7 | +Based on https://git.yoctoproject.org/cgit/cgit.cgi/meta-arm/tree/meta-arm-bsp/recipes-kernel/linux/linux-yocto-5.3/0003-perf-bench-Share-some-global-variables-to-fix-build-.patch |
| 8 | + |
| 9 | +Signed-off-by: Gleb Mazovetskiy <glex.spb@gmail.com> |
| 10 | +--- |
| 11 | + tools/perf/bench/bench.h | 4 ++++ |
| 12 | + tools/perf/bench/futex-hash.c | 12 ++++++------ |
| 13 | + tools/perf/bench/futex-lock-pi.c | 11 +++++------ |
| 14 | + 3 files changed, 15 insertions(+), 12 deletions(-) |
| 15 | + |
| 16 | +diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h |
| 17 | +index a50df86f2b9b..e758896f4995 100644 |
| 18 | +--- a/tools/perf/bench/bench.h |
| 19 | ++++ b/tools/perf/bench/bench.h |
| 20 | +@@ -1,6 +1,10 @@ |
| 21 | + #ifndef BENCH_H |
| 22 | + #define BENCH_H |
| 23 | + |
| 24 | ++#include <sys/time.h> |
| 25 | ++ |
| 26 | ++extern struct timeval bench__start, bench__end, bench__runtime; |
| 27 | ++ |
| 28 | + /* |
| 29 | + * The madvise transparent hugepage constants were added in glibc |
| 30 | + * 2.13. For compatibility with older versions of glibc, define these |
| 31 | +diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c |
| 32 | +index fc9bebd2cca0..80313b40d324 100644 |
| 33 | +--- a/tools/perf/bench/futex-hash.c |
| 34 | ++++ b/tools/perf/bench/futex-hash.c |
| 35 | +@@ -28,7 +28,7 @@ static unsigned int nfutexes = 1024; |
| 36 | + static bool fshared = false, done = false, silent = false; |
| 37 | + static int futex_flag = 0; |
| 38 | + |
| 39 | +-struct timeval start, end, runtime; |
| 40 | ++struct timeval bench__start, bench__end, bench__runtime; |
| 41 | + static pthread_mutex_t thread_lock; |
| 42 | + static unsigned int threads_starting; |
| 43 | + static struct stats throughput_stats; |
| 44 | +@@ -92,8 +92,8 @@ static void toggle_done(int sig __maybe_unused, |
| 45 | + { |
| 46 | + /* inform all threads that we're done for the day */ |
| 47 | + done = true; |
| 48 | +- gettimeofday(&end, NULL); |
| 49 | +- timersub(&end, &start, &runtime); |
| 50 | ++ gettimeofday(&bench__end, NULL); |
| 51 | ++ timersub(&bench__end, &bench__start, &bench__runtime); |
| 52 | + } |
| 53 | + |
| 54 | + static void print_summary(void) |
| 55 | +@@ -103,7 +103,7 @@ static void print_summary(void) |
| 56 | + |
| 57 | + printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n", |
| 58 | + !silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg), |
| 59 | +- (int) runtime.tv_sec); |
| 60 | ++ (int) bench__runtime.tv_sec); |
| 61 | + } |
| 62 | + |
| 63 | + int bench_futex_hash(int argc, const char **argv, |
| 64 | +@@ -148,7 +148,7 @@ int bench_futex_hash(int argc, const char **argv, |
| 65 | + |
| 66 | + threads_starting = nthreads; |
| 67 | + pthread_attr_init(&thread_attr); |
| 68 | +- gettimeofday(&start, NULL); |
| 69 | ++ gettimeofday(&bench__start, NULL); |
| 70 | + for (i = 0; i < nthreads; i++) { |
| 71 | + worker[i].tid = i; |
| 72 | + worker[i].futex = calloc(nfutexes, sizeof(*worker[i].futex)); |
| 73 | +@@ -191,7 +191,7 @@ int bench_futex_hash(int argc, const char **argv, |
| 74 | + pthread_mutex_destroy(&thread_lock); |
| 75 | + |
| 76 | + for (i = 0; i < nthreads; i++) { |
| 77 | +- unsigned long t = worker[i].ops/runtime.tv_sec; |
| 78 | ++ unsigned long t = worker[i].ops/bench__runtime.tv_sec; |
| 79 | + update_stats(&throughput_stats, t); |
| 80 | + if (!silent) { |
| 81 | + if (nfutexes == 1) |
| 82 | +diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c |
| 83 | +index bc6a16adbca8..8d0f60456a95 100644 |
| 84 | +--- a/tools/perf/bench/futex-lock-pi.c |
| 85 | ++++ b/tools/perf/bench/futex-lock-pi.c |
| 86 | +@@ -29,7 +29,6 @@ static bool silent = false, multi = false; |
| 87 | + static bool done = false, fshared = false; |
| 88 | + static unsigned int ncpus, nthreads = 0; |
| 89 | + static int futex_flag = 0; |
| 90 | +-struct timeval start, end, runtime; |
| 91 | + static pthread_mutex_t thread_lock; |
| 92 | + static unsigned int threads_starting; |
| 93 | + static struct stats throughput_stats; |
| 94 | +@@ -56,7 +55,7 @@ static void print_summary(void) |
| 95 | + |
| 96 | + printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n", |
| 97 | + !silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg), |
| 98 | +- (int) runtime.tv_sec); |
| 99 | ++ (int) bench__runtime.tv_sec); |
| 100 | + } |
| 101 | + |
| 102 | + static void toggle_done(int sig __maybe_unused, |
| 103 | +@@ -65,8 +64,8 @@ static void toggle_done(int sig __maybe_unused, |
| 104 | + { |
| 105 | + /* inform all threads that we're done for the day */ |
| 106 | + done = true; |
| 107 | +- gettimeofday(&end, NULL); |
| 108 | +- timersub(&end, &start, &runtime); |
| 109 | ++ gettimeofday(&bench__end, NULL); |
| 110 | ++ timersub(&bench__end, &bench__start, &bench__runtime); |
| 111 | + } |
| 112 | + |
| 113 | + static void *workerfn(void *arg) |
| 114 | +@@ -172,7 +171,7 @@ int bench_futex_lock_pi(int argc, const char **argv, |
| 115 | + |
| 116 | + threads_starting = nthreads; |
| 117 | + pthread_attr_init(&thread_attr); |
| 118 | +- gettimeofday(&start, NULL); |
| 119 | ++ gettimeofday(&bench__start, NULL); |
| 120 | + |
| 121 | + create_threads(worker, thread_attr); |
| 122 | + pthread_attr_destroy(&thread_attr); |
| 123 | +@@ -198,7 +197,7 @@ int bench_futex_lock_pi(int argc, const char **argv, |
| 124 | + pthread_mutex_destroy(&thread_lock); |
| 125 | + |
| 126 | + for (i = 0; i < nthreads; i++) { |
| 127 | +- unsigned long t = worker[i].ops/runtime.tv_sec; |
| 128 | ++ unsigned long t = worker[i].ops/bench__runtime.tv_sec; |
| 129 | + |
| 130 | + update_stats(&throughput_stats, t); |
| 131 | + if (!silent) |
| 132 | +-- |
| 133 | +2.27.0 |
| 134 | + |
0 commit comments