]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
perf evsel: Fix swap for samples with raw data
authorJiri Olsa <jolsa@kernel.org>
Wed, 29 Nov 2017 18:43:46 +0000 (19:43 +0100)
committerThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Thu, 12 Apr 2018 13:03:08 +0000 (10:03 -0300)
BugLink: http://bugs.launchpad.net/bugs/1763366
[ Upstream commit f9d8adb345d7adbb2d3431eea73beb89c8d6d612 ]

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>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
tools/perf/util/evsel.c
tools/perf/util/python-ext-sources

index d5fbcf8c7aa70138716f1d4e153f515a882c4ccb..111b924f0a17d351c2d3949f3884bdd61d8d5728 100644 (file)
@@ -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"
@@ -2120,14 +2121,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);
index b4f2f06722a7acf8f8b036c560df03c000bd1d26..7aa0ea64544ecf4fec8e6a843c244d4bf2d3653c 100644 (file)
@@ -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