Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpuidle: psci: Enable suspend-to-idle for PSCI OSI mode

To select domain idlestates for cpuidle-psci when OSI mode has been
enabled, the PM domains via genpd are being managed through runtime PM.
This works fine for the regular idlepath, but it doesn't during system wide
suspend. More precisely, the domain idlestates becomes temporarily
disabled, which is because the PM core disables runtime PM for devices
during system wide suspend.

Later in the system suspend phase, genpd intends to deal with this from its
->suspend_noirq() callback, but this doesn't work as expected for a device
corresponding to a CPU, because the domain idlestates needs to be selected
on a per CPU basis (the PM core doesn't invoke the callbacks like that).

To address this problem, let's enable the syscore flag for the
corresponding CPU device that becomes successfully attached to its PM
domain (applicable only in OSI mode). This informs the PM core to skip
invoke the system wide suspend/resume callbacks for the device, thus also
prevents genpd from screwing up its internal state of it.

Moreover, to properly select a domain idlestate for the CPUs during
suspend-to-idle, let's assign a specific ->enter_s2idle() callback for the
corresponding domain idlestate (applicable only in OSI mode). From that
callback, let's invoke dev_pm_genpd_suspend|resume(), as this allows a
domain idlestate to be selected for the current CPU by genpd.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Ulf Hansson and committed by
Rafael J. Wysocki
670c90de b9795a3e

+32 -4
+2
drivers/cpuidle/cpuidle-psci-domain.c
··· 327 327 if (cpu_online(cpu)) 328 328 pm_runtime_get_sync(dev); 329 329 330 + dev_pm_syscore_device(dev, true); 331 + 330 332 return dev; 331 333 } 332 334
+30 -4
drivers/cpuidle/cpuidle-psci.c
··· 19 19 #include <linux/of_device.h> 20 20 #include <linux/platform_device.h> 21 21 #include <linux/psci.h> 22 + #include <linux/pm_domain.h> 22 23 #include <linux/pm_runtime.h> 23 24 #include <linux/slab.h> 24 25 #include <linux/string.h> ··· 53 52 return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, idx, state); 54 53 } 55 54 56 - static int psci_enter_domain_idle_state(struct cpuidle_device *dev, 57 - struct cpuidle_driver *drv, int idx) 55 + static int __psci_enter_domain_idle_state(struct cpuidle_device *dev, 56 + struct cpuidle_driver *drv, int idx, 57 + bool s2idle) 58 58 { 59 59 struct psci_cpuidle_data *data = this_cpu_ptr(&psci_cpuidle_data); 60 60 u32 *states = data->psci_states; ··· 68 66 return -1; 69 67 70 68 /* Do runtime PM to manage a hierarchical CPU toplogy. */ 71 - RCU_NONIDLE(pm_runtime_put_sync_suspend(pd_dev)); 69 + rcu_irq_enter_irqson(); 70 + if (s2idle) 71 + dev_pm_genpd_suspend(pd_dev); 72 + else 73 + pm_runtime_put_sync_suspend(pd_dev); 74 + rcu_irq_exit_irqson(); 72 75 73 76 state = psci_get_domain_state(); 74 77 if (!state) ··· 81 74 82 75 ret = psci_cpu_suspend_enter(state) ? -1 : idx; 83 76 84 - RCU_NONIDLE(pm_runtime_get_sync(pd_dev)); 77 + rcu_irq_enter_irqson(); 78 + if (s2idle) 79 + dev_pm_genpd_resume(pd_dev); 80 + else 81 + pm_runtime_get_sync(pd_dev); 82 + rcu_irq_exit_irqson(); 85 83 86 84 cpu_pm_exit(); 87 85 88 86 /* Clear the domain state to start fresh when back from idle. */ 89 87 psci_set_domain_state(0); 90 88 return ret; 89 + } 90 + 91 + static int psci_enter_domain_idle_state(struct cpuidle_device *dev, 92 + struct cpuidle_driver *drv, int idx) 93 + { 94 + return __psci_enter_domain_idle_state(dev, drv, idx, false); 95 + } 96 + 97 + static int psci_enter_s2idle_domain_idle_state(struct cpuidle_device *dev, 98 + struct cpuidle_driver *drv, 99 + int idx) 100 + { 101 + return __psci_enter_domain_idle_state(dev, drv, idx, true); 91 102 } 92 103 93 104 static int psci_idle_cpuhp_up(unsigned int cpu) ··· 195 170 * deeper states. 196 171 */ 197 172 drv->states[state_count - 1].enter = psci_enter_domain_idle_state; 173 + drv->states[state_count - 1].enter_s2idle = psci_enter_s2idle_domain_idle_state; 198 174 psci_cpuidle_use_cpuhp = true; 199 175 200 176 return 0;