Commit 23f62d7a authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

PM: sleep: Pause cpuidle later and resume it earlier during system transitions

Commit 8651f97b ("PM / cpuidle: System resume hang fix with
cpuidle") that introduced cpuidle pausing during system suspend
did that to work around a platform firmware issue causing systems
to hang during resume if CPUs were allowed to enter idle states
in the system suspend and resume code paths.

However, pausing cpuidle before the last phase of suspending
devices is the source of an otherwise arbitrary difference between
the suspend-to-idle path and other system suspend variants, so it is
cleaner to do that later, before taking secondary CPUs offline (it
is still safer to take secondary CPUs offline with cpuidle paused,
though).

Modify the code accordingly, but in order to avoid code duplication,
introduce new wrapper functions, pm_sleep_disable_secondary_cpus()
and pm_sleep_enable_secondary_cpus(), to combine cpuidle_pause()
and cpuidle_resume(), respectively, with the handling of secondary
CPUs during system-wide transitions to sleep states.
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Tested-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent 8d89835b
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include <linux/suspend.h> #include <linux/suspend.h>
#include <trace/events/power.h> #include <trace/events/power.h>
#include <linux/cpufreq.h> #include <linux/cpufreq.h>
#include <linux/cpuidle.h>
#include <linux/devfreq.h> #include <linux/devfreq.h>
#include <linux/timer.h> #include <linux/timer.h>
...@@ -879,7 +878,6 @@ void dpm_resume_early(pm_message_t state) ...@@ -879,7 +878,6 @@ void dpm_resume_early(pm_message_t state)
void dpm_resume_start(pm_message_t state) void dpm_resume_start(pm_message_t state)
{ {
dpm_resume_noirq(state); dpm_resume_noirq(state);
cpuidle_resume();
dpm_resume_early(state); dpm_resume_early(state);
} }
EXPORT_SYMBOL_GPL(dpm_resume_start); EXPORT_SYMBOL_GPL(dpm_resume_start);
...@@ -1519,13 +1517,9 @@ int dpm_suspend_end(pm_message_t state) ...@@ -1519,13 +1517,9 @@ int dpm_suspend_end(pm_message_t state)
if (error) if (error)
goto out; goto out;
cpuidle_pause();
error = dpm_suspend_noirq(state); error = dpm_suspend_noirq(state);
if (error) { if (error)
cpuidle_resume();
dpm_resume_early(resume_event(state)); dpm_resume_early(resume_event(state));
}
out: out:
dpm_show_time(starttime, state, error, "end"); dpm_show_time(starttime, state, error, "end");
......
...@@ -300,7 +300,7 @@ static int create_image(int platform_mode) ...@@ -300,7 +300,7 @@ static int create_image(int platform_mode)
if (error || hibernation_test(TEST_PLATFORM)) if (error || hibernation_test(TEST_PLATFORM))
goto Platform_finish; goto Platform_finish;
error = suspend_disable_secondary_cpus(); error = pm_sleep_disable_secondary_cpus();
if (error || hibernation_test(TEST_CPUS)) if (error || hibernation_test(TEST_CPUS))
goto Enable_cpus; goto Enable_cpus;
...@@ -342,7 +342,7 @@ static int create_image(int platform_mode) ...@@ -342,7 +342,7 @@ static int create_image(int platform_mode)
local_irq_enable(); local_irq_enable();
Enable_cpus: Enable_cpus:
suspend_enable_secondary_cpus(); pm_sleep_enable_secondary_cpus();
/* Allow architectures to do nosmt-specific post-resume dances */ /* Allow architectures to do nosmt-specific post-resume dances */
if (!in_suspend) if (!in_suspend)
...@@ -466,6 +466,8 @@ static int resume_target_kernel(bool platform_mode) ...@@ -466,6 +466,8 @@ static int resume_target_kernel(bool platform_mode)
if (error) if (error)
goto Cleanup; goto Cleanup;
cpuidle_pause();
error = hibernate_resume_nonboot_cpu_disable(); error = hibernate_resume_nonboot_cpu_disable();
if (error) if (error)
goto Enable_cpus; goto Enable_cpus;
...@@ -509,7 +511,7 @@ static int resume_target_kernel(bool platform_mode) ...@@ -509,7 +511,7 @@ static int resume_target_kernel(bool platform_mode)
local_irq_enable(); local_irq_enable();
Enable_cpus: Enable_cpus:
suspend_enable_secondary_cpus(); pm_sleep_enable_secondary_cpus();
Cleanup: Cleanup:
platform_restore_cleanup(platform_mode); platform_restore_cleanup(platform_mode);
...@@ -587,7 +589,7 @@ int hibernation_platform_enter(void) ...@@ -587,7 +589,7 @@ int hibernation_platform_enter(void)
if (error) if (error)
goto Platform_finish; goto Platform_finish;
error = suspend_disable_secondary_cpus(); error = pm_sleep_disable_secondary_cpus();
if (error) if (error)
goto Enable_cpus; goto Enable_cpus;
...@@ -609,7 +611,7 @@ int hibernation_platform_enter(void) ...@@ -609,7 +611,7 @@ int hibernation_platform_enter(void)
local_irq_enable(); local_irq_enable();
Enable_cpus: Enable_cpus:
suspend_enable_secondary_cpus(); pm_sleep_enable_secondary_cpus();
Platform_finish: Platform_finish:
hibernation_ops->finish(); hibernation_ops->finish();
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <linux/utsname.h> #include <linux/utsname.h>
#include <linux/freezer.h> #include <linux/freezer.h>
#include <linux/compiler.h> #include <linux/compiler.h>
#include <linux/cpu.h>
#include <linux/cpuidle.h>
struct swsusp_info { struct swsusp_info {
struct new_utsname uts; struct new_utsname uts;
...@@ -310,3 +312,15 @@ extern int pm_wake_lock(const char *buf); ...@@ -310,3 +312,15 @@ extern int pm_wake_lock(const char *buf);
extern int pm_wake_unlock(const char *buf); extern int pm_wake_unlock(const char *buf);
#endif /* !CONFIG_PM_WAKELOCKS */ #endif /* !CONFIG_PM_WAKELOCKS */
static inline int pm_sleep_disable_secondary_cpus(void)
{
cpuidle_pause();
return suspend_disable_secondary_cpus();
}
static inline void pm_sleep_enable_secondary_cpus(void)
{
suspend_enable_secondary_cpus();
cpuidle_resume();
}
...@@ -403,9 +403,6 @@ static int suspend_enter(suspend_state_t state, bool *wakeup) ...@@ -403,9 +403,6 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
if (error) if (error)
goto Devices_early_resume; goto Devices_early_resume;
if (state != PM_SUSPEND_TO_IDLE)
cpuidle_pause();
error = dpm_suspend_noirq(PMSG_SUSPEND); error = dpm_suspend_noirq(PMSG_SUSPEND);
if (error) { if (error) {
pr_err("noirq suspend of devices failed\n"); pr_err("noirq suspend of devices failed\n");
...@@ -423,7 +420,7 @@ static int suspend_enter(suspend_state_t state, bool *wakeup) ...@@ -423,7 +420,7 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
goto Platform_wake; goto Platform_wake;
} }
error = suspend_disable_secondary_cpus(); error = pm_sleep_disable_secondary_cpus();
if (error || suspend_test(TEST_CPUS)) if (error || suspend_test(TEST_CPUS))
goto Enable_cpus; goto Enable_cpus;
...@@ -453,16 +450,13 @@ static int suspend_enter(suspend_state_t state, bool *wakeup) ...@@ -453,16 +450,13 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
BUG_ON(irqs_disabled()); BUG_ON(irqs_disabled());
Enable_cpus: Enable_cpus:
suspend_enable_secondary_cpus(); pm_sleep_enable_secondary_cpus();
Platform_wake: Platform_wake:
platform_resume_noirq(state); platform_resume_noirq(state);
dpm_resume_noirq(PMSG_RESUME); dpm_resume_noirq(PMSG_RESUME);
Platform_early_resume: Platform_early_resume:
if (state != PM_SUSPEND_TO_IDLE)
cpuidle_resume();
platform_resume_early(state); platform_resume_early(state);
Devices_early_resume: Devices_early_resume:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment