From 286b9069ccbfc914e771bbabec5430e878885819 Mon Sep 17 00:00:00 2001 From: Gaurav Sahitya Date: Wed, 18 Dec 2024 02:44:01 +0000 Subject: [PATCH] update pm_metrics structure --- os/pm/pm.h | 118 ++++-------------------- os/pm/pm_changestate.c | 2 +- os/pm/pm_domain_register.c | 2 +- os/pm/pm_idle.c | 2 +- os/pm/pm_metrics.c | 181 +++++++++++-------------------------- os/pm/pm_resume.c | 2 +- os/pm/pm_suspend.c | 2 +- os/pm/pm_wakehandler.c | 5 +- 8 files changed, 77 insertions(+), 237 deletions(-) diff --git a/os/pm/pm.h b/os/pm/pm.h index 14530f34cb..fba0c7e8b0 100644 --- a/os/pm/pm.h +++ b/os/pm/pm.h @@ -140,6 +140,22 @@ struct pm_global_s { bool is_running; }; +#ifdef CONFIG_PM_METRICS +typedef enum { + PM_MET_DOMAIN, /* Unknown Wakeup Source*/ + PM_MET_SUSPEND, /* BLE Interrupts */ + PM_MET_RESUME, /* Wifi Interrupts */ + PM_MET_IDLE, /* UART Console Interrupts */ + PM_MET_CHANGESTATE, /* UART TTYS2 Interrupts */ + PM_MET_WAKE, /* GPIO Interrupts */ +} pm_metrics_update_t; + +typedef struct { + clock_t ticks; + pm_wakeup_reason_code_t wakeup_src; +} pm_metrics_wake_t; +#endif + /**************************************************************************** * Public Data ****************************************************************************/ @@ -261,107 +277,7 @@ void pm_wakehandler(clock_t missing_tick, pm_wakeup_reason_code_t wakeup_src); #endif #ifdef CONFIG_PM_METRICS -/**************************************************************************** - * Name: pm_metrics_update_domain - * - * Description: - * This function is called when new domain got registered during pm_monitoring - * or during pm_metrics initialization. It initialize the PM Metrics for given - * domain. - * - * Input parameters: - * domain_id - the ID of domain registered with PM. - * - * Returned value: - * None - * - ****************************************************************************/ -void pm_metrics_update_domain(int domain_id); - -/**************************************************************************** - * Name: pm_metrics_update_suspend - * - * Description: - * This function is called inside pm_suspend. It note the timestamp (in ticks) of - * suspended domain. - * - * Input parameters: - * domain_id - the ID of domain registered with PM. - * - * Returned value: - * None - * - ****************************************************************************/ -void pm_metrics_update_suspend(int domain_id); - -/**************************************************************************** - * Name: pm_metrics_update_resume - * - * Description: - * This function is called inside pm_resume. Before resuming domain, it counts - * amount of time (in ticks) the given domain was suspended. - * - * Input parameters: - * domain_id - the ID of domain registered with PM. - * - * Returned value: - * None - * - ****************************************************************************/ -void pm_metrics_update_resume(int domain_id); - - -/**************************************************************************** - * Name: pm_metrics_update_changestate - * - * Description: - * This function is called inside pm_changestate. Before changing state, it counts - * amount of time (in ticks) was in that state. - * - * Input parameters: - * None - * - * Returned value: - * None - * - ****************************************************************************/ -void pm_metrics_update_changestate(void); - - -/**************************************************************************** - * Name: pm_metrics_update_idle - * - * Description: - * This function is called inside pm_idle. It counts the frequency of domain, which - * make board unable to go into sleep during idle cpu time. - * - * Input parameters: - * None - * - * Returned value: - * None - * - ****************************************************************************/ -void pm_metrics_update_idle(void); - - -/**************************************************************************** - * Name: pm_metrics_update_wakehandler - * - * Description: - * This function is called inside pm_wakehandler. It counts the frequency of wakeup - * sources, which are waking up the board. It also checks the amount of time board - * was in sleep. - * - * Input parameters: - * missing_tick - the amount of time the board was in sleep. - * wakeup_src - the wakeup reason code. - * - * Returned value: - * None - * - ****************************************************************************/ -void pm_metrics_update_wakehandler(clock_t missing_tick, pm_wakeup_reason_code_t wakeup_src); +void pm_metrics_update(pm_metrics_update_t cmd, unsigned long arg); #endif #undef EXTERN diff --git a/os/pm/pm_changestate.c b/os/pm/pm_changestate.c index 0961d537ff..69a483946d 100644 --- a/os/pm/pm_changestate.c +++ b/os/pm/pm_changestate.c @@ -235,7 +235,7 @@ int pm_changestate(enum pm_state_e newstate) */ pm_changeall(newstate); #ifdef CONFIG_PM_METRICS - pm_metrics_update_changestate(); + pm_metrics_update(PM_MET_CHANGESTATE, 0); #endif g_pmglobals.state = newstate; } diff --git a/os/pm/pm_domain_register.c b/os/pm/pm_domain_register.c index 7cfff653c5..54bc786be0 100644 --- a/os/pm/pm_domain_register.c +++ b/os/pm/pm_domain_register.c @@ -109,7 +109,7 @@ int pm_domain_register(char *domain) g_pmglobals.ndomains++; #ifdef CONFIG_PM_METRICS /* For newly registered domain initialize its pm metrics*/ - pm_metrics_update_domain(index); + pm_metrics_update(PM_MET_DOMAIN, index); #endif goto EXIT; /* If domain is already registered then return registered domain ID */ diff --git a/os/pm/pm_idle.c b/os/pm/pm_idle.c index b3f207e8e6..1380cc11c5 100644 --- a/os/pm/pm_idle.c +++ b/os/pm/pm_idle.c @@ -97,7 +97,7 @@ void pm_idle(void) /* Decide, which power saving level can be obtained */ newstate = pm_checkstate(); #ifdef CONFIG_PM_METRICS - pm_metrics_update_idle(); + pm_metrics_update(PM_MET_IDLE, 0); #endif #ifdef CONFIG_PM_TIMEDWAKEUP /* get wakeup timer */ diff --git a/os/pm/pm_metrics.c b/os/pm/pm_metrics.c index 6fdf8ab4bf..4bc497a1ba 100644 --- a/os/pm/pm_metrics.c +++ b/os/pm/pm_metrics.c @@ -97,143 +97,64 @@ static void pm_print_metrics(double total_time, int n_domains) * Public Functions ************************************************************************************/ -/**************************************************************************** - * Name: pm_metrics_update_domain - * - * Description: - * This function is called when new domain got registered during pm_monitoring - * or during pm_metrics initialization. It initialize the PM Metrics for given - * domain. - * - * Input parameters: - * domain_id - the ID of domain registered with PM. - * - * Returned value: - * None - * - ****************************************************************************/ -void pm_metrics_update_domain(int domain_id) +void pm_metrics_update(pm_metrics_update_t cmd, unsigned long arg) { - if (g_pm_metrics_running) { - g_pm_metrics->domain_metrics.stime[domain_id] = clock_systimer(); - g_pm_metrics->domain_metrics.suspend_ticks[domain_id] = 0; - } -} + clock_t tick; + pm_wakeup_reason_code_t wakeup_src; + int domain_id; + int index; -/**************************************************************************** - * Name: pm_metrics_update_suspend - * - * Description: - * This function is called inside pm_suspend. It note the timestamp (in ticks) of - * suspended domain. - * - * Input parameters: - * domain_id - the ID of domain registered with PM. - * - * Returned value: - * None - * - ****************************************************************************/ -void pm_metrics_update_suspend(int domain_id) -{ - if (g_pm_metrics_running && (g_pmglobals.suspend_count[domain_id] == 0)) { - g_pm_metrics->domain_metrics.stime[domain_id] = clock_systimer(); + if (!g_pm_metrics_running) { + return; } -} -/**************************************************************************** - * Name: pm_metrics_update_resume - * - * Description: - * This function is called inside pm_resume. Before resuming domain, it counts - * amount of time (in ticks) the given domain was suspended. - * - * Input parameters: - * domain_id - the ID of domain registered with PM. - * - * Returned value: - * None - * - ****************************************************************************/ -void pm_metrics_update_resume(int domain_id) -{ - if (g_pm_metrics_running && (g_pmglobals.suspend_count[domain_id] == 1)) { - g_pm_metrics->domain_metrics.suspend_ticks[domain_id] += clock_systimer() - g_pm_metrics->domain_metrics.stime[domain_id]; - } -} + switch (cmd) { -/**************************************************************************** - * Name: pm_metrics_update_idle - * - * Description: - * This function is called inside pm_idle. It counts the frequency of domain, which - * make board unable to go into sleep during idle cpu time. - * - * Input parameters: - * None - * - * Returned value: - * None - * - ****************************************************************************/ -void pm_metrics_update_idle(void) -{ - int index; - if (g_pm_metrics_running) { - g_pm_metrics->total_try_ticks++; - for (index = 0; index < CONFIG_PM_NDOMAINS; index++) { - if (g_pmglobals.suspend_count[index] != 0) { - g_pm_metrics->domain_metrics.blocking_board_sleep_ticks[index]++; - } - } - } -} + case PM_MET_DOMAIN: + domain_id = (int)arg; + g_pm_metrics->domain_metrics.stime[domain_id] = clock_systimer(); + g_pm_metrics->domain_metrics.suspend_ticks[domain_id] = 0; + break; -/**************************************************************************** - * Name: pm_metrics_update_changestate - * - * Description: - * This function is called inside pm_changestate. Before changing state, it counts - * amount of time (in ticks) was in that state. - * - * Input parameters: - * None - * - * Returned value: - * None - * - ****************************************************************************/ -void pm_metrics_update_changestate(void) -{ - clock_t now; - if (g_pm_metrics_running) { - now = clock_systimer(); - g_pm_metrics->state_metrics.state_accum_ticks[g_pmglobals.state] += now - g_pm_metrics->state_metrics.stime; - g_pm_metrics->state_metrics.stime = now; - } -} + case PM_MET_SUSPEND: + domain_id = (int)arg; + if (g_pmglobals.suspend_count[domain_id] == 0) { + g_pm_metrics->domain_metrics.stime[domain_id] = clock_systimer(); + } + break; -/**************************************************************************** - * Name: pm_metrics_update_wakehandler - * - * Description: - * This function is called inside pm_wakehandler. It counts the frequency of wakeup - * sources, which are waking up the board. It also checks the amount of time board - * was in sleep. - * - * Input parameters: - * missing_tick - the amount of time the board was in sleep. - * wakeup_src - the wakeup reason code. - * - * Returned value: - * None - * - ****************************************************************************/ -void pm_metrics_update_wakehandler(clock_t missing_tick, pm_wakeup_reason_code_t wakeup_src) -{ - if (g_pm_metrics_running) { - g_pm_metrics->wakeup_src_counts[wakeup_src]++; - g_pm_metrics->board_sleep_ticks += missing_tick; + case PM_MET_RESUME: + domain_id = (int)arg; + if (g_pmglobals.suspend_count[domain_id] == 1) { + g_pm_metrics->domain_metrics.suspend_ticks[domain_id] += clock_systimer() - g_pm_metrics->domain_metrics.stime[domain_id]; + } + break; + + case PM_MET_IDLE: + g_pm_metrics->total_try_ticks++; + for (index = 0; index < CONFIG_PM_NDOMAINS; index++) { + if (g_pmglobals.suspend_count[index] != 0) { + g_pm_metrics->domain_metrics.blocking_board_sleep_ticks[index]++; + } + } + break; + + case PM_MET_CHANGESTATE: + tick = clock_systimer(); + g_pm_metrics->state_metrics.state_accum_ticks[g_pmglobals.state] += tick - g_pm_metrics->state_metrics.stime; + g_pm_metrics->state_metrics.stime = tick; + break; + + case PM_MET_WAKE: + tick = ((pm_metrics_wake_t *)arg)->ticks; + wakeup_src = ((pm_metrics_wake_t *)arg)->wakeup_src; + g_pm_metrics->wakeup_src_counts[wakeup_src]++; + g_pm_metrics->board_sleep_ticks += tick; + break; + + default: + pmdbg("Unknown CMD: %d\n", (int)cmd); + break; } } diff --git a/os/pm/pm_resume.c b/os/pm/pm_resume.c index 628c6d880d..caede85527 100644 --- a/os/pm/pm_resume.c +++ b/os/pm/pm_resume.c @@ -108,7 +108,7 @@ int pm_resume(int domain_id) goto errout; } #ifdef CONFIG_PM_METRICS - pm_metrics_update_resume(domain_id); + pm_metrics_update(PM_MET_RESUME, domain_id); #endif g_pmglobals.suspend_count[domain_id]--; errout: diff --git a/os/pm/pm_suspend.c b/os/pm/pm_suspend.c index aa70a79f67..5e84ef2176 100644 --- a/os/pm/pm_suspend.c +++ b/os/pm/pm_suspend.c @@ -111,7 +111,7 @@ int pm_suspend(int domain_id) goto errout; } #ifdef CONFIG_PM_METRICS - pm_metrics_update_suspend(domain_id); + pm_metrics_update(PM_MET_SUSPEND, domain_id); #endif g_pmglobals.suspend_count[domain_id]++; errout: diff --git a/os/pm/pm_wakehandler.c b/os/pm/pm_wakehandler.c index 857aa55be3..081889491b 100644 --- a/os/pm/pm_wakehandler.c +++ b/os/pm/pm_wakehandler.c @@ -56,7 +56,10 @@ void pm_wakehandler(clock_t missing_tick, pm_wakeup_reason_code_t wakeup_src) { irqstate_t flags = enter_critical_section(); #ifdef CONFIG_PM_METRICS - pm_metrics_update_wakehandler(missing_tick, wakeup_src); + pm_metrics_wake_t wake_arg; + wake_arg.ticks = missing_tick; + wake_arg.wakeup_src = wakeup_src; + pm_metrics_update(PM_MET_WAKE, (unsigned long)(&wake_arg)); #endif pmllvdbg("wakeup source code = %d\n", wakeup_src); pmllvdbg("missing_tick: %llu\n", missing_tick);