ia64/xen-unstable

view xen/arch/ia64/linux-xen/smpboot.c @ 10293:4122e88b6c75

Move idle-vcpu allocation logic to a common function.
Signed-off-by: Kevin Tian <kevin.tian@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Jun 02 09:31:35 2006 +0100 (2006-06-02)
parents bd16e299db3d
children 75f791c710df
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 int ht_per_core = 1;
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 void
177 sync_master (void *arg)
178 {
179 unsigned long flags, i;
181 go[MASTER] = 0;
183 local_irq_save(flags);
184 {
185 for (i = 0; i < NUM_ROUNDS*NUM_ITERS; ++i) {
186 while (!go[MASTER])
187 cpu_relax();
188 go[MASTER] = 0;
189 go[SLAVE] = ia64_get_itc();
190 }
191 }
192 local_irq_restore(flags);
193 }
195 /*
196 * Return the number of cycles by which our itc differs from the itc on the master
197 * (time-keeper) CPU. A positive number indicates our itc is ahead of the master,
198 * negative that it is behind.
199 */
200 static inline long
201 #ifdef XEN /* warning cleanup */
202 get_delta (unsigned long *rt, unsigned long *master)
203 #else
204 get_delta (long *rt, long *master)
205 #endif
206 {
207 unsigned long best_t0 = 0, best_t1 = ~0UL, best_tm = 0;
208 unsigned long tcenter, t0, t1, tm;
209 long i;
211 for (i = 0; i < NUM_ITERS; ++i) {
212 t0 = ia64_get_itc();
213 go[MASTER] = 1;
214 while (!(tm = go[SLAVE]))
215 cpu_relax();
216 go[SLAVE] = 0;
217 t1 = ia64_get_itc();
219 if (t1 - t0 < best_t1 - best_t0)
220 best_t0 = t0, best_t1 = t1, best_tm = tm;
221 }
223 *rt = best_t1 - best_t0;
224 *master = best_tm - best_t0;
226 /* average best_t0 and best_t1 without overflow: */
227 tcenter = (best_t0/2 + best_t1/2);
228 if (best_t0 % 2 + best_t1 % 2 == 2)
229 ++tcenter;
230 return tcenter - best_tm;
231 }
233 /*
234 * Synchronize ar.itc of the current (slave) CPU with the ar.itc of the MASTER CPU
235 * (normally the time-keeper CPU). We use a closed loop to eliminate the possibility of
236 * unaccounted-for errors (such as getting a machine check in the middle of a calibration
237 * step). The basic idea is for the slave to ask the master what itc value it has and to
238 * read its own itc before and after the master responds. Each iteration gives us three
239 * timestamps:
240 *
241 * slave master
242 *
243 * t0 ---\
244 * ---\
245 * --->
246 * tm
247 * /---
248 * /---
249 * t1 <---
250 *
251 *
252 * The goal is to adjust the slave's ar.itc such that tm falls exactly half-way between t0
253 * and t1. If we achieve this, the clocks are synchronized provided the interconnect
254 * between the slave and the master is symmetric. Even if the interconnect were
255 * asymmetric, we would still know that the synchronization error is smaller than the
256 * roundtrip latency (t0 - t1).
257 *
258 * When the interconnect is quiet and symmetric, this lets us synchronize the itc to
259 * within one or two cycles. However, we can only *guarantee* that the synchronization is
260 * accurate to within a round-trip time, which is typically in the range of several
261 * hundred cycles (e.g., ~500 cycles). In practice, this means that the itc's are usually
262 * almost perfectly synchronized, but we shouldn't assume that the accuracy is much better
263 * than half a micro second or so.
264 */
265 void
266 ia64_sync_itc (unsigned int master)
267 {
268 long i, delta, adj, adjust_latency = 0, done = 0;
269 unsigned long flags, rt, master_time_stamp, bound;
270 #if DEBUG_ITC_SYNC
271 struct {
272 long rt; /* roundtrip time */
273 long master; /* master's timestamp */
274 long diff; /* difference between midpoint and master's timestamp */
275 long lat; /* estimate of itc adjustment latency */
276 } t[NUM_ROUNDS];
277 #endif
279 /*
280 * Make sure local timer ticks are disabled while we sync. If
281 * they were enabled, we'd have to worry about nasty issues
282 * like setting the ITC ahead of (or a long time before) the
283 * next scheduled tick.
284 */
285 BUG_ON((ia64_get_itv() & (1 << 16)) == 0);
287 go[MASTER] = 1;
289 if (smp_call_function_single(master, sync_master, NULL, 1, 0) < 0) {
290 printk(KERN_ERR "sync_itc: failed to get attention of CPU %u!\n", master);
291 return;
292 }
294 while (go[MASTER])
295 cpu_relax(); /* wait for master to be ready */
297 spin_lock_irqsave(&itc_sync_lock, flags);
298 {
299 for (i = 0; i < NUM_ROUNDS; ++i) {
300 delta = get_delta(&rt, &master_time_stamp);
301 if (delta == 0) {
302 done = 1; /* let's lock on to this... */
303 bound = rt;
304 }
306 if (!done) {
307 if (i > 0) {
308 adjust_latency += -delta;
309 adj = -delta + adjust_latency/4;
310 } else
311 adj = -delta;
313 ia64_set_itc(ia64_get_itc() + adj);
314 }
315 #if DEBUG_ITC_SYNC
316 t[i].rt = rt;
317 t[i].master = master_time_stamp;
318 t[i].diff = delta;
319 t[i].lat = adjust_latency/4;
320 #endif
321 }
322 }
323 spin_unlock_irqrestore(&itc_sync_lock, flags);
325 #if DEBUG_ITC_SYNC
326 for (i = 0; i < NUM_ROUNDS; ++i)
327 printk("rt=%5ld master=%5ld diff=%5ld adjlat=%5ld\n",
328 t[i].rt, t[i].master, t[i].diff, t[i].lat);
329 #endif
331 printk(KERN_INFO "CPU %d: synchronized ITC with CPU %u (last diff %ld cycles, "
332 "maxerr %lu cycles)\n", smp_processor_id(), master, delta, rt);
333 }
335 /*
336 * Ideally sets up per-cpu profiling hooks. Doesn't do much now...
337 */
338 static inline void __devinit
339 smp_setup_percpu_timer (void)
340 {
341 }
343 static void __devinit
344 smp_callin (void)
345 {
346 int cpuid, phys_id;
347 extern void ia64_init_itm(void);
349 #ifdef CONFIG_PERFMON
350 extern void pfm_init_percpu(void);
351 #endif
353 cpuid = smp_processor_id();
354 phys_id = hard_smp_processor_id();
356 if (cpu_online(cpuid)) {
357 printk(KERN_ERR "huh, phys CPU#0x%x, CPU#0x%x already present??\n",
358 phys_id, cpuid);
359 BUG();
360 }
362 lock_ipi_calllock();
363 cpu_set(cpuid, cpu_online_map);
364 unlock_ipi_calllock();
365 per_cpu(cpu_state, cpuid) = CPU_ONLINE;
367 smp_setup_percpu_timer();
369 #ifndef XEN
370 ia64_mca_cmc_vector_setup(); /* Setup vector on AP */
371 #endif
373 #ifdef CONFIG_PERFMON
374 pfm_init_percpu();
375 #endif
377 local_irq_enable();
379 if (!(sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)) {
380 /*
381 * Synchronize the ITC with the BP. Need to do this after irqs are
382 * enabled because ia64_sync_itc() calls smp_call_function_single(), which
383 * calls spin_unlock_bh(), which calls spin_unlock_bh(), which calls
384 * local_bh_enable(), which bugs out if irqs are not enabled...
385 */
386 Dprintk("Going to syncup ITC with BP.\n");
387 ia64_sync_itc(0);
388 }
390 /*
391 * Get our bogomips.
392 */
393 ia64_init_itm();
394 #ifndef XEN
395 calibrate_delay();
396 #endif
397 local_cpu_data->loops_per_jiffy = loops_per_jiffy;
399 #ifdef CONFIG_IA32_SUPPORT
400 ia32_gdt_init();
401 #endif
403 /*
404 * Allow the master to continue.
405 */
406 cpu_set(cpuid, cpu_callin_map);
407 Dprintk("Stack on CPU %d at about %p\n",cpuid, &cpuid);
408 }
411 /*
412 * Activate a secondary processor. head.S calls this.
413 */
414 int __devinit
415 start_secondary (void *unused)
416 {
417 /* Early console may use I/O ports */
418 ia64_set_kr(IA64_KR_IO_BASE, __pa(ia64_iobase));
419 Dprintk("start_secondary: starting CPU 0x%x\n", hard_smp_processor_id());
420 efi_map_pal_code();
421 cpu_init();
422 smp_callin();
424 #ifdef XEN
425 startup_cpu_idle_loop();
426 #else
427 cpu_idle();
428 #endif
429 return 0;
430 }
432 struct pt_regs * __devinit idle_regs(struct pt_regs *regs)
433 {
434 return NULL;
435 }
437 #ifndef XEN
438 struct create_idle {
439 struct task_struct *idle;
440 struct completion done;
441 int cpu;
442 };
444 void
445 do_fork_idle(void *_c_idle)
446 {
447 struct create_idle *c_idle = _c_idle;
449 c_idle->idle = fork_idle(c_idle->cpu);
450 complete(&c_idle->done);
451 }
452 #endif
454 static int __devinit
455 do_boot_cpu (int sapicid, int cpu)
456 {
457 int timeout;
458 #ifndef XEN
459 struct create_idle c_idle = {
460 .cpu = cpu,
461 .done = COMPLETION_INITIALIZER(c_idle.done),
462 };
463 DECLARE_WORK(work, do_fork_idle, &c_idle);
465 c_idle.idle = get_idle_for_cpu(cpu);
466 if (c_idle.idle) {
467 init_idle(c_idle.idle, cpu);
468 goto do_rest;
469 }
471 /*
472 * We can't use kernel_thread since we must avoid to reschedule the child.
473 */
474 if (!keventd_up() || current_is_keventd())
475 work.func(work.data);
476 else {
477 schedule_work(&work);
478 wait_for_completion(&c_idle.done);
479 }
481 if (IS_ERR(c_idle.idle))
482 panic("failed fork for CPU %d", cpu);
484 set_idle_for_cpu(cpu, c_idle.idle);
486 do_rest:
487 task_for_booting_cpu = c_idle.idle;
488 #else
489 struct vcpu *v;
491 v = alloc_idle_vcpu(cpu);
492 BUG_ON(v == NULL);
494 //printf ("do_boot_cpu: cpu=%d, domain=%p, vcpu=%p\n", cpu, idle, v);
496 task_for_booting_cpu = (task_t *)v;
498 /* Set cpu number. */
499 get_thread_info(v)->cpu = cpu;
500 #endif
502 Dprintk("Sending wakeup vector %lu to AP 0x%x/0x%x.\n", ap_wakeup_vector, cpu, sapicid);
504 set_brendez_area(cpu);
505 platform_send_ipi(cpu, ap_wakeup_vector, IA64_IPI_DM_INT, 0);
507 /*
508 * Wait 10s total for the AP to start
509 */
510 Dprintk("Waiting on callin_map ...");
511 for (timeout = 0; timeout < 100000; timeout++) {
512 if (cpu_isset(cpu, cpu_callin_map))
513 break; /* It has booted */
514 udelay(100);
515 }
516 Dprintk("\n");
518 if (!cpu_isset(cpu, cpu_callin_map)) {
519 printk(KERN_ERR "Processor 0x%x/0x%x is stuck.\n", cpu, sapicid);
520 ia64_cpu_to_sapicid[cpu] = -1;
521 cpu_clear(cpu, cpu_online_map); /* was set in smp_callin() */
522 return -EINVAL;
523 }
524 return 0;
525 }
527 #ifndef XEN
528 static int __init
529 decay (char *str)
530 {
531 int ticks;
532 get_option (&str, &ticks);
533 return 1;
534 }
536 __setup("decay=", decay);
537 #endif
539 /*
540 * Initialize the logical CPU number to SAPICID mapping
541 */
542 void __init
543 smp_build_cpu_map (void)
544 {
545 int sapicid, cpu, i;
546 int boot_cpu_id = hard_smp_processor_id();
548 for (cpu = 0; cpu < NR_CPUS; cpu++) {
549 ia64_cpu_to_sapicid[cpu] = -1;
550 #ifdef CONFIG_HOTPLUG_CPU
551 cpu_set(cpu, cpu_possible_map);
552 #endif
553 }
555 ia64_cpu_to_sapicid[0] = boot_cpu_id;
556 cpus_clear(cpu_present_map);
557 cpu_set(0, cpu_present_map);
558 cpu_set(0, cpu_possible_map);
559 for (cpu = 1, i = 0; i < smp_boot_data.cpu_count; i++) {
560 sapicid = smp_boot_data.cpu_phys_id[i];
561 if (sapicid == boot_cpu_id)
562 continue;
563 cpu_set(cpu, cpu_present_map);
564 cpu_set(cpu, cpu_possible_map);
565 ia64_cpu_to_sapicid[cpu] = sapicid;
566 cpu++;
567 }
568 }
570 /*
571 * Cycle through the APs sending Wakeup IPIs to boot each.
572 */
573 void __init
574 smp_prepare_cpus (unsigned int max_cpus)
575 {
576 int boot_cpu_id = hard_smp_processor_id();
578 /*
579 * Initialize the per-CPU profiling counter/multiplier
580 */
582 smp_setup_percpu_timer();
584 /*
585 * We have the boot CPU online for sure.
586 */
587 cpu_set(0, cpu_online_map);
588 cpu_set(0, cpu_callin_map);
590 local_cpu_data->loops_per_jiffy = loops_per_jiffy;
591 ia64_cpu_to_sapicid[0] = boot_cpu_id;
593 printk(KERN_INFO "Boot processor id 0x%x/0x%x\n", 0, boot_cpu_id);
595 current_thread_info()->cpu = 0;
597 /*
598 * If SMP should be disabled, then really disable it!
599 */
600 if (!max_cpus) {
601 printk(KERN_INFO "SMP mode deactivated.\n");
602 cpus_clear(cpu_online_map);
603 cpus_clear(cpu_present_map);
604 cpus_clear(cpu_possible_map);
605 cpu_set(0, cpu_online_map);
606 cpu_set(0, cpu_present_map);
607 cpu_set(0, cpu_possible_map);
608 return;
609 }
610 }
612 void __devinit smp_prepare_boot_cpu(void)
613 {
614 cpu_set(smp_processor_id(), cpu_online_map);
615 cpu_set(smp_processor_id(), cpu_callin_map);
616 per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
617 }
619 /*
620 * mt_info[] is a temporary store for all info returned by
621 * PAL_LOGICAL_TO_PHYSICAL, to be copied into cpuinfo_ia64 when the
622 * specific cpu comes.
623 */
624 static struct {
625 __u32 socket_id;
626 __u16 core_id;
627 __u16 thread_id;
628 __u16 proc_fixed_addr;
629 __u8 valid;
630 } mt_info[NR_CPUS] __devinitdata;
632 #ifdef CONFIG_HOTPLUG_CPU
633 static inline void
634 remove_from_mtinfo(int cpu)
635 {
636 int i;
638 for_each_cpu(i)
639 if (mt_info[i].valid && mt_info[i].socket_id ==
640 cpu_data(cpu)->socket_id)
641 mt_info[i].valid = 0;
642 }
644 static inline void
645 clear_cpu_sibling_map(int cpu)
646 {
647 int i;
649 for_each_cpu_mask(i, cpu_sibling_map[cpu])
650 cpu_clear(cpu, cpu_sibling_map[i]);
651 for_each_cpu_mask(i, cpu_core_map[cpu])
652 cpu_clear(cpu, cpu_core_map[i]);
654 cpu_sibling_map[cpu] = cpu_core_map[cpu] = CPU_MASK_NONE;
655 }
657 static void
658 remove_siblinginfo(int cpu)
659 {
660 int last = 0;
662 if (cpu_data(cpu)->threads_per_core == 1 &&
663 cpu_data(cpu)->cores_per_socket == 1) {
664 cpu_clear(cpu, cpu_core_map[cpu]);
665 cpu_clear(cpu, cpu_sibling_map[cpu]);
666 return;
667 }
669 last = (cpus_weight(cpu_core_map[cpu]) == 1 ? 1 : 0);
671 /* remove it from all sibling map's */
672 clear_cpu_sibling_map(cpu);
674 /* if this cpu is the last in the core group, remove all its info
675 * from mt_info structure
676 */
677 if (last)
678 remove_from_mtinfo(cpu);
679 }
681 extern void fixup_irqs(void);
682 /* must be called with cpucontrol mutex held */
683 int __cpu_disable(void)
684 {
685 int cpu = smp_processor_id();
687 /*
688 * dont permit boot processor for now
689 */
690 if (cpu == 0)
691 return -EBUSY;
693 remove_siblinginfo(cpu);
694 cpu_clear(cpu, cpu_online_map);
695 fixup_irqs();
696 local_flush_tlb_all();
697 cpu_clear(cpu, cpu_callin_map);
698 return 0;
699 }
701 void __cpu_die(unsigned int cpu)
702 {
703 unsigned int i;
705 for (i = 0; i < 100; i++) {
706 /* They ack this in play_dead by setting CPU_DEAD */
707 if (per_cpu(cpu_state, cpu) == CPU_DEAD)
708 {
709 printk ("CPU %d is now offline\n", cpu);
710 return;
711 }
712 msleep(100);
713 }
714 printk(KERN_ERR "CPU %u didn't die...\n", cpu);
715 }
716 #else /* !CONFIG_HOTPLUG_CPU */
717 int __cpu_disable(void)
718 {
719 return -ENOSYS;
720 }
722 void __cpu_die(unsigned int cpu)
723 {
724 /* We said "no" in __cpu_disable */
725 BUG();
726 }
727 #endif /* CONFIG_HOTPLUG_CPU */
729 void
730 smp_cpus_done (unsigned int dummy)
731 {
732 int cpu;
733 unsigned long bogosum = 0;
735 /*
736 * Allow the user to impress friends.
737 */
739 for (cpu = 0; cpu < NR_CPUS; cpu++)
740 if (cpu_online(cpu))
741 bogosum += cpu_data(cpu)->loops_per_jiffy;
743 printk(KERN_INFO "Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
744 (int)num_online_cpus(), bogosum/(500000/HZ), (bogosum/(5000/HZ))%100);
745 }
747 static inline void __devinit
748 set_cpu_sibling_map(int cpu)
749 {
750 int i;
752 for_each_online_cpu(i) {
753 if ((cpu_data(cpu)->socket_id == cpu_data(i)->socket_id)) {
754 cpu_set(i, cpu_core_map[cpu]);
755 cpu_set(cpu, cpu_core_map[i]);
756 if (cpu_data(cpu)->core_id == cpu_data(i)->core_id) {
757 cpu_set(i, cpu_sibling_map[cpu]);
758 cpu_set(cpu, cpu_sibling_map[i]);
759 }
760 }
761 }
762 }
764 int __devinit
765 __cpu_up (unsigned int cpu)
766 {
767 int ret;
768 int sapicid;
770 sapicid = ia64_cpu_to_sapicid[cpu];
771 if (sapicid == -1)
772 return -EINVAL;
774 /*
775 * Already booted cpu? not valid anymore since we dont
776 * do idle loop tightspin anymore.
777 */
778 if (cpu_isset(cpu, cpu_callin_map))
779 return -EINVAL;
781 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
782 /* Processor goes to start_secondary(), sets online flag */
783 ret = do_boot_cpu(sapicid, cpu);
784 if (ret < 0)
785 return ret;
787 if (cpu_data(cpu)->threads_per_core == 1 &&
788 cpu_data(cpu)->cores_per_socket == 1) {
789 cpu_set(cpu, cpu_sibling_map[cpu]);
790 cpu_set(cpu, cpu_core_map[cpu]);
791 return 0;
792 }
794 set_cpu_sibling_map(cpu);
796 return 0;
797 }
799 /*
800 * Assume that CPU's have been discovered by some platform-dependent interface. For
801 * SoftSDV/Lion, that would be ACPI.
802 *
803 * Setup of the IPI irq handler is done in irq.c:init_IRQ_SMP().
804 */
805 void __init
806 init_smp_config(void)
807 {
808 struct fptr {
809 unsigned long fp;
810 unsigned long gp;
811 } *ap_startup;
812 long sal_ret;
814 /* Tell SAL where to drop the AP's. */
815 ap_startup = (struct fptr *) start_ap;
816 sal_ret = ia64_sal_set_vectors(SAL_VECTOR_OS_BOOT_RENDEZ,
817 ia64_tpa(ap_startup->fp), ia64_tpa(ap_startup->gp), 0, 0, 0, 0);
818 if (sal_ret < 0)
819 printk(KERN_ERR "SMP: Can't set SAL AP Boot Rendezvous: %s\n",
820 ia64_sal_strerror(sal_ret));
821 }
823 static inline int __devinit
824 check_for_mtinfo_index(void)
825 {
826 int i;
828 for_each_cpu(i)
829 if (!mt_info[i].valid)
830 return i;
832 return -1;
833 }
835 /*
836 * Search the mt_info to find out if this socket's cid/tid information is
837 * cached or not. If the socket exists, fill in the core_id and thread_id
838 * in cpuinfo
839 */
840 static int __devinit
841 check_for_new_socket(__u16 logical_address, struct cpuinfo_ia64 *c)
842 {
843 int i;
844 __u32 sid = c->socket_id;
846 for_each_cpu(i) {
847 if (mt_info[i].valid && mt_info[i].proc_fixed_addr == logical_address
848 && mt_info[i].socket_id == sid) {
849 c->core_id = mt_info[i].core_id;
850 c->thread_id = mt_info[i].thread_id;
851 return 1; /* not a new socket */
852 }
853 }
854 return 0;
855 }
857 /*
858 * identify_siblings(cpu) gets called from identify_cpu. This populates the
859 * information related to logical execution units in per_cpu_data structure.
860 */
861 void __devinit
862 identify_siblings(struct cpuinfo_ia64 *c)
863 {
864 s64 status;
865 u16 pltid;
866 u64 proc_fixed_addr;
867 int count, i;
868 pal_logical_to_physical_t info;
870 if (smp_num_cpucores == 1 && smp_num_siblings == 1)
871 return;
873 if ((status = ia64_pal_logical_to_phys(0, &info)) != PAL_STATUS_SUCCESS) {
874 printk(KERN_ERR "ia64_pal_logical_to_phys failed with %ld\n",
875 status);
876 return;
877 }
878 if ((status = ia64_sal_physical_id_info(&pltid)) != PAL_STATUS_SUCCESS) {
879 printk(KERN_ERR "ia64_sal_pltid failed with %ld\n", status);
880 return;
881 }
882 if ((status = ia64_pal_fixed_addr(&proc_fixed_addr)) != PAL_STATUS_SUCCESS) {
883 printk(KERN_ERR "ia64_pal_fixed_addr failed with %ld\n", status);
884 return;
885 }
887 c->socket_id = (pltid << 8) | info.overview_ppid;
888 c->cores_per_socket = info.overview_cpp;
889 c->threads_per_core = info.overview_tpc;
890 count = c->num_log = info.overview_num_log;
892 /* If the thread and core id information is already cached, then
893 * we will simply update cpu_info and return. Otherwise, we will
894 * do the PAL calls and cache core and thread id's of all the siblings.
895 */
896 if (check_for_new_socket(proc_fixed_addr, c))
897 return;
899 for (i = 0; i < count; i++) {
900 int index;
902 if (i && (status = ia64_pal_logical_to_phys(i, &info))
903 != PAL_STATUS_SUCCESS) {
904 printk(KERN_ERR "ia64_pal_logical_to_phys failed"
905 " with %ld\n", status);
906 return;
907 }
908 if (info.log2_la == proc_fixed_addr) {
909 c->core_id = info.log1_cid;
910 c->thread_id = info.log1_tid;
911 }
913 index = check_for_mtinfo_index();
914 /* We will not do the mt_info caching optimization in this case.
915 */
916 if (index < 0)
917 continue;
919 mt_info[index].valid = 1;
920 mt_info[index].socket_id = c->socket_id;
921 mt_info[index].core_id = info.log1_cid;
922 mt_info[index].thread_id = info.log1_tid;
923 mt_info[index].proc_fixed_addr = info.log2_la;
924 }
925 }
926 #endif /* CONFIG_SMP ifdef XEN */