Skip to content

Commit ad849de

Browse files
silabs-BastienBhenrikbrixandersen
authored andcommitted
pm: skip min_residency_ticks calculation if input is 0
In the default PM policy, the function k_us_to_ticks_ceil32() is used and does calculation using 64-bit integers which can be slow and avoidable if the input is 0. Signed-off-by: Bastien Beauchamp <[email protected]>
1 parent 0f948ab commit ad849de

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

subsys/pm/policy/policy_default.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks)
2525

2626
for (uint32_t i = 0; i < num_cpu_states; i++) {
2727
const struct pm_state_info *state = &cpu_states[i];
28-
uint32_t min_residency_ticks;
28+
uint32_t min_residency_ticks = 0;
29+
uint32_t min_residency_us = state->min_residency_us + state->exit_latency_us;
2930

30-
min_residency_ticks =
31-
k_us_to_ticks_ceil32(state->min_residency_us + state->exit_latency_us);
31+
/* If the input is zero, avoid 64-bit conversion from microseconds to ticks. */
32+
if (min_residency_us > 0) {
33+
min_residency_ticks = k_us_to_ticks_ceil32(min_residency_us);
34+
}
3235

3336
if (ticks < min_residency_ticks) {
3437
/* If current state has higher residency then use the previous state; */

0 commit comments

Comments
 (0)