powerpc/32: Unset MSR RI in exception epilogs
RFC 1/2 powerpc/32: Unset MSR RI in exception epilogs
In reply to a message not in the archiveAt exception prologs, once SRR0 and SRR1 have been saved, MSR RI is set to mark the interrupt as recoverable.
MSR RI has to be unset before writing into SRR0 and SRR1 at exception epilogs.
--- arch/powerpc/include/asm/ppc_asm.h | 6 ++++++ arch/powerpc/include/asm/reg_8xx.h | 1 + arch/powerpc/kernel/entry_32.S | 5 +++++ 3 files changed, 12 insertions(+)
arch/powerpc/include/asm/ppc_asm.h +6 -0
@@ -514,6 +514,12 @@ END_FTR_SECTION_IFCLR(CPU_FTR_601)#define MTMSR_EERI (reg) mtmsr reg#endif +#ifdef CONFIG_PPC_8xx +#define SET_MSR_NRI (r) mtspr SPRN_NRI,r +#else +#define SET_MSR_NRI (r) mfmsr r; rlwinm r,r,0,~MSR_RI; MTMSRD(r) +#endif +#endif /* __KERNEL__ */ /* The boring bits... */
arch/powerpc/include/asm/reg_8xx.h +1 -0
@@ -28,6 +28,7 @@/* Special MSR manipulation registers */ #define SPRN_EIE 80/* External interrupt enable (EE=1, RI=1) */ #define SPRN_EID 81/* External interrupt disable (EE=0, RI=1) */ +#define SPRN_NRI 82/* Non recoverable interrupt (EE=0, RI=0) */ /* Debug registers */ #define SPRN_CMPE 152
arch/powerpc/kernel/entry_32.S +5 -0
@@ -205,6 +205,7 @@ transfer_to_handler_cont: mflr r9 lwz r11,0(r9) /* virtual address of handler */ lwz r9,4(r9) /* where to go when done */ + SET_MSR_NRI(r12) #ifdef CONFIG_TRACE_IRQFLAGS lis r12,reenable_mmu@h ori r12,r12,reenable_mmu@l
@@ -292,6 +293,7 @@ stack_ovf: lis r9,StackOverflow@ha addi r9,r9,StackOverflow@l LOAD_MSR_KERNEL(r10,MSR_KERNEL) + SET_MSR_NRI(r12) mtspr SPRN_SRR0,r9 mtspr SPRN_SRR1,r10 SYNC
@@ -418,6 +420,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX) lwz r7,_NIP(r1) lwz r2,GPR2(r1) lwz r1,GPR1(r1) + SET_MSR_NRI(r4) mtspr SPRN_SRR0,r7 mtspr SPRN_SRR1,r8 SYNC
@@ -700,6 +703,7 @@ fast_exception_return: mtcr r10 lwz r10,_LINK(r11) mtlr r10 + SET_MSR_NRI(r10) REST_GPR(10, r11) mtspr SPRN_SRR1,r9 mtspr SPRN_SRR0,r12
@@ -974,6 +978,7 @@ exc_exit_restart_end: .globl exc_exit_restart exc_exit_restart: lwz r11,_NIP(r1) + SET_MSR_NRI(r12) lwz r12,_MSR(r1) exc_exit_start: mtspr SPRN_SRR0,r11
Signature · 1 line
2.10.1
RFC 2/2 powerpc/8xx: Perf events on PPC 8xx
In reply to a message not in the archiveThe 8xx has no PMU, however some events can be emulated by other means.
This patch implements the following 4 events:
cpu-cycles OR cycles [Hardware event] instructions [Hardware event] dTLB-load-misses [Hardware cache event] iTLB-load-misses [Hardware cache event]
'cycles' event is implemented using the timebase clock. Timebase clock corresponds to CPU clock divided by 16, so number of cycles is approximatly 16 times the number of TB ticks
'instructions' is calculated by using instruction watchpoint counter. We set counter A to count instructions at address greater than 0, hence we count all instructions executed while MSR RI bit is set. The counter is set to the maximum which is 0xffff. Every 65535 instructions, debug instruction breakpoint exception fires. The exception handler increments a counter in memory which then represent the upper part of the instruction counter.
On the 8xx, TLB misses are handled by software. It is therefore easy to count all TLB misses.
--- arch/powerpc/include/asm/reg.h | 2 + arch/powerpc/include/asm/reg_8xx.h | 3 + arch/powerpc/kernel/head_8xx.S | 45 +++++++- arch/powerpc/perf/8xx-pmu.c | 181 +++++++++++++++++++++++++++++++++ arch/powerpc/perf/Makefile | 2 + arch/powerpc/platforms/Kconfig.cputype | 7 ++ 6 files changed, 237 insertions(+), 3 deletions(-) create mode 100644 arch/powerpc/perf/8xx-pmu.c
arch/powerpc/include/asm/reg.h +2 -0
@@ -548,7 +548,9 @@#define SPRN_IBAT7U 0x236/* Instruction BAT 7 Upper Register */ #define SPRN_ICMP 0x3D5/* Instruction TLB Compare Register */ #define SPRN_ICTC 0x3FB/* Instruction Cache Throttling Control Reg */ +#ifndef SPRN_ICTRL #define SPRN_ICTRL 0x3F3/* 1011 7450 icache and interrupt ctrl */ +#endif #define ICTRL_EICE 0x08000000/* enable icache parity errs */ #define ICTRL_EDC 0x04000000/* enable dcache parity errs */ #define ICTRL_EICP 0x00000100/* enable icache par. check */
arch/powerpc/include/asm/reg_8xx.h +3 -0
@@ -31,10 +31,13 @@#define SPRN_NRI 82/* Non recoverable interrupt (EE=0, RI=0) */ /* Debug registers */ +#define SPRN_CMPA 144 +#define SPRN_COUNTA 150#define SPRN_CMPE 152#define SPRN_CMPF 153#define SPRN_LCTRL1 156#define SPRN_LCTRL2 157 +#define SPRN_ICTRL 158#define SPRN_BAR 159/* Commands. Only the first few are available to the instruction cache.
arch/powerpc/kernel/head_8xx.S +42 -3
73 lines not on this page · raw message
arch/powerpc/perf/8xx-pmu.c new file +181 -0
181 lines not on this page · raw message
arch/powerpc/perf/Makefile +2 -0
@@ -13,5 +13,7 @@ obj-$(CONFIG_FSL_EMB_PERF_EVENT_E500) += e500-pmu.o e6500-pmu.o obj-$(CONFIG_HV_PERF_CTRS) += hv-24x7.o hv-gpci.o hv-common.o +obj-$(CONFIG_PPC_8xx_PERF_EVENT) += 8xx-pmu.o + obj-$(CONFIG_PPC64) += $(obj64-y) obj-$(CONFIG_PPC32) += $(obj32-y)
arch/powerpc/platforms/Kconfig.cputype +7 -0
@@ -172,6 +172,13 @@ config PPC_FPU bool default y if PPC64 +config PPC_8xx_PERF_EVENT + bool "PPC 8xx perf events" + depends on PPC_8xx && PERF_EVENTS + help + This is Performance Events support for PPC 8xx. The 8xx doesn't + have a PMU but some events are emulated using 8xx features. + config FSL_EMB_PERFMON bool "Freescale Embedded Perfmon" depends on E500 || PPC_83xx
Signature · 1 line
2.10.1
Quoted 5 lines · Christophe Leroy
At exception prologs, once SRR0 and SRR1 have been saved, MSR RI is set to mark the interrupt as recoverable.
MSR RI has to be unset before writing into SRR0 and SRR1 at exception epilogs.
Why? What goes wrong without this? Etc.
Segher
Quoted 10 lines · Segher Boessenkool
Quoted 5 lines · Christophe Leroy
At exception prologs, once SRR0 and SRR1 have been saved, MSR RI is set to mark the interrupt as recoverable.
MSR RI has to be unset before writing into SRR0 and SRR1 at exception epilogs.
Why? What goes wrong without this? Etc.
The following patch implements perf instruction counting using the 8xx debug counters. When the counter reaches 0, it fires a debug exception. If that exception happens between the setting of srr0/srr1 and the rfi, values set to srr0/srr1 are lost and we end up with an Oops.
To avoid that, MSR RI has to be unset. That way, because the debug counters mode is set to masked mode in register LCTRL2, no debug interrupt will happen during that critical phase.
Christophe
---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus
Quoted 10 lines · christophe leroy
Quoted 8 lines · Segher Boessenkool
Quoted 5 lines · Christophe Leroy
At exception prologs, once SRR0 and SRR1 have been saved, MSR RI is set to mark the interrupt as recoverable.
MSR RI has to be unset before writing into SRR0 and SRR1 at exception epilogs.
Why? What goes wrong without this? Etc.
Quoted 8 lines
The following patch implements perf instruction counting using the 8xx debug counters. When the counter reaches 0, it fires a debug exception. If that exception happens between the setting of srr0/srr1 and the rfi, values set to srr0/srr1 are lost and we end up with an Oops.
To avoid that, MSR RI has to be unset. That way, because the debug counters mode is set to masked mode in register LCTRL2, no debug interrupt will happen during that critical phase.
Okay, so why then do you do an expensive sequence on all other processors?
Segher
Quoted 16 lines · Segher Boessenkool
Quoted 15 lines · christophe leroy
Quoted 8 lines · Segher Boessenkool
Quoted 5 lines · Christophe Leroy
At exception prologs, once SRR0 and SRR1 have been saved, MSR RI is set to mark the interrupt as recoverable.
MSR RI has to be unset before writing into SRR0 and SRR1 at exception epilogs.
Why? What goes wrong without this? Etc.
The following patch implements perf instruction counting using the 8xx debug counters. When the counter reaches 0, it fires a debug exception. If that exception happens between the setting of srr0/srr1 and the rfi, values set to srr0/srr1 are lost and we end up with an Oops.
Quoted 6 lines
Quoted 3 lines
To avoid that, MSR RI has to be unset. That way, because the debug counters mode is set to masked mode in register LCTRL2, no debug interrupt will happen during that critical phase.
Okay, so why then do you do an expensive sequence on all other processors?
Does ppc32 support runtime code patching? If so, you could perhaps utilize that to only inflict the painful code sequence when perf is enabled.
Re: [RFC 2/2] powerpc/8xx: Perf events on PPC 8xx
In reply to Christophe Leroyarch/powerpc/perf/8xx-pmu.c line 70
Quoted 11 lines · Christophe Leroy
arch/powerpc/perf/8xx-pmu.c new file +11
-0+int mpc8xx_pmu_event_init (struct perf_event *event) +{ +int type =event_type (event); + +switch (type) { +case PERF_8xx_ID_CPU_CYCLES: +case PERF_8xx_ID_ITLB_LOAD_MISS: +case PERF_8xx_ID_DTLB_LOAD_MISS: +break ; +case PERF_8xx_ID_HW_INSTRUCTIONS: +mtspr (SPRN_CMPA ,0 );
Should that not live in init_mpc8xx_pmu() ?
Afaict its a one time setup thing.
Quoted 11 lines
arch/powerpc/perf/8xx-pmu.c new file +11
-0+break ; +default : +return type; + } +return 0 ; +} + +int mpc8xx_pmu_add (struct perf_event *event,int flags) +{ +int type =event_type (event); +s64 val;
arch/powerpc/perf/8xx-pmu.c line 91
Quoted 10 lines
arch/powerpc/perf/8xx-pmu.c new file +10
-0+ +switch (type) { +case PERF_8xx_ID_CPU_CYCLES: + val =get_tb (); +break ; +case PERF_8xx_ID_HW_INSTRUCTIONS: + val = (instruction_counter <<16 ) |0xffff ; +mtspr (SPRN_COUNTA ,0xffff0001 ); +mtspr (SPRN_ICTRL ,0xc0080007 ); +break ;
So this sets up the counter and starts counting, right?
What happens if someone adds two events of this type?
Also, typical implementations would do:
if (flags & PERF_EF_START) mpc8xx_pmu_start(event, flags);
arch/powerpc/perf/8xx-pmu.c line 101
Quoted 10 lines
arch/powerpc/perf/8xx-pmu.c new file +10
-0+case PERF_8xx_ID_ITLB_LOAD_MISS: + val = itlb_miss_counter; +break ; +case PERF_8xx_ID_DTLB_LOAD_MISS: + val = dtlb_miss_counter; +break ; +default : +break ; + } +local64_set (&event->hw.prev_count, val);
Right, so aside from that INSTRUCTION event, the rest is treated like freerunning counters which is fine.
Quoted 24 lines
arch/powerpc/perf/8xx-pmu.c new file +24
-0+return 0 ; +} + +void mpc8xx_pmu_read (struct perf_event *event) +{ +int type =event_type (event); +s64 prev, val, delta; + + prev =local64_read (&event->hw.prev_count); +switch (type) { +case PERF_8xx_ID_CPU_CYCLES: + val =get_tb (); + delta =16 * (val - prev); +break ; +case PERF_8xx_ID_HW_INSTRUCTIONS: +mtspr (SPRN_ICTRL ,7 ); + val = (instruction_counter <<16 ) | (0xffff - (mfspr (SPRN_COUNTA ) >>16 )); +mtspr (SPRN_ICTRL ,0xc0080007 ); + delta = val - prev; +break ; +case PERF_8xx_ID_ITLB_LOAD_MISS: + val = itlb_miss_counter; + delta = val - prev; +break ;
arch/powerpc/perf/8xx-pmu.c line 135
Quoted 10 lines
arch/powerpc/perf/8xx-pmu.c new file +10
-0+case PERF_8xx_ID_DTLB_LOAD_MISS: + val = dtlb_miss_counter; + delta = val - prev; +break ; +default : +break ; + } +local64_set (&event->hw.prev_count, val); +local64_add (delta, &event->count); +}
So there is one case, where we group this event with a software hrtimer event and the hrtimer would call ::read() from interrupt context while you're already in ::read().
This seems to suggest you still need a cmpxchg() loop to update, no?
Quoted 10 lines
arch/powerpc/perf/8xx-pmu.c new file +10
-0+void mpc8xx_pmu_del (struct perf_event *event,int flags) +{ +int type =event_type (event); +s64 prev, val; + + prev =local64_read (&event->hw.prev_count); +switch (type) { +case PERF_8xx_ID_HW_INSTRUCTIONS: +mtspr (SPRN_ICTRL ,7 ); + val = (instruction_counter <<16 ) | (0xffff - (mfspr (SPRN_COUNTA ) >>16 ));
arch/powerpc/perf/8xx-pmu.c line 156
Quoted 10 lines
arch/powerpc/perf/8xx-pmu.c new file +10
-0+local64_add (val - prev, &event->count); +break ; +case PERF_8xx_ID_CPU_CYCLES: +case PERF_8xx_ID_ITLB_LOAD_MISS: +case PERF_8xx_ID_DTLB_LOAD_MISS: +mpc8xx_pmu_read (event); +break ; +default : +break ; + }
Right, so you make all del()'s imply PERF_EF_UPDATE, which is fine.
arch/powerpc/perf/8xx-pmu.c line 165
Quoted 9 lines
arch/powerpc/perf/8xx-pmu.c new file +9
-0+} + +void mpc8xx_pmu_start (struct perf_event *event,int flags) +{ +} + +void mpc8xx_pmu_stop (struct perf_event *event,int flags) +{ +}
So I think you can get away with doing this because the PMU doesn't do sampling, which is what would normally start/stop already programmed counters.
arch/powerpc/perf/8xx-pmu.c line 173
Quoted 7 lines
arch/powerpc/perf/8xx-pmu.c new file +7
-0+static struct pmu mpc8xx_pmu = { + .event_init = mpc8xx_pmu_event_init, + .add = mpc8xx_pmu_add, + .del = mpc8xx_pmu_del, + .start = mpc8xx_pmu_start, + .stop = mpc8xx_pmu_stop, + .read = mpc8xx_pmu_read,
.capabilities = PERF_PMU_CAP_NO_INTERRUPT |
PERF_PMU_CAP_NO_NMI,
Quoted 8 lines
arch/powerpc/perf/8xx-pmu.c new file +8
-0+}; + +static int init_mpc8xx_pmu (void ) +{ +return perf_pmu_register (&mpc8xx_pmu,"cpu" ,PERF_TYPE_RAW ); +} + +early_initcall (init_mpc8xx_pmu);