powerpc/perf: Create mmcra_sihv/mmcra_sipv helpers
Subsystems (2)
PATCH 1/4 powerpc/perf: Create mmcra_sihv/mmcra_sipv helpers
We want to access the MMCRA_SIHV and MMCRA_SIPR bits elsewhere so create mmcra_sihv and mmcra_sipr which hide the differences between the old and new layout of the bits.
---
arch/powerpc/perf/core-book3s.c +22 -9
@@ -116,6 +116,26 @@ static inline void perf_get_data_addr(st *addrp =mfspr (SPRN_SDAR ); } +static bool mmcra_sihv (unsigned long mmcra) +{ +unsigned long sihv =MMCRA_SIHV ; + +if (ppmu->flags &PPMU_ALT_SIPR ) + sihv =POWER6_MMCRA_SIHV ; + +return !!(mmcra & sihv); +} + +static bool mmcra_sipr (unsigned long mmcra) +{ +unsigned long sipr =MMCRA_SIPR ; + +if (ppmu->flags &PPMU_ALT_SIPR ) + sipr =POWER6_MMCRA_SIPR ; + +return !!(mmcra & sipr); +} +static inline u32 perf_flags_from_msr (struct pt_regs *regs) {if (regs->msr &MSR_PR )
@@ -128,8 +148,6 @@ static inline u32 perf_flags_from_msr(ststatic inline u32 perf_get_misc_flags (struct pt_regs *regs) {unsigned long mmcra = regs->dsisr; -unsigned long sihv =MMCRA_SIHV ; -unsigned long sipr =MMCRA_SIPR ;/* Not a PMU interrupt: Make up flags from regs->msr */ if (TRAP (regs) !=0xf00 )
@@ -156,15 +174,10 @@ static inline u32 perf_get_misc_flags(streturn PERF_RECORD_MISC_USER ; } -if (ppmu->flags &PPMU_ALT_SIPR ) { - sihv =POWER6_MMCRA_SIHV ; - sipr =POWER6_MMCRA_SIPR ; - } -/* PR has priority over HV, so order below is important */ -if (mmcra & sipr) +if (mmcra_sipr (mmcra))return PERF_RECORD_MISC_USER ; -if ((mmcra & sihv) && (freeze_events_kernel !=MMCR0_FCHV )) +if (mmcra_sihv (mmcra) && (freeze_events_kernel !=MMCR0_FCHV ))return PERF_RECORD_MISC_HYPERVISOR ;return PERF_RECORD_MISC_KERNEL ; }
PATCH 2/4 powerpc/perf: Move code to select SIAR or pt_regs into perf_read_regs
The logic to choose whether to use the SIAR or get the information out of pt_regs is going to get more complicated, so do it once in perf_read_regs.
We overload regs->result which is gross but we are already doing it with regs->dsisr.
---
Other architectures appear to be playing similar overloading tricks so we should probably solve this in a nicer way.
arch/powerpc/include/asm/perf_event.h +5 -0
@@ -26,8 +26,13 @@#include <asm/ptrace.h> #include <asm/reg.h> +/* +* Overload regs->result to specify whether we should use the MSR (result +* is zero) or the SIAR (result is non zero). +*/ #define perf_arch_fetch_caller_regs (regs, __ip) \ do { \ + (regs)->result = 0; \ (regs)->nip = __ip; \ (regs)->gpr[1] = *(unsigned long *)__get_SP(); \ asm volatile("mfmsr %0" : "=r" ((regs)->msr)); \
arch/powerpc/perf/core-book3s.c +25 -22
77 lines not on this page · raw message
PATCH 3/4 powerpc/perf: Always use pt_regs for userspace samples
In reply to Anton BlanchardAt the moment we always use the SIAR if the PMU supports continuous sampling. Unfortunately the SIAR and the PMU exception are not synchronised for non marked events so we can end up with callchains that dont make sense.
The following patch checks the HV and PR bits for samples coming from userspace and always uses pt_regs for them. Userspace will never have interrupts off so there is no real advantage to using the SIAR for non marked events in userspace.
I had experimented with a patch that did a similar thing for kernel samples but we lost a significant amount of information. I was unable to profile any of our early exception code for example.
---
arch/powerpc/perf/core-book3s.c +22 -1
@@ -189,9 +189,30 @@ static inline void perf_read_regs(structint marked = mmcra &MMCRA_SAMPLE_ENABLE ;int use_siar; +/* +* If this isn't a PMU exception (eg a software event) the SIAR is +* not valid. Use pt_regs. +* +* If it is a marked event use the SIAR. +* +* If the PMU doesn't update the SIAR for non marked events use +* pt_regs. +* +* If the PMU has HV/PR flags then check to see if they +* place the exception in userspace. If so, use pt_regs. In +* continuous sampling mode the SIAR and the PMU exception are +* not synchronised, so they may be many instructions apart. +* This can result in confusing backtraces. We still want +* hypervisor samples as well as samples in the kernel with +* interrupts off hence the userspace check. +*/ if (TRAP (regs) !=0xf00 ) use_siar =0 ; -else if ((ppmu->flags &PPMU_NO_CONT_SAMPLING ) && !marked) +else if (marked) + use_siar =1 ; +else if ((ppmu->flags &PPMU_NO_CONT_SAMPLING )) + use_siar =0 ; +else if (!(ppmu->flags &PPMU_NO_SIPR ) &&mmcra_sipr (mmcra)) use_siar =0 ;else use_siar =1 ;
PATCH 4/4 powerpc/perf: Use perf_instruction_pointer in callchains
In reply to Anton BlanchardWe use SIAR or regs->nip for the instruction pointer depending on the PMU configuration, but we always use regs->nip in the callchain.
Use perf_instruction_pointer so the backtrace is consistent.
---
arch/powerpc/perf/callchain.c +3 -3
@@ -57,7 +57,7 @@ perf_callchain_kernel(struct perf_callch lr = regs->link; sp = regs->gpr[1 ]; -perf_callchain_store (entry, regs->nip); +perf_callchain_store (entry,perf_instruction_pointer (regs));if (!validate_sp (sp, current,STACK_FRAME_OVERHEAD ))return ;
@@ -238,7 +238,7 @@ static void perf_callchain_user_64(strucstruct signal_frame_64 __user *sigframe;unsigned long __user *fp, *uregs; - next_ip = regs->nip; + next_ip =perf_instruction_pointer (regs); lr = regs->link; sp = regs->gpr[1 ];perf_callchain_store (entry, next_ip);
@@ -444,7 +444,7 @@ static void perf_callchain_user_32(struclong level =0 ;unsigned int __user *fp, *uregs; - next_ip = regs->nip; + next_ip =perf_instruction_pointer (regs); lr = regs->link; sp = regs->gpr[1 ];perf_callchain_store (entry, next_ip);
Re: [PATCH 4/4] powerpc/perf: Use perf_instruction_pointer in callchains
Quoted 14 lines · Anton Blanchard
We use SIAR or
regs->nipfor the instruction pointer depending on the PMU configuration, but we always useregs->nipin the callchain.Use
perf_instruction_pointerso the backtrace is consistent.Signed-off-by Anton Blanchard <[email protected]>---
Index:
linux-build/arch/powerpc/perf/callchain.c
===================================================================
arch/powerpc/perf/callchain.c perf_callchain_kernel(struct perf_callch · line 60
Quoted 5 lines
arch/powerpc/perf/callchain.c +1
-1@@ -57,7 +57,7 @@ perf_callchain_kernel(struct perf_callch lr = regs->link; sp = regs->gpr[1 ]; -perf_callchain_store (entry, regs->nip); +perf_callchain_store (entry,perf_instruction_pointer (regs));
Won't this break core-fsl-emb, which doesn't define perf_instruction_pointer()?
-Scott
Re: [PATCH 4/4] powerpc/perf: Use perf_instruction_pointer in callchains
Hi Scott,
Quoted 2 lines
Won't this break core-fsl-emb, which doesn't define
perf_instruction_pointer()?
It links ok for me. You should get the default version:
#ifndef perf_misc_flags
# define perf_misc_flags(regs) \
(user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL)
# define perf_instruction_pointer(regs) instruction_pointer(regs)
#endifAnton
Re: [PATCH 4/4] powerpc/perf: Use perf_instruction_pointer in callchains
Quoted 6 lines · Anton Blanchard
Hi Scott,
Quoted 2 lines
Won't this break core-fsl-emb, which doesn't define
perf_instruction_pointer()?
Quoted 7 lines
It links ok for me. You should get the default version:
#ifndef
perf_misc_flags# define perf_misc_flags(regs) \ (user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL) # define perf_instruction_pointer(regs) instruction_pointer(regs) #endif
OK, sorry -- forgot to grep outside arch/powerpc. :-)
-Scott
Quoted 5 lines · Anton Blanchard
We want to access the
MMCRA_SIHVandMMCRA_SIPRbits elsewhere so createmmcra_sihvandmmcra_siprwhich hide the differences between the old and new layout of the bits.
Hey Anton,
Going further in this direction, we can actually create wrapper functions to capture SIHV and SIPR values whether they are based out of MMCRA register or not. It would help us decide PERF_RECORD_MISC_USER | PERF_RECORD_MISC_HYPERVISOR | PERF_RECORD_MISC_KERNEL hiding the register and related bit details.
Quoted 30 lines
Signed-off-by Anton Blanchard <[email protected]>---
Index:
linux-build/arch/powerpc/perf/core-book3s.c
===================================================================arch/powerpc/perf/core-book3s.c +19
-0@@ -116,6 +116,26 @@ static inline void perf_get_data_addr(st *addrp =mfspr (SPRN_SDAR ); } +static bool mmcra_sihv (unsigned long mmcra) +{ +unsigned long sihv =MMCRA_SIHV ; + +if (ppmu->flags &PPMU_ALT_SIPR ) + sihv =POWER6_MMCRA_SIHV ; + +return !!(mmcra & sihv); +} + +static bool mmcra_sipr (unsigned long mmcra) +{ +unsigned long sipr =MMCRA_SIPR ; + +if (ppmu->flags &PPMU_ALT_SIPR ) + sipr =POWER6_MMCRA_SIPR ; + +return !!(mmcra & sipr); +}