smpboot.c (384d9fe3741657c8ed8cd9bf30bc1d4611864d56) smpboot.c (0100301bfdf56a2a370c7157b5ab0fbf9313e1cd)
1 /*
2 * x86 SMP booting functions
3 *
4 * (c) 1995 Alan Cox, Building #3 <alan@lxorguk.ukuu.org.uk>
5 * (c) 1998, 1999, 2000, 2009 Ingo Molnar <mingo@redhat.com>
6 * Copyright 2001 Andi Kleen, SuSE Labs.
7 *
8 * Much of the core SMP work is based on previous work by Thomas Radke, to

--- 86 unchanged lines hidden (view full) ---

95
96/* Per CPU bogomips and other parameters */
97DEFINE_PER_CPU_READ_MOSTLY(struct cpuinfo_x86, cpu_info);
98EXPORT_PER_CPU_SYMBOL(cpu_info);
99
100/* Logical package management. We might want to allocate that dynamically */
101static int *physical_to_logical_pkg __read_mostly;
102static unsigned long *physical_package_map __read_mostly;;
1 /*
2 * x86 SMP booting functions
3 *
4 * (c) 1995 Alan Cox, Building #3 <alan@lxorguk.ukuu.org.uk>
5 * (c) 1998, 1999, 2000, 2009 Ingo Molnar <mingo@redhat.com>
6 * Copyright 2001 Andi Kleen, SuSE Labs.
7 *
8 * Much of the core SMP work is based on previous work by Thomas Radke, to

--- 86 unchanged lines hidden (view full) ---

95
96/* Per CPU bogomips and other parameters */
97DEFINE_PER_CPU_READ_MOSTLY(struct cpuinfo_x86, cpu_info);
98EXPORT_PER_CPU_SYMBOL(cpu_info);
99
100/* Logical package management. We might want to allocate that dynamically */
101static int *physical_to_logical_pkg __read_mostly;
102static unsigned long *physical_package_map __read_mostly;;
103static unsigned long *logical_package_map __read_mostly;
104static unsigned int max_physical_pkg_id __read_mostly;
105unsigned int __max_logical_packages __read_mostly;
106EXPORT_SYMBOL(__max_logical_packages);
103static unsigned int max_physical_pkg_id __read_mostly;
104unsigned int __max_logical_packages __read_mostly;
105EXPORT_SYMBOL(__max_logical_packages);
106static unsigned int logical_packages __read_mostly;
107static bool logical_packages_frozen __read_mostly;
107
108/* Maximum number of SMT threads on any online core */
109int __max_smt_threads __read_mostly;
110
111static inline void smpboot_setup_warm_reset_vector(unsigned long start_eip)
112{
113 unsigned long flags;
114

--- 157 unchanged lines hidden (view full) ---

272
273 if (pkg >= max_physical_pkg_id)
274 return -EINVAL;
275
276 /* Set the logical package id */
277 if (test_and_set_bit(pkg, physical_package_map))
278 goto found;
279
108
109/* Maximum number of SMT threads on any online core */
110int __max_smt_threads __read_mostly;
111
112static inline void smpboot_setup_warm_reset_vector(unsigned long start_eip)
113{
114 unsigned long flags;
115

--- 157 unchanged lines hidden (view full) ---

273
274 if (pkg >= max_physical_pkg_id)
275 return -EINVAL;
276
277 /* Set the logical package id */
278 if (test_and_set_bit(pkg, physical_package_map))
279 goto found;
280
280 new = find_first_zero_bit(logical_package_map, __max_logical_packages);
281 if (new >= __max_logical_packages) {
281 if (logical_packages_frozen) {
282 physical_to_logical_pkg[pkg] = -1;
282 physical_to_logical_pkg[pkg] = -1;
283 pr_warn("APIC(%x) Package %u exceeds logical package map\n",
283 pr_warn("APIC(%x) Package %u exceeds logical package max\n",
284 apicid, pkg);
285 return -ENOSPC;
286 }
284 apicid, pkg);
285 return -ENOSPC;
286 }
287 set_bit(new, logical_package_map);
287
288 new = logical_packages++;
288 pr_info("APIC(%x) Converting physical %u to logical package %u\n",
289 apicid, pkg, new);
290 physical_to_logical_pkg[pkg] = new;
291
292found:
293 cpu_data(cpu).logical_proc_id = physical_to_logical_pkg[pkg];
294 return 0;
295}

--- 40 unchanged lines hidden (view full) ---

336 */
337 ncpus = boot_cpu_data.x86_max_cores;
338 if (!ncpus) {
339 pr_warn("x86_max_cores == zero !?!?");
340 ncpus = 1;
341 }
342
343 __max_logical_packages = DIV_ROUND_UP(total_cpus, ncpus);
289 pr_info("APIC(%x) Converting physical %u to logical package %u\n",
290 apicid, pkg, new);
291 physical_to_logical_pkg[pkg] = new;
292
293found:
294 cpu_data(cpu).logical_proc_id = physical_to_logical_pkg[pkg];
295 return 0;
296}

--- 40 unchanged lines hidden (view full) ---

337 */
338 ncpus = boot_cpu_data.x86_max_cores;
339 if (!ncpus) {
340 pr_warn("x86_max_cores == zero !?!?");
341 ncpus = 1;
342 }
343
344 __max_logical_packages = DIV_ROUND_UP(total_cpus, ncpus);
345 logical_packages = 0;
344
345 /*
346 * Possibly larger than what we need as the number of apic ids per
347 * package can be smaller than the actual used apic ids.
348 */
349 max_physical_pkg_id = DIV_ROUND_UP(MAX_LOCAL_APIC, ncpus);
350 size = max_physical_pkg_id * sizeof(unsigned int);
351 physical_to_logical_pkg = kmalloc(size, GFP_KERNEL);
352 memset(physical_to_logical_pkg, 0xff, size);
353 size = BITS_TO_LONGS(max_physical_pkg_id) * sizeof(unsigned long);
354 physical_package_map = kzalloc(size, GFP_KERNEL);
346
347 /*
348 * Possibly larger than what we need as the number of apic ids per
349 * package can be smaller than the actual used apic ids.
350 */
351 max_physical_pkg_id = DIV_ROUND_UP(MAX_LOCAL_APIC, ncpus);
352 size = max_physical_pkg_id * sizeof(unsigned int);
353 physical_to_logical_pkg = kmalloc(size, GFP_KERNEL);
354 memset(physical_to_logical_pkg, 0xff, size);
355 size = BITS_TO_LONGS(max_physical_pkg_id) * sizeof(unsigned long);
356 physical_package_map = kzalloc(size, GFP_KERNEL);
355 size = BITS_TO_LONGS(__max_logical_packages) * sizeof(unsigned long);
356 logical_package_map = kzalloc(size, GFP_KERNEL);
357
357
358 pr_info("Max logical packages: %u\n", __max_logical_packages);
359
360 for_each_present_cpu(cpu) {
361 unsigned int apicid = apic->cpu_present_to_apicid(cpu);
362
363 if (apicid == BAD_APICID || !apic->apic_id_valid(apicid))
364 continue;
365 if (!topology_update_package_map(apicid, cpu))
366 continue;
367 pr_warn("CPU %u APICId %x disabled\n", cpu, apicid);
368 per_cpu(x86_bios_cpu_apicid, cpu) = BAD_APICID;
369 set_cpu_possible(cpu, false);
370 set_cpu_present(cpu, false);
371 }
358 for_each_present_cpu(cpu) {
359 unsigned int apicid = apic->cpu_present_to_apicid(cpu);
360
361 if (apicid == BAD_APICID || !apic->apic_id_valid(apicid))
362 continue;
363 if (!topology_update_package_map(apicid, cpu))
364 continue;
365 pr_warn("CPU %u APICId %x disabled\n", cpu, apicid);
366 per_cpu(x86_bios_cpu_apicid, cpu) = BAD_APICID;
367 set_cpu_possible(cpu, false);
368 set_cpu_present(cpu, false);
369 }
370
371 if (logical_packages > __max_logical_packages) {
372 pr_warn("Detected more packages (%u), then computed by BIOS data (%u).\n",
373 logical_packages, __max_logical_packages);
374 logical_packages_frozen = true;
375 __max_logical_packages = logical_packages;
376 }
377
378 pr_info("Max logical packages: %u\n", __max_logical_packages);
372}
373
374void __init smp_store_boot_cpu_info(void)
375{
376 int id = 0; /* CPU 0 */
377 struct cpuinfo_x86 *c = &cpu_data(id);
378
379 *c = boot_cpu_data;

--- 550 unchanged lines hidden (view full) ---

930 per_cpu(current_task, cpu) = idle;
931
932#ifdef CONFIG_X86_32
933 /* Stack for startup_32 can be just as for start_secondary onwards */
934 irq_ctx_init(cpu);
935 per_cpu(cpu_current_top_of_stack, cpu) =
936 (unsigned long)task_stack_page(idle) + THREAD_SIZE;
937#else
379}
380
381void __init smp_store_boot_cpu_info(void)
382{
383 int id = 0; /* CPU 0 */
384 struct cpuinfo_x86 *c = &cpu_data(id);
385
386 *c = boot_cpu_data;

--- 550 unchanged lines hidden (view full) ---

937 per_cpu(current_task, cpu) = idle;
938
939#ifdef CONFIG_X86_32
940 /* Stack for startup_32 can be just as for start_secondary onwards */
941 irq_ctx_init(cpu);
942 per_cpu(cpu_current_top_of_stack, cpu) =
943 (unsigned long)task_stack_page(idle) + THREAD_SIZE;
944#else
938 clear_tsk_thread_flag(idle, TIF_FORK);
939 initial_gs = per_cpu_offset(cpu);
940#endif
941}
942
943/*
944 * NOTE - on most systems this is a PHYSICAL apic ID, but on multiquad
945 * (ie clustered apic addressing mode), this is a LOGICAL apic ID.
946 * Returns zero if CPU booted OK, else error code from

--- 10 unchanged lines hidden (view full) ---

957 int cpu0_nmi_registered = 0;
958 unsigned long timeout;
959
960 idle->thread.sp = (unsigned long) (((struct pt_regs *)
961 (THREAD_SIZE + task_stack_page(idle))) - 1);
962
963 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
964 initial_code = (unsigned long)start_secondary;
945 initial_gs = per_cpu_offset(cpu);
946#endif
947}
948
949/*
950 * NOTE - on most systems this is a PHYSICAL apic ID, but on multiquad
951 * (ie clustered apic addressing mode), this is a LOGICAL apic ID.
952 * Returns zero if CPU booted OK, else error code from

--- 10 unchanged lines hidden (view full) ---

963 int cpu0_nmi_registered = 0;
964 unsigned long timeout;
965
966 idle->thread.sp = (unsigned long) (((struct pt_regs *)
967 (THREAD_SIZE + task_stack_page(idle))) - 1);
968
969 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
970 initial_code = (unsigned long)start_secondary;
965 stack_start = idle->thread.sp;
971 initial_stack = idle->thread.sp;
966
967 /*
968 * Enable the espfix hack for this CPU
969 */
970#ifdef CONFIG_X86_ESPFIX64
971 init_espfix_ap(cpu);
972#endif
973

--- 337 unchanged lines hidden (view full) ---

1311 case SMP_FORCE_UP:
1312 disable_smp();
1313 apic_bsp_setup(false);
1314 return;
1315 case SMP_OK:
1316 break;
1317 }
1318
972
973 /*
974 * Enable the espfix hack for this CPU
975 */
976#ifdef CONFIG_X86_ESPFIX64
977 init_espfix_ap(cpu);
978#endif
979

--- 337 unchanged lines hidden (view full) ---

1317 case SMP_FORCE_UP:
1318 disable_smp();
1319 apic_bsp_setup(false);
1320 return;
1321 case SMP_OK:
1322 break;
1323 }
1324
1325 default_setup_apic_routing();
1326
1319 if (read_apic_id() != boot_cpu_physical_apicid) {
1320 panic("Boot APIC ID in local APIC unexpected (%d vs %d)",
1321 read_apic_id(), boot_cpu_physical_apicid);
1322 /* Or can we switch back to PIC here? */
1323 }
1324
1327 if (read_apic_id() != boot_cpu_physical_apicid) {
1328 panic("Boot APIC ID in local APIC unexpected (%d vs %d)",
1329 read_apic_id(), boot_cpu_physical_apicid);
1330 /* Or can we switch back to PIC here? */
1331 }
1332
1325 default_setup_apic_routing();
1326 cpu0_logical_apicid = apic_bsp_setup(false);
1327
1328 pr_info("CPU%d: ", 0);
1329 print_cpu_info(&cpu_data(0));
1330
1331 if (is_uv_system())
1332 uv_system_init();
1333

--- 355 unchanged lines hidden ---
1333 cpu0_logical_apicid = apic_bsp_setup(false);
1334
1335 pr_info("CPU%d: ", 0);
1336 print_cpu_info(&cpu_data(0));
1337
1338 if (is_uv_system())
1339 uv_system_init();
1340

--- 355 unchanged lines hidden ---