smp.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #ifndef _ASM_X86_SMP_H
  2. #define _ASM_X86_SMP_H
  3. #ifndef __ASSEMBLY__
  4. #include <linux/cpumask.h>
  5. #include <linux/init.h>
  6. #include <asm/percpu.h>
  7. /*
  8. * We need the APIC definitions automatically as part of 'smp.h'
  9. */
  10. #ifdef CONFIG_X86_LOCAL_APIC
  11. # include <asm/mpspec.h>
  12. # include <asm/apic.h>
  13. # ifdef CONFIG_X86_IO_APIC
  14. # include <asm/io_apic.h>
  15. # endif
  16. #endif
  17. #include <asm/thread_info.h>
  18. #include <asm/cpumask.h>
  19. #include <asm/cpufeature.h>
  20. extern int smp_num_siblings;
  21. extern unsigned int num_processors;
  22. static inline bool cpu_has_ht_siblings(void)
  23. {
  24. bool has_siblings = false;
  25. #ifdef CONFIG_SMP
  26. has_siblings = cpu_has_ht && smp_num_siblings > 1;
  27. #endif
  28. return has_siblings;
  29. }
  30. DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);
  31. DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
  32. /* cpus sharing the last level cache: */
  33. DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
  34. DECLARE_PER_CPU(u16, cpu_llc_id);
  35. DECLARE_PER_CPU(int, cpu_number);
  36. static inline struct cpumask *cpu_sibling_mask(int cpu)
  37. {
  38. return per_cpu(cpu_sibling_map, cpu);
  39. }
  40. static inline struct cpumask *cpu_core_mask(int cpu)
  41. {
  42. return per_cpu(cpu_core_map, cpu);
  43. }
  44. static inline struct cpumask *cpu_llc_shared_mask(int cpu)
  45. {
  46. return per_cpu(cpu_llc_shared_map, cpu);
  47. }
  48. DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_apicid);
  49. DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
  50. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
  51. DECLARE_EARLY_PER_CPU(int, x86_cpu_to_logical_apicid);
  52. #endif
  53. /* Static state in head.S used to set up a CPU */
  54. extern unsigned long stack_start; /* Initial stack pointer address */
  55. struct task_struct;
  56. struct smp_ops {
  57. void (*smp_prepare_boot_cpu)(void);
  58. void (*smp_prepare_cpus)(unsigned max_cpus);
  59. void (*smp_cpus_done)(unsigned max_cpus);
  60. void (*stop_other_cpus)(int wait);
  61. void (*smp_send_reschedule)(int cpu);
  62. int (*cpu_up)(unsigned cpu, struct task_struct *tidle);
  63. int (*cpu_disable)(void);
  64. void (*cpu_die)(unsigned int cpu);
  65. void (*play_dead)(void);
  66. void (*send_call_func_ipi)(const struct cpumask *mask);
  67. void (*send_call_func_single_ipi)(int cpu);
  68. };
  69. /* Globals due to paravirt */
  70. extern void set_cpu_sibling_map(int cpu);
  71. #ifdef CONFIG_SMP
  72. #ifndef CONFIG_PARAVIRT
  73. #define startup_ipi_hook(phys_apicid, start_eip, start_esp) do { } while (0)
  74. #endif
  75. extern struct smp_ops smp_ops;
  76. static inline void smp_send_stop(void)
  77. {
  78. smp_ops.stop_other_cpus(0);
  79. }
  80. static inline void stop_other_cpus(void)
  81. {
  82. smp_ops.stop_other_cpus(1);
  83. }
  84. static inline void smp_prepare_boot_cpu(void)
  85. {
  86. smp_ops.smp_prepare_boot_cpu();
  87. }
  88. static inline void smp_prepare_cpus(unsigned int max_cpus)
  89. {
  90. smp_ops.smp_prepare_cpus(max_cpus);
  91. }
  92. static inline void smp_cpus_done(unsigned int max_cpus)
  93. {
  94. smp_ops.smp_cpus_done(max_cpus);
  95. }
  96. static inline int __cpu_up(unsigned int cpu, struct task_struct *tidle)
  97. {
  98. return smp_ops.cpu_up(cpu, tidle);
  99. }
  100. static inline int __cpu_disable(void)
  101. {
  102. return smp_ops.cpu_disable();
  103. }
  104. static inline void __cpu_die(unsigned int cpu)
  105. {
  106. smp_ops.cpu_die(cpu);
  107. }
  108. static inline void play_dead(void)
  109. {
  110. smp_ops.play_dead();
  111. }
  112. static inline void smp_send_reschedule(int cpu)
  113. {
  114. smp_ops.smp_send_reschedule(cpu);
  115. }
  116. static inline void arch_send_call_function_single_ipi(int cpu)
  117. {
  118. smp_ops.send_call_func_single_ipi(cpu);
  119. }
  120. static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  121. {
  122. smp_ops.send_call_func_ipi(mask);
  123. }
  124. void cpu_disable_common(void);
  125. void native_smp_prepare_boot_cpu(void);
  126. void native_smp_prepare_cpus(unsigned int max_cpus);
  127. void native_smp_cpus_done(unsigned int max_cpus);
  128. int native_cpu_up(unsigned int cpunum, struct task_struct *tidle);
  129. int native_cpu_disable(void);
  130. void native_cpu_die(unsigned int cpu);
  131. void native_play_dead(void);
  132. void play_dead_common(void);
  133. void wbinvd_on_cpu(int cpu);
  134. int wbinvd_on_all_cpus(void);
  135. void native_send_call_func_ipi(const struct cpumask *mask);
  136. void native_send_call_func_single_ipi(int cpu);
  137. void x86_idle_thread_init(unsigned int cpu, struct task_struct *idle);
  138. void smp_store_cpu_info(int id);
  139. #define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu)
  140. /* We don't mark CPUs online until __cpu_up(), so we need another measure */
  141. static inline int num_booting_cpus(void)
  142. {
  143. return cpumask_weight(cpu_callout_mask);
  144. }
  145. #else /* !CONFIG_SMP */
  146. #define wbinvd_on_cpu(cpu) wbinvd()
  147. static inline int wbinvd_on_all_cpus(void)
  148. {
  149. wbinvd();
  150. return 0;
  151. }
  152. #endif /* CONFIG_SMP */
  153. extern unsigned disabled_cpus __cpuinitdata;
  154. #ifdef CONFIG_X86_32_SMP
  155. /*
  156. * This function is needed by all SMP systems. It must _always_ be valid
  157. * from the initial startup. We map APIC_BASE very early in page_setup(),
  158. * so this is correct in the x86 case.
  159. */
  160. #define raw_smp_processor_id() (this_cpu_read(cpu_number))
  161. extern int safe_smp_processor_id(void);
  162. #elif defined(CONFIG_X86_64_SMP)
  163. #define raw_smp_processor_id() (this_cpu_read(cpu_number))
  164. #define stack_smp_processor_id() \
  165. ({ \
  166. struct thread_info *ti; \
  167. __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
  168. ti->cpu; \
  169. })
  170. #define safe_smp_processor_id() smp_processor_id()
  171. #endif
  172. #ifdef CONFIG_X86_LOCAL_APIC
  173. #ifndef CONFIG_X86_64
  174. static inline int logical_smp_processor_id(void)
  175. {
  176. /* we don't want to mark this access volatile - bad code generation */
  177. return GET_APIC_LOGICAL_ID(apic_read(APIC_LDR));
  178. }
  179. #endif
  180. extern int hard_smp_processor_id(void);
  181. #else /* CONFIG_X86_LOCAL_APIC */
  182. # ifndef CONFIG_SMP
  183. # define hard_smp_processor_id() 0
  184. # endif
  185. #endif /* CONFIG_X86_LOCAL_APIC */
  186. #ifdef CONFIG_DEBUG_NMI_SELFTEST
  187. extern void nmi_selftest(void);
  188. #else
  189. #define nmi_selftest() do { } while (0)
  190. #endif
  191. #endif /* __ASSEMBLY__ */
  192. #endif /* _ASM_X86_SMP_H */