Merge branch 'acpica'
[linux-2.6-block.git] / lib / dump_stack.c
CommitLineData
1da177e4
LT
1/*
2 * Provide a default dump_stack() function for architectures
3 * which don't implement their own.
4 */
5
6#include <linux/kernel.h>
8bc3bcc9 7#include <linux/export.h>
196779b9 8#include <linux/sched.h>
b58d9774
AT
9#include <linux/smp.h>
10#include <linux/atomic.h>
11
12static void __dump_stack(void)
13{
14 dump_stack_print_info(KERN_DEFAULT);
15 show_stack(NULL, NULL);
16}
1da177e4 17
196779b9
TH
18/**
19 * dump_stack - dump the current task information and its stack trace
20 *
21 * Architectures can override this implementation by implementing its own.
22 */
b58d9774
AT
23#ifdef CONFIG_SMP
24static atomic_t dump_lock = ATOMIC_INIT(-1);
25
722a9f92 26asmlinkage __visible void dump_stack(void)
1da177e4 27{
d7ce3692 28 unsigned long flags;
b58d9774
AT
29 int was_locked;
30 int old;
31 int cpu;
32
33 /*
34 * Permit this cpu to perform nested stack dumps while serialising
35 * against other CPUs
36 */
b58d9774 37retry:
d7ce3692 38 local_irq_save(flags);
b58d9774
AT
39 cpu = smp_processor_id();
40 old = atomic_cmpxchg(&dump_lock, -1, cpu);
41 if (old == -1) {
42 was_locked = 0;
43 } else if (old == cpu) {
44 was_locked = 1;
45 } else {
d7ce3692 46 local_irq_restore(flags);
b58d9774
AT
47 cpu_relax();
48 goto retry;
49 }
50
51 __dump_stack();
52
53 if (!was_locked)
54 atomic_set(&dump_lock, -1);
55
d7ce3692 56 local_irq_restore(flags);
b58d9774
AT
57}
58#else
722a9f92 59asmlinkage __visible void dump_stack(void)
b58d9774
AT
60{
61 __dump_stack();
1da177e4 62}
b58d9774 63#endif
1da177e4 64EXPORT_SYMBOL(dump_stack);