* [PATCH] perf tools: fix endian conversion reading event attr from header
@ 2011-07-12 15:19 David Ahern
2011-07-15 15:31 ` David Ahern
2011-07-15 15:47 ` Frederic Weisbecker
0 siblings, 2 replies; 4+ messages in thread
From: David Ahern @ 2011-07-12 15:19 UTC (permalink / raw)
To: linux-perf-users, linux-kernel
Cc: acme, mingo, peterz, fweisbec, paulus, David Ahern
The perf_event_attr struct has 2 __u32's at the top and need to
be swapped individually. With this change I was able to analyze
a perf.data collected in a 32-bit PPC VM on an x86 system. I
tested both 32-bit and 64-bit binaries for the Intel analysis
side; both read the PPC perf.data file correctly.
Signed-off-by: David Ahern <dsahern@gmail.com>
---
| 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index afb0849..8044c6f 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -877,9 +877,16 @@ int perf_session__read_header(struct perf_session *session, int fd)
struct perf_evsel *evsel;
off_t tmp;
- if (perf_header__getbuffer64(header, fd, &f_attr, sizeof(f_attr)))
+ if (readn(fd, &f_attr, sizeof(f_attr)) <= 0)
goto out_errno;
+ if (header->needs_swap) {
+ f_attr.attr.type = bswap_32(f_attr.attr.type);
+ f_attr.attr.size = bswap_32(f_attr.attr.size);
+ mem_bswap_64(&f_attr.attr.config,
+ sizeof(struct perf_event_attr) - 8);
+ }
+
tmp = lseek(fd, 0, SEEK_CUR);
evsel = perf_evsel__new(&f_attr.attr, i);
--
1.7.6
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] perf tools: fix endian conversion reading event attr from header
2011-07-12 15:19 [PATCH] perf tools: fix endian conversion reading event attr from header David Ahern
@ 2011-07-15 15:31 ` David Ahern
2011-07-15 15:47 ` Frederic Weisbecker
1 sibling, 0 replies; 4+ messages in thread
From: David Ahern @ 2011-07-15 15:31 UTC (permalink / raw)
To: mingo, fweisbec; +Cc: linux-perf-users, linux-kernel, acme, peterz, paulus
On 07/12/2011 09:19 AM, David Ahern wrote:
> The perf_event_attr struct has 2 __u32's at the top and need to
> be swapped individually. With this change I was able to analyze
> a perf.data collected in a 32-bit PPC VM on an x86 system. I
> tested both 32-bit and 64-bit binaries for the Intel analysis
> side; both read the PPC perf.data file correctly.
Similarly with this one. It replaces a call to perf_header__getbuffer64
with what it does inline -- only doing the swap of the attr struct after
the initial 2 u32's. I spent 2 days tracking this down and would hate to
lose it waiting for Arnaldo's return.
David
>
> Signed-off-by: David Ahern <dsahern@gmail.com>
> ---
> tools/perf/util/header.c | 9 ++++++++-
> 1 files changed, 8 insertions(+), 1 deletions(-)
>
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index afb0849..8044c6f 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -877,9 +877,16 @@ int perf_session__read_header(struct perf_session *session, int fd)
> struct perf_evsel *evsel;
> off_t tmp;
>
> - if (perf_header__getbuffer64(header, fd, &f_attr, sizeof(f_attr)))
> + if (readn(fd, &f_attr, sizeof(f_attr)) <= 0)
> goto out_errno;
>
> + if (header->needs_swap) {
> + f_attr.attr.type = bswap_32(f_attr.attr.type);
> + f_attr.attr.size = bswap_32(f_attr.attr.size);
> + mem_bswap_64(&f_attr.attr.config,
> + sizeof(struct perf_event_attr) - 8);
> + }
> +
> tmp = lseek(fd, 0, SEEK_CUR);
> evsel = perf_evsel__new(&f_attr.attr, i);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] perf tools: fix endian conversion reading event attr from header
2011-07-12 15:19 [PATCH] perf tools: fix endian conversion reading event attr from header David Ahern
2011-07-15 15:31 ` David Ahern
@ 2011-07-15 15:47 ` Frederic Weisbecker
2011-07-15 16:02 ` David Ahern
1 sibling, 1 reply; 4+ messages in thread
From: Frederic Weisbecker @ 2011-07-15 15:47 UTC (permalink / raw)
To: David Ahern; +Cc: linux-perf-users, linux-kernel, acme, mingo, peterz, paulus
On Tue, Jul 12, 2011 at 09:19:19AM -0600, David Ahern wrote:
> The perf_event_attr struct has 2 __u32's at the top and need to
> be swapped individually. With this change I was able to analyze
> a perf.data collected in a 32-bit PPC VM on an x86 system. I
> tested both 32-bit and 64-bit binaries for the Intel analysis
> side; both read the PPC perf.data file correctly.
>
> Signed-off-by: David Ahern <dsahern@gmail.com>
> ---
> tools/perf/util/header.c | 9 ++++++++-
> 1 files changed, 8 insertions(+), 1 deletions(-)
>
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index afb0849..8044c6f 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -877,9 +877,16 @@ int perf_session__read_header(struct perf_session *session, int fd)
> struct perf_evsel *evsel;
> off_t tmp;
>
> - if (perf_header__getbuffer64(header, fd, &f_attr, sizeof(f_attr)))
> + if (readn(fd, &f_attr, sizeof(f_attr)) <= 0)
> goto out_errno;
>
> + if (header->needs_swap) {
> + f_attr.attr.type = bswap_32(f_attr.attr.type);
> + f_attr.attr.size = bswap_32(f_attr.attr.size);
> + mem_bswap_64(&f_attr.attr.config,
> + sizeof(struct perf_event_attr) - 8);
> + }
> +
Good catch!
But would be nice to also handle the wakeup_events and bp_type fields.
Thanks.
> tmp = lseek(fd, 0, SEEK_CUR);
> evsel = perf_evsel__new(&f_attr.attr, i);
>
> --
> 1.7.6
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] perf tools: fix endian conversion reading event attr from header
2011-07-15 15:47 ` Frederic Weisbecker
@ 2011-07-15 16:02 ` David Ahern
0 siblings, 0 replies; 4+ messages in thread
From: David Ahern @ 2011-07-15 16:02 UTC (permalink / raw)
To: Frederic Weisbecker
Cc: linux-perf-users, linux-kernel, acme, mingo, peterz, paulus
On 07/15/2011 09:47 AM, Frederic Weisbecker wrote:
>> - if (perf_header__getbuffer64(header, fd, &f_attr, sizeof(f_attr)))
>> + if (readn(fd, &f_attr, sizeof(f_attr)) <= 0)
>> goto out_errno;
>>
>> + if (header->needs_swap) {
>> + f_attr.attr.type = bswap_32(f_attr.attr.type);
>> + f_attr.attr.size = bswap_32(f_attr.attr.size);
>> + mem_bswap_64(&f_attr.attr.config,
>> + sizeof(struct perf_event_attr) - 8);
>> + }
>> +
>
> Good catch!
A long, painful discovery
> But would be nice to also handle the wakeup_events and bp_type fields.
>
I did not think those values were used in userspace, so did not touch
them. But then your inquiry pushed me into cscope and I found the
perf_event__attr_swap() function. I'll redo the patch leveraging the
swapping done there.
David
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-07-15 16:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-12 15:19 [PATCH] perf tools: fix endian conversion reading event attr from header David Ahern
2011-07-15 15:31 ` David Ahern
2011-07-15 15:47 ` Frederic Weisbecker
2011-07-15 16:02 ` David Ahern
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).