2012-04-20 06:05:44 -07:00
|
|
|
/*
|
|
|
|
* Common SMP CPU bringup/teardown functions
|
|
|
|
*/
|
2012-04-20 06:05:45 -07:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/smp.h>
|
2012-04-20 06:05:44 -07:00
|
|
|
#include <linux/init.h>
|
2012-04-20 06:05:45 -07:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/percpu.h>
|
2012-04-20 06:05:44 -07:00
|
|
|
|
|
|
|
#include "smpboot.h"
|
|
|
|
|
2012-04-20 06:05:45 -07:00
|
|
|
#ifdef CONFIG_GENERIC_SMP_IDLE_THREAD
|
|
|
|
/*
|
|
|
|
* For the hotplug case we keep the task structs around and reuse
|
|
|
|
* them.
|
|
|
|
*/
|
|
|
|
static DEFINE_PER_CPU(struct task_struct *, idle_threads);
|
|
|
|
|
2012-04-20 17:08:50 -07:00
|
|
|
struct task_struct * __cpuinit idle_thread_get(unsigned int cpu)
|
2012-04-20 06:05:45 -07:00
|
|
|
{
|
|
|
|
struct task_struct *tsk = per_cpu(idle_threads, cpu);
|
|
|
|
|
|
|
|
if (!tsk)
|
2012-04-20 17:08:50 -07:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2012-04-20 06:05:45 -07:00
|
|
|
init_idle(tsk, cpu);
|
|
|
|
return tsk;
|
|
|
|
}
|
|
|
|
|
2012-04-20 17:08:50 -07:00
|
|
|
void __init idle_thread_set_boot_cpu(void)
|
2012-04-20 06:05:45 -07:00
|
|
|
{
|
2012-04-20 17:08:50 -07:00
|
|
|
per_cpu(idle_threads, smp_processor_id()) = current;
|
2012-04-20 06:05:45 -07:00
|
|
|
}
|
|
|
|
|
2012-04-20 17:08:50 -07:00
|
|
|
static inline void idle_init(unsigned int cpu)
|
2012-04-20 06:05:45 -07:00
|
|
|
{
|
2012-04-20 17:08:50 -07:00
|
|
|
struct task_struct *tsk = per_cpu(idle_threads, cpu);
|
|
|
|
|
|
|
|
if (!tsk) {
|
|
|
|
tsk = fork_idle(cpu);
|
|
|
|
if (IS_ERR(tsk))
|
|
|
|
pr_err("SMP: fork_idle() failed for CPU %u\n", cpu);
|
|
|
|
else
|
|
|
|
per_cpu(idle_threads, cpu) = tsk;
|
|
|
|
}
|
2012-04-20 06:05:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* idle_thread_init - Initialize the idle thread for a cpu
|
|
|
|
* @cpu: The cpu for which the idle thread should be initialized
|
|
|
|
*
|
|
|
|
* Creates the thread if it does not exist.
|
|
|
|
*/
|
2012-04-20 17:08:50 -07:00
|
|
|
void __init idle_threads_init(void)
|
2012-04-20 06:05:45 -07:00
|
|
|
{
|
2012-04-20 17:08:50 -07:00
|
|
|
unsigned int cpu;
|
2012-04-20 06:05:45 -07:00
|
|
|
|
2012-04-20 17:08:50 -07:00
|
|
|
for_each_possible_cpu(cpu) {
|
|
|
|
if (cpu != smp_processor_id())
|
|
|
|
idle_init(cpu);
|
2012-04-20 06:05:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|