Lazy interrupt disabling for 64-bit machines
PATCH 1/1 Lazy interrupt disabling for 64-bit machines
This implements a lazy strategy for disabling interrupts. This means that local_irq_disable() et al. just clear the 'interrupts are enabled' flag in the paca. If an interrupt comes along, the interrupt entry code notices that interrupts are supposed to be disabled, and clears the EE bit in SRR1, clears the 'interrupts are hard-enabled' flag in the paca, and returns. This means that interrupts only actually get disabled in the processor when an interrupt comes along.
When interrupts are enabled by local_irq_enable() et al., the code sets the interrupts-enabled flag in the paca, and then checks whether interrupts got hard-disabled. If so, it also sets the EE bit in the MSR to hard-enable the interrupts.
This has the potential to improve performance, and also makes it easier to make a kernel that can boot on iSeries and on other 64-bit machines, since this lazy-disable strategy is very similar to the soft-disable strategy that iSeries already uses.
---
arch/powerpc/kernel/asm-offsets.c +1 -0
@@ -119,6 +119,7 @@ #ifdef CONFIG_PPC64DEFINE (PACAR1 , offsetof(struct paca_struct , saved_r1));DEFINE (PACATOC , offsetof(struct paca_struct , kernel_toc));DEFINE (PACAPROCENABLED , offsetof(struct paca_struct , proc_enabled)); +DEFINE (PACAHARDIRQEN , offsetof(struct paca_struct , hard_enabled));DEFINE (PACASLBCACHE , offsetof(struct paca_struct , slb_cache));DEFINE (PACASLBCACHEPTR , offsetof(struct paca_struct , slb_cache_ptr)); DEFINE(PACACONTEXTID, offsetof(struct paca_struct, context.id));
arch/powerpc/kernel/entry_64.S +16 -17
@@ -28,10 +28,6 @@ #include <asm/ppc_asm.h> #include <asm/asm-offsets.h> #include <asm/cputable.h> -#ifdef CONFIG_PPC_ISERIES -#define DO_SOFT_DISABLE -#endif - /* * System calls. */
@@ -90,14 +86,16 @@ system_call_common: addi r9,r1,STACK_FRAME_OVERHEAD ld r11,exception_marker@toc(r2) std r11,-16(r9) /* "regshere" marker */ + li r10,1 + stb r10,PACAPROCENABLED(r13) + stb r10,PACAHARDIRQEN(r13) + std r10,SOFTE(r1) #ifdef CONFIG_PPC_ISERIES /* Hack for handling interrupts when soft-enabling on iSeries */ cmpdi cr1,r0,0x5555 /* syscall 0x5555 */ andi. r10,r12,MSR_PR /* from kernel */ crand 4*cr0+eq,4*cr1+eq,4*cr0+eq beq hardware_interrupt_entry - lbz r10,PACAPROCENABLED(r13) - std r10,SOFTE(r1) #endif mfmsr r11 ori r11,r11,MSR_EE
@@ -461,8 +459,8 @@ #else /* !CONFIG_PREEMPT */ #endif restore: -#ifdef CONFIG_PPC_ISERIES ld r5,SOFTE(r1) +#ifdef CONFIG_PPC_ISERIES cmpdi 0,r5,0 beq 4f /* Check for pending interrupts (iSeries) */
@@ -479,8 +477,9 @@ #ifdef CONFIG_PPC_ISERIES bl .do_IRQ b .ret_from_except_lite /* loop back and handle more */ -4: stb r5,PACAPROCENABLED(r13) +4: #endif + stb r5,PACAPROCENABLED(r13) ld r3,_MSR(r1) andi. r0,r3,MSR_RI
@@ -537,20 +536,15 @@ #ifdef CONFIG_PREEMPT /* Check that preempt_count() == 0 and interrupts are enabled */ lwz r8,TI_PREEMPT(r9) cmpwi cr1,r8,0 -#ifdef CONFIG_PPC_ISERIES ld r0,SOFTE(r1) cmpdi r0,0 -#else - andi. r0,r3,MSR_EE -#endif crandc eq,cr1*4+eq,eq bne restore /* here we are preempting the current task */ 1: -#ifdef CONFIG_PPC_ISERIES li r0,1 stb r0,PACAPROCENABLED(r13) -#endif + stb r0,PACAHARDIRQEN(r13) ori r10,r10,MSR_EE mtmsrd r10,1 /* reenable interrupts */ bl .preempt_schedule
@@ -633,8 +627,7 @@ _GLOBAL(enter_rtas) /* There is no way it is acceptable to get here with interrupts enabled, * check it with the asm equivalent of WARN_ON */ - mfmsr r6 - andi. r0,r6,MSR_EE + lbz r0,PACAPROCENABLED(r13) 1: tdnei r0,0 .section __bug_table,"a" .llong 1b,__LINE__ + 0x1000000, 1f, 2f
@@ -643,7 +636,13 @@ _GLOBAL(enter_rtas) 1: .asciz __FILE__ 2: .asciz "enter_rtas" .previous - + + /* Hard-disable interrupts */ + mfmsr r6 + rldicl r7,r6,48,1 + rotldi r7,r7,16 + mtmsrd r7,1 + /* Unfortunately, the stack pointer and the MSR are also clobbered, * so they are saved in the PACA which allows us to restore * our original state after RTAS returns.
arch/powerpc/kernel/head_64.S +66 -23
163 lines not on this page · raw message
arch/powerpc/kernel/idle_power4.S +7 -1
@@ -30,6 +30,13 @@ END_FTR_SECTION_IFCLR(CPU_FTR_CAN_NAP) beqlr /* Go to NAP now */ + mfmsr r7 + rldicl r0,r7,48,1 + rotldi r0,r0,16 + mtmsrd r0,1 /* hard-disable interrupts */ + li r0,1 + stb r0,PACAPROCENABLED(r13) /* we'll hard-enable shortly */ + stb r0,PACAHARDIRQEN(r13) BEGIN_FTR_SECTION DSSALL sync
@@ -38,7 +45,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) ld r8,TI_LOCAL_FLAGS(r9) /* set napping bit */ ori r8,r8,_TLF_NAPPING /* so when we take an exception */ std r8,TI_LOCAL_FLAGS(r9) /* it will return to our caller */ - mfmsr r7 ori r7,r7,MSR_EE oris r7,r7,MSR_POW@h 1: sync
arch/powerpc/kernel/irq.c +14 -0
@@ -95,6 +95,20 @@ #ifdef CONFIG_PPC64EXPORT_SYMBOL (irq_desc);int distribute_irqs =1 ; + +#ifndef CONFIG_PPC_ISERIES +void local_irq_restore (unsigned long en) +{ +get_paca ()->proc_enabled = en; +if (!en ||get_paca ()->hard_enabled) +return ; +/* need to hard-enable interrupts here */ +get_paca ()->hard_enabled = en; +if ((int )mfspr (SPRN_DEC ) <0 ) +mtspr (SPRN_DEC ,1 ); +hard_irq_enable (); +} +#endif /* CONFIG_PPC_ISERIES */ #endif /* CONFIG_PPC64 */ int show_interrupts (struct seq_file *p,void *v)
arch/powerpc/kernel/ppc_ksyms.c +4 -0
@@ -49,6 +49,10 @@ #ifdef CONFIG_8xx#include <asm/commproc.h> #endif +#ifdef CONFIG_PPC64 +EXPORT_SYMBOL (local_irq_restore); +#endif +#ifdef CONFIG_PPC32 extern void transfer_to_handler (void );extern void do_IRQ (struct pt_regs *regs);
arch/powerpc/platforms/iseries/ksyms.c +0 -6
@@ -19,9 +19,3 @@ EXPORT_SYMBOL(HvCall4);EXPORT_SYMBOL (HvCall5);EXPORT_SYMBOL (HvCall6);EXPORT_SYMBOL (HvCall7); - -#ifdef CONFIG_SMP -EXPORT_SYMBOL (local_get_flags); -EXPORT_SYMBOL (local_irq_disable); -EXPORT_SYMBOL (local_irq_restore); -#endif
arch/powerpc/platforms/iseries/misc.S +0 -12
@@ -19,18 +19,6 @@ #include <asm/ppc_asm.h> .text -/* unsigned long local_save_flags(void) */ -_GLOBAL(local_get_flags) - lbz r3,PACAPROCENABLED(r13) - blr - -/* unsigned long local_irq_disable(void) */ -_GLOBAL(local_irq_disable) - lbz r3,PACAPROCENABLED(r13) - li r4,0 - stb r4,PACAPROCENABLED(r13) - blr /* Done */ - /* void local_irq_restore(unsigned long flags) */ _GLOBAL(local_irq_restore) lbz r5,PACAPROCENABLED(r13)
include/asm-powerpc/hw_irq.h +20 -10
@@ -7,15 +7,28 @@ #define _ASM_POWERPC_HW_IRQ_H#ifdef __KERNEL__#include <linux/errno.h> +#include <linux/compiler.h> #include <asm/ptrace.h> #include <asm/processor.h> extern void timer_interrupt (struct pt_regs *); -#ifdef CONFIG_PPC_ISERIES +#ifdef CONFIG_PPC64 +#include <asm/paca.h> + +static inline unsigned long local_get_flags (void ) +{ +return get_paca ()->proc_enabled; +} + +static inline unsigned long local_irq_disable (void ) +{ +unsigned long flag =get_paca ()->proc_enabled; +get_paca ()->proc_enabled =0 ; +barrier (); +return flag; +} -extern unsigned long local_get_flags (void ); -extern unsigned long local_irq_disable (void );extern void local_irq_restore (unsigned long );#define local_irq_enable () local_irq_restore(1)
@@ -24,17 +37,14 @@ #define local_irq_save(flags) ((flags) =#define irqs_disabled () (local_get_flags() == 0) +#define hard_irq_enable () __mtmsrd(mfmsr() | MSR_EE, 1) +#define hard_irq_disable () __mtmsrd(mfmsr() & ~MSR_EE, 1) +#else #if defined(CONFIG_BOOKE )#define SET_MSR_EE (x) mtmsr(x)#define local_irq_restore (flags) __asm__ __volatile__("wrtee %0" : : "r" (flags) : "memory") -#elif defined(__powerpc64__) -#define SET_MSR_EE (x) __mtmsrd(x, 1) -#define local_irq_restore (flags) do { \ - __asm__ __volatile__("": : :"memory"); \ - __mtmsrd((flags), 1); \ -} while(0)#else #define SET_MSR_EE (x) mtmsr(x)#define local_irq_restore (flags) mtmsr(flags)
@@ -81,7 +91,7 @@ #define local_save_flags(flags) ((flags)#define local_irq_save (flags) local_irq_save_ptr(&flags)#define irqs_disabled () ((mfmsr() & MSR_EE) == 0) -#endif /* CONFIG_PPC_ISERIES */ +#endif /* CONFIG_PPC64 */ #define mask_irq (irq) \ ({ \
include/asm-powerpc/paca.h +1 -0
@@ -94,6 +94,7 @@ #endif /* CONFIG_PPC_ISERIES */u64 saved_r1;/* r1 save for RTAS calls */ u64 saved_msr;/* MSR saved here by enter_rtas */ u8 proc_enabled;/* irq soft-enable flag */ +u8 hard_enabled;/* set if irqs are enabled in MSR */ u8 io_sync;/* writel() needs spin_unlock sync */ /* Stuff for accurate time accounting */
Quoted 7 lines · Paul Mackerras
This implements a lazy strategy for disabling interrupts. This means that
local_irq_disable()et al. just clear the 'interrupts are enabled' flag in the paca. If an interrupt comes along, the interrupt entry code notices that interrupts are supposed to be disabled, and clears the EE bit in SRR1, clears the 'interrupts are hard-enabled' flag in the paca, and returns. This means that interrupts only actually get disabled in the processor when an interrupt comes along.
I saw this once testing kdump, although I haven't hit it again (3 retries).
Badness in _local_bh_enable at /home/michael/src/auto/git/kernel/softirq.c:120
Call Trace:
[C000000009F83B60] [C00000000200F810] .show_stack+0x6c/0x1a0 (unreliable)
[C000000009F83C00] [C0000000020219F0] .program_check_exception+0x19c/0x5d0
[C000000009F83CA0] [C0000000020043D0] program_check_common+0xd0/0x100
--- Exception: 700 at ._local_bh_enable+0x34/0x78
LR = .call_do_softirq+0x14/0x24
[C0000000028FF8B0] [C00000000200C4A8] .do_softirq+0x6c/0xb0
[C0000000028FF940] [C00000000204E550] .irq_exit+0x4c/0x64
[C0000000028FF9C0] [C00000000201FC94] .timer_interrupt+0x3c0/0x3fc
[C0000000028FFA90] [C00000000200354C] decrementer_common+0xcc/0x100
--- Exception: 901 at .__delay+0x8/0x24
LR = .__cpu_up+0x118/0x214
[C0000000028FFD80] [C000000002024C80] .__cpu_up+0xfc/0x214 (unreliable)
[C0000000028FFE10] [C00000000206987C] .cpu_up+0xd4/0x164
[C0000000028FFEC0] [C0000000020093A0] .init+0xd4/0x39c
[C0000000028FFF90] [C000000002022F0C] .kernel_thread+0x4c/0x68Looks like it's hitting the in_irq() warning:
void _local_bh_enable(void)
{
WARN_ON_ONCE(in_irq());
WARN_ON_ONCE(!irqs_disabled());
...cheers
Signature · 8 lines
Michael Ellerman OzLabs, IBM Australia Development Lab wwweb: http://michael.ellerman.id.au phone: +61 2 6212 1183 (tie line 70 21183) We do not inherit the earth from our ancestors, we borrow it from our children. - S.M.A.R.T Person
Quoted 13 lines · On Tue, 26 Sep 2006 14:55:30 +1000 Paul Mackerras <[email protected]> wrote:
This implements a lazy strategy for disabling interrupts. This means that
local_irq_disable()et al. just clear the 'interrupts are enabled' flag in the paca. If an interrupt comes along, the interrupt entry code notices that interrupts are supposed to be disabled, and clears the EE bit in SRR1, clears the 'interrupts are hard-enabled' flag in the paca, and returns. This means that interrupts only actually get disabled in the processor when an interrupt comes along.When interrupts are enabled by
local_irq_enable()et al., the code sets the interrupts-enabled flag in the paca, and then checks whether interrupts got hard-disabled. If so, it also sets the EE bit in the MSR to hard-enable the interrupts.
Quoted 4 lines
This has the potential to improve performance, and also makes it easier to make a kernel that can boot on iSeries and on other 64-bit machines, since this lazy-disable strategy is very similar to the soft-disable strategy that iSeries already uses.
I like it. Got any benchmarks that show a difference?
At first glance I found it a bit hard to follow, since the old+new terminology is a bit complicated. There's softe, proc_enabled and hard_enabled. A s/proc_enabled/soft_enabled/g (and similar for asm-offsets) might make it a little more intuitive, since you're touching most uses of it already?
-Olof
Quoted 8 lines
I like it. Got any benchmarks that show a difference?
At first glance I found it a bit hard to follow, since the old+new terminology is a bit complicated. There's softe,
proc_enabledandhard_enabled. A s/proc_enabled/soft_enabled/g (and similar for asm-offsets) might make it a little more intuitive, since you're touching most uses of it already?
Now think about using -ffixed=crN ... reserve a CR field and use that for per-cpu flags like that :)
Ben.
Quoted 12 lines · Benjamin Herrenschmidt
Quoted 8 lines
I like it. Got any benchmarks that show a difference?
At first glance I found it a bit hard to follow, since the old+new terminology is a bit complicated. There's softe,
proc_enabledandhard_enabled. A s/proc_enabled/soft_enabled/g (and similar for asm-offsets) might make it a little more intuitive, since you're touching most uses of it already?Now think about using -ffixed=crN ... reserve a CR field and use that for per-cpu flags like that :)
Actually cr5 is never used by GCC on any PPC. Look at the source code in config/rs6000.h, it is marked fixed and never allocated as far as I understand.
Regards,
Gabriel "an unused register is a wasted register"
Quoted 11 lines · On Tue, 26 Sep 2006 19:12:06 +1000 Benjamin Herrenschmidt…
Quoted 8 lines
I like it. Got any benchmarks that show a difference?
At first glance I found it a bit hard to follow, since the old+new terminology is a bit complicated. There's softe,
proc_enabledandhard_enabled. A s/proc_enabled/soft_enabled/g (and similar for asm-offsets) might make it a little more intuitive, since you're touching most uses of it already?Now think about using -ffixed=crN ... reserve a CR field and use that for per-cpu flags like that :)
You can also get away from doing the mfspr(SPRN_DEC) in local_irq_enable() by changing the polarity of hard_enabled to hard_disabled, and have different values for why it was disabled. Saves an mfspr which can be costly, but adds one instruction (li (n>>8) or so) in the exception entry path. Not which way that tradeoff will swing, without benchmarking to show benefit it's just added complexity.
That can be done with a fixed cr too, it just uses two bits instead of one. There are fewer to take from there though.
-Olof