aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/smpboot.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2008-07-18 07:53:16 -0400
committerIngo Molnar <mingo@elte.hu>2008-07-18 07:53:16 -0400
commitcdbfc557c43ea1f1f9b7062300ecb1254969814b (patch)
tree255f1cf62cea2c3dec208799a00a116e714a6128 /arch/x86/kernel/smpboot.c
parent4d8cc874d7ed43eda72765e9c0e141e170fee4f3 (diff)
parent5b664cb235e97afbf34db9c4d77f08ebd725335e (diff)
Merge branch 'linus' into x86/cleanups
Diffstat (limited to 'arch/x86/kernel/smpboot.c')
-rw-r--r--arch/x86/kernel/smpboot.c216
1 files changed, 77 insertions, 139 deletions
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index e47bfac70c38..a9ca7dadc852 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -67,22 +67,6 @@
67#include <mach_wakecpu.h> 67#include <mach_wakecpu.h>
68#include <smpboot_hooks.h> 68#include <smpboot_hooks.h>
69 69
70/*
71 * FIXME: For x86_64, those are defined in other files. But moving them here,
72 * would make the setup areas dependent on smp, which is a loss. When we
73 * integrate apic between arches, we can probably do a better job, but
74 * right now, they'll stay here -- glommer
75 */
76
77/* which logical CPU number maps to which CPU (physical APIC ID) */
78u16 x86_cpu_to_apicid_init[NR_CPUS] __initdata =
79 { [0 ... NR_CPUS-1] = BAD_APICID };
80void *x86_cpu_to_apicid_early_ptr;
81
82u16 x86_bios_cpu_apicid_init[NR_CPUS] __initdata
83 = { [0 ... NR_CPUS-1] = BAD_APICID };
84void *x86_bios_cpu_apicid_early_ptr;
85
86#ifdef CONFIG_X86_32 70#ifdef CONFIG_X86_32
87u8 apicid_2_node[MAX_APICID]; 71u8 apicid_2_node[MAX_APICID];
88static int low_mappings; 72static int low_mappings;
@@ -197,13 +181,12 @@ static void map_cpu_to_logical_apicid(void)
197 map_cpu_to_node(cpu, node); 181 map_cpu_to_node(cpu, node);
198} 182}
199 183
200static void unmap_cpu_to_logical_apicid(int cpu) 184void numa_remove_cpu(int cpu)
201{ 185{
202 cpu_2_logical_apicid[cpu] = BAD_APICID; 186 cpu_2_logical_apicid[cpu] = BAD_APICID;
203 unmap_cpu_to_node(cpu); 187 unmap_cpu_to_node(cpu);
204} 188}
205#else 189#else
206#define unmap_cpu_to_logical_apicid(cpu) do {} while (0)
207#define map_cpu_to_logical_apicid() do {} while (0) 190#define map_cpu_to_logical_apicid() do {} while (0)
208#endif 191#endif
209 192
@@ -344,19 +327,12 @@ static void __cpuinit start_secondary(void *unused)
344 * lock helps us to not include this cpu in a currently in progress 327 * lock helps us to not include this cpu in a currently in progress
345 * smp_call_function(). 328 * smp_call_function().
346 */ 329 */
347 lock_ipi_call_lock(); 330 ipi_call_lock_irq();
348#ifdef CONFIG_X86_64 331#ifdef CONFIG_X86_IO_APIC
349 spin_lock(&vector_lock); 332 setup_vector_irq(smp_processor_id());
350
351 /* Setup the per cpu irq handling data structures */
352 __setup_vector_irq(smp_processor_id());
353 /*
354 * Allow the master to continue.
355 */
356 spin_unlock(&vector_lock);
357#endif 333#endif
358 cpu_set(smp_processor_id(), cpu_online_map); 334 cpu_set(smp_processor_id(), cpu_online_map);
359 unlock_ipi_call_lock(); 335 ipi_call_unlock_irq();
360 per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE; 336 per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
361 337
362 setup_secondary_clock(); 338 setup_secondary_clock();
@@ -365,31 +341,8 @@ static void __cpuinit start_secondary(void *unused)
365 cpu_idle(); 341 cpu_idle();
366} 342}
367 343
368#ifdef CONFIG_X86_32
369/*
370 * Everything has been set up for the secondary
371 * CPUs - they just need to reload everything
372 * from the task structure
373 * This function must not return.
374 */
375void __devinit initialize_secondary(void)
376{
377 /*
378 * We don't actually need to load the full TSS,
379 * basically just the stack pointer and the ip.
380 */
381
382 asm volatile(
383 "movl %0,%%esp\n\t"
384 "jmp *%1"
385 :
386 :"m" (current->thread.sp), "m" (current->thread.ip));
387}
388#endif
389
390static void __cpuinit smp_apply_quirks(struct cpuinfo_x86 *c) 344static void __cpuinit smp_apply_quirks(struct cpuinfo_x86 *c)
391{ 345{
392#ifdef CONFIG_X86_32
393 /* 346 /*
394 * Mask B, Pentium, but not Pentium MMX 347 * Mask B, Pentium, but not Pentium MMX
395 */ 348 */
@@ -439,7 +392,6 @@ static void __cpuinit smp_apply_quirks(struct cpuinfo_x86 *c)
439 392
440valid_k7: 393valid_k7:
441 ; 394 ;
442#endif
443} 395}
444 396
445static void __cpuinit smp_checks(void) 397static void __cpuinit smp_checks(void)
@@ -554,23 +506,6 @@ cpumask_t cpu_coregroup_map(int cpu)
554 return c->llc_shared_map; 506 return c->llc_shared_map;
555} 507}
556 508
557#ifdef CONFIG_X86_32
558/*
559 * We are called very early to get the low memory for the
560 * SMP bootup trampoline page.
561 */
562void __init smp_alloc_memory(void)
563{
564 trampoline_base = alloc_bootmem_low_pages(PAGE_SIZE);
565 /*
566 * Has to be in very low memory so we can execute
567 * real-mode AP code.
568 */
569 if (__pa(trampoline_base) >= 0x9F000)
570 BUG();
571}
572#endif
573
574static void impress_friends(void) 509static void impress_friends(void)
575{ 510{
576 int cpu; 511 int cpu;
@@ -747,11 +682,7 @@ wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip)
747 * target processor state. 682 * target processor state.
748 */ 683 */
749 startup_ipi_hook(phys_apicid, (unsigned long) start_secondary, 684 startup_ipi_hook(phys_apicid, (unsigned long) start_secondary,
750#ifdef CONFIG_X86_64
751 (unsigned long)init_rsp);
752#else
753 (unsigned long)stack_start.sp); 685 (unsigned long)stack_start.sp);
754#endif
755 686
756 /* 687 /*
757 * Run STARTUP IPI loop. 688 * Run STARTUP IPI loop.
@@ -831,6 +762,45 @@ static void __cpuinit do_fork_idle(struct work_struct *work)
831 complete(&c_idle->done); 762 complete(&c_idle->done);
832} 763}
833 764
765#ifdef CONFIG_X86_64
766/*
767 * Allocate node local memory for the AP pda.
768 *
769 * Must be called after the _cpu_pda pointer table is initialized.
770 */
771static int __cpuinit get_local_pda(int cpu)
772{
773 struct x8664_pda *oldpda, *newpda;
774 unsigned long size = sizeof(struct x8664_pda);
775 int node = cpu_to_node(cpu);
776
777 if (cpu_pda(cpu) && !cpu_pda(cpu)->in_bootmem)
778 return 0;
779
780 oldpda = cpu_pda(cpu);
781 newpda = kmalloc_node(size, GFP_ATOMIC, node);
782 if (!newpda) {
783 printk(KERN_ERR "Could not allocate node local PDA "
784 "for CPU %d on node %d\n", cpu, node);
785
786 if (oldpda)
787 return 0; /* have a usable pda */
788 else
789 return -1;
790 }
791
792 if (oldpda) {
793 memcpy(newpda, oldpda, size);
794 if (!after_bootmem)
795 free_bootmem((unsigned long)oldpda, size);
796 }
797
798 newpda->in_bootmem = 0;
799 cpu_pda(cpu) = newpda;
800 return 0;
801}
802#endif /* CONFIG_X86_64 */
803
834static int __cpuinit do_boot_cpu(int apicid, int cpu) 804static int __cpuinit do_boot_cpu(int apicid, int cpu)
835/* 805/*
836 * NOTE - on most systems this is a PHYSICAL apic ID, but on multiquad 806 * NOTE - on most systems this is a PHYSICAL apic ID, but on multiquad
@@ -847,28 +817,14 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
847 .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done), 817 .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done),
848 }; 818 };
849 INIT_WORK(&c_idle.work, do_fork_idle); 819 INIT_WORK(&c_idle.work, do_fork_idle);
850#ifdef CONFIG_X86_64
851 /* allocate memory for gdts of secondary cpus. Hotplug is considered */
852 if (!cpu_gdt_descr[cpu].address &&
853 !(cpu_gdt_descr[cpu].address = get_zeroed_page(GFP_KERNEL))) {
854 printk(KERN_ERR "Failed to allocate GDT for CPU %d\n", cpu);
855 return -1;
856 }
857 820
821#ifdef CONFIG_X86_64
858 /* Allocate node local memory for AP pdas */ 822 /* Allocate node local memory for AP pdas */
859 if (cpu_pda(cpu) == &boot_cpu_pda[cpu]) { 823 if (cpu > 0) {
860 struct x8664_pda *newpda, *pda; 824 boot_error = get_local_pda(cpu);
861 int node = cpu_to_node(cpu); 825 if (boot_error)
862 pda = cpu_pda(cpu); 826 goto restore_state;
863 newpda = kmalloc_node(sizeof(struct x8664_pda), GFP_ATOMIC, 827 /* if can't get pda memory, can't start cpu */
864 node);
865 if (newpda) {
866 memcpy(newpda, pda, sizeof(struct x8664_pda));
867 cpu_pda(cpu) = newpda;
868 } else
869 printk(KERN_ERR
870 "Could not allocate node local PDA for CPU %d on node %d\n",
871 cpu, node);
872 } 828 }
873#endif 829#endif
874 830
@@ -904,18 +860,15 @@ do_rest:
904#ifdef CONFIG_X86_32 860#ifdef CONFIG_X86_32
905 per_cpu(current_task, cpu) = c_idle.idle; 861 per_cpu(current_task, cpu) = c_idle.idle;
906 init_gdt(cpu); 862 init_gdt(cpu);
907 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
908 c_idle.idle->thread.ip = (unsigned long) start_secondary;
909 /* Stack for startup_32 can be just as for start_secondary onwards */ 863 /* Stack for startup_32 can be just as for start_secondary onwards */
910 stack_start.sp = (void *) c_idle.idle->thread.sp;
911 irq_ctx_init(cpu); 864 irq_ctx_init(cpu);
912#else 865#else
913 cpu_pda(cpu)->pcurrent = c_idle.idle; 866 cpu_pda(cpu)->pcurrent = c_idle.idle;
914 init_rsp = c_idle.idle->thread.sp;
915 load_sp0(&per_cpu(init_tss, cpu), &c_idle.idle->thread);
916 initial_code = (unsigned long)start_secondary;
917 clear_tsk_thread_flag(c_idle.idle, TIF_FORK); 867 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
918#endif 868#endif
869 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
870 initial_code = (unsigned long)start_secondary;
871 stack_start.sp = (void *) c_idle.idle->thread.sp;
919 872
920 /* start_ip had better be page-aligned! */ 873 /* start_ip had better be page-aligned! */
921 start_ip = setup_trampoline(); 874 start_ip = setup_trampoline();
@@ -986,16 +939,14 @@ do_rest:
986 inquire_remote_apic(apicid); 939 inquire_remote_apic(apicid);
987 } 940 }
988 } 941 }
989
990 if (boot_error) {
991 /* Try to put things back the way they were before ... */
992 unmap_cpu_to_logical_apicid(cpu);
993#ifdef CONFIG_X86_64 942#ifdef CONFIG_X86_64
994 clear_node_cpumask(cpu); /* was set by numa_add_cpu */ 943restore_state:
995#endif 944#endif
945 if (boot_error) {
946 /* Try to put things back the way they were before ... */
947 numa_remove_cpu(cpu); /* was set by numa_add_cpu */
996 cpu_clear(cpu, cpu_callout_map); /* was set by do_boot_cpu() */ 948 cpu_clear(cpu, cpu_callout_map); /* was set by do_boot_cpu() */
997 cpu_clear(cpu, cpu_initialized); /* was set by cpu_init() */ 949 cpu_clear(cpu, cpu_initialized); /* was set by cpu_init() */
998 cpu_clear(cpu, cpu_possible_map);
999 cpu_clear(cpu, cpu_present_map); 950 cpu_clear(cpu, cpu_present_map);
1000 per_cpu(x86_cpu_to_apicid, cpu) = BAD_APICID; 951 per_cpu(x86_cpu_to_apicid, cpu) = BAD_APICID;
1001 } 952 }
@@ -1087,14 +1038,12 @@ static __init void disable_smp(void)
1087{ 1038{
1088 cpu_present_map = cpumask_of_cpu(0); 1039 cpu_present_map = cpumask_of_cpu(0);
1089 cpu_possible_map = cpumask_of_cpu(0); 1040 cpu_possible_map = cpumask_of_cpu(0);
1090#ifdef CONFIG_X86_32
1091 smpboot_clear_io_apic_irqs(); 1041 smpboot_clear_io_apic_irqs();
1092#endif 1042
1093 if (smp_found_config) 1043 if (smp_found_config)
1094 phys_cpu_present_map = 1044 physid_set_mask_of_physid(boot_cpu_physical_apicid, &phys_cpu_present_map);
1095 physid_mask_of_physid(boot_cpu_physical_apicid);
1096 else 1045 else
1097 phys_cpu_present_map = physid_mask_of_physid(0); 1046 physid_set_mask_of_physid(0, &phys_cpu_present_map);
1098 map_cpu_to_logical_apicid(); 1047 map_cpu_to_logical_apicid();
1099 cpu_set(0, per_cpu(cpu_sibling_map, 0)); 1048 cpu_set(0, per_cpu(cpu_sibling_map, 0));
1100 cpu_set(0, per_cpu(cpu_core_map, 0)); 1049 cpu_set(0, per_cpu(cpu_core_map, 0));
@@ -1157,12 +1106,12 @@ static int __init smp_sanity_check(unsigned max_cpus)
1157 * If SMP should be disabled, then really disable it! 1106 * If SMP should be disabled, then really disable it!
1158 */ 1107 */
1159 if (!max_cpus) { 1108 if (!max_cpus) {
1160 printk(KERN_INFO "SMP mode deactivated," 1109 printk(KERN_INFO "SMP mode deactivated.\n");
1161 "forcing use of dummy APIC emulation.\n");
1162 smpboot_clear_io_apic(); 1110 smpboot_clear_io_apic();
1163#ifdef CONFIG_X86_32 1111
1112 localise_nmi_watchdog();
1113
1164 connect_bsp_APIC(); 1114 connect_bsp_APIC();
1165#endif
1166 setup_local_APIC(); 1115 setup_local_APIC();
1167 end_local_APIC_setup(); 1116 end_local_APIC_setup();
1168 return -1; 1117 return -1;
@@ -1190,7 +1139,6 @@ static void __init smp_cpu_index_default(void)
1190void __init native_smp_prepare_cpus(unsigned int max_cpus) 1139void __init native_smp_prepare_cpus(unsigned int max_cpus)
1191{ 1140{
1192 preempt_disable(); 1141 preempt_disable();
1193 nmi_watchdog_default();
1194 smp_cpu_index_default(); 1142 smp_cpu_index_default();
1195 current_cpu_data = boot_cpu_data; 1143 current_cpu_data = boot_cpu_data;
1196 cpu_callin_map = cpumask_of_cpu(0); 1144 cpu_callin_map = cpumask_of_cpu(0);
@@ -1217,9 +1165,8 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
1217 } 1165 }
1218 preempt_enable(); 1166 preempt_enable();
1219 1167
1220#ifdef CONFIG_X86_32
1221 connect_bsp_APIC(); 1168 connect_bsp_APIC();
1222#endif 1169
1223 /* 1170 /*
1224 * Switch from PIC to APIC mode. 1171 * Switch from PIC to APIC mode.
1225 */ 1172 */
@@ -1257,8 +1204,8 @@ void __init native_smp_prepare_boot_cpu(void)
1257 int me = smp_processor_id(); 1204 int me = smp_processor_id();
1258#ifdef CONFIG_X86_32 1205#ifdef CONFIG_X86_32
1259 init_gdt(me); 1206 init_gdt(me);
1260 switch_to_new_gdt();
1261#endif 1207#endif
1208 switch_to_new_gdt();
1262 /* already set me in cpu_online_map in boot_cpu_init() */ 1209 /* already set me in cpu_online_map in boot_cpu_init() */
1263 cpu_set(me, cpu_callout_map); 1210 cpu_set(me, cpu_callout_map);
1264 per_cpu(cpu_state, me) = CPU_ONLINE; 1211 per_cpu(cpu_state, me) = CPU_ONLINE;
@@ -1278,23 +1225,6 @@ void __init native_smp_cpus_done(unsigned int max_cpus)
1278 1225
1279#ifdef CONFIG_HOTPLUG_CPU 1226#ifdef CONFIG_HOTPLUG_CPU
1280 1227
1281# ifdef CONFIG_X86_32
1282void cpu_exit_clear(void)
1283{
1284 int cpu = raw_smp_processor_id();
1285
1286 idle_task_exit();
1287
1288 cpu_uninit();
1289 irq_ctx_exit(cpu);
1290
1291 cpu_clear(cpu, cpu_callout_map);
1292 cpu_clear(cpu, cpu_callin_map);
1293
1294 unmap_cpu_to_logical_apicid(cpu);
1295}
1296# endif /* CONFIG_X86_32 */
1297
1298static void remove_siblinginfo(int cpu) 1228static void remove_siblinginfo(int cpu)
1299{ 1229{
1300 int sibling; 1230 int sibling;
@@ -1348,12 +1278,20 @@ __init void prefill_possible_map(void)
1348 int i; 1278 int i;
1349 int possible; 1279 int possible;
1350 1280
1281 /* no processor from mptable or madt */
1282 if (!num_processors)
1283 num_processors = 1;
1284
1285#ifdef CONFIG_HOTPLUG_CPU
1351 if (additional_cpus == -1) { 1286 if (additional_cpus == -1) {
1352 if (disabled_cpus > 0) 1287 if (disabled_cpus > 0)
1353 additional_cpus = disabled_cpus; 1288 additional_cpus = disabled_cpus;
1354 else 1289 else
1355 additional_cpus = 0; 1290 additional_cpus = 0;
1356 } 1291 }
1292#else
1293 additional_cpus = 0;
1294#endif
1357 possible = num_processors + additional_cpus; 1295 possible = num_processors + additional_cpus;
1358 if (possible > NR_CPUS) 1296 if (possible > NR_CPUS)
1359 possible = NR_CPUS; 1297 possible = NR_CPUS;
@@ -1363,18 +1301,18 @@ __init void prefill_possible_map(void)
1363 1301
1364 for (i = 0; i < possible; i++) 1302 for (i = 0; i < possible; i++)
1365 cpu_set(i, cpu_possible_map); 1303 cpu_set(i, cpu_possible_map);
1304
1305 nr_cpu_ids = possible;
1366} 1306}
1367 1307
1368static void __ref remove_cpu_from_maps(int cpu) 1308static void __ref remove_cpu_from_maps(int cpu)
1369{ 1309{
1370 cpu_clear(cpu, cpu_online_map); 1310 cpu_clear(cpu, cpu_online_map);
1371#ifdef CONFIG_X86_64
1372 cpu_clear(cpu, cpu_callout_map); 1311 cpu_clear(cpu, cpu_callout_map);
1373 cpu_clear(cpu, cpu_callin_map); 1312 cpu_clear(cpu, cpu_callin_map);
1374 /* was set by cpu_init() */ 1313 /* was set by cpu_init() */
1375 clear_bit(cpu, (unsigned long *)&cpu_initialized); 1314 clear_bit(cpu, (unsigned long *)&cpu_initialized);
1376 clear_node_cpumask(cpu); 1315 numa_remove_cpu(cpu);
1377#endif
1378} 1316}
1379 1317
1380int __cpu_disable(void) 1318int __cpu_disable(void)