ia64/xen-unstable

view xen/arch/ia64/linux-xen/smpboot.c @ 18136:bfddf170cef9

[IA64] improve __cpu_die()

use udelay instead of nop loop.
This patch reduces __cpu_die() time much.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Mon Jul 28 17:29:09 2008 +0900 (2008-07-28)
parents 7da7b53b2139
children 57c94bdbd6b3
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 #ifndef XEN
442 efi_map_pal_code();
443 #endif
444 cpu_init();
445 smp_callin();
447 #ifdef XEN
448 if (vmx_enabled)
449 vmx_init_env(0, 0);
451 startup_cpu_idle_loop();
452 #else
453 cpu_idle();
454 #endif
455 return 0;
456 }
458 struct pt_regs * __devinit idle_regs(struct pt_regs *regs)
459 {
460 return NULL;
461 }
463 #ifndef XEN
464 struct create_idle {
465 struct task_struct *idle;
466 struct completion done;
467 int cpu;
468 };
470 void
471 do_fork_idle(void *_c_idle)
472 {
473 struct create_idle *c_idle = _c_idle;
475 c_idle->idle = fork_idle(c_idle->cpu);
476 complete(&c_idle->done);
477 }
478 #endif
480 static int __devinit
481 do_boot_cpu (int sapicid, int cpu)
482 {
483 int timeout;
484 #ifndef XEN
485 struct create_idle c_idle = {
486 .cpu = cpu,
487 .done = COMPLETION_INITIALIZER(c_idle.done),
488 };
489 DECLARE_WORK(work, do_fork_idle, &c_idle);
491 c_idle.idle = get_idle_for_cpu(cpu);
492 if (c_idle.idle) {
493 init_idle(c_idle.idle, cpu);
494 goto do_rest;
495 }
497 /*
498 * We can't use kernel_thread since we must avoid to reschedule the child.
499 */
500 if (!keventd_up() || current_is_keventd())
501 work.func(work.data);
502 else {
503 schedule_work(&work);
504 wait_for_completion(&c_idle.done);
505 }
507 if (IS_ERR(c_idle.idle))
508 panic("failed fork for CPU %d", cpu);
510 set_idle_for_cpu(cpu, c_idle.idle);
512 do_rest:
513 task_for_booting_cpu = c_idle.idle;
514 #else
515 struct vcpu *v;
517 v = alloc_idle_vcpu(cpu);
518 BUG_ON(v == NULL);
520 //printf ("do_boot_cpu: cpu=%d, domain=%p, vcpu=%p\n", cpu, idle, v);
522 task_for_booting_cpu = (task_t *)v;
524 /* Set cpu number. */
525 get_thread_info(v)->cpu = cpu;
526 #endif
528 Dprintk("Sending wakeup vector %lu to AP 0x%x/0x%x.\n", ap_wakeup_vector, cpu, sapicid);
530 set_brendez_area(cpu);
531 platform_send_ipi(cpu, ap_wakeup_vector, IA64_IPI_DM_INT, 0);
533 /*
534 * Wait 10s total for the AP to start
535 */
536 Dprintk("Waiting on callin_map ...");
537 for (timeout = 0; timeout < 100000; timeout++) {
538 if (cpu_isset(cpu, cpu_callin_map))
539 break; /* It has booted */
540 udelay(100);
541 }
542 Dprintk("\n");
544 if (!cpu_isset(cpu, cpu_callin_map)) {
545 printk(KERN_ERR "Processor 0x%x/0x%x is stuck.\n", cpu, sapicid);
546 ia64_cpu_to_sapicid[cpu] = -1;
547 cpu_clear(cpu, cpu_online_map); /* was set in smp_callin() */
548 return -EINVAL;
549 }
550 return 0;
551 }
553 #ifndef XEN
554 static int __init
555 decay (char *str)
556 {
557 int ticks;
558 get_option (&str, &ticks);
559 return 1;
560 }
562 __setup("decay=", decay);
563 #endif
565 /*
566 * Initialize the logical CPU number to SAPICID mapping
567 */
568 void __init
569 smp_build_cpu_map (void)
570 {
571 int sapicid, cpu, i;
572 int boot_cpu_id = hard_smp_processor_id();
574 for (cpu = 0; cpu < NR_CPUS; cpu++) {
575 ia64_cpu_to_sapicid[cpu] = -1;
576 #ifndef XEN
577 #ifdef CONFIG_HOTPLUG_CPU
578 cpu_set(cpu, cpu_possible_map);
579 #endif
580 #endif
581 }
583 ia64_cpu_to_sapicid[0] = boot_cpu_id;
584 cpus_clear(cpu_present_map);
585 cpu_set(0, cpu_present_map);
586 cpu_set(0, cpu_possible_map);
587 for (cpu = 1, i = 0; i < smp_boot_data.cpu_count; i++) {
588 sapicid = smp_boot_data.cpu_phys_id[i];
589 if (sapicid == boot_cpu_id)
590 continue;
591 cpu_set(cpu, cpu_present_map);
592 cpu_set(cpu, cpu_possible_map);
593 ia64_cpu_to_sapicid[cpu] = sapicid;
594 cpu++;
595 }
596 }
598 /*
599 * Cycle through the APs sending Wakeup IPIs to boot each.
600 */
601 void __init
602 smp_prepare_cpus (unsigned int max_cpus)
603 {
604 int boot_cpu_id = hard_smp_processor_id();
606 /*
607 * Initialize the per-CPU profiling counter/multiplier
608 */
610 smp_setup_percpu_timer();
612 /*
613 * We have the boot CPU online for sure.
614 */
615 cpu_set(0, cpu_online_map);
616 cpu_set(0, cpu_callin_map);
618 local_cpu_data->loops_per_jiffy = loops_per_jiffy;
619 ia64_cpu_to_sapicid[0] = boot_cpu_id;
621 printk(KERN_INFO "Boot processor id 0x%x/0x%x\n", 0, boot_cpu_id);
623 current_thread_info()->cpu = 0;
625 /*
626 * If SMP should be disabled, then really disable it!
627 */
628 if (!max_cpus) {
629 printk(KERN_INFO "SMP mode deactivated.\n");
630 cpus_clear(cpu_online_map);
631 cpus_clear(cpu_present_map);
632 cpus_clear(cpu_possible_map);
633 cpu_set(0, cpu_online_map);
634 cpu_set(0, cpu_present_map);
635 cpu_set(0, cpu_possible_map);
636 return;
637 }
638 }
640 void __devinit smp_prepare_boot_cpu(void)
641 {
642 cpu_set(smp_processor_id(), cpu_online_map);
643 cpu_set(smp_processor_id(), cpu_callin_map);
644 per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
645 }
647 /*
648 * mt_info[] is a temporary store for all info returned by
649 * PAL_LOGICAL_TO_PHYSICAL, to be copied into cpuinfo_ia64 when the
650 * specific cpu comes.
651 */
652 static struct {
653 __u32 socket_id;
654 __u16 core_id;
655 __u16 thread_id;
656 __u16 proc_fixed_addr;
657 __u8 valid;
658 } mt_info[NR_CPUS] __devinitdata;
660 #if defined(XEN) && !defined(CONFIG_HOTPLUG_CPU)
661 static inline void
662 remove_from_mtinfo(int cpu)
663 {
664 int i;
666 for_each_cpu(i)
667 if (mt_info[i].valid && mt_info[i].socket_id ==
668 cpu_data(cpu)->socket_id)
669 mt_info[i].valid = 0;
670 }
672 static inline void
673 clear_cpu_sibling_map(int cpu)
674 {
675 int i;
677 for_each_cpu_mask(i, cpu_sibling_map[cpu])
678 cpu_clear(cpu, cpu_sibling_map[i]);
679 for_each_cpu_mask(i, cpu_core_map[cpu])
680 cpu_clear(cpu, cpu_core_map[i]);
682 cpus_clear(cpu_sibling_map[cpu]);
683 cpus_clear(cpu_core_map[cpu]);
684 }
686 static void
687 remove_siblinginfo(int cpu)
688 {
689 int last = 0;
691 if (cpu_data(cpu)->threads_per_core == 1 &&
692 cpu_data(cpu)->cores_per_socket == 1) {
693 cpu_clear(cpu, cpu_core_map[cpu]);
694 cpu_clear(cpu, cpu_sibling_map[cpu]);
695 return;
696 }
698 last = (cpus_weight(cpu_core_map[cpu]) == 1 ? 1 : 0);
700 /* remove it from all sibling map's */
701 clear_cpu_sibling_map(cpu);
703 /* if this cpu is the last in the core group, remove all its info
704 * from mt_info structure
705 */
706 if (last)
707 remove_from_mtinfo(cpu);
708 }
710 extern void fixup_irqs(void);
711 /* must be called with cpucontrol mutex held */
712 int __cpu_disable(void)
713 {
714 int cpu = smp_processor_id();
716 /*
717 * dont permit boot processor for now
718 */
719 if (cpu == 0)
720 return -EBUSY;
722 remove_siblinginfo(cpu);
723 cpu_clear(cpu, cpu_online_map);
724 #ifndef XEN
725 fixup_irqs();
726 #endif
727 local_flush_tlb_all();
728 cpu_clear(cpu, cpu_callin_map);
729 return 0;
730 }
731 #else /* !CONFIG_HOTPLUG_CPU */
732 int __cpu_disable(void)
733 {
734 return -ENOSYS;
735 }
736 #endif /* CONFIG_HOTPLUG_CPU */
738 #ifdef CONFIG_HOTPLUG_CPU
739 void __cpu_die(unsigned int cpu)
740 {
741 unsigned int i;
743 for (i = 0; i < 100; i++) {
744 /* They ack this in play_dead by setting CPU_DEAD */
745 if (per_cpu(cpu_state, cpu) == CPU_DEAD)
746 {
747 printk ("CPU %d is now offline\n", cpu);
748 return;
749 }
750 #ifdef XEN
751 udelay(100 * 1000);
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 */