Skip to content

Commit 03232f9

Browse files
gmarullcarlescufi
authored andcommitted
pm: policy: residency: add compile time checks for timings
Check that minimum residency time is greater than exit latency time for all CPUs power states at compile time. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent d5036ec commit 03232f9

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

subsys/pm/pm.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,6 @@ bool pm_system_suspend(int32_t ticks)
206206
}
207207

208208
if (ticks != K_TICKS_FOREVER) {
209-
/*
210-
* Just a sanity check in case the policy manager does not
211-
* handle this error condition properly.
212-
*/
213-
__ASSERT(z_power_states[id].min_residency_us >=
214-
z_power_states[id].exit_latency_us,
215-
"min_residency_us < exit_latency_us");
216-
217209
/*
218210
* We need to set the timer to interrupt a little bit early to
219211
* accommodate the time required by the CPU to fully wake up.

subsys/pm/policy/policy_residency.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,36 @@
1414
#include <logging/log.h>
1515
LOG_MODULE_DECLARE(pm, CONFIG_PM_LOG_LEVEL);
1616

17+
/**
18+
* Check CPU power state consistency.
19+
*
20+
* @param i Power state index.
21+
* @param node_id CPU node identifier.
22+
*/
23+
#define CHECK_POWER_STATE_CONSISTENCY(i, node_id) \
24+
BUILD_ASSERT( \
25+
DT_PROP_BY_PHANDLE_IDX_OR(node_id, cpu_power_states, i, \
26+
min_residency_us, 0U) >= \
27+
DT_PROP_BY_PHANDLE_IDX_OR(node_id, cpu_power_states, i, \
28+
exit_latency_us, 0U), \
29+
"Found CPU power state with min_residency < exit_latency");
30+
31+
/**
32+
* @brief Check CPU power states consistency
33+
*
34+
* All states should have a minimum residency >= than the exit latency.
35+
*
36+
* @param node_id A CPU node identifier.
37+
*/
38+
#define CHECK_POWER_STATES_CONSISTENCY(node_id) \
39+
UTIL_LISTIFY(DT_NUM_CPU_POWER_STATES(node_id), \
40+
CHECK_POWER_STATE_CONSISTENCY, node_id) \
41+
42+
/* Check that all power states are consistent */
43+
COND_CODE_1(DT_NODE_EXISTS(DT_PATH(cpus)),
44+
(DT_FOREACH_CHILD(DT_PATH(cpus), CHECK_POWER_STATES_CONSISTENCY)),
45+
())
46+
1747
#define NUM_CPU_STATES(n) DT_NUM_CPU_POWER_STATES(n),
1848
#define CPU_STATES(n) (struct pm_state_info[])PM_STATE_INFO_LIST_FROM_DT_CPU(n),
1949

@@ -47,8 +77,6 @@ struct pm_state_info pm_policy_next_state(uint8_t cpu, int32_t ticks)
4777

4878
min_residency = k_us_to_ticks_ceil32(state->min_residency_us);
4979
exit_latency = k_us_to_ticks_ceil32(state->exit_latency_us);
50-
__ASSERT(min_residency > exit_latency,
51-
"min_residency_us < exit_latency_us");
5280

5381
if ((ticks == K_TICKS_FOREVER) ||
5482
(ticks >= (min_residency + exit_latency))) {

0 commit comments

Comments
 (0)