]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
perf bench futex: Sanitize numeric parameters
authorDavidlohr Bueso <dave@stgolabs.net>
Mon, 24 Oct 2016 20:56:53 +0000 (13:56 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 25 Oct 2016 12:50:53 +0000 (09:50 -0300)
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>
tools/perf/bench/futex-hash.c
tools/perf/bench/futex-lock-pi.c
tools/perf/bench/futex-requeue.c
tools/perf/bench/futex-wake-parallel.c
tools/perf/bench/futex-wake.c
tools/perf/bench/futex.h

index da04b8c5568a39cf509b9aa5df844641866bcfd1..bfbb6b5f609cd0427bf3f7531143771e2c4f4248 100644 (file)
@@ -130,6 +130,8 @@ int bench_futex_hash(int argc, const char **argv,
        }
 
        ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+       nsecs = futexbench_sanitize_numeric(nsecs);
+       nfutexes = futexbench_sanitize_numeric(nfutexes);
 
        sigfillset(&act.sa_mask);
        act.sa_sigaction = toggle_done;
@@ -137,6 +139,8 @@ int bench_futex_hash(int argc, const char **argv,
 
        if (!nthreads) /* default to the number of CPUs */
                nthreads = ncpus;
+       else
+               nthreads = futexbench_sanitize_numeric(nthreads);
 
        worker = calloc(nthreads, sizeof(*worker));
        if (!worker)
index 7032e4643c65f40018b0e1999e35097342d74de0..465012b320ee75a594465d4b76a2648811f7cb59 100644 (file)
@@ -152,6 +152,7 @@ int bench_futex_lock_pi(int argc, const char **argv,
                goto err;
 
        ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+       nsecs = futexbench_sanitize_numeric(nsecs);
 
        sigfillset(&act.sa_mask);
        act.sa_sigaction = toggle_done;
@@ -159,6 +160,8 @@ int bench_futex_lock_pi(int argc, const char **argv,
 
        if (!nthreads)
                nthreads = ncpus;
+       else
+               nthreads = futexbench_sanitize_numeric(nthreads);
 
        worker = calloc(nthreads, sizeof(*worker));
        if (!worker)
index 2b9705a8734cd6005fd3149943e2ff20eecf4bbe..fd4ee95b689a11c4646c33fdd07a1c202cc50958 100644 (file)
@@ -128,6 +128,8 @@ int bench_futex_requeue(int argc, const char **argv,
 
        if (!nthreads)
                nthreads = ncpus;
+       else
+               nthreads = futexbench_sanitize_numeric(nthreads);
 
        worker = calloc(nthreads, sizeof(*worker));
        if (!worker)
index 2c8fa67ad53767e43c7e91dc84279528268fcb3a..beaa6c142477b5d500c9c83d12dadc242420e497 100644 (file)
@@ -217,8 +217,12 @@ int bench_futex_wake_parallel(int argc, const char **argv,
        sigaction(SIGINT, &act, NULL);
 
        ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+       nwaking_threads = futexbench_sanitize_numeric(nwaking_threads);
+
        if (!nblocked_threads)
                nblocked_threads = ncpus;
+       else
+               nblocked_threads = futexbench_sanitize_numeric(nblocked_threads);
 
        /* some sanity checks */
        if (nwaking_threads > nblocked_threads || !nwaking_threads)
index e246b1b8388a3fd3bfc7c9c398a90efc26d86c79..46efcb98b5a4be7041678712ed29d8c69ca3ab3c 100644 (file)
@@ -129,6 +129,7 @@ int bench_futex_wake(int argc, const char **argv,
        }
 
        ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+       nwakes = futexbench_sanitize_numeric(nwakes);
 
        sigfillset(&act.sa_mask);
        act.sa_sigaction = toggle_done;
@@ -136,6 +137,8 @@ int bench_futex_wake(int argc, const char **argv,
 
        if (!nthreads)
                nthreads = ncpus;
+       else
+               nthreads = futexbench_sanitize_numeric(nthreads);
 
        worker = calloc(nthreads, sizeof(*worker));
        if (!worker)
index b2e06d1190d0766694c97f7f0b808717442af604..ba7c735c0c62db090a2c1fddd9aec54876496cfe 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef _FUTEX_H
 #define _FUTEX_H
 
+#include <stdlib.h>
 #include <unistd.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
@@ -99,4 +100,7 @@ static inline int pthread_attr_setaffinity_np(pthread_attr_t *attr,
 }
 #endif
 
+/* User input sanitation */
+#define futexbench_sanitize_numeric(__n) abs((__n))
+
 #endif /* _FUTEX_H */