Merge branches 'acpi_pad', 'acpica', 'apei-bugzilla-43282', 'battery', 'cpuidle-coupl...
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / kernel / smpboot.c
CommitLineData
38498a67
TG
1/*
2 * Common SMP CPU bringup/teardown functions
3 */
29d5e047
TG
4#include <linux/err.h>
5#include <linux/smp.h>
38498a67 6#include <linux/init.h>
29d5e047
TG
7#include <linux/sched.h>
8#include <linux/percpu.h>
38498a67
TG
9
10#include "smpboot.h"
11
29d5e047 12#ifdef CONFIG_GENERIC_SMP_IDLE_THREAD
29d5e047
TG
13/*
14 * For the hotplug case we keep the task structs around and reuse
15 * them.
16 */
17static DEFINE_PER_CPU(struct task_struct *, idle_threads);
18
3bb5d2ee 19struct task_struct * __cpuinit idle_thread_get(unsigned int cpu)
29d5e047
TG
20{
21 struct task_struct *tsk = per_cpu(idle_threads, cpu);
22
23 if (!tsk)
3bb5d2ee 24 return ERR_PTR(-ENOMEM);
29d5e047
TG
25 init_idle(tsk, cpu);
26 return tsk;
27}
28
3bb5d2ee 29void __init idle_thread_set_boot_cpu(void)
29d5e047 30{
3bb5d2ee 31 per_cpu(idle_threads, smp_processor_id()) = current;
29d5e047
TG
32}
33
4a70d2d9
SB
34/**
35 * idle_init - Initialize the idle thread for a cpu
36 * @cpu: The cpu for which the idle thread should be initialized
37 *
38 * Creates the thread if it does not exist.
39 */
3bb5d2ee 40static inline void idle_init(unsigned int cpu)
29d5e047 41{
3bb5d2ee
SS
42 struct task_struct *tsk = per_cpu(idle_threads, cpu);
43
44 if (!tsk) {
45 tsk = fork_idle(cpu);
46 if (IS_ERR(tsk))
47 pr_err("SMP: fork_idle() failed for CPU %u\n", cpu);
48 else
49 per_cpu(idle_threads, cpu) = tsk;
50 }
29d5e047
TG
51}
52
53/**
4a70d2d9 54 * idle_threads_init - Initialize idle threads for all cpus
29d5e047 55 */
3bb5d2ee 56void __init idle_threads_init(void)
29d5e047 57{
ee74d132
SB
58 unsigned int cpu, boot_cpu;
59
60 boot_cpu = smp_processor_id();
29d5e047 61
3bb5d2ee 62 for_each_possible_cpu(cpu) {
ee74d132 63 if (cpu != boot_cpu)
3bb5d2ee 64 idle_init(cpu);
29d5e047 65 }
29d5e047 66}
29d5e047 67#endif