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 #include <linux/random.h>
7 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
8 # define DBG(x...) printk(KERN_DEBUG x)
14 * Which logical CPUs are on which nodes
16 cpumask_var_t node_to_cpumask_map[MAX_NUMNODES];
17 EXPORT_SYMBOL(node_to_cpumask_map);
20 * Allocate node_to_cpumask_map based on number of available nodes
21 * Requires node_possible_map to be valid.
23 * Note: node_to_cpumask() is not valid until after this is done.
24 * (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.)
26 void __init setup_node_to_cpumask_map(void)
28 unsigned int node, num = 0;
30 /* setup nr_node_ids if not done yet */
31 if (nr_node_ids == MAX_NUMNODES) {
32 for_each_node_mask(node, node_possible_map)
34 nr_node_ids = num + 1;
37 /* allocate the map */
38 for (node = 0; node < nr_node_ids; node++)
39 alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]);
41 /* cpumask_of_node() will now work */
42 pr_debug("Node to cpumask map for %d nodes\n", nr_node_ids);
45 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
47 * Returns a pointer to the bitmask of CPUs on Node 'node'.
49 const struct cpumask *cpumask_of_node(int node)
51 if (node >= nr_node_ids) {
53 "cpumask_of_node(%d): node > nr_node_ids(%d)\n",
58 if (node_to_cpumask_map[node] == NULL) {
60 "cpumask_of_node(%d): no node_to_cpumask_map!\n",
63 return cpu_online_mask;
65 return node_to_cpumask_map[node];
67 EXPORT_SYMBOL(cpumask_of_node);
71 * Return the bit number of a random bit set in the nodemask.
72 * (returns -1 if nodemask is empty)
74 int __node_random(const nodemask_t *maskp)
78 w = nodes_weight(*maskp);
80 bit = bitmap_ord_to_pos(maskp->bits,
81 get_random_int() % w, MAX_NUMNODES);
84 EXPORT_SYMBOL(__node_random);