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_);
133
134#ifndef set_numa_mem
135static inline void set_numa_mem(int node)
136{
137 this_cpu_write(_numa_mem_, node);
138}
139#endif
140
141#ifndef numa_mem_id
142
143static inline int numa_mem_id(void)
144{
145 return raw_cpu_read(_numa_mem_);
146}
147#endif
148
149#ifndef cpu_to_mem
150static inline int cpu_to_mem(int cpu)
151{
152 return per_cpu(_numa_mem_, cpu);
153}
154#endif
155
156#ifndef set_cpu_numa_mem
157static inline void set_cpu_numa_mem(int cpu, int node)
158{
159 per_cpu(_numa_mem_, cpu) = node;
160}
161#endif
162
163#else
164
165#ifndef numa_mem_id
166
167static inline int numa_mem_id(void)
168{
169 return numa_node_id();
170}
171#endif
172
173#ifndef cpu_to_mem
174static inline int cpu_to_mem(int cpu)
175{
176 return cpu_to_node(cpu);
177}
178#endif
179
180#endif
181
182#ifndef topology_physical_package_id
183#define topology_physical_package_id(cpu) ((void)(cpu), -1)
184#endif
185#ifndef topology_die_id
186#define topology_die_id(cpu) ((void)(cpu), -1)
187#endif
188#ifndef topology_core_id
189#define topology_core_id(cpu) ((void)(cpu), 0)
190#endif
191#ifndef topology_sibling_cpumask
192#define topology_sibling_cpumask(cpu) cpumask_of(cpu)
193#endif
194#ifndef topology_core_cpumask
195#define topology_core_cpumask(cpu) cpumask_of(cpu)
196#endif
197#ifndef topology_die_cpumask
198#define topology_die_cpumask(cpu) cpumask_of(cpu)
199#endif
200
201#ifdef CONFIG_SCHED_SMT
202static inline const struct cpumask *cpu_smt_mask(int cpu)
203{
204 return topology_sibling_cpumask(cpu);
205}
206#endif
207
208static inline const struct cpumask *cpu_cpu_mask(int cpu)
209{
210 return cpumask_of_node(cpu_to_node(cpu));
211}
212
213
214#endif
215