ia64/xen-unstable

view xen/arch/ia64/linux-xen/smpboot.c @ 17208:82fa2e6cb592

[IA64] vmx_init_env must be called on every processor

Signed-off-by: Anthony Xu <anthony.xu@intel.com>
author Alex Williamson <alex.williamson@hp.com>
date Fri Mar 14 15:02:12 2008 -0600 (2008-03-14)
parents ec3f4e9e62f6
children 7da7b53b2139
line source
1 /*
2 * SMP boot-related support
3 *
4 * Copyright (C) 1998-2003, 2005 Hewlett-Packard Co
5 * David Mosberger-Tang <davidm@hpl.hp.com>
6 * Copyright (C) 2001, 2004-2005 Intel Corp
7 * Rohit Seth <rohit.seth@intel.com>
8 * Suresh Siddha <suresh.b.siddha@intel.com>
9 * Gordon Jin <gordon.jin@intel.com>
10 * Ashok Raj <ashok.raj@intel.com>
11 *
12 * 01/05/16 Rohit Seth <rohit.seth@intel.com> Moved SMP booting functions from smp.c to here.
13 * 01/04/27 David Mosberger <davidm@hpl.hp.com> Added ITC synching code.
14 * 02/07/31 David Mosberger <davidm@hpl.hp.com> Switch over to hotplug-CPU boot-sequence.
15 * smp_boot_cpus()/smp_commence() is replaced by
16 * smp_prepare_cpus()/__cpu_up()/smp_cpus_done().
17 * 04/06/21 Ashok Raj <ashok.raj@intel.com> Added CPU Hotplug Support
18 * 04/12/26 Jin Gordon <gordon.jin@intel.com>
19 * 04/12/26 Rohit Seth <rohit.seth@intel.com>
20 * Add multi-threading and multi-core detection
21 * 05/01/30 Suresh Siddha <suresh.b.siddha@intel.com>
22 * Setup cpu_sibling_map and cpu_core_map
23 */
24 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/acpi.h>
28 #include <linux/bootmem.h>
29 #include <linux/cpu.h>
30 #include <linux/delay.h>
31 #include <linux/init.h>
32 #include <linux/interrupt.h>
33 #include <linux/irq.h>
34 #include <linux/kernel.h>
35 #include <linux/kernel_stat.h>
36 #include <linux/mm.h>
37 #include <linux/notifier.h> /* hg add me */
38 #include <linux/smp.h>
39 #include <linux/smp_lock.h>
40 #include <linux/spinlock.h>
41 #include <linux/efi.h>
42 #include <linux/percpu.h>
43 #include <linux/bitops.h>
45 #include <asm/atomic.h>
46 #include <asm/cache.h>
47 #include <asm/current.h>
48 #include <asm/delay.h>
49 #include <asm/ia32.h>
50 #include <asm/io.h>
51 #include <asm/irq.h>
52 #include <asm/machvec.h>
53 #include <asm/mca.h>
54 #include <asm/page.h>
55 #include <asm/pgalloc.h>
56 #include <asm/pgtable.h>
57 #include <asm/processor.h>
58 #include <asm/ptrace.h>
59 #include <asm/sal.h>
60 #include <asm/system.h>
61 #include <asm/tlbflush.h>
62 #include <asm/unistd.h>
64 #ifdef XEN
65 #include <xen/domain.h>
66 #include <asm/hw_irq.h>
67 #include <asm/vmx.h>
68 #ifndef CONFIG_SMP
69 cpumask_t cpu_online_map = CPU_MASK_CPU0;
70 EXPORT_SYMBOL(cpu_online_map);
71 #endif
72 #endif
74 #ifdef CONFIG_SMP /* ifdef XEN */
76 #define SMP_DEBUG 0
78 #if SMP_DEBUG
79 #define Dprintk(x...) printk(x)
80 #else
81 #define Dprintk(x...)
82 #endif
84 #ifdef CONFIG_HOTPLUG_CPU
85 /*
86 * Store all idle threads, this can be reused instead of creating
87 * a new thread. Also avoids complicated thread destroy functionality
88 * for idle threads.
89 */
90 struct task_struct *idle_thread_array[NR_CPUS];
92 /*
93 * Global array allocated for NR_CPUS at boot time
94 */
95 struct sal_to_os_boot sal_boot_rendez_state[NR_CPUS];
97 /*
98 * start_ap in head.S uses this to store current booting cpu
99 * info.
100 */
101 struct sal_to_os_boot *sal_state_for_booting_cpu = &sal_boot_rendez_state[0];
103 #define set_brendez_area(x) (sal_state_for_booting_cpu = &sal_boot_rendez_state[(x)]);
105 #define get_idle_for_cpu(x) (idle_thread_array[(x)])
106 #define set_idle_for_cpu(x,p) (idle_thread_array[(x)] = (p))
108 #else
110 #define get_idle_for_cpu(x) (NULL)
111 #define set_idle_for_cpu(x,p)
112 #define set_brendez_area(x)
113 #endif
116 /*
117 * ITC synchronization related stuff:
118 */
119 #define MASTER 0
120 #define SLAVE (SMP_CACHE_BYTES/8)
122 #define NUM_ROUNDS 64 /* magic value */
123 #define NUM_ITERS 5 /* likewise */
125 static DEFINE_SPINLOCK(itc_sync_lock);
126 static volatile unsigned long go[SLAVE + 1];
128 #define DEBUG_ITC_SYNC 0
130 extern void __devinit calibrate_delay (void);
131 extern void start_ap (void);
132 extern unsigned long ia64_iobase;
134 task_t *task_for_booting_cpu;
136 /*
137 * State for each CPU
138 */
139 DEFINE_PER_CPU(int, cpu_state);
141 /* Bitmasks of currently online, and possible CPUs */
142 cpumask_t cpu_online_map;
143 EXPORT_SYMBOL(cpu_online_map);
144 cpumask_t cpu_possible_map;
145 EXPORT_SYMBOL(cpu_possible_map);
147 cpumask_t cpu_core_map[NR_CPUS] __cacheline_aligned;
148 cpumask_t cpu_sibling_map[NR_CPUS] __cacheline_aligned;
149 int smp_num_siblings = 1;
150 int smp_num_cpucores = 1;
152 /* which logical CPU number maps to which CPU (physical APIC ID) */
153 volatile int ia64_cpu_to_sapicid[NR_CPUS];
154 EXPORT_SYMBOL(ia64_cpu_to_sapicid);
156 static volatile cpumask_t cpu_callin_map;
158 struct smp_boot_data smp_boot_data __initdata;
160 unsigned long ap_wakeup_vector = -1; /* External Int use to wakeup APs */
162 char __initdata no_int_routing;
164 unsigned char smp_int_redirect; /* are INT and IPI redirectable by the chipset? */
166 static int __init
167 nointroute (char *str)
168 {
169 no_int_routing = 1;
170 printk ("no_int_routing on\n");
171 return 1;
172 }
174 __setup("nointroute", nointroute);
176 static void fix_b0_for_bsp(void)
177 {
178 #ifdef CONFIG_HOTPLUG_CPU
179 int cpuid;
180 static int fix_bsp_b0 = 1;
182 cpuid = smp_processor_id();
184 /*
185 * Cache the b0 value on the first AP that comes up
186 */
187 if (!(fix_bsp_b0 && cpuid))
188 return;
190 sal_boot_rendez_state[0].br[0] = sal_boot_rendez_state[cpuid].br[0];
191 printk ("Fixed BSP b0 value from CPU %d\n", cpuid);
193 fix_bsp_b0 = 0;
194 #endif
195 }
197 void
198 sync_master (void *arg)
199 {
200 unsigned long flags, i;
202 go[MASTER] = 0;
204 local_irq_save(flags);
205 {
206 for (i = 0; i < NUM_ROUNDS*NUM_ITERS; ++i) {
207 while (!go[MASTER])
208 cpu_relax();
209 go[MASTER] = 0;
210 go[SLAVE] = ia64_get_itc();
211 }
212 }
213 local_irq_restore(flags);
214 }
216 /*
217 * Return the number of cycles by which our itc differs from the itc on the master
218 * (time-keeper) CPU. A positive number indicates our itc is ahead of the master,
219 * negative that it is behind.
220 */
221 static inline long
222 #ifdef XEN /* warning cleanup */
223 get_delta (unsigned long *rt, unsigned long *master)
224 #else
225 get_delta (long *rt, long *master)
226 #endif
227 {
228 unsigned long best_t0 = 0, best_t1 = ~0UL, best_tm = 0;
229 unsigned long tcenter, t0, t1, tm;
230 long i;
232 for (i = 0; i < NUM_ITERS; ++i) {
233 t0 = ia64_get_itc();
234 go[MASTER] = 1;
235 while (!(tm = go[SLAVE]))
236 cpu_relax();
237 go[SLAVE] = 0;
238 t1 = ia64_get_itc();
240 if (t1 - t0 < best_t1 - best_t0)
241 best_t0 = t0, best_t1 = t1, best_tm = tm;
242 }
244 *rt = best_t1 - best_t0;
245 *master = best_tm - best_t0;
247 /* average best_t0 and best_t1 without overflow: */
248 tcenter = (best_t0/2 + best_t1/2);
249 if (best_t0 % 2 + best_t1 % 2 == 2)
250 ++tcenter;
251 return tcenter - best_tm;
252 }
254 /*
255 * Synchronize ar.itc of the current (slave) CPU with the ar.itc of the MASTER CPU
256 * (normally the time-keeper CPU). We use a closed loop to eliminate the possibility of
257 * unaccounted-for errors (such as getting a machine check in the middle of a calibration
258 * step). The basic idea is for the slave to ask the master what itc value it has and to
259 * read its own itc before and after the master responds. Each iteration gives us three
260 * timestamps:
261 *
262 * slave master
263 *
264 * t0 ---\
265 * ---\
266 * --->
267 * tm
268 * /---
269 * /---
270 * t1 <---
271 *
272 *
273 * The goal is to adjust the slave's ar.itc such that tm falls exactly half-way between t0
274 * and t1. If we achieve this, the clocks are synchronized provided the interconnect
275 * between the slave and the master is symmetric. Even if the interconnect were
276 * asymmetric, we would still know that the synchronization error is smaller than the
277 * roundtrip latency (t0 - t1).
278 *
279 * When the interconnect is quiet and symmetric, this lets us synchronize the itc to
280 * within one or two cycles. However, we can only *guarantee* that the synchronization is
281 * accurate to within a round-trip time, which is typically in the range of several
282 * hundred cycles (e.g., ~500 cycles). In practice, this means that the itc's are usually
283 * almost perfectly synchronized, but we shouldn't assume that the accuracy is much better
284 * than half a micro second or so.
285 */
286 void
287 ia64_sync_itc (unsigned int master)
288 {
289 long i, delta, adj, adjust_latency = 0, done = 0;
290 unsigned long flags, rt, master_time_stamp, bound;
291 #if DEBUG_ITC_SYNC
292 struct {
293 long rt; /* roundtrip time */
294 long master; /* master's timestamp */
295 long diff; /* difference between midpoint and master's timestamp */
296 long lat; /* estimate of itc adjustment latency */
297 } t[NUM_ROUNDS];
298 #endif
300 /*
301 * Make sure local timer ticks are disabled while we sync. If
302 * they were enabled, we'd have to worry about nasty issues
303 * like setting the ITC ahead of (or a long time before) the
304 * next scheduled tick.
305 */
306 BUG_ON((ia64_get_itv() & (1 << 16)) == 0);
308 go[MASTER] = 1;
310 if (smp_call_function_single(master, sync_master, NULL, 1, 0) < 0) {
311 printk(KERN_ERR "sync_itc: failed to get attention of CPU %u!\n", master);
312 return;
313 }
315 while (go[MASTER])
316 cpu_relax(); /* wait for master to be ready */
318 spin_lock_irqsave(&itc_sync_lock, flags);
319 {
320 for (i = 0; i < NUM_ROUNDS; ++i) {
321 delta = get_delta(&rt, &master_time_stamp);
322 if (delta == 0) {
323 done = 1; /* let's lock on to this... */
324 bound = rt;
325 }
327 if (!done) {
328 if (i > 0) {
329 adjust_latency += -delta;
330 adj = -delta + adjust_latency/4;
331 } else
332 adj = -delta;
334 ia64_set_itc(ia64_get_itc() + adj);
335 }
336 #if DEBUG_ITC_SYNC
337 t[i].rt = rt;
338 t[i].master = master_time_stamp;
339 t[i].diff = delta;
340 t[i].lat = adjust_latency/4;
341 #endif
342 }
343 }
344 spin_unlock_irqrestore(&itc_sync_lock, flags);
346 #if DEBUG_ITC_SYNC
347 for (i = 0; i < NUM_ROUNDS; ++i)
348 printk("rt=%5ld master=%5ld diff=%5ld adjlat=%5ld\n",
349 t[i].rt, t[i].master, t[i].diff, t[i].lat);
350 #endif
352 printk(KERN_INFO "CPU %d: synchronized ITC with CPU %u (last diff %ld cycles, "
353 "maxerr %lu cycles)\n", smp_processor_id(), master, delta, rt);
354 }
356 /*
357 * Ideally sets up per-cpu profiling hooks. Doesn't do much now...
358 */
359 static inline void __devinit
360 smp_setup_percpu_timer (void)
361 {
362 }
364 static void __devinit
365 smp_callin (void)
366 {
367 int cpuid, phys_id;
368 extern void ia64_init_itm(void);
370 #ifdef CONFIG_PERFMON
371 extern void pfm_init_percpu(void);
372 #endif
374 cpuid = smp_processor_id();
375 phys_id = hard_smp_processor_id();
377 if (cpu_online(cpuid)) {
378 printk(KERN_ERR "huh, phys CPU#0x%x, CPU#0x%x already present??\n",
379 phys_id, cpuid);
380 BUG();
381 }
383 fix_b0_for_bsp();
385 lock_ipi_calllock();
386 cpu_set(cpuid, cpu_online_map);
387 unlock_ipi_calllock();
388 per_cpu(cpu_state, cpuid) = CPU_ONLINE;
390 smp_setup_percpu_timer();
392 ia64_mca_cmc_vector_setup(); /* Setup vector on AP */
394 #ifdef CONFIG_PERFMON
395 pfm_init_percpu();
396 #endif
398 local_irq_enable();
400 if (!(sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)) {
401 /*
402 * Synchronize the ITC with the BP. Need to do this after irqs are
403 * enabled because ia64_sync_itc() calls smp_call_function_single(), which
404 * calls spin_unlock_bh(), which calls spin_unlock_bh(), which calls
405 * local_bh_enable(), which bugs out if irqs are not enabled...
406 */
407 Dprintk("Going to syncup ITC with BP.\n");
408 ia64_sync_itc(0);
409 }
411 /*
412 * Get our bogomips.
413 */
414 ia64_init_itm();
415 #ifndef XEN
416 calibrate_delay();
417 #endif
418 local_cpu_data->loops_per_jiffy = loops_per_jiffy;
420 #ifdef CONFIG_IA32_SUPPORT
421 ia32_gdt_init();
422 #endif
424 /*
425 * Allow the master to continue.
426 */
427 cpu_set(cpuid, cpu_callin_map);
428 Dprintk("Stack on CPU %d at about %p\n",cpuid, &cpuid);
429 }
432 /*
433 * Activate a secondary processor. head.S calls this.
434 */
435 int __devinit
436 start_secondary (void *unused)
437 {
438 /* Early console may use I/O ports */
439 ia64_set_kr(IA64_KR_IO_BASE, __pa(ia64_iobase));
440 Dprintk("start_secondary: starting CPU 0x%x\n", hard_smp_processor_id());
441 efi_map_pal_code();
442 cpu_init();
443 smp_callin();
445 #ifdef XEN
446 if (vmx_enabled)
447 vmx_init_env(0, 0);
449 startup_cpu_idle_loop();
450 #else
451 cpu_idle();
452 #endif
453 return 0;
454 }
456 struct pt_regs * __devinit idle_regs(struct pt_regs *regs)
457 {
458 return NULL;
459 }
461 #ifndef XEN
462 struct create_idle {
463 struct task_struct *idle;
464 struct completion done;
465 int cpu;
466 };
468 void
469 do_fork_idle(void *_c_idle)
470 {
471 struct create_idle *c_idle = _c_idle;
473 c_idle->idle = fork_idle(c_idle->cpu);
474 complete(&c_idle->done);
475 }
476 #endif
478 static int __devinit
479 do_boot_cpu (int sapicid, int cpu)
480 {
481 int timeout;
482 #ifndef XEN
483 struct create_idle c_idle = {
484 .cpu = cpu,
485 .done = COMPLETION_INITIALIZER(c_idle.done),
486 };
487 DECLARE_WORK(work, do_fork_idle, &c_idle);
489 c_idle.idle = get_idle_for_cpu(cpu);
490 if (c_idle.idle) {
491 init_idle(c_idle.idle, cpu);
492 goto do_rest;
493 }
495 /*
496 * We can't use kernel_thread since we must avoid to reschedule the child.
497 */
498 if (!keventd_up() || current_is_keventd())
499 work.func(work.data);
500 else {
501 schedule_work(&work);
502 wait_for_completion(&c_idle.done);
503 }
505 if (IS_ERR(c_idle.idle))
506 panic("failed fork for CPU %d", cpu);
508 set_idle_for_cpu(cpu, c_idle.idle);
510 do_rest:
511 task_for_booting_cpu = c_idle.idle;
512 #else
513 struct vcpu *v;
515 v = alloc_idle_vcpu(cpu);
516 BUG_ON(v == NULL);
518 //printf ("do_boot_cpu: cpu=%d, domain=%p, vcpu=%p\n", cpu, idle, v);
520 task_for_booting_cpu = (task_t *)v;
522 /* Set cpu number. */
523 get_thread_info(v)->cpu = cpu;
524 #endif
526 Dprintk("Sending wakeup vector %lu to AP 0x%x/0x%x.\n", ap_wakeup_vector, cpu, sapicid);
528 set_brendez_area(cpu);
529 platform_send_ipi(cpu, ap_wakeup_vector, IA64_IPI_DM_INT, 0);
531 /*
532 * Wait 10s total for the AP to start
533 */
534 Dprintk("Waiting on callin_map ...");
535 for (timeout = 0; timeout < 100000; timeout++) {
536 if (cpu_isset(cpu, cpu_callin_map))
537 break; /* It has booted */
538 udelay(100);
539 }
540 Dprintk("\n");
542 if (!cpu_isset(cpu, cpu_callin_map)) {
543 printk(KERN_ERR "Processor 0x%x/0x%x is stuck.\n", cpu, sapicid);
544 ia64_cpu_to_sapicid[cpu] = -1;
545 cpu_clear(cpu, cpu_online_map); /* was set in smp_callin() */
546 return -EINVAL;
547 }
548 return 0;
549 }
551 #ifndef XEN
552 static int __init
553 decay (char *str)
554 {
555 int ticks;
556 get_option (&str, &ticks);
557 return 1;
558 }
560 __setup("decay=", decay);
561 #endif
563 /*
564 * Initialize the logical CPU number to SAPICID mapping
565 */
566 void __init
567 smp_build_cpu_map (void)
568 {
569 int sapicid, cpu, i;
570 int boot_cpu_id = hard_smp_processor_id();
572 for (cpu = 0; cpu < NR_CPUS; cpu++) {
573 ia64_cpu_to_sapicid[cpu] = -1;
574 #ifndef XEN
575 #ifdef CONFIG_HOTPLUG_CPU
576 cpu_set(cpu, cpu_possible_map);
577 #endif
578 #endif
579 }
581 ia64_cpu_to_sapicid[0] = boot_cpu_id;
582 cpus_clear(cpu_present_map);
583 cpu_set(0, cpu_present_map);
584 cpu_set(0, cpu_possible_map);
585 for (cpu = 1, i = 0; i < smp_boot_data.cpu_count; i++) {
586 sapicid = smp_boot_data.cpu_phys_id[i];
587 if (sapicid == boot_cpu_id)
588 continue;
589 cpu_set(cpu, cpu_present_map);
590 cpu_set(cpu, cpu_possible_map);
591 ia64_cpu_to_sapicid[cpu] = sapicid;
592 cpu++;
593 }
594 }
596 /*
597 * Cycle through the APs sending Wakeup IPIs to boot each.
598 */
599 void __init
600 smp_prepare_cpus (unsigned int max_cpus)
601 {
602 int boot_cpu_id = hard_smp_processor_id();
604 /*
605 * Initialize the per-CPU profiling counter/multiplier
606 */
608 smp_setup_percpu_timer();
610 /*
611 * We have the boot CPU online for sure.
612 */
613 cpu_set(0, cpu_online_map);
614 cpu_set(0, cpu_callin_map);
616 local_cpu_data->loops_per_jiffy = loops_per_jiffy;
617 ia64_cpu_to_sapicid[0] = boot_cpu_id;
619 printk(KERN_INFO "Boot processor id 0x%x/0x%x\n", 0, boot_cpu_id);
621 current_thread_info()->cpu = 0;
623 /*
624 * If SMP should be disabled, then really disable it!
625 */
626 if (!max_cpus) {
627 printk(KERN_INFO "SMP mode deactivated.\n");
628 cpus_clear(cpu_online_map);
629 cpus_clear(cpu_present_map);
630 cpus_clear(cpu_possible_map);
631 cpu_set(0, cpu_online_map);
632 cpu_set(0, cpu_present_map);
633 cpu_set(0, cpu_possible_map);
634 return;
635 }
636 }
638 void __devinit smp_prepare_boot_cpu(void)
639 {
640 cpu_set(smp_processor_id(), cpu_online_map);
641 cpu_set(smp_processor_id(), cpu_callin_map);
642 per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
643 }
645 /*
646 * mt_info[] is a temporary store for all info returned by
647 * PAL_LOGICAL_TO_PHYSICAL, to be copied into cpuinfo_ia64 when the
648 * specific cpu comes.
649 */
650 static struct {
651 __u32 socket_id;
652 __u16 core_id;
653 __u16 thread_id;
654 __u16 proc_fixed_addr;
655 __u8 valid;
656 } mt_info[NR_CPUS] __devinitdata;
658 #if defined(XEN) && !defined(CONFIG_HOTPLUG_CPU)
659 static inline void
660 remove_from_mtinfo(int cpu)
661 {
662 int i;
664 for_each_cpu(i)
665 if (mt_info[i].valid && mt_info[i].socket_id ==
666 cpu_data(cpu)->socket_id)
667 mt_info[i].valid = 0;
668 }
670 static inline void
671 clear_cpu_sibling_map(int cpu)
672 {
673 int i;
675 for_each_cpu_mask(i, cpu_sibling_map[cpu])
676 cpu_clear(cpu, cpu_sibling_map[i]);
677 for_each_cpu_mask(i, cpu_core_map[cpu])
678 cpu_clear(cpu, cpu_core_map[i]);
680 cpus_clear(cpu_sibling_map[cpu]);
681 cpus_clear(cpu_core_map[cpu]);
682 }
684 static void
685 remove_siblinginfo(int cpu)
686 {
687 int last = 0;
689 if (cpu_data(cpu)->threads_per_core == 1 &&
690 cpu_data(cpu)->cores_per_socket == 1) {
691 cpu_clear(cpu, cpu_core_map[cpu]);
692 cpu_clear(cpu, cpu_sibling_map[cpu]);
693 return;
694 }
696 last = (cpus_weight(cpu_core_map[cpu]) == 1 ? 1 : 0);
698 /* remove it from all sibling map's */
699 clear_cpu_sibling_map(cpu);
701 /* if this cpu is the last in the core group, remove all its info
702 * from mt_info structure
703 */
704 if (last)
705 remove_from_mtinfo(cpu);
706 }
708 extern void fixup_irqs(void);
709 /* must be called with cpucontrol mutex held */
710 int __cpu_disable(void)
711 {
712 int cpu = smp_processor_id();
714 /*
715 * dont permit boot processor for now
716 */
717 if (cpu == 0)
718 return -EBUSY;
720 remove_siblinginfo(cpu);
721 cpu_clear(cpu, cpu_online_map);
722 #ifndef XEN
723 fixup_irqs();
724 #endif
725 local_flush_tlb_all();
726 cpu_clear(cpu, cpu_callin_map);
727 return 0;
728 }
729 #else /* !CONFIG_HOTPLUG_CPU */
730 int __cpu_disable(void)
731 {
732 return -ENOSYS;
733 }
734 #endif /* CONFIG_HOTPLUG_CPU */
736 #ifdef CONFIG_HOTPLUG_CPU
737 void __cpu_die(unsigned int cpu)
738 {
739 unsigned int i;
741 for (i = 0; i < 100; i++) {
742 /* They ack this in play_dead by setting CPU_DEAD */
743 if (per_cpu(cpu_state, cpu) == CPU_DEAD)
744 {
745 printk ("CPU %d is now offline\n", cpu);
746 return;
747 }
748 #ifdef XEN
749 /* XXX: There must be a better way to sleep */
750 for (int j = 0; j < 1000000; j++)
751 cpu_relax();
752 #else
753 msleep(100);
754 #endif
755 }
756 printk(KERN_ERR "CPU %u didn't die...\n", cpu);
757 }
758 #else /* !CONFIG_HOTPLUG_CPU */
759 void __cpu_die(unsigned int cpu)
760 {
761 /* We said "no" in __cpu_disable */
762 BUG();
763 }
764 #endif /* CONFIG_HOTPLUG_CPU */
766 void
767 smp_cpus_done (unsigned int dummy)
768 {
769 int cpu;
770 unsigned long bogosum = 0;
772 /*
773 * Allow the user to impress friends.
774 */
776 for (cpu = 0; cpu < NR_CPUS; cpu++)
777 if (cpu_online(cpu))
778 bogosum += cpu_data(cpu)->loops_per_jiffy;
780 printk(KERN_INFO "Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
781 (int)num_online_cpus(), bogosum/(500000/HZ), (bogosum/(5000/HZ))%100);
782 }
784 static inline void __devinit
785 set_cpu_sibling_map(int cpu)
786 {
787 int i;
789 for_each_online_cpu(i) {
790 if ((cpu_data(cpu)->socket_id == cpu_data(i)->socket_id)) {
791 cpu_set(i, cpu_core_map[cpu]);
792 cpu_set(cpu, cpu_core_map[i]);
793 if (cpu_data(cpu)->core_id == cpu_data(i)->core_id) {
794 cpu_set(i, cpu_sibling_map[cpu]);
795 cpu_set(cpu, cpu_sibling_map[i]);
796 }
797 }
798 }
799 }
801 int __devinit
802 __cpu_up (unsigned int cpu)
803 {
804 int ret;
805 int sapicid;
807 sapicid = ia64_cpu_to_sapicid[cpu];
808 if (sapicid == -1)
809 return -EINVAL;
811 /*
812 * Already booted cpu? not valid anymore since we dont
813 * do idle loop tightspin anymore.
814 */
815 if (cpu_isset(cpu, cpu_callin_map))
816 return -EINVAL;
818 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
819 /* Processor goes to start_secondary(), sets online flag */
820 ret = do_boot_cpu(sapicid, cpu);
821 if (ret < 0)
822 return ret;
824 if (cpu_data(cpu)->threads_per_core == 1 &&
825 cpu_data(cpu)->cores_per_socket == 1) {
826 cpu_set(cpu, cpu_sibling_map[cpu]);
827 cpu_set(cpu, cpu_core_map[cpu]);
828 return 0;
829 }
831 set_cpu_sibling_map(cpu);
833 return 0;
834 }
836 /*
837 * Assume that CPU's have been discovered by some platform-dependent interface. For
838 * SoftSDV/Lion, that would be ACPI.
839 *
840 * Setup of the IPI irq handler is done in irq.c:init_IRQ_SMP().
841 */
842 void __init
843 init_smp_config(void)
844 {
845 struct fptr {
846 unsigned long fp;
847 unsigned long gp;
848 } *ap_startup;
849 long sal_ret;
851 /* Tell SAL where to drop the AP's. */
852 ap_startup = (struct fptr *) start_ap;
853 sal_ret = ia64_sal_set_vectors(SAL_VECTOR_OS_BOOT_RENDEZ,
854 ia64_tpa(ap_startup->fp), ia64_tpa(ap_startup->gp), 0, 0, 0, 0);
855 if (sal_ret < 0)
856 printk(KERN_ERR "SMP: Can't set SAL AP Boot Rendezvous: %s\n",
857 ia64_sal_strerror(sal_ret));
858 }
860 static inline int __devinit
861 check_for_mtinfo_index(void)
862 {
863 int i;
865 for_each_cpu(i)
866 if (!mt_info[i].valid)
867 return i;
869 return -1;
870 }
872 /*
873 * Search the mt_info to find out if this socket's cid/tid information is
874 * cached or not. If the socket exists, fill in the core_id and thread_id
875 * in cpuinfo
876 */
877 static int __devinit
878 check_for_new_socket(__u16 logical_address, struct cpuinfo_ia64 *c)
879 {
880 int i;
881 __u32 sid = c->socket_id;
883 for_each_cpu(i) {
884 if (mt_info[i].valid && mt_info[i].proc_fixed_addr == logical_address
885 && mt_info[i].socket_id == sid) {
886 c->core_id = mt_info[i].core_id;
887 c->thread_id = mt_info[i].thread_id;
888 return 1; /* not a new socket */
889 }
890 }
891 return 0;
892 }
894 /*
895 * identify_siblings(cpu) gets called from identify_cpu. This populates the
896 * information related to logical execution units in per_cpu_data structure.
897 */
898 void __devinit
899 identify_siblings(struct cpuinfo_ia64 *c)
900 {
901 s64 status;
902 u16 pltid;
903 u64 proc_fixed_addr;
904 int count, i;
905 pal_logical_to_physical_t info;
907 if (smp_num_cpucores == 1 && smp_num_siblings == 1)
908 return;
910 if ((status = ia64_pal_logical_to_phys(0, &info)) != PAL_STATUS_SUCCESS) {
911 printk(KERN_ERR "ia64_pal_logical_to_phys failed with %ld\n",
912 status);
913 return;
914 }
915 if ((status = ia64_sal_physical_id_info(&pltid)) != PAL_STATUS_SUCCESS) {
916 printk(KERN_ERR "ia64_sal_pltid failed with %ld\n", status);
917 return;
918 }
919 if ((status = ia64_pal_fixed_addr(&proc_fixed_addr)) != PAL_STATUS_SUCCESS) {
920 printk(KERN_ERR "ia64_pal_fixed_addr failed with %ld\n", status);
921 return;
922 }
924 c->socket_id = (pltid << 8) | info.overview_ppid;
925 c->cores_per_socket = info.overview_cpp;
926 c->threads_per_core = info.overview_tpc;
927 count = c->num_log = info.overview_num_log;
929 /* If the thread and core id information is already cached, then
930 * we will simply update cpu_info and return. Otherwise, we will
931 * do the PAL calls and cache core and thread id's of all the siblings.
932 */
933 if (check_for_new_socket(proc_fixed_addr, c))
934 return;
936 for (i = 0; i < count; i++) {
937 int index;
939 if (i && (status = ia64_pal_logical_to_phys(i, &info))
940 != PAL_STATUS_SUCCESS) {
941 printk(KERN_ERR "ia64_pal_logical_to_phys failed"
942 " with %ld\n", status);
943 return;
944 }
945 if (info.log2_la == proc_fixed_addr) {
946 c->core_id = info.log1_cid;
947 c->thread_id = info.log1_tid;
948 }
950 index = check_for_mtinfo_index();
951 /* We will not do the mt_info caching optimization in this case.
952 */
953 if (index < 0)
954 continue;
956 mt_info[index].valid = 1;
957 mt_info[index].socket_id = c->socket_id;
958 mt_info[index].core_id = info.log1_cid;
959 mt_info[index].thread_id = info.log1_tid;
960 mt_info[index].proc_fixed_addr = info.log2_la;
961 }
962 }
963 #endif /* CONFIG_SMP ifdef XEN */