linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Rabin Vincent <rabin.vincent@axis.com>,
	Ingo Molnar <mingo@redhat.com>, Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Rabin Vincent <rabin@rab.in>, Rabin Vincent <rabinv@axis.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 03/18] perf bench: Fix memcpy/memset output
Date: Thu, 11 Dec 2014 18:25:51 -0300	[thread overview]
Message-ID: <1418333166-15429-4-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1418333166-15429-1-git-send-email-acme@kernel.org>

From: Rabin Vincent <rabin.vincent@axis.com>

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: Rabin Vincent <rabin.vincent@axis.com>
Acked-by: Ingo 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.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/bench/mem-memcpy.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/tools/perf/bench/mem-memcpy.c b/tools/perf/bench/mem-memcpy.c
index e18be70c8a47..6c14afe8c1b1 100644
--- a/tools/perf/bench/mem-memcpy.c
+++ b/tools/perf/bench/mem-memcpy.c
@@ -141,6 +141,7 @@ static int bench_mem_common(int argc, const char **argv,
 {
 	int i;
 	size_t len;
+	double totallen;
 	double result_bps[2];
 	u64 result_cycle[2];
 
@@ -156,6 +157,7 @@ static int bench_mem_common(int argc, const char **argv,
 		init_cycle();
 
 	len = (size_t)perf_atoll((char *)length_str);
+	totallen = (double)len * iterations;
 
 	result_cycle[0] = result_cycle[1] = 0ULL;
 	result_bps[0] = result_bps[1] = 0.0;
@@ -219,10 +221,10 @@ static int bench_mem_common(int argc, const char **argv,
 			if (use_cycle) {
 				printf(" %14lf Cycle/Byte\n",
 					(double)result_cycle[0]
-					/ (double)len);
+					/ totallen);
 				printf(" %14lf Cycle/Byte (with prefault)\n",
 					(double)result_cycle[1]
-					/ (double)len);
+					/ totallen);
 			} else {
 				print_bps(result_bps[0]);
 				printf("\n");
@@ -233,7 +235,7 @@ static int bench_mem_common(int argc, const char **argv,
 			if (use_cycle) {
 				printf(" %14lf Cycle/Byte",
 					(double)result_cycle[pf]
-					/ (double)len);
+					/ totallen);
 			} else
 				print_bps(result_bps[pf]);
 
@@ -244,8 +246,8 @@ static int bench_mem_common(int argc, const char **argv,
 		if (!only_prefault && !no_prefault) {
 			if (use_cycle) {
 				printf("%lf %lf\n",
-					(double)result_cycle[0] / (double)len,
-					(double)result_cycle[1] / (double)len);
+					(double)result_cycle[0] / totallen,
+					(double)result_cycle[1] / totallen);
 			} else {
 				printf("%lf %lf\n",
 					result_bps[0], result_bps[1]);
@@ -253,7 +255,7 @@ static int bench_mem_common(int argc, const char **argv,
 		} else {
 			if (use_cycle) {
 				printf("%lf\n", (double)result_cycle[pf]
-					/ (double)len);
+					/ totallen);
 			} else
 				printf("%lf\n", result_bps[pf]);
 		}
@@ -324,7 +326,7 @@ static double do_memcpy_gettimeofday(const struct routine *r, size_t len,
 
 	free(src);
 	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,
@@ -389,7 +391,7 @@ static double do_memset_gettimeofday(const struct routine *r, size_t len,
 	timersub(&tv_end, &tv_start, &tv_diff);
 
 	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[] = {
-- 
1.9.3


  parent reply	other threads:[~2014-12-11 21:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-11 21:25 [GIT PULL 00/18] perf/core improvements and fixes Arnaldo Carvalho de Melo
2014-12-11 21:25 ` [PATCH 01/18] perf bench: Prepare memcpy for merge Arnaldo Carvalho de Melo
2014-12-11 21:25 ` [PATCH 02/18] perf bench: Merge memset into memcpy Arnaldo Carvalho de Melo
2014-12-11 21:25 ` Arnaldo Carvalho de Melo [this message]
2014-12-11 21:25 ` [PATCH 04/18] perf hists browser: Change print format from %lu to %PRIu64 Arnaldo Carvalho de Melo
2014-12-11 21:25 ` [PATCH 05/18] perf tools: Use single strcmp call instead of two Arnaldo Carvalho de Melo
2014-12-11 21:25 ` [PATCH 06/18] perf buildid-cache: Remove extra debugdir variables Arnaldo Carvalho de Melo
2014-12-11 21:25 ` [PATCH 07/18] perf buildid cache: Fix -a segfault related to kcore handling Arnaldo Carvalho de Melo
2014-12-11 21:25 ` [PATCH 08/18] perf tools: Add --buildid-dir option to set cache directory Arnaldo Carvalho de Melo
2014-12-11 21:25 ` [PATCH 09/18] perf callchain: Fixup parameter handling error message Arnaldo Carvalho de Melo
2014-12-11 21:25 ` [PATCH 10/18] perf callchain: Move cpumode resolve code to add_callchain_ip Arnaldo Carvalho de Melo
2014-12-11 21:25 ` [PATCH 11/18] calloc/xcalloc: Fix argument order Arnaldo Carvalho de Melo
2014-12-11 21:26 ` [PATCH 12/18] perf tests: Fix attr tests size values to cope with machine state on interrupt ABI changes Arnaldo Carvalho de Melo
2014-12-11 21:26 ` [PATCH 13/18] perf kvm stat live: Mark events as (x86 only) in help output Arnaldo Carvalho de Melo
2014-12-11 21:26 ` [PATCH 14/18] tools lib fs: Adopt filename__read_int from tools/perf/ Arnaldo Carvalho de Melo
2014-12-11 21:26 ` [PATCH 15/18] tools lib fs: Add sysctl__read_int helper Arnaldo Carvalho de Melo
2014-12-11 21:26 ` [PATCH 16/18] perf tools: Use sysctl__read_int instead of ad-hoc copies Arnaldo Carvalho de Melo
2014-12-11 21:26 ` [PATCH 17/18] perf evlist: Introduce strerror_mmap method Arnaldo Carvalho de Melo
2014-12-11 21:26 ` [PATCH 18/18] perf trace: Provide a better explanation when mmap fails Arnaldo Carvalho de Melo
2014-12-12  8:10 ` [GIT PULL 00/18] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1418333166-15429-4-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulus@samba.org \
    --cc=rabin.vincent@axis.com \
    --cc=rabin@rab.in \
    --cc=rabinv@axis.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).