diff options
author | Davidlohr Bueso <dave@stgolabs.net> | 2016-10-24 16:56:53 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-10-25 08:50:53 -0400 |
commit | 60758d6668b3e2fa8e5fd143d24d0425203d007e (patch) | |
tree | 4e825f050b8853a68ec3e711a6e7d0c458b1e61f | |
parent | e2e1680fda1573ebfdd6bba5d58f978044746993 (diff) |
perf bench futex: Sanitize numeric parameters
This gets rid of oddities such as:
perf bench futex hash -t -4
perf: calloc: Cannot allocate memory
Runtime (and many more) are equally busted, i.e. run for bogus amounts of
time. Just use the abs, instead of, for example errorring out.
Committer note:
After the patch:
$ perf bench futex hash -t -4
# Running 'futex/hash' benchmark:
Run summary [PID 10178]: 4 threads, each operating on 1024 [private] futexes for 10 secs.
[thread 0] futexes: 0x34f9fa0 ... 0x34faf9c [ 4702208 ops/sec ]
[thread 1] futexes: 0x34fb140 ... 0x34fc13c [ 4707020 ops/sec ]
[thread 2] futexes: 0x34fc2e0 ... 0x34fd2dc [ 4711526 ops/sec ]
[thread 3] futexes: 0x34fd480 ... 0x34fe47c [ 4709683 ops/sec ]
Averaged 4707609 operations/sec (+- 0.04%), total secs = 10
$
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: http://lkml.kernel.org/r/1477342613-9938-3-git-send-email-dave@stgolabs.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/bench/futex-hash.c | 4 | ||||
-rw-r--r-- | tools/perf/bench/futex-lock-pi.c | 3 | ||||
-rw-r--r-- | tools/perf/bench/futex-requeue.c | 2 | ||||
-rw-r--r-- | tools/perf/bench/futex-wake-parallel.c | 4 | ||||
-rw-r--r-- | tools/perf/bench/futex-wake.c | 3 | ||||
-rw-r--r-- | tools/perf/bench/futex.h | 4 |
6 files changed, 20 insertions, 0 deletions
diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c index da04b8c5568a..bfbb6b5f609c 100644 --- a/tools/perf/bench/futex-hash.c +++ b/tools/perf/bench/futex-hash.c | |||
@@ -130,6 +130,8 @@ int bench_futex_hash(int argc, const char **argv, | |||
130 | } | 130 | } |
131 | 131 | ||
132 | ncpus = sysconf(_SC_NPROCESSORS_ONLN); | 132 | ncpus = sysconf(_SC_NPROCESSORS_ONLN); |
133 | nsecs = futexbench_sanitize_numeric(nsecs); | ||
134 | nfutexes = futexbench_sanitize_numeric(nfutexes); | ||
133 | 135 | ||
134 | sigfillset(&act.sa_mask); | 136 | sigfillset(&act.sa_mask); |
135 | act.sa_sigaction = toggle_done; | 137 | act.sa_sigaction = toggle_done; |
@@ -137,6 +139,8 @@ int bench_futex_hash(int argc, const char **argv, | |||
137 | 139 | ||
138 | if (!nthreads) /* default to the number of CPUs */ | 140 | if (!nthreads) /* default to the number of CPUs */ |
139 | nthreads = ncpus; | 141 | nthreads = ncpus; |
142 | else | ||
143 | nthreads = futexbench_sanitize_numeric(nthreads); | ||
140 | 144 | ||
141 | worker = calloc(nthreads, sizeof(*worker)); | 145 | worker = calloc(nthreads, sizeof(*worker)); |
142 | if (!worker) | 146 | if (!worker) |
diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c index 7032e4643c65..465012b320ee 100644 --- a/tools/perf/bench/futex-lock-pi.c +++ b/tools/perf/bench/futex-lock-pi.c | |||
@@ -152,6 +152,7 @@ int bench_futex_lock_pi(int argc, const char **argv, | |||
152 | goto err; | 152 | goto err; |
153 | 153 | ||
154 | ncpus = sysconf(_SC_NPROCESSORS_ONLN); | 154 | ncpus = sysconf(_SC_NPROCESSORS_ONLN); |
155 | nsecs = futexbench_sanitize_numeric(nsecs); | ||
155 | 156 | ||
156 | sigfillset(&act.sa_mask); | 157 | sigfillset(&act.sa_mask); |
157 | act.sa_sigaction = toggle_done; | 158 | act.sa_sigaction = toggle_done; |
@@ -159,6 +160,8 @@ int bench_futex_lock_pi(int argc, const char **argv, | |||
159 | 160 | ||
160 | if (!nthreads) | 161 | if (!nthreads) |
161 | nthreads = ncpus; | 162 | nthreads = ncpus; |
163 | else | ||
164 | nthreads = futexbench_sanitize_numeric(nthreads); | ||
162 | 165 | ||
163 | worker = calloc(nthreads, sizeof(*worker)); | 166 | worker = calloc(nthreads, sizeof(*worker)); |
164 | if (!worker) | 167 | if (!worker) |
diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c index 2b9705a8734c..fd4ee95b689a 100644 --- a/tools/perf/bench/futex-requeue.c +++ b/tools/perf/bench/futex-requeue.c | |||
@@ -128,6 +128,8 @@ int bench_futex_requeue(int argc, const char **argv, | |||
128 | 128 | ||
129 | if (!nthreads) | 129 | if (!nthreads) |
130 | nthreads = ncpus; | 130 | nthreads = ncpus; |
131 | else | ||
132 | nthreads = futexbench_sanitize_numeric(nthreads); | ||
131 | 133 | ||
132 | worker = calloc(nthreads, sizeof(*worker)); | 134 | worker = calloc(nthreads, sizeof(*worker)); |
133 | if (!worker) | 135 | if (!worker) |
diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c index 2c8fa67ad537..beaa6c142477 100644 --- a/tools/perf/bench/futex-wake-parallel.c +++ b/tools/perf/bench/futex-wake-parallel.c | |||
@@ -217,8 +217,12 @@ int bench_futex_wake_parallel(int argc, const char **argv, | |||
217 | sigaction(SIGINT, &act, NULL); | 217 | sigaction(SIGINT, &act, NULL); |
218 | 218 | ||
219 | ncpus = sysconf(_SC_NPROCESSORS_ONLN); | 219 | ncpus = sysconf(_SC_NPROCESSORS_ONLN); |
220 | nwaking_threads = futexbench_sanitize_numeric(nwaking_threads); | ||
221 | |||
220 | if (!nblocked_threads) | 222 | if (!nblocked_threads) |
221 | nblocked_threads = ncpus; | 223 | nblocked_threads = ncpus; |
224 | else | ||
225 | nblocked_threads = futexbench_sanitize_numeric(nblocked_threads); | ||
222 | 226 | ||
223 | /* some sanity checks */ | 227 | /* some sanity checks */ |
224 | if (nwaking_threads > nblocked_threads || !nwaking_threads) | 228 | if (nwaking_threads > nblocked_threads || !nwaking_threads) |
diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c index e246b1b8388a..46efcb98b5a4 100644 --- a/tools/perf/bench/futex-wake.c +++ b/tools/perf/bench/futex-wake.c | |||
@@ -129,6 +129,7 @@ int bench_futex_wake(int argc, const char **argv, | |||
129 | } | 129 | } |
130 | 130 | ||
131 | ncpus = sysconf(_SC_NPROCESSORS_ONLN); | 131 | ncpus = sysconf(_SC_NPROCESSORS_ONLN); |
132 | nwakes = futexbench_sanitize_numeric(nwakes); | ||
132 | 133 | ||
133 | sigfillset(&act.sa_mask); | 134 | sigfillset(&act.sa_mask); |
134 | act.sa_sigaction = toggle_done; | 135 | act.sa_sigaction = toggle_done; |
@@ -136,6 +137,8 @@ int bench_futex_wake(int argc, const char **argv, | |||
136 | 137 | ||
137 | if (!nthreads) | 138 | if (!nthreads) |
138 | nthreads = ncpus; | 139 | nthreads = ncpus; |
140 | else | ||
141 | nthreads = futexbench_sanitize_numeric(nthreads); | ||
139 | 142 | ||
140 | worker = calloc(nthreads, sizeof(*worker)); | 143 | worker = calloc(nthreads, sizeof(*worker)); |
141 | if (!worker) | 144 | if (!worker) |
diff --git a/tools/perf/bench/futex.h b/tools/perf/bench/futex.h index b2e06d1190d0..ba7c735c0c62 100644 --- a/tools/perf/bench/futex.h +++ b/tools/perf/bench/futex.h | |||
@@ -7,6 +7,7 @@ | |||
7 | #ifndef _FUTEX_H | 7 | #ifndef _FUTEX_H |
8 | #define _FUTEX_H | 8 | #define _FUTEX_H |
9 | 9 | ||
10 | #include <stdlib.h> | ||
10 | #include <unistd.h> | 11 | #include <unistd.h> |
11 | #include <sys/syscall.h> | 12 | #include <sys/syscall.h> |
12 | #include <sys/types.h> | 13 | #include <sys/types.h> |
@@ -99,4 +100,7 @@ static inline int pthread_attr_setaffinity_np(pthread_attr_t *attr, | |||
99 | } | 100 | } |
100 | #endif | 101 | #endif |
101 | 102 | ||
103 | /* User input sanitation */ | ||
104 | #define futexbench_sanitize_numeric(__n) abs((__n)) | ||
105 | |||
102 | #endif /* _FUTEX_H */ | 106 | #endif /* _FUTEX_H */ |