linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf tools: Fix swap for samples with raw data
@ 2017-11-29 18:43 Jiri Olsa
  2017-11-29 19:02 ` Steven Rostedt
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Jiri Olsa @ 2017-11-29 18:43 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: David Ahern, Steven Rostedt, lkml, Ingo Molnar, Namhyung Kim,
	Peter Zijlstra

When we detect different endianity we swap event before
processing. It's tricky for samples because we have no
idea what's inside. We treat it as an array of u64s,
swap them and later on we swap back parts which are
different.

We mangle this way also the tracepoint raw data, which
ends up in report showing wrong data:

  1.95%  comm=Q^B pid=29285 prio=16777216 target_cpu=000
  1.67%  comm=l^B pid=0 prio=16777216 target_cpu=000

Luckily the traceevent library handles the endianity by
itself (thank you Steven!), so we can pass the RAW data
directly in the other endianity.

  2.51%  comm=beah-rhts-task pid=1175 prio=120 target_cpu=002
  2.23%  comm=kworker/0:0 pid=11566 prio=120 target_cpu=000

The fix is basically to swap back the raw data if different
endianity is detected.

Cc: David Ahern <dsahern@gmail.com>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Link: http://lkml.kernel.org/n/tip-0zcnwqf2k4pq854huwxc1v4l@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/evsel.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 95853c51c0ca..09c68cf2d9d2 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -36,6 +36,7 @@
 #include "debug.h"
 #include "trace-event.h"
 #include "stat.h"
+#include "memswap.h"
 #include "util/parse-branch-options.h"
 
 #include "sane_ctype.h"
@@ -2131,14 +2132,27 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
 	if (type & PERF_SAMPLE_RAW) {
 		OVERFLOW_CHECK_u64(array);
 		u.val64 = *array;
-		if (WARN_ONCE(swapped,
-			      "Endianness of raw data not corrected!\n")) {
-			/* undo swap of u64, then swap on individual u32s */
+
+		/*
+		 * Undo swap of u64, then swap on individual u32s,
+		 * get the size of the raw area and undo all of the
+		 * swap. The pevent interface handles endianity by
+		 * itself.
+		 */
+		if (swapped) {
 			u.val64 = bswap_64(u.val64);
 			u.val32[0] = bswap_32(u.val32[0]);
 			u.val32[1] = bswap_32(u.val32[1]);
 		}
 		data->raw_size = u.val32[0];
+
+		/*
+		 * The raw data is aligned on 64bits including the
+		 * u32 size, so it's safe to use mem_bswap_64.
+		 */
+		if (swapped)
+			mem_bswap_64((void *) array, data->raw_size);
+
 		array = (void *)array + sizeof(u32);
 
 		OVERFLOW_CHECK(array, data->raw_size, max_size);
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] perf tools: Fix swap for samples with raw data
  2017-11-29 18:43 [PATCH] perf tools: Fix swap for samples with raw data Jiri Olsa
@ 2017-11-29 19:02 ` Steven Rostedt
  2017-12-11 20:08 ` Arnaldo Carvalho de Melo
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2017-11-29 19:02 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, David Ahern, lkml, Ingo Molnar,
	Namhyung Kim, Peter Zijlstra

On Wed, 29 Nov 2017 19:43:46 +0100
Jiri Olsa <jolsa@kernel.org> wrote:

> Luckily the traceevent library handles the endianity by
> itself (thank you Steven!), so we can pass the RAW data
> directly in the other endianity.

You are welcome ;-)

-- Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] perf tools: Fix swap for samples with raw data
  2017-11-29 18:43 [PATCH] perf tools: Fix swap for samples with raw data Jiri Olsa
  2017-11-29 19:02 ` Steven Rostedt
@ 2017-12-11 20:08 ` Arnaldo Carvalho de Melo
  2017-12-13 12:33 ` Arnaldo Carvalho de Melo
  2017-12-28 15:33 ` [tip:perf/core] perf evsel: " tip-bot for Jiri Olsa
  3 siblings, 0 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-12-11 20:08 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: David Ahern, Steven Rostedt, lkml, Ingo Molnar, Namhyung Kim,
	Peter Zijlstra

Em Wed, Nov 29, 2017 at 07:43:46PM +0100, Jiri Olsa escreveu:
> When we detect different endianity we swap event before
> processing. It's tricky for samples because we have no
> idea what's inside. We treat it as an array of u64s,
> swap them and later on we swap back parts which are
> different.

Thanks, applied to perf/core, now at:

https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=perf/core&id=26ea2ece7802f8fdaaacf321dbfb22de3271ab82

- Arnaldo
 
> We mangle this way also the tracepoint raw data, which
> ends up in report showing wrong data:
> 
>   1.95%  comm=Q^B pid=29285 prio=16777216 target_cpu=000
>   1.67%  comm=l^B pid=0 prio=16777216 target_cpu=000
> 
> Luckily the traceevent library handles the endianity by
> itself (thank you Steven!), so we can pass the RAW data
> directly in the other endianity.
> 
>   2.51%  comm=beah-rhts-task pid=1175 prio=120 target_cpu=002
>   2.23%  comm=kworker/0:0 pid=11566 prio=120 target_cpu=000
> 
> The fix is basically to swap back the raw data if different
> endianity is detected.
> 
> Cc: David Ahern <dsahern@gmail.com>
> Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
> Link: http://lkml.kernel.org/n/tip-0zcnwqf2k4pq854huwxc1v4l@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/util/evsel.c | 20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 95853c51c0ca..09c68cf2d9d2 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -36,6 +36,7 @@
>  #include "debug.h"
>  #include "trace-event.h"
>  #include "stat.h"
> +#include "memswap.h"
>  #include "util/parse-branch-options.h"
>  
>  #include "sane_ctype.h"
> @@ -2131,14 +2132,27 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
>  	if (type & PERF_SAMPLE_RAW) {
>  		OVERFLOW_CHECK_u64(array);
>  		u.val64 = *array;
> -		if (WARN_ONCE(swapped,
> -			      "Endianness of raw data not corrected!\n")) {
> -			/* undo swap of u64, then swap on individual u32s */
> +
> +		/*
> +		 * Undo swap of u64, then swap on individual u32s,
> +		 * get the size of the raw area and undo all of the
> +		 * swap. The pevent interface handles endianity by
> +		 * itself.
> +		 */
> +		if (swapped) {
>  			u.val64 = bswap_64(u.val64);
>  			u.val32[0] = bswap_32(u.val32[0]);
>  			u.val32[1] = bswap_32(u.val32[1]);
>  		}
>  		data->raw_size = u.val32[0];
> +
> +		/*
> +		 * The raw data is aligned on 64bits including the
> +		 * u32 size, so it's safe to use mem_bswap_64.
> +		 */
> +		if (swapped)
> +			mem_bswap_64((void *) array, data->raw_size);
> +
>  		array = (void *)array + sizeof(u32);
>  
>  		OVERFLOW_CHECK(array, data->raw_size, max_size);
> -- 
> 2.13.6

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] perf tools: Fix swap for samples with raw data
  2017-11-29 18:43 [PATCH] perf tools: Fix swap for samples with raw data Jiri Olsa
  2017-11-29 19:02 ` Steven Rostedt
  2017-12-11 20:08 ` Arnaldo Carvalho de Melo
@ 2017-12-13 12:33 ` Arnaldo Carvalho de Melo
  2017-12-13 12:36   ` Jiri Olsa
  2017-12-28 15:33 ` [tip:perf/core] perf evsel: " tip-bot for Jiri Olsa
  3 siblings, 1 reply; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-12-13 12:33 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: David Ahern, Steven Rostedt, lkml, Ingo Molnar, Namhyung Kim,
	Peter Zijlstra

Em Wed, Nov 29, 2017 at 07:43:46PM +0100, Jiri Olsa escreveu:
> The fix is basically to swap back the raw data if different
> endianity is detected.
 
> +++ b/tools/perf/util/evsel.c
> @@ -36,6 +36,7 @@
>  #include "trace-event.h"
>  #include "stat.h"
> +#include "memswap.h"

> @@ -2131,14 +2132,27 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
>  	if (type & PERF_SAMPLE_RAW) {

> +		if (swapped)
> +			mem_bswap_64((void *) array, data->raw_size);
> +


you forgot to add util/memswap.c to tools/perf/util/python-ext-sources,
breaking 'perf test python'.

Please run 'perf test' before sending pull requests :-)

Fixed it this time.

- Arnaldo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] perf tools: Fix swap for samples with raw data
  2017-12-13 12:33 ` Arnaldo Carvalho de Melo
@ 2017-12-13 12:36   ` Jiri Olsa
  0 siblings, 0 replies; 6+ messages in thread
From: Jiri Olsa @ 2017-12-13 12:36 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, David Ahern, Steven Rostedt, lkml, Ingo Molnar,
	Namhyung Kim, Peter Zijlstra

On Wed, Dec 13, 2017 at 09:33:58AM -0300, Arnaldo Carvalho de Melo wrote:
> Em Wed, Nov 29, 2017 at 07:43:46PM +0100, Jiri Olsa escreveu:
> > The fix is basically to swap back the raw data if different
> > endianity is detected.
>  
> > +++ b/tools/perf/util/evsel.c
> > @@ -36,6 +36,7 @@
> >  #include "trace-event.h"
> >  #include "stat.h"
> > +#include "memswap.h"
> 
> > @@ -2131,14 +2132,27 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
> >  	if (type & PERF_SAMPLE_RAW) {
> 
> > +		if (swapped)
> > +			mem_bswap_64((void *) array, data->raw_size);
> > +
> 
> 
> you forgot to add util/memswap.c to tools/perf/util/python-ext-sources,
> breaking 'perf test python'.
> 
> Please run 'perf test' before sending pull requests :-)
> 

ouch ;-)

> Fixed it this time.

thanks,
jirka

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [tip:perf/core] perf evsel: Fix swap for samples with raw data
  2017-11-29 18:43 [PATCH] perf tools: Fix swap for samples with raw data Jiri Olsa
                   ` (2 preceding siblings ...)
  2017-12-13 12:33 ` Arnaldo Carvalho de Melo
@ 2017-12-28 15:33 ` tip-bot for Jiri Olsa
  3 siblings, 0 replies; 6+ messages in thread
From: tip-bot for Jiri Olsa @ 2017-12-28 15:33 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, rostedt, hpa, namhyung, jolsa, tglx, dsahern,
	linux-kernel, acme, peterz

Commit-ID:  f9d8adb345d7adbb2d3431eea73beb89c8d6d612
Gitweb:     https://git.kernel.org/tip/f9d8adb345d7adbb2d3431eea73beb89c8d6d612
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Wed, 29 Nov 2017 19:43:46 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 27 Dec 2017 12:15:56 -0300

perf evsel: Fix swap for samples with raw data

When we detect a different endianity we swap event before processing.
It's tricky for samples because we have no idea what's inside. We treat
it as an array of u64s, swap them and later on we swap back parts which
are different.

We mangle this way also the tracepoint raw data, which ends up in report
showing wrong data:

  1.95%  comm=Q^B pid=29285 prio=16777216 target_cpu=000
  1.67%  comm=l^B pid=0 prio=16777216 target_cpu=000

Luckily the traceevent library handles the endianity by itself (thank
you Steven!), so we can pass the RAW data directly in the other
endianity.

  2.51%  comm=beah-rhts-task pid=1175 prio=120 target_cpu=002
  2.23%  comm=kworker/0:0 pid=11566 prio=120 target_cpu=000

The fix is basically to swap back the raw data if different endianity is
detected.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/20171129184346.3656-1-jolsa@kernel.org
[ Add util/memswap.c to python-ext-sources to link missing mem_bswap_64() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/evsel.c            | 20 +++++++++++++++++---
 tools/perf/util/python-ext-sources |  1 +
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 4718f0a..1cf044c 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -36,6 +36,7 @@
 #include "debug.h"
 #include "trace-event.h"
 #include "stat.h"
+#include "memswap.h"
 #include "util/parse-branch-options.h"
 
 #include "sane_ctype.h"
@@ -2131,14 +2132,27 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
 	if (type & PERF_SAMPLE_RAW) {
 		OVERFLOW_CHECK_u64(array);
 		u.val64 = *array;
-		if (WARN_ONCE(swapped,
-			      "Endianness of raw data not corrected!\n")) {
-			/* undo swap of u64, then swap on individual u32s */
+
+		/*
+		 * Undo swap of u64, then swap on individual u32s,
+		 * get the size of the raw area and undo all of the
+		 * swap. The pevent interface handles endianity by
+		 * itself.
+		 */
+		if (swapped) {
 			u.val64 = bswap_64(u.val64);
 			u.val32[0] = bswap_32(u.val32[0]);
 			u.val32[1] = bswap_32(u.val32[1]);
 		}
 		data->raw_size = u.val32[0];
+
+		/*
+		 * The raw data is aligned on 64bits including the
+		 * u32 size, so it's safe to use mem_bswap_64.
+		 */
+		if (swapped)
+			mem_bswap_64((void *) array, data->raw_size);
+
 		array = (void *)array + sizeof(u32);
 
 		OVERFLOW_CHECK(array, data->raw_size, max_size);
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
index b4f2f06..7aa0ea6 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -10,6 +10,7 @@ util/ctype.c
 util/evlist.c
 util/evsel.c
 util/cpumap.c
+util/memswap.c
 util/mmap.c
 util/namespaces.c
 ../lib/bitmap.c

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-12-28 15:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-29 18:43 [PATCH] perf tools: Fix swap for samples with raw data Jiri Olsa
2017-11-29 19:02 ` Steven Rostedt
2017-12-11 20:08 ` Arnaldo Carvalho de Melo
2017-12-13 12:33 ` Arnaldo Carvalho de Melo
2017-12-13 12:36   ` Jiri Olsa
2017-12-28 15:33 ` [tip:perf/core] perf evsel: " tip-bot for Jiri Olsa

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).