2222#include <logging/log.h>
2323LOG_MODULE_REGISTER (pm , CONFIG_PM_LOG_LEVEL );
2424
25- static bool post_ops_done = true ;
25+ static ATOMIC_DEFINE ( z_post_ops_required , CONFIG_MP_NUM_CPUS ) ;
2626static sys_slist_t pm_notifiers = SYS_SLIST_STATIC_INIT (& pm_notifiers );
2727static struct pm_state_info z_power_states [CONFIG_MP_NUM_CPUS ];
2828/* bitmask to check if a power state was forced. */
@@ -148,6 +148,8 @@ static inline void pm_state_notify(bool entering_state)
148148
149149void pm_system_resume (void )
150150{
151+ uint8_t id = _current_cpu -> id ;
152+
151153 /*
152154 * This notification is called from the ISR of the event
153155 * that caused exit from kernel idling after PM operations.
@@ -160,10 +162,7 @@ void pm_system_resume(void)
160162 * The kernel scheduler will get control after the ISR finishes
161163 * and it may schedule another thread.
162164 */
163- if (!post_ops_done ) {
164- uint8_t id = _current_cpu -> id ;
165-
166- post_ops_done = true;
165+ if (atomic_test_and_clear_bit (z_post_ops_required , id )) {
167166 exit_pos_ops (z_power_states [id ]);
168167 pm_state_notify (false);
169168 z_power_states [id ] = (struct pm_state_info ){PM_STATE_ACTIVE ,
@@ -205,7 +204,6 @@ bool pm_system_suspend(int32_t ticks)
205204 ret = false;
206205 goto end ;
207206 }
208- post_ops_done = false;
209207
210208 if (ticks != K_TICKS_FOREVER ) {
211209 /*
@@ -253,6 +251,7 @@ bool pm_system_suspend(int32_t ticks)
253251 pm_stats_start ();
254252 /* Enter power state */
255253 pm_state_notify (true);
254+ atomic_set_bit (z_post_ops_required , id );
256255 pm_state_set (z_power_states [id ]);
257256 pm_stats_stop ();
258257
0 commit comments