2 * Generic VM initialization for x86-64 NUMA setups.
3 * Copyright 2002,2003 Andi Kleen, SuSE Labs.
5 #include <linux/kernel.h>
7 #include <linux/string.h>
8 #include <linux/init.h>
9 #include <linux/bootmem.h>
10 #include <linux/memblock.h>
11 #include <linux/mmzone.h>
12 #include <linux/ctype.h>
13 #include <linux/module.h>
14 #include <linux/nodemask.h>
15 #include <linux/sched.h>
18 #include <asm/proto.h>
22 #include <asm/amd_nb.h>
24 struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
25 EXPORT_SYMBOL(node_data);
27 struct memnode memnode;
29 s16 apicid_to_node[MAX_LOCAL_APIC] __cpuinitdata = {
30 [0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE
33 int numa_off __initdata;
34 static unsigned long __initdata nodemap_addr;
35 static unsigned long __initdata nodemap_size;
38 * Map cpu index to node index
40 DEFINE_EARLY_PER_CPU(int, x86_cpu_to_node_map, NUMA_NO_NODE);
41 EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_node_map);
44 * Given a shift value, try to populate memnodemap[]
47 * 0 if memnodmap[] too small (of shift too small)
48 * -1 if node overlap or lost ram (shift too big)
50 static int __init populate_memnodemap(const struct bootnode *nodes,
51 int numnodes, int shift, int *nodeids)
53 unsigned long addr, end;
56 memset(memnodemap, 0xff, sizeof(s16)*memnodemapsize);
57 for (i = 0; i < numnodes; i++) {
58 addr = nodes[i].start;
62 if ((end >> shift) >= memnodemapsize)
65 if (memnodemap[addr >> shift] != NUMA_NO_NODE)
69 memnodemap[addr >> shift] = i;
71 memnodemap[addr >> shift] = nodeids[i];
73 addr += (1UL << shift);
80 static int __init allocate_cachealigned_memnodemap(void)
84 memnodemap = memnode.embedded_map;
85 if (memnodemapsize <= ARRAY_SIZE(memnode.embedded_map))
89 nodemap_size = roundup(sizeof(s16) * memnodemapsize, L1_CACHE_BYTES);
90 nodemap_addr = memblock_find_in_range(addr, max_pfn<<PAGE_SHIFT,
91 nodemap_size, L1_CACHE_BYTES);
92 if (nodemap_addr == MEMBLOCK_ERROR) {
94 "NUMA: Unable to allocate Memory to Node hash map\n");
95 nodemap_addr = nodemap_size = 0;
98 memnodemap = phys_to_virt(nodemap_addr);
99 memblock_x86_reserve_range(nodemap_addr, nodemap_addr + nodemap_size, "MEMNODEMAP");
101 printk(KERN_DEBUG "NUMA: Allocated memnodemap from %lx - %lx\n",
102 nodemap_addr, nodemap_addr + nodemap_size);
107 * The LSB of all start and end addresses in the node map is the value of the
108 * maximum possible shift.
110 static int __init extract_lsb_from_nodes(const struct bootnode *nodes,
113 int i, nodes_used = 0;
114 unsigned long start, end;
115 unsigned long bitfield = 0, memtop = 0;
117 for (i = 0; i < numnodes; i++) {
118 start = nodes[i].start;
130 i = find_first_bit(&bitfield, sizeof(unsigned long)*8);
131 memnodemapsize = (memtop >> i)+1;
135 int __init compute_hash_shift(struct bootnode *nodes, int numnodes,
140 shift = extract_lsb_from_nodes(nodes, numnodes);
141 if (allocate_cachealigned_memnodemap())
143 printk(KERN_DEBUG "NUMA: Using %d for the hash shift.\n",
146 if (populate_memnodemap(nodes, numnodes, shift, nodeids) != 1) {
147 printk(KERN_INFO "Your memory is not aligned you need to "
148 "rebuild your kernel with a bigger NODEMAPSIZE "
149 "shift=%d\n", shift);
155 int __meminit __early_pfn_to_nid(unsigned long pfn)
157 return phys_to_nid(pfn << PAGE_SHIFT);
160 static void * __init early_node_mem(int nodeid, unsigned long start,
161 unsigned long end, unsigned long size,
167 * put it on high as possible
168 * something will go with NODE_DATA
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;
175 mem = memblock_x86_find_in_range_node(nodeid, start, end, size, align);
176 if (mem != MEMBLOCK_ERROR)
179 /* extend the search scope */
180 end = max_pfn_mapped << PAGE_SHIFT;
181 start = MAX_DMA_PFN << PAGE_SHIFT;
182 mem = memblock_find_in_range(start, end, size, align);
183 if (mem != MEMBLOCK_ERROR)
186 printk(KERN_ERR "Cannot find %lu bytes in node %d\n",
192 /* Initialize bootmem allocator for a node */
194 setup_node_bootmem(int nodeid, unsigned long start, unsigned long end)
196 unsigned long start_pfn, last_pfn, nodedata_phys;
197 const int pgdat_size = roundup(sizeof(pg_data_t), PAGE_SIZE);
204 * Don't confuse VM with a node that doesn't have the
205 * minimum amount of memory:
207 if (end && (end - start) < NODE_MIN_SIZE)
210 start = roundup(start, ZONE_ALIGN);
212 printk(KERN_INFO "Initmem setup node %d %016lx-%016lx\n", nodeid,
215 start_pfn = start >> PAGE_SHIFT;
216 last_pfn = end >> PAGE_SHIFT;
218 node_data[nodeid] = early_node_mem(nodeid, start, end, pgdat_size,
220 if (node_data[nodeid] == NULL)
222 nodedata_phys = __pa(node_data[nodeid]);
223 memblock_x86_reserve_range(nodedata_phys, nodedata_phys + pgdat_size, "NODE_DATA");
224 printk(KERN_INFO " NODE_DATA [%016lx - %016lx]\n", nodedata_phys,
225 nodedata_phys + pgdat_size - 1);
226 nid = phys_to_nid(nodedata_phys);
228 printk(KERN_INFO " NODE_DATA(%d) on node %d\n", nodeid, nid);
230 memset(NODE_DATA(nodeid), 0, sizeof(pg_data_t));
231 NODE_DATA(nodeid)->node_id = nodeid;
232 NODE_DATA(nodeid)->node_start_pfn = start_pfn;
233 NODE_DATA(nodeid)->node_spanned_pages = last_pfn - start_pfn;
235 node_set_online(nodeid);
239 * There are unfortunately some poorly designed mainboards around that
240 * only connect memory to a single CPU. This breaks the 1:1 cpu->node
241 * mapping. To avoid this fill in the mapping for all possible CPUs,
242 * as the number of CPUs is not known yet. We round robin the existing
245 void __init numa_init_array(void)
249 rr = first_node(node_online_map);
250 for (i = 0; i < nr_cpu_ids; i++) {
251 if (early_cpu_to_node(i) != NUMA_NO_NODE)
253 numa_set_node(i, rr);
254 rr = next_node(rr, node_online_map);
255 if (rr == MAX_NUMNODES)
256 rr = first_node(node_online_map);
260 #ifdef CONFIG_NUMA_EMU
262 static struct bootnode nodes[MAX_NUMNODES] __initdata;
263 static struct bootnode physnodes[MAX_NUMNODES] __cpuinitdata;
264 static char *cmdline __initdata;
266 static int __init setup_physnodes(unsigned long start, unsigned long end,
272 memset(physnodes, 0, sizeof(physnodes));
273 #ifdef CONFIG_ACPI_NUMA
275 acpi_get_nodes(physnodes, start, end);
277 #ifdef CONFIG_AMD_NUMA
279 amd_get_nodes(physnodes);
282 * Basic sanity checking on the physical node map: there may be errors
283 * if the SRAT or AMD code incorrectly reported the topology or the mem=
284 * kernel parameter is used.
286 for (i = 0; i < MAX_NUMNODES; i++) {
287 if (physnodes[i].start == physnodes[i].end)
289 if (physnodes[i].start > end) {
290 physnodes[i].end = physnodes[i].start;
293 if (physnodes[i].end < start) {
294 physnodes[i].start = physnodes[i].end;
297 if (physnodes[i].start < start)
298 physnodes[i].start = start;
299 if (physnodes[i].end > end)
300 physnodes[i].end = end;
305 * If no physical topology was detected, a single node is faked to cover
306 * the entire address space.
309 physnodes[ret].start = start;
310 physnodes[ret].end = end;
316 static void __init fake_physnodes(int acpi, int amd, int nr_nodes)
321 #ifdef CONFIG_ACPI_NUMA
323 acpi_fake_nodes(nodes, nr_nodes);
325 #ifdef CONFIG_AMD_NUMA
327 amd_fake_nodes(nodes, nr_nodes);
330 for (i = 0; i < nr_cpu_ids; i++)
335 * Setups up nid to range from addr to addr + size. If the end
336 * boundary is greater than max_addr, then max_addr is used instead.
337 * The return value is 0 if there is additional memory left for
338 * allocation past addr and -1 otherwise. addr is adjusted to be at
339 * the end of the node.
341 static int __init setup_node_range(int nid, u64 *addr, u64 size, u64 max_addr)
344 nodes[nid].start = *addr;
346 if (*addr >= max_addr) {
350 nodes[nid].end = *addr;
351 node_set(nid, node_possible_map);
352 printk(KERN_INFO "Faking node %d at %016Lx-%016Lx (%LuMB)\n", nid,
353 nodes[nid].start, nodes[nid].end,
354 (nodes[nid].end - nodes[nid].start) >> 20);
359 * Sets up nr_nodes fake nodes interleaved over physical nodes ranging from addr
360 * to max_addr. The return value is the number of nodes allocated.
362 static int __init split_nodes_interleave(u64 addr, u64 max_addr, int nr_nodes)
364 nodemask_t physnode_mask = NODE_MASK_NONE;
372 if (nr_nodes > MAX_NUMNODES) {
373 pr_info("numa=fake=%d too large, reducing to %d\n",
374 nr_nodes, MAX_NUMNODES);
375 nr_nodes = MAX_NUMNODES;
378 size = (max_addr - addr - memblock_x86_hole_size(addr, max_addr)) / nr_nodes;
380 * Calculate the number of big nodes that can be allocated as a result
381 * of consolidating the remainder.
383 big = ((size & ~FAKE_NODE_MIN_HASH_MASK) * nr_nodes) /
386 size &= FAKE_NODE_MIN_HASH_MASK;
388 pr_err("Not enough memory for each node. "
389 "NUMA emulation disabled.\n");
393 for (i = 0; i < MAX_NUMNODES; i++)
394 if (physnodes[i].start != physnodes[i].end)
395 node_set(i, physnode_mask);
398 * Continue to fill physical nodes with fake nodes until there is no
399 * memory left on any of them.
401 while (nodes_weight(physnode_mask)) {
402 for_each_node_mask(i, physnode_mask) {
403 u64 end = physnodes[i].start + size;
404 u64 dma32_end = PFN_PHYS(MAX_DMA32_PFN);
407 end += FAKE_NODE_MIN_SIZE;
410 * Continue to add memory to this fake node if its
411 * non-reserved memory is less than the per-node size.
413 while (end - physnodes[i].start -
414 memblock_x86_hole_size(physnodes[i].start, end) < size) {
415 end += FAKE_NODE_MIN_SIZE;
416 if (end > physnodes[i].end) {
417 end = physnodes[i].end;
423 * If there won't be at least FAKE_NODE_MIN_SIZE of
424 * non-reserved memory in ZONE_DMA32 for the next node,
425 * this one must extend to the boundary.
427 if (end < dma32_end && dma32_end - end -
428 memblock_x86_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
432 * If there won't be enough non-reserved memory for the
433 * next node, this one must extend to the end of the
436 if (physnodes[i].end - end -
437 memblock_x86_hole_size(end, physnodes[i].end) < size)
438 end = physnodes[i].end;
441 * Avoid allocating more nodes than requested, which can
442 * happen as a result of rounding down each node's size
443 * to FAKE_NODE_MIN_SIZE.
445 if (nodes_weight(physnode_mask) + ret >= nr_nodes)
446 end = physnodes[i].end;
448 if (setup_node_range(ret++, &physnodes[i].start,
449 end - physnodes[i].start,
450 physnodes[i].end) < 0)
451 node_clear(i, physnode_mask);
458 * Returns the end address of a node so that there is at least `size' amount of
459 * non-reserved memory or `max_addr' is reached.
461 static u64 __init find_end_of_node(u64 start, u64 max_addr, u64 size)
463 u64 end = start + size;
465 while (end - start - memblock_x86_hole_size(start, end) < size) {
466 end += FAKE_NODE_MIN_SIZE;
467 if (end > max_addr) {
476 * Sets up fake nodes of `size' interleaved over physical nodes ranging from
477 * `addr' to `max_addr'. The return value is the number of nodes allocated.
479 static int __init split_nodes_size_interleave(u64 addr, u64 max_addr, u64 size)
481 nodemask_t physnode_mask = NODE_MASK_NONE;
489 * The limit on emulated nodes is MAX_NUMNODES, so the size per node is
490 * increased accordingly if the requested size is too small. This
491 * creates a uniform distribution of node sizes across the entire
492 * machine (but not necessarily over physical nodes).
494 min_size = (max_addr - addr - memblock_x86_hole_size(addr, max_addr)) /
496 min_size = max(min_size, FAKE_NODE_MIN_SIZE);
497 if ((min_size & FAKE_NODE_MIN_HASH_MASK) < min_size)
498 min_size = (min_size + FAKE_NODE_MIN_SIZE) &
499 FAKE_NODE_MIN_HASH_MASK;
500 if (size < min_size) {
501 pr_err("Fake node size %LuMB too small, increasing to %LuMB\n",
502 size >> 20, min_size >> 20);
505 size &= FAKE_NODE_MIN_HASH_MASK;
507 for (i = 0; i < MAX_NUMNODES; i++)
508 if (physnodes[i].start != physnodes[i].end)
509 node_set(i, physnode_mask);
511 * Fill physical nodes with fake nodes of size until there is no memory
512 * left on any of them.
514 while (nodes_weight(physnode_mask)) {
515 for_each_node_mask(i, physnode_mask) {
516 u64 dma32_end = MAX_DMA32_PFN << PAGE_SHIFT;
519 end = find_end_of_node(physnodes[i].start,
520 physnodes[i].end, size);
522 * If there won't be at least FAKE_NODE_MIN_SIZE of
523 * non-reserved memory in ZONE_DMA32 for the next node,
524 * this one must extend to the boundary.
526 if (end < dma32_end && dma32_end - end -
527 memblock_x86_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
531 * If there won't be enough non-reserved memory for the
532 * next node, this one must extend to the end of the
535 if (physnodes[i].end - end -
536 memblock_x86_hole_size(end, physnodes[i].end) < size)
537 end = physnodes[i].end;
540 * Setup the fake node that will be allocated as bootmem
541 * later. If setup_node_range() returns non-zero, there
542 * is no more memory available on this physical node.
544 if (setup_node_range(ret++, &physnodes[i].start,
545 end - physnodes[i].start,
546 physnodes[i].end) < 0)
547 node_clear(i, physnode_mask);
554 * Sets up the system RAM area from start_pfn to last_pfn according to the
555 * numa=fake command-line option.
557 static int __init numa_emulation(unsigned long start_pfn,
558 unsigned long last_pfn, int acpi, int amd)
560 u64 addr = start_pfn << PAGE_SHIFT;
561 u64 max_addr = last_pfn << PAGE_SHIFT;
566 * If the numa=fake command-line contains a 'M' or 'G', it represents
567 * the fixed node size. Otherwise, if it is just a single number N,
568 * split the system RAM into N fake nodes.
570 if (strchr(cmdline, 'M') || strchr(cmdline, 'G')) {
573 size = memparse(cmdline, &cmdline);
574 num_nodes = split_nodes_size_interleave(addr, max_addr, size);
578 n = simple_strtoul(cmdline, NULL, 0);
579 num_nodes = split_nodes_interleave(addr, max_addr, n);
584 memnode_shift = compute_hash_shift(nodes, num_nodes, NULL);
585 if (memnode_shift < 0) {
587 printk(KERN_ERR "No NUMA hash function found. NUMA emulation "
593 * We need to vacate all active ranges that may have been registered for
594 * the e820 memory map.
596 remove_all_active_ranges();
597 for_each_node_mask(i, node_possible_map) {
598 memblock_x86_register_active_regions(i, nodes[i].start >> PAGE_SHIFT,
599 nodes[i].end >> PAGE_SHIFT);
600 setup_node_bootmem(i, nodes[i].start, nodes[i].end);
602 setup_physnodes(addr, max_addr, acpi, amd);
603 fake_physnodes(acpi, amd, num_nodes);
607 #endif /* CONFIG_NUMA_EMU */
609 void __init initmem_init(unsigned long start_pfn, unsigned long last_pfn,
614 nodes_clear(node_possible_map);
615 nodes_clear(node_online_map);
617 #ifdef CONFIG_NUMA_EMU
618 setup_physnodes(start_pfn << PAGE_SHIFT, last_pfn << PAGE_SHIFT,
620 if (cmdline && !numa_emulation(start_pfn, last_pfn, acpi, amd))
622 setup_physnodes(start_pfn << PAGE_SHIFT, last_pfn << PAGE_SHIFT,
624 nodes_clear(node_possible_map);
625 nodes_clear(node_online_map);
628 #ifdef CONFIG_ACPI_NUMA
629 if (!numa_off && acpi && !acpi_scan_nodes(start_pfn << PAGE_SHIFT,
630 last_pfn << PAGE_SHIFT))
632 nodes_clear(node_possible_map);
633 nodes_clear(node_online_map);
636 #ifdef CONFIG_AMD_NUMA
637 if (!numa_off && amd && !amd_scan_nodes())
639 nodes_clear(node_possible_map);
640 nodes_clear(node_online_map);
642 printk(KERN_INFO "%s\n",
643 numa_off ? "NUMA turned off" : "No NUMA configuration found");
645 printk(KERN_INFO "Faking a node at %016lx-%016lx\n",
646 start_pfn << PAGE_SHIFT,
647 last_pfn << PAGE_SHIFT);
648 /* setup dummy node covering all memory */
650 memnodemap = memnode.embedded_map;
653 node_set(0, node_possible_map);
654 for (i = 0; i < nr_cpu_ids; i++)
656 memblock_x86_register_active_regions(0, start_pfn, last_pfn);
657 setup_node_bootmem(0, start_pfn << PAGE_SHIFT, last_pfn << PAGE_SHIFT);
660 unsigned long __init numa_free_all_bootmem(void)
662 unsigned long pages = 0;
665 for_each_online_node(i)
666 pages += free_all_bootmem_node(NODE_DATA(i));
668 pages += free_all_memory_core_early(MAX_NUMNODES);
673 static __init int numa_setup(char *opt)
677 if (!strncmp(opt, "off", 3))
679 #ifdef CONFIG_NUMA_EMU
680 if (!strncmp(opt, "fake=", 5))
683 #ifdef CONFIG_ACPI_NUMA
684 if (!strncmp(opt, "noacpi", 6))
689 early_param("numa", numa_setup);
693 static __init int find_near_online_node(int node)
696 int min_val = INT_MAX;
699 for_each_online_node(n) {
700 val = node_distance(node, n);
712 * Setup early cpu_to_node.
714 * Populate cpu_to_node[] only if x86_cpu_to_apicid[],
715 * and apicid_to_node[] tables have valid entries for a CPU.
716 * This means we skip cpu_to_node[] initialisation for NUMA
717 * emulation and faking node case (when running a kernel compiled
718 * for NUMA on a non NUMA box), which is OK as cpu_to_node[]
719 * is already initialized in a round robin manner at numa_init_array,
720 * prior to this call, and this initialization is good enough
721 * for the fake NUMA cases.
723 * Called before the per_cpu areas are setup.
725 void __init init_cpu_to_node(void)
728 u16 *cpu_to_apicid = early_per_cpu_ptr(x86_cpu_to_apicid);
730 BUG_ON(cpu_to_apicid == NULL);
732 for_each_possible_cpu(cpu) {
734 u16 apicid = cpu_to_apicid[cpu];
736 if (apicid == BAD_APICID)
738 node = apicid_to_node[apicid];
739 if (node == NUMA_NO_NODE)
741 if (!node_online(node))
742 node = find_near_online_node(node);
743 numa_set_node(cpu, node);
749 void __cpuinit numa_set_node(int cpu, int node)
751 int *cpu_to_node_map = early_per_cpu_ptr(x86_cpu_to_node_map);
753 /* early setting, no percpu area yet */
754 if (cpu_to_node_map) {
755 cpu_to_node_map[cpu] = node;
759 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
760 if (cpu >= nr_cpu_ids || !cpu_possible(cpu)) {
761 printk(KERN_ERR "numa_set_node: invalid cpu# (%d)\n", cpu);
766 per_cpu(x86_cpu_to_node_map, cpu) = node;
768 if (node != NUMA_NO_NODE)
769 set_cpu_numa_node(cpu, node);
772 void __cpuinit numa_clear_node(int cpu)
774 numa_set_node(cpu, NUMA_NO_NODE);
777 #ifndef CONFIG_DEBUG_PER_CPU_MAPS
779 #ifndef CONFIG_NUMA_EMU
780 void __cpuinit numa_add_cpu(int cpu)
782 cpumask_set_cpu(cpu, node_to_cpumask_map[early_cpu_to_node(cpu)]);
785 void __cpuinit numa_remove_cpu(int cpu)
787 cpumask_clear_cpu(cpu, node_to_cpumask_map[early_cpu_to_node(cpu)]);
790 void __cpuinit numa_add_cpu(int cpu)
795 int nid = NUMA_NO_NODE;
797 apicid = early_per_cpu(x86_cpu_to_apicid, cpu);
798 if (apicid != BAD_APICID)
799 nid = apicid_to_node[apicid];
800 if (nid == NUMA_NO_NODE)
801 nid = early_cpu_to_node(cpu);
802 BUG_ON(nid == NUMA_NO_NODE || !node_online(nid));
805 * Use the starting address of the emulated node to find which physical
806 * node it is allocated on.
808 addr = node_start_pfn(nid) << PAGE_SHIFT;
809 for (physnid = 0; physnid < MAX_NUMNODES; physnid++)
810 if (addr >= physnodes[physnid].start &&
811 addr < physnodes[physnid].end)
815 * Map the cpu to each emulated node that is allocated on the physical
816 * node of the cpu's apic id.
818 for_each_online_node(nid) {
819 addr = node_start_pfn(nid) << PAGE_SHIFT;
820 if (addr >= physnodes[physnid].start &&
821 addr < physnodes[physnid].end)
822 cpumask_set_cpu(cpu, node_to_cpumask_map[nid]);
826 void __cpuinit numa_remove_cpu(int cpu)
830 for_each_online_node(i)
831 cpumask_clear_cpu(cpu, node_to_cpumask_map[i]);
833 #endif /* !CONFIG_NUMA_EMU */
835 #else /* CONFIG_DEBUG_PER_CPU_MAPS */
836 static struct cpumask __cpuinit *debug_cpumask_set_cpu(int cpu, int enable)
838 int node = early_cpu_to_node(cpu);
839 struct cpumask *mask;
842 mask = node_to_cpumask_map[node];
844 pr_err("node_to_cpumask_map[%i] NULL\n", node);
849 cpulist_scnprintf(buf, sizeof(buf), mask);
850 printk(KERN_DEBUG "%s cpu %d node %d: mask now %s\n",
851 enable ? "numa_add_cpu" : "numa_remove_cpu",
857 * --------- debug versions of the numa functions ---------
859 #ifndef CONFIG_NUMA_EMU
860 static void __cpuinit numa_set_cpumask(int cpu, int enable)
862 struct cpumask *mask;
864 mask = debug_cpumask_set_cpu(cpu, enable);
869 cpumask_set_cpu(cpu, mask);
871 cpumask_clear_cpu(cpu, mask);
874 static void __cpuinit numa_set_cpumask(int cpu, int enable)
876 int node = early_cpu_to_node(cpu);
877 struct cpumask *mask;
880 for_each_online_node(i) {
883 addr = node_start_pfn(i) << PAGE_SHIFT;
884 if (addr < physnodes[node].start ||
885 addr >= physnodes[node].end)
887 mask = debug_cpumask_set_cpu(cpu, enable);
892 cpumask_set_cpu(cpu, mask);
894 cpumask_clear_cpu(cpu, mask);
897 #endif /* CONFIG_NUMA_EMU */
899 void __cpuinit numa_add_cpu(int cpu)
901 numa_set_cpumask(cpu, 1);
904 void __cpuinit numa_remove_cpu(int cpu)
906 numa_set_cpumask(cpu, 0);
909 int __cpu_to_node(int cpu)
911 if (early_per_cpu_ptr(x86_cpu_to_node_map)) {
913 "cpu_to_node(%d): usage too early!\n", cpu);
915 return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu];
917 return per_cpu(x86_cpu_to_node_map, cpu);
919 EXPORT_SYMBOL(__cpu_to_node);
922 * Same function as cpu_to_node() but used if called before the
923 * per_cpu areas are setup.
925 int early_cpu_to_node(int cpu)
927 if (early_per_cpu_ptr(x86_cpu_to_node_map))
928 return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu];
930 if (!cpu_possible(cpu)) {
932 "early_cpu_to_node(%d): no per_cpu area!\n", cpu);
936 return per_cpu(x86_cpu_to_node_map, cpu);
940 * --------- end of debug versions of the numa functions ---------
943 #endif /* CONFIG_DEBUG_PER_CPU_MAPS */