2012-04-20 15:05:44 +02:00
|
|
|
/*
|
|
|
|
* Common SMP CPU bringup/teardown functions
|
|
|
|
*/
|
2012-04-20 15:05:45 +02:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/smp.h>
|
2012-04-20 15:05:44 +02:00
|
|
|
#include <linux/init.h>
|
2012-04-20 15:05:45 +02:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/percpu.h>
|
2012-04-20 15:05:44 +02:00
|
|
|
|
|
|
|
#include "smpboot.h"
|
|
|
|
|
2012-04-20 15:05:45 +02: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-21 02:08:50 +02:00
|
|
|
struct task_struct * __cpuinit idle_thread_get(unsigned int cpu)
|
2012-04-20 15:05:45 +02:00
|
|
|
{
|
|
|
|
struct task_struct *tsk = per_cpu(idle_threads, cpu);
|
|
|
|
|
|
|
|
if (!tsk)
|
2012-04-21 02:08:50 +02:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2012-04-20 15:05:45 +02:00
|
|
|
init_idle(tsk, cpu);
|
|
|
|
return tsk;
|
|
|
|
}
|
|
|
|
|
2012-04-21 02:08:50 +02:00
|
|
|
void __init idle_thread_set_boot_cpu(void)
|
2012-04-20 15:05:45 +02:00
|
|
|
{
|
2012-04-21 02:08:50 +02:00
|
|
|
per_cpu(idle_threads, smp_processor_id()) = current;
|
2012-04-20 15:05:45 +02:00
|
|
|
}
|
|
|
|
|
2012-05-24 17:11:00 +02:00
|
|
|
/**
|
|
|
|
* idle_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-21 02:08:50 +02:00
|
|
|
static inline void idle_init(unsigned int cpu)
|
2012-04-20 15:05:45 +02:00
|
|
|
{
|
2012-04-21 02:08:50 +02: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 15:05:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-05-24 17:11:00 +02:00
|
|
|
* idle_threads_init - Initialize idle threads for all cpus
|
2012-04-20 15:05:45 +02:00
|
|
|
*/
|
2012-04-21 02:08:50 +02:00
|
|
|
void __init idle_threads_init(void)
|
2012-04-20 15:05:45 +02:00
|
|
|
{
|
2012-05-24 17:10:55 +02:00
|
|
|
unsigned int cpu, boot_cpu;
|
|
|
|
|
|
|
|
boot_cpu = smp_processor_id();
|
2012-04-20 15:05:45 +02:00
|
|
|
|
2012-04-21 02:08:50 +02:00
|
|
|
for_each_possible_cpu(cpu) {
|
2012-05-24 17:10:55 +02:00
|
|
|
if (cpu != boot_cpu)
|
2012-04-21 02:08:50 +02:00
|
|
|
idle_init(cpu);
|
2012-04-20 15:05:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|