1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#ifndef _LINUX_TOPOLOGY_H
28#define _LINUX_TOPOLOGY_H
29
30#include <linux/arch_topology.h>
31#include <linux/cpumask.h>
32#include <linux/bitops.h>
33#include <linux/mmzone.h>
34#include <linux/smp.h>
35#include <linux/percpu.h>
36#include <asm/topology.h>
37
38#ifndef nr_cpus_node
39#define nr_cpus_node(node) cpumask_weight(cpumask_of_node(node))
40#endif
41
42#define for_each_node_with_cpus(node) \
43 for_each_online_node(node) \
44 if (nr_cpus_node(node))
45
46int arch_update_cpu_topology(void);
47
48
49#define LOCAL_DISTANCE 10
50#define REMOTE_DISTANCE 20
51#ifndef node_distance
52#define node_distance(from,to) ((from) == (to) ? LOCAL_DISTANCE : REMOTE_DISTANCE)
53#endif
54#ifndef RECLAIM_DISTANCE
55
56
57
58
59
60
61#define RECLAIM_DISTANCE 30
62#endif
63
64
65
66
67
68
69
70
71
72
73
74
75extern int __read_mostly node_reclaim_distance;
76
77#ifndef PENALTY_FOR_NODE_WITH_CPUS
78#define PENALTY_FOR_NODE_WITH_CPUS (1)
79#endif
80
81#ifdef CONFIG_USE_PERCPU_NUMA_NODE_ID
82DECLARE_PER_CPU(int, numa_node);
83
84#ifndef numa_node_id
85
86static inline int numa_node_id(void)
87{
88 return raw_cpu_read(numa_node);
89}
90#endif
91
92#ifndef cpu_to_node
93static inline int cpu_to_node(int cpu)
94{
95 return per_cpu(numa_node, cpu);
96}
97#endif
98
99#ifndef set_numa_node
100static inline void set_numa_node(int node)
101{
102 this_cpu_write(numa_node, node);
103}
104#endif
105
106#ifndef set_cpu_numa_node
107static inline void set_cpu_numa_node(int cpu, int node)
108{
109 per_cpu(numa_node, cpu) = node;
110}
111#endif
112
113#else
114
115
116#ifndef numa_node_id
117static inline int numa_node_id(void)
118{
119 return cpu_to_node(raw_smp_processor_id());
120}
121#endif
122
123#endif
124
125#ifdef CONFIG_HAVE_MEMORYLESS_NODES
126
127
128
129
130
131
132DECLARE_PER_CPU(int, _numa_mem_);
133extern int _node_numa_mem_[MAX_NUMNODES];
134
135#ifndef set_numa_mem
136static inline void set_numa_mem(int node)
137{
138 this_cpu_write(_numa_mem_, node);
139 _node_numa_mem_[numa_node_id()] = node;
140}
141#endif
142
143#ifndef node_to_mem_node
144static inline int node_to_mem_node(int node)
145{
146 return _node_numa_mem_[node];
147}
148#endif
149
150#ifndef numa_mem_id
151
152static inline int numa_mem_id(void)
153{
154 return raw_cpu_read(_numa_mem_);
155}
156#endif
157
158#ifndef cpu_to_mem
159static inline int cpu_to_mem(int cpu)
160{
161 return per_cpu(_numa_mem_, cpu);
162}
163#endif
164
165#ifndef set_cpu_numa_mem
166static inline void set_cpu_numa_mem(int cpu, int node)
167{
168 per_cpu(_numa_mem_, cpu) = node;
169 _node_numa_mem_[cpu_to_node(cpu)] = node;
170}
171#endif
172
173#else
174
175#ifndef numa_mem_id
176
177static inline int numa_mem_id(void)
178{
179 return numa_node_id();
180}
181#endif
182
183#ifndef node_to_mem_node
184static inline int node_to_mem_node(int node)
185{
186 return node;
187}
188#endif
189
190#ifndef cpu_to_mem
191static inline int cpu_to_mem(int cpu)
192{
193 return cpu_to_node(cpu);
194}
195#endif
196
197#endif
198
199#ifndef topology_physical_package_id
200#define topology_physical_package_id(cpu) ((void)(cpu), -1)
201#endif
202#ifndef topology_die_id
203#define topology_die_id(cpu) ((void)(cpu), -1)
204#endif
205#ifndef topology_core_id
206#define topology_core_id(cpu) ((void)(cpu), 0)
207#endif
208#ifndef topology_sibling_cpumask
209#define topology_sibling_cpumask(cpu) cpumask_of(cpu)
210#endif
211#ifndef topology_core_cpumask
212#define topology_core_cpumask(cpu) cpumask_of(cpu)
213#endif
214#ifndef topology_die_cpumask
215#define topology_die_cpumask(cpu) cpumask_of(cpu)
216#endif
217
218#ifdef CONFIG_SCHED_SMT
219static inline const struct cpumask *cpu_smt_mask(int cpu)
220{
221 return topology_sibling_cpumask(cpu);
222}
223#endif
224
225static inline const struct cpumask *cpu_cpu_mask(int cpu)
226{
227 return cpumask_of_node(cpu_to_node(cpu));
228}
229
230
231#endif
232