sys_pm_ctrl: fragility in managing state control #20775
Labels
area: Power Management
bug
The issue is a bug, or the PR is fixing a bug
priority: low
Low impact/importance bug
Stale
subsys/power supports the option (via
CONFIG_SYS_PM_STATE_LOCK
) to enable and disable specific power states. State is managed with an array ofatomic_t
instances.A request to disable a state corresponds to an atomic increment.
A request to enable a state corresponds to an atomic decrement.
The state is considered enabled when the counter is zero, which is the initial condition.
This approach results in some unusual behavior:
sys_pm_ctrl_enable_state(S)
when S is enabled decrements the counter to -1 thereby disabling the state.sys_pm_ctrl_disable_state(S)
when S is disabled means that a subsequentsys_pm_ctrl_enable_state(S)
may not enable the state.The code has asserts to detect for underflow and overflow but since assertions are not generally enabled "misuse" is unlikely to be found.
It may be that this behavior is intended. If so it needs to be documented.
The text was updated successfully, but these errors were encountered: