1b0c4e27cSMike Rapoport (Microsoft) // SPDX-License-Identifier: GPL-2.0
2b0c4e27cSMike Rapoport (Microsoft) /*
3b0c4e27cSMike Rapoport (Microsoft) * NUMA emulation
4b0c4e27cSMike Rapoport (Microsoft) */
5b0c4e27cSMike Rapoport (Microsoft) #include <linux/kernel.h>
6b0c4e27cSMike Rapoport (Microsoft) #include <linux/errno.h>
7b0c4e27cSMike Rapoport (Microsoft) #include <linux/topology.h>
8b0c4e27cSMike Rapoport (Microsoft) #include <linux/memblock.h>
9b0c4e27cSMike Rapoport (Microsoft) #include <linux/numa_memblks.h>
10b0c4e27cSMike Rapoport (Microsoft) #include <asm/numa.h>
1163db8170SBruno Faccini #include <acpi/acpi_numa.h>
12b0c4e27cSMike Rapoport (Microsoft)
13b0c4e27cSMike Rapoport (Microsoft) #define FAKE_NODE_MIN_SIZE ((u64)32 << 20)
14b0c4e27cSMike Rapoport (Microsoft) #define FAKE_NODE_MIN_HASH_MASK (~(FAKE_NODE_MIN_SIZE - 1UL))
15b0c4e27cSMike Rapoport (Microsoft)
1663db8170SBruno Faccini int emu_nid_to_phys[MAX_NUMNODES];
17b0c4e27cSMike Rapoport (Microsoft) static char *emu_cmdline __initdata;
18b0c4e27cSMike Rapoport (Microsoft)
numa_emu_cmdline(char * str)19b0c4e27cSMike Rapoport (Microsoft) int __init numa_emu_cmdline(char *str)
20b0c4e27cSMike Rapoport (Microsoft) {
21b0c4e27cSMike Rapoport (Microsoft) emu_cmdline = str;
22b0c4e27cSMike Rapoport (Microsoft) return 0;
23b0c4e27cSMike Rapoport (Microsoft) }
24b0c4e27cSMike Rapoport (Microsoft)
emu_find_memblk_by_nid(int nid,const struct numa_meminfo * mi)25b0c4e27cSMike Rapoport (Microsoft) static int __init emu_find_memblk_by_nid(int nid, const struct numa_meminfo *mi)
26b0c4e27cSMike Rapoport (Microsoft) {
27b0c4e27cSMike Rapoport (Microsoft) int i;
28b0c4e27cSMike Rapoport (Microsoft)
29b0c4e27cSMike Rapoport (Microsoft) for (i = 0; i < mi->nr_blks; i++)
30b0c4e27cSMike Rapoport (Microsoft) if (mi->blk[i].nid == nid)
31b0c4e27cSMike Rapoport (Microsoft) return i;
32b0c4e27cSMike Rapoport (Microsoft) return -ENOENT;
33b0c4e27cSMike Rapoport (Microsoft) }
34b0c4e27cSMike Rapoport (Microsoft)
mem_hole_size(u64 start,u64 end)35b0c4e27cSMike Rapoport (Microsoft) static u64 __init mem_hole_size(u64 start, u64 end)
36b0c4e27cSMike Rapoport (Microsoft) {
37b0c4e27cSMike Rapoport (Microsoft) unsigned long start_pfn = PFN_UP(start);
38b0c4e27cSMike Rapoport (Microsoft) unsigned long end_pfn = PFN_DOWN(end);
39b0c4e27cSMike Rapoport (Microsoft)
40b0c4e27cSMike Rapoport (Microsoft) if (start_pfn < end_pfn)
41b0c4e27cSMike Rapoport (Microsoft) return PFN_PHYS(absent_pages_in_range(start_pfn, end_pfn));
42b0c4e27cSMike Rapoport (Microsoft) return 0;
43b0c4e27cSMike Rapoport (Microsoft) }
44b0c4e27cSMike Rapoport (Microsoft)
45b0c4e27cSMike Rapoport (Microsoft) /*
46b0c4e27cSMike Rapoport (Microsoft) * Sets up nid to range from @start to @end. The return value is -errno if
47b0c4e27cSMike Rapoport (Microsoft) * something went wrong, 0 otherwise.
48b0c4e27cSMike Rapoport (Microsoft) */
emu_setup_memblk(struct numa_meminfo * ei,struct numa_meminfo * pi,int nid,int phys_blk,u64 size)49b0c4e27cSMike Rapoport (Microsoft) static int __init emu_setup_memblk(struct numa_meminfo *ei,
50b0c4e27cSMike Rapoport (Microsoft) struct numa_meminfo *pi,
51b0c4e27cSMike Rapoport (Microsoft) int nid, int phys_blk, u64 size)
52b0c4e27cSMike Rapoport (Microsoft) {
53b0c4e27cSMike Rapoport (Microsoft) struct numa_memblk *eb = &ei->blk[ei->nr_blks];
54b0c4e27cSMike Rapoport (Microsoft) struct numa_memblk *pb = &pi->blk[phys_blk];
55b0c4e27cSMike Rapoport (Microsoft)
56b0c4e27cSMike Rapoport (Microsoft) if (ei->nr_blks >= NR_NODE_MEMBLKS) {
57b0c4e27cSMike Rapoport (Microsoft) pr_err("NUMA: Too many emulated memblks, failing emulation\n");
58b0c4e27cSMike Rapoport (Microsoft) return -EINVAL;
59b0c4e27cSMike Rapoport (Microsoft) }
60b0c4e27cSMike Rapoport (Microsoft)
61b0c4e27cSMike Rapoport (Microsoft) ei->nr_blks++;
62b0c4e27cSMike Rapoport (Microsoft) eb->start = pb->start;
63b0c4e27cSMike Rapoport (Microsoft) eb->end = pb->start + size;
64b0c4e27cSMike Rapoport (Microsoft) eb->nid = nid;
65b0c4e27cSMike Rapoport (Microsoft)
66b0c4e27cSMike Rapoport (Microsoft) if (emu_nid_to_phys[nid] == NUMA_NO_NODE)
67b0c4e27cSMike Rapoport (Microsoft) emu_nid_to_phys[nid] = pb->nid;
68b0c4e27cSMike Rapoport (Microsoft)
69b0c4e27cSMike Rapoport (Microsoft) pb->start += size;
70b0c4e27cSMike Rapoport (Microsoft) if (pb->start >= pb->end) {
71b0c4e27cSMike Rapoport (Microsoft) WARN_ON_ONCE(pb->start > pb->end);
72b0c4e27cSMike Rapoport (Microsoft) numa_remove_memblk_from(phys_blk, pi);
73b0c4e27cSMike Rapoport (Microsoft) }
74b0c4e27cSMike Rapoport (Microsoft)
75b0c4e27cSMike Rapoport (Microsoft) printk(KERN_INFO "Faking node %d at [mem %#018Lx-%#018Lx] (%LuMB)\n",
76*4647c4deSPratyush Brahma nid, eb->start, eb->end - 1, (eb->end - eb->start) / SZ_1M);
77b0c4e27cSMike Rapoport (Microsoft) return 0;
78b0c4e27cSMike Rapoport (Microsoft) }
79b0c4e27cSMike Rapoport (Microsoft)
80b0c4e27cSMike Rapoport (Microsoft) /*
81b0c4e27cSMike Rapoport (Microsoft) * Sets up nr_nodes fake nodes interleaved over physical nodes ranging from addr
82b0c4e27cSMike Rapoport (Microsoft) * to max_addr.
83b0c4e27cSMike Rapoport (Microsoft) *
84b0c4e27cSMike Rapoport (Microsoft) * Returns zero on success or negative on error.
85b0c4e27cSMike Rapoport (Microsoft) */
split_nodes_interleave(struct numa_meminfo * ei,struct numa_meminfo * pi,u64 addr,u64 max_addr,int nr_nodes)86b0c4e27cSMike Rapoport (Microsoft) static int __init split_nodes_interleave(struct numa_meminfo *ei,
87b0c4e27cSMike Rapoport (Microsoft) struct numa_meminfo *pi,
88b0c4e27cSMike Rapoport (Microsoft) u64 addr, u64 max_addr, int nr_nodes)
89b0c4e27cSMike Rapoport (Microsoft) {
90b0c4e27cSMike Rapoport (Microsoft) nodemask_t physnode_mask = numa_nodes_parsed;
91b0c4e27cSMike Rapoport (Microsoft) u64 size;
92b0c4e27cSMike Rapoport (Microsoft) int big;
93b0c4e27cSMike Rapoport (Microsoft) int nid = 0;
94b0c4e27cSMike Rapoport (Microsoft) int i, ret;
95b0c4e27cSMike Rapoport (Microsoft)
96b0c4e27cSMike Rapoport (Microsoft) if (nr_nodes <= 0)
97b0c4e27cSMike Rapoport (Microsoft) return -1;
98b0c4e27cSMike Rapoport (Microsoft) if (nr_nodes > MAX_NUMNODES) {
99b0c4e27cSMike Rapoport (Microsoft) pr_info("numa=fake=%d too large, reducing to %d\n",
100b0c4e27cSMike Rapoport (Microsoft) nr_nodes, MAX_NUMNODES);
101b0c4e27cSMike Rapoport (Microsoft) nr_nodes = MAX_NUMNODES;
102b0c4e27cSMike Rapoport (Microsoft) }
103b0c4e27cSMike Rapoport (Microsoft)
104b0c4e27cSMike Rapoport (Microsoft) /*
105b0c4e27cSMike Rapoport (Microsoft) * Calculate target node size. x86_32 freaks on __udivdi3() so do
106b0c4e27cSMike Rapoport (Microsoft) * the division in ulong number of pages and convert back.
107b0c4e27cSMike Rapoport (Microsoft) */
108b0c4e27cSMike Rapoport (Microsoft) size = max_addr - addr - mem_hole_size(addr, max_addr);
109b0c4e27cSMike Rapoport (Microsoft) size = PFN_PHYS((unsigned long)(size >> PAGE_SHIFT) / nr_nodes);
110b0c4e27cSMike Rapoport (Microsoft)
111b0c4e27cSMike Rapoport (Microsoft) /*
112b0c4e27cSMike Rapoport (Microsoft) * Calculate the number of big nodes that can be allocated as a result
113b0c4e27cSMike Rapoport (Microsoft) * of consolidating the remainder.
114b0c4e27cSMike Rapoport (Microsoft) */
115b0c4e27cSMike Rapoport (Microsoft) big = ((size & ~FAKE_NODE_MIN_HASH_MASK) * nr_nodes) /
116b0c4e27cSMike Rapoport (Microsoft) FAKE_NODE_MIN_SIZE;
117b0c4e27cSMike Rapoport (Microsoft)
118b0c4e27cSMike Rapoport (Microsoft) size &= FAKE_NODE_MIN_HASH_MASK;
119b0c4e27cSMike Rapoport (Microsoft) if (!size) {
120b0c4e27cSMike Rapoport (Microsoft) pr_err("Not enough memory for each node. "
121b0c4e27cSMike Rapoport (Microsoft) "NUMA emulation disabled.\n");
122b0c4e27cSMike Rapoport (Microsoft) return -1;
123b0c4e27cSMike Rapoport (Microsoft) }
124b0c4e27cSMike Rapoport (Microsoft)
125b0c4e27cSMike Rapoport (Microsoft) /*
126b0c4e27cSMike Rapoport (Microsoft) * Continue to fill physical nodes with fake nodes until there is no
127b0c4e27cSMike Rapoport (Microsoft) * memory left on any of them.
128b0c4e27cSMike Rapoport (Microsoft) */
129b0c4e27cSMike Rapoport (Microsoft) while (!nodes_empty(physnode_mask)) {
130b0c4e27cSMike Rapoport (Microsoft) for_each_node_mask(i, physnode_mask) {
131b0c4e27cSMike Rapoport (Microsoft) u64 dma32_end = numa_emu_dma_end();
132b0c4e27cSMike Rapoport (Microsoft) u64 start, limit, end;
133b0c4e27cSMike Rapoport (Microsoft) int phys_blk;
134b0c4e27cSMike Rapoport (Microsoft)
135b0c4e27cSMike Rapoport (Microsoft) phys_blk = emu_find_memblk_by_nid(i, pi);
136b0c4e27cSMike Rapoport (Microsoft) if (phys_blk < 0) {
137b0c4e27cSMike Rapoport (Microsoft) node_clear(i, physnode_mask);
138b0c4e27cSMike Rapoport (Microsoft) continue;
139b0c4e27cSMike Rapoport (Microsoft) }
140b0c4e27cSMike Rapoport (Microsoft) start = pi->blk[phys_blk].start;
141b0c4e27cSMike Rapoport (Microsoft) limit = pi->blk[phys_blk].end;
142b0c4e27cSMike Rapoport (Microsoft) end = start + size;
143b0c4e27cSMike Rapoport (Microsoft)
144b0c4e27cSMike Rapoport (Microsoft) if (nid < big)
145b0c4e27cSMike Rapoport (Microsoft) end += FAKE_NODE_MIN_SIZE;
146b0c4e27cSMike Rapoport (Microsoft)
147b0c4e27cSMike Rapoport (Microsoft) /*
148b0c4e27cSMike Rapoport (Microsoft) * Continue to add memory to this fake node if its
149b0c4e27cSMike Rapoport (Microsoft) * non-reserved memory is less than the per-node size.
150b0c4e27cSMike Rapoport (Microsoft) */
151b0c4e27cSMike Rapoport (Microsoft) while (end - start - mem_hole_size(start, end) < size) {
152b0c4e27cSMike Rapoport (Microsoft) end += FAKE_NODE_MIN_SIZE;
153b0c4e27cSMike Rapoport (Microsoft) if (end > limit) {
154b0c4e27cSMike Rapoport (Microsoft) end = limit;
155b0c4e27cSMike Rapoport (Microsoft) break;
156b0c4e27cSMike Rapoport (Microsoft) }
157b0c4e27cSMike Rapoport (Microsoft) }
158b0c4e27cSMike Rapoport (Microsoft)
159b0c4e27cSMike Rapoport (Microsoft) /*
160b0c4e27cSMike Rapoport (Microsoft) * If there won't be at least FAKE_NODE_MIN_SIZE of
161b0c4e27cSMike Rapoport (Microsoft) * non-reserved memory in ZONE_DMA32 for the next node,
162b0c4e27cSMike Rapoport (Microsoft) * this one must extend to the boundary.
163b0c4e27cSMike Rapoport (Microsoft) */
164b0c4e27cSMike Rapoport (Microsoft) if (end < dma32_end && dma32_end - end -
165b0c4e27cSMike Rapoport (Microsoft) mem_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
166b0c4e27cSMike Rapoport (Microsoft) end = dma32_end;
167b0c4e27cSMike Rapoport (Microsoft)
168b0c4e27cSMike Rapoport (Microsoft) /*
169b0c4e27cSMike Rapoport (Microsoft) * If there won't be enough non-reserved memory for the
170b0c4e27cSMike Rapoport (Microsoft) * next node, this one must extend to the end of the
171b0c4e27cSMike Rapoport (Microsoft) * physical node.
172b0c4e27cSMike Rapoport (Microsoft) */
173b0c4e27cSMike Rapoport (Microsoft) if (limit - end - mem_hole_size(end, limit) < size)
174b0c4e27cSMike Rapoport (Microsoft) end = limit;
175b0c4e27cSMike Rapoport (Microsoft)
176b0c4e27cSMike Rapoport (Microsoft) ret = emu_setup_memblk(ei, pi, nid++ % nr_nodes,
177b0c4e27cSMike Rapoport (Microsoft) phys_blk,
178b0c4e27cSMike Rapoport (Microsoft) min(end, limit) - start);
179b0c4e27cSMike Rapoport (Microsoft) if (ret < 0)
180b0c4e27cSMike Rapoport (Microsoft) return ret;
181b0c4e27cSMike Rapoport (Microsoft) }
182b0c4e27cSMike Rapoport (Microsoft) }
183b0c4e27cSMike Rapoport (Microsoft) return 0;
184b0c4e27cSMike Rapoport (Microsoft) }
185b0c4e27cSMike Rapoport (Microsoft)
186b0c4e27cSMike Rapoport (Microsoft) /*
187b0c4e27cSMike Rapoport (Microsoft) * Returns the end address of a node so that there is at least `size' amount of
188b0c4e27cSMike Rapoport (Microsoft) * non-reserved memory or `max_addr' is reached.
189b0c4e27cSMike Rapoport (Microsoft) */
find_end_of_node(u64 start,u64 max_addr,u64 size)190b0c4e27cSMike Rapoport (Microsoft) static u64 __init find_end_of_node(u64 start, u64 max_addr, u64 size)
191b0c4e27cSMike Rapoport (Microsoft) {
192b0c4e27cSMike Rapoport (Microsoft) u64 end = start + size;
193b0c4e27cSMike Rapoport (Microsoft)
194b0c4e27cSMike Rapoport (Microsoft) while (end - start - mem_hole_size(start, end) < size) {
195b0c4e27cSMike Rapoport (Microsoft) end += FAKE_NODE_MIN_SIZE;
196b0c4e27cSMike Rapoport (Microsoft) if (end > max_addr) {
197b0c4e27cSMike Rapoport (Microsoft) end = max_addr;
198b0c4e27cSMike Rapoport (Microsoft) break;
199b0c4e27cSMike Rapoport (Microsoft) }
200b0c4e27cSMike Rapoport (Microsoft) }
201b0c4e27cSMike Rapoport (Microsoft) return end;
202b0c4e27cSMike Rapoport (Microsoft) }
203b0c4e27cSMike Rapoport (Microsoft)
uniform_size(u64 max_addr,u64 base,u64 hole,int nr_nodes)204b0c4e27cSMike Rapoport (Microsoft) static u64 uniform_size(u64 max_addr, u64 base, u64 hole, int nr_nodes)
205b0c4e27cSMike Rapoport (Microsoft) {
206b0c4e27cSMike Rapoport (Microsoft) unsigned long max_pfn = PHYS_PFN(max_addr);
207b0c4e27cSMike Rapoport (Microsoft) unsigned long base_pfn = PHYS_PFN(base);
208b0c4e27cSMike Rapoport (Microsoft) unsigned long hole_pfns = PHYS_PFN(hole);
209b0c4e27cSMike Rapoport (Microsoft)
210b0c4e27cSMike Rapoport (Microsoft) return PFN_PHYS((max_pfn - base_pfn - hole_pfns) / nr_nodes);
211b0c4e27cSMike Rapoport (Microsoft) }
212b0c4e27cSMike Rapoport (Microsoft)
213b0c4e27cSMike Rapoport (Microsoft) /*
214b0c4e27cSMike Rapoport (Microsoft) * Sets up fake nodes of `size' interleaved over physical nodes ranging from
215b0c4e27cSMike Rapoport (Microsoft) * `addr' to `max_addr'.
216b0c4e27cSMike Rapoport (Microsoft) *
217b0c4e27cSMike Rapoport (Microsoft) * Returns zero on success or negative on error.
218b0c4e27cSMike Rapoport (Microsoft) */
split_nodes_size_interleave_uniform(struct numa_meminfo * ei,struct numa_meminfo * pi,u64 addr,u64 max_addr,u64 size,int nr_nodes,struct numa_memblk * pblk,int nid)219b0c4e27cSMike Rapoport (Microsoft) static int __init split_nodes_size_interleave_uniform(struct numa_meminfo *ei,
220b0c4e27cSMike Rapoport (Microsoft) struct numa_meminfo *pi,
221b0c4e27cSMike Rapoport (Microsoft) u64 addr, u64 max_addr, u64 size,
222b0c4e27cSMike Rapoport (Microsoft) int nr_nodes, struct numa_memblk *pblk,
223b0c4e27cSMike Rapoport (Microsoft) int nid)
224b0c4e27cSMike Rapoport (Microsoft) {
225b0c4e27cSMike Rapoport (Microsoft) nodemask_t physnode_mask = numa_nodes_parsed;
226b0c4e27cSMike Rapoport (Microsoft) int i, ret, uniform = 0;
227b0c4e27cSMike Rapoport (Microsoft) u64 min_size;
228b0c4e27cSMike Rapoport (Microsoft)
229b0c4e27cSMike Rapoport (Microsoft) if ((!size && !nr_nodes) || (nr_nodes && !pblk))
230b0c4e27cSMike Rapoport (Microsoft) return -1;
231b0c4e27cSMike Rapoport (Microsoft)
232b0c4e27cSMike Rapoport (Microsoft) /*
233b0c4e27cSMike Rapoport (Microsoft) * In the 'uniform' case split the passed in physical node by
234b0c4e27cSMike Rapoport (Microsoft) * nr_nodes, in the non-uniform case, ignore the passed in
235b0c4e27cSMike Rapoport (Microsoft) * physical block and try to create nodes of at least size
236b0c4e27cSMike Rapoport (Microsoft) * @size.
237b0c4e27cSMike Rapoport (Microsoft) *
238b0c4e27cSMike Rapoport (Microsoft) * In the uniform case, split the nodes strictly by physical
239b0c4e27cSMike Rapoport (Microsoft) * capacity, i.e. ignore holes. In the non-uniform case account
240b0c4e27cSMike Rapoport (Microsoft) * for holes and treat @size as a minimum floor.
241b0c4e27cSMike Rapoport (Microsoft) */
242b0c4e27cSMike Rapoport (Microsoft) if (!nr_nodes)
243b0c4e27cSMike Rapoport (Microsoft) nr_nodes = MAX_NUMNODES;
244b0c4e27cSMike Rapoport (Microsoft) else {
245b0c4e27cSMike Rapoport (Microsoft) nodes_clear(physnode_mask);
246b0c4e27cSMike Rapoport (Microsoft) node_set(pblk->nid, physnode_mask);
247b0c4e27cSMike Rapoport (Microsoft) uniform = 1;
248b0c4e27cSMike Rapoport (Microsoft) }
249b0c4e27cSMike Rapoport (Microsoft)
250b0c4e27cSMike Rapoport (Microsoft) if (uniform) {
251b0c4e27cSMike Rapoport (Microsoft) min_size = uniform_size(max_addr, addr, 0, nr_nodes);
252b0c4e27cSMike Rapoport (Microsoft) size = min_size;
253b0c4e27cSMike Rapoport (Microsoft) } else {
254b0c4e27cSMike Rapoport (Microsoft) /*
255b0c4e27cSMike Rapoport (Microsoft) * The limit on emulated nodes is MAX_NUMNODES, so the
256b0c4e27cSMike Rapoport (Microsoft) * size per node is increased accordingly if the
257b0c4e27cSMike Rapoport (Microsoft) * requested size is too small. This creates a uniform
258b0c4e27cSMike Rapoport (Microsoft) * distribution of node sizes across the entire machine
259b0c4e27cSMike Rapoport (Microsoft) * (but not necessarily over physical nodes).
260b0c4e27cSMike Rapoport (Microsoft) */
261b0c4e27cSMike Rapoport (Microsoft) min_size = uniform_size(max_addr, addr,
262b0c4e27cSMike Rapoport (Microsoft) mem_hole_size(addr, max_addr), nr_nodes);
263b0c4e27cSMike Rapoport (Microsoft) }
264b0c4e27cSMike Rapoport (Microsoft) min_size = ALIGN(max(min_size, FAKE_NODE_MIN_SIZE), FAKE_NODE_MIN_SIZE);
265b0c4e27cSMike Rapoport (Microsoft) if (size < min_size) {
266b0c4e27cSMike Rapoport (Microsoft) pr_err("Fake node size %LuMB too small, increasing to %LuMB\n",
267*4647c4deSPratyush Brahma size / SZ_1M, min_size / SZ_1M);
268b0c4e27cSMike Rapoport (Microsoft) size = min_size;
269b0c4e27cSMike Rapoport (Microsoft) }
270b0c4e27cSMike Rapoport (Microsoft) size = ALIGN_DOWN(size, FAKE_NODE_MIN_SIZE);
271b0c4e27cSMike Rapoport (Microsoft)
272b0c4e27cSMike Rapoport (Microsoft) /*
273b0c4e27cSMike Rapoport (Microsoft) * Fill physical nodes with fake nodes of size until there is no memory
274b0c4e27cSMike Rapoport (Microsoft) * left on any of them.
275b0c4e27cSMike Rapoport (Microsoft) */
276b0c4e27cSMike Rapoport (Microsoft) while (!nodes_empty(physnode_mask)) {
277b0c4e27cSMike Rapoport (Microsoft) for_each_node_mask(i, physnode_mask) {
278b0c4e27cSMike Rapoport (Microsoft) u64 dma32_end = numa_emu_dma_end();
279b0c4e27cSMike Rapoport (Microsoft) u64 start, limit, end;
280b0c4e27cSMike Rapoport (Microsoft) int phys_blk;
281b0c4e27cSMike Rapoport (Microsoft)
282b0c4e27cSMike Rapoport (Microsoft) phys_blk = emu_find_memblk_by_nid(i, pi);
283b0c4e27cSMike Rapoport (Microsoft) if (phys_blk < 0) {
284b0c4e27cSMike Rapoport (Microsoft) node_clear(i, physnode_mask);
285b0c4e27cSMike Rapoport (Microsoft) continue;
286b0c4e27cSMike Rapoport (Microsoft) }
287b0c4e27cSMike Rapoport (Microsoft)
288b0c4e27cSMike Rapoport (Microsoft) start = pi->blk[phys_blk].start;
289b0c4e27cSMike Rapoport (Microsoft) limit = pi->blk[phys_blk].end;
290b0c4e27cSMike Rapoport (Microsoft)
291b0c4e27cSMike Rapoport (Microsoft) if (uniform)
292b0c4e27cSMike Rapoport (Microsoft) end = start + size;
293b0c4e27cSMike Rapoport (Microsoft) else
294b0c4e27cSMike Rapoport (Microsoft) end = find_end_of_node(start, limit, size);
295b0c4e27cSMike Rapoport (Microsoft) /*
296b0c4e27cSMike Rapoport (Microsoft) * If there won't be at least FAKE_NODE_MIN_SIZE of
297b0c4e27cSMike Rapoport (Microsoft) * non-reserved memory in ZONE_DMA32 for the next node,
298b0c4e27cSMike Rapoport (Microsoft) * this one must extend to the boundary.
299b0c4e27cSMike Rapoport (Microsoft) */
300b0c4e27cSMike Rapoport (Microsoft) if (end < dma32_end && dma32_end - end -
301b0c4e27cSMike Rapoport (Microsoft) mem_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
302b0c4e27cSMike Rapoport (Microsoft) end = dma32_end;
303b0c4e27cSMike Rapoport (Microsoft)
304b0c4e27cSMike Rapoport (Microsoft) /*
305b0c4e27cSMike Rapoport (Microsoft) * If there won't be enough non-reserved memory for the
306b0c4e27cSMike Rapoport (Microsoft) * next node, this one must extend to the end of the
307b0c4e27cSMike Rapoport (Microsoft) * physical node.
308b0c4e27cSMike Rapoport (Microsoft) */
309b0c4e27cSMike Rapoport (Microsoft) if ((limit - end - mem_hole_size(end, limit) < size)
310b0c4e27cSMike Rapoport (Microsoft) && !uniform)
311b0c4e27cSMike Rapoport (Microsoft) end = limit;
312b0c4e27cSMike Rapoport (Microsoft)
313b0c4e27cSMike Rapoport (Microsoft) ret = emu_setup_memblk(ei, pi, nid++ % MAX_NUMNODES,
314b0c4e27cSMike Rapoport (Microsoft) phys_blk,
315b0c4e27cSMike Rapoport (Microsoft) min(end, limit) - start);
316b0c4e27cSMike Rapoport (Microsoft) if (ret < 0)
317b0c4e27cSMike Rapoport (Microsoft) return ret;
318b0c4e27cSMike Rapoport (Microsoft) }
319b0c4e27cSMike Rapoport (Microsoft) }
320b0c4e27cSMike Rapoport (Microsoft) return nid;
321b0c4e27cSMike Rapoport (Microsoft) }
322b0c4e27cSMike Rapoport (Microsoft)
split_nodes_size_interleave(struct numa_meminfo * ei,struct numa_meminfo * pi,u64 addr,u64 max_addr,u64 size)323b0c4e27cSMike Rapoport (Microsoft) static int __init split_nodes_size_interleave(struct numa_meminfo *ei,
324b0c4e27cSMike Rapoport (Microsoft) struct numa_meminfo *pi,
325b0c4e27cSMike Rapoport (Microsoft) u64 addr, u64 max_addr, u64 size)
326b0c4e27cSMike Rapoport (Microsoft) {
327b0c4e27cSMike Rapoport (Microsoft) return split_nodes_size_interleave_uniform(ei, pi, addr, max_addr, size,
328b0c4e27cSMike Rapoport (Microsoft) 0, NULL, 0);
329b0c4e27cSMike Rapoport (Microsoft) }
330b0c4e27cSMike Rapoport (Microsoft)
setup_emu2phys_nid(int * dfl_phys_nid)331b0c4e27cSMike Rapoport (Microsoft) static int __init setup_emu2phys_nid(int *dfl_phys_nid)
332b0c4e27cSMike Rapoport (Microsoft) {
333b0c4e27cSMike Rapoport (Microsoft) int i, max_emu_nid = 0;
334b0c4e27cSMike Rapoport (Microsoft)
335b0c4e27cSMike Rapoport (Microsoft) *dfl_phys_nid = NUMA_NO_NODE;
336b0c4e27cSMike Rapoport (Microsoft) for (i = 0; i < ARRAY_SIZE(emu_nid_to_phys); i++) {
337b0c4e27cSMike Rapoport (Microsoft) if (emu_nid_to_phys[i] != NUMA_NO_NODE) {
338b0c4e27cSMike Rapoport (Microsoft) max_emu_nid = i;
339b0c4e27cSMike Rapoport (Microsoft) if (*dfl_phys_nid == NUMA_NO_NODE)
340b0c4e27cSMike Rapoport (Microsoft) *dfl_phys_nid = emu_nid_to_phys[i];
341b0c4e27cSMike Rapoport (Microsoft) }
342b0c4e27cSMike Rapoport (Microsoft) }
343b0c4e27cSMike Rapoport (Microsoft)
344b0c4e27cSMike Rapoport (Microsoft) return max_emu_nid;
345b0c4e27cSMike Rapoport (Microsoft) }
346b0c4e27cSMike Rapoport (Microsoft)
347b0c4e27cSMike Rapoport (Microsoft) /**
348b0c4e27cSMike Rapoport (Microsoft) * numa_emulation - Emulate NUMA nodes
349b0c4e27cSMike Rapoport (Microsoft) * @numa_meminfo: NUMA configuration to massage
350b0c4e27cSMike Rapoport (Microsoft) * @numa_dist_cnt: The size of the physical NUMA distance table
351b0c4e27cSMike Rapoport (Microsoft) *
352b0c4e27cSMike Rapoport (Microsoft) * Emulate NUMA nodes according to the numa=fake kernel parameter.
353b0c4e27cSMike Rapoport (Microsoft) * @numa_meminfo contains the physical memory configuration and is modified
354b0c4e27cSMike Rapoport (Microsoft) * to reflect the emulated configuration on success. @numa_dist_cnt is
355b0c4e27cSMike Rapoport (Microsoft) * used to determine the size of the physical distance table.
356b0c4e27cSMike Rapoport (Microsoft) *
357b0c4e27cSMike Rapoport (Microsoft) * On success, the following modifications are made.
358b0c4e27cSMike Rapoport (Microsoft) *
359b0c4e27cSMike Rapoport (Microsoft) * - @numa_meminfo is updated to reflect the emulated nodes.
360b0c4e27cSMike Rapoport (Microsoft) *
361b0c4e27cSMike Rapoport (Microsoft) * - __apicid_to_node[] is updated such that APIC IDs are mapped to the
362b0c4e27cSMike Rapoport (Microsoft) * emulated nodes.
363b0c4e27cSMike Rapoport (Microsoft) *
364b0c4e27cSMike Rapoport (Microsoft) * - NUMA distance table is rebuilt to represent distances between emulated
365b0c4e27cSMike Rapoport (Microsoft) * nodes. The distances are determined considering how emulated nodes
366b0c4e27cSMike Rapoport (Microsoft) * are mapped to physical nodes and match the actual distances.
367b0c4e27cSMike Rapoport (Microsoft) *
368b0c4e27cSMike Rapoport (Microsoft) * - emu_nid_to_phys[] reflects how emulated nodes are mapped to physical
369b0c4e27cSMike Rapoport (Microsoft) * nodes. This is used by numa_add_cpu() and numa_remove_cpu().
370b0c4e27cSMike Rapoport (Microsoft) *
371b0c4e27cSMike Rapoport (Microsoft) * If emulation is not enabled or fails, emu_nid_to_phys[] is filled with
372b0c4e27cSMike Rapoport (Microsoft) * identity mapping and no other modification is made.
373b0c4e27cSMike Rapoport (Microsoft) */
numa_emulation(struct numa_meminfo * numa_meminfo,int numa_dist_cnt)374b0c4e27cSMike Rapoport (Microsoft) void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
375b0c4e27cSMike Rapoport (Microsoft) {
376b0c4e27cSMike Rapoport (Microsoft) static struct numa_meminfo ei __initdata;
377b0c4e27cSMike Rapoport (Microsoft) static struct numa_meminfo pi __initdata;
378b0c4e27cSMike Rapoport (Microsoft) const u64 max_addr = PFN_PHYS(max_pfn);
379b0c4e27cSMike Rapoport (Microsoft) u8 *phys_dist = NULL;
380b0c4e27cSMike Rapoport (Microsoft) size_t phys_size = numa_dist_cnt * numa_dist_cnt * sizeof(phys_dist[0]);
381b0c4e27cSMike Rapoport (Microsoft) int max_emu_nid, dfl_phys_nid;
382b0c4e27cSMike Rapoport (Microsoft) int i, j, ret;
38363db8170SBruno Faccini nodemask_t physnode_mask = numa_nodes_parsed;
384b0c4e27cSMike Rapoport (Microsoft)
385b0c4e27cSMike Rapoport (Microsoft) if (!emu_cmdline)
386b0c4e27cSMike Rapoport (Microsoft) goto no_emu;
387b0c4e27cSMike Rapoport (Microsoft)
388b0c4e27cSMike Rapoport (Microsoft) memset(&ei, 0, sizeof(ei));
389b0c4e27cSMike Rapoport (Microsoft) pi = *numa_meminfo;
390b0c4e27cSMike Rapoport (Microsoft)
391b0c4e27cSMike Rapoport (Microsoft) for (i = 0; i < MAX_NUMNODES; i++)
392b0c4e27cSMike Rapoport (Microsoft) emu_nid_to_phys[i] = NUMA_NO_NODE;
393b0c4e27cSMike Rapoport (Microsoft)
394b0c4e27cSMike Rapoport (Microsoft) /*
395b0c4e27cSMike Rapoport (Microsoft) * If the numa=fake command-line contains a 'M' or 'G', it represents
396b0c4e27cSMike Rapoport (Microsoft) * the fixed node size. Otherwise, if it is just a single number N,
397b0c4e27cSMike Rapoport (Microsoft) * split the system RAM into N fake nodes.
398b0c4e27cSMike Rapoport (Microsoft) */
399b0c4e27cSMike Rapoport (Microsoft) if (strchr(emu_cmdline, 'U')) {
400b0c4e27cSMike Rapoport (Microsoft) unsigned long n;
401b0c4e27cSMike Rapoport (Microsoft) int nid = 0;
402b0c4e27cSMike Rapoport (Microsoft)
403b0c4e27cSMike Rapoport (Microsoft) n = simple_strtoul(emu_cmdline, &emu_cmdline, 0);
404b0c4e27cSMike Rapoport (Microsoft) ret = -1;
405b0c4e27cSMike Rapoport (Microsoft) for_each_node_mask(i, physnode_mask) {
406b0c4e27cSMike Rapoport (Microsoft) /*
407b0c4e27cSMike Rapoport (Microsoft) * The reason we pass in blk[0] is due to
408b0c4e27cSMike Rapoport (Microsoft) * numa_remove_memblk_from() called by
409b0c4e27cSMike Rapoport (Microsoft) * emu_setup_memblk() will delete entry 0
410b0c4e27cSMike Rapoport (Microsoft) * and then move everything else up in the pi.blk
411b0c4e27cSMike Rapoport (Microsoft) * array. Therefore we should always be looking
412b0c4e27cSMike Rapoport (Microsoft) * at blk[0].
413b0c4e27cSMike Rapoport (Microsoft) */
414b0c4e27cSMike Rapoport (Microsoft) ret = split_nodes_size_interleave_uniform(&ei, &pi,
415b0c4e27cSMike Rapoport (Microsoft) pi.blk[0].start, pi.blk[0].end, 0,
416b0c4e27cSMike Rapoport (Microsoft) n, &pi.blk[0], nid);
417b0c4e27cSMike Rapoport (Microsoft) if (ret < 0)
418b0c4e27cSMike Rapoport (Microsoft) break;
419b0c4e27cSMike Rapoport (Microsoft) if (ret < n) {
420b0c4e27cSMike Rapoport (Microsoft) pr_info("%s: phys: %d only got %d of %ld nodes, failing\n",
421b0c4e27cSMike Rapoport (Microsoft) __func__, i, ret, n);
422b0c4e27cSMike Rapoport (Microsoft) ret = -1;
423b0c4e27cSMike Rapoport (Microsoft) break;
424b0c4e27cSMike Rapoport (Microsoft) }
425b0c4e27cSMike Rapoport (Microsoft) nid = ret;
426b0c4e27cSMike Rapoport (Microsoft) }
427b0c4e27cSMike Rapoport (Microsoft) } else if (strchr(emu_cmdline, 'M') || strchr(emu_cmdline, 'G')) {
428b0c4e27cSMike Rapoport (Microsoft) u64 size;
429b0c4e27cSMike Rapoport (Microsoft)
430b0c4e27cSMike Rapoport (Microsoft) size = memparse(emu_cmdline, &emu_cmdline);
431b0c4e27cSMike Rapoport (Microsoft) ret = split_nodes_size_interleave(&ei, &pi, 0, max_addr, size);
432b0c4e27cSMike Rapoport (Microsoft) } else {
433b0c4e27cSMike Rapoport (Microsoft) unsigned long n;
434b0c4e27cSMike Rapoport (Microsoft)
435b0c4e27cSMike Rapoport (Microsoft) n = simple_strtoul(emu_cmdline, &emu_cmdline, 0);
436b0c4e27cSMike Rapoport (Microsoft) ret = split_nodes_interleave(&ei, &pi, 0, max_addr, n);
437b0c4e27cSMike Rapoport (Microsoft) }
438b0c4e27cSMike Rapoport (Microsoft) if (*emu_cmdline == ':')
439b0c4e27cSMike Rapoport (Microsoft) emu_cmdline++;
440b0c4e27cSMike Rapoport (Microsoft)
441b0c4e27cSMike Rapoport (Microsoft) if (ret < 0)
442b0c4e27cSMike Rapoport (Microsoft) goto no_emu;
443b0c4e27cSMike Rapoport (Microsoft)
444b0c4e27cSMike Rapoport (Microsoft) if (numa_cleanup_meminfo(&ei) < 0) {
445b0c4e27cSMike Rapoport (Microsoft) pr_warn("NUMA: Warning: constructed meminfo invalid, disabling emulation\n");
446b0c4e27cSMike Rapoport (Microsoft) goto no_emu;
447b0c4e27cSMike Rapoport (Microsoft) }
448b0c4e27cSMike Rapoport (Microsoft)
449b0c4e27cSMike Rapoport (Microsoft) /* copy the physical distance table */
450b0c4e27cSMike Rapoport (Microsoft) if (numa_dist_cnt) {
451b0c4e27cSMike Rapoport (Microsoft) phys_dist = memblock_alloc(phys_size, PAGE_SIZE);
452b0c4e27cSMike Rapoport (Microsoft) if (!phys_dist) {
453b0c4e27cSMike Rapoport (Microsoft) pr_warn("NUMA: Warning: can't allocate copy of distance table, disabling emulation\n");
454b0c4e27cSMike Rapoport (Microsoft) goto no_emu;
455b0c4e27cSMike Rapoport (Microsoft) }
456b0c4e27cSMike Rapoport (Microsoft)
457b0c4e27cSMike Rapoport (Microsoft) for (i = 0; i < numa_dist_cnt; i++)
458b0c4e27cSMike Rapoport (Microsoft) for (j = 0; j < numa_dist_cnt; j++)
459b0c4e27cSMike Rapoport (Microsoft) phys_dist[i * numa_dist_cnt + j] =
460b0c4e27cSMike Rapoport (Microsoft) node_distance(i, j);
461b0c4e27cSMike Rapoport (Microsoft) }
462b0c4e27cSMike Rapoport (Microsoft)
463b0c4e27cSMike Rapoport (Microsoft) /*
464b0c4e27cSMike Rapoport (Microsoft) * Determine the max emulated nid and the default phys nid to use
465b0c4e27cSMike Rapoport (Microsoft) * for unmapped nodes.
466b0c4e27cSMike Rapoport (Microsoft) */
467b0c4e27cSMike Rapoport (Microsoft) max_emu_nid = setup_emu2phys_nid(&dfl_phys_nid);
468b0c4e27cSMike Rapoport (Microsoft)
469b0c4e27cSMike Rapoport (Microsoft) /* Make sure numa_nodes_parsed only contains emulated nodes */
470b0c4e27cSMike Rapoport (Microsoft) nodes_clear(numa_nodes_parsed);
471b0c4e27cSMike Rapoport (Microsoft) for (i = 0; i < ARRAY_SIZE(ei.blk); i++)
472b0c4e27cSMike Rapoport (Microsoft) if (ei.blk[i].start != ei.blk[i].end &&
473b0c4e27cSMike Rapoport (Microsoft) ei.blk[i].nid != NUMA_NO_NODE)
474b0c4e27cSMike Rapoport (Microsoft) node_set(ei.blk[i].nid, numa_nodes_parsed);
475b0c4e27cSMike Rapoport (Microsoft)
47663db8170SBruno Faccini /* fix pxm_to_node_map[] and node_to_pxm_map[] to avoid collision
47763db8170SBruno Faccini * with faked numa nodes, particularly during later memory hotplug
47863db8170SBruno Faccini * handling, and also update numa_nodes_parsed accordingly.
47963db8170SBruno Faccini */
48063db8170SBruno Faccini ret = fix_pxm_node_maps(max_emu_nid);
48163db8170SBruno Faccini if (ret < 0)
48263db8170SBruno Faccini goto no_emu;
48363db8170SBruno Faccini
48463db8170SBruno Faccini /* commit */
48563db8170SBruno Faccini *numa_meminfo = ei;
48663db8170SBruno Faccini
48763db8170SBruno Faccini numa_emu_update_cpu_to_node(emu_nid_to_phys, max_emu_nid + 1);
488b0c4e27cSMike Rapoport (Microsoft)
489b0c4e27cSMike Rapoport (Microsoft) /* make sure all emulated nodes are mapped to a physical node */
49063db8170SBruno Faccini for (i = 0; i < max_emu_nid + 1; i++)
491b0c4e27cSMike Rapoport (Microsoft) if (emu_nid_to_phys[i] == NUMA_NO_NODE)
492b0c4e27cSMike Rapoport (Microsoft) emu_nid_to_phys[i] = dfl_phys_nid;
493b0c4e27cSMike Rapoport (Microsoft)
494b0c4e27cSMike Rapoport (Microsoft) /* transform distance table */
495b0c4e27cSMike Rapoport (Microsoft) numa_reset_distance();
496b0c4e27cSMike Rapoport (Microsoft) for (i = 0; i < max_emu_nid + 1; i++) {
497b0c4e27cSMike Rapoport (Microsoft) for (j = 0; j < max_emu_nid + 1; j++) {
498b0c4e27cSMike Rapoport (Microsoft) int physi = emu_nid_to_phys[i];
499b0c4e27cSMike Rapoport (Microsoft) int physj = emu_nid_to_phys[j];
500b0c4e27cSMike Rapoport (Microsoft) int dist;
501b0c4e27cSMike Rapoport (Microsoft)
502b0c4e27cSMike Rapoport (Microsoft) if (get_option(&emu_cmdline, &dist) == 2)
503b0c4e27cSMike Rapoport (Microsoft) ;
504b0c4e27cSMike Rapoport (Microsoft) else if (physi >= numa_dist_cnt || physj >= numa_dist_cnt)
505b0c4e27cSMike Rapoport (Microsoft) dist = physi == physj ?
506b0c4e27cSMike Rapoport (Microsoft) LOCAL_DISTANCE : REMOTE_DISTANCE;
507b0c4e27cSMike Rapoport (Microsoft) else
508b0c4e27cSMike Rapoport (Microsoft) dist = phys_dist[physi * numa_dist_cnt + physj];
509b0c4e27cSMike Rapoport (Microsoft)
510b0c4e27cSMike Rapoport (Microsoft) numa_set_distance(i, j, dist);
511b0c4e27cSMike Rapoport (Microsoft) }
512b0c4e27cSMike Rapoport (Microsoft) }
51363db8170SBruno Faccini for (i = 0; i < numa_distance_cnt; i++) {
51463db8170SBruno Faccini for (j = 0; j < numa_distance_cnt; j++) {
51563db8170SBruno Faccini int physi, physj;
51663db8170SBruno Faccini u8 dist;
51763db8170SBruno Faccini
51863db8170SBruno Faccini /* distance between fake nodes is already ok */
51963db8170SBruno Faccini if (emu_nid_to_phys[i] != NUMA_NO_NODE &&
52063db8170SBruno Faccini emu_nid_to_phys[j] != NUMA_NO_NODE)
52163db8170SBruno Faccini continue;
52263db8170SBruno Faccini if (emu_nid_to_phys[i] != NUMA_NO_NODE)
52363db8170SBruno Faccini physi = emu_nid_to_phys[i];
52463db8170SBruno Faccini else
52563db8170SBruno Faccini physi = i - max_emu_nid;
52663db8170SBruno Faccini if (emu_nid_to_phys[j] != NUMA_NO_NODE)
52763db8170SBruno Faccini physj = emu_nid_to_phys[j];
52863db8170SBruno Faccini else
52963db8170SBruno Faccini physj = j - max_emu_nid;
53063db8170SBruno Faccini dist = phys_dist[physi * numa_dist_cnt + physj];
53163db8170SBruno Faccini numa_set_distance(i, j, dist);
53263db8170SBruno Faccini }
53363db8170SBruno Faccini }
534b0c4e27cSMike Rapoport (Microsoft)
535b0c4e27cSMike Rapoport (Microsoft) /* free the copied physical distance table */
536b0c4e27cSMike Rapoport (Microsoft) memblock_free(phys_dist, phys_size);
537b0c4e27cSMike Rapoport (Microsoft) return;
538b0c4e27cSMike Rapoport (Microsoft)
539b0c4e27cSMike Rapoport (Microsoft) no_emu:
54063db8170SBruno Faccini numa_nodes_parsed = physnode_mask;
541b0c4e27cSMike Rapoport (Microsoft) /* No emulation. Build identity emu_nid_to_phys[] for numa_add_cpu() */
542b0c4e27cSMike Rapoport (Microsoft) for (i = 0; i < ARRAY_SIZE(emu_nid_to_phys); i++)
543b0c4e27cSMike Rapoport (Microsoft) emu_nid_to_phys[i] = i;
544b0c4e27cSMike Rapoport (Microsoft) }
545b0c4e27cSMike Rapoport (Microsoft)
546b0c4e27cSMike Rapoport (Microsoft) #ifndef CONFIG_DEBUG_PER_CPU_MAPS
numa_add_cpu(unsigned int cpu)547b0c4e27cSMike Rapoport (Microsoft) void numa_add_cpu(unsigned int cpu)
548b0c4e27cSMike Rapoport (Microsoft) {
549b0c4e27cSMike Rapoport (Microsoft) int physnid, nid;
550b0c4e27cSMike Rapoport (Microsoft)
551b0c4e27cSMike Rapoport (Microsoft) nid = early_cpu_to_node(cpu);
552b0c4e27cSMike Rapoport (Microsoft) BUG_ON(nid == NUMA_NO_NODE || !node_online(nid));
553b0c4e27cSMike Rapoport (Microsoft)
554b0c4e27cSMike Rapoport (Microsoft) physnid = emu_nid_to_phys[nid];
555b0c4e27cSMike Rapoport (Microsoft)
556b0c4e27cSMike Rapoport (Microsoft) /*
557b0c4e27cSMike Rapoport (Microsoft) * Map the cpu to each emulated node that is allocated on the physical
558b0c4e27cSMike Rapoport (Microsoft) * node of the cpu's apic id.
559b0c4e27cSMike Rapoport (Microsoft) */
560b0c4e27cSMike Rapoport (Microsoft) for_each_online_node(nid)
561b0c4e27cSMike Rapoport (Microsoft) if (emu_nid_to_phys[nid] == physnid)
562b0c4e27cSMike Rapoport (Microsoft) cpumask_set_cpu(cpu, node_to_cpumask_map[nid]);
563b0c4e27cSMike Rapoport (Microsoft) }
564b0c4e27cSMike Rapoport (Microsoft)
numa_remove_cpu(unsigned int cpu)565b0c4e27cSMike Rapoport (Microsoft) void numa_remove_cpu(unsigned int cpu)
566b0c4e27cSMike Rapoport (Microsoft) {
567b0c4e27cSMike Rapoport (Microsoft) int i;
568b0c4e27cSMike Rapoport (Microsoft)
569b0c4e27cSMike Rapoport (Microsoft) for_each_online_node(i)
570b0c4e27cSMike Rapoport (Microsoft) cpumask_clear_cpu(cpu, node_to_cpumask_map[i]);
571b0c4e27cSMike Rapoport (Microsoft) }
572b0c4e27cSMike Rapoport (Microsoft) #else /* !CONFIG_DEBUG_PER_CPU_MAPS */
numa_set_cpumask(unsigned int cpu,bool enable)573b0c4e27cSMike Rapoport (Microsoft) static void numa_set_cpumask(unsigned int cpu, bool enable)
574b0c4e27cSMike Rapoport (Microsoft) {
575b0c4e27cSMike Rapoport (Microsoft) int nid, physnid;
576b0c4e27cSMike Rapoport (Microsoft)
577b0c4e27cSMike Rapoport (Microsoft) nid = early_cpu_to_node(cpu);
578b0c4e27cSMike Rapoport (Microsoft) if (nid == NUMA_NO_NODE) {
579b0c4e27cSMike Rapoport (Microsoft) /* early_cpu_to_node() already emits a warning and trace */
580b0c4e27cSMike Rapoport (Microsoft) return;
581b0c4e27cSMike Rapoport (Microsoft) }
582b0c4e27cSMike Rapoport (Microsoft)
583b0c4e27cSMike Rapoport (Microsoft) physnid = emu_nid_to_phys[nid];
584b0c4e27cSMike Rapoport (Microsoft)
585b0c4e27cSMike Rapoport (Microsoft) for_each_online_node(nid) {
586b0c4e27cSMike Rapoport (Microsoft) if (emu_nid_to_phys[nid] != physnid)
587b0c4e27cSMike Rapoport (Microsoft) continue;
588b0c4e27cSMike Rapoport (Microsoft)
589b0c4e27cSMike Rapoport (Microsoft) debug_cpumask_set_cpu(cpu, nid, enable);
590b0c4e27cSMike Rapoport (Microsoft) }
591b0c4e27cSMike Rapoport (Microsoft) }
592b0c4e27cSMike Rapoport (Microsoft)
numa_add_cpu(unsigned int cpu)593b0c4e27cSMike Rapoport (Microsoft) void numa_add_cpu(unsigned int cpu)
594b0c4e27cSMike Rapoport (Microsoft) {
595b0c4e27cSMike Rapoport (Microsoft) numa_set_cpumask(cpu, true);
596b0c4e27cSMike Rapoport (Microsoft) }
597b0c4e27cSMike Rapoport (Microsoft)
numa_remove_cpu(unsigned int cpu)598b0c4e27cSMike Rapoport (Microsoft) void numa_remove_cpu(unsigned int cpu)
599b0c4e27cSMike Rapoport (Microsoft) {
600b0c4e27cSMike Rapoport (Microsoft) numa_set_cpumask(cpu, false);
601b0c4e27cSMike Rapoport (Microsoft) }
602b0c4e27cSMike Rapoport (Microsoft) #endif /* !CONFIG_DEBUG_PER_CPU_MAPS */
603