linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@redhat.com>,
	Corey Ashford <cjashfor@linux.vnet.ibm.com>,
	David Ahern <dsahern@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@elte.hu>, Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 11/15] perf evsel: Fix 32 bit values endianity swap for sample_id_all header
Date: Fri,  1 Jun 2012 19:16:35 -0300	[thread overview]
Message-ID: <1338588999-32509-12-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1338588999-32509-1-git-send-email-acme@infradead.org>

From: Jiri Olsa <jolsa@redhat.com>

We swap the sample_id_all header by u64 pointers. Some members of the
header happen to be 32 bit values. We need to handle them separatelly.

Together with other endianity patches, this change fixies perf report
discrepancies on origin and target systems as described in test 1 below,
e.g. following perf report diff:

...
      0.12%               ps  [kernel.kallsyms]    [k] clear_page
-     0.12%              awk  bash                 [.] alloc_word_desc
+     0.12%              awk  bash                 [.] yyparse
      0.11%   beah-rhts-task  libpython2.6.so.1.0  [.] 0x5560e
      0.10%             perf  libc-2.12.so         [.] __ctype_toupper_loc
-     0.09%  rhts-test-runne  bash                 [.] maybe_make_export_env
+     0.09%  rhts-test-runne  bash                 [.] 0x385a0
      0.09%               ps  [kernel.kallsyms]    [k] page_fault
...

Note, running following to test perf endianity handling:
test 1)
  - origin system:
    # perf record -a -- sleep 10 (any perf record will do)
    # perf report > report.origin
    # perf archive perf.data

  - copy the perf.data, report.origin and perf.data.tar.bz2
    to a target system and run:
    # tar xjvf perf.data.tar.bz2 -C ~/.debug
    # perf report > report.target
    # diff -u report.origin report.target

  - the diff should produce no output
    (besides some white space stuff and possibly different
     date/TZ output)

test 2)
  - origin system:
    # perf record -ag -fo /tmp/perf.data -- sleep 1
  - mount origin system root to the target system on /mnt/origin
  - target system:
    # perf script --symfs /mnt/origin -I -i /mnt/origin/tmp/perf.data \
     --kallsyms /mnt/origin/proc/kallsyms
  - complete perf.data header is displayed

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Reviewed-by: David Ahern <dsahern@gmail.com>
Tested-by: David Ahern <dsahern@gmail.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1338380624-7443-4-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/evsel.c |   29 ++++++++++++++++++++++-------
 1 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 91d1913..9f6cebd 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -494,16 +494,24 @@ int perf_evsel__open_per_thread(struct perf_evsel *evsel,
 }
 
 static int perf_event__parse_id_sample(const union perf_event *event, u64 type,
-				       struct perf_sample *sample)
+				       struct perf_sample *sample,
+				       bool swapped)
 {
 	const u64 *array = event->sample.array;
+	union u64_swap u;
 
 	array += ((event->header.size -
 		   sizeof(event->header)) / sizeof(u64)) - 1;
 
 	if (type & PERF_SAMPLE_CPU) {
-		u32 *p = (u32 *)array;
-		sample->cpu = *p;
+		u.val64 = *array;
+		if (swapped) {
+			/* undo swap of u64, then swap on individual u32s */
+			u.val64 = bswap_64(u.val64);
+			u.val32[0] = bswap_32(u.val32[0]);
+		}
+
+		sample->cpu = u.val32[0];
 		array--;
 	}
 
@@ -523,9 +531,16 @@ static int perf_event__parse_id_sample(const union perf_event *event, u64 type,
 	}
 
 	if (type & PERF_SAMPLE_TID) {
-		u32 *p = (u32 *)array;
-		sample->pid = p[0];
-		sample->tid = p[1];
+		u.val64 = *array;
+		if (swapped) {
+			/* undo swap of u64, then swap on individual u32s */
+			u.val64 = bswap_64(u.val64);
+			u.val32[0] = bswap_32(u.val32[0]);
+			u.val32[1] = bswap_32(u.val32[1]);
+		}
+
+		sample->pid = u.val32[0];
+		sample->tid = u.val32[1];
 	}
 
 	return 0;
@@ -562,7 +577,7 @@ int perf_event__parse_sample(const union perf_event *event, u64 type,
 	if (event->header.type != PERF_RECORD_SAMPLE) {
 		if (!sample_id_all)
 			return 0;
-		return perf_event__parse_id_sample(event, type, data);
+		return perf_event__parse_id_sample(event, type, data, swapped);
 	}
 
 	array = event->sample.array;
-- 
1.7.1


  parent reply	other threads:[~2012-06-01 22:18 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-01 22:16 [GIT PULL 00/15] perf/urgent fixes Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 01/15] perf script: Fix regression in callchain dso name Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 02/15] perf tools: Fix make tarballs Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 03/15] perf tools: Fix pager on minimal-install embedded systems Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 04/15] perf callchain: Make callchain cursors TLS Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 05/15] perf tools: Check if callchain is corrupted Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 06/15] perf tools: Make --version show kernel version instead of pull req tag Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 07/15] perf tools: Update ioctl documentation for PERF_IOC_FLAG_GROUP Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 08/15] perf evlist: Pass third argument to ioctl explicitly Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 09/15] perf symbols: Handle different endians properly during symbol load Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 10/15] perf session: Handle endianity swap on sample_id_all header data Arnaldo Carvalho de Melo
2012-06-01 22:16 ` Arnaldo Carvalho de Melo [this message]
2012-06-01 22:16 ` [PATCH 12/15] perf symbols: Check for valid dso before creating map Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 13/15] perf uprobes: Remove unnecessary check before strlist__delete Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 14/15] perf: Remove duplicate invocation on perf_event_for_each Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 15/15] perf tool: Build fix, remove duplicate declarations Arnaldo Carvalho de Melo
2012-06-01 22:45 ` [GIT PULL 00/15] perf/urgent fixes David Ahern
2012-06-01 23:08   ` Arnaldo Carvalho de Melo
2012-06-06  6:50 ` Ingo Molnar
2012-06-06 22:50   ` David Ahern
2012-06-07  2:19     ` Namhyung Kim
2012-06-07  3:52   ` David Ahern
2012-06-07 16:09     ` Arnaldo Carvalho de Melo
2012-06-07 16:11       ` Steven Rostedt
2012-06-07 16:43         ` Arnaldo Carvalho de Melo
2012-06-07 16:55         ` Borislav Petkov

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=1338588999-32509-12-git-send-email-acme@infradead.org \
    --to=acme@infradead.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=dsahern@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@kernel.org \
    --cc=paulus@samba.org \
    /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).