Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Written by: Matthew Dobson, IBM Corporation
0003  *
0004  * Copyright (C) 2002, IBM Corp.
0005  *
0006  * All rights reserved.
0007  *
0008  * This program is free software; you can redistribute it and/or modify
0009  * it under the terms of the GNU General Public License as published by
0010  * the Free Software Foundation; either version 2 of the License, or
0011  * (at your option) any later version.
0012  *
0013  * This program is distributed in the hope that it will be useful, but
0014  * WITHOUT ANY WARRANTY; without even the implied warranty of
0015  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
0016  * NON INFRINGEMENT.  See the GNU General Public License for more
0017  * details.
0018  *
0019  * You should have received a copy of the GNU General Public License
0020  * along with this program; if not, write to the Free Software
0021  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0022  *
0023  * Send feedback to <colpatch@us.ibm.com>
0024  */
0025 #ifndef _ASM_X86_TOPOLOGY_H
0026 #define _ASM_X86_TOPOLOGY_H
0027 
0028 /*
0029  * to preserve the visibility of NUMA_NO_NODE definition,
0030  * moved to there from here.  May be used independent of
0031  * CONFIG_NUMA.
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 /* Mappings between logical cpu number and node number */
0042 DECLARE_EARLY_PER_CPU(int, x86_cpu_to_node_map);
0043 
0044 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
0045 /*
0046  * override generic percpu implementation of cpu_to_node
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   /* !CONFIG_DEBUG_PER_CPU_MAPS */
0054 
0055 /* Same function but used if called before per_cpu areas are setup */
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 /* !CONFIG_DEBUG_PER_CPU_MAPS */
0062 
0063 /* Mappings between node number and cpus on that node. */
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 /* Returns a pointer to the cpumask of CPUs on Node 'node'. */
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 /* !CONFIG_NUMA */
0084 
0085 static inline int numa_node_id(void)
0086 {
0087     return 0;
0088 }
0089 /*
0090  * indicate override:
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 /* Interface to set priority of a cpu */
0177 void sched_set_itmt_core_prio(int prio, int core_cpu);
0178 
0179 /* Interface to notify scheduler that system supports ITMT */
0180 int sched_set_itmt_support(void);
0181 
0182 /* Interface to notify scheduler that system revokes ITMT support */
0183 void sched_clear_itmt_support(void);
0184 
0185 #else /* CONFIG_SCHED_MC_PRIO */
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 /* CONFIG_SCHED_MC_PRIO */
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 /* _ASM_X86_TOPOLOGY_H */