2 * x86 SMP booting functions
4 * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
5 * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com>
6 * Copyright 2001 Andi Kleen, SuSE Labs.
8 * Much of the core SMP work is based on previous work by Thomas Radke, to
9 * whom a great many thanks are extended.
11 * Thanks to Intel for making available several different Pentium,
12 * Pentium Pro and Pentium-II/Xeon MP machines.
13 * Original development of Linux SMP code supported by Caldera.
15 * This code is released under the GNU General Public License version 2
18 * Felix Koop : NR_CPUS used properly
19 * Jose Renau : Handle single CPU case.
20 * Alan Cox : By repeated request 8) - Total BogoMIP report.
21 * Greg Wright : Fix for kernel stacks panic.
22 * Erich Boleyn : MP v1.4 and additional changes.
23 * Matthias Sattler : Changes for 2.1 kernel map.
24 * Michel Lespinasse : Changes for 2.1 kernel map.
25 * Michael Chastain : Change trampoline.S to gnu as.
26 * Alan Cox : Dumb bug: 'B' step PPro's are fine
27 * Ingo Molnar : Added APIC timers, based on code
29 * Ingo Molnar : various cleanups and rewrites
30 * Tigran Aivazian : fixed "0.00 in /proc/uptime on SMP" bug.
31 * Maciej W. Rozycki : Bits for genuine 82489DX APICs
32 * Andi Kleen : Changed for SMP boot into long mode.
33 * Rusty Russell : Hacked into shape for new "hotplug" boot process.
34 * Andi Kleen : Converted to new state machine.
36 * Probably mostly hotplug CPU ready now.
37 * Ashok Raj : CPU hotplug support
41 #include <linux/init.h>
44 #include <linux/kernel_stat.h>
45 #include <linux/bootmem.h>
46 #include <linux/thread_info.h>
47 #include <linux/module.h>
48 #include <linux/delay.h>
49 #include <linux/mc146818rtc.h>
50 #include <linux/smp.h>
51 #include <linux/kdebug.h>
54 #include <asm/pgalloc.h>
56 #include <asm/tlbflush.h>
57 #include <asm/proto.h>
60 #include <asm/hw_irq.h>
63 /* Number of siblings per CPU package */
64 int smp_num_siblings = 1;
65 EXPORT_SYMBOL(smp_num_siblings);
67 /* Last level cache ID of each logical CPU */
68 DEFINE_PER_CPU(u16, cpu_llc_id) = BAD_APICID;
70 /* Bitmask of currently online CPUs */
71 cpumask_t cpu_online_map __read_mostly;
73 EXPORT_SYMBOL(cpu_online_map);
76 * Private maps to synchronize booting between AP and BP.
77 * Probably not needed anymore, but it makes for easier debugging. -AK
79 cpumask_t cpu_callin_map;
80 cpumask_t cpu_callout_map;
81 cpumask_t cpu_possible_map;
82 EXPORT_SYMBOL(cpu_possible_map);
84 /* Per CPU bogomips and other parameters */
85 DEFINE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info);
86 EXPORT_PER_CPU_SYMBOL(cpu_info);
88 /* Set when the idlers are all forked */
89 int smp_threads_ready;
91 /* representing HT siblings of each logical CPU */
92 DEFINE_PER_CPU(cpumask_t, cpu_sibling_map);
93 EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);
95 /* representing HT and core siblings of each logical CPU */
96 DEFINE_PER_CPU(cpumask_t, cpu_core_map);
97 EXPORT_PER_CPU_SYMBOL(cpu_core_map);
100 * Trampoline 80x86 program as an array.
103 extern const unsigned char trampoline_data[];
104 extern const unsigned char trampoline_end[];
106 /* State of each CPU */
107 DEFINE_PER_CPU(int, cpu_state) = { 0 };
110 * Store all idle threads, this can be reused instead of creating
111 * a new thread. Also avoids complicated thread destroy functionality
114 #ifdef CONFIG_HOTPLUG_CPU
116 * Needed only for CONFIG_HOTPLUG_CPU because __cpuinitdata is
117 * removed after init for !CONFIG_HOTPLUG_CPU.
119 static DEFINE_PER_CPU(struct task_struct *, idle_thread_array);
120 #define get_idle_for_cpu(x) (per_cpu(idle_thread_array, x))
121 #define set_idle_for_cpu(x,p) (per_cpu(idle_thread_array, x) = (p))
123 struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;
124 #define get_idle_for_cpu(x) (idle_thread_array[(x)])
125 #define set_idle_for_cpu(x,p) (idle_thread_array[(x)] = (p))
130 * Currently trivial. Write the real->protected mode
131 * bootstrap into the page concerned. The caller
132 * has made sure it's suitably aligned.
135 static unsigned long __cpuinit setup_trampoline(void)
137 void *tramp = __va(SMP_TRAMPOLINE_BASE);
138 memcpy(tramp, trampoline_data, trampoline_end - trampoline_data);
139 return virt_to_phys(tramp);
143 * The bootstrap kernel entry code has set these up. Save them for
147 static void __cpuinit smp_store_cpu_info(int id)
149 struct cpuinfo_x86 *c = &cpu_data(id);
157 static atomic_t init_deasserted __cpuinitdata;
160 * Report back to the Boot Processor.
163 void __cpuinit smp_callin(void)
166 unsigned long timeout;
169 * If waken up by an INIT in an 82489DX configuration
170 * we may get here before an INIT-deassert IPI reaches
171 * our local APIC. We have to wait for the IPI or we'll
172 * lock up on an APIC access.
174 while (!atomic_read(&init_deasserted))
178 * (This works even if the APIC is not enabled.)
180 phys_id = GET_APIC_ID(apic_read(APIC_ID));
181 cpuid = smp_processor_id();
182 if (cpu_isset(cpuid, cpu_callin_map)) {
183 panic("smp_callin: phys CPU#%d, CPU#%d already present??\n",
186 Dprintk("CPU#%d (phys ID: %d) waiting for CALLOUT\n", cpuid, phys_id);
189 * STARTUP IPIs are fragile beasts as they might sometimes
190 * trigger some glue motherboard logic. Complete APIC bus
191 * silence for 1 second, this overestimates the time the
192 * boot CPU is spending to send the up to 2 STARTUP IPIs
193 * by a factor of two. This should be enough.
197 * Waiting 2s total for startup (udelay is not yet working)
199 timeout = jiffies + 2*HZ;
200 while (time_before(jiffies, timeout)) {
202 * Has the boot CPU finished it's STARTUP sequence?
204 if (cpu_isset(cpuid, cpu_callout_map))
209 if (!time_before(jiffies, timeout)) {
210 panic("smp_callin: CPU%d started up but did not get a callout!\n",
215 * the boot CPU has finished the init stage and is spinning
216 * on callin_map until we finish. We are free to set up this
217 * CPU, first the APIC. (this is probably redundant on most
221 Dprintk("CALLIN, before setup_local_APIC().\n");
223 end_local_APIC_setup();
228 * Need to enable IRQs because it can take longer and then
229 * the NMI watchdog might kill us.
234 Dprintk("Stack at about %p\n",&cpuid);
237 * Save our processor parameters
239 smp_store_cpu_info(cpuid);
242 * Allow the master to continue.
244 cpu_set(cpuid, cpu_callin_map);
247 /* maps the cpu to the sched domain representing multi-core */
248 cpumask_t cpu_coregroup_map(int cpu)
250 struct cpuinfo_x86 *c = &cpu_data(cpu);
252 * For perf, we return last level cache shared map.
253 * And for power savings, we return cpu_core_map
255 if (sched_mc_power_savings || sched_smt_power_savings)
256 return per_cpu(cpu_core_map, cpu);
258 return c->llc_shared_map;
261 /* representing cpus for which sibling maps can be computed */
262 static cpumask_t cpu_sibling_setup_map;
264 static inline void set_cpu_sibling_map(int cpu)
267 struct cpuinfo_x86 *c = &cpu_data(cpu);
269 cpu_set(cpu, cpu_sibling_setup_map);
271 if (smp_num_siblings > 1) {
272 for_each_cpu_mask(i, cpu_sibling_setup_map) {
273 if (c->phys_proc_id == cpu_data(i).phys_proc_id &&
274 c->cpu_core_id == cpu_data(i).cpu_core_id) {
275 cpu_set(i, per_cpu(cpu_sibling_map, cpu));
276 cpu_set(cpu, per_cpu(cpu_sibling_map, i));
277 cpu_set(i, per_cpu(cpu_core_map, cpu));
278 cpu_set(cpu, per_cpu(cpu_core_map, i));
279 cpu_set(i, c->llc_shared_map);
280 cpu_set(cpu, cpu_data(i).llc_shared_map);
284 cpu_set(cpu, per_cpu(cpu_sibling_map, cpu));
287 cpu_set(cpu, c->llc_shared_map);
289 if (current_cpu_data.x86_max_cores == 1) {
290 per_cpu(cpu_core_map, cpu) = per_cpu(cpu_sibling_map, cpu);
295 for_each_cpu_mask(i, cpu_sibling_setup_map) {
296 if (per_cpu(cpu_llc_id, cpu) != BAD_APICID &&
297 per_cpu(cpu_llc_id, cpu) == per_cpu(cpu_llc_id, i)) {
298 cpu_set(i, c->llc_shared_map);
299 cpu_set(cpu, cpu_data(i).llc_shared_map);
301 if (c->phys_proc_id == cpu_data(i).phys_proc_id) {
302 cpu_set(i, per_cpu(cpu_core_map, cpu));
303 cpu_set(cpu, per_cpu(cpu_core_map, i));
305 * Does this new cpu bringup a new core?
307 if (cpus_weight(per_cpu(cpu_sibling_map, cpu)) == 1) {
309 * for each core in package, increment
310 * the booted_cores for this new cpu
312 if (first_cpu(per_cpu(cpu_sibling_map, i)) == i)
315 * increment the core count for all
316 * the other cpus in this package
319 cpu_data(i).booted_cores++;
320 } else if (i != cpu && !c->booted_cores)
321 c->booted_cores = cpu_data(i).booted_cores;
327 * Setup code on secondary processor (after comming out of the trampoline)
329 void __cpuinit start_secondary(void)
332 * Dont put anything before smp_callin(), SMP
333 * booting is too fragile that we want to limit the
334 * things done here to the most necessary things.
340 /* otherwise gcc will move up the smp_processor_id before the cpu_init */
344 * Check TSC sync first:
346 check_tsc_sync_target();
348 if (nmi_watchdog == NMI_IO_APIC) {
349 disable_8259A_irq(0);
350 enable_NMI_through_LVT0();
355 * The sibling maps must be set before turing the online map on for
358 set_cpu_sibling_map(smp_processor_id());
361 * We need to hold call_lock, so there is no inconsistency
362 * between the time smp_call_function() determines number of
363 * IPI recipients, and the time when the determination is made
364 * for which cpus receive the IPI in genapic_flat.c. Holding this
365 * lock helps us to not include this cpu in a currently in progress
366 * smp_call_function().
368 lock_ipi_call_lock();
369 spin_lock(&vector_lock);
371 /* Setup the per cpu irq handling data structures */
372 __setup_vector_irq(smp_processor_id());
374 * Allow the master to continue.
376 cpu_set(smp_processor_id(), cpu_online_map);
377 per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
378 spin_unlock(&vector_lock);
380 unlock_ipi_call_lock();
382 setup_secondary_clock();
387 extern volatile unsigned long init_rsp;
388 extern void (*initial_code)(void);
391 static void inquire_remote_apic(int apicid)
393 unsigned i, regs[] = { APIC_ID >> 4, APIC_LVR >> 4, APIC_SPIV >> 4 };
394 char *names[] = { "ID", "VERSION", "SPIV" };
398 printk(KERN_INFO "Inquiring remote APIC #%d...\n", apicid);
400 for (i = 0; i < ARRAY_SIZE(regs); i++) {
401 printk(KERN_INFO "... APIC #%d %s: ", apicid, names[i]);
406 status = safe_apic_wait_icr_idle();
409 "a previous APIC delivery may have failed\n");
411 apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(apicid));
412 apic_write(APIC_ICR, APIC_DM_REMRD | regs[i]);
417 status = apic_read(APIC_ICR) & APIC_ICR_RR_MASK;
418 } while (status == APIC_ICR_RR_INPROG && timeout++ < 1000);
421 case APIC_ICR_RR_VALID:
422 status = apic_read(APIC_RRR);
423 printk(KERN_CONT "%08x\n", status);
426 printk(KERN_CONT "failed\n");
433 * Kick the secondary to wake up.
435 static int __cpuinit wakeup_secondary_via_INIT(int phys_apicid, unsigned int start_rip)
437 unsigned long send_status, accept_status = 0;
438 int maxlvt, num_starts, j;
440 Dprintk("Asserting INIT.\n");
443 * Turn INIT on target chip
445 apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
450 apic_write(APIC_ICR, APIC_INT_LEVELTRIG | APIC_INT_ASSERT
453 Dprintk("Waiting for send to finish...\n");
454 send_status = safe_apic_wait_icr_idle();
458 Dprintk("Deasserting INIT.\n");
461 apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
464 apic_write(APIC_ICR, APIC_INT_LEVELTRIG | APIC_DM_INIT);
466 Dprintk("Waiting for send to finish...\n");
467 send_status = safe_apic_wait_icr_idle();
470 atomic_set(&init_deasserted, 1);
475 * Run STARTUP IPI loop.
477 Dprintk("#startup loops: %d.\n", num_starts);
479 maxlvt = lapic_get_maxlvt();
481 for (j = 1; j <= num_starts; j++) {
482 Dprintk("Sending STARTUP #%d.\n",j);
483 apic_write(APIC_ESR, 0);
485 Dprintk("After apic_write.\n");
492 apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
494 /* Boot on the stack */
495 /* Kick the second */
496 apic_write(APIC_ICR, APIC_DM_STARTUP | (start_rip >> 12));
499 * Give the other CPU some time to accept the IPI.
503 Dprintk("Startup point 1.\n");
505 Dprintk("Waiting for send to finish...\n");
506 send_status = safe_apic_wait_icr_idle();
509 * Give the other CPU some time to accept the IPI.
513 * Due to the Pentium erratum 3AP.
516 apic_write(APIC_ESR, 0);
518 accept_status = (apic_read(APIC_ESR) & 0xEF);
519 if (send_status || accept_status)
522 Dprintk("After Startup.\n");
525 printk(KERN_ERR "APIC never delivered???\n");
527 printk(KERN_ERR "APIC delivery error (%lx).\n", accept_status);
529 return (send_status | accept_status);
533 struct work_struct work;
534 struct task_struct *idle;
535 struct completion done;
539 static void __cpuinit do_fork_idle(struct work_struct *work)
541 struct create_idle *c_idle =
542 container_of(work, struct create_idle, work);
544 c_idle->idle = fork_idle(c_idle->cpu);
545 complete(&c_idle->done);
551 static int __cpuinit do_boot_cpu(int cpu, int apicid)
553 unsigned long boot_error;
555 unsigned long start_rip;
556 struct create_idle c_idle = {
558 .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done),
560 INIT_WORK(&c_idle.work, do_fork_idle);
562 /* allocate memory for gdts of secondary cpus. Hotplug is considered */
563 if (!cpu_gdt_descr[cpu].address &&
564 !(cpu_gdt_descr[cpu].address = get_zeroed_page(GFP_KERNEL))) {
565 printk(KERN_ERR "Failed to allocate GDT for CPU %d\n", cpu);
569 /* Allocate node local memory for AP pdas */
570 if (cpu_pda(cpu) == &boot_cpu_pda[cpu]) {
571 struct x8664_pda *newpda, *pda;
572 int node = cpu_to_node(cpu);
574 newpda = kmalloc_node(sizeof (struct x8664_pda), GFP_ATOMIC,
577 memcpy(newpda, pda, sizeof (struct x8664_pda));
578 cpu_pda(cpu) = newpda;
581 "Could not allocate node local PDA for CPU %d on node %d\n",
585 alternatives_smp_switch(1);
587 c_idle.idle = get_idle_for_cpu(cpu);
590 c_idle.idle->thread.sp = (unsigned long) (((struct pt_regs *)
591 (THREAD_SIZE + task_stack_page(c_idle.idle))) - 1);
592 init_idle(c_idle.idle, cpu);
597 * During cold boot process, keventd thread is not spun up yet.
598 * When we do cpu hot-add, we create idle threads on the fly, we should
599 * not acquire any attributes from the calling context. Hence the clean
600 * way to create kernel_threads() is to do that from keventd().
601 * We do the current_is_keventd() due to the fact that ACPI notifier
602 * was also queuing to keventd() and when the caller is already running
603 * in context of keventd(), we would end up with locking up the keventd
606 if (!keventd_up() || current_is_keventd())
607 c_idle.work.func(&c_idle.work);
609 schedule_work(&c_idle.work);
610 wait_for_completion(&c_idle.done);
613 if (IS_ERR(c_idle.idle)) {
614 printk("failed fork for CPU %d\n", cpu);
615 return PTR_ERR(c_idle.idle);
618 set_idle_for_cpu(cpu, c_idle.idle);
622 cpu_pda(cpu)->pcurrent = c_idle.idle;
624 start_rip = setup_trampoline();
626 init_rsp = c_idle.idle->thread.sp;
627 load_sp0(&per_cpu(init_tss, cpu), &c_idle.idle->thread);
628 initial_code = start_secondary;
629 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
631 printk(KERN_INFO "Booting processor %d/%d APIC 0x%x\n", cpu,
632 cpus_weight(cpu_present_map),
636 * This grunge runs the startup process for
637 * the targeted processor.
640 atomic_set(&init_deasserted, 0);
642 Dprintk("Setting warm reset code and vector.\n");
644 CMOS_WRITE(0xa, 0xf);
647 *((volatile unsigned short *) phys_to_virt(0x469)) = start_rip >> 4;
649 *((volatile unsigned short *) phys_to_virt(0x467)) = start_rip & 0xf;
653 * Be paranoid about clearing APIC errors.
655 apic_write(APIC_ESR, 0);
659 * Status is now clean
664 * Starting actual IPI sequence...
666 boot_error = wakeup_secondary_via_INIT(apicid, start_rip);
670 * allow APs to start initializing.
672 Dprintk("Before Callout %d.\n", cpu);
673 cpu_set(cpu, cpu_callout_map);
674 Dprintk("After Callout %d.\n", cpu);
677 * Wait 5s total for a response
679 for (timeout = 0; timeout < 50000; timeout++) {
680 if (cpu_isset(cpu, cpu_callin_map))
681 break; /* It has booted */
685 if (cpu_isset(cpu, cpu_callin_map)) {
686 /* number CPUs logically, starting from 1 (BSP is 0) */
687 Dprintk("CPU has booted.\n");
690 if (*((volatile unsigned char *)phys_to_virt(SMP_TRAMPOLINE_BASE))
692 /* trampoline started but...? */
693 printk("Stuck ??\n");
695 /* trampoline code not run */
696 printk("Not responding.\n");
698 inquire_remote_apic(apicid);
703 cpu_clear(cpu, cpu_callout_map); /* was set here (do_boot_cpu()) */
704 clear_bit(cpu, (unsigned long *)&cpu_initialized); /* was set by cpu_init() */
705 clear_node_cpumask(cpu); /* was set by numa_add_cpu */
706 cpu_clear(cpu, cpu_present_map);
707 cpu_clear(cpu, cpu_possible_map);
708 per_cpu(x86_cpu_to_apicid, cpu) = BAD_APICID;
715 cycles_t cacheflush_time;
716 unsigned long cache_decay_ticks;
719 * Cleanup possible dangling ends...
721 static __cpuinit void smp_cleanup_boot(void)
724 * Paranoid: Set warm reset code and vector here back
730 * Reset trampoline flag
732 *((volatile int *) phys_to_virt(0x467)) = 0;
736 * Fall back to non SMP mode after errors.
738 * RED-PEN audit/test this more. I bet there is more state messed up here.
740 static __init void disable_smp(void)
742 cpu_present_map = cpumask_of_cpu(0);
743 cpu_possible_map = cpumask_of_cpu(0);
744 if (smp_found_config)
745 phys_cpu_present_map = physid_mask_of_physid(boot_cpu_id);
747 phys_cpu_present_map = physid_mask_of_physid(0);
748 cpu_set(0, per_cpu(cpu_sibling_map, 0));
749 cpu_set(0, per_cpu(cpu_core_map, 0));
753 * Various sanity checks.
755 static int __init smp_sanity_check(unsigned max_cpus)
757 if (!physid_isset(hard_smp_processor_id(), phys_cpu_present_map)) {
758 printk("weird, boot CPU (#%d) not listed by the BIOS.\n",
759 hard_smp_processor_id());
760 physid_set(hard_smp_processor_id(), phys_cpu_present_map);
764 * If we couldn't find an SMP configuration at boot time,
765 * get out of here now!
767 if (!smp_found_config) {
768 printk(KERN_NOTICE "SMP motherboard not detected.\n");
770 if (APIC_init_uniprocessor())
771 printk(KERN_NOTICE "Local APIC not detected."
772 " Using dummy APIC emulation.\n");
777 * Should not be necessary because the MP table should list the boot
778 * CPU too, but we do it for the sake of robustness anyway.
780 if (!physid_isset(boot_cpu_id, phys_cpu_present_map)) {
781 printk(KERN_NOTICE "weird, boot CPU (#%d) not listed by the BIOS.\n",
783 physid_set(hard_smp_processor_id(), phys_cpu_present_map);
787 * If we couldn't find a local APIC, then get out of here now!
790 printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
792 printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
798 * If SMP should be disabled, then really disable it!
801 printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n");
809 static void __init smp_cpu_index_default(void)
812 struct cpuinfo_x86 *c;
814 for_each_cpu_mask(i, cpu_possible_map) {
816 /* mark all to hotplug */
817 c->cpu_index = NR_CPUS;
822 * Prepare for SMP bootup. The MP table or ACPI has been read
823 * earlier. Just do some sanity checking here and enable APIC mode.
825 void __init native_smp_prepare_cpus(unsigned int max_cpus)
827 nmi_watchdog_default();
828 smp_cpu_index_default();
829 current_cpu_data = boot_cpu_data;
830 current_thread_info()->cpu = 0; /* needed? */
831 set_cpu_sibling_map(0);
833 if (smp_sanity_check(max_cpus) < 0) {
834 printk(KERN_INFO "SMP disabled\n");
841 * Switch from PIC to APIC mode.
846 * Enable IO APIC before setting up error vector
848 if (!skip_ioapic_setup && nr_ioapics)
850 end_local_APIC_setup();
852 if (GET_APIC_ID(apic_read(APIC_ID)) != boot_cpu_id) {
853 panic("Boot APIC ID in local APIC unexpected (%d vs %d)",
854 GET_APIC_ID(apic_read(APIC_ID)), boot_cpu_id);
855 /* Or can we switch back to PIC here? */
859 * Now start the IO-APICs
861 if (!skip_ioapic_setup && nr_ioapics)
867 * Set up local APIC timer on boot CPU.
874 * Early setup to make printk work.
876 void __init native_smp_prepare_boot_cpu(void)
878 int me = smp_processor_id();
879 /* already set me in cpu_online_map in boot_cpu_init() */
880 cpu_set(me, cpu_callout_map);
881 per_cpu(cpu_state, me) = CPU_ONLINE;
885 * Entry point to boot a CPU.
887 int __cpuinit native_cpu_up(unsigned int cpu)
889 int apicid = cpu_present_to_apicid(cpu);
893 WARN_ON(irqs_disabled());
895 Dprintk("++++++++++++++++++++=_---CPU UP %u\n", cpu);
897 if (apicid == BAD_APICID || apicid == boot_cpu_id ||
898 !physid_isset(apicid, phys_cpu_present_map)) {
899 printk("__cpu_up: bad cpu %d\n", cpu);
904 * Already booted CPU?
906 if (cpu_isset(cpu, cpu_callin_map)) {
907 Dprintk("do_boot_cpu %d Already started\n", cpu);
912 * Save current MTRR state in case it was changed since early boot
913 * (e.g. by the ACPI SMI) to initialize new CPUs with MTRRs in sync:
917 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
919 err = do_boot_cpu(cpu, apicid);
921 Dprintk("do_boot_cpu failed %d\n", err);
925 /* Unleash the CPU! */
926 Dprintk("waiting for cpu %d\n", cpu);
929 * Make sure and check TSC sync:
931 local_irq_save(flags);
932 check_tsc_sync_source(cpu);
933 local_irq_restore(flags);
935 while (!cpu_isset(cpu, cpu_online_map))
943 * Finish the SMP boot.
945 void __init native_smp_cpus_done(unsigned int max_cpus)
949 check_nmi_watchdog();
952 #ifdef CONFIG_HOTPLUG_CPU
954 static void remove_siblinginfo(int cpu)
957 struct cpuinfo_x86 *c = &cpu_data(cpu);
959 for_each_cpu_mask(sibling, per_cpu(cpu_core_map, cpu)) {
960 cpu_clear(cpu, per_cpu(cpu_core_map, sibling));
962 * last thread sibling in this cpu core going down
964 if (cpus_weight(per_cpu(cpu_sibling_map, cpu)) == 1)
965 cpu_data(sibling).booted_cores--;
968 for_each_cpu_mask(sibling, per_cpu(cpu_sibling_map, cpu))
969 cpu_clear(cpu, per_cpu(cpu_sibling_map, sibling));
970 cpus_clear(per_cpu(cpu_sibling_map, cpu));
971 cpus_clear(per_cpu(cpu_core_map, cpu));
974 cpu_clear(cpu, cpu_sibling_setup_map);
977 static void __ref remove_cpu_from_maps(void)
979 int cpu = smp_processor_id();
981 cpu_clear(cpu, cpu_callout_map);
982 cpu_clear(cpu, cpu_callin_map);
983 clear_bit(cpu, (unsigned long *)&cpu_initialized); /* was set by cpu_init() */
984 clear_node_cpumask(cpu);
987 int __cpu_disable(void)
989 int cpu = smp_processor_id();
992 * Perhaps use cpufreq to drop frequency, but that could go
995 * We won't take down the boot processor on i386 due to some
996 * interrupts only being able to be serviced by the BSP.
997 * Especially so if we're not using an IOAPIC -zwane
1002 if (nmi_watchdog == NMI_LOCAL_APIC)
1003 stop_apic_nmi_watchdog(NULL);
1008 * Allow any queued timer interrupts to get serviced
1009 * This is only a temporary solution until we cleanup
1010 * fixup_irqs as we do for IA64.
1015 local_irq_disable();
1016 remove_siblinginfo(cpu);
1018 spin_lock(&vector_lock);
1019 /* It's now safe to remove this processor from the online map */
1020 cpu_clear(cpu, cpu_online_map);
1021 spin_unlock(&vector_lock);
1022 remove_cpu_from_maps();
1023 fixup_irqs(cpu_online_map);
1027 void __cpu_die(unsigned int cpu)
1029 /* We don't do anything here: idle task is faking death itself. */
1032 for (i = 0; i < 10; i++) {
1033 /* They ack this in play_dead by setting CPU_DEAD */
1034 if (per_cpu(cpu_state, cpu) == CPU_DEAD) {
1035 printk ("CPU %d is now offline\n", cpu);
1036 if (1 == num_online_cpus())
1037 alternatives_smp_switch(0);
1042 printk(KERN_ERR "CPU %u didn't die...\n", cpu);
1045 #else /* ... !CONFIG_HOTPLUG_CPU */
1047 int __cpu_disable(void)
1052 void __cpu_die(unsigned int cpu)
1054 /* We said "no" in __cpu_disable */
1057 #endif /* CONFIG_HOTPLUG_CPU */