smp.h 5.0 KB

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