Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 1 | #include <linux/kernel.h> |
| 2 | #include <linux/module.h> |
| 3 | #include <linux/init.h> |
| 4 | #include <linux/bootmem.h> |
| 5 | #include <linux/percpu.h> |
| 6 | #include <asm/smp.h> |
| 7 | #include <asm/percpu.h> |
| 8 | #include <asm/sections.h> |
| 9 | #include <asm/processor.h> |
| 10 | #include <asm/setup.h> |
| 11 | #include <asm/topology.h> |
Alexey Starikovskiy | 0fc0906 | 2008-04-04 23:40:48 +0400 | [diff] [blame] | 12 | #include <asm/mpspec.h> |
Alexey Starikovskiy | 76eb413 | 2008-04-04 23:40:41 +0400 | [diff] [blame] | 13 | #include <asm/apicdef.h> |
| 14 | |
James Bottomley | f8955eb | 2008-05-10 09:01:48 -0500 | [diff] [blame] | 15 | #ifdef CONFIG_X86_LOCAL_APIC |
Alexey Starikovskiy | 2fe6014 | 2008-04-04 23:41:44 +0400 | [diff] [blame] | 16 | unsigned int num_processors; |
| 17 | unsigned disabled_cpus __cpuinitdata; |
| 18 | /* Processor that is doing the boot up */ |
| 19 | unsigned int boot_cpu_physical_apicid = -1U; |
Yinghai Lu | e0da336 | 2008-06-08 18:29:22 -0700 | [diff] [blame] | 20 | unsigned int max_physical_apicid; |
Alexey Starikovskiy | 2fe6014 | 2008-04-04 23:41:44 +0400 | [diff] [blame] | 21 | EXPORT_SYMBOL(boot_cpu_physical_apicid); |
| 22 | |
Alexey Starikovskiy | 0fc0906 | 2008-04-04 23:40:48 +0400 | [diff] [blame] | 23 | /* Bitmask of physically existing CPUs */ |
| 24 | physid_mask_t phys_cpu_present_map; |
James Bottomley | f8955eb | 2008-05-10 09:01:48 -0500 | [diff] [blame] | 25 | #endif |
Alexey Starikovskiy | 0fc0906 | 2008-04-04 23:40:48 +0400 | [diff] [blame] | 26 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 27 | /* map cpu index to physical APIC ID */ |
| 28 | DEFINE_EARLY_PER_CPU(u16, x86_cpu_to_apicid, BAD_APICID); |
| 29 | DEFINE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid, BAD_APICID); |
| 30 | EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_apicid); |
| 31 | EXPORT_EARLY_PER_CPU_SYMBOL(x86_bios_cpu_apicid); |
| 32 | |
| 33 | #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64) |
| 34 | #define X86_64_NUMA 1 |
| 35 | |
Mike Travis | 7891a24 | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 36 | /* map cpu index to node index */ |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 37 | DEFINE_EARLY_PER_CPU(int, x86_cpu_to_node_map, NUMA_NO_NODE); |
| 38 | EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_node_map); |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 39 | |
| 40 | /* which logical CPUs are on which nodes */ |
| 41 | cpumask_t *node_to_cpumask_map; |
| 42 | EXPORT_SYMBOL(node_to_cpumask_map); |
| 43 | |
| 44 | /* setup node_to_cpumask_map */ |
| 45 | static void __init setup_node_to_cpumask_map(void); |
| 46 | |
| 47 | #else |
| 48 | static inline void setup_node_to_cpumask_map(void) { } |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 49 | #endif |
| 50 | |
James Bottomley | f8955eb | 2008-05-10 09:01:48 -0500 | [diff] [blame] | 51 | #if defined(CONFIG_HAVE_SETUP_PER_CPU_AREA) && defined(CONFIG_X86_SMP) |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 52 | /* |
| 53 | * Copy data used in early init routines from the initial arrays to the |
| 54 | * per cpu data areas. These arrays then become expendable and the |
| 55 | * *_early_ptr's are zeroed indicating that the static arrays are gone. |
| 56 | */ |
| 57 | static void __init setup_per_cpu_maps(void) |
| 58 | { |
| 59 | int cpu; |
| 60 | |
| 61 | for_each_possible_cpu(cpu) { |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 62 | per_cpu(x86_cpu_to_apicid, cpu) = |
| 63 | early_per_cpu_map(x86_cpu_to_apicid, cpu); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 64 | per_cpu(x86_bios_cpu_apicid, cpu) = |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 65 | early_per_cpu_map(x86_bios_cpu_apicid, cpu); |
| 66 | #ifdef X86_64_NUMA |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 67 | per_cpu(x86_cpu_to_node_map, cpu) = |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 68 | early_per_cpu_map(x86_cpu_to_node_map, cpu); |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 69 | #endif |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /* indicate the early static arrays will soon be gone */ |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 73 | early_per_cpu_ptr(x86_cpu_to_apicid) = NULL; |
| 74 | early_per_cpu_ptr(x86_bios_cpu_apicid) = NULL; |
| 75 | #ifdef X86_64_NUMA |
| 76 | early_per_cpu_ptr(x86_cpu_to_node_map) = NULL; |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 77 | #endif |
| 78 | } |
| 79 | |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 80 | #ifdef CONFIG_HAVE_CPUMASK_OF_CPU_MAP |
| 81 | cpumask_t *cpumask_of_cpu_map __read_mostly; |
| 82 | EXPORT_SYMBOL(cpumask_of_cpu_map); |
| 83 | |
| 84 | /* requires nr_cpu_ids to be initialized */ |
| 85 | static void __init setup_cpumask_of_cpu(void) |
| 86 | { |
| 87 | int i; |
| 88 | |
| 89 | /* alloc_bootmem zeroes memory */ |
| 90 | cpumask_of_cpu_map = alloc_bootmem_low(sizeof(cpumask_t) * nr_cpu_ids); |
| 91 | for (i = 0; i < nr_cpu_ids; i++) |
| 92 | cpu_set(i, cpumask_of_cpu_map[i]); |
| 93 | } |
| 94 | #else |
| 95 | static inline void setup_cpumask_of_cpu(void) { } |
| 96 | #endif |
| 97 | |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 98 | #ifdef CONFIG_X86_32 |
| 99 | /* |
| 100 | * Great future not-so-futuristic plan: make i386 and x86_64 do it |
| 101 | * the same way |
| 102 | */ |
| 103 | unsigned long __per_cpu_offset[NR_CPUS] __read_mostly; |
| 104 | EXPORT_SYMBOL(__per_cpu_offset); |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 105 | static inline void setup_cpu_pda_map(void) { } |
| 106 | |
| 107 | #elif !defined(CONFIG_SMP) |
| 108 | static inline void setup_cpu_pda_map(void) { } |
| 109 | |
| 110 | #else /* CONFIG_SMP && CONFIG_X86_64 */ |
| 111 | |
| 112 | /* |
| 113 | * Allocate cpu_pda pointer table and array via alloc_bootmem. |
| 114 | */ |
| 115 | static void __init setup_cpu_pda_map(void) |
| 116 | { |
| 117 | char *pda; |
| 118 | struct x8664_pda **new_cpu_pda; |
| 119 | unsigned long size; |
| 120 | int cpu; |
| 121 | |
| 122 | size = roundup(sizeof(struct x8664_pda), cache_line_size()); |
| 123 | |
| 124 | /* allocate cpu_pda array and pointer table */ |
| 125 | { |
| 126 | unsigned long tsize = nr_cpu_ids * sizeof(void *); |
| 127 | unsigned long asize = size * (nr_cpu_ids - 1); |
| 128 | |
| 129 | tsize = roundup(tsize, cache_line_size()); |
| 130 | new_cpu_pda = alloc_bootmem(tsize + asize); |
| 131 | pda = (char *)new_cpu_pda + tsize; |
| 132 | } |
| 133 | |
| 134 | /* initialize pointer table to static pda's */ |
| 135 | for_each_possible_cpu(cpu) { |
| 136 | if (cpu == 0) { |
| 137 | /* leave boot cpu pda in place */ |
| 138 | new_cpu_pda[0] = cpu_pda(0); |
| 139 | continue; |
| 140 | } |
| 141 | new_cpu_pda[cpu] = (struct x8664_pda *)pda; |
| 142 | new_cpu_pda[cpu]->in_bootmem = 1; |
| 143 | pda += size; |
| 144 | } |
| 145 | |
| 146 | /* point to new pointer table */ |
| 147 | _cpu_pda = new_cpu_pda; |
| 148 | } |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 149 | #endif |
| 150 | |
| 151 | /* |
| 152 | * Great future plan: |
| 153 | * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data. |
| 154 | * Always point %gs to its beginning |
| 155 | */ |
| 156 | void __init setup_per_cpu_areas(void) |
| 157 | { |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 158 | ssize_t size = PERCPU_ENOUGH_ROOM; |
| 159 | char *ptr; |
| 160 | int cpu; |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 161 | |
| 162 | #ifdef CONFIG_HOTPLUG_CPU |
| 163 | prefill_possible_map(); |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 164 | #else |
| 165 | nr_cpu_ids = num_processors; |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 166 | #endif |
| 167 | |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 168 | /* Setup cpu_pda map */ |
| 169 | setup_cpu_pda_map(); |
| 170 | |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 171 | /* Copy section for each CPU (we discard the original) */ |
| 172 | size = PERCPU_ENOUGH_ROOM; |
Randy Dunlap | 053713f | 2008-06-05 11:10:59 -0700 | [diff] [blame] | 173 | printk(KERN_INFO "PERCPU: Allocating %zd bytes of per cpu data\n", |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 174 | size); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 175 | |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 176 | for_each_possible_cpu(cpu) { |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 177 | #ifndef CONFIG_NEED_MULTIPLE_NODES |
| 178 | ptr = alloc_bootmem_pages(size); |
| 179 | #else |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 180 | int node = early_cpu_to_node(cpu); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 181 | if (!node_online(node) || !NODE_DATA(node)) { |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 182 | ptr = alloc_bootmem_pages(size); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 183 | printk(KERN_INFO |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 184 | "cpu %d has no node %d or node-local memory\n", |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 185 | cpu, node); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 186 | } |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 187 | else |
| 188 | ptr = alloc_bootmem_pages_node(NODE_DATA(node), size); |
| 189 | #endif |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 190 | per_cpu_offset(cpu) = ptr - __per_cpu_start; |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 191 | memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start); |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 192 | |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 193 | } |
| 194 | |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 195 | printk(KERN_DEBUG "NR_CPUS: %d, nr_cpu_ids: %d, nr_node_ids %d\n", |
| 196 | NR_CPUS, nr_cpu_ids, nr_node_ids); |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 197 | |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 198 | /* Setup percpu data maps */ |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 199 | setup_per_cpu_maps(); |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 200 | |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 201 | /* Setup node to cpumask map */ |
| 202 | setup_node_to_cpumask_map(); |
| 203 | |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 204 | /* Setup cpumask_of_cpu map */ |
| 205 | setup_cpumask_of_cpu(); |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | #endif |
Huang, Ying | c45a707 | 2008-06-02 14:26:25 +0800 | [diff] [blame] | 209 | |
| 210 | void __init parse_setup_data(void) |
| 211 | { |
| 212 | struct setup_data *data; |
| 213 | u64 pa_data; |
| 214 | |
| 215 | if (boot_params.hdr.version < 0x0209) |
| 216 | return; |
| 217 | pa_data = boot_params.hdr.setup_data; |
| 218 | while (pa_data) { |
| 219 | data = early_ioremap(pa_data, PAGE_SIZE); |
| 220 | switch (data->type) { |
Huang, Ying | 8c5beb5 | 2008-06-11 11:33:39 +0800 | [diff] [blame] | 221 | case SETUP_E820_EXT: |
| 222 | parse_e820_ext(data, pa_data); |
| 223 | break; |
Huang, Ying | c45a707 | 2008-06-02 14:26:25 +0800 | [diff] [blame] | 224 | default: |
| 225 | break; |
| 226 | } |
| 227 | #ifndef CONFIG_DEBUG_BOOT_PARAMS |
| 228 | free_early(pa_data, pa_data+sizeof(*data)+data->len); |
| 229 | #endif |
| 230 | pa_data = data->next; |
| 231 | early_iounmap(data, PAGE_SIZE); |
| 232 | } |
| 233 | } |
Ingo Molnar | 2b4fa85 | 2008-07-08 11:59:23 +0200 | [diff] [blame^] | 234 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 235 | #ifdef X86_64_NUMA |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 236 | |
| 237 | /* |
| 238 | * Allocate node_to_cpumask_map based on number of available nodes |
| 239 | * Requires node_possible_map to be valid. |
| 240 | * |
| 241 | * Note: node_to_cpumask() is not valid until after this is done. |
| 242 | */ |
| 243 | static void __init setup_node_to_cpumask_map(void) |
| 244 | { |
| 245 | unsigned int node, num = 0; |
| 246 | cpumask_t *map; |
| 247 | |
| 248 | /* setup nr_node_ids if not done yet */ |
| 249 | if (nr_node_ids == MAX_NUMNODES) { |
| 250 | for_each_node_mask(node, node_possible_map) |
| 251 | num = node; |
| 252 | nr_node_ids = num + 1; |
| 253 | } |
| 254 | |
| 255 | /* allocate the map */ |
| 256 | map = alloc_bootmem_low(nr_node_ids * sizeof(cpumask_t)); |
| 257 | |
| 258 | Dprintk(KERN_DEBUG "Node to cpumask map at %p for %d nodes\n", |
| 259 | map, nr_node_ids); |
| 260 | |
| 261 | /* node_to_cpumask() will now work */ |
| 262 | node_to_cpumask_map = map; |
| 263 | } |
| 264 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 265 | void __cpuinit numa_set_node(int cpu, int node) |
| 266 | { |
| 267 | int *cpu_to_node_map = early_per_cpu_ptr(x86_cpu_to_node_map); |
| 268 | |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 269 | if (cpu_pda(cpu) && node != NUMA_NO_NODE) |
Mike Travis | 7891a24 | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 270 | cpu_pda(cpu)->nodenumber = node; |
| 271 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 272 | if (cpu_to_node_map) |
| 273 | cpu_to_node_map[cpu] = node; |
| 274 | |
| 275 | else if (per_cpu_offset(cpu)) |
| 276 | per_cpu(x86_cpu_to_node_map, cpu) = node; |
| 277 | |
| 278 | else |
| 279 | Dprintk(KERN_INFO "Setting node for non-present cpu %d\n", cpu); |
| 280 | } |
| 281 | |
| 282 | void __cpuinit numa_clear_node(int cpu) |
| 283 | { |
| 284 | numa_set_node(cpu, NUMA_NO_NODE); |
| 285 | } |
| 286 | |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 287 | #ifndef CONFIG_DEBUG_PER_CPU_MAPS |
| 288 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 289 | void __cpuinit numa_add_cpu(int cpu) |
| 290 | { |
| 291 | cpu_set(cpu, node_to_cpumask_map[early_cpu_to_node(cpu)]); |
| 292 | } |
| 293 | |
| 294 | void __cpuinit numa_remove_cpu(int cpu) |
| 295 | { |
| 296 | cpu_clear(cpu, node_to_cpumask_map[cpu_to_node(cpu)]); |
| 297 | } |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 298 | |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 299 | #else /* CONFIG_DEBUG_PER_CPU_MAPS */ |
| 300 | |
| 301 | /* |
| 302 | * --------- debug versions of the numa functions --------- |
| 303 | */ |
| 304 | static void __cpuinit numa_set_cpumask(int cpu, int enable) |
| 305 | { |
| 306 | int node = cpu_to_node(cpu); |
| 307 | cpumask_t *mask; |
| 308 | char buf[64]; |
| 309 | |
| 310 | if (node_to_cpumask_map == NULL) { |
| 311 | printk(KERN_ERR "node_to_cpumask_map NULL\n"); |
| 312 | dump_stack(); |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | mask = &node_to_cpumask_map[node]; |
| 317 | if (enable) |
| 318 | cpu_set(cpu, *mask); |
| 319 | else |
| 320 | cpu_clear(cpu, *mask); |
| 321 | |
| 322 | cpulist_scnprintf(buf, sizeof(buf), *mask); |
| 323 | printk(KERN_DEBUG "%s cpu %d node %d: mask now %s\n", |
| 324 | enable? "numa_add_cpu":"numa_remove_cpu", cpu, node, buf); |
| 325 | } |
| 326 | |
| 327 | void __cpuinit numa_add_cpu(int cpu) |
| 328 | { |
| 329 | numa_set_cpumask(cpu, 1); |
| 330 | } |
| 331 | |
| 332 | void __cpuinit numa_remove_cpu(int cpu) |
| 333 | { |
| 334 | numa_set_cpumask(cpu, 0); |
| 335 | } |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 336 | |
| 337 | int cpu_to_node(int cpu) |
| 338 | { |
| 339 | if (early_per_cpu_ptr(x86_cpu_to_node_map)) { |
| 340 | printk(KERN_WARNING |
| 341 | "cpu_to_node(%d): usage too early!\n", cpu); |
| 342 | dump_stack(); |
| 343 | return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu]; |
| 344 | } |
| 345 | return per_cpu(x86_cpu_to_node_map, cpu); |
| 346 | } |
| 347 | EXPORT_SYMBOL(cpu_to_node); |
| 348 | |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 349 | /* |
| 350 | * Same function as cpu_to_node() but used if called before the |
| 351 | * per_cpu areas are setup. |
| 352 | */ |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 353 | int early_cpu_to_node(int cpu) |
| 354 | { |
| 355 | if (early_per_cpu_ptr(x86_cpu_to_node_map)) |
| 356 | return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu]; |
| 357 | |
| 358 | if (!per_cpu_offset(cpu)) { |
| 359 | printk(KERN_WARNING |
| 360 | "early_cpu_to_node(%d): no per_cpu area!\n", cpu); |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 361 | dump_stack(); |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 362 | return NUMA_NO_NODE; |
| 363 | } |
| 364 | return per_cpu(x86_cpu_to_node_map, cpu); |
| 365 | } |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 366 | |
| 367 | /* |
| 368 | * Returns a pointer to the bitmask of CPUs on Node 'node'. |
| 369 | */ |
| 370 | cpumask_t *_node_to_cpumask_ptr(int node) |
| 371 | { |
| 372 | if (node_to_cpumask_map == NULL) { |
| 373 | printk(KERN_WARNING |
| 374 | "_node_to_cpumask_ptr(%d): no node_to_cpumask_map!\n", |
| 375 | node); |
| 376 | dump_stack(); |
| 377 | return &cpu_online_map; |
| 378 | } |
Vegard Nossum | 03db1f7 | 2008-06-06 16:33:25 +0200 | [diff] [blame] | 379 | BUG_ON(node >= nr_node_ids); |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 380 | return &node_to_cpumask_map[node]; |
| 381 | } |
| 382 | EXPORT_SYMBOL(_node_to_cpumask_ptr); |
| 383 | |
| 384 | /* |
| 385 | * Returns a bitmask of CPUs on Node 'node'. |
| 386 | */ |
| 387 | cpumask_t node_to_cpumask(int node) |
| 388 | { |
| 389 | if (node_to_cpumask_map == NULL) { |
| 390 | printk(KERN_WARNING |
| 391 | "node_to_cpumask(%d): no node_to_cpumask_map!\n", node); |
| 392 | dump_stack(); |
| 393 | return cpu_online_map; |
| 394 | } |
Vegard Nossum | 03db1f7 | 2008-06-06 16:33:25 +0200 | [diff] [blame] | 395 | BUG_ON(node >= nr_node_ids); |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 396 | return node_to_cpumask_map[node]; |
| 397 | } |
| 398 | EXPORT_SYMBOL(node_to_cpumask); |
| 399 | |
| 400 | /* |
| 401 | * --------- end of debug versions of the numa functions --------- |
| 402 | */ |
| 403 | |
| 404 | #endif /* CONFIG_DEBUG_PER_CPU_MAPS */ |
| 405 | |
| 406 | #endif /* X86_64_NUMA */ |