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