From 3296cd9650962e95f6399f14a676f18de53b2a07 Mon Sep 17 00:00:00 2001 From: Gaurav Sahitya Date: Thu, 7 Nov 2024 17:59:25 +0000 Subject: [PATCH] os/pm: Change pm_suspend and pm_resume API logic This commit change the logic of pm_suspend and pm_resume API. Now, instead of incrementing or decrementing suspend counts, we maintain only suspended domain flag to prevent board sleep. --- os/pm/pm_resume.c | 9 ++++----- os/pm/pm_suspend.c | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/os/pm/pm_resume.c b/os/pm/pm_resume.c index 628c6d880d..d0adf35c99 100644 --- a/os/pm/pm_resume.c +++ b/os/pm/pm_resume.c @@ -102,15 +102,14 @@ int pm_resume(int domain_id) if (ret != OK) { goto errout; } - if (g_pmglobals.suspend_count[domain_id] <= 0) { - ret = ERROR; - set_errno(ERANGE); - goto errout; + if (g_pmglobals.suspend_count[domain_id]) { + g_pmglobals.suspend_count[domain_id] = false; + } else { + pmdbg("Thread with pid (%d) tried to resume domain (%s) again\n", getpid(), pm_domain_map[domain_id]); } #ifdef CONFIG_PM_METRICS pm_metrics_update_resume(domain_id); #endif - g_pmglobals.suspend_count[domain_id]--; errout: leave_critical_section(flags); return ret; diff --git a/os/pm/pm_suspend.c b/os/pm/pm_suspend.c index aa70a79f67..eb450d6d8b 100644 --- a/os/pm/pm_suspend.c +++ b/os/pm/pm_suspend.c @@ -105,15 +105,14 @@ int pm_suspend(int domain_id) if (ret != OK) { goto errout; } - if (g_pmglobals.suspend_count[domain_id] >= UINT16_MAX) { - ret = ERROR; - set_errno(ERANGE); - goto errout; + if (g_pmglobals.suspend_count[domain_id]) { + pmdbg("Thread with pid (%d) tried to suspend domain (%s) again\n", getpid(), pm_domain_map[domain_id]); + } else { + g_pmglobals.suspend_count[domain_id] = true; } #ifdef CONFIG_PM_METRICS pm_metrics_update_suspend(domain_id); #endif - g_pmglobals.suspend_count[domain_id]++; errout: leave_critical_section(flags); return ret;