ia64/xen-unstable

view xen/arch/ia64/linux-xen/smp.c @ 9770:ced37bea0647

[IA64] FPH enabling + cleanup

Move contents of switch_to macro from xensystem.h to context_switch function.
Initialize FPU on all processors. FPH is always enabled in Xen.
Speed up context-switch (a little bit!) by not enabling/disabling FPH.
Cleanup (unused function/variablesi/fields, debug printf...)
vmx_ia64_switch_to removed (was unused).

Signed-off-by: Tristan Gingold <tristan.gingold@bull.net>
author awilliam@xenbuild.aw
date Tue Apr 25 22:35:41 2006 -0600 (2006-04-25)
parents 0665256a7a53
children fcfc614d3713
line source
1 /*
2 * SMP Support
3 *
4 * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
5 * Copyright (C) 1999, 2001, 2003 David Mosberger-Tang <davidm@hpl.hp.com>
6 *
7 * Lots of stuff stolen from arch/alpha/kernel/smp.c
8 *
9 * 01/05/16 Rohit Seth <rohit.seth@intel.com> IA64-SMP functions. Reorganized
10 * the existing code (on the lines of x86 port).
11 * 00/09/11 David Mosberger <davidm@hpl.hp.com> Do loops_per_jiffy
12 * calibration on each CPU.
13 * 00/08/23 Asit Mallick <asit.k.mallick@intel.com> fixed logical processor id
14 * 00/03/31 Rohit Seth <rohit.seth@intel.com> Fixes for Bootstrap Processor
15 * & cpu_online_map now gets done here (instead of setup.c)
16 * 99/10/05 davidm Update to bring it in sync with new command-line processing
17 * scheme.
18 * 10/13/00 Goutham Rao <goutham.rao@intel.com> Updated smp_call_function and
19 * smp_call_function_single to resend IPI on timeouts
20 */
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/sched.h>
24 #include <linux/init.h>
25 #include <linux/interrupt.h>
26 #include <linux/smp.h>
27 #include <linux/kernel_stat.h>
28 #include <linux/mm.h>
29 #include <linux/cache.h>
30 #include <linux/delay.h>
31 #include <linux/efi.h>
32 #include <linux/bitops.h>
34 #include <asm/atomic.h>
35 #include <asm/current.h>
36 #include <asm/delay.h>
37 #include <asm/machvec.h>
38 #include <asm/io.h>
39 #include <asm/irq.h>
40 #include <asm/page.h>
41 #include <asm/pgalloc.h>
42 #include <asm/pgtable.h>
43 #include <asm/processor.h>
44 #include <asm/ptrace.h>
45 #include <asm/sal.h>
46 #include <asm/system.h>
47 #include <asm/tlbflush.h>
48 #include <asm/unistd.h>
49 #include <asm/mca.h>
50 #ifdef XEN
51 #include <asm/vhpt.h>
52 #include <asm/hw_irq.h>
53 #endif
55 #ifdef XEN
56 // FIXME: MOVE ELSEWHERE
57 //Huh? This seems to be used on ia64 even if !CONFIG_SMP
58 void flush_tlb_mask(cpumask_t mask)
59 {
60 #ifdef CONFIG_SMP
61 int cpu;
63 cpu = smp_processor_id();
64 if (cpu_isset (cpu, mask)) {
65 cpu_clear(cpu, mask);
66 local_flush_tlb_all ();
67 }
69 if (cpus_empty(mask))
70 return;
72 for (cpu = 0; cpu < NR_CPUS; ++cpu)
73 if (cpu_isset(cpu, mask))
74 smp_call_function_single
75 (cpu, (void (*)(void *))local_flush_tlb_all, NULL, 1, 1);
76 #endif
77 }
78 //#if CONFIG_SMP || IA64
79 #if CONFIG_SMP
80 //Huh? This seems to be used on ia64 even if !CONFIG_SMP
81 void smp_send_event_check_mask(cpumask_t mask)
82 {
83 int cpu;
85 /* Not for me. */
86 cpu_clear(smp_processor_id(), mask);
87 if (cpus_empty(mask))
88 return;
90 //printf("smp_send_event_check_mask called\n");
92 for (cpu = 0; cpu < NR_CPUS; ++cpu)
93 if (cpu_isset(cpu, mask))
94 platform_send_ipi(cpu, IA64_IPI_RESCHEDULE, IA64_IPI_DM_INT, 0);
95 }
98 //Huh? This seems to be used on ia64 even if !CONFIG_SMP
99 int try_flush_tlb_mask(cpumask_t mask)
100 {
101 dummy();
102 return 1;
103 }
104 #endif
105 #endif
107 #ifdef CONFIG_SMP /* ifdef XEN */
109 /*
110 * Structure and data for smp_call_function(). This is designed to minimise static memory
111 * requirements. It also looks cleaner.
112 */
113 static __cacheline_aligned DEFINE_SPINLOCK(call_lock);
115 struct call_data_struct {
116 void (*func) (void *info);
117 void *info;
118 long wait;
119 atomic_t started;
120 atomic_t finished;
121 };
123 static volatile struct call_data_struct *call_data;
125 #define IPI_CALL_FUNC 0
126 #define IPI_CPU_STOP 1
128 /* This needs to be cacheline aligned because it is written to by *other* CPUs. */
129 static DEFINE_PER_CPU(u64, ipi_operation) ____cacheline_aligned;
131 extern void cpu_halt (void);
133 void
134 lock_ipi_calllock(void)
135 {
136 spin_lock_irq(&call_lock);
137 }
139 void
140 unlock_ipi_calllock(void)
141 {
142 spin_unlock_irq(&call_lock);
143 }
145 static void
146 stop_this_cpu (void)
147 {
148 /*
149 * Remove this CPU:
150 */
151 cpu_clear(smp_processor_id(), cpu_online_map);
152 max_xtp();
153 local_irq_disable();
154 #ifndef XEN
155 cpu_halt();
156 #endif
157 }
159 void
160 cpu_die(void)
161 {
162 max_xtp();
163 local_irq_disable();
164 #ifndef XEN
165 cpu_halt();
166 #endif
167 /* Should never be here */
168 BUG();
169 for (;;);
170 }
172 irqreturn_t
173 handle_IPI (int irq, void *dev_id, struct pt_regs *regs)
174 {
175 int this_cpu = get_cpu();
176 unsigned long *pending_ipis = &__ia64_per_cpu_var(ipi_operation);
177 unsigned long ops;
179 mb(); /* Order interrupt and bit testing. */
180 while ((ops = xchg(pending_ipis, 0)) != 0) {
181 mb(); /* Order bit clearing and data access. */
182 do {
183 unsigned long which;
185 which = ffz(~ops);
186 ops &= ~(1 << which);
188 switch (which) {
189 case IPI_CALL_FUNC:
190 {
191 struct call_data_struct *data;
192 void (*func)(void *info);
193 void *info;
194 int wait;
196 /* release the 'pointer lock' */
197 data = (struct call_data_struct *) call_data;
198 func = data->func;
199 info = data->info;
200 wait = data->wait;
202 mb();
203 atomic_inc(&data->started);
204 /*
205 * At this point the structure may be gone unless
206 * wait is true.
207 */
208 (*func)(info);
210 /* Notify the sending CPU that the task is done. */
211 mb();
212 if (wait)
213 atomic_inc(&data->finished);
214 }
215 break;
217 case IPI_CPU_STOP:
218 stop_this_cpu();
219 break;
221 default:
222 printk(KERN_CRIT "Unknown IPI on CPU %d: %lu\n", this_cpu, which);
223 break;
224 }
225 } while (ops);
226 mb(); /* Order data access and bit testing. */
227 }
228 put_cpu();
229 return IRQ_HANDLED;
230 }
232 /*
233 * Called with preeemption disabled.
234 */
235 static inline void
236 send_IPI_single (int dest_cpu, int op)
237 {
238 set_bit(op, &per_cpu(ipi_operation, dest_cpu));
239 platform_send_ipi(dest_cpu, IA64_IPI_VECTOR, IA64_IPI_DM_INT, 0);
240 }
242 /*
243 * Called with preeemption disabled.
244 */
245 static inline void
246 send_IPI_allbutself (int op)
247 {
248 unsigned int i;
250 for (i = 0; i < NR_CPUS; i++) {
251 if (cpu_online(i) && i != smp_processor_id())
252 send_IPI_single(i, op);
253 }
254 }
256 /*
257 * Called with preeemption disabled.
258 */
259 static inline void
260 send_IPI_all (int op)
261 {
262 int i;
264 for (i = 0; i < NR_CPUS; i++)
265 if (cpu_online(i))
266 send_IPI_single(i, op);
267 }
269 /*
270 * Called with preeemption disabled.
271 */
272 static inline void
273 send_IPI_self (int op)
274 {
275 send_IPI_single(smp_processor_id(), op);
276 }
278 #ifndef XEN
279 /*
280 * Called with preeemption disabled.
281 */
282 void
283 smp_send_reschedule (int cpu)
284 {
285 platform_send_ipi(cpu, IA64_IPI_RESCHEDULE, IA64_IPI_DM_INT, 0);
286 }
287 #endif
289 void
290 smp_flush_tlb_all (void)
291 {
292 on_each_cpu((void (*)(void *))local_flush_tlb_all, NULL, 1, 1);
293 }
295 #ifdef XEN
296 void
297 smp_vhpt_flush_all(void)
298 {
299 on_each_cpu((void (*)(void *))vhpt_flush, NULL, 1, 1);
300 }
301 #endif
303 #ifndef XEN
304 void
305 smp_flush_tlb_mm (struct mm_struct *mm)
306 {
307 preempt_disable();
308 /* this happens for the common case of a single-threaded fork(): */
309 if (likely(mm == current->active_mm && atomic_read(&mm->mm_users) == 1))
310 {
311 local_finish_flush_tlb_mm(mm);
312 preempt_enable();
313 return;
314 }
316 preempt_enable();
317 /*
318 * We could optimize this further by using mm->cpu_vm_mask to track which CPUs
319 * have been running in the address space. It's not clear that this is worth the
320 * trouble though: to avoid races, we have to raise the IPI on the target CPU
321 * anyhow, and once a CPU is interrupted, the cost of local_flush_tlb_all() is
322 * rather trivial.
323 */
324 on_each_cpu((void (*)(void *))local_finish_flush_tlb_mm, mm, 1, 1);
325 }
326 #endif
328 /*
329 * Run a function on another CPU
330 * <func> The function to run. This must be fast and non-blocking.
331 * <info> An arbitrary pointer to pass to the function.
332 * <nonatomic> Currently unused.
333 * <wait> If true, wait until function has completed on other CPUs.
334 * [RETURNS] 0 on success, else a negative status code.
335 *
336 * Does not return until the remote CPU is nearly ready to execute <func>
337 * or is or has executed.
338 */
340 int
341 smp_call_function_single (int cpuid, void (*func) (void *info), void *info, int nonatomic,
342 int wait)
343 {
344 struct call_data_struct data;
345 int cpus = 1;
346 int me = get_cpu(); /* prevent preemption and reschedule on another processor */
348 if (cpuid == me) {
349 printk(KERN_INFO "%s: trying to call self\n", __FUNCTION__);
350 put_cpu();
351 return -EBUSY;
352 }
354 data.func = func;
355 data.info = info;
356 atomic_set(&data.started, 0);
357 data.wait = wait;
358 if (wait)
359 atomic_set(&data.finished, 0);
361 #ifdef XEN
362 spin_lock(&call_lock);
363 #else
364 spin_lock_bh(&call_lock);
365 #endif
367 call_data = &data;
368 mb(); /* ensure store to call_data precedes setting of IPI_CALL_FUNC */
369 send_IPI_single(cpuid, IPI_CALL_FUNC);
371 /* Wait for response */
372 while (atomic_read(&data.started) != cpus)
373 cpu_relax();
375 if (wait)
376 while (atomic_read(&data.finished) != cpus)
377 cpu_relax();
378 call_data = NULL;
380 #ifdef XEN
381 spin_unlock(&call_lock);
382 #else
383 spin_unlock_bh(&call_lock);
384 #endif
385 put_cpu();
386 return 0;
387 }
388 EXPORT_SYMBOL(smp_call_function_single);
390 /*
391 * this function sends a 'generic call function' IPI to all other CPUs
392 * in the system.
393 */
395 /*
396 * [SUMMARY] Run a function on all other CPUs.
397 * <func> The function to run. This must be fast and non-blocking.
398 * <info> An arbitrary pointer to pass to the function.
399 * <nonatomic> currently unused.
400 * <wait> If true, wait (atomically) until function has completed on other CPUs.
401 * [RETURNS] 0 on success, else a negative status code.
402 *
403 * Does not return until remote CPUs are nearly ready to execute <func> or are or have
404 * executed.
405 *
406 * You must not call this function with disabled interrupts or from a
407 * hardware interrupt handler or from a bottom half handler.
408 */
409 int
410 smp_call_function (void (*func) (void *info), void *info, int nonatomic, int wait)
411 {
412 struct call_data_struct data;
413 int cpus = num_online_cpus()-1;
415 if (!cpus)
416 return 0;
418 /* Can deadlock when called with interrupts disabled */
419 #ifdef XEN
420 if (irqs_disabled()) {
421 printk("smp_call_function called with interrupts disabled...");
422 printk("enabling interrupts\n");
423 local_irq_enable();
424 }
425 #else
426 WARN_ON(irqs_disabled());
427 #endif
429 data.func = func;
430 data.info = info;
431 atomic_set(&data.started, 0);
432 data.wait = wait;
433 if (wait)
434 atomic_set(&data.finished, 0);
436 spin_lock(&call_lock);
437 #if 0 //def XEN
438 printk("smp_call_function: %d lock\n", smp_processor_id ());
439 #endif
441 call_data = &data;
442 mb(); /* ensure store to call_data precedes setting of IPI_CALL_FUNC */
443 send_IPI_allbutself(IPI_CALL_FUNC);
445 /* Wait for response */
446 while (atomic_read(&data.started) != cpus)
447 cpu_relax();
449 if (wait)
450 while (atomic_read(&data.finished) != cpus)
451 cpu_relax();
452 call_data = NULL;
454 spin_unlock(&call_lock);
455 #if 0 //def XEN
456 printk("smp_call_function: DONE WITH spin_unlock, returning \n");
457 #endif
458 return 0;
459 }
460 EXPORT_SYMBOL(smp_call_function);
462 /*
463 * this function calls the 'stop' function on all other CPUs in the system.
464 */
465 void
466 smp_send_stop (void)
467 {
468 send_IPI_allbutself(IPI_CPU_STOP);
469 }
471 int __init
472 setup_profiling_timer (unsigned int multiplier)
473 {
474 return -EINVAL;
475 }
476 #endif /* CONFIG_SMP ifdef XEN */