2 * Generic entry point for the idle threads
4 #include <linux/sched.h>
6 #include <linux/tick.h>
11 #include <trace/events/power.h>
13 static int __read_mostly cpu_idle_force_poll;
15 void cpu_idle_poll_ctrl(bool enable)
18 cpu_idle_force_poll++;
20 cpu_idle_force_poll--;
21 WARN_ON_ONCE(cpu_idle_force_poll < 0);
25 #ifdef CONFIG_GENERIC_IDLE_POLL_SETUP
26 static int __init cpu_idle_poll_setup(char *__unused)
28 cpu_idle_force_poll = 1;
31 __setup("nohlt", cpu_idle_poll_setup);
33 static int __init cpu_idle_nopoll_setup(char *__unused)
35 cpu_idle_force_poll = 0;
38 __setup("hlt", cpu_idle_nopoll_setup);
41 static inline int cpu_idle_poll(void)
44 trace_cpu_idle_rcuidle(0, smp_processor_id());
46 while (!need_resched())
48 trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, smp_processor_id());
53 /* Weak implementations for optional arch specific functions */
54 void __weak arch_cpu_idle_prepare(void) { }
55 void __weak arch_cpu_idle_enter(void) { }
56 void __weak arch_cpu_idle_exit(void) { }
57 void __weak arch_cpu_idle_dead(void) { }
58 void __weak arch_cpu_idle(void)
60 cpu_idle_force_poll = 1;
64 * Generic idle loop implementation
66 static void cpu_idle_loop(void)
69 tick_nohz_idle_enter();
71 while (!need_resched()) {
75 if (cpu_is_offline(smp_processor_id()))
79 arch_cpu_idle_enter();
82 * In poll mode we reenable interrupts and spin.
84 * Also if we detected in the wakeup from idle
85 * path that the tick broadcast device expired
86 * for us, we don't want to go deep idle as we
87 * know that the IPI is going to arrive right
90 if (cpu_idle_force_poll || tick_check_broadcast_expired()) {
93 current_clr_polling();
94 if (!need_resched()) {
95 stop_critical_timings();
98 WARN_ON_ONCE(irqs_disabled());
100 start_critical_timings();
104 current_set_polling();
106 arch_cpu_idle_exit();
108 tick_nohz_idle_exit();
109 schedule_preempt_disabled();
113 void cpu_startup_entry(enum cpuhp_state state)
115 current_set_polling();
116 arch_cpu_idle_prepare();