blob: aef0ff74f7ddcb934134ecfba9c4e549036370ff [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#include <asm/e820.h>
18#include <asm/proto.h>
19#include <asm/dma.h>
20#include <asm/numa.h>
21#include <asm/acpi.h>
Thomas Gleixnerc9ff0342008-01-30 13:30:16 +010022#include <asm/k8.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Ravikiran G Thirumalai6c231b72005-09-06 15:17:45 -070024struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +010025EXPORT_SYMBOL(node_data);
26
Eric Dumazetdcf36bf2006-03-25 16:31:46 +010027struct memnode memnode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
travis@sgi.com43238382008-01-30 13:33:25 +010029s16 apicid_to_node[MAX_LOCAL_APIC] __cpuinitdata = {
Thomas Gleixnere3cfe522008-01-30 13:30:37 +010030 [0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE
Andi Kleen3f098c22005-09-12 18:49:24 +020031};
Thomas Gleixnere3cfe522008-01-30 13:30:37 +010032
Linus Torvalds1da177e2005-04-16 15:20:36 -070033int numa_off __initdata;
Thomas Gleixner864fc312008-05-12 15:43:36 +020034static unsigned long __initdata nodemap_addr;
35static unsigned long __initdata nodemap_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Brian Gerst6470aff2009-01-27 12:56:47 +090037/*
38 * Map cpu index to node index
39 */
40DEFINE_EARLY_PER_CPU(int, x86_cpu_to_node_map, NUMA_NO_NODE);
41EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_node_map);
42
43/*
Eric Dumazet529a3402005-11-05 17:25:54 +010044 * Given a shift value, try to populate memnodemap[]
45 * Returns :
46 * 1 if OK
47 * 0 if memnodmap[] too small (of shift too small)
48 * -1 if node overlap or lost ram (shift too big)
49 */
Thomas Gleixnere3cfe522008-01-30 13:30:37 +010050static int __init populate_memnodemap(const struct bootnode *nodes,
Suresh Siddha6ec6e0d2008-03-25 10:14:35 -070051 int numnodes, int shift, int *nodeids)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Eric Dumazet529a3402005-11-05 17:25:54 +010053 unsigned long addr, end;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +010054 int i, res = -1;
Keith Manntheyb6846642005-07-28 21:15:38 -070055
travis@sgi.com43238382008-01-30 13:33:25 +010056 memset(memnodemap, 0xff, sizeof(s16)*memnodemapsize);
Eric Dumazet529a3402005-11-05 17:25:54 +010057 for (i = 0; i < numnodes; i++) {
58 addr = nodes[i].start;
59 end = nodes[i].end;
60 if (addr >= end)
61 continue;
Amul Shah076422d22007-02-13 13:26:19 +010062 if ((end >> shift) >= memnodemapsize)
Eric Dumazet529a3402005-11-05 17:25:54 +010063 return 0;
64 do {
travis@sgi.com43238382008-01-30 13:33:25 +010065 if (memnodemap[addr >> shift] != NUMA_NO_NODE)
Eric Dumazet529a3402005-11-05 17:25:54 +010066 return -1;
Suresh Siddha6ec6e0d2008-03-25 10:14:35 -070067
68 if (!nodeids)
69 memnodemap[addr >> shift] = i;
70 else
71 memnodemap[addr >> shift] = nodeids[i];
72
Amul Shah076422d22007-02-13 13:26:19 +010073 addr += (1UL << shift);
Eric Dumazet529a3402005-11-05 17:25:54 +010074 } while (addr < end);
75 res = 1;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +010076 }
Eric Dumazet529a3402005-11-05 17:25:54 +010077 return res;
78}
79
Amul Shah076422d22007-02-13 13:26:19 +010080static int __init allocate_cachealigned_memnodemap(void)
81{
Yinghai Lu24a5da72008-02-01 17:49:41 +010082 unsigned long addr;
Amul Shah076422d22007-02-13 13:26:19 +010083
84 memnodemap = memnode.embedded_map;
travis@sgi.com316390b2008-01-30 13:33:15 +010085 if (memnodemapsize <= ARRAY_SIZE(memnode.embedded_map))
Amul Shah076422d22007-02-13 13:26:19 +010086 return 0;
Amul Shah076422d22007-02-13 13:26:19 +010087
Yinghai Lu24a5da72008-02-01 17:49:41 +010088 addr = 0x8000;
Joerg Roedelbe3e89e2008-07-25 16:48:58 +020089 nodemap_size = roundup(sizeof(s16) * memnodemapsize, L1_CACHE_BYTES);
Yinghai Lua9ce6bc2010-08-25 13:39:17 -070090 nodemap_addr = memblock_find_in_range(addr, max_pfn<<PAGE_SHIFT,
Yinghai Lu24a5da72008-02-01 17:49:41 +010091 nodemap_size, L1_CACHE_BYTES);
Yinghai Lua9ce6bc2010-08-25 13:39:17 -070092 if (nodemap_addr == MEMBLOCK_ERROR) {
Amul Shah076422d22007-02-13 13:26:19 +010093 printk(KERN_ERR
94 "NUMA: Unable to allocate Memory to Node hash map\n");
95 nodemap_addr = nodemap_size = 0;
96 return -1;
97 }
Yinghai Lu24a5da72008-02-01 17:49:41 +010098 memnodemap = phys_to_virt(nodemap_addr);
Yinghai Lua9ce6bc2010-08-25 13:39:17 -070099 memblock_x86_reserve_range(nodemap_addr, nodemap_addr + nodemap_size, "MEMNODEMAP");
Amul Shah076422d22007-02-13 13:26:19 +0100100
101 printk(KERN_DEBUG "NUMA: Allocated memnodemap from %lx - %lx\n",
102 nodemap_addr, nodemap_addr + nodemap_size);
103 return 0;
104}
105
106/*
107 * The LSB of all start and end addresses in the node map is the value of the
108 * maximum possible shift.
109 */
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100110static int __init extract_lsb_from_nodes(const struct bootnode *nodes,
111 int numnodes)
Amul Shah076422d22007-02-13 13:26:19 +0100112{
Amul Shah54413922007-02-13 13:26:20 +0100113 int i, nodes_used = 0;
Amul Shah076422d22007-02-13 13:26:19 +0100114 unsigned long start, end;
115 unsigned long bitfield = 0, memtop = 0;
116
117 for (i = 0; i < numnodes; i++) {
118 start = nodes[i].start;
119 end = nodes[i].end;
120 if (start >= end)
121 continue;
Amul Shah54413922007-02-13 13:26:20 +0100122 bitfield |= start;
123 nodes_used++;
Amul Shah076422d22007-02-13 13:26:19 +0100124 if (end > memtop)
125 memtop = end;
126 }
Amul Shah54413922007-02-13 13:26:20 +0100127 if (nodes_used <= 1)
128 i = 63;
129 else
130 i = find_first_bit(&bitfield, sizeof(unsigned long)*8);
Amul Shah076422d22007-02-13 13:26:19 +0100131 memnodemapsize = (memtop >> i)+1;
132 return i;
133}
134
Suresh Siddha6ec6e0d2008-03-25 10:14:35 -0700135int __init compute_hash_shift(struct bootnode *nodes, int numnodes,
136 int *nodeids)
Eric Dumazet529a3402005-11-05 17:25:54 +0100137{
Amul Shah076422d22007-02-13 13:26:19 +0100138 int shift;
Eric Dumazet529a3402005-11-05 17:25:54 +0100139
Amul Shah076422d22007-02-13 13:26:19 +0100140 shift = extract_lsb_from_nodes(nodes, numnodes);
141 if (allocate_cachealigned_memnodemap())
142 return -1;
Andi Kleen6b050f82006-01-11 22:44:33 +0100143 printk(KERN_DEBUG "NUMA: Using %d for the hash shift.\n",
Eric Dumazet529a3402005-11-05 17:25:54 +0100144 shift);
145
Suresh Siddha6ec6e0d2008-03-25 10:14:35 -0700146 if (populate_memnodemap(nodes, numnodes, shift, nodeids) != 1) {
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100147 printk(KERN_INFO "Your memory is not aligned you need to "
148 "rebuild your kernel with a bigger NODEMAPSIZE "
149 "shift=%d\n", shift);
Eric Dumazet529a3402005-11-05 17:25:54 +0100150 return -1;
151 }
Keith Manntheyb6846642005-07-28 21:15:38 -0700152 return shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153}
154
KAMEZAWA Hiroyukif2dbcfa2009-02-18 14:48:32 -0800155int __meminit __early_pfn_to_nid(unsigned long pfn)
Matt Tolentinobbfceef2005-06-23 00:08:07 -0700156{
157 return phys_to_nid(pfn << PAGE_SHIFT);
158}
Matt Tolentinobbfceef2005-06-23 00:08:07 -0700159
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100160static void * __init early_node_mem(int nodeid, unsigned long start,
Yinghai Lu24a5da72008-02-01 17:49:41 +0100161 unsigned long end, unsigned long size,
162 unsigned long align)
Andi Kleena8062232006-04-07 19:49:21 +0200163{
Yinghai Lucef625e2010-02-10 01:20:18 -0800164 unsigned long mem;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100165
Yinghai Lucef625e2010-02-10 01:20:18 -0800166 /*
167 * put it on high as possible
168 * something will go with NODE_DATA
169 */
170 if (start < (MAX_DMA_PFN<<PAGE_SHIFT))
171 start = MAX_DMA_PFN<<PAGE_SHIFT;
172 if (start < (MAX_DMA32_PFN<<PAGE_SHIFT) &&
173 end > (MAX_DMA32_PFN<<PAGE_SHIFT))
174 start = MAX_DMA32_PFN<<PAGE_SHIFT;
Yinghai Lu72d7c3b2010-08-25 13:39:17 -0700175 mem = memblock_x86_find_in_range_node(nodeid, start, end, size, align);
176 if (mem != MEMBLOCK_ERROR)
Andi Kleena8062232006-04-07 19:49:21 +0200177 return __va(mem);
Yinghai Lu9347e0b2008-02-01 17:49:42 +0100178
Yinghai Lucef625e2010-02-10 01:20:18 -0800179 /* extend the search scope */
180 end = max_pfn_mapped << PAGE_SHIFT;
181 if (end > (MAX_DMA32_PFN<<PAGE_SHIFT))
182 start = MAX_DMA32_PFN<<PAGE_SHIFT;
183 else
184 start = MAX_DMA_PFN<<PAGE_SHIFT;
Yinghai Lu72d7c3b2010-08-25 13:39:17 -0700185 mem = memblock_x86_find_in_range_node(nodeid, start, end, size, align);
186 if (mem != MEMBLOCK_ERROR)
Yinghai Lu1842f902010-02-10 01:20:15 -0800187 return __va(mem);
188
189 printk(KERN_ERR "Cannot find %lu bytes in node %d\n",
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100190 size, nodeid);
Yinghai Lu1842f902010-02-10 01:20:15 -0800191
192 return NULL;
Andi Kleena8062232006-04-07 19:49:21 +0200193}
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195/* Initialize bootmem allocator for a node */
Yinghai Lu7c437692009-05-15 13:59:37 -0700196void __init
197setup_node_bootmem(int nodeid, unsigned long start, unsigned long end)
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100198{
Yinghai Lu08677212010-02-10 01:20:20 -0800199 unsigned long start_pfn, last_pfn, nodedata_phys;
Yinghai Lu7c437692009-05-15 13:59:37 -0700200 const int pgdat_size = roundup(sizeof(pg_data_t), PAGE_SIZE);
Yinghai Lu1a27fc02008-03-18 12:52:37 -0700201 int nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Yinghai Lu4c31e922009-04-22 14:19:27 -0700203 if (!end)
204 return;
205
Yinghai Lu7c437692009-05-15 13:59:37 -0700206 /*
207 * Don't confuse VM with a node that doesn't have the
208 * minimum amount of memory:
209 */
210 if (end && (end - start) < NODE_MIN_SIZE)
211 return;
212
Joerg Roedelbe3e89e2008-07-25 16:48:58 +0200213 start = roundup(start, ZONE_ALIGN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Yinghai Lu08677212010-02-10 01:20:20 -0800215 printk(KERN_INFO "Initmem setup node %d %016lx-%016lx\n", nodeid,
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100216 start, end);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218 start_pfn = start >> PAGE_SHIFT;
Thomas Gleixner886533a2008-05-12 15:43:36 +0200219 last_pfn = end >> PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Yinghai Lu24a5da72008-02-01 17:49:41 +0100221 node_data[nodeid] = early_node_mem(nodeid, start, end, pgdat_size,
222 SMP_CACHE_BYTES);
Andi Kleena8062232006-04-07 19:49:21 +0200223 if (node_data[nodeid] == NULL)
224 return;
225 nodedata_phys = __pa(node_data[nodeid]);
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700226 memblock_x86_reserve_range(nodedata_phys, nodedata_phys + pgdat_size, "NODE_DATA");
Yinghai Lu6118f762008-02-04 16:47:56 +0100227 printk(KERN_INFO " NODE_DATA [%016lx - %016lx]\n", nodedata_phys,
228 nodedata_phys + pgdat_size - 1);
Yinghai Lu1842f902010-02-10 01:20:15 -0800229 nid = phys_to_nid(nodedata_phys);
230 if (nid != nodeid)
231 printk(KERN_INFO " NODE_DATA(%d) on node %d\n", nodeid, nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 memset(NODE_DATA(nodeid), 0, sizeof(pg_data_t));
Yinghai Lu08677212010-02-10 01:20:20 -0800234 NODE_DATA(nodeid)->node_id = nodeid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 NODE_DATA(nodeid)->node_start_pfn = start_pfn;
Thomas Gleixner886533a2008-05-12 15:43:36 +0200236 NODE_DATA(nodeid)->node_spanned_pages = last_pfn - start_pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 node_set_online(nodeid);
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100239}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100241/*
242 * There are unfortunately some poorly designed mainboards around that
243 * only connect memory to a single CPU. This breaks the 1:1 cpu->node
244 * mapping. To avoid this fill in the mapping for all possible CPUs,
245 * as the number of CPUs is not known yet. We round robin the existing
246 * nodes.
247 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248void __init numa_init_array(void)
249{
250 int rr, i;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100251
Ravikiran G Thirumalai85cc5132005-09-30 11:59:22 -0700252 rr = first_node(node_online_map);
Mike Travis168ef542008-12-16 17:34:01 -0800253 for (i = 0; i < nr_cpu_ids; i++) {
travis@sgi.com1ce35712008-01-30 13:33:33 +0100254 if (early_cpu_to_node(i) != NUMA_NO_NODE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 continue;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100256 numa_set_node(i, rr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 rr = next_node(rr, node_online_map);
258 if (rr == MAX_NUMNODES)
259 rr = first_node(node_online_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261}
262
263#ifdef CONFIG_NUMA_EMU
Rohit Seth53fee042007-02-13 13:26:22 +0100264/* Numa emulation */
David Rientjesadc19382009-09-25 15:20:09 -0700265static struct bootnode nodes[MAX_NUMNODES] __initdata;
266static struct bootnode physnodes[MAX_NUMNODES] __initdata;
Thomas Gleixner864fc312008-05-12 15:43:36 +0200267static char *cmdline __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
David Rientjesadc19382009-09-25 15:20:09 -0700269static int __init setup_physnodes(unsigned long start, unsigned long end,
270 int acpi, int k8)
271{
272 int nr_nodes = 0;
273 int ret = 0;
274 int i;
275
276#ifdef CONFIG_ACPI_NUMA
277 if (acpi)
278 nr_nodes = acpi_get_nodes(physnodes);
279#endif
280#ifdef CONFIG_K8_NUMA
281 if (k8)
282 nr_nodes = k8_get_nodes(physnodes);
283#endif
284 /*
285 * Basic sanity checking on the physical node map: there may be errors
286 * if the SRAT or K8 incorrectly reported the topology or the mem=
287 * kernel parameter is used.
288 */
289 for (i = 0; i < nr_nodes; i++) {
290 if (physnodes[i].start == physnodes[i].end)
291 continue;
292 if (physnodes[i].start > end) {
293 physnodes[i].end = physnodes[i].start;
294 continue;
295 }
296 if (physnodes[i].end < start) {
297 physnodes[i].start = physnodes[i].end;
298 continue;
299 }
300 if (physnodes[i].start < start)
301 physnodes[i].start = start;
302 if (physnodes[i].end > end)
303 physnodes[i].end = end;
304 }
305
306 /*
307 * Remove all nodes that have no memory or were truncated because of the
308 * limited address range.
309 */
310 for (i = 0; i < nr_nodes; i++) {
311 if (physnodes[i].start == physnodes[i].end)
312 continue;
313 physnodes[ret].start = physnodes[i].start;
314 physnodes[ret].end = physnodes[i].end;
315 ret++;
316 }
317
318 /*
319 * If no physical topology was detected, a single node is faked to cover
320 * the entire address space.
321 */
322 if (!ret) {
323 physnodes[ret].start = start;
324 physnodes[ret].end = end;
325 ret = 1;
326 }
327 return ret;
328}
329
Rohit Seth53fee042007-02-13 13:26:22 +0100330/*
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100331 * Setups up nid to range from addr to addr + size. If the end
332 * boundary is greater than max_addr, then max_addr is used instead.
333 * The return value is 0 if there is additional memory left for
334 * allocation past addr and -1 otherwise. addr is adjusted to be at
335 * the end of the node.
Rohit Seth53fee042007-02-13 13:26:22 +0100336 */
David Rientjesadc19382009-09-25 15:20:09 -0700337static int __init setup_node_range(int nid, u64 *addr, u64 size, u64 max_addr)
Rohit Seth53fee042007-02-13 13:26:22 +0100338{
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200339 int ret = 0;
340 nodes[nid].start = *addr;
341 *addr += size;
342 if (*addr >= max_addr) {
343 *addr = max_addr;
344 ret = -1;
345 }
346 nodes[nid].end = *addr;
Suresh Siddhae3f1cae2007-05-02 19:27:20 +0200347 node_set(nid, node_possible_map);
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200348 printk(KERN_INFO "Faking node %d at %016Lx-%016Lx (%LuMB)\n", nid,
349 nodes[nid].start, nodes[nid].end,
350 (nodes[nid].end - nodes[nid].start) >> 20);
351 return ret;
Rohit Seth53fee042007-02-13 13:26:22 +0100352}
353
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200354/*
David Rientjesadc19382009-09-25 15:20:09 -0700355 * Sets up nr_nodes fake nodes interleaved over physical nodes ranging from addr
356 * to max_addr. The return value is the number of nodes allocated.
357 */
358static int __init split_nodes_interleave(u64 addr, u64 max_addr,
359 int nr_phys_nodes, int nr_nodes)
360{
361 nodemask_t physnode_mask = NODE_MASK_NONE;
362 u64 size;
363 int big;
364 int ret = 0;
365 int i;
366
367 if (nr_nodes <= 0)
368 return -1;
369 if (nr_nodes > MAX_NUMNODES) {
370 pr_info("numa=fake=%d too large, reducing to %d\n",
371 nr_nodes, MAX_NUMNODES);
372 nr_nodes = MAX_NUMNODES;
373 }
374
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700375 size = (max_addr - addr - memblock_x86_hole_size(addr, max_addr)) / nr_nodes;
David Rientjesadc19382009-09-25 15:20:09 -0700376 /*
377 * Calculate the number of big nodes that can be allocated as a result
378 * of consolidating the remainder.
379 */
David Rientjes68fd1112010-02-15 13:43:25 -0800380 big = ((size & ~FAKE_NODE_MIN_HASH_MASK) * nr_nodes) /
David Rientjesadc19382009-09-25 15:20:09 -0700381 FAKE_NODE_MIN_SIZE;
382
383 size &= FAKE_NODE_MIN_HASH_MASK;
384 if (!size) {
385 pr_err("Not enough memory for each node. "
386 "NUMA emulation disabled.\n");
387 return -1;
388 }
389
390 for (i = 0; i < nr_phys_nodes; i++)
391 if (physnodes[i].start != physnodes[i].end)
392 node_set(i, physnode_mask);
393
394 /*
395 * Continue to fill physical nodes with fake nodes until there is no
396 * memory left on any of them.
397 */
398 while (nodes_weight(physnode_mask)) {
399 for_each_node_mask(i, physnode_mask) {
400 u64 end = physnodes[i].start + size;
401 u64 dma32_end = PFN_PHYS(MAX_DMA32_PFN);
402
403 if (ret < big)
404 end += FAKE_NODE_MIN_SIZE;
405
406 /*
407 * Continue to add memory to this fake node if its
408 * non-reserved memory is less than the per-node size.
409 */
410 while (end - physnodes[i].start -
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700411 memblock_x86_hole_size(physnodes[i].start, end) < size) {
David Rientjesadc19382009-09-25 15:20:09 -0700412 end += FAKE_NODE_MIN_SIZE;
413 if (end > physnodes[i].end) {
414 end = physnodes[i].end;
415 break;
416 }
417 }
418
419 /*
420 * If there won't be at least FAKE_NODE_MIN_SIZE of
421 * non-reserved memory in ZONE_DMA32 for the next node,
422 * this one must extend to the boundary.
423 */
424 if (end < dma32_end && dma32_end - end -
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700425 memblock_x86_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
David Rientjesadc19382009-09-25 15:20:09 -0700426 end = dma32_end;
427
428 /*
429 * If there won't be enough non-reserved memory for the
430 * next node, this one must extend to the end of the
431 * physical node.
432 */
433 if (physnodes[i].end - end -
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700434 memblock_x86_hole_size(end, physnodes[i].end) < size)
David Rientjesadc19382009-09-25 15:20:09 -0700435 end = physnodes[i].end;
436
437 /*
438 * Avoid allocating more nodes than requested, which can
439 * happen as a result of rounding down each node's size
440 * to FAKE_NODE_MIN_SIZE.
441 */
442 if (nodes_weight(physnode_mask) + ret >= nr_nodes)
443 end = physnodes[i].end;
444
445 if (setup_node_range(ret++, &physnodes[i].start,
446 end - physnodes[i].start,
447 physnodes[i].end) < 0)
448 node_clear(i, physnode_mask);
449 }
450 }
451 return ret;
452}
453
454/*
David Rientjes8df5bb342010-02-15 13:43:30 -0800455 * Returns the end address of a node so that there is at least `size' amount of
456 * non-reserved memory or `max_addr' is reached.
457 */
458static u64 __init find_end_of_node(u64 start, u64 max_addr, u64 size)
459{
460 u64 end = start + size;
461
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700462 while (end - start - memblock_x86_hole_size(start, end) < size) {
David Rientjes8df5bb342010-02-15 13:43:30 -0800463 end += FAKE_NODE_MIN_SIZE;
464 if (end > max_addr) {
465 end = max_addr;
466 break;
467 }
468 }
469 return end;
470}
471
472/*
473 * Sets up fake nodes of `size' interleaved over physical nodes ranging from
474 * `addr' to `max_addr'. The return value is the number of nodes allocated.
475 */
476static int __init split_nodes_size_interleave(u64 addr, u64 max_addr, u64 size)
477{
478 nodemask_t physnode_mask = NODE_MASK_NONE;
479 u64 min_size;
480 int ret = 0;
481 int i;
482
483 if (!size)
484 return -1;
485 /*
486 * The limit on emulated nodes is MAX_NUMNODES, so the size per node is
487 * increased accordingly if the requested size is too small. This
488 * creates a uniform distribution of node sizes across the entire
489 * machine (but not necessarily over physical nodes).
490 */
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700491 min_size = (max_addr - addr - memblock_x86_hole_size(addr, max_addr)) /
David Rientjes8df5bb342010-02-15 13:43:30 -0800492 MAX_NUMNODES;
493 min_size = max(min_size, FAKE_NODE_MIN_SIZE);
494 if ((min_size & FAKE_NODE_MIN_HASH_MASK) < min_size)
495 min_size = (min_size + FAKE_NODE_MIN_SIZE) &
496 FAKE_NODE_MIN_HASH_MASK;
497 if (size < min_size) {
498 pr_err("Fake node size %LuMB too small, increasing to %LuMB\n",
499 size >> 20, min_size >> 20);
500 size = min_size;
501 }
502 size &= FAKE_NODE_MIN_HASH_MASK;
503
504 for (i = 0; i < MAX_NUMNODES; i++)
505 if (physnodes[i].start != physnodes[i].end)
506 node_set(i, physnode_mask);
507 /*
508 * Fill physical nodes with fake nodes of size until there is no memory
509 * left on any of them.
510 */
511 while (nodes_weight(physnode_mask)) {
512 for_each_node_mask(i, physnode_mask) {
513 u64 dma32_end = MAX_DMA32_PFN << PAGE_SHIFT;
514 u64 end;
515
516 end = find_end_of_node(physnodes[i].start,
517 physnodes[i].end, size);
518 /*
519 * If there won't be at least FAKE_NODE_MIN_SIZE of
520 * non-reserved memory in ZONE_DMA32 for the next node,
521 * this one must extend to the boundary.
522 */
523 if (end < dma32_end && dma32_end - end -
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700524 memblock_x86_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
David Rientjes8df5bb342010-02-15 13:43:30 -0800525 end = dma32_end;
526
527 /*
528 * If there won't be enough non-reserved memory for the
529 * next node, this one must extend to the end of the
530 * physical node.
531 */
532 if (physnodes[i].end - end -
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700533 memblock_x86_hole_size(end, physnodes[i].end) < size)
David Rientjes8df5bb342010-02-15 13:43:30 -0800534 end = physnodes[i].end;
535
536 /*
537 * Setup the fake node that will be allocated as bootmem
538 * later. If setup_node_range() returns non-zero, there
539 * is no more memory available on this physical node.
540 */
541 if (setup_node_range(ret++, &physnodes[i].start,
542 end - physnodes[i].start,
543 physnodes[i].end) < 0)
544 node_clear(i, physnode_mask);
545 }
546 }
547 return ret;
548}
549
550/*
Thomas Gleixner886533a2008-05-12 15:43:36 +0200551 * Sets up the system RAM area from start_pfn to last_pfn according to the
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200552 * numa=fake command-line option.
553 */
David Rientjesadc19382009-09-25 15:20:09 -0700554static int __init numa_emulation(unsigned long start_pfn,
555 unsigned long last_pfn, int acpi, int k8)
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200556{
David Rientjesca2107c2010-02-15 13:43:33 -0800557 u64 addr = start_pfn << PAGE_SHIFT;
Thomas Gleixner886533a2008-05-12 15:43:36 +0200558 u64 max_addr = last_pfn << PAGE_SHIFT;
David Rientjesadc19382009-09-25 15:20:09 -0700559 int num_phys_nodes;
David Rientjesca2107c2010-02-15 13:43:33 -0800560 int num_nodes;
561 int i;
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200562
David Rientjesadc19382009-09-25 15:20:09 -0700563 num_phys_nodes = setup_physnodes(addr, max_addr, acpi, k8);
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200564 /*
David Rientjes8df5bb342010-02-15 13:43:30 -0800565 * If the numa=fake command-line contains a 'M' or 'G', it represents
David Rientjesca2107c2010-02-15 13:43:33 -0800566 * the fixed node size. Otherwise, if it is just a single number N,
567 * split the system RAM into N fake nodes.
David Rientjes8df5bb342010-02-15 13:43:30 -0800568 */
569 if (strchr(cmdline, 'M') || strchr(cmdline, 'G')) {
David Rientjesca2107c2010-02-15 13:43:33 -0800570 u64 size;
571
David Rientjes8df5bb342010-02-15 13:43:30 -0800572 size = memparse(cmdline, &cmdline);
573 num_nodes = split_nodes_size_interleave(addr, max_addr, size);
David Rientjesca2107c2010-02-15 13:43:33 -0800574 } else {
575 unsigned long n;
576
577 n = simple_strtoul(cmdline, NULL, 0);
578 num_nodes = split_nodes_interleave(addr, max_addr, num_phys_nodes, n);
David Rientjes8df5bb342010-02-15 13:43:30 -0800579 }
580
David Rientjesca2107c2010-02-15 13:43:33 -0800581 if (num_nodes < 0)
582 return num_nodes;
Suresh Siddha6ec6e0d2008-03-25 10:14:35 -0700583 memnode_shift = compute_hash_shift(nodes, num_nodes, NULL);
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200584 if (memnode_shift < 0) {
585 memnode_shift = 0;
586 printk(KERN_ERR "No NUMA hash function found. NUMA emulation "
587 "disabled.\n");
588 return -1;
589 }
590
591 /*
David Rientjesadc19382009-09-25 15:20:09 -0700592 * We need to vacate all active ranges that may have been registered for
593 * the e820 memory map.
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200594 */
595 remove_all_active_ranges();
Suresh Siddhae3f1cae2007-05-02 19:27:20 +0200596 for_each_node_mask(i, node_possible_map) {
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700597 memblock_x86_register_active_regions(i, nodes[i].start >> PAGE_SHIFT,
Mel Gorman5cb248a2006-09-27 01:49:52 -0700598 nodes[i].end >> PAGE_SHIFT);
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100599 setup_node_bootmem(i, nodes[i].start, nodes[i].end);
Mel Gorman5cb248a2006-09-27 01:49:52 -0700600 }
David Rientjes3484d792007-07-21 17:10:32 +0200601 acpi_fake_nodes(nodes, num_nodes);
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100602 numa_init_array();
603 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200605#endif /* CONFIG_NUMA_EMU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
David Rientjes8ee2deb2009-09-25 15:20:00 -0700607void __init initmem_init(unsigned long start_pfn, unsigned long last_pfn,
608 int acpi, int k8)
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100609{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 int i;
611
Suresh Siddhae3f1cae2007-05-02 19:27:20 +0200612 nodes_clear(node_possible_map);
Yinghai Lub7ad1492008-02-17 02:02:21 -0800613 nodes_clear(node_online_map);
Suresh Siddhae3f1cae2007-05-02 19:27:20 +0200614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615#ifdef CONFIG_NUMA_EMU
David Rientjesadc19382009-09-25 15:20:09 -0700616 if (cmdline && !numa_emulation(start_pfn, last_pfn, acpi, k8))
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100617 return;
Suresh Siddhae3f1cae2007-05-02 19:27:20 +0200618 nodes_clear(node_possible_map);
Yinghai Lub7ad1492008-02-17 02:02:21 -0800619 nodes_clear(node_online_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620#endif
621
622#ifdef CONFIG_ACPI_NUMA
David Rientjes87162732009-09-25 15:20:04 -0700623 if (!numa_off && acpi && !acpi_scan_nodes(start_pfn << PAGE_SHIFT,
624 last_pfn << PAGE_SHIFT))
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100625 return;
Suresh Siddhae3f1cae2007-05-02 19:27:20 +0200626 nodes_clear(node_possible_map);
Yinghai Lub7ad1492008-02-17 02:02:21 -0800627 nodes_clear(node_online_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628#endif
629
630#ifdef CONFIG_K8_NUMA
David Rientjes8ee2deb2009-09-25 15:20:00 -0700631 if (!numa_off && k8 && !k8_scan_nodes())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 return;
Suresh Siddhae3f1cae2007-05-02 19:27:20 +0200633 nodes_clear(node_possible_map);
Yinghai Lub7ad1492008-02-17 02:02:21 -0800634 nodes_clear(node_online_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635#endif
636 printk(KERN_INFO "%s\n",
637 numa_off ? "NUMA turned off" : "No NUMA configuration found");
638
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100639 printk(KERN_INFO "Faking a node at %016lx-%016lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 start_pfn << PAGE_SHIFT,
Thomas Gleixner886533a2008-05-12 15:43:36 +0200641 last_pfn << PAGE_SHIFT);
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100642 /* setup dummy node covering all memory */
643 memnode_shift = 63;
Amul Shah076422d22007-02-13 13:26:19 +0100644 memnodemap = memnode.embedded_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 memnodemap[0] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 node_set_online(0);
Suresh Siddhae3f1cae2007-05-02 19:27:20 +0200647 node_set(0, node_possible_map);
Mike Travis168ef542008-12-16 17:34:01 -0800648 for (i = 0; i < nr_cpu_ids; i++)
Andi Kleen69d81fc2005-11-05 17:25:53 +0100649 numa_set_node(i, 0);
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700650 memblock_x86_register_active_regions(0, start_pfn, last_pfn);
Thomas Gleixner886533a2008-05-12 15:43:36 +0200651 setup_node_bootmem(0, start_pfn << PAGE_SHIFT, last_pfn << PAGE_SHIFT);
Andi Kleen69d81fc2005-11-05 17:25:53 +0100652}
653
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100654unsigned long __init numa_free_all_bootmem(void)
655{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 unsigned long pages = 0;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100657 int i;
658
659 for_each_online_node(i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 pages += free_all_bootmem_node(NODE_DATA(i));
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100661
Yinghai Lu08677212010-02-10 01:20:20 -0800662 pages += free_all_memory_core_early(MAX_NUMNODES);
Yinghai Lu08677212010-02-10 01:20:20 -0800663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 return pages;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100665}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
Andi Kleen2c8c0e62006-09-26 10:52:32 +0200667static __init int numa_setup(char *opt)
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100668{
Andi Kleen2c8c0e62006-09-26 10:52:32 +0200669 if (!opt)
670 return -EINVAL;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100671 if (!strncmp(opt, "off", 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 numa_off = 1;
673#ifdef CONFIG_NUMA_EMU
David Rientjes8b8ca80e2007-05-02 19:27:09 +0200674 if (!strncmp(opt, "fake=", 5))
675 cmdline = opt + 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676#endif
677#ifdef CONFIG_ACPI_NUMA
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100678 if (!strncmp(opt, "noacpi", 6))
679 acpi_numa = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680#endif
Andi Kleen2c8c0e62006-09-26 10:52:32 +0200681 return 0;
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100682}
Andi Kleen2c8c0e62006-09-26 10:52:32 +0200683early_param("numa", numa_setup);
684
Mike Travis23ca4bb2008-05-12 21:21:12 +0200685#ifdef CONFIG_NUMA
Yinghai Lud9c2d5a2009-11-21 00:23:37 -0800686
687static __init int find_near_online_node(int node)
688{
689 int n, val;
690 int min_val = INT_MAX;
691 int best_node = -1;
692
693 for_each_online_node(n) {
694 val = node_distance(node, n);
695
696 if (val < min_val) {
697 min_val = val;
698 best_node = n;
699 }
700 }
701
702 return best_node;
703}
704
Ravikiran Thirumalai05b3cbd2006-01-11 22:45:36 +0100705/*
706 * Setup early cpu_to_node.
707 *
708 * Populate cpu_to_node[] only if x86_cpu_to_apicid[],
709 * and apicid_to_node[] tables have valid entries for a CPU.
710 * This means we skip cpu_to_node[] initialisation for NUMA
711 * emulation and faking node case (when running a kernel compiled
712 * for NUMA on a non NUMA box), which is OK as cpu_to_node[]
713 * is already initialized in a round robin manner at numa_init_array,
714 * prior to this call, and this initialization is good enough
715 * for the fake NUMA cases.
Mike Travis23ca4bb2008-05-12 21:21:12 +0200716 *
717 * Called before the per_cpu areas are setup.
Ravikiran Thirumalai05b3cbd2006-01-11 22:45:36 +0100718 */
719void __init init_cpu_to_node(void)
720{
Mike Travis23ca4bb2008-05-12 21:21:12 +0200721 int cpu;
722 u16 *cpu_to_apicid = early_per_cpu_ptr(x86_cpu_to_apicid);
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100723
Mike Travis23ca4bb2008-05-12 21:21:12 +0200724 BUG_ON(cpu_to_apicid == NULL);
725
726 for_each_possible_cpu(cpu) {
Yinghai Lu7c9e92b2008-02-19 15:35:54 -0800727 int node;
Mike Travis23ca4bb2008-05-12 21:21:12 +0200728 u16 apicid = cpu_to_apicid[cpu];
Thomas Gleixnere3cfe522008-01-30 13:30:37 +0100729
Ravikiran Thirumalai05b3cbd2006-01-11 22:45:36 +0100730 if (apicid == BAD_APICID)
731 continue;
Yinghai Lu7c9e92b2008-02-19 15:35:54 -0800732 node = apicid_to_node[apicid];
733 if (node == NUMA_NO_NODE)
Ravikiran Thirumalai05b3cbd2006-01-11 22:45:36 +0100734 continue;
Yinghai Lu7c9e92b2008-02-19 15:35:54 -0800735 if (!node_online(node))
Yinghai Lud9c2d5a2009-11-21 00:23:37 -0800736 node = find_near_online_node(node);
Mike Travis23ca4bb2008-05-12 21:21:12 +0200737 numa_set_node(cpu, node);
Ravikiran Thirumalai05b3cbd2006-01-11 22:45:36 +0100738 }
739}
Mike Travis23ca4bb2008-05-12 21:21:12 +0200740#endif
Ravikiran Thirumalai05b3cbd2006-01-11 22:45:36 +0100741
Andi Kleencf050132006-01-11 22:46:27 +0100742
Brian Gerst6470aff2009-01-27 12:56:47 +0900743void __cpuinit numa_set_node(int cpu, int node)
744{
745 int *cpu_to_node_map = early_per_cpu_ptr(x86_cpu_to_node_map);
746
747 /* early setting, no percpu area yet */
748 if (cpu_to_node_map) {
749 cpu_to_node_map[cpu] = node;
750 return;
751 }
752
753#ifdef CONFIG_DEBUG_PER_CPU_MAPS
Brian Gerst44581a22009-02-08 09:58:40 -0500754 if (cpu >= nr_cpu_ids || !cpu_possible(cpu)) {
Brian Gerst6470aff2009-01-27 12:56:47 +0900755 printk(KERN_ERR "numa_set_node: invalid cpu# (%d)\n", cpu);
756 dump_stack();
757 return;
758 }
759#endif
760 per_cpu(x86_cpu_to_node_map, cpu) = node;
761
762 if (node != NUMA_NO_NODE)
Lee Schermerhorne534c7c2010-05-26 14:44:58 -0700763 set_cpu_numa_node(cpu, node);
Brian Gerst6470aff2009-01-27 12:56:47 +0900764}
765
766void __cpuinit numa_clear_node(int cpu)
767{
768 numa_set_node(cpu, NUMA_NO_NODE);
769}
770
771#ifndef CONFIG_DEBUG_PER_CPU_MAPS
772
773void __cpuinit numa_add_cpu(int cpu)
774{
Rusty Russellc032ef602009-03-13 14:49:53 +1030775 cpumask_set_cpu(cpu, node_to_cpumask_map[early_cpu_to_node(cpu)]);
Brian Gerst6470aff2009-01-27 12:56:47 +0900776}
777
778void __cpuinit numa_remove_cpu(int cpu)
779{
Rusty Russellc032ef602009-03-13 14:49:53 +1030780 cpumask_clear_cpu(cpu, node_to_cpumask_map[early_cpu_to_node(cpu)]);
Brian Gerst6470aff2009-01-27 12:56:47 +0900781}
782
783#else /* CONFIG_DEBUG_PER_CPU_MAPS */
784
785/*
786 * --------- debug versions of the numa functions ---------
787 */
788static void __cpuinit numa_set_cpumask(int cpu, int enable)
789{
790 int node = early_cpu_to_node(cpu);
Rusty Russell73e907d2009-03-13 14:49:57 +1030791 struct cpumask *mask;
Brian Gerst6470aff2009-01-27 12:56:47 +0900792 char buf[64];
793
Rusty Russellc032ef602009-03-13 14:49:53 +1030794 mask = node_to_cpumask_map[node];
795 if (mask == NULL) {
796 printk(KERN_ERR "node_to_cpumask_map[%i] NULL\n", node);
Brian Gerst6470aff2009-01-27 12:56:47 +0900797 dump_stack();
798 return;
799 }
800
Brian Gerst6470aff2009-01-27 12:56:47 +0900801 if (enable)
Rusty Russellc032ef602009-03-13 14:49:53 +1030802 cpumask_set_cpu(cpu, mask);
Brian Gerst6470aff2009-01-27 12:56:47 +0900803 else
Rusty Russellc032ef602009-03-13 14:49:53 +1030804 cpumask_clear_cpu(cpu, mask);
Brian Gerst6470aff2009-01-27 12:56:47 +0900805
806 cpulist_scnprintf(buf, sizeof(buf), mask);
807 printk(KERN_DEBUG "%s cpu %d node %d: mask now %s\n",
808 enable ? "numa_add_cpu" : "numa_remove_cpu", cpu, node, buf);
809}
810
811void __cpuinit numa_add_cpu(int cpu)
812{
813 numa_set_cpumask(cpu, 1);
814}
815
816void __cpuinit numa_remove_cpu(int cpu)
817{
818 numa_set_cpumask(cpu, 0);
819}
820
Lee Schermerhorne534c7c2010-05-26 14:44:58 -0700821int __cpu_to_node(int cpu)
Brian Gerst6470aff2009-01-27 12:56:47 +0900822{
823 if (early_per_cpu_ptr(x86_cpu_to_node_map)) {
824 printk(KERN_WARNING
825 "cpu_to_node(%d): usage too early!\n", cpu);
826 dump_stack();
827 return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu];
828 }
829 return per_cpu(x86_cpu_to_node_map, cpu);
830}
Lee Schermerhorne534c7c2010-05-26 14:44:58 -0700831EXPORT_SYMBOL(__cpu_to_node);
Brian Gerst6470aff2009-01-27 12:56:47 +0900832
833/*
834 * Same function as cpu_to_node() but used if called before the
835 * per_cpu areas are setup.
836 */
837int early_cpu_to_node(int cpu)
838{
839 if (early_per_cpu_ptr(x86_cpu_to_node_map))
840 return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu];
841
Brian Gerst44581a22009-02-08 09:58:40 -0500842 if (!cpu_possible(cpu)) {
Brian Gerst6470aff2009-01-27 12:56:47 +0900843 printk(KERN_WARNING
844 "early_cpu_to_node(%d): no per_cpu area!\n", cpu);
845 dump_stack();
846 return NUMA_NO_NODE;
847 }
848 return per_cpu(x86_cpu_to_node_map, cpu);
849}
850
Brian Gerst6470aff2009-01-27 12:56:47 +0900851/*
Brian Gerst6470aff2009-01-27 12:56:47 +0900852 * --------- end of debug versions of the numa functions ---------
853 */
854
855#endif /* CONFIG_DEBUG_PER_CPU_MAPS */