smp.h 5.5 KB

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