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)
43 trace_cpu_idle_rcuidle(0, smp_processor_id());
45 while (!need_resched())
47 trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, smp_processor_id());
51 /* Weak implementations for optional arch specific functions */
52 void __weak arch_cpu_idle_prepare(void) { }
53 void __weak arch_cpu_idle_enter(void) { }
54 void __weak arch_cpu_idle_exit(void) { }
55 void __weak arch_cpu_idle_dead(void) { }
56 void __weak arch_cpu_idle(void)
58 cpu_idle_force_poll = 1;
62 * Generic idle loop implementation
64 static void cpu_idle_loop(void)
67 tick_nohz_idle_enter();
69 while (!need_resched()) {
73 if (cpu_is_offline(smp_processor_id()))
77 arch_cpu_idle_enter();
80 * In poll mode we reenable interrupts and spin.
82 * Also if we detected in the wakeup from idle
83 * path that the tick broadcast device expired
84 * for us, we don't want to go deep idle as we
85 * know that the IPI is going to arrive right
88 if (cpu_idle_force_poll || tick_check_broadcast_expired()) {
91 current_clr_polling();
92 if (!need_resched()) {
93 stop_critical_timings();
96 WARN_ON_ONCE(irqs_disabled());
98 start_critical_timings();
102 current_set_polling();
104 arch_cpu_idle_exit();
106 tick_nohz_idle_exit();
107 schedule_preempt_disabled();
111 void cpu_startup_entry(enum cpuhp_state state)
113 current_set_polling();
114 arch_cpu_idle_prepare();