xref: /linux/arch/x86/mm/numa.c (revision 0dd9ac63ce26ec87b080ca9c3e6efed33c23ace6)
1 /* Common code for 32 and 64-bit NUMA */
2 #include <linux/topology.h>
3 #include <linux/module.h>
4 #include <linux/bootmem.h>
5 
6 /*
7  * Which logical CPUs are on which nodes
8  */
9 cpumask_var_t node_to_cpumask_map[MAX_NUMNODES];
10 EXPORT_SYMBOL(node_to_cpumask_map);
11 
12 /*
13  * Allocate node_to_cpumask_map based on number of available nodes
14  * Requires node_possible_map to be valid.
15  *
16  * Note: node_to_cpumask() is not valid until after this is done.
17  * (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.)
18  */
19 void __init setup_node_to_cpumask_map(void)
20 {
21 	unsigned int node, num = 0;
22 
23 	/* setup nr_node_ids if not done yet */
24 	if (nr_node_ids == MAX_NUMNODES) {
25 		for_each_node_mask(node, node_possible_map)
26 			num = node;
27 		nr_node_ids = num + 1;
28 	}
29 
30 	/* allocate the map */
31 	for (node = 0; node < nr_node_ids; node++)
32 		alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]);
33 
34 	/* cpumask_of_node() will now work */
35 	pr_debug("Node to cpumask map for %d nodes\n", nr_node_ids);
36 }
37 
38 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
39 /*
40  * Returns a pointer to the bitmask of CPUs on Node 'node'.
41  */
42 const struct cpumask *cpumask_of_node(int node)
43 {
44 	if (node >= nr_node_ids) {
45 		printk(KERN_WARNING
46 			"cpumask_of_node(%d): node > nr_node_ids(%d)\n",
47 			node, nr_node_ids);
48 		dump_stack();
49 		return cpu_none_mask;
50 	}
51 	if (node_to_cpumask_map[node] == NULL) {
52 		printk(KERN_WARNING
53 			"cpumask_of_node(%d): no node_to_cpumask_map!\n",
54 			node);
55 		dump_stack();
56 		return cpu_online_mask;
57 	}
58 	return node_to_cpumask_map[node];
59 }
60 EXPORT_SYMBOL(cpumask_of_node);
61 #endif
62