powerpc/perf: Export memory hierarchy level
Subsystems (2)
cover powerpc/perf: Export memory hierarchy level
Power8 Perforence Monitoring Unit (PMU) supports different sampling modes (SM) Random Instruction Sampling (RIS), Random Load/Store Facility Sampling (RLS) and Random Branch Sampling (RBS). This patchset enabled RLS mode to mark Load/Store instructions to save the memory hierarchy level (eg: L2, L3) for cache reload. Event used here to sample is "marked instruction complete".
This patchset exports the hierarchy information to the user via the perf_mem_data_src object. Patchset is based on and derived from Sukadev Bhattiprolu work[1]. It exports the memory hierarchy information only to Power8 processor based system, since similiar event or modes are not supported in Power7
[1]:https://lkml.org/lkml/2013/10/15/858
perf interface sample. Workload used here is "ebizzy"
# perf report -n --mem-mode --sort=mem,sym,dso,symbol_daddr --stdio
# To display the perf.data header info, please use --header/--header-only options.
#
# Samples: 33 of event 'cpu/mem_access/'
# Total weight : 33
# Sort order : mem,sym,dso,symbol_daddr
#
# Overhead Samples Memory access Symbol Shared Object Data Symbol
# ........ ............ ........................ .................................. ................. .........................................
#
12.12% 4 L2 hit [k] __do_softirq [kernel.kallsyms] [k] softirq_vec+0x8
6.06% 2 L2 hit [k] __schedule [kernel.kallsyms] [k] 0xc0000003bb975df0
6.06% 2 Remote Cache (1 hop) hit [k] scheduler_tick [kernel.kallsyms] [k] 0xc0000003feb1e4b0
3.03% 1 L2 hit [k] __acct_update_integrals [kernel.kallsyms] [k] 0xc0000003b79d8a30
3.03% 1 L2 hit [.] __memcpy_power7 libc-2.17.so [.] 0x0000010021349b00
3.03% 1 L2 hit [.] __memcpy_power7 libc-2.17.so [.] 0x000001002134a030
3.03% 1 L2 hit [k] __mmdrop [kernel.kallsyms] [k] pgtable_cache+0x58
3.03% 1 L2 hit [k] __update_cpu_load [kernel.kallsyms] [k] 0xc0000003feb1dc60
3.03% 1 L2 hit [.] _int_malloc libc-2.17.so [.] 0x00003fff90000090
3.03% 1 L2 hit [k] account_system_time [kernel.kallsyms] [k] 0xc0000003feb08088
.....Madhavan Srinivasan (8):
powerpc/perf: Remove PME_ prefix for power7 events powerpc/perf: Export Power8 generic events in sysfs powerpc/perf: EVENT macro for exporting generic events powerpc/perf: Add Power8 mem_access event to sysfs powerpc/perf: Define big-endian version of perf_mem_data_src powerpc/perf: Export Power8 memory hierarchy info to user space powerpc/perf: Set data source value
powerpc/perf: cleanup in perf_event_print_debug()
arch/powerpc/include/asm/perf_event_server.h | 4 +- arch/powerpc/perf/core-book3s.c | 17 ++++- arch/powerpc/perf/power7-pmu.c | 18 ++--- arch/powerpc/perf/power8-events-list.h | 21 ++++++ arch/powerpc/perf/power8-pmu.c | 98 ++++++++++++++++++++++++++-- include/uapi/linux/perf_event.h | 16 +++++ 6 files changed, 155 insertions(+), 19 deletions(-) create mode 100644 arch/powerpc/perf/power8-events-list.h
Signature · 1 line
1.9.1
PATCH 1/8 powerpc/perf: Remove PME_ prefix for power7 events
From: Sukadev Bhattiprolu <[email protected]>
We used the PME_ prefix earlier to avoid some macro/variable name collisions. We have since changed the way we define/use the event macros so we no longer need the prefix.
By dropping the prefix, we keep the the event macros consistent with their official names.
--- arch/powerpc/include/asm/perf_event_server.h | 2 +- arch/powerpc/perf/power7-pmu.c | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/perf_event_server.h +1 -1
@@ -141,7 +141,7 @@ extern ssize_t power_events_sysfs_show(struct device *dev,#define EVENT_PTR (_id, _suffix) &EVENT_VAR(_id, _suffix).attr.attr#define EVENT_ATTR (_name, _id, _suffix) \ - PMU_EVENT_ATTR(_name, EVENT_VAR(_id, _suffix), PME_##_id, \ + PMU_EVENT_ATTR(_name, EVENT_VAR(_id, _suffix), _id, \ power_events_sysfs_show)#define GENERIC_EVENT_ATTR (_name, _id) EVENT_ATTR(_name, _id, _g)
arch/powerpc/perf/power7-pmu.c +9 -9
@@ -54,7 +54,7 @@* Power7 event codes. */ #define EVENT (_name, _code) \ - PME_##_name = _code, + _name = _code,enum {#include "power7-events-list.h"
@@ -318,14 +318,14 @@ static void power7_disable_pmc(unsigned int pmc, unsigned long mmcr[]) }static int power7_generic_events[] = { - [PERF_COUNT_HW_CPU_CYCLES ] =PME_PM_CYC , - [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND ] =PME_PM_GCT_NOSLOT_CYC , - [PERF_COUNT_HW_STALLED_CYCLES_BACKEND ] =PME_PM_CMPLU_STALL , - [PERF_COUNT_HW_INSTRUCTIONS ] =PME_PM_INST_CMPL , - [PERF_COUNT_HW_CACHE_REFERENCES ] =PME_PM_LD_REF_L1 , - [PERF_COUNT_HW_CACHE_MISSES ] =PME_PM_LD_MISS_L1 , - [PERF_COUNT_HW_BRANCH_INSTRUCTIONS ] =PME_PM_BRU_FIN , - [PERF_COUNT_HW_BRANCH_MISSES ] =PME_PM_BR_MPRED , + [PERF_COUNT_HW_CPU_CYCLES ] =PM_CYC , + [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND ] =PM_GCT_NOSLOT_CYC , + [PERF_COUNT_HW_STALLED_CYCLES_BACKEND ] =PM_CMPLU_STALL , + [PERF_COUNT_HW_INSTRUCTIONS ] =PM_INST_CMPL , + [PERF_COUNT_HW_CACHE_REFERENCES ] =PM_LD_REF_L1 , + [PERF_COUNT_HW_CACHE_MISSES ] =PM_LD_MISS_L1 , + [PERF_COUNT_HW_BRANCH_INSTRUCTIONS ] =PM_BRU_FIN , + [PERF_COUNT_HW_BRANCH_MISSES ] =PM_BR_MPRED , };#define C (x) PERF_COUNT_HW_CACHE_##x
Signature · 1 line
1.9.1
PATCH 2/8 powerpc/perf: Export Power8 generic events in sysfs
In reply to Madhavan SrinivasanFrom: Sukadev Bhattiprolu <[email protected]>
Export generic perf events for Power8 in sysfs.
--- arch/powerpc/perf/power8-events-list.h | 20 ++++++++++++++++ arch/powerpc/perf/power8-pmu.c | 43 +++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 arch/powerpc/perf/power8-events-list.h
arch/powerpc/perf/power8-events-list.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* Performance counter support for POWER8 processors. +* +* Copyright 2013 Sukadev Bhattiprolu, IBM Corporation. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +/* +* Some power8 event codes. +*/ +EVENT(PM_CYC, 0x0001e) +EVENT(PM_GCT_NOSLOT_CYC, 0x100f8) +EVENT(PM_CMPLU_STALL, 0x4000a) +EVENT(PM_INST_CMPL, 0x00002) +EVENT(PM_BRU_FIN, 0x10068) +EVENT (PM_BR_MPRED_CMPL ,0x400f6 )
arch/powerpc/perf/power8-pmu.c +37 -6
61 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 3/8 powerpc/perf: EVENT macro for exporting generic events
In reply to Madhavan SrinivasanAdding EVENT macro for exporting Power8 generic events
--- arch/powerpc/perf/power8-pmu.c | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/perf/power8-pmu.c +2 -0
@@ -21,6 +21,8 @@/* * Some power8 event codes. */ +#define EVENT (_name, _code) \ + _name = _code,enum {#include "power8-events-list.h" };
Signature · 1 line
1.9.1
PATCH 4/8 powerpc/perf: Add Power8 mem_access event to sysfs
In reply to Madhavan SrinivasanPatch add "mem_access" event to sysfs. This as-is not a raw event supported by Power8 pmu. Instead, it is formed based on raw event encoding specificed in Power8-pmu.c.
Primary PMU event used here is PM_MRK_INST_CMPL. This event tracks only the completed marked instructions.
Random sampling mode (MMCRA[SM]) with Random Load/Store Facility Sampling (RLS) is enabled to mark type of instructions.
With Random sampling in RLS mode with PM_MRK_INST_CMPL event on Power8, the LDST field in SIER identifies the memory hierarchy level (eg: L1, L2 etc), from which a data-cache miss for a marked instruction are satisfied.
--- arch/powerpc/perf/power8-events-list.h | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/perf/power8-events-list.h +1 -0
@@ -18,3 +18,4 @@ EVENT(PM_CMPLU_STALL, 0x4000a) EVENT(PM_INST_CMPL, 0x00002) EVENT(PM_BRU_FIN, 0x10068) EVENT(PM_BR_MPRED_CMPL, 0x400f6) +EVENT (mem_access,0x100010401e0 )
Signature · 1 line
1.9.1
PATCH 5/8 powerpc/perf: Define big-endian version of perf_mem_data_src
In reply to Madhavan SrinivasanFrom: Sukadev Bhattiprolu <[email protected]>
perf_mem_data_src is an union that is initialized via the ->val field and accessed via the bitmap fields. For this to work on big endian platforms, we also need a big-endian represenation of perf_mem_data_src.
--- include/uapi/linux/perf_event.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
include/uapi/linux/perf_event.h +16 -0
@@ -747,6 +747,7 @@ enum perf_callchain_context {#define PERF_FLAG_PID_CGROUP (1UL << 2)/* pid=cgroup id, per-cpu mode only */ #define PERF_FLAG_FD_CLOEXEC (1UL << 3)/* O_CLOEXEC */ +#if defined(__LITTLE_ENDIAN_BITFIELD) union perf_mem_data_src { __u64 val; struct {
@@ -758,6 +759,21 @@ union perf_mem_data_src { mem_rsvd:31; }; }; +#elif defined(__BIG_ENDIAN_BITFIELD) +union perf_mem_data_src { +__u64 val; +struct { +__u64 mem_rsvd:31 , + mem_dtlb:7 ,/* tlb access */ + mem_lock:2 ,/* lock instr */ + mem_snoop:5 ,/* snoop mode */ + mem_lvl:14 ,/* memory hierarchy level */ + mem_op:5 ;/* type of opcode */ + }; +}; +#else +#error "Unknown endianness" +#endif /* type of opcode (load/store/prefetch,code) */ #define PERF_MEM_OP_NA 0x01/* not available */
Signature · 1 line
1.9.1
PATCH 6/8 powerpc/perf: Export Power8 memory hierarchy info to user space
In reply to Madhavan SrinivasanFrom: Sukadev Bhattiprolu <[email protected]>
On Power8, the LDST field in SIER identifies the memory hierarchy level (eg: L1, L2 etc), from which a data-cache miss for a marked instruction was satisfied.
Use the 'perf_mem_data_src' object to export this hierarchy level to user space. Fortunately, the memory hierarchy levels in Power8 map fairly easily into the arch-neutral levels as described by the ldst_src_map[] table.
Usage:
perf record -d -e 'cpu/mem_access/' <application>
perf report -n --mem-mode --sort=mem,sym,dso,symbol_daddr,dso_daddr"
For samples involving load/store instructions, the memory hierarchy level is shown as "L1 hit", "Remote RAM hit" etc.
# or
perf record --data <application>
perf report -D
Sample records contain a 'data_src' field which encodes the memory hierarchy level: Eg: data_src 0x442 indicates MEM_OP_LOAD, MEM_LVL_HIT, MEM_LVL_L2 (i.e load hit L2).
As the precise semantics of 'perf mem -t load' or 'perf mem -t store' (which require sampling only loads or only stores) cannot be implemented on Power, we don't implement 'perf mem' on Power for now.
Thanks to input from Stephane Eranian, Michael Ellerman and Michael Neuling.
---
Edited the commit message to fit in the new event name
arch/powerpc/include/asm/perf_event_server.h | 2 ++ arch/powerpc/perf/core-book3s.c | 11 ++++++ arch/powerpc/perf/power8-pmu.c | 53 ++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+)
arch/powerpc/include/asm/perf_event_server.h +2 -0
@@ -42,6 +42,8 @@ struct power_pmu {void (*config_bhrb)(u64 pmu_bhrb_filter);void (*disable_pmc)(unsigned int pmc,unsigned long mmcr[]);int (*limited_pmc_event)(u64 event_id); +void (*get_mem_data_src)(union perf_mem_data_src *dsrc, +struct pt_regs *regs);u32 flags;const struct attribute_group **attr_groups;int n_generic;
arch/powerpc/perf/core-book3s.c +11 -0
@@ -1888,6 +1888,13 @@ ssize_t power_events_sysfs_show(struct device *dev,return sprintf (page,"event=0x%02llx\n" , pmu_attr->id); } +static inline void power_get_mem_data_src (union perf_mem_data_src *dsrc, +struct pt_regs *regs) +{ +if (ppmu->get_mem_data_src) + ppmu->get_mem_data_src (dsrc, regs); +} +static struct pmu power_pmu = { .pmu_enable = power_pmu_enable, .pmu_disable = power_pmu_disable,
@@ -1969,6 +1976,10 @@ static void record_and_restart(struct perf_event *event, unsigned long val, data.br_stack = &cpuhw->bhrb_stack; } +if (event->attr.sample_type &PERF_SAMPLE_DATA_SRC && + ppmu->get_mem_data_src) + ppmu->get_mem_data_src (&data.data_src, regs); +if (perf_event_overflow (event, &data, regs))power_pmu_stop (event,0 ); }
arch/powerpc/perf/power8-pmu.c +53 -0
65 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 7/8 powerpc/perf: Set data source value
In reply to Madhavan Srinivasanperf_sample_data_init initialize the data source variable "->val" with PERF_MEM_NA. New value should not be ORed since the userspace perf tool will look at bitmap field when displaying the hierarchy levels.
--- arch/powerpc/perf/power8-pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/perf/power8-pmu.c +1 -1
@@ -684,7 +684,7 @@ static void power8_get_mem_data_src(union perf_mem_data_src *dsrc,if (is_load_store_inst (sier)) { idx = (sier &POWER8_SIER_LDST_MASK ) >>POWER8_SIER_LDST_SHIFT ; - dsrc->val |= ldst_src_map[idx]; + dsrc->val = ldst_src_map[idx]; } }
Signature · 1 line
1.9.1
PATCH 8/8 powerpc/perf: cleanup in perf_event_print_debug()
In reply to Madhavan SrinivasanFrom: Janani <[email protected]>
Code cleanup/fix in perf_event_print_debug(). Performance Monitoring Unit (PMU) registers in the server side are 64bit long.
--- arch/powerpc/perf/core-book3s.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/perf/core-book3s.c +3 -3
@@ -758,7 +758,7 @@ static void write_pmc(int idx, unsigned long val)void perf_event_print_debug (void ) {unsigned long sdar, sier, flags; -u32 pmcs[MAX_HWEVENTS ]; +unsigned long pmcs[MAX_HWEVENTS ];int i;if (!ppmu->n_counter)
@@ -775,11 +775,11 @@ void perf_event_print_debug(void)for (; i <MAX_HWEVENTS ; i++) pmcs[i] =0xdeadbeef ; -pr_info ("PMC1: %08x PMC2: %08x PMC3: %08x PMC4: %08x\n" , +pr_info ("PMC1: %016lx PMC2: %016lx PMC3: %016lx PMC4: %016lx\n" , pmcs[0 ], pmcs[1 ], pmcs[2 ], pmcs[3 ]);if (ppmu->n_counter >4 ) -pr_info ("PMC5: %08x PMC6: %08x PMC7: %08x PMC8: %08x\n" , +pr_info ("PMC5: %016lx PMC6: %016lx PMC7: %016lx PMC8: %016lx\n" , pmcs[4 ], pmcs[5 ], pmcs[6 ], pmcs[7 ]); pr_info("MMCR0: %016lx MMCR1: %016lx MMCRA: %016lx\n",
Signature · 1 line
1.9.1
Michael Ellerman
reviewerRe: [8/8] powerpc/perf: cleanup in perf_event_print_debug()
Quoted 5 lines · Madhavan Srinivasan
From: Janani <[email protected]>
Code cleanup/fix in
perf_event_print_debug(). Performance Monitoring Unit (PMU) registers in the server side are 64bit long.
No they're not, see the ISA, figure 17.
cheers