smp.h 4.7 KB

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