blob: a1d702d2584c08712a6f1b14247b553fd4e0d07d [file] [log] [blame]
Thomas Gleixnere3cfe522008-01-30 13:30:37 +01001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Generic VM initialization for x86-64 NUMA setups.
3 * Copyright 2002,2003 Andi Kleen, SuSE Labs.
Thomas Gleixnere3cfe522008-01-30 13:30:37 +01004 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/kernel.h>
6#include <linux/mm.h>
7#include <linux/string.h>
8#include <linux/init.h>
9#include <linux/bootmem.h>
Yinghai Lu72d7c3b2010-08-25 13:39:17 -070010#include <linux/memblock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/mmzone.h>
12#include <linux/ctype.h>
13#include <linux/module.h>
14#include <linux/nodemask.h>
travis@sgi.com3cc87e32008-01-30 13:33:11 +010015#include <linux/sched.h>
Tejun Heod8fc3af2011-02-16 12:13:06 +010016#include <linux/acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#include <asm/e820.h>
19#include <asm/proto.h>
20#include <asm/dma.h>
21#include <asm/numa.h>
22#include <asm/acpi.h>
Andreas Herrmann23ac4ae2010-09-17 18:03:43 +020023#include <asm/amd_nb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Ravikiran G Thirumalai6c231b72005-09-06 15:17:45 -070025struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +010026EXPORT_SYMBOL(node_data);
27
Tejun Heoec8cf29b2011-02-16 12:13:07 +010028nodemask_t cpu_nodes_parsed __initdata;
29nodemask_t mem_nodes_parsed __initdata;
30
Eric Dumazetdcf36bf2006-03-25 16:31:46 +010031struct memnode memnode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Thomas Gleixner864fc312008-05-12 15:43:36 +020033static unsigned long __initdata nodemap_addr;
34static unsigned long __initdata nodemap_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Tejun Heoef396ec2011-02-16 17:11:07 +010036static int num_node_memblks __initdata;
37static struct bootnode node_memblk_range[NR_NODE_MEMBLKS] __initdata;
38static int memblk_nodeid[NR_NODE_MEMBLKS] __initdata;
39
Tejun Heo206e4202011-02-16 12:13:07 +010040struct bootnode numa_nodes[MAX_NUMNODES] __initdata;
41
Brian Gerst6470aff2009-01-27 12:56:47 +090042/*
Eric Dumazet529a3402005-11-05 17:25:54 +010043 * Given a shift value, try to populate memnodemap[]
44 * Returns :
45 * 1 if OK
46 * 0 if memnodmap[] too small (of shift too small)
47 * -1 if node overlap or lost ram (shift too big)
48 */
Thomas Gleixnere3cfe522008-01-30 13:30:37 +010049static int __init populate_memnodemap(const struct bootnode *nodes,
Suresh Siddha6ec6e0d2008-03-25 10:14:35 -070050 int numnodes, int shift, int *nodeids)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Eric Dumazet529a3402005-11-05 17:25:54 +010052 unsigned long addr, end;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +010053 int i, res = -1;
Keith Manntheyb6846642005-07-28 21:15:38 -070054
travis@sgi.com43238382008-01-30 13:33:25 +010055 memset(memnodemap, 0xff, sizeof(s16)*memnodemapsize);
Eric Dumazet529a3402005-11-05 17:25:54 +010056 for (i = 0; i < numnodes; i++) {
57 addr = nodes[i].start;
58 end = nodes[i].end;
59 if (addr >= end)
60 continue;
Amul Shah076422d2007-02-13 13:26:19 +010061 if ((end >> shift) >= memnodemapsize)
Eric Dumazet529a3402005-11-05 17:25:54 +010062 return 0;
63 do {
travis@sgi.com43238382008-01-30 13:33:25 +010064 if (memnodemap[addr >> shift] != NUMA_NO_NODE)
Eric Dumazet529a3402005-11-05 17:25:54 +010065 return -1;
Suresh Siddha6ec6e0d2008-03-25 10:14:35 -070066
67 if (!nodeids)
68 memnodemap[addr >> shift] = i;
69 else
70 memnodemap[addr >> shift] = nodeids[i];
71
Amul Shah076422d2007-02-13 13:26:19 +010072 addr += (1UL << shift);
Eric Dumazet529a3402005-11-05 17:25:54 +010073 } while (addr < end);
74 res = 1;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +010075 }
Eric Dumazet529a3402005-11-05 17:25:54 +010076 return res;
77}
78
Amul Shah076422d2007-02-13 13:26:19 +010079static int __init allocate_cachealigned_memnodemap(void)
80{
Yinghai Lu24a5da72008-02-01 17:49:41 +010081 unsigned long addr;
Amul Shah076422d2007-02-13 13:26:19 +010082
83 memnodemap = memnode.embedded_map;
travis@sgi.com316390b2008-01-30 13:33:15 +010084 if (memnodemapsize <= ARRAY_SIZE(memnode.embedded_map))
Amul Shah076422d2007-02-13 13:26:19 +010085 return 0;
Amul Shah076422d2007-02-13 13:26:19 +010086
Yinghai Lu24a5da72008-02-01 17:49:41 +010087 addr = 0x8000;
Joerg Roedelbe3e89e2008-07-25 16:48:58 +020088 nodemap_size = roundup(sizeof(s16) * memnodemapsize, L1_CACHE_BYTES);
Yinghai Ludbef7b52010-12-27 16:48:08 -080089 nodemap_addr = memblock_find_in_range(addr, get_max_mapped(),
Yinghai Lu24a5da72008-02-01 17:49:41 +010090 nodemap_size, L1_CACHE_BYTES);
Yinghai Lua9ce6bc2010-08-25 13:39:17 -070091 if (nodemap_addr == MEMBLOCK_ERROR) {
Amul Shah076422d2007-02-13 13:26:19 +010092 printk(KERN_ERR
93 "NUMA: Unable to allocate Memory to Node hash map\n");
94 nodemap_addr = nodemap_size = 0;
95 return -1;
96 }
Yinghai Lu24a5da72008-02-01 17:49:41 +010097 memnodemap = phys_to_virt(nodemap_addr);
Yinghai Lua9ce6bc2010-08-25 13:39:17 -070098 memblock_x86_reserve_range(nodemap_addr, nodemap_addr + nodemap_size, "MEMNODEMAP");
Amul Shah076422d2007-02-13 13:26:19 +010099
100 printk(KERN_DEBUG "NUMA: Allocated memnodemap from %lx - %lx\n",
101 nodemap_addr, nodemap_addr + nodemap_size);
102 return 0;
103}
104
105/*
106 * The LSB of all start and end addresses in the node map is the value of the
107 * maximum possible shift.
108 */
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100109static int __init extract_lsb_from_nodes(const struct bootnode *nodes,
110 int numnodes)
Amul Shah076422d2007-02-13 13:26:19 +0100111{
Amul Shah54413922007-02-13 13:26:20 +0100112 int i, nodes_used = 0;
Amul Shah076422d2007-02-13 13:26:19 +0100113 unsigned long start, end;
114 unsigned long bitfield = 0, memtop = 0;
115
116 for (i = 0; i < numnodes; i++) {
117 start = nodes[i].start;
118 end = nodes[i].end;
119 if (start >= end)
120 continue;
Amul Shah54413922007-02-13 13:26:20 +0100121 bitfield |= start;
122 nodes_used++;
Amul Shah076422d2007-02-13 13:26:19 +0100123 if (end > memtop)
124 memtop = end;
125 }
Amul Shah54413922007-02-13 13:26:20 +0100126 if (nodes_used <= 1)
127 i = 63;
128 else
129 i = find_first_bit(&bitfield, sizeof(unsigned long)*8);
Amul Shah076422d2007-02-13 13:26:19 +0100130 memnodemapsize = (memtop >> i)+1;
131 return i;
132}
133
Suresh Siddha6ec6e0d2008-03-25 10:14:35 -0700134int __init compute_hash_shift(struct bootnode *nodes, int numnodes,
135 int *nodeids)
Eric Dumazet529a3402005-11-05 17:25:54 +0100136{
Amul Shah076422d2007-02-13 13:26:19 +0100137 int shift;
Eric Dumazet529a3402005-11-05 17:25:54 +0100138
Amul Shah076422d2007-02-13 13:26:19 +0100139 shift = extract_lsb_from_nodes(nodes, numnodes);
140 if (allocate_cachealigned_memnodemap())
141 return -1;
Andi Kleen6b050f82006-01-11 22:44:33 +0100142 printk(KERN_DEBUG "NUMA: Using %d for the hash shift.\n",
Eric Dumazet529a3402005-11-05 17:25:54 +0100143 shift);
144
Suresh Siddha6ec6e0d2008-03-25 10:14:35 -0700145 if (populate_memnodemap(nodes, numnodes, shift, nodeids) != 1) {
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100146 printk(KERN_INFO "Your memory is not aligned you need to "
147 "rebuild your kernel with a bigger NODEMAPSIZE "
148 "shift=%d\n", shift);
Eric Dumazet529a3402005-11-05 17:25:54 +0100149 return -1;
150 }
Keith Manntheyb6846642005-07-28 21:15:38 -0700151 return shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
KAMEZAWA Hiroyukif2dbcfa2009-02-18 14:48:32 -0800154int __meminit __early_pfn_to_nid(unsigned long pfn)
Matt Tolentinobbfceef2005-06-23 00:08:07 -0700155{
156 return phys_to_nid(pfn << PAGE_SHIFT);
157}
Matt Tolentinobbfceef2005-06-23 00:08:07 -0700158
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100159static void * __init early_node_mem(int nodeid, unsigned long start,
Yinghai Lu24a5da72008-02-01 17:49:41 +0100160 unsigned long end, unsigned long size,
161 unsigned long align)
Andi Kleena8062232006-04-07 19:49:21 +0200162{
Yinghai Lucef625e2010-02-10 01:20:18 -0800163 unsigned long mem;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100164
Yinghai Lucef625e2010-02-10 01:20:18 -0800165 /*
166 * put it on high as possible
167 * something will go with NODE_DATA
168 */
169 if (start < (MAX_DMA_PFN<<PAGE_SHIFT))
170 start = MAX_DMA_PFN<<PAGE_SHIFT;
171 if (start < (MAX_DMA32_PFN<<PAGE_SHIFT) &&
172 end > (MAX_DMA32_PFN<<PAGE_SHIFT))
173 start = MAX_DMA32_PFN<<PAGE_SHIFT;
Yinghai Lu72d7c3b2010-08-25 13:39:17 -0700174 mem = memblock_x86_find_in_range_node(nodeid, start, end, size, align);
175 if (mem != MEMBLOCK_ERROR)
Andi Kleena8062232006-04-07 19:49:21 +0200176 return __va(mem);
Yinghai Lu9347e0b2008-02-01 17:49:42 +0100177
Yinghai Lucef625e2010-02-10 01:20:18 -0800178 /* extend the search scope */
179 end = max_pfn_mapped << PAGE_SHIFT;
Yinghai Lu419db272010-10-28 09:50:17 -0700180 start = MAX_DMA_PFN << PAGE_SHIFT;
181 mem = memblock_find_in_range(start, end, size, align);
Yinghai Lu72d7c3b2010-08-25 13:39:17 -0700182 if (mem != MEMBLOCK_ERROR)
Yinghai Lu1842f902010-02-10 01:20:15 -0800183 return __va(mem);
184
185 printk(KERN_ERR "Cannot find %lu bytes in node %d\n",
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100186 size, nodeid);
Yinghai Lu1842f902010-02-10 01:20:15 -0800187
188 return NULL;
Andi Kleena8062232006-04-07 19:49:21 +0200189}
190
Tejun Heoef396ec2011-02-16 17:11:07 +0100191static __init int conflicting_memblks(unsigned long start, unsigned long end)
192{
193 int i;
194 for (i = 0; i < num_node_memblks; i++) {
195 struct bootnode *nd = &node_memblk_range[i];
196 if (nd->start == nd->end)
197 continue;
198 if (nd->end > start && nd->start < end)
199 return memblk_nodeid[i];
200 if (nd->end == end && nd->start == start)
201 return memblk_nodeid[i];
202 }
203 return -1;
204}
205
206int __init numa_add_memblk(int nid, u64 start, u64 end)
207{
208 int i;
209
210 i = conflicting_memblks(start, end);
211 if (i == nid) {
212 printk(KERN_WARNING "NUMA: Warning: node %d (%Lx-%Lx) overlaps with itself (%Lx-%Lx)\n",
213 nid, start, end, numa_nodes[i].start, numa_nodes[i].end);
214 } else if (i >= 0) {
215 printk(KERN_ERR "NUMA: node %d (%Lx-%Lx) overlaps with node %d (%Lx-%Lx)\n",
216 nid, start, end, i,
217 numa_nodes[i].start, numa_nodes[i].end);
218 return -EINVAL;
219 }
220
221 node_memblk_range[num_node_memblks].start = start;
222 node_memblk_range[num_node_memblks].end = end;
223 memblk_nodeid[num_node_memblks] = nid;
224 num_node_memblks++;
225 return 0;
226}
227
Tejun Heo206e4202011-02-16 12:13:07 +0100228static __init void cutoff_node(int i, unsigned long start, unsigned long end)
229{
230 struct bootnode *nd = &numa_nodes[i];
231
232 if (nd->start < start) {
233 nd->start = start;
234 if (nd->end < nd->start)
235 nd->start = nd->end;
236 }
237 if (nd->end > end) {
238 nd->end = end;
239 if (nd->start > nd->end)
240 nd->start = nd->end;
241 }
242}
243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244/* Initialize bootmem allocator for a node */
Yinghai Lu7c437692009-05-15 13:59:37 -0700245void __init
246setup_node_bootmem(int nodeid, unsigned long start, unsigned long end)
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100247{
Yinghai Lu08677212010-02-10 01:20:20 -0800248 unsigned long start_pfn, last_pfn, nodedata_phys;
Yinghai Lu7c437692009-05-15 13:59:37 -0700249 const int pgdat_size = roundup(sizeof(pg_data_t), PAGE_SIZE);
Yinghai Lu1a27fc02008-03-18 12:52:37 -0700250 int nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Yinghai Lu4c31e922009-04-22 14:19:27 -0700252 if (!end)
253 return;
254
Yinghai Lu7c437692009-05-15 13:59:37 -0700255 /*
256 * Don't confuse VM with a node that doesn't have the
257 * minimum amount of memory:
258 */
259 if (end && (end - start) < NODE_MIN_SIZE)
260 return;
261
Joerg Roedelbe3e89e2008-07-25 16:48:58 +0200262 start = roundup(start, ZONE_ALIGN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Yinghai Lu08677212010-02-10 01:20:20 -0800264 printk(KERN_INFO "Initmem setup node %d %016lx-%016lx\n", nodeid,
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100265 start, end);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 start_pfn = start >> PAGE_SHIFT;
Thomas Gleixner886533a2008-05-12 15:43:36 +0200268 last_pfn = end >> PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Yinghai Lu24a5da72008-02-01 17:49:41 +0100270 node_data[nodeid] = early_node_mem(nodeid, start, end, pgdat_size,
271 SMP_CACHE_BYTES);
Andi Kleena8062232006-04-07 19:49:21 +0200272 if (node_data[nodeid] == NULL)
273 return;
274 nodedata_phys = __pa(node_data[nodeid]);
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700275 memblock_x86_reserve_range(nodedata_phys, nodedata_phys + pgdat_size, "NODE_DATA");
Yinghai Lu6118f762008-02-04 16:47:56 +0100276 printk(KERN_INFO " NODE_DATA [%016lx - %016lx]\n", nodedata_phys,
277 nodedata_phys + pgdat_size - 1);
Yinghai Lu1842f902010-02-10 01:20:15 -0800278 nid = phys_to_nid(nodedata_phys);
279 if (nid != nodeid)
280 printk(KERN_INFO " NODE_DATA(%d) on node %d\n", nodeid, nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 memset(NODE_DATA(nodeid), 0, sizeof(pg_data_t));
Yinghai Lu08677212010-02-10 01:20:20 -0800283 NODE_DATA(nodeid)->node_id = nodeid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 NODE_DATA(nodeid)->node_start_pfn = start_pfn;
Thomas Gleixner886533a2008-05-12 15:43:36 +0200285 NODE_DATA(nodeid)->node_spanned_pages = last_pfn - start_pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 node_set_online(nodeid);
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100288}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Tejun Heoef396ec2011-02-16 17:11:07 +0100290int __init numa_register_memblks(void)
291{
292 int i;
293
294 /*
295 * Join together blocks on the same node, holes between
296 * which don't overlap with memory on other nodes.
297 */
298 for (i = 0; i < num_node_memblks; ++i) {
299 int j, k;
300
301 for (j = i + 1; j < num_node_memblks; ++j) {
302 unsigned long start, end;
303
304 if (memblk_nodeid[i] != memblk_nodeid[j])
305 continue;
306 start = min(node_memblk_range[i].end,
307 node_memblk_range[j].end);
308 end = max(node_memblk_range[i].start,
309 node_memblk_range[j].start);
310 for (k = 0; k < num_node_memblks; ++k) {
311 if (memblk_nodeid[i] == memblk_nodeid[k])
312 continue;
313 if (start < node_memblk_range[k].end &&
314 end > node_memblk_range[k].start)
315 break;
316 }
317 if (k < num_node_memblks)
318 continue;
319 start = min(node_memblk_range[i].start,
320 node_memblk_range[j].start);
321 end = max(node_memblk_range[i].end,
322 node_memblk_range[j].end);
323 printk(KERN_INFO "NUMA: Node %d [%Lx,%Lx) + [%Lx,%Lx) -> [%lx,%lx)\n",
324 memblk_nodeid[i],
325 node_memblk_range[i].start,
326 node_memblk_range[i].end,
327 node_memblk_range[j].start,
328 node_memblk_range[j].end,
329 start, end);
330 node_memblk_range[i].start = start;
331 node_memblk_range[i].end = end;
332 k = --num_node_memblks - j;
333 memmove(memblk_nodeid + j, memblk_nodeid + j+1,
334 k * sizeof(*memblk_nodeid));
335 memmove(node_memblk_range + j, node_memblk_range + j+1,
336 k * sizeof(*node_memblk_range));
337 --j;
338 }
339 }
340
341 memnode_shift = compute_hash_shift(node_memblk_range, num_node_memblks,
342 memblk_nodeid);
343 if (memnode_shift < 0) {
344 printk(KERN_ERR "NUMA: No NUMA node hash function found. Contact maintainer\n");
345 return -EINVAL;
346 }
347
348 for (i = 0; i < num_node_memblks; i++)
349 memblock_x86_register_active_regions(memblk_nodeid[i],
350 node_memblk_range[i].start >> PAGE_SHIFT,
351 node_memblk_range[i].end >> PAGE_SHIFT);
352 return 0;
353}
354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355#ifdef CONFIG_NUMA_EMU
Rohit Seth53fee042007-02-13 13:26:22 +0100356/* Numa emulation */
David Rientjesadc19382009-09-25 15:20:09 -0700357static struct bootnode nodes[MAX_NUMNODES] __initdata;
David Rientjesc1c34432010-12-22 17:23:54 -0800358static struct bootnode physnodes[MAX_NUMNODES] __cpuinitdata;
Thomas Gleixner864fc312008-05-12 15:43:36 +0200359static char *cmdline __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Jan Beulich90321602011-01-19 08:57:21 +0000361void __init numa_emu_cmdline(char *str)
362{
363 cmdline = str;
364}
365
Tejun Heo190955482011-02-16 12:13:07 +0100366static int __init setup_physnodes(unsigned long start, unsigned long end)
David Rientjesadc19382009-09-25 15:20:09 -0700367{
David Rientjesadc19382009-09-25 15:20:09 -0700368 int ret = 0;
369 int i;
370
David Rientjesc1c34432010-12-22 17:23:54 -0800371 memset(physnodes, 0, sizeof(physnodes));
Tejun Heo190955482011-02-16 12:13:07 +0100372
373 for_each_node_mask(i, mem_nodes_parsed) {
374 physnodes[i].start = numa_nodes[i].start;
375 physnodes[i].end = numa_nodes[i].end;
376 }
377
David Rientjesadc19382009-09-25 15:20:09 -0700378 /*
379 * Basic sanity checking on the physical node map: there may be errors
Hans Rosenfeldeec1d4f2010-10-29 17:14:30 +0200380 * if the SRAT or AMD code incorrectly reported the topology or the mem=
David Rientjesadc19382009-09-25 15:20:09 -0700381 * kernel parameter is used.
382 */
David Rientjesa387e952010-12-22 17:23:56 -0800383 for (i = 0; i < MAX_NUMNODES; i++) {
David Rientjesadc19382009-09-25 15:20:09 -0700384 if (physnodes[i].start == physnodes[i].end)
385 continue;
386 if (physnodes[i].start > end) {
387 physnodes[i].end = physnodes[i].start;
388 continue;
389 }
390 if (physnodes[i].end < start) {
391 physnodes[i].start = physnodes[i].end;
392 continue;
393 }
394 if (physnodes[i].start < start)
395 physnodes[i].start = start;
396 if (physnodes[i].end > end)
397 physnodes[i].end = end;
David Rientjesadc19382009-09-25 15:20:09 -0700398 ret++;
399 }
400
401 /*
402 * If no physical topology was detected, a single node is faked to cover
403 * the entire address space.
404 */
405 if (!ret) {
406 physnodes[ret].start = start;
407 physnodes[ret].end = end;
408 ret = 1;
409 }
410 return ret;
411}
412
David Rientjesf51bf302010-12-22 17:23:51 -0800413static void __init fake_physnodes(int acpi, int amd, int nr_nodes)
414{
415 int i;
416
417 BUG_ON(acpi && amd);
418#ifdef CONFIG_ACPI_NUMA
419 if (acpi)
420 acpi_fake_nodes(nodes, nr_nodes);
421#endif
422#ifdef CONFIG_AMD_NUMA
423 if (amd)
424 amd_fake_nodes(nodes, nr_nodes);
425#endif
426 if (!acpi && !amd)
427 for (i = 0; i < nr_cpu_ids; i++)
428 numa_set_node(i, 0);
429}
430
Rohit Seth53fee042007-02-13 13:26:22 +0100431/*
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100432 * Setups up nid to range from addr to addr + size. If the end
433 * boundary is greater than max_addr, then max_addr is used instead.
434 * The return value is 0 if there is additional memory left for
435 * allocation past addr and -1 otherwise. addr is adjusted to be at
436 * the end of the node.
Rohit Seth53fee042007-02-13 13:26:22 +0100437 */
David Rientjesadc19382009-09-25 15:20:09 -0700438static int __init setup_node_range(int nid, u64 *addr, u64 size, u64 max_addr)
Rohit Seth53fee042007-02-13 13:26:22 +0100439{
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200440 int ret = 0;
441 nodes[nid].start = *addr;
442 *addr += size;
443 if (*addr >= max_addr) {
444 *addr = max_addr;
445 ret = -1;
446 }
447 nodes[nid].end = *addr;
Suresh Siddhae3f1cae2007-05-02 19:27:20 +0200448 node_set(nid, node_possible_map);
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200449 printk(KERN_INFO "Faking node %d at %016Lx-%016Lx (%LuMB)\n", nid,
450 nodes[nid].start, nodes[nid].end,
451 (nodes[nid].end - nodes[nid].start) >> 20);
452 return ret;
Rohit Seth53fee042007-02-13 13:26:22 +0100453}
454
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200455/*
David Rientjesadc19382009-09-25 15:20:09 -0700456 * Sets up nr_nodes fake nodes interleaved over physical nodes ranging from addr
457 * to max_addr. The return value is the number of nodes allocated.
458 */
David Rientjesc1c34432010-12-22 17:23:54 -0800459static int __init split_nodes_interleave(u64 addr, u64 max_addr, int nr_nodes)
David Rientjesadc19382009-09-25 15:20:09 -0700460{
461 nodemask_t physnode_mask = NODE_MASK_NONE;
462 u64 size;
463 int big;
464 int ret = 0;
465 int i;
466
467 if (nr_nodes <= 0)
468 return -1;
469 if (nr_nodes > MAX_NUMNODES) {
470 pr_info("numa=fake=%d too large, reducing to %d\n",
471 nr_nodes, MAX_NUMNODES);
472 nr_nodes = MAX_NUMNODES;
473 }
474
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700475 size = (max_addr - addr - memblock_x86_hole_size(addr, max_addr)) / nr_nodes;
David Rientjesadc19382009-09-25 15:20:09 -0700476 /*
477 * Calculate the number of big nodes that can be allocated as a result
478 * of consolidating the remainder.
479 */
David Rientjes68fd1112010-02-15 13:43:25 -0800480 big = ((size & ~FAKE_NODE_MIN_HASH_MASK) * nr_nodes) /
David Rientjesadc19382009-09-25 15:20:09 -0700481 FAKE_NODE_MIN_SIZE;
482
483 size &= FAKE_NODE_MIN_HASH_MASK;
484 if (!size) {
485 pr_err("Not enough memory for each node. "
486 "NUMA emulation disabled.\n");
487 return -1;
488 }
489
David Rientjesc1c34432010-12-22 17:23:54 -0800490 for (i = 0; i < MAX_NUMNODES; i++)
David Rientjesadc19382009-09-25 15:20:09 -0700491 if (physnodes[i].start != physnodes[i].end)
492 node_set(i, physnode_mask);
493
494 /*
495 * Continue to fill physical nodes with fake nodes until there is no
496 * memory left on any of them.
497 */
498 while (nodes_weight(physnode_mask)) {
499 for_each_node_mask(i, physnode_mask) {
500 u64 end = physnodes[i].start + size;
501 u64 dma32_end = PFN_PHYS(MAX_DMA32_PFN);
502
503 if (ret < big)
504 end += FAKE_NODE_MIN_SIZE;
505
506 /*
507 * Continue to add memory to this fake node if its
508 * non-reserved memory is less than the per-node size.
509 */
510 while (end - physnodes[i].start -
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700511 memblock_x86_hole_size(physnodes[i].start, end) < size) {
David Rientjesadc19382009-09-25 15:20:09 -0700512 end += FAKE_NODE_MIN_SIZE;
513 if (end > physnodes[i].end) {
514 end = physnodes[i].end;
515 break;
516 }
517 }
518
519 /*
520 * If there won't be at least FAKE_NODE_MIN_SIZE of
521 * non-reserved memory in ZONE_DMA32 for the next node,
522 * this one must extend to the boundary.
523 */
524 if (end < dma32_end && dma32_end - end -
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700525 memblock_x86_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
David Rientjesadc19382009-09-25 15:20:09 -0700526 end = dma32_end;
527
528 /*
529 * If there won't be enough non-reserved memory for the
530 * next node, this one must extend to the end of the
531 * physical node.
532 */
533 if (physnodes[i].end - end -
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700534 memblock_x86_hole_size(end, physnodes[i].end) < size)
David Rientjesadc19382009-09-25 15:20:09 -0700535 end = physnodes[i].end;
536
537 /*
538 * Avoid allocating more nodes than requested, which can
539 * happen as a result of rounding down each node's size
540 * to FAKE_NODE_MIN_SIZE.
541 */
542 if (nodes_weight(physnode_mask) + ret >= nr_nodes)
543 end = physnodes[i].end;
544
545 if (setup_node_range(ret++, &physnodes[i].start,
546 end - physnodes[i].start,
547 physnodes[i].end) < 0)
548 node_clear(i, physnode_mask);
549 }
550 }
551 return ret;
552}
553
554/*
David Rientjes8df5bb342010-02-15 13:43:30 -0800555 * Returns the end address of a node so that there is at least `size' amount of
556 * non-reserved memory or `max_addr' is reached.
557 */
558static u64 __init find_end_of_node(u64 start, u64 max_addr, u64 size)
559{
560 u64 end = start + size;
561
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700562 while (end - start - memblock_x86_hole_size(start, end) < size) {
David Rientjes8df5bb342010-02-15 13:43:30 -0800563 end += FAKE_NODE_MIN_SIZE;
564 if (end > max_addr) {
565 end = max_addr;
566 break;
567 }
568 }
569 return end;
570}
571
572/*
573 * Sets up fake nodes of `size' interleaved over physical nodes ranging from
574 * `addr' to `max_addr'. The return value is the number of nodes allocated.
575 */
576static int __init split_nodes_size_interleave(u64 addr, u64 max_addr, u64 size)
577{
578 nodemask_t physnode_mask = NODE_MASK_NONE;
579 u64 min_size;
580 int ret = 0;
581 int i;
582
583 if (!size)
584 return -1;
585 /*
586 * The limit on emulated nodes is MAX_NUMNODES, so the size per node is
587 * increased accordingly if the requested size is too small. This
588 * creates a uniform distribution of node sizes across the entire
589 * machine (but not necessarily over physical nodes).
590 */
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700591 min_size = (max_addr - addr - memblock_x86_hole_size(addr, max_addr)) /
David Rientjes8df5bb342010-02-15 13:43:30 -0800592 MAX_NUMNODES;
593 min_size = max(min_size, FAKE_NODE_MIN_SIZE);
594 if ((min_size & FAKE_NODE_MIN_HASH_MASK) < min_size)
595 min_size = (min_size + FAKE_NODE_MIN_SIZE) &
596 FAKE_NODE_MIN_HASH_MASK;
597 if (size < min_size) {
598 pr_err("Fake node size %LuMB too small, increasing to %LuMB\n",
599 size >> 20, min_size >> 20);
600 size = min_size;
601 }
602 size &= FAKE_NODE_MIN_HASH_MASK;
603
604 for (i = 0; i < MAX_NUMNODES; i++)
605 if (physnodes[i].start != physnodes[i].end)
606 node_set(i, physnode_mask);
607 /*
608 * Fill physical nodes with fake nodes of size until there is no memory
609 * left on any of them.
610 */
611 while (nodes_weight(physnode_mask)) {
612 for_each_node_mask(i, physnode_mask) {
613 u64 dma32_end = MAX_DMA32_PFN << PAGE_SHIFT;
614 u64 end;
615
616 end = find_end_of_node(physnodes[i].start,
617 physnodes[i].end, size);
618 /*
619 * If there won't be at least FAKE_NODE_MIN_SIZE of
620 * non-reserved memory in ZONE_DMA32 for the next node,
621 * this one must extend to the boundary.
622 */
623 if (end < dma32_end && dma32_end - end -
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700624 memblock_x86_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
David Rientjes8df5bb342010-02-15 13:43:30 -0800625 end = dma32_end;
626
627 /*
628 * If there won't be enough non-reserved memory for the
629 * next node, this one must extend to the end of the
630 * physical node.
631 */
632 if (physnodes[i].end - end -
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700633 memblock_x86_hole_size(end, physnodes[i].end) < size)
David Rientjes8df5bb342010-02-15 13:43:30 -0800634 end = physnodes[i].end;
635
636 /*
637 * Setup the fake node that will be allocated as bootmem
638 * later. If setup_node_range() returns non-zero, there
639 * is no more memory available on this physical node.
640 */
641 if (setup_node_range(ret++, &physnodes[i].start,
642 end - physnodes[i].start,
643 physnodes[i].end) < 0)
644 node_clear(i, physnode_mask);
645 }
646 }
647 return ret;
648}
649
650/*
Thomas Gleixner886533a2008-05-12 15:43:36 +0200651 * Sets up the system RAM area from start_pfn to last_pfn according to the
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200652 * numa=fake command-line option.
653 */
David Rientjesadc19382009-09-25 15:20:09 -0700654static int __init numa_emulation(unsigned long start_pfn,
Hans Rosenfeldeec1d4f2010-10-29 17:14:30 +0200655 unsigned long last_pfn, int acpi, int amd)
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200656{
David Rientjesca2107c2010-02-15 13:43:33 -0800657 u64 addr = start_pfn << PAGE_SHIFT;
Thomas Gleixner886533a2008-05-12 15:43:36 +0200658 u64 max_addr = last_pfn << PAGE_SHIFT;
David Rientjesca2107c2010-02-15 13:43:33 -0800659 int num_nodes;
660 int i;
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200661
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200662 /*
David Rientjes8df5bb342010-02-15 13:43:30 -0800663 * If the numa=fake command-line contains a 'M' or 'G', it represents
David Rientjesca2107c2010-02-15 13:43:33 -0800664 * the fixed node size. Otherwise, if it is just a single number N,
665 * split the system RAM into N fake nodes.
David Rientjes8df5bb342010-02-15 13:43:30 -0800666 */
667 if (strchr(cmdline, 'M') || strchr(cmdline, 'G')) {
David Rientjesca2107c2010-02-15 13:43:33 -0800668 u64 size;
669
David Rientjes8df5bb342010-02-15 13:43:30 -0800670 size = memparse(cmdline, &cmdline);
671 num_nodes = split_nodes_size_interleave(addr, max_addr, size);
David Rientjesca2107c2010-02-15 13:43:33 -0800672 } else {
673 unsigned long n;
674
675 n = simple_strtoul(cmdline, NULL, 0);
David Rientjesc1c34432010-12-22 17:23:54 -0800676 num_nodes = split_nodes_interleave(addr, max_addr, n);
David Rientjes8df5bb342010-02-15 13:43:30 -0800677 }
678
David Rientjesca2107c2010-02-15 13:43:33 -0800679 if (num_nodes < 0)
680 return num_nodes;
Suresh Siddha6ec6e0d2008-03-25 10:14:35 -0700681 memnode_shift = compute_hash_shift(nodes, num_nodes, NULL);
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200682 if (memnode_shift < 0) {
683 memnode_shift = 0;
684 printk(KERN_ERR "No NUMA hash function found. NUMA emulation "
685 "disabled.\n");
686 return -1;
687 }
688
689 /*
David Rientjesadc19382009-09-25 15:20:09 -0700690 * We need to vacate all active ranges that may have been registered for
691 * the e820 memory map.
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200692 */
693 remove_all_active_ranges();
Yinghai Lu1411e0e2010-12-27 16:48:17 -0800694 for_each_node_mask(i, node_possible_map)
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700695 memblock_x86_register_active_regions(i, nodes[i].start >> PAGE_SHIFT,
Mel Gorman5cb248a2006-09-27 01:49:52 -0700696 nodes[i].end >> PAGE_SHIFT);
Yinghai Lu1411e0e2010-12-27 16:48:17 -0800697 init_memory_mapping_high();
698 for_each_node_mask(i, node_possible_map)
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100699 setup_node_bootmem(i, nodes[i].start, nodes[i].end);
Tejun Heo190955482011-02-16 12:13:07 +0100700 setup_physnodes(addr, max_addr);
David Rientjesf51bf302010-12-22 17:23:51 -0800701 fake_physnodes(acpi, amd, num_nodes);
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100702 numa_init_array();
703 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704}
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200705#endif /* CONFIG_NUMA_EMU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Tejun Heoffe77a42011-02-16 12:13:06 +0100707static int dummy_numa_init(void)
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100708{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 printk(KERN_INFO "%s\n",
710 numa_off ? "NUMA turned off" : "No NUMA configuration found");
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100711 printk(KERN_INFO "Faking a node at %016lx-%016lx\n",
Tejun Heo86ef4db2011-02-16 12:13:06 +0100712 0LU, max_pfn << PAGE_SHIFT);
Tejun Heoffe77a42011-02-16 12:13:06 +0100713
Tejun Heoec8cf29b2011-02-16 12:13:07 +0100714 node_set(0, cpu_nodes_parsed);
715 node_set(0, mem_nodes_parsed);
716
717 return 0;
718}
719
720static int dummy_scan_nodes(void)
721{
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100722 /* setup dummy node covering all memory */
723 memnode_shift = 63;
Amul Shah076422d2007-02-13 13:26:19 +0100724 memnodemap = memnode.embedded_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 memnodemap[0] = 0;
Tejun Heo86ef4db2011-02-16 12:13:06 +0100726 memblock_x86_register_active_regions(0, 0, max_pfn);
Yinghai Lu1411e0e2010-12-27 16:48:17 -0800727 init_memory_mapping_high();
Tejun Heo86ef4db2011-02-16 12:13:06 +0100728 setup_node_bootmem(0, 0, max_pfn << PAGE_SHIFT);
Tejun Heo7d36b7b2011-02-16 12:13:06 +0100729 numa_init_array();
Tejun Heoffe77a42011-02-16 12:13:06 +0100730
731 return 0;
732}
733
734void __init initmem_init(void)
735{
736 int (*numa_init[])(void) = { [2] = dummy_numa_init };
737 int (*scan_nodes[])(void) = { [2] = dummy_scan_nodes };
738 int i, j;
739
740 if (!numa_off) {
741#ifdef CONFIG_ACPI_NUMA
742 numa_init[0] = x86_acpi_numa_init;
743 scan_nodes[0] = acpi_scan_nodes;
744#endif
745#ifdef CONFIG_AMD_NUMA
746 numa_init[1] = amd_numa_init;
747 scan_nodes[1] = amd_scan_nodes;
748#endif
749 }
750
751 for (i = 0; i < ARRAY_SIZE(numa_init); i++) {
752 if (!numa_init[i])
753 continue;
754
755 for (j = 0; j < MAX_LOCAL_APIC; j++)
756 set_apicid_to_node(j, NUMA_NO_NODE);
757
Tejun Heoec8cf29b2011-02-16 12:13:07 +0100758 nodes_clear(cpu_nodes_parsed);
759 nodes_clear(mem_nodes_parsed);
Tejun Heoffe77a42011-02-16 12:13:06 +0100760 nodes_clear(node_possible_map);
761 nodes_clear(node_online_map);
Tejun Heoef396ec2011-02-16 17:11:07 +0100762 num_node_memblks = 0;
763 memset(node_memblk_range, 0, sizeof(node_memblk_range));
764 memset(memblk_nodeid, 0, sizeof(memblk_nodeid));
Tejun Heo206e4202011-02-16 12:13:07 +0100765 memset(numa_nodes, 0, sizeof(numa_nodes));
Tejun Heoffe77a42011-02-16 12:13:06 +0100766
767 if (numa_init[i]() < 0)
768 continue;
Tejun Heo206e4202011-02-16 12:13:07 +0100769
770 /* clean up the node list */
771 for (j = 0; j < MAX_NUMNODES; j++)
772 cutoff_node(j, 0, max_pfn << PAGE_SHIFT);
773
Tejun Heoffe77a42011-02-16 12:13:06 +0100774#ifdef CONFIG_NUMA_EMU
Tejun Heo190955482011-02-16 12:13:07 +0100775 setup_physnodes(0, max_pfn << PAGE_SHIFT);
Tejun Heoffe77a42011-02-16 12:13:06 +0100776 if (cmdline && !numa_emulation(0, max_pfn, i == 0, i == 1))
777 return;
Tejun Heo190955482011-02-16 12:13:07 +0100778 setup_physnodes(0, max_pfn << PAGE_SHIFT);
Tejun Heoffe77a42011-02-16 12:13:06 +0100779 nodes_clear(node_possible_map);
780 nodes_clear(node_online_map);
781#endif
Tejun Heoec8cf29b2011-02-16 12:13:07 +0100782 /* Account for nodes with cpus and no memory */
783 nodes_or(node_possible_map, mem_nodes_parsed, cpu_nodes_parsed);
784 if (WARN_ON(nodes_empty(node_possible_map)))
785 continue;
786
Tejun Heoffe77a42011-02-16 12:13:06 +0100787 if (!scan_nodes[i]())
788 return;
789 }
790 BUG();
Andi Kleen69d81fc2005-11-05 17:25:53 +0100791}
792
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100793unsigned long __init numa_free_all_bootmem(void)
794{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 unsigned long pages = 0;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100796 int i;
797
798 for_each_online_node(i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 pages += free_all_bootmem_node(NODE_DATA(i));
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100800
Yinghai Lu08677212010-02-10 01:20:20 -0800801 pages += free_all_memory_core_early(MAX_NUMNODES);
Yinghai Lu08677212010-02-10 01:20:20 -0800802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 return pages;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100804}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
Tejun Heobbc9e2f2011-01-23 14:37:39 +0100806int __cpuinit numa_cpu_node(int cpu)
Yinghai Lud9c2d5a2009-11-21 00:23:37 -0800807{
Tejun Heobbc9e2f2011-01-23 14:37:39 +0100808 int apicid = early_per_cpu(x86_cpu_to_apicid, cpu);
Yinghai Lud9c2d5a2009-11-21 00:23:37 -0800809
Tejun Heobbc9e2f2011-01-23 14:37:39 +0100810 if (apicid != BAD_APICID)
811 return __apicid_to_node[apicid];
812 return NUMA_NO_NODE;
Yinghai Lud9c2d5a2009-11-21 00:23:37 -0800813}
814
Ravikiran Thirumalai05b3cbd2006-01-11 22:45:36 +0100815/*
Tejun Heode2d9442011-01-23 14:37:41 +0100816 * UGLINESS AHEAD: Currently, CONFIG_NUMA_EMU is 64bit only and makes use
817 * of 64bit specific data structures. The distinction is artificial and
818 * should be removed. numa_{add|remove}_cpu() are implemented in numa.c
819 * for both 32 and 64bit when CONFIG_NUMA_EMU is disabled but here when
820 * enabled.
Ravikiran Thirumalai05b3cbd2006-01-11 22:45:36 +0100821 *
Tejun Heode2d9442011-01-23 14:37:41 +0100822 * NUMA emulation is planned to be made generic and the following and other
823 * related code should be moved to numa.c.
Ravikiran Thirumalai05b3cbd2006-01-11 22:45:36 +0100824 */
Tejun Heode2d9442011-01-23 14:37:41 +0100825#ifdef CONFIG_NUMA_EMU
826# ifndef CONFIG_DEBUG_PER_CPU_MAPS
David Rientjesc1c34432010-12-22 17:23:54 -0800827void __cpuinit numa_add_cpu(int cpu)
828{
829 unsigned long addr;
Tejun Heobbc9e2f2011-01-23 14:37:39 +0100830 int physnid, nid;
David Rientjesc1c34432010-12-22 17:23:54 -0800831
Tejun Heobbc9e2f2011-01-23 14:37:39 +0100832 nid = numa_cpu_node(cpu);
David Rientjesc1c34432010-12-22 17:23:54 -0800833 if (nid == NUMA_NO_NODE)
834 nid = early_cpu_to_node(cpu);
835 BUG_ON(nid == NUMA_NO_NODE || !node_online(nid));
836
837 /*
838 * Use the starting address of the emulated node to find which physical
839 * node it is allocated on.
840 */
841 addr = node_start_pfn(nid) << PAGE_SHIFT;
842 for (physnid = 0; physnid < MAX_NUMNODES; physnid++)
843 if (addr >= physnodes[physnid].start &&
844 addr < physnodes[physnid].end)
845 break;
846
847 /*
848 * Map the cpu to each emulated node that is allocated on the physical
849 * node of the cpu's apic id.
850 */
851 for_each_online_node(nid) {
852 addr = node_start_pfn(nid) << PAGE_SHIFT;
853 if (addr >= physnodes[physnid].start &&
854 addr < physnodes[physnid].end)
855 cpumask_set_cpu(cpu, node_to_cpumask_map[nid]);
856 }
857}
858
859void __cpuinit numa_remove_cpu(int cpu)
860{
861 int i;
862
863 for_each_online_node(i)
864 cpumask_clear_cpu(cpu, node_to_cpumask_map[i]);
865}
Tejun Heode2d9442011-01-23 14:37:41 +0100866# else /* !CONFIG_DEBUG_PER_CPU_MAPS */
David Rientjesd906f0e2010-12-30 10:54:16 -0800867static void __cpuinit numa_set_cpumask(int cpu, int enable)
868{
869 int node = early_cpu_to_node(cpu);
870 struct cpumask *mask;
David Rientjesc1c34432010-12-22 17:23:54 -0800871 int i;
Brian Gerst6470aff2009-01-27 12:56:47 +0900872
David Rientjes14392fd2011-02-07 14:08:53 -0800873 if (node == NUMA_NO_NODE) {
874 /* early_cpu_to_node() already emits a warning and trace */
875 return;
876 }
David Rientjesc1c34432010-12-22 17:23:54 -0800877 for_each_online_node(i) {
878 unsigned long addr;
879
880 addr = node_start_pfn(i) << PAGE_SHIFT;
881 if (addr < physnodes[node].start ||
882 addr >= physnodes[node].end)
883 continue;
David Rientjesd906f0e2010-12-30 10:54:16 -0800884 mask = debug_cpumask_set_cpu(cpu, enable);
885 if (!mask)
David Rientjesc1c34432010-12-22 17:23:54 -0800886 return;
David Rientjesc1c34432010-12-22 17:23:54 -0800887
888 if (enable)
889 cpumask_set_cpu(cpu, mask);
890 else
891 cpumask_clear_cpu(cpu, mask);
Brian Gerst6470aff2009-01-27 12:56:47 +0900892 }
Brian Gerst6470aff2009-01-27 12:56:47 +0900893}
894
895void __cpuinit numa_add_cpu(int cpu)
896{
897 numa_set_cpumask(cpu, 1);
898}
899
900void __cpuinit numa_remove_cpu(int cpu)
901{
902 numa_set_cpumask(cpu, 0);
903}
Tejun Heode2d9442011-01-23 14:37:41 +0100904# endif /* !CONFIG_DEBUG_PER_CPU_MAPS */
905#endif /* CONFIG_NUMA_EMU */