process interrupts from idle wakeup
Subsystems (2)
Nicholas Piggin
reviewercover process interrupts from idle wakeup
Hi,
Just wanted to get some opinions on this approach. I will wait until current batch of idle fixes are merged before submitting properly, and still need to test on POWER9, but on POWER8 the speedup is quite good.
Thanks,
Nick
Nicholas Piggin (2):
powerpc/powernv: process interrupts from system reset wakeup powerpc/64s: msgclr when handling doorbell exceptions
arch/powerpc/include/asm/dbell.h | 13 +++++++++++++ arch/powerpc/include/asm/machdep.h | 1 - arch/powerpc/include/asm/ppc-opcode.h | 3 +++ arch/powerpc/include/asm/processor.h | 1 + arch/powerpc/kernel/dbell.c | 9 +++++++++ arch/powerpc/platforms/powernv/idle.c | 11 ++++++++--- drivers/cpuidle/cpuidle-powernv.c | 35 +++++++++++++++++++++++++++++++++-- 7 files changed, 67 insertions(+), 6 deletions(-)
Signature · 1 line
2.11.0
Nicholas Piggin
reviewerPATCH 1/2 powerpc/powernv: process interrupts from system reset wakeup
When the CPU wakes from low power state, it begins at the system reset interrupt with the exception that caused the wakeup encoded in SRR1.
Today, powernv idle wakeup ignores the wakeup reason (except a special case for HMI), and the regular interrupt corresponding to the exception will fire after the idle wakeup exits.
Change this to replay the interrupt from the idle wakeup before interrupts are hard-enabled.
Test on POWER8 of context_switch selftests benchmark with polling idle disabled (e.g., always nap) gives the following results:
original wakeup direct Different threads, same core: 315k/s 264k/s Different cores: 235k/s 242k/s
There is a slowdown for doorbell IPI (same core) case because system reset wakeup does not clear the message and the doorbell interrupt fires again needlessly.
--- arch/powerpc/include/asm/machdep.h | 1 - arch/powerpc/include/asm/processor.h | 1 + arch/powerpc/platforms/powernv/idle.c | 11 ++++++++--- drivers/cpuidle/cpuidle-powernv.c | 35 +++++++++++++++++++++++++++++++++-- 4 files changed, 42 insertions(+), 6 deletions(-)
arch/powerpc/include/asm/machdep.h +0 -1
@@ -223,7 +223,6 @@ struct machdep_calls {extern void e500_idle (void );extern void power4_idle (void ); -extern void power7_idle (void );extern void ppc6xx_idle (void );extern void book3e_idle (void );
arch/powerpc/include/asm/processor.h +1 -0
@@ -454,6 +454,7 @@ extern int powersave_nap; /* set if nap mode can be used in idle loop */extern unsigned long power7_nap (int check_irq);extern unsigned long power7_sleep (void );extern unsigned long power7_winkle (void ); +extern unsigned long power7_idle (void );extern unsigned long power9_idle_stop (unsigned long stop_psscr_val,unsigned long stop_psscr_mask);
arch/powerpc/platforms/powernv/idle.c +8 -3
@@ -234,11 +234,16 @@ u64 pnv_default_stop_mask;/* * Used for ppc_md.power_save which needs a function with no parameters */ -static void power9_idle (void ) +static void power9_power_save (void ) {power9_idle_stop (pnv_default_stop_val, pnv_default_stop_mask); } +static void power7_power_save (void ) +{ +power7_idle (); +} +/* * First deep stop state. Used to figure out when to save/restore * hypervisor context.
@@ -534,9 +539,9 @@ static int __init pnv_init_idle_states(void) }if (supported_cpuidle_states &OPAL_PM_NAP_ENABLED ) - ppc_md.power_save = power7_idle; + ppc_md.power_save = power7_power_save;else if (supported_cpuidle_states &OPAL_PM_STOP_INST_FAST ) - ppc_md.power_save = power9_idle; + ppc_md.power_save = power9_power_save; out:return 0 ;
drivers/cpuidle/cpuidle-powernv.c +33 -2
@@ -70,13 +70,37 @@ static int snooze_loop(struct cpuidle_device *dev,return index; } +/* +* Table to convert shifted SRR1 wakeup reason for POWER7, POWER8, POWER9 +* to __replay_interrupt vector. +*/ +static const unsigned short srr1_wakeup_to_replay_table[0x10 ] = +{0 ,0 ,0 ,0xe80 ,/* 0x3 = hv doorbell */ +0 ,0xa00 ,/* 0x5 = doorbell */ +0x900 ,/* 0x6 = decrementer */ +0 ,0x500 ,/* 0x8 = external */ +0xea0 ,/* 0x9 = hv virt (POWER9) */ +0xe60 ,/* 0xa = hmi */ +0 ,0 ,0 ,0 ,0 , }; + +/* Shift SRR1_WAKEMASK_P8 down and convert to __replay_interrupt vector */ +#define SRR1_TO_REPLAY (srr1) \ + ((unsigned int)srr1_wakeup_to_replay_table[((srr1) >> 18) & 0xf]) +static int nap_loop (struct cpuidle_device *dev,struct cpuidle_driver *drv,int index) { +u64 srr1; +unsigned int reason; +ppc64_runlatch_off (); -power7_idle (); + srr1 =power7_idle ();ppc64_runlatch_on (); + + reason =SRR1_TO_REPLAY (srr1); +__replay_interrupt (reason); +return index; }
@@ -111,10 +135,17 @@ static int stop_loop(struct cpuidle_device *dev, struct cpuidle_driver *drv, int index) { +u64 srr1; +unsigned int reason; +ppc64_runlatch_off (); -power9_idle_stop (stop_psscr_table[index].val, + srr1 =power9_idle_stop (stop_psscr_table[index].val, stop_psscr_table[index].mask);ppc64_runlatch_on (); + + reason =SRR1_TO_REPLAY (srr1); +__replay_interrupt (reason); +return index; }
Signature · 1 line
2.11.0
Michael Ellerman
reviewerRe: [PATCH 1/2] powerpc/powernv: process interrupts from system reset wakeup
Quoted 13 lines · Nicholas Piggin
When the CPU wakes from low power state, it begins at the system reset interrupt with the exception that caused the wakeup encoded in SRR1.
Today, powernv idle wakeup ignores the wakeup reason (except a special case for HMI), and the regular interrupt corresponding to the exception will fire after the idle wakeup exits.
Change this to replay the interrupt from the idle wakeup before interrupts are hard-enabled.
Test on POWER8 of
context_switchselftests benchmark with polling idle disabled (e.g., always nap) gives the following results:
Quoted 7 lines
original wakeup direct Different threads, same core: 315k/s 264k/s Different cores: 235k/s 242k/sThere is a slowdown for doorbell IPI (same core) case because system reset wakeup does not clear the message and the doorbell interrupt fires again needlessly.
Seems like a win.
Quoted 32 lines
arch/powerpc/include/asm/machdep.h +0
-1@@ -223,7 +223,6 @@ struct machdep_calls {extern void e500_idle (void );extern void power4_idle (void ); -extern void power7_idle (void );extern void ppc6xx_idle (void );extern void book3e_idle (void );arch/powerpc/include/asm/processor.h +1
-0@@ -454,6 +454,7 @@ extern int powersave_nap; /* set if nap mode can be used in idle loop */extern unsigned long power7_nap (int check_irq);extern unsigned long power7_sleep (void );extern unsigned long power7_winkle (void ); +extern unsigned long power7_idle (void );extern unsigned long power9_idle_stop (unsigned long stop_psscr_val,unsigned long stop_psscr_mask);arch/powerpc/platforms/powernv/idle.c +0
-0@@ -234,11 +234,16 @@ u64 pnv_default_stop_mask;/* * Used for ppc_md.power_save which needs a function with no parameters */
arch/powerpc/platforms/powernv/idle.c u64 pnv_default_stop_mask; · line 245
Quoted 10 lines
arch/powerpc/platforms/powernv/idle.c +5
-1-static void power9_idle (void ) +static void power9_power_save (void ) {power9_idle_stop (pnv_default_stop_val, pnv_default_stop_mask); } +static void power7_power_save (void ) +{ +power7_idle (); +}
Erk. This makes me wonder if we can just mandate using cpuidle for powernv and drop ppc_md.power_save. I wonder who if anyone has ever tested powernv without cpuidle.
I notice we already have:
config CPU_IDLE
bool "CPU idle PM support" default y if ACPI || PPC_PSERIES
But not your problem for this patch.
Quoted 26 lines
arch/powerpc/platforms/powernv/idle.c +2
-2@@ -534,9 +539,9 @@ static int __init pnv_init_idle_states(void) }if (supported_cpuidle_states &OPAL_PM_NAP_ENABLED ) - ppc_md.power_save = power7_idle; + ppc_md.power_save = power7_power_save;else if (supported_cpuidle_states &OPAL_PM_STOP_INST_FAST ) - ppc_md.power_save = power9_idle; + ppc_md.power_save = power9_power_save; out:return 0 ;drivers/cpuidle/cpuidle-powernv.c +6
-0@@ -70,13 +70,37 @@ static int snooze_loop(struct cpuidle_device *dev,return index; } +/* +* Table to convert shifted SRR1 wakeup reason for POWER7, POWER8, POWER9 +* to __replay_interrupt vector. +*/ +static const unsigned short srr1_wakeup_to_replay_table[0x10 ] = +{0 ,0 ,0 ,0xe80 ,/* 0x3 = hv doorbell */
drivers/cpuidle/cpuidle-powernv.c static int snooze_loop(struct cpuidle_device *dev, · line 88
Quoted 10 lines
drivers/cpuidle/cpuidle-powernv.c +10
-0+0 ,0xa00 ,/* 0x5 = doorbell */ +0x900 ,/* 0x6 = decrementer */ +0 ,0x500 ,/* 0x8 = external */ +0xea0 ,/* 0x9 = hv virt (POWER9) */ +0xe60 ,/* 0xa = hmi */ + 0, 0, 0, 0, 0, }; + +/* Shift SRR1_WAKEMASK_P8 down and convert to __replay_interrupt vector */ +#define SRR1_TO_REPLAY (srr1) \ + ((unsigned int)srr1_wakeup_to_replay_table[((srr1) >> 18) & 0xf])
This is a bit hairy, I'd just use a switch, but I guess this generates vastly better code?
Quoted 27 lines
drivers/cpuidle/cpuidle-powernv.c +12
-1+static int nap_loop (struct cpuidle_device *dev,struct cpuidle_driver *drv,int index) { +u64 srr1; +unsigned int reason; +ppc64_runlatch_off (); -power7_idle (); + srr1 =power7_idle ();ppc64_runlatch_on (); + + reason =SRR1_TO_REPLAY (srr1); +__replay_interrupt (reason); +return index; }@@ -111,10 +135,17 @@ static int stop_loop(struct cpuidle_device *dev, struct cpuidle_driver *drv, int index) { +u64 srr1; +unsigned int reason; +ppc64_runlatch_off ();
drivers/cpuidle/cpuidle-powernv.c static int stop_loop(struct cpuidle_device *dev, · line 150
Quoted 10 lines
drivers/cpuidle/cpuidle-powernv.c +5
-1-power9_idle_stop (stop_psscr_table[index].val, + srr1 =power9_idle_stop (stop_psscr_table[index].val, stop_psscr_table[index].mask);ppc64_runlatch_on (); + + reason =SRR1_TO_REPLAY (srr1); +__replay_interrupt (reason); +return index; }
We end up with a bit of duplicated code there, but I guess it's not worth worrying about.
cheers
Nicholas Piggin
reviewerPATCH 2/2 powerpc/64s: msgclr when handling doorbell exceptions
In reply to Nicholas Pigginmsgsnd doorbell exceptions are cleared when the doorbell interrupt is taken. However if a doorbell exception causes a system reset interrupt wake from power saving state, the message is not cleared. Processing the doorbell from the system reset interrupt requires msgclr to avoid taking the exception twice.
Testing this plus the previous wakup direct patch gives:
original wakeup direct msgclr Different threads, same core: 315k/s 264k/s 345k/s Different cores: 235k/s 242k/s 242k/s
Net speedup is +10% for same core, and +3% for different core.
--- arch/powerpc/include/asm/dbell.h | 13 +++++++++++++ arch/powerpc/include/asm/ppc-opcode.h | 3 +++ arch/powerpc/kernel/dbell.c | 9 +++++++++ 3 files changed, 25 insertions(+)
arch/powerpc/include/asm/dbell.h +13 -0
@@ -46,6 +46,19 @@ static inline void _ppc_msgsnd(u32 msg) __asm__ __volatile__ (PPC_MSGSNDP(%0) : : "r" (msg)); } +static inline void _ppc_msgclr (u32 msg) +{ + __asm__ __volatile__ (ASM_FTR_IFSET(PPC_MSGCLR(%1), PPC_MSGCLRP(%1), %0) + : : "i" (CPU_FTR_HVMODE), "r" (msg)); +} + +static inline void ppc_msgclr (enum ppc_dbell type) +{ +u32 msg =PPC_DBELL_TYPE (type); + +_ppc_msgclr (msg); +} +#else /* CONFIG_PPC_BOOK3S */ #define PPC_DBELL_MSGTYPE PPC_DBELL
arch/powerpc/include/asm/ppc-opcode.h +3 -0
@@ -162,6 +162,7 @@#define PPC_INST_MSGSND 0x7c00019c#define PPC_INST_MSGCLR 0x7c0001dc#define PPC_INST_MSGSNDP 0x7c00011c +#define PPC_INST_MSGCLRP 0x7c00015c#define PPC_INST_MTTMR 0x7c0003dc#define PPC_INST_NOP 0x60000000#define PPC_INST_PASTE 0x7c00070c
@@ -349,6 +350,8 @@ ___PPC_RB(b))#define PPC_MSGSNDP (b) stringify_in_c(.long PPC_INST_MSGSNDP | \ ___PPC_RB(b)) +#define PPC_MSGCLRP (b) stringify_in_c(.long PPC_INST_MSGCLRP | \ + ___PPC_RB(b))#define PPC_POPCNTB (a, s) stringify_in_c(.long PPC_INST_POPCNTB | \ __PPC_RA(a) | __PPC_RS(s))#define PPC_POPCNTD (a, s) stringify_in_c(.long PPC_INST_POPCNTD | \
arch/powerpc/kernel/dbell.c +9 -0
@@ -40,6 +40,15 @@ void doorbell_exception(struct pt_regs *regs)irq_enter (); +/* +* May have come from doorbell triggered sreset wakeup, which does +* not clear the message (tested on POWER8). Clear it here so we +* don't get a doorbell interrupt when enabling hard irqs. This +* msgclear could be moved into the sreset wakeup replay specific +* code if it is expensive. +*/ +ppc_msgclr (PPC_DBELL_MSGTYPE ); +may_hard_irq_enable ();kvmppc_set_host_ipi (smp_processor_id (),0 );
Signature · 1 line
2.11.0