smp.h 4.4 KB

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