2 * The idle loop for all SuperH platforms.
4 * Copyright (C) 2002 - 2009 Paul Mundt
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
10 #include <linux/module.h>
11 #include <linux/init.h>
14 #include <linux/tick.h>
15 #include <linux/preempt.h>
16 #include <linux/thread_info.h>
17 #include <linux/irqflags.h>
18 #include <linux/smp.h>
19 #include <asm/pgalloc.h>
20 #include <asm/system.h>
21 #include <asm/atomic.h>
24 void (*pm_idle
)(void) = NULL
;
26 static int hlt_counter
;
28 static int __init
nohlt_setup(char *__unused
)
33 __setup("nohlt", nohlt_setup
);
35 static int __init
hlt_setup(char *__unused
)
40 __setup("hlt", hlt_setup
);
42 static inline int hlt_works(void)
48 * On SMP it's slightly faster (but much more power-consuming!)
49 * to poll the ->work.need_resched flag instead of waiting for the
50 * cross-CPU IPI to arrive. Use this option with caution.
52 static void poll_idle(void)
55 while (!need_resched())
59 void default_idle(void)
62 clear_thread_flag(TIF_POLLING_NRFLAG
);
63 smp_mb__after_clear_bit();
66 if (!need_resched()) {
72 set_thread_flag(TIF_POLLING_NRFLAG
);
79 * The idle thread. There's no useful work to be done, so just try to conserve
80 * power and have a low exit latency (ie sit in a loop waiting for somebody to
81 * say that they'd like to reschedule)
85 unsigned int cpu
= smp_processor_id();
87 set_thread_flag(TIF_POLLING_NRFLAG
);
89 /* endless idle loop with no priority at all */
91 tick_nohz_stop_sched_tick(1);
93 while (!need_resched()) {
97 if (cpu_is_offline(cpu
))
101 /* Don't trace irqs off for idle */
102 stop_critical_timings();
105 * Sanity check to ensure that pm_idle() returns
108 WARN_ON(irqs_disabled());
109 start_critical_timings();
112 tick_nohz_restart_sched_tick();
113 preempt_enable_no_resched();
119 void __init
select_idle_routine(void)
122 * If a platform has set its own idle routine, leave it alone.
128 pm_idle
= default_idle
;
133 static void do_nothing(void *unused
)
137 void stop_this_cpu(void *unused
)
140 set_cpu_online(smp_processor_id(), false);
147 * cpu_idle_wait - Used to ensure that all the CPUs discard old value of
148 * pm_idle and update to new pm_idle value. Required while changing pm_idle
149 * handler on SMP systems.
151 * Caller must have changed pm_idle to the new value before the call. Old
152 * pm_idle value will not be used by any CPU after the return of this function.
154 void cpu_idle_wait(void)
157 /* kick all the CPUs so that they exit out of pm_idle */
158 smp_call_function(do_nothing
, NULL
, 1);
160 EXPORT_SYMBOL_GPL(cpu_idle_wait
);