Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86: Convert cpu_core_map to be a per cpu variable

This is from an earlier message from 'Christoph Lameter':

cpu_core_map is currently an array defined using NR_CPUS. This means that
we overallocate since we will rarely really use maximum configured cpu.

If we put the cpu_core_map into the per cpu area then it will be allocated
for each processor as it comes online.

This means that the core map cannot be accessed until the per cpu area
has been allocated. Xen does a weird thing here looping over all processors
and zeroing the masks that are not yet allocated and that will be zeroed
when they are allocated. I commented the code out.

Signed-off-by: Christoph Lameter <clameter@sgi.com>
Signed-off-by: Mike Travis <travis@sgi.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Christoph Lameter <clameter@sgi.com>
Cc: "Siddha, Suresh B" <suresh.b.siddha@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Mike Travis and committed by
Linus Torvalds
08357611 cc84634f

+63 -46
+1 -1
arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
··· 595 595 dmi_check_system(sw_any_bug_dmi_table); 596 596 if (bios_with_sw_any_bug && cpus_weight(policy->cpus) == 1) { 597 597 policy->shared_type = CPUFREQ_SHARED_TYPE_ALL; 598 - policy->cpus = cpu_core_map[cpu]; 598 + policy->cpus = per_cpu(cpu_core_map, cpu); 599 599 } 600 600 #endif 601 601
+5 -5
arch/x86/kernel/cpu/cpufreq/powernow-k8.c
··· 57 57 static int cpu_family = CPU_OPTERON; 58 58 59 59 #ifndef CONFIG_SMP 60 - static cpumask_t cpu_core_map[1]; 60 + DEFINE_PER_CPU(cpumask_t, cpu_core_map); 61 61 #endif 62 62 63 63 /* Return a frequency in MHz, given an input fid */ ··· 667 667 668 668 dprintk("cfid 0x%x, cvid 0x%x\n", data->currfid, data->currvid); 669 669 data->powernow_table = powernow_table; 670 - if (first_cpu(cpu_core_map[data->cpu]) == data->cpu) 670 + if (first_cpu(per_cpu(cpu_core_map, data->cpu)) == data->cpu) 671 671 print_basics(data); 672 672 673 673 for (j = 0; j < data->numps; j++) ··· 821 821 822 822 /* fill in data */ 823 823 data->numps = data->acpi_data.state_count; 824 - if (first_cpu(cpu_core_map[data->cpu]) == data->cpu) 824 + if (first_cpu(per_cpu(cpu_core_map, data->cpu)) == data->cpu) 825 825 print_basics(data); 826 826 powernow_k8_acpi_pst_values(data, 0); 827 827 ··· 1214 1214 if (cpu_family == CPU_HW_PSTATE) 1215 1215 pol->cpus = cpumask_of_cpu(pol->cpu); 1216 1216 else 1217 - pol->cpus = cpu_core_map[pol->cpu]; 1217 + pol->cpus = per_cpu(cpu_core_map, pol->cpu); 1218 1218 data->available_cores = &(pol->cpus); 1219 1219 1220 1220 /* Take a crude guess here. ··· 1281 1281 cpumask_t oldmask = current->cpus_allowed; 1282 1282 unsigned int khz = 0; 1283 1283 1284 - data = powernow_data[first_cpu(cpu_core_map[cpu])]; 1284 + data = powernow_data[first_cpu(per_cpu(cpu_core_map, cpu))]; 1285 1285 1286 1286 if (!data) 1287 1287 return -EINVAL;
+2 -1
arch/x86/kernel/cpu/proc.c
··· 122 122 #ifdef CONFIG_X86_HT 123 123 if (c->x86_max_cores * smp_num_siblings > 1) { 124 124 seq_printf(m, "physical id\t: %d\n", c->phys_proc_id); 125 - seq_printf(m, "siblings\t: %d\n", cpus_weight(cpu_core_map[n])); 125 + seq_printf(m, "siblings\t: %d\n", 126 + cpus_weight(per_cpu(cpu_core_map, n))); 126 127 seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id); 127 128 seq_printf(m, "cpu cores\t: %d\n", c->booted_cores); 128 129 }
+3 -3
arch/x86/kernel/mce_amd_64.c
··· 472 472 473 473 #ifdef CONFIG_SMP 474 474 if (cpu_data[cpu].cpu_core_id && shared_bank[bank]) { /* symlink */ 475 - i = first_cpu(cpu_core_map[cpu]); 475 + i = first_cpu(per_cpu(cpu_core_map, cpu)); 476 476 477 477 /* first core not up yet */ 478 478 if (cpu_data[i].cpu_core_id) ··· 492 492 if (err) 493 493 goto out; 494 494 495 - b->cpus = cpu_core_map[cpu]; 495 + b->cpus = per_cpu(cpu_core_map, cpu); 496 496 per_cpu(threshold_banks, cpu)[bank] = b; 497 497 goto out; 498 498 } ··· 509 509 #ifndef CONFIG_SMP 510 510 b->cpus = CPU_MASK_ALL; 511 511 #else 512 - b->cpus = cpu_core_map[cpu]; 512 + b->cpus = per_cpu(cpu_core_map, cpu); 513 513 #endif 514 514 err = kobject_register(&b->kobj); 515 515 if (err)
+2 -1
arch/x86/kernel/setup_64.c
··· 1070 1070 if (smp_num_siblings * c->x86_max_cores > 1) { 1071 1071 int cpu = c - cpu_data; 1072 1072 seq_printf(m, "physical id\t: %d\n", c->phys_proc_id); 1073 - seq_printf(m, "siblings\t: %d\n", cpus_weight(cpu_core_map[cpu])); 1073 + seq_printf(m, "siblings\t: %d\n", 1074 + cpus_weight(per_cpu(cpu_core_map, cpu))); 1074 1075 seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id); 1075 1076 seq_printf(m, "cpu cores\t: %d\n", c->booted_cores); 1076 1077 }
+17 -17
arch/x86/kernel/smpboot_32.c
··· 74 74 EXPORT_SYMBOL(cpu_sibling_map); 75 75 76 76 /* representing HT and core siblings of each logical CPU */ 77 - cpumask_t cpu_core_map[NR_CPUS] __read_mostly; 78 - EXPORT_SYMBOL(cpu_core_map); 77 + DEFINE_PER_CPU(cpumask_t, cpu_core_map); 78 + EXPORT_PER_CPU_SYMBOL(cpu_core_map); 79 79 80 80 /* bitmap of online cpus */ 81 81 cpumask_t cpu_online_map __read_mostly; ··· 300 300 * And for power savings, we return cpu_core_map 301 301 */ 302 302 if (sched_mc_power_savings || sched_smt_power_savings) 303 - return cpu_core_map[cpu]; 303 + return per_cpu(cpu_core_map, cpu); 304 304 else 305 305 return c->llc_shared_map; 306 306 } ··· 321 321 c[cpu].cpu_core_id == c[i].cpu_core_id) { 322 322 cpu_set(i, cpu_sibling_map[cpu]); 323 323 cpu_set(cpu, cpu_sibling_map[i]); 324 - cpu_set(i, cpu_core_map[cpu]); 325 - cpu_set(cpu, cpu_core_map[i]); 324 + cpu_set(i, per_cpu(cpu_core_map, cpu)); 325 + cpu_set(cpu, per_cpu(cpu_core_map, i)); 326 326 cpu_set(i, c[cpu].llc_shared_map); 327 327 cpu_set(cpu, c[i].llc_shared_map); 328 328 } ··· 334 334 cpu_set(cpu, c[cpu].llc_shared_map); 335 335 336 336 if (current_cpu_data.x86_max_cores == 1) { 337 - cpu_core_map[cpu] = cpu_sibling_map[cpu]; 337 + per_cpu(cpu_core_map, cpu) = cpu_sibling_map[cpu]; 338 338 c[cpu].booted_cores = 1; 339 339 return; 340 340 } ··· 346 346 cpu_set(cpu, c[i].llc_shared_map); 347 347 } 348 348 if (c[cpu].phys_proc_id == c[i].phys_proc_id) { 349 - cpu_set(i, cpu_core_map[cpu]); 350 - cpu_set(cpu, cpu_core_map[i]); 349 + cpu_set(i, per_cpu(cpu_core_map, cpu)); 350 + cpu_set(cpu, per_cpu(cpu_core_map, i)); 351 351 /* 352 352 * Does this new cpu bringup a new core? 353 353 */ ··· 984 984 " Using dummy APIC emulation.\n"); 985 985 map_cpu_to_logical_apicid(); 986 986 cpu_set(0, cpu_sibling_map[0]); 987 - cpu_set(0, cpu_core_map[0]); 987 + cpu_set(0, per_cpu(cpu_core_map, 0)); 988 988 return; 989 989 } 990 990 ··· 1009 1009 smpboot_clear_io_apic_irqs(); 1010 1010 phys_cpu_present_map = physid_mask_of_physid(0); 1011 1011 cpu_set(0, cpu_sibling_map[0]); 1012 - cpu_set(0, cpu_core_map[0]); 1012 + cpu_set(0, per_cpu(cpu_core_map, 0)); 1013 1013 return; 1014 1014 } 1015 1015 ··· 1024 1024 smpboot_clear_io_apic_irqs(); 1025 1025 phys_cpu_present_map = physid_mask_of_physid(0); 1026 1026 cpu_set(0, cpu_sibling_map[0]); 1027 - cpu_set(0, cpu_core_map[0]); 1027 + cpu_set(0, per_cpu(cpu_core_map, 0)); 1028 1028 return; 1029 1029 } 1030 1030 ··· 1107 1107 */ 1108 1108 for (cpu = 0; cpu < NR_CPUS; cpu++) { 1109 1109 cpus_clear(cpu_sibling_map[cpu]); 1110 - cpus_clear(cpu_core_map[cpu]); 1110 + cpus_clear(per_cpu(cpu_core_map, cpu)); 1111 1111 } 1112 1112 1113 1113 cpu_set(0, cpu_sibling_map[0]); 1114 - cpu_set(0, cpu_core_map[0]); 1114 + cpu_set(0, per_cpu(cpu_core_map, 0)); 1115 1115 1116 1116 smpboot_setup_io_apic(); 1117 1117 ··· 1148 1148 int sibling; 1149 1149 struct cpuinfo_x86 *c = cpu_data; 1150 1150 1151 - for_each_cpu_mask(sibling, cpu_core_map[cpu]) { 1152 - cpu_clear(cpu, cpu_core_map[sibling]); 1153 - /* 1151 + for_each_cpu_mask(sibling, per_cpu(cpu_core_map, cpu)) { 1152 + cpu_clear(cpu, per_cpu(cpu_core_map, sibling)); 1153 + /*/ 1154 1154 * last thread sibling in this cpu core going down 1155 1155 */ 1156 1156 if (cpus_weight(cpu_sibling_map[cpu]) == 1) ··· 1160 1160 for_each_cpu_mask(sibling, cpu_sibling_map[cpu]) 1161 1161 cpu_clear(cpu, cpu_sibling_map[sibling]); 1162 1162 cpus_clear(cpu_sibling_map[cpu]); 1163 - cpus_clear(cpu_core_map[cpu]); 1163 + cpus_clear(per_cpu(cpu_core_map, cpu)); 1164 1164 c[cpu].phys_proc_id = 0; 1165 1165 c[cpu].cpu_core_id = 0; 1166 1166 cpu_clear(cpu, cpu_sibling_setup_map);
+12 -12
arch/x86/kernel/smpboot_64.c
··· 95 95 EXPORT_SYMBOL(cpu_sibling_map); 96 96 97 97 /* representing HT and core siblings of each logical CPU */ 98 - cpumask_t cpu_core_map[NR_CPUS] __read_mostly; 99 - EXPORT_SYMBOL(cpu_core_map); 98 + DEFINE_PER_CPU(cpumask_t, cpu_core_map); 99 + EXPORT_PER_CPU_SYMBOL(cpu_core_map); 100 100 101 101 /* 102 102 * Trampoline 80x86 program as an array. ··· 243 243 * And for power savings, we return cpu_core_map 244 244 */ 245 245 if (sched_mc_power_savings || sched_smt_power_savings) 246 - return cpu_core_map[cpu]; 246 + return per_cpu(cpu_core_map, cpu); 247 247 else 248 248 return c->llc_shared_map; 249 249 } ··· 264 264 c[cpu].cpu_core_id == c[i].cpu_core_id) { 265 265 cpu_set(i, cpu_sibling_map[cpu]); 266 266 cpu_set(cpu, cpu_sibling_map[i]); 267 - cpu_set(i, cpu_core_map[cpu]); 268 - cpu_set(cpu, cpu_core_map[i]); 267 + cpu_set(i, per_cpu(cpu_core_map, cpu)); 268 + cpu_set(cpu, per_cpu(cpu_core_map, i)); 269 269 cpu_set(i, c[cpu].llc_shared_map); 270 270 cpu_set(cpu, c[i].llc_shared_map); 271 271 } ··· 277 277 cpu_set(cpu, c[cpu].llc_shared_map); 278 278 279 279 if (current_cpu_data.x86_max_cores == 1) { 280 - cpu_core_map[cpu] = cpu_sibling_map[cpu]; 280 + per_cpu(cpu_core_map, cpu) = cpu_sibling_map[cpu]; 281 281 c[cpu].booted_cores = 1; 282 282 return; 283 283 } ··· 289 289 cpu_set(cpu, c[i].llc_shared_map); 290 290 } 291 291 if (c[cpu].phys_proc_id == c[i].phys_proc_id) { 292 - cpu_set(i, cpu_core_map[cpu]); 293 - cpu_set(cpu, cpu_core_map[i]); 292 + cpu_set(i, per_cpu(cpu_core_map, cpu)); 293 + cpu_set(cpu, per_cpu(cpu_core_map, i)); 294 294 /* 295 295 * Does this new cpu bringup a new core? 296 296 */ ··· 736 736 else 737 737 phys_cpu_present_map = physid_mask_of_physid(0); 738 738 cpu_set(0, cpu_sibling_map[0]); 739 - cpu_set(0, cpu_core_map[0]); 739 + cpu_set(0, per_cpu(cpu_core_map, 0)); 740 740 } 741 741 742 742 #ifdef CONFIG_HOTPLUG_CPU ··· 971 971 int sibling; 972 972 struct cpuinfo_x86 *c = cpu_data; 973 973 974 - for_each_cpu_mask(sibling, cpu_core_map[cpu]) { 975 - cpu_clear(cpu, cpu_core_map[sibling]); 974 + for_each_cpu_mask(sibling, per_cpu(cpu_core_map, cpu)) { 975 + cpu_clear(cpu, per_cpu(cpu_core_map, sibling)); 976 976 /* 977 977 * last thread sibling in this cpu core going down 978 978 */ ··· 983 983 for_each_cpu_mask(sibling, cpu_sibling_map[cpu]) 984 984 cpu_clear(cpu, cpu_sibling_map[sibling]); 985 985 cpus_clear(cpu_sibling_map[cpu]); 986 - cpus_clear(cpu_core_map[cpu]); 986 + cpus_clear(per_cpu(cpu_core_map, cpu)); 987 987 c[cpu].phys_proc_id = 0; 988 988 c[cpu].cpu_core_id = 0; 989 989 cpu_clear(cpu, cpu_sibling_setup_map);
+12 -2
arch/x86/xen/smp.c
··· 148 148 149 149 for (cpu = 0; cpu < NR_CPUS; cpu++) { 150 150 cpus_clear(cpu_sibling_map[cpu]); 151 - cpus_clear(cpu_core_map[cpu]); 151 + /* 152 + * cpu_core_map lives in a per cpu area that is cleared 153 + * when the per cpu array is allocated. 154 + * 155 + * cpus_clear(per_cpu(cpu_core_map, cpu)); 156 + */ 152 157 } 153 158 154 159 xen_setup_vcpu_info_placement(); ··· 165 160 166 161 for (cpu = 0; cpu < NR_CPUS; cpu++) { 167 162 cpus_clear(cpu_sibling_map[cpu]); 168 - cpus_clear(cpu_core_map[cpu]); 163 + /* 164 + * cpu_core_ map will be zeroed when the per 165 + * cpu area is allocated. 166 + * 167 + * cpus_clear(per_cpu(cpu_core_map, cpu)); 168 + */ 169 169 } 170 170 171 171 smp_store_cpu_info(0);
+1 -1
include/asm-x86/smp_32.h
··· 31 31 extern int pic_mode; 32 32 extern int smp_num_siblings; 33 33 extern cpumask_t cpu_sibling_map[]; 34 - extern cpumask_t cpu_core_map[]; 34 + DECLARE_PER_CPU(cpumask_t, cpu_core_map); 35 35 36 36 extern void (*mtrr_hook) (void); 37 37 extern void zap_low_mappings (void);
+6 -1
include/asm-x86/smp_64.h
··· 39 39 extern void smp_send_reschedule(int cpu); 40 40 41 41 extern cpumask_t cpu_sibling_map[NR_CPUS]; 42 - extern cpumask_t cpu_core_map[NR_CPUS]; 42 + /* 43 + * cpu_core_map lives in a per cpu area 44 + * 45 + * extern cpumask_t cpu_core_map[NR_CPUS]; 46 + */ 47 + DECLARE_PER_CPU(cpumask_t, cpu_core_map); 43 48 extern u8 cpu_llc_id[NR_CPUS]; 44 49 45 50 #define SMP_TRAMPOLINE_BASE 0x6000
+1 -1
include/asm-x86/topology_32.h
··· 30 30 #ifdef CONFIG_X86_HT 31 31 #define topology_physical_package_id(cpu) (cpu_data[cpu].phys_proc_id) 32 32 #define topology_core_id(cpu) (cpu_data[cpu].cpu_core_id) 33 - #define topology_core_siblings(cpu) (cpu_core_map[cpu]) 33 + #define topology_core_siblings(cpu) (per_cpu(cpu_core_map, cpu)) 34 34 #define topology_thread_siblings(cpu) (cpu_sibling_map[cpu]) 35 35 #endif 36 36
+1 -1
include/asm-x86/topology_64.h
··· 58 58 #ifdef CONFIG_SMP 59 59 #define topology_physical_package_id(cpu) (cpu_data[cpu].phys_proc_id) 60 60 #define topology_core_id(cpu) (cpu_data[cpu].cpu_core_id) 61 - #define topology_core_siblings(cpu) (cpu_core_map[cpu]) 61 + #define topology_core_siblings(cpu) (per_cpu(cpu_core_map, cpu)) 62 62 #define topology_thread_siblings(cpu) (cpu_sibling_map[cpu]) 63 63 #define mc_capable() (boot_cpu_data.x86_max_cores > 1) 64 64 #define smt_capable() (smp_num_siblings > 1)