smpboot.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Common SMP CPU bringup/teardown functions
  3. */
  4. #include <linux/err.h>
  5. #include <linux/smp.h>
  6. #include <linux/init.h>
  7. #include <linux/sched.h>
  8. #include <linux/percpu.h>
  9. #include "smpboot.h"
  10. #ifdef CONFIG_GENERIC_SMP_IDLE_THREAD
  11. /*
  12. * For the hotplug case we keep the task structs around and reuse
  13. * them.
  14. */
  15. static DEFINE_PER_CPU(struct task_struct *, idle_threads);
  16. struct task_struct * __cpuinit idle_thread_get(unsigned int cpu)
  17. {
  18. struct task_struct *tsk = per_cpu(idle_threads, cpu);
  19. if (!tsk)
  20. return ERR_PTR(-ENOMEM);
  21. init_idle(tsk, cpu);
  22. return tsk;
  23. }
  24. void __init idle_thread_set_boot_cpu(void)
  25. {
  26. per_cpu(idle_threads, smp_processor_id()) = current;
  27. }
  28. /**
  29. * idle_init - Initialize the idle thread for a cpu
  30. * @cpu: The cpu for which the idle thread should be initialized
  31. *
  32. * Creates the thread if it does not exist.
  33. */
  34. static inline void idle_init(unsigned int cpu)
  35. {
  36. struct task_struct *tsk = per_cpu(idle_threads, cpu);
  37. if (!tsk) {
  38. tsk = fork_idle(cpu);
  39. if (IS_ERR(tsk))
  40. pr_err("SMP: fork_idle() failed for CPU %u\n", cpu);
  41. else
  42. per_cpu(idle_threads, cpu) = tsk;
  43. }
  44. }
  45. /**
  46. * idle_threads_init - Initialize idle threads for all cpus
  47. */
  48. void __init idle_threads_init(void)
  49. {
  50. unsigned int cpu, boot_cpu;
  51. boot_cpu = smp_processor_id();
  52. for_each_possible_cpu(cpu) {
  53. if (cpu != boot_cpu)
  54. idle_init(cpu);
  55. }
  56. }
  57. #endif