public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Paul Mackerras <paulus@samba.org>
Cc: Ingo Molnar <mingo@elte.hu>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perfcounters: fix type/event_id layout on big-endian systems
Date: Sat, 21 Mar 2009 11:24:30 +0100	[thread overview]
Message-ID: <1237631070.24626.107.camel@twins> (raw)
In-Reply-To: <18884.29385.854691.357234@cargo.ozlabs.ibm.com>

On Sat, 2009-03-21 at 15:53 +1100, Paul Mackerras wrote:
> Impact: build fix for powerpc
> 
> Commit db3a944aca35ae61 ("perf_counter: revamp syscall input ABI")
> expanded the hw_event.type field into a union of structs containing
> bitfields.  In particular it introduced a type field and a raw_type
> field, with the intention that the 1-bit raw_type field should
> overlay the most-significant bit of the 8-bit type field, and in fact
> perf_counter_alloc() now assumes that (or at least, assumes that
> raw_type doesn't overlay any of the bits that are 1 in the values of
> PERF_TYPE_{HARDWARE,SOFTWARE,TRACEPOINT}).
> 
> Unfortunately this is not true on big-endian systems such as PowerPC,
> where bitfields are laid out from left to right, i.e. from most
> significant bit to least significant.  This means that setting
> hw_event.type = PERF_TYPE_SOFTWARE will set hw_event.raw_type to 1.
> 
> This fixes it by making the layout depend on whether or not
> __BIG_ENDIAN_BITFIELD is defined.  It's a bit ugly, but that's what
> we get for using bitfields in a user/kernel ABI.

Hmm, does userspace know about __BIG_ENDIAN_BITFIELD too? If not, we've
got ourselves a problem here.

Sorry about missing those powerpc bits, I guess I should dust-off the
cross-compiler.

> diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
> index a4b76c0..98f5990 100644
> --- a/include/linux/perf_counter.h
> +++ b/include/linux/perf_counter.h
> @@ -15,6 +15,7 @@
>  
>  #include <linux/types.h>
>  #include <linux/ioctl.h>
> +#include <asm/byteorder.h>
>  
>  /*
>   * User-space ABI bits:
> @@ -86,6 +87,7 @@ enum perf_counter_record_type {
>   */
>  struct perf_counter_hw_event {
>  	union {
> +#ifndef __BIG_ENDIAN_BITFIELD
>  		struct {
>  			__u64			event_id	: 56,
>  						type		:  8;
> @@ -94,6 +96,16 @@ struct perf_counter_hw_event {
>  			__u64			raw_event_id	: 63,
>  						raw_type	:  1;
>  		};
> +#else
> +		struct {
> +			__u64			type		:  8,
> +						event_id	: 56;
> +		};
> +		struct {
> +			__u64			raw_type	:  1,
> +						raw_event_id	: 63;
> +		};
> +#endif /* __BIT_ENDIAN_BITFIELD */
>  		__u64		event_config;
>  	};
>  


  parent reply	other threads:[~2009-03-21 10:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-21  4:53 [PATCH] perfcounters: fix type/event_id layout on big-endian systems Paul Mackerras
2009-03-21  9:42 ` Ingo Molnar
2009-03-21  9:52   ` Paul Mackerras
2009-03-21  9:56     ` Ingo Molnar
2009-03-21 11:41       ` Peter Zijlstra
2009-03-21 22:04         ` [PATCH] perf_counter: remove the event config bitfields Peter Zijlstra
2009-03-21 23:50           ` Paul Mackerras
2009-03-21 10:24 ` Peter Zijlstra [this message]
2009-03-21 12:08   ` [PATCH] perfcounters: fix type/event_id layout on big-endian systems Paul Mackerras

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=1237631070.24626.107.camel@twins \
    --to=a.p.zijlstra@chello.nl \
    --cc=linux-kernel@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox