2 * Common SMP CPU bringup/teardown functions
6 #include <linux/init.h>
7 #include <linux/sched.h>
8 #include <linux/percpu.h>
9 #include <linux/workqueue.h>
13 #ifdef CONFIG_GENERIC_SMP_IDLE_THREAD
15 struct work_struct work;
16 struct task_struct *idle;
17 struct completion done;
21 static void __cpuinit do_fork_idle(struct work_struct *work)
23 struct create_idle *c = container_of(work, struct create_idle, work);
25 c->idle = fork_idle(c->cpu);
29 static struct task_struct * __cpuinit idle_thread_create(unsigned int cpu)
31 struct create_idle c_idle = {
33 .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done),
36 INIT_WORK_ONSTACK(&c_idle.work, do_fork_idle);
37 schedule_work(&c_idle.work);
38 wait_for_completion(&c_idle.done);
39 destroy_work_on_stack(&c_idle.work);
44 * For the hotplug case we keep the task structs around and reuse
47 static DEFINE_PER_CPU(struct task_struct *, idle_threads);
49 static inline struct task_struct *get_idle_for_cpu(unsigned int cpu)
51 struct task_struct *tsk = per_cpu(idle_threads, cpu);
54 return idle_thread_create(cpu);
59 struct task_struct * __cpuinit idle_thread_get(unsigned int cpu)
61 return per_cpu(idle_threads, cpu);
64 void __init idle_thread_set_boot_cpu(void)
66 per_cpu(idle_threads, smp_processor_id()) = current;
70 * idle_thread_init - Initialize the idle thread for a cpu
71 * @cpu: The cpu for which the idle thread should be initialized
73 * Creates the thread if it does not exist.
75 static int __cpuinit idle_thread_init(unsigned int cpu)
77 struct task_struct *idle = get_idle_for_cpu(cpu);
80 printk(KERN_ERR "failed fork for CPU %u\n", cpu);
83 per_cpu(idle_threads, cpu) = idle;
87 static inline int idle_thread_init(unsigned int cpu) { return 0; }
91 * smpboot_prepare - generic smpboot preparation
93 int __cpuinit smpboot_prepare(unsigned int cpu)
95 return idle_thread_init(cpu);