smp.h 4.8 KB

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