smpboot.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. static inline void idle_init(unsigned int cpu)
  29. {
  30. struct task_struct *tsk = per_cpu(idle_threads, cpu);
  31. if (!tsk) {
  32. tsk = fork_idle(cpu);
  33. if (IS_ERR(tsk))
  34. pr_err("SMP: fork_idle() failed for CPU %u\n", cpu);
  35. else
  36. per_cpu(idle_threads, cpu) = tsk;
  37. }
  38. }
  39. /**
  40. * idle_thread_init - Initialize the idle thread for a cpu
  41. * @cpu: The cpu for which the idle thread should be initialized
  42. *
  43. * Creates the thread if it does not exist.
  44. */
  45. void __init idle_threads_init(void)
  46. {
  47. unsigned int cpu;
  48. for_each_possible_cpu(cpu) {
  49. if (cpu != smp_processor_id())
  50. idle_init(cpu);
  51. }
  52. }
  53. #endif