Commit 1182f883 authored by Rabin Vincent's avatar Rabin Vincent Committed by Arnaldo Carvalho de Melo

perf bench: Fix memcpy/memset output

The memcpy and memset benchmarks return bogus results when iterations >
0 because the iterations value is not taken into account when
calculating the final result:

 $ perf bench mem memset --only-prefault --length 1GB --iterations 1
 # Running 'mem/memset' benchmark:
 # Copying 1GB Bytes ...

       20.798669 GB/Sec (with prefault)
 $ perf bench mem memset --only-prefault --length 1GB --iterations 10
 # Running 'mem/memset' benchmark:
 # Copying 1GB Bytes ...

        2.086576 GB/Sec (with prefault)
 $ perf bench mem memset --only-prefault --length 1GB --iterations 100
 # Running 'mem/memset' benchmark:
 # Copying 1GB Bytes ...

      212.840917 MB/Sec (with prefault)

Fix this.
Signed-off-by: default avatarRabin Vincent <rabin.vincent@axis.com>
Acked-by: default avatarIngo Molnar <mingo@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Rabin Vincent <rabin@rab.in>
Cc: Rabin Vincent <rabinv@axis.com>
Link: http://lkml.kernel.org/r/1417535441-3965-3-git-send-email-rabin.vincent@axis.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 5bce1a57
...@@ -141,6 +141,7 @@ static int bench_mem_common(int argc, const char **argv, ...@@ -141,6 +141,7 @@ static int bench_mem_common(int argc, const char **argv,
{ {
int i; int i;
size_t len; size_t len;
double totallen;
double result_bps[2]; double result_bps[2];
u64 result_cycle[2]; u64 result_cycle[2];
...@@ -156,6 +157,7 @@ static int bench_mem_common(int argc, const char **argv, ...@@ -156,6 +157,7 @@ static int bench_mem_common(int argc, const char **argv,
init_cycle(); init_cycle();
len = (size_t)perf_atoll((char *)length_str); len = (size_t)perf_atoll((char *)length_str);
totallen = (double)len * iterations;
result_cycle[0] = result_cycle[1] = 0ULL; result_cycle[0] = result_cycle[1] = 0ULL;
result_bps[0] = result_bps[1] = 0.0; result_bps[0] = result_bps[1] = 0.0;
...@@ -219,10 +221,10 @@ static int bench_mem_common(int argc, const char **argv, ...@@ -219,10 +221,10 @@ static int bench_mem_common(int argc, const char **argv,
if (use_cycle) { if (use_cycle) {
printf(" %14lf Cycle/Byte\n", printf(" %14lf Cycle/Byte\n",
(double)result_cycle[0] (double)result_cycle[0]
/ (double)len); / totallen);
printf(" %14lf Cycle/Byte (with prefault)\n", printf(" %14lf Cycle/Byte (with prefault)\n",
(double)result_cycle[1] (double)result_cycle[1]
/ (double)len); / totallen);
} else { } else {
print_bps(result_bps[0]); print_bps(result_bps[0]);
printf("\n"); printf("\n");
...@@ -233,7 +235,7 @@ static int bench_mem_common(int argc, const char **argv, ...@@ -233,7 +235,7 @@ static int bench_mem_common(int argc, const char **argv,
if (use_cycle) { if (use_cycle) {
printf(" %14lf Cycle/Byte", printf(" %14lf Cycle/Byte",
(double)result_cycle[pf] (double)result_cycle[pf]
/ (double)len); / totallen);
} else } else
print_bps(result_bps[pf]); print_bps(result_bps[pf]);
...@@ -244,8 +246,8 @@ static int bench_mem_common(int argc, const char **argv, ...@@ -244,8 +246,8 @@ static int bench_mem_common(int argc, const char **argv,
if (!only_prefault && !no_prefault) { if (!only_prefault && !no_prefault) {
if (use_cycle) { if (use_cycle) {
printf("%lf %lf\n", printf("%lf %lf\n",
(double)result_cycle[0] / (double)len, (double)result_cycle[0] / totallen,
(double)result_cycle[1] / (double)len); (double)result_cycle[1] / totallen);
} else { } else {
printf("%lf %lf\n", printf("%lf %lf\n",
result_bps[0], result_bps[1]); result_bps[0], result_bps[1]);
...@@ -253,7 +255,7 @@ static int bench_mem_common(int argc, const char **argv, ...@@ -253,7 +255,7 @@ static int bench_mem_common(int argc, const char **argv,
} else { } else {
if (use_cycle) { if (use_cycle) {
printf("%lf\n", (double)result_cycle[pf] printf("%lf\n", (double)result_cycle[pf]
/ (double)len); / totallen);
} else } else
printf("%lf\n", result_bps[pf]); printf("%lf\n", result_bps[pf]);
} }
...@@ -324,7 +326,7 @@ static double do_memcpy_gettimeofday(const struct routine *r, size_t len, ...@@ -324,7 +326,7 @@ static double do_memcpy_gettimeofday(const struct routine *r, size_t len,
free(src); free(src);
free(dst); free(dst);
return (double)((double)len / timeval2double(&tv_diff)); return (double)(((double)len * iterations) / timeval2double(&tv_diff));
} }
int bench_mem_memcpy(int argc, const char **argv, int bench_mem_memcpy(int argc, const char **argv,
...@@ -389,7 +391,7 @@ static double do_memset_gettimeofday(const struct routine *r, size_t len, ...@@ -389,7 +391,7 @@ static double do_memset_gettimeofday(const struct routine *r, size_t len,
timersub(&tv_end, &tv_start, &tv_diff); timersub(&tv_end, &tv_start, &tv_diff);
free(dst); free(dst);
return (double)((double)len / timeval2double(&tv_diff)); return (double)(((double)len * iterations) / timeval2double(&tv_diff));
} }
static const char * const bench_mem_memset_usage[] = { static const char * const bench_mem_memset_usage[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment