smp.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. extern void cpu_idle(void);
  13. typedef void (*smp_call_func_t)(void *info);
  14. struct call_single_data {
  15. struct list_head list;
  16. smp_call_func_t func;
  17. void *info;
  18. u16 flags;
  19. u16 priv;
  20. };
  21. /* total number of cpus in this system (may exceed NR_CPUS) */
  22. extern unsigned int total_cpus;
  23. int smp_call_function_single(int cpuid, smp_call_func_t func, void *info,
  24. int wait);
  25. #ifdef CONFIG_SMP
  26. #include <linux/preempt.h>
  27. #include <linux/kernel.h>
  28. #include <linux/compiler.h>
  29. #include <linux/thread_info.h>
  30. #include <asm/smp.h>
  31. /*
  32. * main cross-CPU interfaces, handles INIT, TLB flush, STOP, etc.
  33. * (defined in asm header):
  34. */
  35. /*
  36. * stops all CPUs but the current one:
  37. */
  38. extern void smp_send_stop(void);
  39. /*
  40. * sends a 'reschedule' event to another CPU:
  41. */
  42. extern void smp_send_reschedule(int cpu);
  43. /*
  44. * Prepare machine for booting other CPUs.
  45. */
  46. extern void smp_prepare_cpus(unsigned int max_cpus);
  47. /*
  48. * Bring a CPU up
  49. */
  50. extern int __cpu_up(unsigned int cpunum, struct task_struct *tidle);
  51. /*
  52. * Final polishing of CPUs
  53. */
  54. extern void smp_cpus_done(unsigned int max_cpus);
  55. /*
  56. * Call a function on all other processors
  57. */
  58. int smp_call_function(smp_call_func_t func, void *info, int wait);
  59. void smp_call_function_many(const struct cpumask *mask,
  60. smp_call_func_t func, void *info, bool wait);
  61. void __smp_call_function_single(int cpuid, struct call_single_data *data,
  62. int wait);
  63. int smp_call_function_any(const struct cpumask *mask,
  64. smp_call_func_t func, void *info, int wait);
  65. void kick_all_cpus_sync(void);
  66. /*
  67. * Generic and arch helpers
  68. */
  69. #ifdef CONFIG_USE_GENERIC_SMP_HELPERS
  70. void __init call_function_init(void);
  71. void generic_smp_call_function_single_interrupt(void);
  72. void generic_smp_call_function_interrupt(void);
  73. void ipi_call_lock(void);
  74. void ipi_call_unlock(void);
  75. void ipi_call_lock_irq(void);
  76. void ipi_call_unlock_irq(void);
  77. #else
  78. static inline void call_function_init(void) { }
  79. #endif
  80. /*
  81. * Call a function on all processors
  82. */
  83. int on_each_cpu(smp_call_func_t func, void *info, int wait);
  84. /*
  85. * Call a function on processors specified by mask, which might include
  86. * the local one.
  87. */
  88. void on_each_cpu_mask(const struct cpumask *mask, smp_call_func_t func,
  89. void *info, bool wait);
  90. /*
  91. * Call a function on each processor for which the supplied function
  92. * cond_func returns a positive value. This may include the local
  93. * processor.
  94. */
  95. void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
  96. smp_call_func_t func, void *info, bool wait,
  97. gfp_t gfp_flags);
  98. /*
  99. * Mark the boot cpu "online" so that it can call console drivers in
  100. * printk() and can access its per-cpu storage.
  101. */
  102. void smp_prepare_boot_cpu(void);
  103. extern unsigned int setup_max_cpus;
  104. extern void __init setup_nr_cpu_ids(void);
  105. extern void __init smp_init(void);
  106. #else /* !SMP */
  107. static inline void smp_send_stop(void) { }
  108. /*
  109. * These macros fold the SMP functionality into a single CPU system
  110. */
  111. #define raw_smp_processor_id() 0
  112. static inline int up_smp_call_function(smp_call_func_t func, void *info)
  113. {
  114. return 0;
  115. }
  116. #define smp_call_function(func, info, wait) \
  117. (up_smp_call_function(func, info))
  118. #define on_each_cpu(func,info,wait) \
  119. ({ \
  120. local_irq_disable(); \
  121. func(info); \
  122. local_irq_enable(); \
  123. 0; \
  124. })
  125. /*
  126. * Note we still need to test the mask even for UP
  127. * because we actually can get an empty mask from
  128. * code that on SMP might call us without the local
  129. * CPU in the mask.
  130. */
  131. #define on_each_cpu_mask(mask, func, info, wait) \
  132. do { \
  133. if (cpumask_test_cpu(0, (mask))) { \
  134. local_irq_disable(); \
  135. (func)(info); \
  136. local_irq_enable(); \
  137. } \
  138. } while (0)
  139. /*
  140. * Preemption is disabled here to make sure the cond_func is called under the
  141. * same condtions in UP and SMP.
  142. */
  143. #define on_each_cpu_cond(cond_func, func, info, wait, gfp_flags)\
  144. do { \
  145. void *__info = (info); \
  146. preempt_disable(); \
  147. if ((cond_func)(0, __info)) { \
  148. local_irq_disable(); \
  149. (func)(__info); \
  150. local_irq_enable(); \
  151. } \
  152. preempt_enable(); \
  153. } while (0)
  154. static inline void smp_send_reschedule(int cpu) { }
  155. #define num_booting_cpus() 1
  156. #define smp_prepare_boot_cpu() do {} while (0)
  157. #define smp_call_function_many(mask, func, info, wait) \
  158. (up_smp_call_function(func, info))
  159. static inline void call_function_init(void) { }
  160. static inline int
  161. smp_call_function_any(const struct cpumask *mask, smp_call_func_t func,
  162. void *info, int wait)
  163. {
  164. return smp_call_function_single(0, func, info, wait);
  165. }
  166. static inline void kick_all_cpus_sync(void) { }
  167. #endif /* !SMP */
  168. /*
  169. * smp_processor_id(): get the current CPU ID.
  170. *
  171. * if DEBUG_PREEMPT is enabled then we check whether it is
  172. * used in a preemption-safe way. (smp_processor_id() is safe
  173. * if it's used in a preemption-off critical section, or in
  174. * a thread that is bound to the current CPU.)
  175. *
  176. * NOTE: raw_smp_processor_id() is for internal use only
  177. * (smp_processor_id() is the preferred variant), but in rare
  178. * instances it might also be used to turn off false positives
  179. * (i.e. smp_processor_id() use that the debugging code reports but
  180. * which use for some reason is legal). Don't use this to hack around
  181. * the warning message, as your code might not work under PREEMPT.
  182. */
  183. #ifdef CONFIG_DEBUG_PREEMPT
  184. extern unsigned int debug_smp_processor_id(void);
  185. # define smp_processor_id() debug_smp_processor_id()
  186. #else
  187. # define smp_processor_id() raw_smp_processor_id()
  188. #endif
  189. #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
  190. #define put_cpu() preempt_enable()
  191. /*
  192. * Callback to arch code if there's nosmp or maxcpus=0 on the
  193. * boot command line:
  194. */
  195. extern void arch_disable_smp_support(void);
  196. void smp_setup_processor_id(void);
  197. #endif /* __LINUX_SMP_H */