blob: 2fd74b06db67093cc3b7789534f30d81b6912346 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Intel SMP support routines.
3 *
4 * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
5 * (c) 1998-99, 2000 Ingo Molnar <mingo@redhat.com>
6 * (c) 2002,2003 Andi Kleen, SuSE Labs.
7 *
8 * This code is released under the GNU General Public License version 2 or
9 * later.
10 */
11
12#include <linux/init.h>
13
14#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/delay.h>
16#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/smp.h>
18#include <linux/kernel_stat.h>
19#include <linux/mc146818rtc.h>
20#include <linux/interrupt.h>
21
22#include <asm/mtrr.h>
23#include <asm/pgalloc.h>
24#include <asm/tlbflush.h>
25#include <asm/mach_apic.h>
26#include <asm/mmu_context.h>
27#include <asm/proto.h>
Andi Kleena8ab26f2005-04-16 15:25:19 -070028#include <asm/apicdef.h>
Andi Kleen95833c82006-01-11 22:44:36 +010029#include <asm/idle.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31/*
Thomas Gleixner16da2f92008-01-30 13:30:27 +010032 * Smarter SMP flushing macros.
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 * c/o Linus Torvalds.
34 *
35 * These mean you can really definitely utterly forget about
36 * writing to user space from interrupts. (Its not allowed anyway).
37 *
38 * Optimizations Manfred Spraul <manfred@colorfullife.com>
Andi Kleene5bc8b62005-09-12 18:49:24 +020039 *
Thomas Gleixner16da2f92008-01-30 13:30:27 +010040 * More scalable flush, from Andi Kleen
Andi Kleene5bc8b62005-09-12 18:49:24 +020041 *
Thomas Gleixner16da2f92008-01-30 13:30:27 +010042 * To avoid global state use 8 different call vectors.
43 * Each CPU uses a specific vector to trigger flushes on other
44 * CPUs. Depending on the received vector the target CPUs look into
Andi Kleene5bc8b62005-09-12 18:49:24 +020045 * the right per cpu variable for the flush data.
46 *
Thomas Gleixner16da2f92008-01-30 13:30:27 +010047 * With more than 8 CPUs they are hashed to the 8 available
48 * vectors. The limited global vector space forces us to this right now.
Andi Kleene5bc8b62005-09-12 18:49:24 +020049 * In future when interrupts are split into per CPU domains this could be
50 * fixed, at the cost of triggering multiple IPIs in some cases.
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 */
52
Andi Kleene5bc8b62005-09-12 18:49:24 +020053union smp_flush_state {
54 struct {
55 cpumask_t flush_cpumask;
56 struct mm_struct *flush_mm;
57 unsigned long flush_va;
Andi Kleene5bc8b62005-09-12 18:49:24 +020058 spinlock_t tlbstate_lock;
59 };
60 char pad[SMP_CACHE_BYTES];
61} ____cacheline_aligned;
62
63/* State is put into the per CPU data section, but padded
64 to a full cache line because other CPUs can access it and we don't
65 want false sharing in the per cpu data segment. */
66static DEFINE_PER_CPU(union smp_flush_state, flush_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68/*
Thomas Gleixner16da2f92008-01-30 13:30:27 +010069 * We cannot call mmdrop() because we are in interrupt context,
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 * instead update mm->cpu_vm_mask.
71 */
Venki Pallipadibde6f5f2008-01-30 13:32:01 +010072void leave_mm(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
74 if (read_pda(mmu_state) == TLBSTATE_OK)
75 BUG();
Brian Gerstb1fc5132006-03-25 16:31:13 +010076 cpu_clear(cpu, read_pda(active_mm)->cpu_vm_mask);
Linus Torvaldse3ebadd2007-05-07 08:44:24 -070077 load_cr3(swapper_pg_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
Venki Pallipadibde6f5f2008-01-30 13:32:01 +010079EXPORT_SYMBOL_GPL(leave_mm);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81/*
82 *
83 * The flush IPI assumes that a thread switch happens in this order:
84 * [cpu0: the cpu that switches]
85 * 1) switch_mm() either 1a) or 1b)
86 * 1a) thread switch to a different mm
Brian Gerstb1fc5132006-03-25 16:31:13 +010087 * 1a1) cpu_clear(cpu, old_mm->cpu_vm_mask);
Thomas Gleixner16da2f92008-01-30 13:30:27 +010088 * Stop ipi delivery for the old mm. This is not synchronized with
89 * the other cpus, but smp_invalidate_interrupt ignore flush ipis
90 * for the wrong mm, and in the worst case we perform a superfluous
91 * tlb flush.
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 * 1a2) set cpu mmu_state to TLBSTATE_OK
Thomas Gleixner16da2f92008-01-30 13:30:27 +010093 * Now the smp_invalidate_interrupt won't call leave_mm if cpu0
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 * was in lazy tlb mode.
95 * 1a3) update cpu active_mm
Thomas Gleixner16da2f92008-01-30 13:30:27 +010096 * Now cpu0 accepts tlb flushes for the new mm.
Brian Gerstb1fc5132006-03-25 16:31:13 +010097 * 1a4) cpu_set(cpu, new_mm->cpu_vm_mask);
Thomas Gleixner16da2f92008-01-30 13:30:27 +010098 * Now the other cpus will send tlb flush ipis.
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 * 1a4) change cr3.
100 * 1b) thread switch without mm change
101 * cpu active_mm is correct, cpu0 already handles
102 * flush ipis.
103 * 1b1) set cpu mmu_state to TLBSTATE_OK
104 * 1b2) test_and_set the cpu bit in cpu_vm_mask.
Thomas Gleixner16da2f92008-01-30 13:30:27 +0100105 * Atomically set the bit [other cpus will start sending flush ipis],
106 * and test the bit.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 * 1b3) if the bit was 0: leave_mm was called, flush the tlb.
108 * 2) switch %%esp, ie current
109 *
110 * The interrupt must handle 2 special cases:
111 * - cr3 is changed before %%esp, ie. it cannot use current->{active_,}mm.
112 * - the cpu performs speculative tlb reads, i.e. even if the cpu only
113 * runs in kernel space, the cpu could load tlb entries for user space
114 * pages.
115 *
116 * The good news is that cpu mmu_state is local to each cpu, no
117 * write/read ordering problems.
118 */
119
120/*
121 * TLB flush IPI:
122 *
123 * 1) Flush the tlb entries if the cpu uses the mm that's being flushed.
124 * 2) Leave the mm if we are in the lazy tlb mode.
Andi Kleene5bc8b62005-09-12 18:49:24 +0200125 *
126 * Interrupts are disabled.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 */
128
Andi Kleene5bc8b62005-09-12 18:49:24 +0200129asmlinkage void smp_invalidate_interrupt(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
Andi Kleene5bc8b62005-09-12 18:49:24 +0200131 int cpu;
132 int sender;
133 union smp_flush_state *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Andi Kleene5bc8b62005-09-12 18:49:24 +0200135 cpu = smp_processor_id();
136 /*
Rusty Russell19eadf92006-06-27 02:53:44 -0700137 * orig_rax contains the negated interrupt vector.
Andi Kleene5bc8b62005-09-12 18:49:24 +0200138 * Use that to determine where the sender put the data.
139 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100140 sender = ~regs->orig_ax - INVALIDATE_TLB_VECTOR_START;
Andi Kleene5bc8b62005-09-12 18:49:24 +0200141 f = &per_cpu(flush_state, sender);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Andi Kleene5bc8b62005-09-12 18:49:24 +0200143 if (!cpu_isset(cpu, f->flush_cpumask))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 goto out;
Thomas Gleixner16da2f92008-01-30 13:30:27 +0100145 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 * This was a BUG() but until someone can quote me the
147 * line from the intel manual that guarantees an IPI to
148 * multiple CPUs is retried _only_ on the erroring CPUs
149 * its staying as a return
150 *
151 * BUG();
152 */
Thomas Gleixner16da2f92008-01-30 13:30:27 +0100153
Andi Kleene5bc8b62005-09-12 18:49:24 +0200154 if (f->flush_mm == read_pda(active_mm)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 if (read_pda(mmu_state) == TLBSTATE_OK) {
Thomas Gleixner0b9c99b2008-01-30 13:30:35 +0100156 if (f->flush_va == TLB_FLUSH_ALL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 local_flush_tlb();
158 else
Andi Kleene5bc8b62005-09-12 18:49:24 +0200159 __flush_tlb_one(f->flush_va);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 } else
161 leave_mm(cpu);
162 }
Andi Kleen5df35742005-07-28 21:15:22 -0700163out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 ack_APIC_irq();
Andi Kleene5bc8b62005-09-12 18:49:24 +0200165 cpu_clear(cpu, f->flush_cpumask);
Joe Korty38e760a2007-10-17 18:04:40 +0200166 add_pda(irq_tlb_count, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167}
168
Thomas Gleixner0b9c99b2008-01-30 13:30:35 +0100169void native_flush_tlb_others(const cpumask_t *cpumaskp, struct mm_struct *mm,
170 unsigned long va)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Andi Kleene5bc8b62005-09-12 18:49:24 +0200172 int sender;
173 union smp_flush_state *f;
Thomas Gleixner0b9c99b2008-01-30 13:30:35 +0100174 cpumask_t cpumask = *cpumaskp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Andi Kleene5bc8b62005-09-12 18:49:24 +0200176 /* Caller has disabled preemption */
177 sender = smp_processor_id() % NUM_INVALIDATE_TLB_VECTORS;
178 f = &per_cpu(flush_state, sender);
179
Thomas Gleixner16da2f92008-01-30 13:30:27 +0100180 /*
181 * Could avoid this lock when
182 * num_online_cpus() <= NUM_INVALIDATE_TLB_VECTORS, but it is
183 * probably not worth checking this for a cache-hot lock.
184 */
Andi Kleene5bc8b62005-09-12 18:49:24 +0200185 spin_lock(&f->tlbstate_lock);
186
187 f->flush_mm = mm;
188 f->flush_va = va;
189 cpus_or(f->flush_cpumask, cpumask, f->flush_cpumask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 /*
192 * We have to send the IPI only to
193 * CPUs affected.
194 */
Andi Kleene5bc8b62005-09-12 18:49:24 +0200195 send_IPI_mask(cpumask, INVALIDATE_TLB_VECTOR_START + sender);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Andi Kleene5bc8b62005-09-12 18:49:24 +0200197 while (!cpus_empty(f->flush_cpumask))
198 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Andi Kleene5bc8b62005-09-12 18:49:24 +0200200 f->flush_mm = NULL;
201 f->flush_va = 0;
202 spin_unlock(&f->tlbstate_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203}
Andi Kleene5bc8b62005-09-12 18:49:24 +0200204
205int __cpuinit init_smp_flush(void)
206{
207 int i;
Thomas Gleixner16da2f92008-01-30 13:30:27 +0100208
Andi Kleene5bc8b62005-09-12 18:49:24 +0200209 for_each_cpu_mask(i, cpu_possible_map) {
Alexey Dobriyan825e0372006-08-05 12:14:34 -0700210 spin_lock_init(&per_cpu(flush_state, i).tlbstate_lock);
Andi Kleene5bc8b62005-09-12 18:49:24 +0200211 }
212 return 0;
213}
Andi Kleene5bc8b62005-09-12 18:49:24 +0200214core_initcall(init_smp_flush);
Thomas Gleixner16da2f92008-01-30 13:30:27 +0100215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216void flush_tlb_current_task(void)
217{
218 struct mm_struct *mm = current->mm;
219 cpumask_t cpu_mask;
220
221 preempt_disable();
222 cpu_mask = mm->cpu_vm_mask;
223 cpu_clear(smp_processor_id(), cpu_mask);
224
225 local_flush_tlb();
226 if (!cpus_empty(cpu_mask))
Thomas Gleixner0b9c99b2008-01-30 13:30:35 +0100227 flush_tlb_others(cpu_mask, mm, TLB_FLUSH_ALL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 preempt_enable();
229}
230
231void flush_tlb_mm (struct mm_struct * mm)
232{
233 cpumask_t cpu_mask;
234
235 preempt_disable();
236 cpu_mask = mm->cpu_vm_mask;
237 cpu_clear(smp_processor_id(), cpu_mask);
238
239 if (current->active_mm == mm) {
240 if (current->mm)
241 local_flush_tlb();
242 else
243 leave_mm(smp_processor_id());
244 }
245 if (!cpus_empty(cpu_mask))
Thomas Gleixner0b9c99b2008-01-30 13:30:35 +0100246 flush_tlb_others(cpu_mask, mm, TLB_FLUSH_ALL);
Linus Torvaldsda8f1532007-09-21 12:09:41 -0700247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 preempt_enable();
249}
250
251void flush_tlb_page(struct vm_area_struct * vma, unsigned long va)
252{
253 struct mm_struct *mm = vma->vm_mm;
254 cpumask_t cpu_mask;
255
256 preempt_disable();
257 cpu_mask = mm->cpu_vm_mask;
258 cpu_clear(smp_processor_id(), cpu_mask);
259
260 if (current->active_mm == mm) {
261 if(current->mm)
262 __flush_tlb_one(va);
Thomas Gleixner16da2f92008-01-30 13:30:27 +0100263 else
264 leave_mm(smp_processor_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 }
266
267 if (!cpus_empty(cpu_mask))
268 flush_tlb_others(cpu_mask, mm, va);
269
270 preempt_enable();
271}
272
273static void do_flush_tlb_all(void* info)
274{
275 unsigned long cpu = smp_processor_id();
276
277 __flush_tlb_all();
278 if (read_pda(mmu_state) == TLBSTATE_LAZY)
279 leave_mm(cpu);
280}
281
282void flush_tlb_all(void)
283{
284 on_each_cpu(do_flush_tlb_all, NULL, 1, 1);
285}
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287/*
288 * this function sends a 'reschedule' IPI to another CPU.
289 * it goes straight through and wastes no time serializing
290 * anything. Worst case is that we lose a reschedule ...
291 */
292
293void smp_send_reschedule(int cpu)
294{
295 send_IPI_mask(cpumask_of_cpu(cpu), RESCHEDULE_VECTOR);
296}
297
298/*
299 * Structure and data for smp_call_function(). This is designed to minimise
300 * static memory requirements. It also looks cleaner.
301 */
302static DEFINE_SPINLOCK(call_lock);
303
304struct call_data_struct {
305 void (*func) (void *info);
306 void *info;
307 atomic_t started;
308 atomic_t finished;
309 int wait;
310};
311
312static struct call_data_struct * call_data;
313
Ashok Raj884d9e42005-06-25 14:55:02 -0700314void lock_ipi_call_lock(void)
315{
316 spin_lock_irq(&call_lock);
317}
318
319void unlock_ipi_call_lock(void)
320{
321 spin_unlock_irq(&call_lock);
322}
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324/*
Laurent Vivier66d16ed2007-10-19 20:35:03 +0200325 * this function sends a 'generic call function' IPI to all other CPU
326 * of the system defined in the mask.
Eric W. Biederman3d483f42005-07-29 14:03:29 -0700327 */
Thomas Gleixner16da2f92008-01-30 13:30:27 +0100328static int __smp_call_function_mask(cpumask_t mask,
329 void (*func)(void *), void *info,
330 int wait)
Eric W. Biederman3d483f42005-07-29 14:03:29 -0700331{
332 struct call_data_struct data;
Laurent Vivier66d16ed2007-10-19 20:35:03 +0200333 cpumask_t allbutself;
334 int cpus;
335
336 allbutself = cpu_online_map;
337 cpu_clear(smp_processor_id(), allbutself);
338
339 cpus_and(mask, mask, allbutself);
340 cpus = cpus_weight(mask);
341
342 if (!cpus)
343 return 0;
Eric W. Biederman3d483f42005-07-29 14:03:29 -0700344
345 data.func = func;
346 data.info = info;
347 atomic_set(&data.started, 0);
348 data.wait = wait;
349 if (wait)
350 atomic_set(&data.finished, 0);
351
352 call_data = &data;
353 wmb();
Laurent Vivier66d16ed2007-10-19 20:35:03 +0200354
355 /* Send a message to other CPUs */
356 if (cpus_equal(mask, allbutself))
357 send_IPI_allbutself(CALL_FUNCTION_VECTOR);
358 else
359 send_IPI_mask(mask, CALL_FUNCTION_VECTOR);
Eric W. Biederman3d483f42005-07-29 14:03:29 -0700360
361 /* Wait for response */
362 while (atomic_read(&data.started) != cpus)
363 cpu_relax();
364
365 if (!wait)
Laurent Vivier66d16ed2007-10-19 20:35:03 +0200366 return 0;
Eric W. Biederman3d483f42005-07-29 14:03:29 -0700367
368 while (atomic_read(&data.finished) != cpus)
369 cpu_relax();
Laurent Vivier66d16ed2007-10-19 20:35:03 +0200370
371 return 0;
Eric W. Biederman3d483f42005-07-29 14:03:29 -0700372}
Laurent Vivier66d16ed2007-10-19 20:35:03 +0200373/**
374 * smp_call_function_mask(): Run a function on a set of other CPUs.
375 * @mask: The set of cpus to run on. Must not include the current cpu.
376 * @func: The function to run. This must be fast and non-blocking.
377 * @info: An arbitrary pointer to pass to the function.
378 * @wait: If true, wait (atomically) until function has completed on other CPUs.
379 *
380 * Returns 0 on success, else a negative status code.
381 *
382 * If @wait is true, then returns once @func has returned; otherwise
383 * it returns just before the target cpu calls @func.
384 *
385 * You must not call this function with disabled interrupts or from a
386 * hardware interrupt handler or from a bottom half handler.
387 */
388int smp_call_function_mask(cpumask_t mask,
389 void (*func)(void *), void *info,
390 int wait)
391{
392 int ret;
393
394 /* Can deadlock when called with interrupts disabled */
395 WARN_ON(irqs_disabled());
396
397 spin_lock(&call_lock);
398 ret = __smp_call_function_mask(mask, func, info, wait);
399 spin_unlock(&call_lock);
400 return ret;
401}
402EXPORT_SYMBOL(smp_call_function_mask);
Eric W. Biederman3d483f42005-07-29 14:03:29 -0700403
404/*
Avi Kivity40555512007-07-09 17:11:49 +0300405 * smp_call_function_single - Run a function on a specific CPU
Eric W. Biederman3d483f42005-07-29 14:03:29 -0700406 * @func: The function to run. This must be fast and non-blocking.
407 * @info: An arbitrary pointer to pass to the function.
408 * @nonatomic: Currently unused.
409 * @wait: If true, wait until function has completed on other CPUs.
410 *
411 * Retrurns 0 on success, else a negative status code.
412 *
413 * Does not return until the remote CPU is nearly ready to execute <func>
414 * or is or has executed.
415 */
416
417int smp_call_function_single (int cpu, void (*func) (void *info), void *info,
Thomas Gleixner16da2f92008-01-30 13:30:27 +0100418 int nonatomic, int wait)
Eric W. Biederman3d483f42005-07-29 14:03:29 -0700419{
420 /* prevent preemption and reschedule on another processor */
Thomas Gleixner16da2f92008-01-30 13:30:27 +0100421 int ret, me = get_cpu();
Andrew Mortona38a44c2006-12-06 20:38:16 -0800422
423 /* Can deadlock when called with interrupts disabled */
424 WARN_ON(irqs_disabled());
425
Avi Kivity40555512007-07-09 17:11:49 +0300426 if (cpu == me) {
427 local_irq_disable();
428 func(info);
429 local_irq_enable();
430 put_cpu();
431 return 0;
432 }
433
Laurent Vivier66d16ed2007-10-19 20:35:03 +0200434 ret = smp_call_function_mask(cpumask_of_cpu(cpu), func, info, wait);
435
Eric W. Biederman3d483f42005-07-29 14:03:29 -0700436 put_cpu();
Laurent Vivier66d16ed2007-10-19 20:35:03 +0200437 return ret;
Eric W. Biederman3d483f42005-07-29 14:03:29 -0700438}
Andi Kleen64a26a732006-12-07 02:14:19 +0100439EXPORT_SYMBOL(smp_call_function_single);
Eric W. Biederman3d483f42005-07-29 14:03:29 -0700440
441/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 * smp_call_function - run a function on all other CPUs.
443 * @func: The function to run. This must be fast and non-blocking.
444 * @info: An arbitrary pointer to pass to the function.
445 * @nonatomic: currently unused.
446 * @wait: If true, wait (atomically) until function has completed on other
447 * CPUs.
448 *
449 * Returns 0 on success, else a negative status code. Does not return until
450 * remote CPUs are nearly ready to execute func or are or have executed.
451 *
452 * You must not call this function with disabled interrupts or from a
453 * hardware interrupt handler or from a bottom half handler.
454 * Actually there are a few legal cases, like panic.
455 */
456int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
457 int wait)
458{
Laurent Vivier66d16ed2007-10-19 20:35:03 +0200459 return smp_call_function_mask(cpu_online_map, func, info, wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460}
Andi Kleen2ee60e172006-06-26 13:59:44 +0200461EXPORT_SYMBOL(smp_call_function);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Jan Beulich9964cf72007-05-02 19:27:05 +0200463static void stop_this_cpu(void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
Jan Beulich9964cf72007-05-02 19:27:05 +0200465 local_irq_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 /*
467 * Remove this CPU:
468 */
469 cpu_clear(smp_processor_id(), cpu_online_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 disable_local_APIC();
Thomas Gleixner16da2f92008-01-30 13:30:27 +0100471 for (;;)
Jan Beulich46d13a32006-06-26 13:57:59 +0200472 halt();
Thomas Gleixner16da2f92008-01-30 13:30:27 +0100473}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475void smp_send_stop(void)
476{
Jan Beulich9964cf72007-05-02 19:27:05 +0200477 int nolock;
478 unsigned long flags;
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 if (reboot_force)
481 return;
Jan Beulich9964cf72007-05-02 19:27:05 +0200482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 /* Don't deadlock on the call lock in panic */
Jan Beulich9964cf72007-05-02 19:27:05 +0200484 nolock = !spin_trylock(&call_lock);
485 local_irq_save(flags);
Laurent Vivier66d16ed2007-10-19 20:35:03 +0200486 __smp_call_function_mask(cpu_online_map, stop_this_cpu, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 if (!nolock)
488 spin_unlock(&call_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 disable_local_APIC();
Jan Beulich9964cf72007-05-02 19:27:05 +0200490 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491}
492
493/*
494 * Reschedule call back. Nothing to do,
495 * all the work is done automatically when
496 * we return from the interrupt.
497 */
498asmlinkage void smp_reschedule_interrupt(void)
499{
500 ack_APIC_irq();
Joe Korty38e760a2007-10-17 18:04:40 +0200501 add_pda(irq_resched_count, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502}
503
504asmlinkage void smp_call_function_interrupt(void)
505{
506 void (*func) (void *info) = call_data->func;
507 void *info = call_data->info;
508 int wait = call_data->wait;
509
510 ack_APIC_irq();
511 /*
512 * Notify initiating CPU that I've grabbed the data and am
513 * about to execute the function
514 */
515 mb();
516 atomic_inc(&call_data->started);
517 /*
518 * At this point the info structure may be out of scope unless wait==1
519 */
Andi Kleen95833c82006-01-11 22:44:36 +0100520 exit_idle();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 irq_enter();
522 (*func)(info);
Joe Korty38e760a2007-10-17 18:04:40 +0200523 add_pda(irq_call_count, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 irq_exit();
525 if (wait) {
526 mb();
527 atomic_inc(&call_data->finished);
528 }
529}
Andi Kleena8ab26f2005-04-16 15:25:19 -0700530