0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #ifndef _ASM_X86_TOPOLOGY_H
0026 #define _ASM_X86_TOPOLOGY_H
0027
0028
0029
0030
0031
0032
0033 #include <linux/numa.h>
0034
0035 #ifdef CONFIG_NUMA
0036 #include <linux/cpumask.h>
0037
0038 #include <asm/mpspec.h>
0039 #include <asm/percpu.h>
0040
0041
0042 DECLARE_EARLY_PER_CPU(int, x86_cpu_to_node_map);
0043
0044 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
0045
0046
0047
0048 extern int __cpu_to_node(int cpu);
0049 #define cpu_to_node __cpu_to_node
0050
0051 extern int early_cpu_to_node(int cpu);
0052
0053 #else
0054
0055
0056 static inline int early_cpu_to_node(int cpu)
0057 {
0058 return early_per_cpu(x86_cpu_to_node_map, cpu);
0059 }
0060
0061 #endif
0062
0063
0064 extern cpumask_var_t node_to_cpumask_map[MAX_NUMNODES];
0065
0066 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
0067 extern const struct cpumask *cpumask_of_node(int node);
0068 #else
0069
0070 static inline const struct cpumask *cpumask_of_node(int node)
0071 {
0072 return node_to_cpumask_map[node];
0073 }
0074 #endif
0075
0076 extern void setup_node_to_cpumask_map(void);
0077
0078 #define pcibus_to_node(bus) __pcibus_to_node(bus)
0079
0080 extern int __node_distance(int, int);
0081 #define node_distance(a, b) __node_distance(a, b)
0082
0083 #else
0084
0085 static inline int numa_node_id(void)
0086 {
0087 return 0;
0088 }
0089
0090
0091
0092 #define numa_node_id numa_node_id
0093
0094 static inline int early_cpu_to_node(int cpu)
0095 {
0096 return 0;
0097 }
0098
0099 static inline void setup_node_to_cpumask_map(void) { }
0100
0101 #endif
0102
0103 #include <asm-generic/topology.h>
0104
0105 extern const struct cpumask *cpu_coregroup_mask(int cpu);
0106 extern const struct cpumask *cpu_clustergroup_mask(int cpu);
0107
0108 #define topology_logical_package_id(cpu) (cpu_data(cpu).logical_proc_id)
0109 #define topology_physical_package_id(cpu) (cpu_data(cpu).phys_proc_id)
0110 #define topology_logical_die_id(cpu) (cpu_data(cpu).logical_die_id)
0111 #define topology_die_id(cpu) (cpu_data(cpu).cpu_die_id)
0112 #define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id)
0113 #define topology_ppin(cpu) (cpu_data(cpu).ppin)
0114
0115 extern unsigned int __max_die_per_package;
0116
0117 #ifdef CONFIG_SMP
0118 #define topology_cluster_id(cpu) (per_cpu(cpu_l2c_id, cpu))
0119 #define topology_die_cpumask(cpu) (per_cpu(cpu_die_map, cpu))
0120 #define topology_cluster_cpumask(cpu) (cpu_clustergroup_mask(cpu))
0121 #define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu))
0122 #define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu))
0123
0124 extern unsigned int __max_logical_packages;
0125 #define topology_max_packages() (__max_logical_packages)
0126
0127 static inline int topology_max_die_per_package(void)
0128 {
0129 return __max_die_per_package;
0130 }
0131
0132 extern int __max_smt_threads;
0133
0134 static inline int topology_max_smt_threads(void)
0135 {
0136 return __max_smt_threads;
0137 }
0138
0139 int topology_update_package_map(unsigned int apicid, unsigned int cpu);
0140 int topology_update_die_map(unsigned int dieid, unsigned int cpu);
0141 int topology_phys_to_logical_pkg(unsigned int pkg);
0142 int topology_phys_to_logical_die(unsigned int die, unsigned int cpu);
0143 bool topology_is_primary_thread(unsigned int cpu);
0144 bool topology_smt_supported(void);
0145 #else
0146 #define topology_max_packages() (1)
0147 static inline int
0148 topology_update_package_map(unsigned int apicid, unsigned int cpu) { return 0; }
0149 static inline int
0150 topology_update_die_map(unsigned int dieid, unsigned int cpu) { return 0; }
0151 static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
0152 static inline int topology_phys_to_logical_die(unsigned int die,
0153 unsigned int cpu) { return 0; }
0154 static inline int topology_max_die_per_package(void) { return 1; }
0155 static inline int topology_max_smt_threads(void) { return 1; }
0156 static inline bool topology_is_primary_thread(unsigned int cpu) { return true; }
0157 static inline bool topology_smt_supported(void) { return false; }
0158 #endif
0159
0160 static inline void arch_fix_phys_package_id(int num, u32 slot)
0161 {
0162 }
0163
0164 struct pci_bus;
0165 int x86_pci_root_bus_node(int bus);
0166 void x86_pci_root_bus_resources(int bus, struct list_head *resources);
0167
0168 extern bool x86_topology_update;
0169
0170 #ifdef CONFIG_SCHED_MC_PRIO
0171 #include <asm/percpu.h>
0172
0173 DECLARE_PER_CPU_READ_MOSTLY(int, sched_core_priority);
0174 extern unsigned int __read_mostly sysctl_sched_itmt_enabled;
0175
0176
0177 void sched_set_itmt_core_prio(int prio, int core_cpu);
0178
0179
0180 int sched_set_itmt_support(void);
0181
0182
0183 void sched_clear_itmt_support(void);
0184
0185 #else
0186
0187 #define sysctl_sched_itmt_enabled 0
0188 static inline void sched_set_itmt_core_prio(int prio, int core_cpu)
0189 {
0190 }
0191 static inline int sched_set_itmt_support(void)
0192 {
0193 return 0;
0194 }
0195 static inline void sched_clear_itmt_support(void)
0196 {
0197 }
0198 #endif
0199
0200 #if defined(CONFIG_SMP) && defined(CONFIG_X86_64)
0201 #include <asm/cpufeature.h>
0202
0203 DECLARE_STATIC_KEY_FALSE(arch_scale_freq_key);
0204
0205 #define arch_scale_freq_invariant() static_branch_likely(&arch_scale_freq_key)
0206
0207 DECLARE_PER_CPU(unsigned long, arch_freq_scale);
0208
0209 static inline long arch_scale_freq_capacity(int cpu)
0210 {
0211 return per_cpu(arch_freq_scale, cpu);
0212 }
0213 #define arch_scale_freq_capacity arch_scale_freq_capacity
0214
0215 extern void arch_set_max_freq_ratio(bool turbo_disabled);
0216 extern void freq_invariance_set_perf_ratio(u64 ratio, bool turbo_disabled);
0217 #else
0218 static inline void arch_set_max_freq_ratio(bool turbo_disabled) { }
0219 static inline void freq_invariance_set_perf_ratio(u64 ratio, bool turbo_disabled) { }
0220 #endif
0221
0222 extern void arch_scale_freq_tick(void);
0223 #define arch_scale_freq_tick arch_scale_freq_tick
0224
0225 #ifdef CONFIG_ACPI_CPPC_LIB
0226 void init_freq_invariance_cppc(void);
0227 #define arch_init_invariance_cppc init_freq_invariance_cppc
0228 #endif
0229
0230 #endif