From 9444480c7b42c0324a9d8a1a531e443a862e12f1 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Sat, 30 Oct 2021 23:13:08 -0700 Subject: [PATCH] pm: Better return type for pm_system_suspend Instead of returning PM_STATE_ACTIVE for when the cpu didn't enter a low power state and a different state when it entered, but has already left the state and is active again, it changes pm_system_suspend to return true when the cpu has entered a low power state and false otherwise. Signed-off-by: Flavio Ceolin --- kernel/idle.c | 4 ++-- kernel/include/kernel_internal.h | 4 +++- subsys/pm/power.c | 4 ++-- subsys/tracing/sysview/SYSVIEW_Zephyr.txt | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/kernel/idle.c b/kernel/idle.c index dd50de9141e..137c4d6351e 100644 --- a/kernel/idle.c +++ b/kernel/idle.c @@ -32,7 +32,7 @@ static void pm_save_idle(void) /* * Call the suspend hook function of the soc interface to allow * entry into a low power state. The function returns - * PM_STATE_ACTIVE if low power state was not entered, in which + * false if low power state was not entered, in which * case, kernel does normal idle processing. * * This function is entered with interrupts disabled. If a low power @@ -42,7 +42,7 @@ static void pm_save_idle(void) * idle processing re-enables interrupts which is essential for * the kernel's scheduling logic. */ - if (pm_system_suspend(ticks) == PM_STATE_ACTIVE) { + if (pm_system_suspend(ticks) == false) { k_cpu_idle(); } #endif diff --git a/kernel/include/kernel_internal.h b/kernel/include/kernel_internal.h index 39186195fe7..3ad4879a48f 100644 --- a/kernel/include/kernel_internal.h +++ b/kernel/include/kernel_internal.h @@ -240,8 +240,10 @@ void z_mem_manage_boot_finish(void); * * This function is entered with interrupts disabled. It should re-enable * interrupts if it had entered a power state. + * + * @return True if the system suspended, otherwise return false */ -enum pm_state pm_system_suspend(int32_t ticks); +bool pm_system_suspend(int32_t ticks); /** * Notify exit from kernel idling after PM operations diff --git a/subsys/pm/power.c b/subsys/pm/power.c index 53f780714b5..2fdea742558 100644 --- a/subsys/pm/power.c +++ b/subsys/pm/power.c @@ -267,7 +267,7 @@ static enum pm_state _handle_device_abort(struct pm_state_info info) } #endif -enum pm_state pm_system_suspend(int32_t ticks) +bool pm_system_suspend(int32_t ticks) { uint8_t id = _current_cpu->id; @@ -340,7 +340,7 @@ enum pm_state pm_system_suspend(int32_t ticks) k_sched_unlock(); SYS_PORT_TRACING_FUNC_EXIT(pm, system_suspend, ticks, z_power_states[id].state); - return z_power_states[id].state; + return true; } void pm_notifier_register(struct pm_notifier *notifier) diff --git a/subsys/tracing/sysview/SYSVIEW_Zephyr.txt b/subsys/tracing/sysview/SYSVIEW_Zephyr.txt index 69e60c5bcfa..a39fe4a98e3 100644 --- a/subsys/tracing/sysview/SYSVIEW_Zephyr.txt +++ b/subsys/tracing/sysview/SYSVIEW_Zephyr.txt @@ -162,7 +162,7 @@ TaskState 0xBF 1=dummy, 2=Waiting, 4=New, 8=Terminated, 16=Suspended, 32=Termina 154 k_lifo_alloc_put lifo=%I, data=%I -155 pm_system_suspend ticks=%u | Returns %PowerState +155 pm_system_suspend ticks=%u | Returns %Bool 156 pm_device_runtime_get dev=%I | Returns %u 157 pm_device_runtime_put dev=%I | Returns %u 158 pm_device_runtime_put_async dev=%I | Returns %u