pm: Fix multithread issue with force state

The "state forced" flag has to be cleared with the scheduler locked,
otherwise the idle thread can be scheduled out without clear it and
the next call to force a state will fail.

Fixes #41911

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
Flavio Ceolin 2022-01-28 11:35:21 -08:00 committed by Anas Nashif
commit fdf7465851

View file

@ -270,12 +270,12 @@ bool pm_system_suspend(int32_t ticks)
#endif
pm_stats_update(z_cpus_pm_state[id].state);
pm_system_resume();
atomic_clear_bit(z_cpus_pm_state_forced, id);
k_sched_unlock();
SYS_PORT_TRACING_FUNC_EXIT(pm, system_suspend, ticks,
z_cpus_pm_state[id].state);
end:
atomic_clear_bit(z_cpus_pm_state_forced, id);
return ret;
}