From cdcd2dff85451b60ea6e074ca933fb5bfb516282 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Fri, 2 Apr 2021 10:49:01 -0700 Subject: [PATCH] power: Consider the exit latency required by an idle state Set the timeout to expire "exit_latency_us" earlier to the CPU be capable of honor the next scheduled event. Signed-off-by: Flavio Ceolin --- subsys/power/power.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/subsys/power/power.c b/subsys/power/power.c index 106dace0557..9f4b26f8ed7 100644 --- a/subsys/power/power.c +++ b/subsys/power/power.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -180,6 +181,15 @@ enum pm_state pm_system_suspend(int32_t ticks) } post_ops_done = 0; + if (ticks != K_TICKS_FOREVER) { + /* + * We need to set the timer to interrupt a little bit early to + * accommodate the time required by the CPU to fully wake up. + */ + z_set_timeout_expiry(ticks - + k_us_to_ticks_ceil32(z_power_state.exit_latency_us), true); + } + #if CONFIG_PM_DEVICE bool should_resume_devices = true;