Commit b58d9774 authored by Alex Thorlton's avatar Alex Thorlton Committed by Linus Torvalds
Browse files

dump_stack: serialize the output from dump_stack()

Add functionality to serialize the output from dump_stack() to avoid
mangling of the output when dump_stack is called simultaneously from
multiple cpus.

[ fix comment indenting, avoid inclusion of <asm/> files - use <linux/> where possiblem fix uniprocessor build (__dump_stack undefined), remove unneeded ifdef around smp.h inclusion]
Signed-off-by: default avatarAlex Thorlton <>
Reported-by: default avatarRuss Anderson <>
Reviewed-by: default avatarRobin Holt <>
Cc: Vineet Gupta <>
Cc: David S. Miller <>
Cc: Richard Kuo <>
Cc: Jesper Nilsson <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent f170168b
......@@ -6,15 +6,58 @@
#include <linux/kernel.h>
#include <linux/export.h>
#include <linux/sched.h>
#include <linux/smp.h>
#include <linux/atomic.h>
static void __dump_stack(void)
show_stack(NULL, NULL);
* dump_stack - dump the current task information and its stack trace
* Architectures can override this implementation by implementing its own.
static atomic_t dump_lock = ATOMIC_INIT(-1);
void dump_stack(void)
show_stack(NULL, NULL);
int was_locked;
int old;
int cpu;
* Permit this cpu to perform nested stack dumps while serialising
* against other CPUs
cpu = smp_processor_id();
old = atomic_cmpxchg(&dump_lock, -1, cpu);
if (old == -1) {
was_locked = 0;
} else if (old == cpu) {
was_locked = 1;
} else {
goto retry;
if (!was_locked)
atomic_set(&dump_lock, -1);
void dump_stack(void)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment