* [PATCH 0/6] ppc, kvm, cpuidle: Allow offline and kvm standby threads to enter fastsleep
@ 2014-05-28 4:38 Preeti U Murthy
2014-05-28 4:38 ` [PATCH 1/6] powernv, cpuidle: Move the flags used for idle state discovery to powernv core Preeti U Murthy
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: Preeti U Murthy @ 2014-05-28 4:38 UTC (permalink / raw)
To: benh, linux-kernel, svaidyan, paulus, srivatsa.bhat, linuxppc-dev
Fast sleep is a deep idle state on Power8. The support for the state was
added in commit 0d94873011. Today the idle threads in the host can
potentially be put to fast sleep. But when we launch guests using kvm,
the secondary threads are required to be offline and the offline threads
are put to nap. Besides this case, when secondary threads are woken up
to run guests and eventually go idle or when the guest is killed, they
enter nap. So when the entire core goes idle in both the above scenarios,
the maximum power savings that we can obtain is as much as we can get from
napping the cpus. This patchset adds support in the above two cases
for the threads to enter fast sleep.
---
Srivatsa S. Bhat (6):
powernv, cpuidle: Move the flags used for idle state discovery to powernv core
powerpc, powernv, CPU hotplug: Put offline CPUs in Fast-Sleep instead of Nap
KVM: PPC: Book3S HV: Enable CPUs to run guest after waking up from fast-sleep
KVM: PPC: Book3S HV: Consolidate the idle-state enter sequence in KVM
KVM: PPC: Book3S HV: Put KVM standby hwthreads to fast-sleep instead of nap
ppc,book3s: Go back to same idle state after handling machine check interrupt
arch/powerpc/include/asm/processor.h | 12 ++++
arch/powerpc/kernel/exceptions-64s.S | 51 +++++++++------
arch/powerpc/kernel/idle.c | 52 ++++++++++++++++
arch/powerpc/kernel/idle_power7.S | 2 -
arch/powerpc/kvm/book3s_hv_rmhandlers.S | 103 ++++++++++++++++++++++++-------
arch/powerpc/platforms/powernv/smp.c | 12 +++-
drivers/cpuidle/cpuidle-powernv.c | 7 +-
7 files changed, 190 insertions(+), 49 deletions(-)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/6] powernv, cpuidle: Move the flags used for idle state discovery to powernv core
2014-05-28 4:38 [PATCH 0/6] ppc, kvm, cpuidle: Allow offline and kvm standby threads to enter fastsleep Preeti U Murthy
@ 2014-05-28 4:38 ` Preeti U Murthy
2014-05-28 4:38 ` [PATCH 2/6] powerpc, powernv, CPU hotplug: Put offline CPUs in Fast-Sleep instead of Nap Preeti U Murthy
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Preeti U Murthy @ 2014-05-28 4:38 UTC (permalink / raw)
To: benh, linux-kernel, svaidyan, paulus, srivatsa.bhat, linuxppc-dev
From: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
These flags will be used by the cpuidle driver as well as in the cpu
offline path. The offline cpus should be put to fastsleep if the idle state
is discovered so as to gain maximum power savings in the offline state.
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
[ Changelog added by <preeti@linux.vnet.ibm.com> ]
Signed-off-by: Preeti U Murthy <preeti@linux.vnet.ibm.com>
---
arch/powerpc/include/asm/processor.h | 4 ++++
drivers/cpuidle/cpuidle-powernv.c | 7 +++----
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/include/asm/processor.h b/arch/powerpc/include/asm/processor.h
index d660dc3..d922e5c 100644
--- a/arch/powerpc/include/asm/processor.h
+++ b/arch/powerpc/include/asm/processor.h
@@ -445,6 +445,10 @@ static inline unsigned long get_clean_sp(unsigned long sp, int is_32)
}
#endif
+/* Support for 'nap' and 'sleep' instructions, as discovered from the DT */
+#define IDLE_INST_NAP 0x00010000 /* nap instruction can be used */
+#define IDLE_INST_SLEEP 0x00020000 /* sleep instruction can be used */
+
extern unsigned long cpuidle_disable;
enum idle_boot_override {IDLE_NO_OVERRIDE = 0, IDLE_POWERSAVE_OFF};
diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c
index 719f6fb..5d4f9e8 100644
--- a/drivers/cpuidle/cpuidle-powernv.c
+++ b/drivers/cpuidle/cpuidle-powernv.c
@@ -17,12 +17,11 @@
#include <asm/machdep.h>
#include <asm/firmware.h>
#include <asm/runlatch.h>
+#include <asm/processor.h>
/* Flags and constants used in PowerNV platform */
#define MAX_POWERNV_IDLE_STATES 8
-#define IDLE_USE_INST_NAP 0x00010000 /* Use nap instruction */
-#define IDLE_USE_INST_SLEEP 0x00020000 /* Use sleep instruction */
struct cpuidle_driver powernv_idle_driver = {
.name = "powernv_idle",
@@ -187,7 +186,7 @@ static int powernv_add_idle_states(void)
for (i = 0; i < dt_idle_states; i++) {
- if (flags[i] & IDLE_USE_INST_NAP) {
+ if (flags[i] & IDLE_INST_NAP) {
/* Add NAP state */
strcpy(powernv_states[nr_idle_states].name, "Nap");
strcpy(powernv_states[nr_idle_states].desc, "Nap");
@@ -198,7 +197,7 @@ static int powernv_add_idle_states(void)
nr_idle_states++;
}
- if (flags[i] & IDLE_USE_INST_SLEEP) {
+ if (flags[i] & IDLE_INST_SLEEP) {
/* Add FASTSLEEP state */
strcpy(powernv_states[nr_idle_states].name, "FastSleep");
strcpy(powernv_states[nr_idle_states].desc, "FastSleep");
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/6] powerpc, powernv, CPU hotplug: Put offline CPUs in Fast-Sleep instead of Nap
2014-05-28 4:38 [PATCH 0/6] ppc, kvm, cpuidle: Allow offline and kvm standby threads to enter fastsleep Preeti U Murthy
2014-05-28 4:38 ` [PATCH 1/6] powernv, cpuidle: Move the flags used for idle state discovery to powernv core Preeti U Murthy
@ 2014-05-28 4:38 ` Preeti U Murthy
2014-06-05 4:23 ` Paul Mackerras
2014-05-28 4:39 ` [PATCH 3/6] KVM: PPC: Book3S HV: Enable CPUs to run guest after waking up from fast-sleep Preeti U Murthy
` (3 subsequent siblings)
5 siblings, 1 reply; 8+ messages in thread
From: Preeti U Murthy @ 2014-05-28 4:38 UTC (permalink / raw)
To: benh, linux-kernel, svaidyan, paulus, srivatsa.bhat, linuxppc-dev
From: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
The offline cpus are put to fast sleep if the idle state is discovered in the
device tree. This is to gain maximum powersavings in the offline state.
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
[ Changelog added by <preeti@linux.vnet.ibm.com> ]
Signed-off-by: Preeti U Murthy <preeti@linux.vnet.ibm.com>
---
arch/powerpc/include/asm/processor.h | 8 +++++
arch/powerpc/kernel/idle.c | 52 ++++++++++++++++++++++++++++++++++
arch/powerpc/platforms/powernv/smp.c | 12 +++++++-
3 files changed, 71 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/include/asm/processor.h b/arch/powerpc/include/asm/processor.h
index d922e5c..c5256db 100644
--- a/arch/powerpc/include/asm/processor.h
+++ b/arch/powerpc/include/asm/processor.h
@@ -449,6 +449,14 @@ static inline unsigned long get_clean_sp(unsigned long sp, int is_32)
#define IDLE_INST_NAP 0x00010000 /* nap instruction can be used */
#define IDLE_INST_SLEEP 0x00020000 /* sleep instruction can be used */
+/* Flags to indicate which of the CPU idle states are available for use */
+
+#define IDLE_USE_NAP (1UL << 0)
+#define IDLE_USE_SLEEP (1UL << 1)
+
+extern unsigned int supported_cpuidle_states;
+extern unsigned int pnv_get_supported_cpuidle_states(void);
+
extern unsigned long cpuidle_disable;
enum idle_boot_override {IDLE_NO_OVERRIDE = 0, IDLE_POWERSAVE_OFF};
diff --git a/arch/powerpc/kernel/idle.c b/arch/powerpc/kernel/idle.c
index d7216c9..e51d574 100644
--- a/arch/powerpc/kernel/idle.c
+++ b/arch/powerpc/kernel/idle.c
@@ -25,6 +25,7 @@
#include <linux/cpu.h>
#include <linux/sysctl.h>
#include <linux/tick.h>
+#include <linux/of.h>
#include <asm/processor.h>
#include <asm/cputable.h>
@@ -32,6 +33,7 @@
#include <asm/machdep.h>
#include <asm/runlatch.h>
#include <asm/smp.h>
+#include <asm/firmware.h>
unsigned long cpuidle_disable = IDLE_NO_OVERRIDE;
@@ -79,6 +81,56 @@ void arch_cpu_idle(void)
ppc64_runlatch_on();
}
+#ifdef CONFIG_PPC_POWERNV
+
+unsigned int supported_cpuidle_states = 0;
+
+unsigned int pnv_get_supported_cpuidle_states(void)
+{
+ return supported_cpuidle_states;
+}
+
+static int __init pnv_probe_idle_states(void)
+{
+ struct device_node *power_mgt;
+ struct property *prop;
+ int dt_idle_states;
+ u32 *flags;
+ int i;
+
+ if (!firmware_has_feature(FW_FEATURE_OPALv3))
+ return 0;
+
+ power_mgt = of_find_node_by_path("/ibm,opal/power-mgt");
+ if (!power_mgt) {
+ pr_warn("opal: PowerMgmt Node not found\n");
+ return 0;
+ }
+
+ prop = of_find_property(power_mgt, "ibm,cpu-idle-state-flags", NULL);
+ if (!prop) {
+ pr_warn("DT-PowerMgmt: missing ibm,cpu-idle-state-flags\n");
+ return 0;
+ }
+
+ dt_idle_states = prop->length / sizeof(u32);
+ flags = (u32 *) prop->value;
+
+ for (i = 0; i < dt_idle_states; i++) {
+ if (flags[i] & IDLE_INST_NAP)
+ supported_cpuidle_states |= IDLE_USE_NAP;
+
+ if (flags[i] & IDLE_INST_SLEEP)
+ supported_cpuidle_states |= IDLE_USE_SLEEP;
+ }
+
+ return 0;
+}
+
+__initcall(pnv_probe_idle_states);
+#endif
+
+
int powersave_nap;
#ifdef CONFIG_SYSCTL
diff --git a/arch/powerpc/platforms/powernv/smp.c b/arch/powerpc/platforms/powernv/smp.c
index bf5fcd4..fc83006 100644
--- a/arch/powerpc/platforms/powernv/smp.c
+++ b/arch/powerpc/platforms/powernv/smp.c
@@ -31,6 +31,7 @@
#include <asm/xics.h>
#include <asm/opal.h>
#include <asm/runlatch.h>
+#include <asm/processor.h>
#include "powernv.h"
@@ -142,6 +143,7 @@ static int pnv_smp_cpu_disable(void)
static void pnv_smp_cpu_kill_self(void)
{
unsigned int cpu;
+ unsigned long idle_states;
/* Standard hot unplug procedure */
local_irq_disable();
@@ -152,13 +154,21 @@ static void pnv_smp_cpu_kill_self(void)
generic_set_cpu_dead(cpu);
smp_wmb();
+ idle_states = pnv_get_supported_cpuidle_states();
+
/* We don't want to take decrementer interrupts while we are offline,
* so clear LPCR:PECE1. We keep PECE2 enabled.
*/
mtspr(SPRN_LPCR, mfspr(SPRN_LPCR) & ~(u64)LPCR_PECE1);
while (!generic_check_cpu_restart(cpu)) {
ppc64_runlatch_off();
- power7_nap();
+
+ /* If sleep is supported, go to sleep, instead of nap */
+ if (idle_states & IDLE_USE_SLEEP)
+ power7_sleep();
+ else
+ power7_nap();
+
ppc64_runlatch_on();
if (!generic_check_cpu_restart(cpu)) {
DBG("CPU%d Unexpected exit while offline !\n", cpu);
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/6] KVM: PPC: Book3S HV: Enable CPUs to run guest after waking up from fast-sleep
2014-05-28 4:38 [PATCH 0/6] ppc, kvm, cpuidle: Allow offline and kvm standby threads to enter fastsleep Preeti U Murthy
2014-05-28 4:38 ` [PATCH 1/6] powernv, cpuidle: Move the flags used for idle state discovery to powernv core Preeti U Murthy
2014-05-28 4:38 ` [PATCH 2/6] powerpc, powernv, CPU hotplug: Put offline CPUs in Fast-Sleep instead of Nap Preeti U Murthy
@ 2014-05-28 4:39 ` Preeti U Murthy
2014-05-28 4:39 ` [PATCH 4/6] KVM: PPC: Book3S HV: Consolidate the idle-state enter sequence in KVM Preeti U Murthy
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Preeti U Murthy @ 2014-05-28 4:39 UTC (permalink / raw)
To: benh, linux-kernel, svaidyan, paulus, srivatsa.bhat, linuxppc-dev
From: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
When guests have to be launched, the secondary threads which are offline
are woken up to run the guests. Today these threads wake up from nap
and check if they have to run guests. Now that the offline secondary threads
can go to fastsleep, add this check in the fastsleep wakeup path as well.
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
[ Changelog added by <preeti@linux.vnet.ibm.com> ]
Signed-off-by: Preeti U Murthy <preeti@linux.vnet.ibm.com>
---
arch/powerpc/kernel/exceptions-64s.S | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 3afd391..b4bf464 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -100,6 +100,19 @@ system_reset_pSeries:
SET_SCRATCH0(r13)
#ifdef CONFIG_PPC_P7_NAP
BEGIN_FTR_SECTION
+
+ GET_PACA(r13)
+#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
+ li r0,KVM_HWTHREAD_IN_KERNEL
+ stb r0,HSTATE_HWTHREAD_STATE(r13)
+ /* Order setting hwthread_state vs. testing hwthread_req */
+ sync
+ lbz r0,HSTATE_HWTHREAD_REQ(r13)
+ cmpwi r0,0
+ beq 1f
+ b kvm_start_guest
+1:
+#endif
/* Running native on arch 2.06 or later, check if we are
* waking up from nap. We only handle no state loss and
* supervisor state loss. We do -not- handle hypervisor
@@ -116,28 +129,15 @@ BEGIN_FTR_SECTION
* OPAL v3 based powernv platforms have new idle states
* which fall in this catagory.
*/
- bgt cr1,8f
GET_PACA(r13)
-
-#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
- li r0,KVM_HWTHREAD_IN_KERNEL
- stb r0,HSTATE_HWTHREAD_STATE(r13)
- /* Order setting hwthread_state vs. testing hwthread_req */
- sync
- lbz r0,HSTATE_HWTHREAD_REQ(r13)
- cmpwi r0,0
- beq 1f
- b kvm_start_guest
-1:
-#endif
+ bgt cr1,8f
beq cr1,2f
b .power7_wakeup_noloss
2: b .power7_wakeup_loss
/* Fast Sleep wakeup on PowerNV */
-8: GET_PACA(r13)
- b .power7_wakeup_tb_loss
+8: b .power7_wakeup_tb_loss
9:
END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/6] KVM: PPC: Book3S HV: Consolidate the idle-state enter sequence in KVM
2014-05-28 4:38 [PATCH 0/6] ppc, kvm, cpuidle: Allow offline and kvm standby threads to enter fastsleep Preeti U Murthy
` (2 preceding siblings ...)
2014-05-28 4:39 ` [PATCH 3/6] KVM: PPC: Book3S HV: Enable CPUs to run guest after waking up from fast-sleep Preeti U Murthy
@ 2014-05-28 4:39 ` Preeti U Murthy
2014-05-28 4:39 ` [PATCH 5/6] KVM: PPC: Book3S HV: Put KVM standby hwthreads to fast-sleep instead of nap Preeti U Murthy
2014-05-28 4:39 ` [PATCH 6/6] ppc, book3s: Go back to same idle state after handling machine check interrupt Preeti U Murthy
5 siblings, 0 replies; 8+ messages in thread
From: Preeti U Murthy @ 2014-05-28 4:39 UTC (permalink / raw)
To: benh, linux-kernel, svaidyan, paulus, srivatsa.bhat, linuxppc-dev
From: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Now that the support for fast sleep idle state is present, the KVM
standby threads can be put to fast sleep when they are either idle
or do not have a guest to run. Today they enter nap in these scenarios.
The purpose is to gain maximum power savings in a KVM scenario as well
when an entire cpu core is idle.
As a precursor, consolidate the code common across all idle states.
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
[ Changelog added by <preeti@linux.vnet.ibm.com> ]
Signed-off-by: Preeti U Murthy <preeti@linux.vnet.ibm.com>
---
arch/powerpc/kvm/book3s_hv_rmhandlers.S | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index b031f93..43aa806 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -40,6 +40,17 @@
#define NAPPING_CEDE 1
#define NAPPING_NOVCPU 2
+#define IDLE_STATE_ENTER_SEQ_HV(IDLE_INST) \
+ /* Magic NAP/SLEEP/WINKLE mode enter sequence */ \
+ std r0, HSTATE_SCRATCH0(r13); \
+ ptesync; \
+ ld r0, HSTATE_SCRATCH0(r13); \
+1: cmpd r0, r0; \
+ bne 1b; \
+ IDLE_INST; \
+ b .
+
+
/*
* Call kvmppc_hv_entry in real mode.
* Must be called with interrupts hard-disabled.
@@ -325,13 +336,9 @@ kvm_do_nap:
rlwimi r4, r3, 0, LPCR_PECE0 | LPCR_PECE1
mtspr SPRN_LPCR, r4
isync
- std r0, HSTATE_SCRATCH0(r13)
- ptesync
- ld r0, HSTATE_SCRATCH0(r13)
-1: cmpd r0, r0
- bne 1b
- nap
- b .
+ IDLE_STATE_ENTER_SEQ_HV(PPC_NAP)
+ /* No return */
+
/******************************************************************************
* *
@@ -2027,13 +2034,8 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
mtspr SPRN_LPCR,r5
isync
li r0, 0
- std r0, HSTATE_SCRATCH0(r13)
- ptesync
- ld r0, HSTATE_SCRATCH0(r13)
-1: cmpd r0, r0
- bne 1b
- nap
- b .
+ IDLE_STATE_ENTER_SEQ_HV(PPC_NAP)
+ /* No return */
33: mr r4, r3
li r3, 0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/6] KVM: PPC: Book3S HV: Put KVM standby hwthreads to fast-sleep instead of nap
2014-05-28 4:38 [PATCH 0/6] ppc, kvm, cpuidle: Allow offline and kvm standby threads to enter fastsleep Preeti U Murthy
` (3 preceding siblings ...)
2014-05-28 4:39 ` [PATCH 4/6] KVM: PPC: Book3S HV: Consolidate the idle-state enter sequence in KVM Preeti U Murthy
@ 2014-05-28 4:39 ` Preeti U Murthy
2014-05-28 4:39 ` [PATCH 6/6] ppc, book3s: Go back to same idle state after handling machine check interrupt Preeti U Murthy
5 siblings, 0 replies; 8+ messages in thread
From: Preeti U Murthy @ 2014-05-28 4:39 UTC (permalink / raw)
To: benh, linux-kernel, svaidyan, paulus, srivatsa.bhat, linuxppc-dev
From: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Now that the support for fast sleep idle state is present, allow
the KVM standby threads to go to fast sleep if the platform supports
it.This will fetch us maximum power savings if an entire core is idle.
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
[ Changelog added by <preeti@linux.vnet.ibm.com> ]
Signed-off-by: Preeti U Murthy <preeti@linux.vnet.ibm.com>
---
arch/powerpc/kvm/book3s_hv_rmhandlers.S | 73 ++++++++++++++++++++++++++++---
1 file changed, 65 insertions(+), 8 deletions(-)
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index 43aa806..69244cc 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -207,7 +207,7 @@ kvmppc_primary_no_guest:
li r3, 1
stb r3, HSTATE_HWTHREAD_REQ(r13)
- b kvm_do_nap
+ b kvm_do_idle
kvm_novcpu_wakeup:
ld r1, HSTATE_HOST_R1(r13)
@@ -247,7 +247,7 @@ kvm_novcpu_exit:
b hdec_soon
/*
- * We come in here when wakened from nap mode.
+ * We come in here when wakened from nap or fast-sleep mode.
* Relocation is off and most register values are lost.
* r13 points to the PACA.
*/
@@ -303,7 +303,7 @@ kvm_start_guest:
bl kvmppc_hv_entry
- /* Back from the guest, go back to nap */
+ /* Back from the guest, go back to nap or fastsleep */
/* Clear our vcpu pointer so we don't come back in early */
li r0, 0
std r0, HSTATE_KVM_VCPU(r13)
@@ -314,7 +314,7 @@ kvm_start_guest:
*/
lwsync
- /* increment the nap count and then go to nap mode */
+ /* increment the nap count and then go to nap or fast-sleep mode */
ld r4, HSTATE_KVM_VCORE(r13)
addi r4, r4, VCORE_NAP_COUNT
51: lwarx r3, 0, r4
@@ -325,6 +325,24 @@ kvm_start_guest:
kvm_no_guest:
li r0, KVM_HWTHREAD_IN_NAP
stb r0, HSTATE_HWTHREAD_STATE(r13)
+
+kvm_do_idle:
+ /*
+ * if (supported_cpuidle_states & IDLE_USE_SLEEP)
+ * kvm_do_fastsleep();
+ * else
+ * kvm_do_nap();
+ */
+ LOAD_REG_ADDRBASE(r3,supported_cpuidle_states)
+ lwz r4,ADDROFF(supported_cpuidle_states)(r3)
+ /*
+ * andi. r4,r4,IDLE_USE_SLEEP. Replacing IDLE_USE_SLEEP
+ * with the immediate value since it is a 32 bit instruction
+ * and the operand needs to fit into this.
+ */
+ andi. r4,r4,2
+ bne kvm_do_fastsleep
+
kvm_do_nap:
/* Clear the runlatch bit before napping */
mfspr r2, SPRN_CTRLF
@@ -339,6 +357,18 @@ kvm_do_nap:
IDLE_STATE_ENTER_SEQ_HV(PPC_NAP)
/* No return */
+kvm_do_fastsleep:
+ li r3, LPCR_PECE0
+ mfspr r4, SPRN_LPCR
+ /* Don't set LPCR_PECE1 since we want to wakeup only on an external
+ * interrupt, and not on a decrementer interrupt.
+ */
+ rlwimi r4, r3, 0, LPCR_PECE0
+ mtspr SPRN_LPCR, r4
+ isync
+ IDLE_STATE_ENTER_SEQ_HV(PPC_SLEEP)
+ /* No return */
+
/******************************************************************************
* *
@@ -2016,8 +2046,8 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_206)
bl kvmppc_save_fp
/*
- * Take a nap until a decrementer or external or doobell interrupt
- * occurs, with PECE1, PECE0 and PECEDP set in LPCR. Also clear the
+ * Go to fastsleep until an external or doobell interrupt
+ * occurs, with PECE0 and PECEDP set in LPCR. Also clear the
* runlatch bit before napping.
*/
mfspr r2, SPRN_CTRLF
@@ -2026,6 +2056,22 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_206)
li r0,1
stb r0,HSTATE_HWTHREAD_REQ(r13)
+ /*
+ * if (supported_cpuidle_states & IDLE_USE_SLEEP)
+ * PPC_SLEEP;
+ * else
+ * PPC_NAP;
+ */
+ LOAD_REG_ADDRBASE(r3,supported_cpuidle_states)
+ lwz r4,ADDROFF(supported_cpuidle_states)(r3)
+ /*
+ * andi. r4,r4,IDLE_USE_SLEEP. Replacing IDLE_USE_SLEEP
+ * with the immediate value since it is a 32 bit instruction
+ * and the operand needs to fit into this.
+ */
+ andi. r4,r4,2
+ bne 35f
+
mfspr r5,SPRN_LPCR
ori r5,r5,LPCR_PECE0 | LPCR_PECE1
BEGIN_FTR_SECTION
@@ -2037,6 +2083,17 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
IDLE_STATE_ENTER_SEQ_HV(PPC_NAP)
/* No return */
+35: mfspr r5,SPRN_LPCR
+ ori r5,r5,LPCR_PECE0
+BEGIN_FTR_SECTION
+ oris r5,r5,LPCR_PECEDP@h
+END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
+ mtspr SPRN_LPCR,r5
+ isync
+ li r0, 0
+ IDLE_STATE_ENTER_SEQ_HV(PPC_SLEEP)
+ /* No return */
+
33: mr r4, r3
li r3, 0
li r12, 0
@@ -2046,7 +2103,7 @@ kvm_end_cede:
/* get vcpu pointer */
ld r4, HSTATE_KVM_VCPU(r13)
- /* Woken by external or decrementer interrupt */
+ /* Woken by external */
ld r1, HSTATE_HOST_R1(r13)
/* load up FP state */
@@ -2129,7 +2186,7 @@ machine_check_realmode:
b fast_interrupt_c_return
/*
- * Check the reason we woke from nap, and take appropriate action.
+ * Check the reason we woke from nap or fastsleep, and take appropriate action.
* Returns:
* 0 if nothing needs to be done
* 1 if something happened that needs to be handled by the host
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 6/6] ppc, book3s: Go back to same idle state after handling machine check interrupt
2014-05-28 4:38 [PATCH 0/6] ppc, kvm, cpuidle: Allow offline and kvm standby threads to enter fastsleep Preeti U Murthy
` (4 preceding siblings ...)
2014-05-28 4:39 ` [PATCH 5/6] KVM: PPC: Book3S HV: Put KVM standby hwthreads to fast-sleep instead of nap Preeti U Murthy
@ 2014-05-28 4:39 ` Preeti U Murthy
5 siblings, 0 replies; 8+ messages in thread
From: Preeti U Murthy @ 2014-05-28 4:39 UTC (permalink / raw)
To: benh, linux-kernel, svaidyan, paulus, srivatsa.bhat, linuxppc-dev
From: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Now that the support for fast sleep is present, threads could have woken up
from fast sleep on getting a machine check interrupt. Hence add code to allow
threads to go back to the idle state they woke up from after handling the
interrupt. Today they go back to nap by default.
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
[ Changelog added by <preeti@linux.vnet.ibm.com> ]
Signed-off-by: Preeti U Murthy <preeti@linux.vnet.ibm.com>
---
arch/powerpc/kernel/exceptions-64s.S | 21 +++++++++++++++------
arch/powerpc/kernel/idle_power7.S | 2 +-
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index b4bf464..94cee3c 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1396,15 +1396,16 @@ machine_check_handle_early:
* of the following is true:
* a. thread wasn't in power saving mode
* b. thread was in power saving mode with no state loss or
- * supervisor state loss
+ * supervisor state loss or hypervisor state loss (fastsleep)
*
- * Go back to nap again if (b) is true.
+ * Go back to nap or fastsleep again if (b) is true.
*/
rlwinm. r11,r12,47-31,30,31 /* Was it in power saving mode? */
beq 4f /* No, it wasn;t */
- /* Thread was in power saving mode. Go back to nap again. */
- cmpwi r11,2
- bne 3f
+ /* Thread was in power saving mode. Go back to the same state again. */
+ cmpwi cr1,r11,2
+ blt cr1,3f
+7:
/* Supervisor state loss */
li r0,1
stb r0,PACA_NAPSTATELOST(r13)
@@ -1412,7 +1413,15 @@ machine_check_handle_early:
MACHINE_CHECK_HANDLER_WINDUP
GET_PACA(r13)
ld r1,PACAR1(r13)
- b .power7_enter_nap_mode
+ /* We need to pass the idle state in r3: 0 -> nap, 1 -> sleep */
+ bgt cr1,8f
+ li r3,0
+ b .power7_enter_idle
+ /* No return */
+
+8: li r3,1 /* Pass 1 in r3 to request sleep in power7_enter_idle */
+ b .power7_enter_idle
+ /* No return */
4:
#endif
/*
diff --git a/arch/powerpc/kernel/idle_power7.S b/arch/powerpc/kernel/idle_power7.S
index c3ab869..e13e21b 100644
--- a/arch/powerpc/kernel/idle_power7.S
+++ b/arch/powerpc/kernel/idle_power7.S
@@ -95,7 +95,7 @@ _GLOBAL(power7_powersave_common)
std r9,_MSR(r1)
std r1,PACAR1(r13)
-_GLOBAL(power7_enter_nap_mode)
+_GLOBAL(power7_enter_idle)
#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
/* Tell KVM we're napping */
li r4,KVM_HWTHREAD_IN_NAP
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/6] powerpc, powernv, CPU hotplug: Put offline CPUs in Fast-Sleep instead of Nap
2014-05-28 4:38 ` [PATCH 2/6] powerpc, powernv, CPU hotplug: Put offline CPUs in Fast-Sleep instead of Nap Preeti U Murthy
@ 2014-06-05 4:23 ` Paul Mackerras
0 siblings, 0 replies; 8+ messages in thread
From: Paul Mackerras @ 2014-06-05 4:23 UTC (permalink / raw)
To: Preeti U Murthy; +Cc: benh, linux-kernel, svaidyan, srivatsa.bhat, linuxppc-dev
On Wed, May 28, 2014 at 10:08:56AM +0530, Preeti U Murthy wrote:
> From: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
>
> The offline cpus are put to fast sleep if the idle state is discovered in the
> device tree. This is to gain maximum powersavings in the offline state.
...
> while (!generic_check_cpu_restart(cpu)) {
> ppc64_runlatch_off();
> - power7_nap();
> +
> + /* If sleep is supported, go to sleep, instead of nap */
> + if (idle_states & IDLE_USE_SLEEP)
> + power7_sleep();
> + else
> + power7_nap();
> +
> ppc64_runlatch_on();
> if (!generic_check_cpu_restart(cpu)) {
> DBG("CPU%d Unexpected exit while offline !\n", cpu);
What is the latency for waking up from fast sleep state? I'm concerned
this will increase the latency for entering KVM guests.
Paul.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-06-05 4:23 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-28 4:38 [PATCH 0/6] ppc, kvm, cpuidle: Allow offline and kvm standby threads to enter fastsleep Preeti U Murthy
2014-05-28 4:38 ` [PATCH 1/6] powernv, cpuidle: Move the flags used for idle state discovery to powernv core Preeti U Murthy
2014-05-28 4:38 ` [PATCH 2/6] powerpc, powernv, CPU hotplug: Put offline CPUs in Fast-Sleep instead of Nap Preeti U Murthy
2014-06-05 4:23 ` Paul Mackerras
2014-05-28 4:39 ` [PATCH 3/6] KVM: PPC: Book3S HV: Enable CPUs to run guest after waking up from fast-sleep Preeti U Murthy
2014-05-28 4:39 ` [PATCH 4/6] KVM: PPC: Book3S HV: Consolidate the idle-state enter sequence in KVM Preeti U Murthy
2014-05-28 4:39 ` [PATCH 5/6] KVM: PPC: Book3S HV: Put KVM standby hwthreads to fast-sleep instead of nap Preeti U Murthy
2014-05-28 4:39 ` [PATCH 6/6] ppc, book3s: Go back to same idle state after handling machine check interrupt Preeti U Murthy
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).