Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 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 | #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 Russell | c032ef60 | 2009-03-13 14:49:53 +1030 | [diff] [blame] | 15 | cpumask_var_t node_to_cpumask_map[MAX_NUMNODES]; |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 16 | EXPORT_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 | */ |
| 25 | void __init setup_node_to_cpumask_map(void) |
| 26 | { |
| 27 | unsigned int node, num = 0; |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 28 | |
| 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 Russell | c032ef60 | 2009-03-13 14:49:53 +1030 | [diff] [blame] | 37 | for (node = 0; node < nr_node_ids; node++) |
| 38 | alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]); |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 39 | |
Rusty Russell | c032ef60 | 2009-03-13 14:49:53 +1030 | [diff] [blame] | 40 | /* cpumask_of_node() will now work */ |
| 41 | pr_debug("Node to cpumask map for %d nodes\n", nr_node_ids); |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | #ifdef CONFIG_DEBUG_PER_CPU_MAPS |
| 45 | /* |
| 46 | * Returns a pointer to the bitmask of CPUs on Node 'node'. |
| 47 | */ |
Rusty Russell | 73e907d | 2009-03-13 14:49:57 +1030 | [diff] [blame] | 48 | const struct cpumask *cpumask_of_node(int node) |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 49 | { |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 50 | 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 Russell | c032ef60 | 2009-03-13 14:49:53 +1030 | [diff] [blame] | 57 | 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 Russell | 0b96625 | 2009-03-13 23:42:42 +1030 | [diff] [blame] | 64 | return node_to_cpumask_map[node]; |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 65 | } |
| 66 | EXPORT_SYMBOL(cpumask_of_node); |
| 67 | #endif |