2 * Generic entry point for the idle threads
4 #include <linux/sched.h>
6 #include <linux/tick.h>
8 #ifdef CONFIG_MT_LOAD_BALANCE_PROFILER
9 #include <mtlbprof/mtlbprof.h>
11 #include <linux/stackprotector.h>
15 #include <trace/events/power.h>
17 static int __read_mostly cpu_idle_force_poll
;
19 void cpu_idle_poll_ctrl(bool enable
)
22 cpu_idle_force_poll
++;
24 cpu_idle_force_poll
--;
25 WARN_ON_ONCE(cpu_idle_force_poll
< 0);
29 #ifdef CONFIG_GENERIC_IDLE_POLL_SETUP
30 static int __init
cpu_idle_poll_setup(char *__unused
)
32 cpu_idle_force_poll
= 1;
35 __setup("nohlt", cpu_idle_poll_setup
);
37 static int __init
cpu_idle_nopoll_setup(char *__unused
)
39 cpu_idle_force_poll
= 0;
42 __setup("hlt", cpu_idle_nopoll_setup
);
45 static inline int cpu_idle_poll(void)
48 trace_cpu_idle_rcuidle(0, smp_processor_id());
50 while (!tif_need_resched())
52 trace_cpu_idle_rcuidle(PWR_EVENT_EXIT
, smp_processor_id());
57 /* Weak implementations for optional arch specific functions */
58 void __weak
arch_cpu_idle_prepare(void) { }
59 void __weak
arch_cpu_idle_enter(void) { }
60 void __weak
arch_cpu_idle_exit(void) { }
61 void __weak
arch_cpu_idle_dead(void) { }
62 void __weak
arch_cpu_idle(void)
64 cpu_idle_force_poll
= 1;
69 * Generic idle loop implementation
71 static void cpu_idle_loop(void)
73 #ifdef CONFIG_MT_LOAD_BALANCE_PROFILER
74 mt_lbprof_update_state(smp_processor_id(), MT_LBPROF_NO_TASK_STATE
);
78 tick_nohz_idle_enter();
80 while (!need_resched()) {
84 if (cpu_is_offline(smp_processor_id()))
87 #ifdef CONFIG_MT_LOAD_BALANCE_PROFILER
88 mt_lbprof_update_state(smp_processor_id(), MT_LBPROF_IDLE_STATE
);
92 arch_cpu_idle_enter();
95 * In poll mode we reenable interrupts and spin.
97 * Also if we detected in the wakeup from idle
98 * path that the tick broadcast device expired
99 * for us, we don't want to go deep idle as we
100 * know that the IPI is going to arrive right
103 if (cpu_idle_force_poll
|| tick_check_broadcast_expired()) {
106 if (!current_clr_polling_and_test()) {
107 stop_critical_timings();
110 WARN_ON_ONCE(irqs_disabled());
112 start_critical_timings();
113 #ifdef CONFIG_MT_LOAD_BALANCE_PROFILER
114 mt_lbprof_update_state(smp_processor_id(), MT_LBPROF_NO_TASK_STATE
);
119 __current_set_polling();
121 arch_cpu_idle_exit();
123 tick_nohz_idle_exit();
124 schedule_preempt_disabled();
128 void cpu_startup_entry(enum cpuhp_state state
)
131 * This #ifdef needs to die, but it's too late in the cycle to
132 * make this generic (arm and sh have never invoked the canary
133 * init for the non boot cpus!). Will be fixed in 3.11
137 * If we're the non-boot CPU, nothing set the stack canary up
138 * for us. The boot CPU already has it initialized but no harm
139 * in doing it again. This is a good place for updating it, as
140 * we wont ever return from this function (so the invalid
141 * canaries already on the stack wont ever trigger).
143 boot_init_stack_canary();
145 __current_set_polling();
146 arch_cpu_idle_prepare();