smp.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #ifndef __LINUX_SMP_H
  2. #define __LINUX_SMP_H
  3. /*
  4. * Generic SMP support
  5. * Alan Cox. <alan@redhat.com>
  6. */
  7. #include <linux/errno.h>
  8. #include <linux/types.h>
  9. #include <linux/list.h>
  10. #include <linux/cpumask.h>
  11. #include <linux/init.h>
  12. #include <linux/llist.h>
  13. typedef void (*smp_call_func_t)(void *info);
  14. struct call_single_data {
  15. struct llist_node llist;
  16. smp_call_func_t func;
  17. void *info;
  18. unsigned int flags;
  19. };
  20. /* total number of cpus in this system (may exceed NR_CPUS) */
  21. extern unsigned int total_cpus;
  22. int smp_call_function_single(int cpuid, smp_call_func_t func, void *info,
  23. int wait);
  24. /*
  25. * Call a function on all processors
  26. */
  27. int on_each_cpu(smp_call_func_t func, void *info, int wait);
  28. /*
  29. * Call a function on processors specified by mask, which might include
  30. * the local one.
  31. */
  32. void on_each_cpu_mask(const struct cpumask *mask, smp_call_func_t func,
  33. void *info, bool wait);
  34. /*
  35. * Call a function on each processor for which the supplied function
  36. * cond_func returns a positive value. This may include the local
  37. * processor.
  38. */
  39. void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
  40. smp_call_func_t func, void *info, bool wait,
  41. gfp_t gfp_flags);
  42. int smp_call_function_single_async(int cpu, struct call_single_data *csd);
  43. #ifdef CONFIG_SMP
  44. #include <linux/preempt.h>
  45. #include <linux/kernel.h>
  46. #include <linux/compiler.h>
  47. #include <linux/thread_info.h>
  48. #include <asm/smp.h>
  49. /*
  50. * main cross-CPU interfaces, handles INIT, TLB flush, STOP, etc.
  51. * (defined in asm header):
  52. */
  53. /*
  54. * stops all CPUs but the current one:
  55. */
  56. extern void smp_send_stop(void);
  57. /*
  58. * sends a 'reschedule' event to another CPU:
  59. */
  60. extern void smp_send_reschedule(int cpu);
  61. /*
  62. * Prepare machine for booting other CPUs.
  63. */
  64. extern void smp_prepare_cpus(unsigned int max_cpus);
  65. /*
  66. * Bring a CPU up
  67. */
  68. extern int __cpu_up(unsigned int cpunum, struct task_struct *tidle);
  69. /*
  70. * Final polishing of CPUs
  71. */
  72. extern void smp_cpus_done(unsigned int max_cpus);
  73. /*
  74. * Call a function on all other processors
  75. */
  76. int smp_call_function(smp_call_func_t func, void *info, int wait);
  77. void smp_call_function_many(const struct cpumask *mask,
  78. smp_call_func_t func, void *info, bool wait);
  79. int smp_call_function_any(const struct cpumask *mask,
  80. smp_call_func_t func, void *info, int wait);
  81. void kick_all_cpus_sync(void);
  82. void wake_up_all_idle_cpus(void);
  83. /*
  84. * Generic and arch helpers
  85. */
  86. void __init call_function_init(void);
  87. void generic_smp_call_function_single_interrupt(void);
  88. #define generic_smp_call_function_interrupt \
  89. generic_smp_call_function_single_interrupt
  90. /*
  91. * Mark the boot cpu "online" so that it can call console drivers in
  92. * printk() and can access its per-cpu storage.
  93. */
  94. void smp_prepare_boot_cpu(void);
  95. extern unsigned int setup_max_cpus;
  96. extern void __init setup_nr_cpu_ids(void);
  97. extern void __init smp_init(void);
  98. #else /* !SMP */
  99. static inline void smp_send_stop(void) { }
  100. /*
  101. * These macros fold the SMP functionality into a single CPU system
  102. */
  103. #define raw_smp_processor_id() 0
  104. static inline int up_smp_call_function(smp_call_func_t func, void *info)
  105. {
  106. return 0;
  107. }
  108. #define smp_call_function(func, info, wait) \
  109. (up_smp_call_function(func, info))
  110. static inline void smp_send_reschedule(int cpu) { }
  111. #define smp_prepare_boot_cpu() do {} while (0)
  112. #define smp_call_function_many(mask, func, info, wait) \
  113. (up_smp_call_function(func, info))
  114. static inline void call_function_init(void) { }
  115. static inline int
  116. smp_call_function_any(const struct cpumask *mask, smp_call_func_t func,
  117. void *info, int wait)
  118. {
  119. return smp_call_function_single(0, func, info, wait);
  120. }
  121. static inline void kick_all_cpus_sync(void) { }
  122. static inline void wake_up_all_idle_cpus(void) { }
  123. #ifdef CONFIG_UP_LATE_INIT
  124. extern void __init up_late_init(void);
  125. static inline void smp_init(void) { up_late_init(); }
  126. #else
  127. static inline void smp_init(void) { }
  128. #endif
  129. #endif /* !SMP */
  130. /*
  131. * smp_processor_id(): get the current CPU ID.
  132. *
  133. * if DEBUG_PREEMPT is enabled then we check whether it is
  134. * used in a preemption-safe way. (smp_processor_id() is safe
  135. * if it's used in a preemption-off critical section, or in
  136. * a thread that is bound to the current CPU.)
  137. *
  138. * NOTE: raw_smp_processor_id() is for internal use only
  139. * (smp_processor_id() is the preferred variant), but in rare
  140. * instances it might also be used to turn off false positives
  141. * (i.e. smp_processor_id() use that the debugging code reports but
  142. * which use for some reason is legal). Don't use this to hack around
  143. * the warning message, as your code might not work under PREEMPT.
  144. */
  145. #ifdef CONFIG_DEBUG_PREEMPT
  146. extern unsigned int debug_smp_processor_id(void);
  147. # define smp_processor_id() debug_smp_processor_id()
  148. #else
  149. # define smp_processor_id() raw_smp_processor_id()
  150. #endif
  151. #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
  152. #define put_cpu() preempt_enable()
  153. /*
  154. * Callback to arch code if there's nosmp or maxcpus=0 on the
  155. * boot command line:
  156. */
  157. extern void arch_disable_smp_support(void);
  158. extern void arch_enable_nonboot_cpus_begin(void);
  159. extern void arch_enable_nonboot_cpus_end(void);
  160. void smp_setup_processor_id(void);
  161. int smp_call_on_cpu(unsigned int cpu, int (*func)(void *), void *par,
  162. bool phys);
  163. /* SMP core functions */
  164. int smpcfd_prepare_cpu(unsigned int cpu);
  165. int smpcfd_dead_cpu(unsigned int cpu);
  166. int smpcfd_dying_cpu(unsigned int cpu);
  167. #endif /* __LINUX_SMP_H */