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>
16 #include <linux/acpi.h>
19 #include <asm/proto.h>
23 #include <asm/amd_nb.h>
33 struct numa_memblk blk[NR_NODE_MEMBLKS];
36 struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
37 EXPORT_SYMBOL(node_data);
39 nodemask_t cpu_nodes_parsed __initdata;
40 nodemask_t mem_nodes_parsed __initdata;
42 struct memnode memnode;
44 static unsigned long __initdata nodemap_addr;
45 static unsigned long __initdata nodemap_size;
47 static struct numa_meminfo numa_meminfo __initdata;
49 struct bootnode numa_nodes[MAX_NUMNODES] __initdata;
52 * Given a shift value, try to populate memnodemap[]
55 * 0 if memnodmap[] too small (of shift too small)
56 * -1 if node overlap or lost ram (shift too big)
58 static int __init populate_memnodemap(const struct numa_meminfo *mi, int shift)
60 unsigned long addr, end;
63 memset(memnodemap, 0xff, sizeof(s16)*memnodemapsize);
64 for (i = 0; i < mi->nr_blks; i++) {
65 addr = mi->blk[i].start;
69 if ((end >> shift) >= memnodemapsize)
72 if (memnodemap[addr >> shift] != NUMA_NO_NODE)
74 memnodemap[addr >> shift] = mi->blk[i].nid;
75 addr += (1UL << shift);
82 static int __init allocate_cachealigned_memnodemap(void)
86 memnodemap = memnode.embedded_map;
87 if (memnodemapsize <= ARRAY_SIZE(memnode.embedded_map))
91 nodemap_size = roundup(sizeof(s16) * memnodemapsize, L1_CACHE_BYTES);
92 nodemap_addr = memblock_find_in_range(addr, get_max_mapped(),
93 nodemap_size, L1_CACHE_BYTES);
94 if (nodemap_addr == MEMBLOCK_ERROR) {
96 "NUMA: Unable to allocate Memory to Node hash map\n");
97 nodemap_addr = nodemap_size = 0;
100 memnodemap = phys_to_virt(nodemap_addr);
101 memblock_x86_reserve_range(nodemap_addr, nodemap_addr + nodemap_size, "MEMNODEMAP");
103 printk(KERN_DEBUG "NUMA: Allocated memnodemap from %lx - %lx\n",
104 nodemap_addr, nodemap_addr + nodemap_size);
109 * The LSB of all start and end addresses in the node map is the value of the
110 * maximum possible shift.
112 static int __init extract_lsb_from_nodes(const struct numa_meminfo *mi)
114 int i, nodes_used = 0;
115 unsigned long start, end;
116 unsigned long bitfield = 0, memtop = 0;
118 for (i = 0; i < mi->nr_blks; i++) {
119 start = mi->blk[i].start;
120 end = mi->blk[i].end;
131 i = find_first_bit(&bitfield, sizeof(unsigned long)*8);
132 memnodemapsize = (memtop >> i)+1;
136 static int __init compute_hash_shift(const struct numa_meminfo *mi)
140 shift = extract_lsb_from_nodes(mi);
141 if (allocate_cachealigned_memnodemap())
143 printk(KERN_DEBUG "NUMA: Using %d for the hash shift.\n",
146 if (populate_memnodemap(mi, shift) != 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 static __init int conflicting_memblks(unsigned long start, unsigned long end)
194 struct numa_meminfo *mi = &numa_meminfo;
197 for (i = 0; i < mi->nr_blks; i++) {
198 struct numa_memblk *blk = &mi->blk[i];
200 if (blk->start == blk->end)
202 if (blk->end > start && blk->start < end)
204 if (blk->end == end && blk->start == start)
210 int __init numa_add_memblk(int nid, u64 start, u64 end)
212 struct numa_meminfo *mi = &numa_meminfo;
215 i = conflicting_memblks(start, end);
217 printk(KERN_WARNING "NUMA: Warning: node %d (%Lx-%Lx) overlaps with itself (%Lx-%Lx)\n",
218 nid, start, end, numa_nodes[i].start, numa_nodes[i].end);
220 printk(KERN_ERR "NUMA: node %d (%Lx-%Lx) overlaps with node %d (%Lx-%Lx)\n",
222 numa_nodes[i].start, numa_nodes[i].end);
226 mi->blk[mi->nr_blks].start = start;
227 mi->blk[mi->nr_blks].end = end;
228 mi->blk[mi->nr_blks].nid = nid;
233 static void __init numa_remove_memblk_from(int idx, struct numa_meminfo *mi)
236 memmove(&mi->blk[idx], &mi->blk[idx + 1],
237 (mi->nr_blks - idx) * sizeof(mi->blk[0]));
240 static __init void cutoff_node(int i, unsigned long start, unsigned long end)
242 struct bootnode *nd = &numa_nodes[i];
244 if (nd->start < start) {
246 if (nd->end < nd->start)
251 if (nd->start > nd->end)
256 /* Initialize bootmem allocator for a node */
258 setup_node_bootmem(int nodeid, unsigned long start, unsigned long end)
260 unsigned long start_pfn, last_pfn, nodedata_phys;
261 const int pgdat_size = roundup(sizeof(pg_data_t), PAGE_SIZE);
268 * Don't confuse VM with a node that doesn't have the
269 * minimum amount of memory:
271 if (end && (end - start) < NODE_MIN_SIZE)
274 start = roundup(start, ZONE_ALIGN);
276 printk(KERN_INFO "Initmem setup node %d %016lx-%016lx\n", nodeid,
279 start_pfn = start >> PAGE_SHIFT;
280 last_pfn = end >> PAGE_SHIFT;
282 node_data[nodeid] = early_node_mem(nodeid, start, end, pgdat_size,
284 if (node_data[nodeid] == NULL)
286 nodedata_phys = __pa(node_data[nodeid]);
287 memblock_x86_reserve_range(nodedata_phys, nodedata_phys + pgdat_size, "NODE_DATA");
288 printk(KERN_INFO " NODE_DATA [%016lx - %016lx]\n", nodedata_phys,
289 nodedata_phys + pgdat_size - 1);
290 nid = phys_to_nid(nodedata_phys);
292 printk(KERN_INFO " NODE_DATA(%d) on node %d\n", nodeid, nid);
294 memset(NODE_DATA(nodeid), 0, sizeof(pg_data_t));
295 NODE_DATA(nodeid)->node_id = nodeid;
296 NODE_DATA(nodeid)->node_start_pfn = start_pfn;
297 NODE_DATA(nodeid)->node_spanned_pages = last_pfn - start_pfn;
299 node_set_online(nodeid);
302 static int __init numa_cleanup_meminfo(struct numa_meminfo *mi)
306 for (i = 0; i < mi->nr_blks; i++) {
307 struct numa_memblk *bi = &mi->blk[i];
309 for (j = i + 1; j < mi->nr_blks; j++) {
310 struct numa_memblk *bj = &mi->blk[j];
311 unsigned long start, end;
314 * Join together blocks on the same node, holes
315 * between which don't overlap with memory on other
318 if (bi->nid != bj->nid)
320 start = min(bi->start, bj->start);
321 end = max(bi->end, bj->end);
322 for (k = 0; k < mi->nr_blks; k++) {
323 struct numa_memblk *bk = &mi->blk[k];
325 if (bi->nid == bk->nid)
327 if (start < bk->end && end > bk->start)
332 printk(KERN_INFO "NUMA: Node %d [%Lx,%Lx) + [%Lx,%Lx) -> [%lx,%lx)\n",
333 bi->nid, bi->start, bi->end, bj->start, bj->end,
337 numa_remove_memblk_from(j--, mi);
345 * Sanity check to catch more bad NUMA configurations (they are amazingly
346 * common). Make sure the nodes cover all memory.
348 static int __init nodes_cover_memory(const struct bootnode *nodes)
350 unsigned long numaram, e820ram;
354 for_each_node_mask(i, mem_nodes_parsed) {
355 unsigned long s = nodes[i].start >> PAGE_SHIFT;
356 unsigned long e = nodes[i].end >> PAGE_SHIFT;
358 numaram -= __absent_pages_in_range(i, s, e);
359 if ((long)numaram < 0)
363 e820ram = max_pfn - (memblock_x86_hole_size(0,
364 max_pfn << PAGE_SHIFT) >> PAGE_SHIFT);
365 /* We seem to lose 3 pages somewhere. Allow 1M of slack. */
366 if ((long)(e820ram - numaram) >= (1 << (20 - PAGE_SHIFT))) {
367 printk(KERN_ERR "NUMA: nodes only cover %luMB of your %luMB e820 RAM. Not used.\n",
368 (numaram << PAGE_SHIFT) >> 20,
369 (e820ram << PAGE_SHIFT) >> 20);
375 static int __init numa_register_memblks(struct numa_meminfo *mi)
379 /* Account for nodes with cpus and no memory */
380 nodes_or(node_possible_map, mem_nodes_parsed, cpu_nodes_parsed);
381 if (WARN_ON(nodes_empty(node_possible_map)))
384 memnode_shift = compute_hash_shift(mi);
385 if (memnode_shift < 0) {
386 printk(KERN_ERR "NUMA: No NUMA node hash function found. Contact maintainer\n");
390 for (i = 0; i < mi->nr_blks; i++)
391 memblock_x86_register_active_regions(mi->blk[i].nid,
392 mi->blk[i].start >> PAGE_SHIFT,
393 mi->blk[i].end >> PAGE_SHIFT);
395 /* for out of order entries */
397 if (!nodes_cover_memory(numa_nodes))
400 init_memory_mapping_high();
402 /* Finally register nodes. */
403 for_each_node_mask(i, node_possible_map)
404 setup_node_bootmem(i, numa_nodes[i].start, numa_nodes[i].end);
407 * Try again in case setup_node_bootmem missed one due to missing
410 for_each_node_mask(i, node_possible_map)
412 setup_node_bootmem(i, numa_nodes[i].start,
418 #ifdef CONFIG_NUMA_EMU
420 static struct bootnode nodes[MAX_NUMNODES] __initdata;
421 static struct bootnode physnodes[MAX_NUMNODES] __cpuinitdata;
422 static char *cmdline __initdata;
424 void __init numa_emu_cmdline(char *str)
429 static int __init setup_physnodes(unsigned long start, unsigned long end)
434 memset(physnodes, 0, sizeof(physnodes));
436 for_each_node_mask(i, mem_nodes_parsed) {
437 physnodes[i].start = numa_nodes[i].start;
438 physnodes[i].end = numa_nodes[i].end;
442 * Basic sanity checking on the physical node map: there may be errors
443 * if the SRAT or AMD code incorrectly reported the topology or the mem=
444 * kernel parameter is used.
446 for (i = 0; i < MAX_NUMNODES; i++) {
447 if (physnodes[i].start == physnodes[i].end)
449 if (physnodes[i].start > end) {
450 physnodes[i].end = physnodes[i].start;
453 if (physnodes[i].end < start) {
454 physnodes[i].start = physnodes[i].end;
457 if (physnodes[i].start < start)
458 physnodes[i].start = start;
459 if (physnodes[i].end > end)
460 physnodes[i].end = end;
465 * If no physical topology was detected, a single node is faked to cover
466 * the entire address space.
469 physnodes[ret].start = start;
470 physnodes[ret].end = end;
476 static void __init fake_physnodes(int acpi, int amd, int nr_nodes)
481 #ifdef CONFIG_ACPI_NUMA
483 acpi_fake_nodes(nodes, nr_nodes);
485 #ifdef CONFIG_AMD_NUMA
487 amd_fake_nodes(nodes, nr_nodes);
490 for (i = 0; i < nr_cpu_ids; i++)
495 * Setups up nid to range from addr to addr + size. If the end
496 * boundary is greater than max_addr, then max_addr is used instead.
497 * The return value is 0 if there is additional memory left for
498 * allocation past addr and -1 otherwise. addr is adjusted to be at
499 * the end of the node.
501 static int __init setup_node_range(int nid, u64 *addr, u64 size, u64 max_addr)
504 nodes[nid].start = *addr;
506 if (*addr >= max_addr) {
510 nodes[nid].end = *addr;
511 node_set(nid, node_possible_map);
512 printk(KERN_INFO "Faking node %d at %016Lx-%016Lx (%LuMB)\n", nid,
513 nodes[nid].start, nodes[nid].end,
514 (nodes[nid].end - nodes[nid].start) >> 20);
519 * Sets up nr_nodes fake nodes interleaved over physical nodes ranging from addr
520 * to max_addr. The return value is the number of nodes allocated.
522 static int __init split_nodes_interleave(u64 addr, u64 max_addr, int nr_nodes)
524 nodemask_t physnode_mask = NODE_MASK_NONE;
532 if (nr_nodes > MAX_NUMNODES) {
533 pr_info("numa=fake=%d too large, reducing to %d\n",
534 nr_nodes, MAX_NUMNODES);
535 nr_nodes = MAX_NUMNODES;
538 size = (max_addr - addr - memblock_x86_hole_size(addr, max_addr)) / nr_nodes;
540 * Calculate the number of big nodes that can be allocated as a result
541 * of consolidating the remainder.
543 big = ((size & ~FAKE_NODE_MIN_HASH_MASK) * nr_nodes) /
546 size &= FAKE_NODE_MIN_HASH_MASK;
548 pr_err("Not enough memory for each node. "
549 "NUMA emulation disabled.\n");
553 for (i = 0; i < MAX_NUMNODES; i++)
554 if (physnodes[i].start != physnodes[i].end)
555 node_set(i, physnode_mask);
558 * Continue to fill physical nodes with fake nodes until there is no
559 * memory left on any of them.
561 while (nodes_weight(physnode_mask)) {
562 for_each_node_mask(i, physnode_mask) {
563 u64 end = physnodes[i].start + size;
564 u64 dma32_end = PFN_PHYS(MAX_DMA32_PFN);
567 end += FAKE_NODE_MIN_SIZE;
570 * Continue to add memory to this fake node if its
571 * non-reserved memory is less than the per-node size.
573 while (end - physnodes[i].start -
574 memblock_x86_hole_size(physnodes[i].start, end) < size) {
575 end += FAKE_NODE_MIN_SIZE;
576 if (end > physnodes[i].end) {
577 end = physnodes[i].end;
583 * If there won't be at least FAKE_NODE_MIN_SIZE of
584 * non-reserved memory in ZONE_DMA32 for the next node,
585 * this one must extend to the boundary.
587 if (end < dma32_end && dma32_end - end -
588 memblock_x86_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
592 * If there won't be enough non-reserved memory for the
593 * next node, this one must extend to the end of the
596 if (physnodes[i].end - end -
597 memblock_x86_hole_size(end, physnodes[i].end) < size)
598 end = physnodes[i].end;
601 * Avoid allocating more nodes than requested, which can
602 * happen as a result of rounding down each node's size
603 * to FAKE_NODE_MIN_SIZE.
605 if (nodes_weight(physnode_mask) + ret >= nr_nodes)
606 end = physnodes[i].end;
608 if (setup_node_range(ret++, &physnodes[i].start,
609 end - physnodes[i].start,
610 physnodes[i].end) < 0)
611 node_clear(i, physnode_mask);
618 * Returns the end address of a node so that there is at least `size' amount of
619 * non-reserved memory or `max_addr' is reached.
621 static u64 __init find_end_of_node(u64 start, u64 max_addr, u64 size)
623 u64 end = start + size;
625 while (end - start - memblock_x86_hole_size(start, end) < size) {
626 end += FAKE_NODE_MIN_SIZE;
627 if (end > max_addr) {
636 * Sets up fake nodes of `size' interleaved over physical nodes ranging from
637 * `addr' to `max_addr'. The return value is the number of nodes allocated.
639 static int __init split_nodes_size_interleave(u64 addr, u64 max_addr, u64 size)
641 nodemask_t physnode_mask = NODE_MASK_NONE;
649 * The limit on emulated nodes is MAX_NUMNODES, so the size per node is
650 * increased accordingly if the requested size is too small. This
651 * creates a uniform distribution of node sizes across the entire
652 * machine (but not necessarily over physical nodes).
654 min_size = (max_addr - addr - memblock_x86_hole_size(addr, max_addr)) /
656 min_size = max(min_size, FAKE_NODE_MIN_SIZE);
657 if ((min_size & FAKE_NODE_MIN_HASH_MASK) < min_size)
658 min_size = (min_size + FAKE_NODE_MIN_SIZE) &
659 FAKE_NODE_MIN_HASH_MASK;
660 if (size < min_size) {
661 pr_err("Fake node size %LuMB too small, increasing to %LuMB\n",
662 size >> 20, min_size >> 20);
665 size &= FAKE_NODE_MIN_HASH_MASK;
667 for (i = 0; i < MAX_NUMNODES; i++)
668 if (physnodes[i].start != physnodes[i].end)
669 node_set(i, physnode_mask);
671 * Fill physical nodes with fake nodes of size until there is no memory
672 * left on any of them.
674 while (nodes_weight(physnode_mask)) {
675 for_each_node_mask(i, physnode_mask) {
676 u64 dma32_end = MAX_DMA32_PFN << PAGE_SHIFT;
679 end = find_end_of_node(physnodes[i].start,
680 physnodes[i].end, size);
682 * If there won't be at least FAKE_NODE_MIN_SIZE of
683 * non-reserved memory in ZONE_DMA32 for the next node,
684 * this one must extend to the boundary.
686 if (end < dma32_end && dma32_end - end -
687 memblock_x86_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
691 * If there won't be enough non-reserved memory for the
692 * next node, this one must extend to the end of the
695 if (physnodes[i].end - end -
696 memblock_x86_hole_size(end, physnodes[i].end) < size)
697 end = physnodes[i].end;
700 * Setup the fake node that will be allocated as bootmem
701 * later. If setup_node_range() returns non-zero, there
702 * is no more memory available on this physical node.
704 if (setup_node_range(ret++, &physnodes[i].start,
705 end - physnodes[i].start,
706 physnodes[i].end) < 0)
707 node_clear(i, physnode_mask);
714 * Sets up the system RAM area from start_pfn to last_pfn according to the
715 * numa=fake command-line option.
717 static int __init numa_emulation(unsigned long start_pfn,
718 unsigned long last_pfn, int acpi, int amd)
720 static struct numa_meminfo ei __initdata;
721 u64 addr = start_pfn << PAGE_SHIFT;
722 u64 max_addr = last_pfn << PAGE_SHIFT;
727 * If the numa=fake command-line contains a 'M' or 'G', it represents
728 * the fixed node size. Otherwise, if it is just a single number N,
729 * split the system RAM into N fake nodes.
731 if (strchr(cmdline, 'M') || strchr(cmdline, 'G')) {
734 size = memparse(cmdline, &cmdline);
735 num_nodes = split_nodes_size_interleave(addr, max_addr, size);
739 n = simple_strtoul(cmdline, NULL, 0);
740 num_nodes = split_nodes_interleave(addr, max_addr, n);
746 ei.nr_blks = num_nodes;
747 for (i = 0; i < ei.nr_blks; i++) {
748 ei.blk[i].start = nodes[i].start;
749 ei.blk[i].end = nodes[i].end;
753 memnode_shift = compute_hash_shift(&ei);
754 if (memnode_shift < 0) {
756 printk(KERN_ERR "No NUMA hash function found. NUMA emulation "
762 * We need to vacate all active ranges that may have been registered for
763 * the e820 memory map.
765 remove_all_active_ranges();
766 for_each_node_mask(i, node_possible_map)
767 memblock_x86_register_active_regions(i, nodes[i].start >> PAGE_SHIFT,
768 nodes[i].end >> PAGE_SHIFT);
769 init_memory_mapping_high();
770 for_each_node_mask(i, node_possible_map)
771 setup_node_bootmem(i, nodes[i].start, nodes[i].end);
772 setup_physnodes(addr, max_addr);
773 fake_physnodes(acpi, amd, num_nodes);
777 #endif /* CONFIG_NUMA_EMU */
779 static int dummy_numa_init(void)
781 printk(KERN_INFO "%s\n",
782 numa_off ? "NUMA turned off" : "No NUMA configuration found");
783 printk(KERN_INFO "Faking a node at %016lx-%016lx\n",
784 0LU, max_pfn << PAGE_SHIFT);
786 node_set(0, cpu_nodes_parsed);
787 node_set(0, mem_nodes_parsed);
788 numa_add_memblk(0, 0, (u64)max_pfn << PAGE_SHIFT);
789 numa_nodes[0].start = 0;
790 numa_nodes[0].end = (u64)max_pfn << PAGE_SHIFT;
795 void __init initmem_init(void)
797 int (*numa_init[])(void) = { [2] = dummy_numa_init };
801 #ifdef CONFIG_ACPI_NUMA
802 numa_init[0] = x86_acpi_numa_init;
804 #ifdef CONFIG_AMD_NUMA
805 numa_init[1] = amd_numa_init;
809 for (i = 0; i < ARRAY_SIZE(numa_init); i++) {
813 for (j = 0; j < MAX_LOCAL_APIC; j++)
814 set_apicid_to_node(j, NUMA_NO_NODE);
816 nodes_clear(cpu_nodes_parsed);
817 nodes_clear(mem_nodes_parsed);
818 nodes_clear(node_possible_map);
819 nodes_clear(node_online_map);
820 memset(&numa_meminfo, 0, sizeof(numa_meminfo));
821 memset(numa_nodes, 0, sizeof(numa_nodes));
822 remove_all_active_ranges();
824 if (numa_init[i]() < 0)
827 /* clean up the node list */
828 for (j = 0; j < MAX_NUMNODES; j++)
829 cutoff_node(j, 0, max_pfn << PAGE_SHIFT);
831 #ifdef CONFIG_NUMA_EMU
832 setup_physnodes(0, max_pfn << PAGE_SHIFT);
833 if (cmdline && !numa_emulation(0, max_pfn, i == 0, i == 1))
835 setup_physnodes(0, max_pfn << PAGE_SHIFT);
836 nodes_clear(node_possible_map);
837 nodes_clear(node_online_map);
839 if (numa_cleanup_meminfo(&numa_meminfo) < 0)
842 if (numa_register_memblks(&numa_meminfo) < 0)
845 for (j = 0; j < nr_cpu_ids; j++) {
846 int nid = early_cpu_to_node(j);
848 if (nid == NUMA_NO_NODE)
850 if (!node_online(nid))
859 unsigned long __init numa_free_all_bootmem(void)
861 unsigned long pages = 0;
864 for_each_online_node(i)
865 pages += free_all_bootmem_node(NODE_DATA(i));
867 pages += free_all_memory_core_early(MAX_NUMNODES);
872 int __cpuinit numa_cpu_node(int cpu)
874 int apicid = early_per_cpu(x86_cpu_to_apicid, cpu);
876 if (apicid != BAD_APICID)
877 return __apicid_to_node[apicid];
882 * UGLINESS AHEAD: Currently, CONFIG_NUMA_EMU is 64bit only and makes use
883 * of 64bit specific data structures. The distinction is artificial and
884 * should be removed. numa_{add|remove}_cpu() are implemented in numa.c
885 * for both 32 and 64bit when CONFIG_NUMA_EMU is disabled but here when
888 * NUMA emulation is planned to be made generic and the following and other
889 * related code should be moved to numa.c.
891 #ifdef CONFIG_NUMA_EMU
892 # ifndef CONFIG_DEBUG_PER_CPU_MAPS
893 void __cpuinit numa_add_cpu(int cpu)
898 nid = numa_cpu_node(cpu);
899 if (nid == NUMA_NO_NODE)
900 nid = early_cpu_to_node(cpu);
901 BUG_ON(nid == NUMA_NO_NODE || !node_online(nid));
904 * Use the starting address of the emulated node to find which physical
905 * node it is allocated on.
907 addr = node_start_pfn(nid) << PAGE_SHIFT;
908 for (physnid = 0; physnid < MAX_NUMNODES; physnid++)
909 if (addr >= physnodes[physnid].start &&
910 addr < physnodes[physnid].end)
914 * Map the cpu to each emulated node that is allocated on the physical
915 * node of the cpu's apic id.
917 for_each_online_node(nid) {
918 addr = node_start_pfn(nid) << PAGE_SHIFT;
919 if (addr >= physnodes[physnid].start &&
920 addr < physnodes[physnid].end)
921 cpumask_set_cpu(cpu, node_to_cpumask_map[nid]);
925 void __cpuinit numa_remove_cpu(int cpu)
929 for_each_online_node(i)
930 cpumask_clear_cpu(cpu, node_to_cpumask_map[i]);
932 # else /* !CONFIG_DEBUG_PER_CPU_MAPS */
933 static void __cpuinit numa_set_cpumask(int cpu, int enable)
935 int node = early_cpu_to_node(cpu);
936 struct cpumask *mask;
939 if (node == NUMA_NO_NODE) {
940 /* early_cpu_to_node() already emits a warning and trace */
943 for_each_online_node(i) {
946 addr = node_start_pfn(i) << PAGE_SHIFT;
947 if (addr < physnodes[node].start ||
948 addr >= physnodes[node].end)
950 mask = debug_cpumask_set_cpu(cpu, enable);
955 cpumask_set_cpu(cpu, mask);
957 cpumask_clear_cpu(cpu, mask);
961 void __cpuinit numa_add_cpu(int cpu)
963 numa_set_cpumask(cpu, 1);
966 void __cpuinit numa_remove_cpu(int cpu)
968 numa_set_cpumask(cpu, 0);
970 # endif /* !CONFIG_DEBUG_PER_CPU_MAPS */
971 #endif /* CONFIG_NUMA_EMU */