linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/3] idle improvements again
@ 2018-04-01  5:48 Nicholas Piggin
  2018-04-01  5:48 ` [PATCH v3 1/3] powerpc/64s/idle: POWER9 implement a separate idle stop function for hotplug Nicholas Piggin
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Nicholas Piggin @ 2018-04-01  5:48 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Nicholas Piggin, Vaidyanathan Srinivasan, Gautham R . Shenoy,
	Paul Mackerras

Since last time, this has been rebased on top of the KVM / SMT4
forcing changes. It has also been updated so as to not disable
EC=ESL=0 idle states for CPU unplug.

That case (and powersave=off) continues to be broken for KVM with
unplugged dependent secondaries, but that's another issue.

This also has EC=ESL=0 states to skip the new hwsync added for the
KVM workaround, which should increase their performance advantage a
little further.

Thanks,
Nick

Nicholas Piggin (3):
  powerpc/64s/idle: POWER9 implement a separate idle stop function for
    hotplug
  powerpc/64s/idle: avoid sync for KVM state when waking from idle
  powerpc/64s/idle: POWER9 ESL=0 stop avoid save/restore overhead

 arch/powerpc/include/asm/processor.h  |  1 +
 arch/powerpc/kernel/idle_book3s.S     | 69 +++++++++++++++++------------------
 arch/powerpc/platforms/powernv/idle.c |  2 +-
 3 files changed, 36 insertions(+), 36 deletions(-)

-- 
2.16.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/3] powerpc/64s/idle: POWER9 implement a separate idle stop function for hotplug
  2018-04-01  5:48 [PATCH v3 0/3] idle improvements again Nicholas Piggin
@ 2018-04-01  5:48 ` Nicholas Piggin
  2018-04-01  5:48 ` [PATCH v3 2/3] powerpc/64s/idle: avoid sync for KVM state when waking from idle Nicholas Piggin
  2018-04-01  5:48 ` [PATCH v3 3/3] powerpc/64s/idle: POWER9 ESL=0 stop avoid save/restore overhead Nicholas Piggin
  2 siblings, 0 replies; 5+ messages in thread
From: Nicholas Piggin @ 2018-04-01  5:48 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Nicholas Piggin, Vaidyanathan Srinivasan, Gautham R . Shenoy,
	Paul Mackerras

Implement a new function to invoke stop, power9_offline_stop, which is
like power9_idle_stop but used by the cpu hotplug code.

Move KVM secondary state manipulation code to the offline case.

Cc: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Cc: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Cc: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/include/asm/processor.h  |  1 +
 arch/powerpc/kernel/idle_book3s.S     | 21 +++++++++++++++------
 arch/powerpc/platforms/powernv/idle.c |  2 +-
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/include/asm/processor.h b/arch/powerpc/include/asm/processor.h
index bb9cb25ffb20..c4b36a494a63 100644
--- a/arch/powerpc/include/asm/processor.h
+++ b/arch/powerpc/include/asm/processor.h
@@ -518,6 +518,7 @@ extern int powersave_nap;	/* set if nap mode can be used in idle loop */
 extern unsigned long power7_idle_insn(unsigned long type); /* PNV_THREAD_NAP/etc*/
 extern void power7_idle_type(unsigned long type);
 extern unsigned long power9_idle_stop(unsigned long psscr_val);
+extern unsigned long power9_offline_stop(unsigned long psscr_val);
 extern void power9_idle_type(unsigned long stop_psscr_val,
 			      unsigned long stop_psscr_mask);
 
diff --git a/arch/powerpc/kernel/idle_book3s.S b/arch/powerpc/kernel/idle_book3s.S
index d503203842b0..fc2e5cf2c74c 100644
--- a/arch/powerpc/kernel/idle_book3s.S
+++ b/arch/powerpc/kernel/idle_book3s.S
@@ -325,12 +325,6 @@ enter_winkle:
  * r3 - PSSCR value corresponding to the requested stop state.
  */
 power_enter_stop:
-#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
-	/* Tell KVM we're entering idle */
-	li	r4,KVM_HWTHREAD_IN_IDLE
-	/* DO THIS IN REAL MODE!  See comment above. */
-	stb	r4,HSTATE_HWTHREAD_STATE(r13)
-#endif
 /*
  * Check if we are executing the lite variant with ESL=EC=0
  */
@@ -428,7 +422,22 @@ ALT_FTR_SECTION_END_NESTED_IFSET(CPU_FTR_ARCH_207S, 66);		\
 /*
  * Entered with MSR[EE]=0 and no soft-masked interrupts pending.
  * r3 contains desired PSSCR register value.
+ *
+ * Offline (CPU unplug) case also must notify KVM that the CPU is
+ * idle.
  */
+_GLOBAL(power9_offline_stop)
+#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
+	/*
+	 * Tell KVM we're entering idle.
+	 * This does not have to be done in real mode because the P9 MMU
+	 * is independent per-thread. Some steppings share radix/hash mode
+	 * between threads, but in that case KVM has a barrier sync in real
+	 * mode before and after switching between radix and hash.
+	 */
+	li	r4,KVM_HWTHREAD_IN_IDLE
+	stb	r4,HSTATE_HWTHREAD_STATE(r13)
+#endif
 _GLOBAL(power9_idle_stop)
 	std	r3, PACA_REQ_PSSCR(r13)
 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
diff --git a/arch/powerpc/platforms/powernv/idle.c b/arch/powerpc/platforms/powernv/idle.c
index d9e366bb23da..378fde1f85a8 100644
--- a/arch/powerpc/platforms/powernv/idle.c
+++ b/arch/powerpc/platforms/powernv/idle.c
@@ -511,7 +511,7 @@ unsigned long pnv_cpu_offline(unsigned int cpu)
 		psscr = mfspr(SPRN_PSSCR);
 		psscr = (psscr & ~pnv_deepest_stop_psscr_mask) |
 						pnv_deepest_stop_psscr_val;
-		srr1 = power9_idle_stop(psscr);
+		srr1 = power9_offline_stop(psscr);
 
 	} else if ((idle_states & OPAL_PM_WINKLE_ENABLED) &&
 		   (idle_states & OPAL_PM_LOSE_FULL_CONTEXT)) {
-- 
2.16.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/3] powerpc/64s/idle: avoid sync for KVM state when waking from idle
  2018-04-01  5:48 [PATCH v3 0/3] idle improvements again Nicholas Piggin
  2018-04-01  5:48 ` [PATCH v3 1/3] powerpc/64s/idle: POWER9 implement a separate idle stop function for hotplug Nicholas Piggin
@ 2018-04-01  5:48 ` Nicholas Piggin
  2018-04-01  5:48 ` [PATCH v3 3/3] powerpc/64s/idle: POWER9 ESL=0 stop avoid save/restore overhead Nicholas Piggin
  2 siblings, 0 replies; 5+ messages in thread
From: Nicholas Piggin @ 2018-04-01  5:48 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Nicholas Piggin, Vaidyanathan Srinivasan, Gautham R . Shenoy,
	Paul Mackerras

When waking from a CPU idle instruction (e.g., nap or stop), the sync
for ordering the KVM secondary thread state can be avoided if there
wakeup is coming from a kernel context rather than KVM context.

This improves performance for ping-pong benchmark with the stop0 idle
state by 0.46% for 2 threads in the same core, and 1.02% for different
cores.

Cc: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Cc: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Cc: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/idle_book3s.S | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/powerpc/kernel/idle_book3s.S b/arch/powerpc/kernel/idle_book3s.S
index fc2e5cf2c74c..68fa97885fc0 100644
--- a/arch/powerpc/kernel/idle_book3s.S
+++ b/arch/powerpc/kernel/idle_book3s.S
@@ -549,6 +549,9 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_300)
 	mr	r3,r12
 
 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
+	lbz	r0,HSTATE_HWTHREAD_STATE(r13)
+	cmpwi	r0,KVM_HWTHREAD_IN_KERNEL
+	beq	1f
 	li	r0,KVM_HWTHREAD_IN_KERNEL
 	stb	r0,HSTATE_HWTHREAD_STATE(r13)
 	/* Order setting hwthread_state vs. testing hwthread_req */
-- 
2.16.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 3/3] powerpc/64s/idle: POWER9 ESL=0 stop avoid save/restore overhead
  2018-04-01  5:48 [PATCH v3 0/3] idle improvements again Nicholas Piggin
  2018-04-01  5:48 ` [PATCH v3 1/3] powerpc/64s/idle: POWER9 implement a separate idle stop function for hotplug Nicholas Piggin
  2018-04-01  5:48 ` [PATCH v3 2/3] powerpc/64s/idle: avoid sync for KVM state when waking from idle Nicholas Piggin
@ 2018-04-01  5:48 ` Nicholas Piggin
  2018-04-04 14:39   ` [v3, " Michael Ellerman
  2 siblings, 1 reply; 5+ messages in thread
From: Nicholas Piggin @ 2018-04-01  5:48 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Nicholas Piggin, Vaidyanathan Srinivasan, Gautham R . Shenoy,
	Paul Mackerras

When stop is executed with EC=ESL=0, it appears to execute like a
normal instruction (resuming from NIP when woken by interrupt). So all
the save/restore handling can be avoided completely. In particular NV
GPRs do not have to be saved, and MSR does not have to be switched
back to kernel MSR.

So move the test for EC=ESL=0 sleep states out to power9_idle_stop,
and return directly to the caller after stop in that case.

This improves performance for ping-pong benchmark with the stop0_lite
idle state by 2.54% for 2 threads in the same core, and 2.57% for
different cores. Performance increase with HV_POSSIBLE defined will be
improved further by avoiding the hwsync.

Cc: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Cc: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Cc: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/idle_book3s.S | 45 ++++++++++++++-------------------------
 1 file changed, 16 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/kernel/idle_book3s.S b/arch/powerpc/kernel/idle_book3s.S
index 68fa97885fc0..dedcd78a204a 100644
--- a/arch/powerpc/kernel/idle_book3s.S
+++ b/arch/powerpc/kernel/idle_book3s.S
@@ -324,32 +324,8 @@ enter_winkle:
 /*
  * r3 - PSSCR value corresponding to the requested stop state.
  */
-power_enter_stop:
-/*
- * Check if we are executing the lite variant with ESL=EC=0
- */
-	andis.   r4,r3,PSSCR_EC_ESL_MASK_SHIFTED
+power_enter_stop_esl:
 	clrldi   r3,r3,60 /* r3 = Bits[60:63] = Requested Level (RL) */
-	bne	 .Lhandle_esl_ec_set
-	PPC_STOP
-	li	r3,0  /* Since we didn't lose state, return 0 */
-	std	r3, PACA_REQ_PSSCR(r13)
-
-	/*
-	 * pnv_wakeup_noloss() expects r12 to contain the SRR1 value so
-	 * it can determine if the wakeup reason is an HMI in
-	 * CHECK_HMI_INTERRUPT.
-	 *
-	 * However, when we wakeup with ESL=0, SRR1 will not contain the wakeup
-	 * reason, so there is no point setting r12 to SRR1.
-	 *
-	 * Further, we clear r12 here, so that we don't accidentally enter the
-	 * HMI in pnv_wakeup_noloss() if the value of r12[42:45] == WAKE_HMI.
-	 */
-	li	r12, 0
-	b 	pnv_wakeup_noloss
-
-.Lhandle_esl_ec_set:
 BEGIN_FTR_SECTION
 	/*
 	 * POWER9 DD2.0 or earlier can incorrectly set PMAO when waking up after
@@ -439,21 +415,32 @@ _GLOBAL(power9_offline_stop)
 	stb	r4,HSTATE_HWTHREAD_STATE(r13)
 #endif
 _GLOBAL(power9_idle_stop)
+	mtspr 	SPRN_PSSCR,r3
+	/*
+	 * The ESL=EC=0 case does not wake up at 0x100, and it does not
+	 * allow SMT mode switching, so it does not require PSSCR to be
+	 * saved.
+	 */
+	andis.	r4,r3,PSSCR_EC_ESL_MASK_SHIFTED
+	bne	1f
+	PPC_STOP
+	li	r3,0  /* Since we didn't lose state, return 0 */
+	blr
+1:
 	std	r3, PACA_REQ_PSSCR(r13)
 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
 BEGIN_FTR_SECTION
 	sync
 	lwz	r5, PACA_DONT_STOP(r13)
 	cmpwi	r5, 0
-	bne	1f
+	bne	2f
 END_FTR_SECTION_IFSET(CPU_FTR_P9_TM_XER_SO_BUG)
 #endif
-	mtspr 	SPRN_PSSCR,r3
-	LOAD_REG_ADDR(r4,power_enter_stop)
+	LOAD_REG_ADDR(r4,power_enter_stop_esl)
 	b	pnv_powersave_common
 	/* No return */
 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
-1:
+2:
 	/*
 	 * We get here when TM / thread reconfiguration bug workaround
 	 * code wants to get the CPU into SMT4 mode, and therefore
-- 
2.16.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [v3, 3/3] powerpc/64s/idle: POWER9 ESL=0 stop avoid save/restore overhead
  2018-04-01  5:48 ` [PATCH v3 3/3] powerpc/64s/idle: POWER9 ESL=0 stop avoid save/restore overhead Nicholas Piggin
@ 2018-04-04 14:39   ` Michael Ellerman
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2018-04-04 14:39 UTC (permalink / raw)
  To: Nicholas Piggin, linuxppc-dev; +Cc: Gautham R . Shenoy, Nicholas Piggin

On Sun, 2018-04-01 at 05:48:55 UTC, Nicholas Piggin wrote:
> When stop is executed with EC=ESL=0, it appears to execute like a
> normal instruction (resuming from NIP when woken by interrupt). So all
> the save/restore handling can be avoided completely. In particular NV
> GPRs do not have to be saved, and MSR does not have to be switched
> back to kernel MSR.
> 
> So move the test for EC=ESL=0 sleep states out to power9_idle_stop,
> and return directly to the caller after stop in that case.
> 
> This improves performance for ping-pong benchmark with the stop0_lite
> idle state by 2.54% for 2 threads in the same core, and 2.57% for
> different cores. Performance increase with HV_POSSIBLE defined will be
> improved further by avoiding the hwsync.
> 
> Cc: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
> Cc: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
> Cc: Paul Mackerras <paulus@ozlabs.org>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/b9ee31e100e73075431faaf7af2ee0

cheers

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-04-04 14:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-01  5:48 [PATCH v3 0/3] idle improvements again Nicholas Piggin
2018-04-01  5:48 ` [PATCH v3 1/3] powerpc/64s/idle: POWER9 implement a separate idle stop function for hotplug Nicholas Piggin
2018-04-01  5:48 ` [PATCH v3 2/3] powerpc/64s/idle: avoid sync for KVM state when waking from idle Nicholas Piggin
2018-04-01  5:48 ` [PATCH v3 3/3] powerpc/64s/idle: POWER9 ESL=0 stop avoid save/restore overhead Nicholas Piggin
2018-04-04 14:39   ` [v3, " Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).