1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_SCHED_IDLE_H
3 #define _LINUX_SCHED_IDLE_H
5 #include <linux/sched.h>
15 extern void wake_up_if_idle(int cpu);
17 static inline void wake_up_if_idle(int cpu) { }
21 * Idle thread specific functions to determine the need_resched
24 #ifdef TIF_POLLING_NRFLAG
26 static inline void __current_set_polling(void)
28 set_thread_flag(TIF_POLLING_NRFLAG);
31 static inline bool __must_check current_set_polling_and_test(void)
33 __current_set_polling();
36 * Polling state must be visible before we test NEED_RESCHED,
37 * paired by resched_curr()
39 smp_mb__after_atomic();
41 return unlikely(tif_need_resched());
44 static inline void __current_clr_polling(void)
46 clear_thread_flag(TIF_POLLING_NRFLAG);
49 static inline bool __must_check current_clr_polling_and_test(void)
51 __current_clr_polling();
54 * Polling state must be visible before we test NEED_RESCHED,
55 * paired by resched_curr()
57 smp_mb__after_atomic();
59 return unlikely(tif_need_resched());
63 static inline void __current_set_polling(void) { }
64 static inline void __current_clr_polling(void) { }
66 static inline bool __must_check current_set_polling_and_test(void)
68 return unlikely(tif_need_resched());
70 static inline bool __must_check current_clr_polling_and_test(void)
72 return unlikely(tif_need_resched());
76 static inline void current_clr_polling(void)
78 __current_clr_polling();
81 * Ensure we check TIF_NEED_RESCHED after we clear the polling bit.
82 * Once the bit is cleared, we'll get IPIs with every new
83 * TIF_NEED_RESCHED and the IPI handler, scheduler_ipi(), will also
86 smp_mb(); /* paired with resched_curr() */
88 preempt_fold_need_resched();
91 #endif /* _LINUX_SCHED_IDLE_H */