From: David Ahern <dsahern@gmail.com>
To: Stephane Eranian <eranian@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
linux-kernel@vger.kernel.org, acme@redhat.com, mingo@elte.hu
Subject: Re: [PATCH] perf: make perf.data more self-descriptive (v4)
Date: Fri, 16 Sep 2011 08:50:21 -0600 [thread overview]
Message-ID: <4E73622D.5010506@gmail.com> (raw)
In-Reply-To: <CABPqkBShe6OG1ukQ=7vn_Mr=Aa_c8jcbo1mYuF+41Euy5_R7Dw@mail.gmail.com>
On 09/16/2011 08:35 AM, Stephane Eranian wrote:
> On Mon, Sep 12, 2011 at 4:43 PM, Peter Zijlstra <peterz@infradead.org> wrote:
>> On Mon, 2011-09-12 at 16:40 +0200, Stephane Eranian wrote:
>>> I don't think this should be the test to detect endianess.
>>
>> You should be able to tell the endianness from the PERF_MAGIC string, it
>> stores the string as a u64, so depending on endianness it reads back as
>> either: PERFFILE or ELIFFREP or whatever the bswap64 result is.
>>
>
> I believe in big endian, if you do od -c perf.data | head -1, you also see:
>
> 0000000 P E R F F I L E h \0 \0 \0 \0 \0 \0 \0
>
> static const char *__perf_magic = "PERFFILE";
> #define PERF_MAGIC (*(u64 *)__perf_magic)
>
> u64 hm = PERF_MAGIC;
>
> The layout in memory is the same for both little-endian and
> big-endian. Thus the layout on the file is the same.
>
> When you look at the memory as u64, then things are different:
> In little-endian, hm=0x454c494646524550
> in big-endian, hm=0x5045524646494c45
>
> In big-endian, the MSB 0x50 ('P') ends up at the lowest memory address.
> In little-endian, the LSB 0x50 ('P') ends up at the lowest memory address.
>
> Thus, I suspect we need to write in the file a different MAGIC for big vs.
> little endian.
>
> David, can you confirm this?
on x86:
$ od -c perf.data | head -1
0000000 P E R F F I L E h \0 \0 \0 \0 \0 \0 \0
on PPC:
# od -c perf.data | head -1
0000000 P E R F F I L E \0 \0 \0 \0 \0 \0 \0 h
And then PPC file on x86:
$ od -c perf-ppc.data | head -1
0000000 P E R F F I L E \0 \0 \0 \0 \0 \0 \0 h
So it is the same and that explains why the current code is:
if (readn(fd, header, sizeof(*header)) <= 0 ||
memcmp(&header->magic, __perf_magic, sizeof(header->magic)))
return -1;
versus a u64 comparison. Printing magic as a PRIx64 running the command
on x86:
ppc data file: header->magic 454c494646524550
x86 data file: header->magic 454c494646524550
Which is expected given the od -c output above.
David
next prev parent reply other threads:[~2011-09-16 14:50 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-07 19:10 [PATCH] perf: make perf.data more self-descriptive (v4) Stephane Eranian
2011-09-08 15:27 ` David Ahern
[not found] ` <CABPqkBRKcxeTDMyVYPXU6AQEY-Hp2bnE03ebEtvjYWde2JKqoQ@mail.gmail.com>
2011-09-08 15:37 ` David Ahern
2011-09-08 15:42 ` Stephane Eranian
2011-09-12 13:45 ` David Ahern
2011-09-12 13:54 ` Stephane Eranian
2011-09-12 14:33 ` David Ahern
2011-09-12 14:40 ` Stephane Eranian
2011-09-12 14:43 ` Peter Zijlstra
2011-09-12 14:47 ` Stephane Eranian
2011-09-13 14:40 ` Arnaldo Carvalho de Melo
2011-09-16 14:35 ` Stephane Eranian
2011-09-16 14:37 ` Peter Zijlstra
2011-09-16 14:44 ` Stephane Eranian
2011-09-16 14:52 ` David Ahern
2011-09-16 14:56 ` Stephane Eranian
2011-09-16 14:50 ` David Ahern [this message]
2011-09-16 15:19 ` Peter Zijlstra
2011-09-16 15:33 ` David Ahern
2011-09-16 15:42 ` Peter Zijlstra
2011-09-16 16:34 ` Stephane Eranian
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=4E73622D.5010506@gmail.com \
--to=dsahern@gmail.com \
--cc=acme@redhat.com \
--cc=eranian@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.