Merge branch 'timers-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[pandora-kernel.git] / arch / x86 / mm / numa.c
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>
6
7 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
8 # define DBG(x...) printk(KERN_DEBUG x)
9 #else
10 # define DBG(x...)
11 #endif
12
13 /*
14  * Which logical CPUs are on which nodes
15  */
16 cpumask_var_t node_to_cpumask_map[MAX_NUMNODES];
17 EXPORT_SYMBOL(node_to_cpumask_map);
18
19 /*
20  * Allocate node_to_cpumask_map based on number of available nodes
21  * Requires node_possible_map to be valid.
22  *
23  * Note: node_to_cpumask() is not valid until after this is done.
24  * (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.)
25  */
26 void __init setup_node_to_cpumask_map(void)
27 {
28         unsigned int node, num = 0;
29
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)
33                         num = node;
34                 nr_node_ids = num + 1;
35         }
36
37         /* allocate the map */
38         for (node = 0; node < nr_node_ids; node++)
39                 alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]);
40
41         /* cpumask_of_node() will now work */
42         pr_debug("Node to cpumask map for %d nodes\n", nr_node_ids);
43 }
44
45 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
46 /*
47  * Returns a pointer to the bitmask of CPUs on Node 'node'.
48  */
49 const struct cpumask *cpumask_of_node(int node)
50 {
51         if (node >= nr_node_ids) {
52                 printk(KERN_WARNING
53                         "cpumask_of_node(%d): node > nr_node_ids(%d)\n",
54                         node, nr_node_ids);
55                 dump_stack();
56                 return cpu_none_mask;
57         }
58         if (node_to_cpumask_map[node] == NULL) {
59                 printk(KERN_WARNING
60                         "cpumask_of_node(%d): no node_to_cpumask_map!\n",
61                         node);
62                 dump_stack();
63                 return cpu_online_mask;
64         }
65         return node_to_cpumask_map[node];
66 }
67 EXPORT_SYMBOL(cpumask_of_node);
68 #endif
69
70 /*
71  * Return the bit number of a random bit set in the nodemask.
72  *   (returns -1 if nodemask is empty)
73  */
74 int __node_random(const nodemask_t *maskp)
75 {
76         int w, bit = -1;
77
78         w = nodes_weight(*maskp);
79         if (w)
80                 bit = bitmap_ord_to_pos(maskp->bits,
81                         get_random_int() % w, MAX_NUMNODES);
82         return bit;
83 }
84 EXPORT_SYMBOL(__node_random);