diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-02-14 12:12:43 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-02-14 13:19:17 -0500 |
commit | 16cab3226fc91fd8060a3d15d1f27051a7b189fb (patch) | |
tree | aa8e8a5767c50544faf9f277dac5c4105e3d3cd9 /tools/perf | |
parent | b98897166280c4cfb9bc5a6c1b5682528eb4abff (diff) |
Revert "perf bench futex: Sanitize numeric parameters"
This reverts commit 60758d6668b3e2fa8e5fd143d24d0425203d007e.
Now that libsubcmd makes sure that OPT_UINTEGER options will not
return negative values, we can revert this patch while addressing
the problem it solved:
# perf bench futex hash -t -4
# Running 'futex/hash' benchmark:
Error: switch `t' expects an unsigned numerical value
Usage: perf bench futex hash <options>
-t, --threads <n> Specify amount of threads
# perf bench futex hash -t-4
# Running 'futex/hash' benchmark:
Error: switch `t' expects an unsigned numerical value
Usage: perf bench futex hash <options>
-t, --threads <n> Specify amount of threads
#
IMO it is more reasonable to flat out refuse to process a negative
number than to silently turn it into an absolute value.
This also helps in silencing clang's complaint about asking for an
absolute value of an unsigned integer:
bench/futex-hash.c:133:10: error: taking the absolute value of unsigned type 'unsigned int' has no effect [-Werror,-Wabsolute-value]
nsecs = futexbench_sanitize_numeric(nsecs);
^
bench/futex.h:104:42: note: expanded from macro 'futexbench_sanitize_numeric'
#define futexbench_sanitize_numeric(__n) abs((__n))
^
bench/futex-hash.c:133:10: note: remove the call to 'abs' since unsigned values cannot be negative
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Davidlohr Bueso <dbueso@suse.de>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-2kl68v22or31vw643m2exz8x@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-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, 0 insertions, 20 deletions
diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c index bfbb6b5f609c..da04b8c5568a 100644 --- a/tools/perf/bench/futex-hash.c +++ b/tools/perf/bench/futex-hash.c | |||
@@ -130,8 +130,6 @@ 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); | ||
135 | 133 | ||
136 | sigfillset(&act.sa_mask); | 134 | sigfillset(&act.sa_mask); |
137 | act.sa_sigaction = toggle_done; | 135 | act.sa_sigaction = toggle_done; |
@@ -139,8 +137,6 @@ int bench_futex_hash(int argc, const char **argv, | |||
139 | 137 | ||
140 | if (!nthreads) /* default to the number of CPUs */ | 138 | if (!nthreads) /* default to the number of CPUs */ |
141 | nthreads = ncpus; | 139 | nthreads = ncpus; |
142 | else | ||
143 | nthreads = futexbench_sanitize_numeric(nthreads); | ||
144 | 140 | ||
145 | worker = calloc(nthreads, sizeof(*worker)); | 141 | worker = calloc(nthreads, sizeof(*worker)); |
146 | if (!worker) | 142 | if (!worker) |
diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c index 6d9d6c40a916..91877777ec6e 100644 --- a/tools/perf/bench/futex-lock-pi.c +++ b/tools/perf/bench/futex-lock-pi.c | |||
@@ -152,7 +152,6 @@ 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); | ||
156 | 155 | ||
157 | sigfillset(&act.sa_mask); | 156 | sigfillset(&act.sa_mask); |
158 | act.sa_sigaction = toggle_done; | 157 | act.sa_sigaction = toggle_done; |
@@ -160,8 +159,6 @@ int bench_futex_lock_pi(int argc, const char **argv, | |||
160 | 159 | ||
161 | if (!nthreads) | 160 | if (!nthreads) |
162 | nthreads = ncpus; | 161 | nthreads = ncpus; |
163 | else | ||
164 | nthreads = futexbench_sanitize_numeric(nthreads); | ||
165 | 162 | ||
166 | worker = calloc(nthreads, sizeof(*worker)); | 163 | worker = calloc(nthreads, sizeof(*worker)); |
167 | if (!worker) | 164 | if (!worker) |
diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c index fd4ee95b689a..2b9705a8734c 100644 --- a/tools/perf/bench/futex-requeue.c +++ b/tools/perf/bench/futex-requeue.c | |||
@@ -128,8 +128,6 @@ 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); | ||
133 | 131 | ||
134 | worker = calloc(nthreads, sizeof(*worker)); | 132 | worker = calloc(nthreads, sizeof(*worker)); |
135 | if (!worker) | 133 | if (!worker) |
diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c index beaa6c142477..2c8fa67ad537 100644 --- a/tools/perf/bench/futex-wake-parallel.c +++ b/tools/perf/bench/futex-wake-parallel.c | |||
@@ -217,12 +217,8 @@ 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 | |||
222 | if (!nblocked_threads) | 220 | if (!nblocked_threads) |
223 | nblocked_threads = ncpus; | 221 | nblocked_threads = ncpus; |
224 | else | ||
225 | nblocked_threads = futexbench_sanitize_numeric(nblocked_threads); | ||
226 | 222 | ||
227 | /* some sanity checks */ | 223 | /* some sanity checks */ |
228 | if (nwaking_threads > nblocked_threads || !nwaking_threads) | 224 | if (nwaking_threads > nblocked_threads || !nwaking_threads) |
diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c index 46efcb98b5a4..e246b1b8388a 100644 --- a/tools/perf/bench/futex-wake.c +++ b/tools/perf/bench/futex-wake.c | |||
@@ -129,7 +129,6 @@ 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); | ||
133 | 132 | ||
134 | sigfillset(&act.sa_mask); | 133 | sigfillset(&act.sa_mask); |
135 | act.sa_sigaction = toggle_done; | 134 | act.sa_sigaction = toggle_done; |
@@ -137,8 +136,6 @@ int bench_futex_wake(int argc, const char **argv, | |||
137 | 136 | ||
138 | if (!nthreads) | 137 | if (!nthreads) |
139 | nthreads = ncpus; | 138 | nthreads = ncpus; |
140 | else | ||
141 | nthreads = futexbench_sanitize_numeric(nthreads); | ||
142 | 139 | ||
143 | worker = calloc(nthreads, sizeof(*worker)); | 140 | worker = calloc(nthreads, sizeof(*worker)); |
144 | if (!worker) | 141 | if (!worker) |
diff --git a/tools/perf/bench/futex.h b/tools/perf/bench/futex.h index ba7c735c0c62..b2e06d1190d0 100644 --- a/tools/perf/bench/futex.h +++ b/tools/perf/bench/futex.h | |||
@@ -7,7 +7,6 @@ | |||
7 | #ifndef _FUTEX_H | 7 | #ifndef _FUTEX_H |
8 | #define _FUTEX_H | 8 | #define _FUTEX_H |
9 | 9 | ||
10 | #include <stdlib.h> | ||
11 | #include <unistd.h> | 10 | #include <unistd.h> |
12 | #include <sys/syscall.h> | 11 | #include <sys/syscall.h> |
13 | #include <sys/types.h> | 12 | #include <sys/types.h> |
@@ -100,7 +99,4 @@ static inline int pthread_attr_setaffinity_np(pthread_attr_t *attr, | |||
100 | } | 99 | } |
101 | #endif | 100 | #endif |
102 | 101 | ||
103 | /* User input sanitation */ | ||
104 | #define futexbench_sanitize_numeric(__n) abs((__n)) | ||
105 | |||
106 | #endif /* _FUTEX_H */ | 102 | #endif /* _FUTEX_H */ |