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> |
Jan Beulich | 9032160 | 2011-01-19 08:57:21 +0000 | [diff] [blame^] | 5 | #include <asm/numa.h> |
| 6 | #include <asm/acpi.h> |
| 7 | |
| 8 | int __initdata numa_off; |
| 9 | |
| 10 | static __init int numa_setup(char *opt) |
| 11 | { |
| 12 | if (!opt) |
| 13 | return -EINVAL; |
| 14 | if (!strncmp(opt, "off", 3)) |
| 15 | numa_off = 1; |
| 16 | #ifdef CONFIG_NUMA_EMU |
| 17 | if (!strncmp(opt, "fake=", 5)) |
| 18 | numa_emu_cmdline(opt + 5); |
| 19 | #endif |
| 20 | #ifdef CONFIG_ACPI_NUMA |
| 21 | if (!strncmp(opt, "noacpi", 6)) |
| 22 | acpi_numa = -1; |
| 23 | #endif |
| 24 | return 0; |
| 25 | } |
| 26 | early_param("numa", numa_setup); |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 27 | |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 28 | /* |
| 29 | * Which logical CPUs are on which nodes |
| 30 | */ |
Rusty Russell | c032ef60 | 2009-03-13 14:49:53 +1030 | [diff] [blame] | 31 | cpumask_var_t node_to_cpumask_map[MAX_NUMNODES]; |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 32 | EXPORT_SYMBOL(node_to_cpumask_map); |
| 33 | |
| 34 | /* |
| 35 | * Allocate node_to_cpumask_map based on number of available nodes |
| 36 | * Requires node_possible_map to be valid. |
| 37 | * |
| 38 | * Note: node_to_cpumask() is not valid until after this is done. |
| 39 | * (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.) |
| 40 | */ |
| 41 | void __init setup_node_to_cpumask_map(void) |
| 42 | { |
| 43 | unsigned int node, num = 0; |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 44 | |
| 45 | /* setup nr_node_ids if not done yet */ |
| 46 | if (nr_node_ids == MAX_NUMNODES) { |
| 47 | for_each_node_mask(node, node_possible_map) |
| 48 | num = node; |
| 49 | nr_node_ids = num + 1; |
| 50 | } |
| 51 | |
| 52 | /* allocate the map */ |
Rusty Russell | c032ef60 | 2009-03-13 14:49:53 +1030 | [diff] [blame] | 53 | for (node = 0; node < nr_node_ids; node++) |
| 54 | alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]); |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 55 | |
Rusty Russell | c032ef60 | 2009-03-13 14:49:53 +1030 | [diff] [blame] | 56 | /* cpumask_of_node() will now work */ |
| 57 | 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] | 58 | } |
| 59 | |
| 60 | #ifdef CONFIG_DEBUG_PER_CPU_MAPS |
| 61 | /* |
| 62 | * Returns a pointer to the bitmask of CPUs on Node 'node'. |
| 63 | */ |
Rusty Russell | 73e907d | 2009-03-13 14:49:57 +1030 | [diff] [blame] | 64 | const struct cpumask *cpumask_of_node(int node) |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 65 | { |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 66 | if (node >= nr_node_ids) { |
| 67 | printk(KERN_WARNING |
| 68 | "cpumask_of_node(%d): node > nr_node_ids(%d)\n", |
| 69 | node, nr_node_ids); |
| 70 | dump_stack(); |
| 71 | return cpu_none_mask; |
| 72 | } |
Rusty Russell | c032ef60 | 2009-03-13 14:49:53 +1030 | [diff] [blame] | 73 | if (node_to_cpumask_map[node] == NULL) { |
| 74 | printk(KERN_WARNING |
| 75 | "cpumask_of_node(%d): no node_to_cpumask_map!\n", |
| 76 | node); |
| 77 | dump_stack(); |
| 78 | return cpu_online_mask; |
| 79 | } |
Rusty Russell | 0b96625 | 2009-03-13 23:42:42 +1030 | [diff] [blame] | 80 | return node_to_cpumask_map[node]; |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 81 | } |
| 82 | EXPORT_SYMBOL(cpumask_of_node); |
| 83 | #endif |