2008-11-26 06:52:44 +00:00
|
|
|
/*
|
|
|
|
* The idle loop for all SuperH platforms.
|
|
|
|
*
|
2009-06-19 05:40:51 +00:00
|
|
|
* Copyright (C) 2002 - 2009 Paul Mundt
|
2008-11-26 06:52:44 +00:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/pm.h>
|
|
|
|
#include <linux/tick.h>
|
|
|
|
#include <linux/preempt.h>
|
|
|
|
#include <linux/thread_info.h>
|
|
|
|
#include <linux/irqflags.h>
|
2009-06-19 05:40:51 +00:00
|
|
|
#include <linux/smp.h>
|
2011-04-01 23:34:59 +00:00
|
|
|
#include <linux/cpuidle.h>
|
2008-11-26 06:52:44 +00:00
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/system.h>
|
2011-07-26 23:09:06 +00:00
|
|
|
#include <linux/atomic.h>
|
2010-04-26 10:08:55 +00:00
|
|
|
#include <asm/smp.h>
|
2008-11-26 06:52:44 +00:00
|
|
|
|
2011-04-01 23:34:59 +00:00
|
|
|
static void (*pm_idle)(void);
|
2010-01-20 07:42:52 +00:00
|
|
|
|
|
|
|
static int hlt_counter;
|
2008-11-26 06:52:44 +00:00
|
|
|
|
|
|
|
static int __init nohlt_setup(char *__unused)
|
|
|
|
{
|
|
|
|
hlt_counter = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("nohlt", nohlt_setup);
|
|
|
|
|
|
|
|
static int __init hlt_setup(char *__unused)
|
|
|
|
{
|
|
|
|
hlt_counter = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("hlt", hlt_setup);
|
|
|
|
|
2009-10-16 08:20:58 +00:00
|
|
|
static inline int hlt_works(void)
|
|
|
|
{
|
|
|
|
return !hlt_counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On SMP it's slightly faster (but much more power-consuming!)
|
|
|
|
* to poll the ->work.need_resched flag instead of waiting for the
|
|
|
|
* cross-CPU IPI to arrive. Use this option with caution.
|
|
|
|
*/
|
|
|
|
static void poll_idle(void)
|
|
|
|
{
|
|
|
|
local_irq_enable();
|
|
|
|
while (!need_resched())
|
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
|
2009-04-02 04:08:31 +00:00
|
|
|
void default_idle(void)
|
2008-11-26 06:52:44 +00:00
|
|
|
{
|
2009-10-16 08:20:58 +00:00
|
|
|
if (hlt_works()) {
|
2008-11-26 06:52:44 +00:00
|
|
|
clear_thread_flag(TIF_POLLING_NRFLAG);
|
|
|
|
smp_mb__after_clear_bit();
|
|
|
|
|
2009-12-18 05:40:56 +00:00
|
|
|
set_bl_bit();
|
2009-10-16 08:20:58 +00:00
|
|
|
if (!need_resched()) {
|
|
|
|
local_irq_enable();
|
2008-11-26 06:52:44 +00:00
|
|
|
cpu_sleep();
|
2009-10-16 08:55:59 +00:00
|
|
|
} else
|
|
|
|
local_irq_enable();
|
2008-11-26 06:52:44 +00:00
|
|
|
|
|
|
|
set_thread_flag(TIF_POLLING_NRFLAG);
|
2009-12-18 05:40:56 +00:00
|
|
|
clear_bl_bit();
|
2008-11-26 06:52:44 +00:00
|
|
|
} else
|
2009-10-16 08:20:58 +00:00
|
|
|
poll_idle();
|
2008-11-26 06:52:44 +00:00
|
|
|
}
|
|
|
|
|
2009-10-16 08:20:58 +00:00
|
|
|
/*
|
|
|
|
* The idle thread. There's no useful work to be done, so just try to conserve
|
|
|
|
* power and have a low exit latency (ie sit in a loop waiting for somebody to
|
|
|
|
* say that they'd like to reschedule)
|
|
|
|
*/
|
2008-11-26 06:52:44 +00:00
|
|
|
void cpu_idle(void)
|
|
|
|
{
|
2009-10-16 08:20:58 +00:00
|
|
|
unsigned int cpu = smp_processor_id();
|
|
|
|
|
2008-11-26 06:52:44 +00:00
|
|
|
set_thread_flag(TIF_POLLING_NRFLAG);
|
|
|
|
|
|
|
|
/* endless idle loop with no priority at all */
|
|
|
|
while (1) {
|
2009-10-16 08:20:58 +00:00
|
|
|
tick_nohz_stop_sched_tick(1);
|
2008-11-26 06:52:44 +00:00
|
|
|
|
2010-04-26 10:08:55 +00:00
|
|
|
while (!need_resched()) {
|
2009-10-16 08:27:58 +00:00
|
|
|
check_pgt_cache();
|
|
|
|
rmb();
|
|
|
|
|
2010-04-26 10:08:55 +00:00
|
|
|
if (cpu_is_offline(cpu))
|
|
|
|
play_dead();
|
|
|
|
|
2009-10-16 08:20:58 +00:00
|
|
|
local_irq_disable();
|
|
|
|
/* Don't trace irqs off for idle */
|
|
|
|
stop_critical_timings();
|
2011-08-04 16:24:31 +00:00
|
|
|
if (cpuidle_idle_call())
|
2011-04-01 23:34:59 +00:00
|
|
|
pm_idle();
|
2009-10-16 08:20:58 +00:00
|
|
|
/*
|
|
|
|
* Sanity check to ensure that pm_idle() returns
|
|
|
|
* with IRQs enabled
|
|
|
|
*/
|
|
|
|
WARN_ON(irqs_disabled());
|
|
|
|
start_critical_timings();
|
|
|
|
}
|
2008-11-26 06:52:44 +00:00
|
|
|
|
|
|
|
tick_nohz_restart_sched_tick();
|
|
|
|
preempt_enable_no_resched();
|
|
|
|
schedule();
|
|
|
|
preempt_disable();
|
|
|
|
}
|
|
|
|
}
|
2009-06-19 05:40:51 +00:00
|
|
|
|
2010-03-23 08:06:47 +00:00
|
|
|
void __init select_idle_routine(void)
|
2009-10-16 08:20:58 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If a platform has set its own idle routine, leave it alone.
|
|
|
|
*/
|
|
|
|
if (pm_idle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (hlt_works())
|
|
|
|
pm_idle = default_idle;
|
|
|
|
else
|
|
|
|
pm_idle = poll_idle;
|
|
|
|
}
|
|
|
|
|
2009-06-19 05:40:51 +00:00
|
|
|
static void do_nothing(void *unused)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-01-20 07:42:52 +00:00
|
|
|
void stop_this_cpu(void *unused)
|
|
|
|
{
|
|
|
|
local_irq_disable();
|
2010-04-26 09:39:50 +00:00
|
|
|
set_cpu_online(smp_processor_id(), false);
|
2010-01-20 07:42:52 +00:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
cpu_sleep();
|
|
|
|
}
|
|
|
|
|
2009-06-19 05:40:51 +00:00
|
|
|
/*
|
|
|
|
* cpu_idle_wait - Used to ensure that all the CPUs discard old value of
|
|
|
|
* pm_idle and update to new pm_idle value. Required while changing pm_idle
|
|
|
|
* handler on SMP systems.
|
|
|
|
*
|
|
|
|
* Caller must have changed pm_idle to the new value before the call. Old
|
|
|
|
* pm_idle value will not be used by any CPU after the return of this function.
|
|
|
|
*/
|
|
|
|
void cpu_idle_wait(void)
|
|
|
|
{
|
|
|
|
smp_mb();
|
|
|
|
/* kick all the CPUs so that they exit out of pm_idle */
|
|
|
|
smp_call_function(do_nothing, NULL, 1);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpu_idle_wait);
|