Commit | Line | Data |
---|---|---|
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> |
b17b0153 | 9 | #include <linux/sched/debug.h> |
b58d9774 AT |
10 | #include <linux/smp.h> |
11 | #include <linux/atomic.h> | |
12 | ||
13 | static void __dump_stack(void) | |
14 | { | |
15 | dump_stack_print_info(KERN_DEFAULT); | |
16 | show_stack(NULL, NULL); | |
17 | } | |
1da177e4 | 18 | |
196779b9 TH |
19 | /** |
20 | * dump_stack - dump the current task information and its stack trace | |
21 | * | |
22 | * Architectures can override this implementation by implementing its own. | |
23 | */ | |
b58d9774 AT |
24 | #ifdef CONFIG_SMP |
25 | static atomic_t dump_lock = ATOMIC_INIT(-1); | |
26 | ||
722a9f92 | 27 | asmlinkage __visible void dump_stack(void) |
1da177e4 | 28 | { |
d7ce3692 | 29 | unsigned long flags; |
b58d9774 AT |
30 | int was_locked; |
31 | int old; | |
32 | int cpu; | |
33 | ||
34 | /* | |
35 | * Permit this cpu to perform nested stack dumps while serialising | |
36 | * against other CPUs | |
37 | */ | |
b58d9774 | 38 | retry: |
d7ce3692 | 39 | local_irq_save(flags); |
b58d9774 AT |
40 | cpu = smp_processor_id(); |
41 | old = atomic_cmpxchg(&dump_lock, -1, cpu); | |
42 | if (old == -1) { | |
43 | was_locked = 0; | |
44 | } else if (old == cpu) { | |
45 | was_locked = 1; | |
46 | } else { | |
d7ce3692 | 47 | local_irq_restore(flags); |
b58d9774 AT |
48 | cpu_relax(); |
49 | goto retry; | |
50 | } | |
51 | ||
52 | __dump_stack(); | |
53 | ||
54 | if (!was_locked) | |
55 | atomic_set(&dump_lock, -1); | |
56 | ||
d7ce3692 | 57 | local_irq_restore(flags); |
b58d9774 AT |
58 | } |
59 | #else | |
722a9f92 | 60 | asmlinkage __visible void dump_stack(void) |
b58d9774 AT |
61 | { |
62 | __dump_stack(); | |
1da177e4 | 63 | } |
b58d9774 | 64 | #endif |
1da177e4 | 65 | EXPORT_SYMBOL(dump_stack); |