From: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
To: Michael Ellerman <michael@ellerman.id.au>
Cc: Anton Blanchard <anton@au1.ibm.com>,
linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org,
paulus@samba.org, acme@ghostprotocols.net, mingo <mingo@elte.hu>,
Jiri Olsa <jolsa@redhat.com>
Subject: Re: [PATCH] perf: Fix compile warnings in tests/attr.c
Date: Wed, 23 Jan 2013 10:57:33 -0800 [thread overview]
Message-ID: <20130123185733.GA22906@us.ibm.com> (raw)
In-Reply-To: <1358898333.29791.14.camel@concordia>
Michael Ellerman [michael@ellerman.id.au] wrote:
| > | make: *** [tests/attr.o] Error 1
| > |
| > | i386 compiles fine
| >
| > __u64 is 'unsigned long long' on x86 and PRIu64 is 'llu' which is fine.
| >
| > __u64 is 'unsigned long' on Power and PRIu64 is 'lu' which is again fine.
| >
| > But __u64 is 'unsigned long long' on x86_64, but PRIu64 is '%lu' bc __WORDSIZE
| > is 64.
|
|
| This is a bit of a mess, but let me see if I can help explain it.
Yes it is :-) thanks for explaining it.
|
| The root of the problem is that you're mixing up the kernel type __u64,
| with the userspace format specifier PRIu64.
struct perf_event_attr is shared with user space and is using __u64. Should
it use uint64_t instead ?
|
| PRIu64 is the format specifier for printing a uint64_t, it _may_ also be
| the right specifier for a __u64, but there's no guarantee of that - as
| you have discovered.
|
| Inside the kernel both x86 and powerpc use unsigned long long always, in
| 32-bit and 64-bit code. That means in the kernel we can always use %llu.
|
| On x86 that definition is also exported to userspace, so on x86 __u64 is
| always unsigned long long. As you noticed this potentially differs from
| uint64_t, which can be confusing. However it means in x86 userspace code
| you can always print a __u64 with %llu.
|
| On powerpc we default to using definitions that match userspace, so
| __u64 changes depending on your wordsize, and so you must use PRIu64
| etc. to print them.
Well, using __u64 and PRIu64 seems breaks x86-64...
|
| There is however support in recent powerpc kernels to switch to using
| unsigned long long even on 64-bit. See commit 2c9c6ce.
|
| You need to define __SANE_USERSPACE_TYPES__ before including types.h.
| Then you can always use %llu to print __u64.
but __SANE_USERSPACE_TYPES__ with __u64 and %llu seems to work on x86,
x86-64, powerpc.
Will modify my patch to add __SANE_USERSPACE_TYPES__ but leave the %llu
as is.
Sukadev
WARNING: multiple messages have this Message-ID (diff)
From: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
To: Michael Ellerman <michael@ellerman.id.au>
Cc: Jiri Olsa <jolsa@redhat.com>,
linuxppc-dev@ozlabs.org, Anton Blanchard <anton@au1.ibm.com>,
paulus@samba.org, linux-kernel@vger.kernel.org,
acme@ghostprotocols.net, mingo <mingo@elte.hu>
Subject: Re: [PATCH] perf: Fix compile warnings in tests/attr.c
Date: Wed, 23 Jan 2013 10:57:33 -0800 [thread overview]
Message-ID: <20130123185733.GA22906@us.ibm.com> (raw)
In-Reply-To: <1358898333.29791.14.camel@concordia>
Michael Ellerman [michael@ellerman.id.au] wrote:
| > | make: *** [tests/attr.o] Error 1
| > |
| > | i386 compiles fine
| >
| > __u64 is 'unsigned long long' on x86 and PRIu64 is 'llu' which is fine.
| >
| > __u64 is 'unsigned long' on Power and PRIu64 is 'lu' which is again fine.
| >
| > But __u64 is 'unsigned long long' on x86_64, but PRIu64 is '%lu' bc __WORDSIZE
| > is 64.
|
|
| This is a bit of a mess, but let me see if I can help explain it.
Yes it is :-) thanks for explaining it.
|
| The root of the problem is that you're mixing up the kernel type __u64,
| with the userspace format specifier PRIu64.
struct perf_event_attr is shared with user space and is using __u64. Should
it use uint64_t instead ?
|
| PRIu64 is the format specifier for printing a uint64_t, it _may_ also be
| the right specifier for a __u64, but there's no guarantee of that - as
| you have discovered.
|
| Inside the kernel both x86 and powerpc use unsigned long long always, in
| 32-bit and 64-bit code. That means in the kernel we can always use %llu.
|
| On x86 that definition is also exported to userspace, so on x86 __u64 is
| always unsigned long long. As you noticed this potentially differs from
| uint64_t, which can be confusing. However it means in x86 userspace code
| you can always print a __u64 with %llu.
|
| On powerpc we default to using definitions that match userspace, so
| __u64 changes depending on your wordsize, and so you must use PRIu64
| etc. to print them.
Well, using __u64 and PRIu64 seems breaks x86-64...
|
| There is however support in recent powerpc kernels to switch to using
| unsigned long long even on 64-bit. See commit 2c9c6ce.
|
| You need to define __SANE_USERSPACE_TYPES__ before including types.h.
| Then you can always use %llu to print __u64.
but __SANE_USERSPACE_TYPES__ with __u64 and %llu seems to work on x86,
x86-64, powerpc.
Will modify my patch to add __SANE_USERSPACE_TYPES__ but leave the %llu
as is.
Sukadev
next prev parent reply other threads:[~2013-01-23 18:58 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-19 1:30 [PATCH] perf: Fix compile warnings in tests/attr.c Sukadev Bhattiprolu
2013-01-19 1:30 ` Sukadev Bhattiprolu
2013-01-21 13:59 ` Jiri Olsa
2013-01-21 13:59 ` Jiri Olsa
2013-01-21 21:38 ` Sukadev Bhattiprolu
2013-01-21 21:38 ` Sukadev Bhattiprolu
2013-01-22 13:57 ` Jiri Olsa
2013-01-22 13:57 ` Jiri Olsa
2013-01-22 23:45 ` Michael Ellerman
2013-01-22 23:45 ` Michael Ellerman
2013-01-23 18:57 ` Sukadev Bhattiprolu [this message]
2013-01-23 18:57 ` Sukadev Bhattiprolu
2013-01-24 2:42 ` Michael Ellerman
2013-01-24 2:42 ` Michael Ellerman
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=20130123185733.GA22906@us.ibm.com \
--to=sukadev@linux.vnet.ibm.com \
--cc=acme@ghostprotocols.net \
--cc=anton@au1.ibm.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=michael@ellerman.id.au \
--cc=mingo@elte.hu \
--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 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.