diff options
author | Paul Mackerras <paulus@samba.org> | 2009-03-21 00:31:47 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-04-06 03:30:18 -0400 |
commit | 9aaa131a279834dff75c290c91f0058f62d72d46 (patch) | |
tree | d996052d5cdc48b38e300d2b3d87f64cf97ede15 | |
parent | db4fb5acf20295063d1d5105e67724eb51440207 (diff) |
perf_counter: fix type/event_id layout on big-endian systems
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.
Also, that commit didn't fix up some places in arch/powerpc/kernel/
perf_counter.c where hw_event.raw and hw_event.event_id were used.
This fixes them too.
Signed-off-by: Paul Mackerras <paulus@samba.org>
-rw-r--r-- | arch/powerpc/kernel/perf_counter.c | 9 | ||||
-rw-r--r-- | include/linux/perf_counter.h | 12 |
2 files changed, 17 insertions, 4 deletions
diff --git a/arch/powerpc/kernel/perf_counter.c b/arch/powerpc/kernel/perf_counter.c index 830ca9c4494c..6413d9c0313b 100644 --- a/arch/powerpc/kernel/perf_counter.c +++ b/arch/powerpc/kernel/perf_counter.c | |||
@@ -602,12 +602,13 @@ hw_perf_counter_init(struct perf_counter *counter) | |||
602 | return NULL; | 602 | return NULL; |
603 | if ((s64)counter->hw_event.irq_period < 0) | 603 | if ((s64)counter->hw_event.irq_period < 0) |
604 | return NULL; | 604 | return NULL; |
605 | ev = counter->hw_event.event_id; | 605 | if (!counter->hw_event.raw_type) { |
606 | if (!counter->hw_event.raw) { | 606 | ev = counter->hw_event.event_id; |
607 | if (ev >= ppmu->n_generic || | 607 | if (ev >= ppmu->n_generic || ppmu->generic_events[ev] == 0) |
608 | ppmu->generic_events[ev] == 0) | ||
609 | return NULL; | 608 | return NULL; |
610 | ev = ppmu->generic_events[ev]; | 609 | ev = ppmu->generic_events[ev]; |
610 | } else { | ||
611 | ev = counter->hw_event.raw_event_id; | ||
611 | } | 612 | } |
612 | counter->hw.config_base = ev; | 613 | counter->hw.config_base = ev; |
613 | counter->hw.idx = 0; | 614 | counter->hw.idx = 0; |
diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h index a4b76c0175f3..98f5990be1e1 100644 --- a/include/linux/perf_counter.h +++ b/include/linux/perf_counter.h | |||
@@ -15,6 +15,7 @@ | |||
15 | 15 | ||
16 | #include <linux/types.h> | 16 | #include <linux/types.h> |
17 | #include <linux/ioctl.h> | 17 | #include <linux/ioctl.h> |
18 | #include <asm/byteorder.h> | ||
18 | 19 | ||
19 | /* | 20 | /* |
20 | * User-space ABI bits: | 21 | * User-space ABI bits: |
@@ -86,6 +87,7 @@ enum perf_counter_record_type { | |||
86 | */ | 87 | */ |
87 | struct perf_counter_hw_event { | 88 | struct perf_counter_hw_event { |
88 | union { | 89 | union { |
90 | #ifndef __BIG_ENDIAN_BITFIELD | ||
89 | struct { | 91 | struct { |
90 | __u64 event_id : 56, | 92 | __u64 event_id : 56, |
91 | type : 8; | 93 | type : 8; |
@@ -94,6 +96,16 @@ struct perf_counter_hw_event { | |||
94 | __u64 raw_event_id : 63, | 96 | __u64 raw_event_id : 63, |
95 | raw_type : 1; | 97 | raw_type : 1; |
96 | }; | 98 | }; |
99 | #else | ||
100 | struct { | ||
101 | __u64 type : 8, | ||
102 | event_id : 56; | ||
103 | }; | ||
104 | struct { | ||
105 | __u64 raw_type : 1, | ||
106 | raw_event_id : 63; | ||
107 | }; | ||
108 | #endif /* __BIT_ENDIAN_BITFIELD */ | ||
97 | __u64 event_config; | 109 | __u64 event_config; |
98 | }; | 110 | }; |
99 | 111 | ||