blob: 550df481accd58d8ce23e7c96549f0507b1365b8 [file] [log] [blame]
Rusty Russell71ee73e2009-03-13 14:49:52 +10301/* 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#ifdef CONFIG_DEBUG_PER_CPU_MAPS
7# define DBG(x...) printk(KERN_DEBUG x)
8#else
9# define DBG(x...)
10#endif
11
12/*
13 * Which logical CPUs are on which nodes
14 */
Rusty Russellc032ef602009-03-13 14:49:53 +103015cpumask_var_t node_to_cpumask_map[MAX_NUMNODES];
Rusty Russell71ee73e2009-03-13 14:49:52 +103016EXPORT_SYMBOL(node_to_cpumask_map);
17
18/*
19 * Allocate node_to_cpumask_map based on number of available nodes
20 * Requires node_possible_map to be valid.
21 *
22 * Note: node_to_cpumask() is not valid until after this is done.
23 * (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.)
24 */
25void __init setup_node_to_cpumask_map(void)
26{
27 unsigned int node, num = 0;
Rusty Russell71ee73e2009-03-13 14:49:52 +103028
29 /* setup nr_node_ids if not done yet */
30 if (nr_node_ids == MAX_NUMNODES) {
31 for_each_node_mask(node, node_possible_map)
32 num = node;
33 nr_node_ids = num + 1;
34 }
35
36 /* allocate the map */
Rusty Russellc032ef602009-03-13 14:49:53 +103037 for (node = 0; node < nr_node_ids; node++)
38 alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]);
Rusty Russell71ee73e2009-03-13 14:49:52 +103039
Rusty Russellc032ef602009-03-13 14:49:53 +103040 /* cpumask_of_node() will now work */
41 pr_debug("Node to cpumask map for %d nodes\n", nr_node_ids);
Rusty Russell71ee73e2009-03-13 14:49:52 +103042}
43
44#ifdef CONFIG_DEBUG_PER_CPU_MAPS
45/*
46 * Returns a pointer to the bitmask of CPUs on Node 'node'.
47 */
Rusty Russell73e907d2009-03-13 14:49:57 +103048const struct cpumask *cpumask_of_node(int node)
Rusty Russell71ee73e2009-03-13 14:49:52 +103049{
Rusty Russell71ee73e2009-03-13 14:49:52 +103050 if (node >= nr_node_ids) {
51 printk(KERN_WARNING
52 "cpumask_of_node(%d): node > nr_node_ids(%d)\n",
53 node, nr_node_ids);
54 dump_stack();
55 return cpu_none_mask;
56 }
Rusty Russellc032ef602009-03-13 14:49:53 +103057 if (node_to_cpumask_map[node] == NULL) {
58 printk(KERN_WARNING
59 "cpumask_of_node(%d): no node_to_cpumask_map!\n",
60 node);
61 dump_stack();
62 return cpu_online_mask;
63 }
Rusty Russell0b966252009-03-13 23:42:42 +103064 return node_to_cpumask_map[node];
Rusty Russell71ee73e2009-03-13 14:49:52 +103065}
66EXPORT_SYMBOL(cpumask_of_node);
67#endif