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
0026
0027 #ifndef _LINUX_TOPOLOGY_H
0028 #define _LINUX_TOPOLOGY_H
0029
0030 #include <linux/arch_topology.h>
0031 #include <linux/cpumask.h>
0032 #include <linux/bitops.h>
0033 #include <linux/mmzone.h>
0034 #include <linux/smp.h>
0035 #include <linux/percpu.h>
0036 #include <asm/topology.h>
0037
0038 #ifndef nr_cpus_node
0039 #define nr_cpus_node(node) cpumask_weight(cpumask_of_node(node))
0040 #endif
0041
0042 #define for_each_node_with_cpus(node) \
0043 for_each_online_node(node) \
0044 if (nr_cpus_node(node))
0045
0046 int arch_update_cpu_topology(void);
0047
0048
0049 #define LOCAL_DISTANCE 10
0050 #define REMOTE_DISTANCE 20
0051 #define DISTANCE_BITS 8
0052 #ifndef node_distance
0053 #define node_distance(from,to) ((from) == (to) ? LOCAL_DISTANCE : REMOTE_DISTANCE)
0054 #endif
0055 #ifndef RECLAIM_DISTANCE
0056
0057
0058
0059
0060
0061
0062 #define RECLAIM_DISTANCE 30
0063 #endif
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 extern int __read_mostly node_reclaim_distance;
0077
0078 #ifndef PENALTY_FOR_NODE_WITH_CPUS
0079 #define PENALTY_FOR_NODE_WITH_CPUS (1)
0080 #endif
0081
0082 #ifdef CONFIG_USE_PERCPU_NUMA_NODE_ID
0083 DECLARE_PER_CPU(int, numa_node);
0084
0085 #ifndef numa_node_id
0086
0087 static inline int numa_node_id(void)
0088 {
0089 return raw_cpu_read(numa_node);
0090 }
0091 #endif
0092
0093 #ifndef cpu_to_node
0094 static inline int cpu_to_node(int cpu)
0095 {
0096 return per_cpu(numa_node, cpu);
0097 }
0098 #endif
0099
0100 #ifndef set_numa_node
0101 static inline void set_numa_node(int node)
0102 {
0103 this_cpu_write(numa_node, node);
0104 }
0105 #endif
0106
0107 #ifndef set_cpu_numa_node
0108 static inline void set_cpu_numa_node(int cpu, int node)
0109 {
0110 per_cpu(numa_node, cpu) = node;
0111 }
0112 #endif
0113
0114 #else
0115
0116
0117 #ifndef numa_node_id
0118 static inline int numa_node_id(void)
0119 {
0120 return cpu_to_node(raw_smp_processor_id());
0121 }
0122 #endif
0123
0124 #endif
0125
0126 #ifdef CONFIG_HAVE_MEMORYLESS_NODES
0127
0128
0129
0130
0131
0132
0133 DECLARE_PER_CPU(int, _numa_mem_);
0134
0135 #ifndef set_numa_mem
0136 static inline void set_numa_mem(int node)
0137 {
0138 this_cpu_write(_numa_mem_, node);
0139 }
0140 #endif
0141
0142 #ifndef numa_mem_id
0143
0144 static inline int numa_mem_id(void)
0145 {
0146 return raw_cpu_read(_numa_mem_);
0147 }
0148 #endif
0149
0150 #ifndef cpu_to_mem
0151 static inline int cpu_to_mem(int cpu)
0152 {
0153 return per_cpu(_numa_mem_, cpu);
0154 }
0155 #endif
0156
0157 #ifndef set_cpu_numa_mem
0158 static inline void set_cpu_numa_mem(int cpu, int node)
0159 {
0160 per_cpu(_numa_mem_, cpu) = node;
0161 }
0162 #endif
0163
0164 #else
0165
0166 #ifndef numa_mem_id
0167
0168 static inline int numa_mem_id(void)
0169 {
0170 return numa_node_id();
0171 }
0172 #endif
0173
0174 #ifndef cpu_to_mem
0175 static inline int cpu_to_mem(int cpu)
0176 {
0177 return cpu_to_node(cpu);
0178 }
0179 #endif
0180
0181 #endif
0182
0183 #if defined(topology_die_id) && defined(topology_die_cpumask)
0184 #define TOPOLOGY_DIE_SYSFS
0185 #endif
0186 #if defined(topology_cluster_id) && defined(topology_cluster_cpumask)
0187 #define TOPOLOGY_CLUSTER_SYSFS
0188 #endif
0189 #if defined(topology_book_id) && defined(topology_book_cpumask)
0190 #define TOPOLOGY_BOOK_SYSFS
0191 #endif
0192 #if defined(topology_drawer_id) && defined(topology_drawer_cpumask)
0193 #define TOPOLOGY_DRAWER_SYSFS
0194 #endif
0195
0196 #ifndef topology_physical_package_id
0197 #define topology_physical_package_id(cpu) ((void)(cpu), -1)
0198 #endif
0199 #ifndef topology_die_id
0200 #define topology_die_id(cpu) ((void)(cpu), -1)
0201 #endif
0202 #ifndef topology_cluster_id
0203 #define topology_cluster_id(cpu) ((void)(cpu), -1)
0204 #endif
0205 #ifndef topology_core_id
0206 #define topology_core_id(cpu) ((void)(cpu), 0)
0207 #endif
0208 #ifndef topology_book_id
0209 #define topology_book_id(cpu) ((void)(cpu), -1)
0210 #endif
0211 #ifndef topology_drawer_id
0212 #define topology_drawer_id(cpu) ((void)(cpu), -1)
0213 #endif
0214 #ifndef topology_ppin
0215 #define topology_ppin(cpu) ((void)(cpu), 0ull)
0216 #endif
0217 #ifndef topology_sibling_cpumask
0218 #define topology_sibling_cpumask(cpu) cpumask_of(cpu)
0219 #endif
0220 #ifndef topology_core_cpumask
0221 #define topology_core_cpumask(cpu) cpumask_of(cpu)
0222 #endif
0223 #ifndef topology_cluster_cpumask
0224 #define topology_cluster_cpumask(cpu) cpumask_of(cpu)
0225 #endif
0226 #ifndef topology_die_cpumask
0227 #define topology_die_cpumask(cpu) cpumask_of(cpu)
0228 #endif
0229 #ifndef topology_book_cpumask
0230 #define topology_book_cpumask(cpu) cpumask_of(cpu)
0231 #endif
0232 #ifndef topology_drawer_cpumask
0233 #define topology_drawer_cpumask(cpu) cpumask_of(cpu)
0234 #endif
0235
0236 #if defined(CONFIG_SCHED_SMT) && !defined(cpu_smt_mask)
0237 static inline const struct cpumask *cpu_smt_mask(int cpu)
0238 {
0239 return topology_sibling_cpumask(cpu);
0240 }
0241 #endif
0242
0243 static inline const struct cpumask *cpu_cpu_mask(int cpu)
0244 {
0245 return cpumask_of_node(cpu_to_node(cpu));
0246 }
0247
0248
0249 #endif