Skip to content

Commit

Permalink
update pm_metrics structure
Browse files Browse the repository at this point in the history
  • Loading branch information
gSahitya-samsung committed Dec 18, 2024
1 parent 99d9563 commit 1ea6e65
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 238 deletions.
118 changes: 17 additions & 101 deletions os/pm/pm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
****************************************************************************/
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion os/pm/pm_changestate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion os/pm/pm_domain_register.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion os/pm/pm_idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
182 changes: 51 additions & 131 deletions os/pm/pm_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -284,7 +205,6 @@ int pm_metrics(int milliseconds)
start_time = clock_systimer();
g_pm_metrics->state_metrics.stime = start_time;
for (index = 0; (index < CONFIG_PM_NDOMAINS) && pm_domain_map[index]; index++) {
pm_metrics_update_domain(index);
g_pm_metrics->domain_metrics.stime[index] = start_time;
}
g_pm_metrics_running = true;
Expand Down
2 changes: 1 addition & 1 deletion os/pm/pm_resume.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion os/pm/pm_suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion os/pm/pm_wakehandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1ea6e65

Please sign in to comment.