powerpc/powernv: Enable Offline CPUs to enter deep idle states
authorShreyas B. Prabhu <shreyas@linux.vnet.ibm.com>
Tue, 9 Dec 2014 18:56:51 +0000 (00:26 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Sun, 14 Dec 2014 23:46:40 +0000 (10:46 +1100)
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>
arch/powerpc/include/asm/opal.h
arch/powerpc/platforms/powernv/powernv.h
arch/powerpc/platforms/powernv/setup.c
arch/powerpc/platforms/powernv/smp.c
drivers/cpuidle/cpuidle-powernv.c

index 4095749c973fef195bbc6575679a819344a50b9b..6dedf9b05a862b523938aa3ecc3308aa6609ea2f 100644 (file)
@@ -168,6 +168,14 @@ struct opal_sg_list {
 #define OPAL_IPMI_RECV                         108
 #define OPAL_I2C_REQUEST                       109
 
+/* Device tree flags */
+
+/* Flags set in power-mgmt nodes in device tree if
+ * respective idle states are supported in the platform.
+ */
+#define OPAL_PM_NAP_ENABLED    0x00010000
+#define OPAL_PM_SLEEP_ENABLED  0x00020000
+
 #ifndef __ASSEMBLY__
 
 #include <linux/notifier.h>
index 6c8e2d188cd096330b7b1926da13c50de1e73f2e..604c48e7879a081cfea23a57f863328dc04d7688 100644 (file)
@@ -29,6 +29,8 @@ static inline u64 pnv_pci_dma_get_required_mask(struct pci_dev *pdev)
 }
 #endif
 
+extern u32 pnv_get_supported_cpuidle_states(void);
+
 extern void pnv_lpc_init(void);
 
 bool cpu_core_split_required(void);
index 30b1c3e298a64aae1fc0b8fc609ea449b2955027..88e579e62a73e14dab56228599a0c237ab9da31c 100644 (file)
@@ -288,6 +288,55 @@ static void __init pnv_setup_machdep_rtas(void)
 }
 #endif /* CONFIG_PPC_POWERNV_RTAS */
 
+static u32 supported_cpuidle_states;
+
+u32 pnv_get_supported_cpuidle_states(void)
+{
+       return supported_cpuidle_states;
+}
+
+static int __init pnv_init_idle_states(void)
+{
+       struct device_node *power_mgt;
+       int dt_idle_states;
+       const __be32 *idle_state_flags;
+       u32 len_flags, flags;
+       int i;
+
+       supported_cpuidle_states = 0;
+
+       if (cpuidle_disable != IDLE_NO_OVERRIDE)
+               return 0;
+
+       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;
+       }
+
+       idle_state_flags = of_get_property(power_mgt,
+                       "ibm,cpu-idle-state-flags", &len_flags);
+       if (!idle_state_flags) {
+               pr_warn("DT-PowerMgmt: missing ibm,cpu-idle-state-flags\n");
+               return 0;
+       }
+
+       dt_idle_states = len_flags / sizeof(u32);
+
+       for (i = 0; i < dt_idle_states; i++) {
+               flags = be32_to_cpu(idle_state_flags[i]);
+               supported_cpuidle_states |= flags;
+       }
+
+       return 0;
+}
+
+subsys_initcall(pnv_init_idle_states);
+
+
 static int __init pnv_probe(void)
 {
        unsigned long root = of_get_flat_dt_root();
index b716f666e48ae96c974dd01d0bb5eb40c0197b7b..83299ef2dc3d3d1c6d98447b80aa199366fad394 100644 (file)
@@ -150,6 +150,7 @@ static void pnv_smp_cpu_kill_self(void)
 {
        unsigned int cpu;
        unsigned long srr1;
+       u32 idle_states;
 
        /* Standard hot unplug procedure */
        local_irq_disable();
@@ -160,13 +161,17 @@ 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();
-               srr1 = power7_nap(1);
+               if (idle_states & OPAL_PM_SLEEP_ENABLED)
+                       srr1 = power7_sleep();
+               else
+                       srr1 = power7_nap(1);
                ppc64_runlatch_on();
 
                /*
index 7d3a3497dd4cfeef09f7d4fbaf88ecace4c4c5bf..0a7d827897e43b1e807b8e673ded0cb1151e381f 100644 (file)
 
 #include <asm/machdep.h>
 #include <asm/firmware.h>
+#include <asm/opal.h>
 #include <asm/runlatch.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",
@@ -198,7 +195,7 @@ static int powernv_add_idle_states(void)
                 * target residency to be 10x exit_latency
                 */
                latency_ns = be32_to_cpu(idle_state_latency[i]);
-               if (flags & IDLE_USE_INST_NAP) {
+               if (flags & OPAL_PM_NAP_ENABLED) {
                        /* Add NAP state */
                        strcpy(powernv_states[nr_idle_states].name, "Nap");
                        strcpy(powernv_states[nr_idle_states].desc, "Nap");
@@ -211,7 +208,7 @@ static int powernv_add_idle_states(void)
                        nr_idle_states++;
                }
 
-               if (flags & IDLE_USE_INST_SLEEP) {
+               if (flags & OPAL_PM_SLEEP_ENABLED) {
                        /* Add FASTSLEEP state */
                        strcpy(powernv_states[nr_idle_states].name, "FastSleep");
                        strcpy(powernv_states[nr_idle_states].desc, "FastSleep");
This page took 0.033498 seconds and 5 git commands to generate.