Skip to content

Commit 8eb8ac8

Browse files
shreyasbpmpe
authored andcommitted
powerpc/powernv: Enable Offline CPUs to enter deep idle states
The secondary threads should enter deep idle states so as to gain maximum powersavings when the entire core is offline. To do so the offline path must be made aware of the available deepest idle state. Hence probe the device tree for the possible idle states in powernv core code and expose the deepest idle state through flags. Since the device tree is probed by the cpuidle driver as well, move the parameters required to discover the idle states into an appropriate common place to both the driver and the powernv core code. Another point is that fastsleep idle state may require workarounds in the kernel to function properly. This workaround is introduced in the subsequent patches. However neither the cpuidle driver or the hotplug path need be bothered about this workaround. They will be taken care of by the core powernv code. Originally-by: Srivatsa S. Bhat <srivatsa@mit.edu> Signed-off-by: Preeti U. Murthy <preeti@linux.vnet.ibm.com> Signed-off-by: Shreyas B. Prabhu <shreyas@linux.vnet.ibm.com> Reviewed-by: Paul Mackerras <paulus@samba.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Rafael J. Wysocki <rjw@rjwysocki.net> Cc: linux-pm@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 8117ac6 commit 8eb8ac8

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed

arch/powerpc/include/asm/opal.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ struct opal_sg_list {
168168
#define OPAL_IPMI_RECV 108
169169
#define OPAL_I2C_REQUEST 109
170170

171+
/* Device tree flags */
172+
173+
/* Flags set in power-mgmt nodes in device tree if
174+
* respective idle states are supported in the platform.
175+
*/
176+
#define OPAL_PM_NAP_ENABLED 0x00010000
177+
#define OPAL_PM_SLEEP_ENABLED 0x00020000
178+
171179
#ifndef __ASSEMBLY__
172180

173181
#include <linux/notifier.h>

arch/powerpc/platforms/powernv/powernv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ static inline u64 pnv_pci_dma_get_required_mask(struct pci_dev *pdev)
2929
}
3030
#endif
3131

32+
extern u32 pnv_get_supported_cpuidle_states(void);
33+
3234
extern void pnv_lpc_init(void);
3335

3436
bool cpu_core_split_required(void);

arch/powerpc/platforms/powernv/setup.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,55 @@ static void __init pnv_setup_machdep_rtas(void)
288288
}
289289
#endif /* CONFIG_PPC_POWERNV_RTAS */
290290

291+
static u32 supported_cpuidle_states;
292+
293+
u32 pnv_get_supported_cpuidle_states(void)
294+
{
295+
return supported_cpuidle_states;
296+
}
297+
298+
static int __init pnv_init_idle_states(void)
299+
{
300+
struct device_node *power_mgt;
301+
int dt_idle_states;
302+
const __be32 *idle_state_flags;
303+
u32 len_flags, flags;
304+
int i;
305+
306+
supported_cpuidle_states = 0;
307+
308+
if (cpuidle_disable != IDLE_NO_OVERRIDE)
309+
return 0;
310+
311+
if (!firmware_has_feature(FW_FEATURE_OPALv3))
312+
return 0;
313+
314+
power_mgt = of_find_node_by_path("/ibm,opal/power-mgt");
315+
if (!power_mgt) {
316+
pr_warn("opal: PowerMgmt Node not found\n");
317+
return 0;
318+
}
319+
320+
idle_state_flags = of_get_property(power_mgt,
321+
"ibm,cpu-idle-state-flags", &len_flags);
322+
if (!idle_state_flags) {
323+
pr_warn("DT-PowerMgmt: missing ibm,cpu-idle-state-flags\n");
324+
return 0;
325+
}
326+
327+
dt_idle_states = len_flags / sizeof(u32);
328+
329+
for (i = 0; i < dt_idle_states; i++) {
330+
flags = be32_to_cpu(idle_state_flags[i]);
331+
supported_cpuidle_states |= flags;
332+
}
333+
334+
return 0;
335+
}
336+
337+
subsys_initcall(pnv_init_idle_states);
338+
339+
291340
static int __init pnv_probe(void)
292341
{
293342
unsigned long root = of_get_flat_dt_root();

arch/powerpc/platforms/powernv/smp.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ static void pnv_smp_cpu_kill_self(void)
150150
{
151151
unsigned int cpu;
152152
unsigned long srr1;
153+
u32 idle_states;
153154

154155
/* Standard hot unplug procedure */
155156
local_irq_disable();
@@ -160,13 +161,17 @@ static void pnv_smp_cpu_kill_self(void)
160161
generic_set_cpu_dead(cpu);
161162
smp_wmb();
162163

164+
idle_states = pnv_get_supported_cpuidle_states();
163165
/* We don't want to take decrementer interrupts while we are offline,
164166
* so clear LPCR:PECE1. We keep PECE2 enabled.
165167
*/
166168
mtspr(SPRN_LPCR, mfspr(SPRN_LPCR) & ~(u64)LPCR_PECE1);
167169
while (!generic_check_cpu_restart(cpu)) {
168170
ppc64_runlatch_off();
169-
srr1 = power7_nap(1);
171+
if (idle_states & OPAL_PM_SLEEP_ENABLED)
172+
srr1 = power7_sleep();
173+
else
174+
srr1 = power7_nap(1);
170175
ppc64_runlatch_on();
171176

172177
/*

drivers/cpuidle/cpuidle-powernv.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616

1717
#include <asm/machdep.h>
1818
#include <asm/firmware.h>
19+
#include <asm/opal.h>
1920
#include <asm/runlatch.h>
2021

21-
/* Flags and constants used in PowerNV platform */
22-
2322
#define MAX_POWERNV_IDLE_STATES 8
24-
#define IDLE_USE_INST_NAP 0x00010000 /* Use nap instruction */
25-
#define IDLE_USE_INST_SLEEP 0x00020000 /* Use sleep instruction */
2623

2724
struct cpuidle_driver powernv_idle_driver = {
2825
.name = "powernv_idle",
@@ -198,7 +195,7 @@ static int powernv_add_idle_states(void)
198195
* target residency to be 10x exit_latency
199196
*/
200197
latency_ns = be32_to_cpu(idle_state_latency[i]);
201-
if (flags & IDLE_USE_INST_NAP) {
198+
if (flags & OPAL_PM_NAP_ENABLED) {
202199
/* Add NAP state */
203200
strcpy(powernv_states[nr_idle_states].name, "Nap");
204201
strcpy(powernv_states[nr_idle_states].desc, "Nap");
@@ -211,7 +208,7 @@ static int powernv_add_idle_states(void)
211208
nr_idle_states++;
212209
}
213210

214-
if (flags & IDLE_USE_INST_SLEEP) {
211+
if (flags & OPAL_PM_SLEEP_ENABLED) {
215212
/* Add FASTSLEEP state */
216213
strcpy(powernv_states[nr_idle_states].name, "FastSleep");
217214
strcpy(powernv_states[nr_idle_states].desc, "FastSleep");

0 commit comments

Comments
 (0)