OSDN Git Service

powerpc/perf: Define big-endian version of perf_mem_data_src
authorSukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Tue, 11 Apr 2017 01:51:05 +0000 (07:21 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 19 Apr 2017 10:00:21 +0000 (20:00 +1000)
commit8c5073db0ee680c7e70e123918c9b260e49f757d
tree1c85ca41eb516810dd4ec664c1a0da8b226ffb38
parente889e96e98e8da97bd39e46b7253615eabe14397
powerpc/perf: Define big-endian version of perf_mem_data_src

perf_mem_data_src is a union that is initialized in the kernel via the ->val
field and accessed by userspace via the mem_xxx bitfields. For this to work
correctly on big endian platforms, we need a big-endian definition for the
bitfields.

Currently on a big endian system, if a user requests PERF_SAMPLE_DATA_SRC (perf
report -d), they will get the default value from perf_sample_data_init(), which
is PERF_MEM_NA. The value for PERF_MEM_NA is constructed using shifts:

  /* TLB access */
  #define PERF_MEM_TLB_NA 0x01 /* not available */
  ...
  #define PERF_MEM_TLB_SHIFT 26

  #define PERF_MEM_S(a, s) \
(((__u64)PERF_MEM_##a##_##s) << PERF_MEM_##a##_SHIFT)

  #define PERF_MEM_NA (PERF_MEM_S(OP, NA)   |\
    PERF_MEM_S(LVL, NA)   |\
    PERF_MEM_S(SNOOP, NA) |\
    PERF_MEM_S(LOCK, NA)  |\
    PERF_MEM_S(TLB, NA))

Which works out as:

  ((0x01 << 0) | (0x01 << 5) | (0x01 << 19) | (0x01 << 24) | (0x01 << 26))

Which means the PERF_MEM_NA value comes out of the kernel as 0x5080021
in CPU endian.

But then in the perf tool, the code uses the bitfields to inspect the value, and
currently the bitfields are defined using little endian ordering.

So eg. in perf_mem__tlb_scnprintf() we see:
  data_src->val = 0x5080021
             op = 0x0
            lvl = 0x0
          snoop = 0x0
           lock = 0x0
           dtlb = 0x0
           rsvd = 0x5080021

Because of the way the perf tool code is written this is still displayed to the
user as "N/A", so there is no bug visible at the UI level.

Currently there are no big endian architectures which export a meaningful
value (ie. other than PERF_MEM_NA), so the extent of the bug on big endian
platforms is that the PERF_MEM_NA value is exported incorrectly as described
above. Subsequent patches will add support on big endian powerpc for populating
the data source value.

This patch does a minimal fix of adding big endian definition of the bitfields
to match the values that are already exported by the kernel on big endian. And
it makes no change on little endian.

Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
include/uapi/linux/perf_event.h
tools/include/uapi/linux/perf_event.h