perf tool: fix endianness handling of u32 data in samples
PATCH 1/1 perf tool: fix endianness handling of u32 data in samples
Currently, analyzing PPC data files on x86 the cpu field is always 0 and the tid and pid are backwards. For example, analyzing a PPC file on PPC the pid/tid fields show:
rsyslogd 1210/1212
and analyzing the same PPC file using an x86 perf binary shows:
rsyslogd 1212/1210
The problem is that the swap_op method for samples is perf_event__all64_swap which assumes all elements in the sample_data struct are u64s. cpu, tid and pid are u32s and need to be handled individually. Given that the swap is done before the sample is parsed, the simplest solution is to undo the 64-bit swap of those elements when the sample is parsed and do the proper swap.
The RAW data field is generic and perf cannot have programmatic knowledge of how to treat that data. Instead a warning is given to the user.
Thanks to Anton Blanchard for providing a data file for a mult-CPU PPC system so I could verify the fix for the CPU fields.
--- tools/perf/builtin-test.c | 2 +- tools/perf/util/event.h | 2 +- tools/perf/util/evsel.c | 43 +++++++++++++++++++++++++++++++++++++------ tools/perf/util/session.h | 3 ++- 4 files changed, 41 insertions(+), 9 deletions(-)
tools/perf/builtin-test.c +1 -1
@@ -561,7 +561,7 @@ static int test__basic_mmap(void) } err =perf_event__parse_sample (event, attr.sample_type, sample_size, - false, &sample); + false, &sample, false);if (err) {pr_err ("Can't parse sample, err = %d\n" , err); goto out_munmap;
tools/perf/util/event.h +1 -1
@@ -186,6 +186,6 @@ const char *perf_event__name(unsigned int id);int perf_event__parse_sample (const union perf_event *event,u64 type,int sample_size,bool sample_id_all, -struct perf_sample *sample); +struct perf_sample *sample,bool swapped);#endif /* __PERF_RECORD_H */
tools/perf/util/evsel.c +37 -6
77 lines not on this page · raw message
tools/perf/util/session.h +2 -1
@@ -162,7 +162,8 @@ static inline int perf_session__parse_sample(struct perf_session *session, {return perf_event__parse_sample (event, session->sample_type, session->sample_size, - session->sample_id_all, sample); + session->sample_id_all, sample, + session->header.needs_swap); } struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
Signature · 1 line
1.7.6
Em Mon, Aug 29, 2011 at 03:55:24PM -0600, David Ahern escreveu:
Quoted 15 lines
Currently, analyzing PPC data files on x86 the cpu field is always 0 and the tid and pid are backwards. For example, analyzing a PPC file on PPC the pid/tid fields show:
rsyslogd 1210/1212and analyzing the same PPC file using an x86 perf binary shows:
rsyslogd 1212/1210The problem is that the
swap_opmethod for samples isperf_event__all64_swapwhich assumes all elements in thesample_datastruct are u64s. cpu, tid and pid are u32s and need to be handled individually. Given that the swap is done before the sample is parsed, the simplest solution is to undo the 64-bit swap of those elements when the sample is parsed and do the proper swap.
Quoted 7 lines
The RAW data field is generic and perf cannot have programmatic knowledge of how to treat that data. Instead a warning is given to the user.
Thanks to Anton Blanchard for providing a data file for a mult-CPU PPC system so I could verify the fix for the CPU fields.
Signed-off-by David Ahern <[email protected]>
cc1: warnings being treated as errorsutil/evsel.c: In function ‘perf_event__parse_sample’:util/evsel.c:379: error: dereferencing pointer ‘p’ does break strict-aliasing rules util/evsel.c:375: error: dereferencing pointer ‘p’ does break strict-aliasing rules util/evsel.c:375: error: dereferencing pointer ‘p’ does break strict-aliasing rules util/evsel.c:371: note: initialized from hereutil/evsel.c:376: error: dereferencing pointer ‘({anonymous})’ does break strict-aliasing rules util/evsel.c:376: error: dereferencing pointer ‘({anonymous})’ does break strict-aliasing rules util/evsel.c:376: note: initialized from hereutil/evsel.c:380: error: dereferencing pointer ‘({anonymous})’ does break strict-aliasing rules util/evsel.c:380: note: initialized from hereutil/evsel.c:414: error: dereferencing pointer ‘p’ does break strict-aliasing rules util/evsel.c:412: error: dereferencing pointer ‘p’ does break strict-aliasing rules util/evsel.c:408: note: initialized from hereutil/evsel.c:462: error: dereferencing pointer ‘p’ does break strict-aliasing rules util/evsel.c:450: error: dereferencing pointer ‘p’ does break strict-aliasing rules util/evsel.c:450: error: dereferencing pointer ‘p’ does break strict-aliasing rules util/evsel.c:444: note: initialized from hereutil/evsel.c:451: error: dereferencing pointer ‘({anonymous})’ does break strict-aliasing rules util/evsel.c:451: error: dereferencing pointer ‘({anonymous})’ does break strict-aliasing rules util/evsel.c:451: note: initialized from here
CC /home/acme/git/build/perf//util/symbol.o
make: *** [/home/acme/git/build/perf//util/evsel.o] Error 1
make: *** Waiting for unfinished jobs....
make: Leaving directory `/home/acme/git/linux/tools/perf'
[acme@emilia linux]$
[acme@emilia linux]$ uname -a
Linux emilia.ghostprotocols.net 3.0.3-rt12.14.el6rt.x86_64 #1 SMP PREEMPT RT Wed Aug 31 12:38:53 BRT 2011 x86_64 x86_64 x86_64 GNU/Linux [acme@emilia linux]$ cat /etc/redhat-release
Red Hat Enterprise Linux release 6.0 Beta (Santiago)
[acme@emilia linux]$
- Arnaldo
Quoted 37 lines · Arnaldo Carvalho de Melo
Em Mon, Aug 29, 2011 at 03:55:24PM -0600, David Ahern escreveu:
Quoted 15 lines
Currently, analyzing PPC data files on x86 the cpu field is always 0 and the tid and pid are backwards. For example, analyzing a PPC file on PPC the pid/tid fields show:
rsyslogd 1210/1212and analyzing the same PPC file using an x86 perf binary shows:
rsyslogd 1212/1210The problem is that the
swap_opmethod for samples isperf_event__all64_swapwhich assumes all elements in thesample_datastruct are u64s. cpu, tid and pid are u32s and need to be handled individually. Given that the swap is done before the sample is parsed, the simplest solution is to undo the 64-bit swap of those elements when the sample is parsed and do the proper swap.Quoted 7 lines
The RAW data field is generic and perf cannot have programmatic knowledge of how to treat that data. Instead a warning is given to the user.
Thanks to Anton Blanchard for providing a data file for a mult-CPU PPC system so I could verify the fix for the CPU fields.
Signed-off-by David Ahern <[email protected]>cc1: warnings being treated as errors
util/evsel.c: In function ‘perf_event__parse_sample’:util/evsel.c:379: error: dereferencing pointer ‘p’ does break strict-aliasing rulesutil/evsel.c:375: error: dereferencing pointer ‘p’ does break strict-aliasing rulesutil/evsel.c:375: error: dereferencing pointer ‘p’ does break strict-aliasing rulesutil/evsel.c:371: note: initialized from hereutil/evsel.c:376: error: dereferencing pointer ‘({anonymous})’ does break strict-aliasing rulesutil/evsel.c:376: error: dereferencing pointer ‘({anonymous})’ does break strict-aliasing rulesutil/evsel.c:376: note: initialized from hereutil/evsel.c:380: error: dereferencing pointer ‘({anonymous})’ does break strict-aliasing rulesutil/evsel.c:380: note: initialized from hereutil/evsel.c:414: error: dereferencing pointer ‘p’ does break strict-aliasing rulesutil/evsel.c:412: error: dereferencing pointer ‘p’ does break strict-aliasing rules
Quoted 8 lines
util/evsel.c:408: note: initialized from hereutil/evsel.c:462: error: dereferencing pointer ‘p’ does break strict-aliasing rulesutil/evsel.c:450: error: dereferencing pointer ‘p’ does break strict-aliasing rulesutil/evsel.c:450: error: dereferencing pointer ‘p’ does break strict-aliasing rulesutil/evsel.c:444: note: initialized from hereutil/evsel.c:451: error: dereferencing pointer ‘({anonymous})’ does break strict-aliasing rulesutil/evsel.c:451: error: dereferencing pointer ‘({anonymous})’ does break strict-aliasing rulesutil/evsel.c:451: note: initialized from here
That's no good. It compiles cleanly on Fedora 15-x86 and Fedora 12-ppc. What version of gcc is this?
David
Quoted 13 lines
CC
/home/acme/git/build/perf//util/symbol.o
make: *** [/home/acme/git/build/perf//util/evsel.o] Error 1
make: *** Waiting for unfinished jobs....
make: Leaving directory `/home/acme/git/linux/tools/perf' [acme@emilia linux]$[acme@emilia linux]$ uname -a
Linux emilia.ghostprotocols.net 3.0.3-rt12.14.el6rt.x86_64 #1 SMP PREEMPT RT Wed Aug 31 12:38:53 BRT 2011x86_64x86_64x86_64GNU/Linux [acme@emilia linux]$ cat/etc/redhat-release
Red Hat Enterprise Linux release 6.0 Beta (Santiago)
[acme@emilia linux]$- Arnaldo
Quoted 2 lines · David Ahern
That's no good. It compiles cleanly on Fedora 15-x86 and Fedora 12-ppc. What version of gcc is this?
hmm.... correction, fails on F12. I guess I only tested the swap code on x86 running F15. I'll investigate.
David