perf bench: Fix div-by-zero if runtime is zero

Fix div-by-zero if runtime is zero:

  $ perf bench futex hash --runtime=0
  # Running 'futex/hash' benchmark:
  Run summary [PID 12090]: 4 threads, each operating on 1024 [private] futexes for 0 secs.
  Floating point exception (core dumped)

Signed-off-by: Tommi Rantala <tommi.t.rantala@nokia.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lore.kernel.org/lkml/20200417132330.119407-4-tommi.t.rantala@nokia.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Tommi Rantala 2020-04-17 16:23:29 +03:00 committed by Arnaldo Carvalho de Melo
parent d2e7d8636f
commit 41e7c32b97
3 changed files with 6 additions and 3 deletions

View File

@ -519,7 +519,8 @@ int bench_epoll_wait(int argc, const char **argv)
qsort(worker, nthreads, sizeof(struct worker), cmpworker); qsort(worker, nthreads, sizeof(struct worker), cmpworker);
for (i = 0; i < nthreads; i++) { for (i = 0; i < nthreads; i++) {
unsigned long t = worker[i].ops / bench__runtime.tv_sec; unsigned long t = bench__runtime.tv_sec > 0 ?
worker[i].ops / bench__runtime.tv_sec : 0;
update_stats(&throughput_stats, t); update_stats(&throughput_stats, t);

View File

@ -205,7 +205,8 @@ int bench_futex_hash(int argc, const char **argv)
pthread_mutex_destroy(&thread_lock); pthread_mutex_destroy(&thread_lock);
for (i = 0; i < nthreads; i++) { for (i = 0; i < nthreads; i++) {
unsigned long t = worker[i].ops / bench__runtime.tv_sec; unsigned long t = bench__runtime.tv_sec > 0 ?
worker[i].ops / bench__runtime.tv_sec : 0;
update_stats(&throughput_stats, t); update_stats(&throughput_stats, t);
if (!silent) { if (!silent) {
if (nfutexes == 1) if (nfutexes == 1)

View File

@ -211,7 +211,8 @@ int bench_futex_lock_pi(int argc, const char **argv)
pthread_mutex_destroy(&thread_lock); pthread_mutex_destroy(&thread_lock);
for (i = 0; i < nthreads; i++) { for (i = 0; i < nthreads; i++) {
unsigned long t = worker[i].ops / bench__runtime.tv_sec; unsigned long t = bench__runtime.tv_sec > 0 ?
worker[i].ops / bench__runtime.tv_sec : 0;
update_stats(&throughput_stats, t); update_stats(&throughput_stats, t);
if (!silent) if (!silent)