[Skiboot] [PATCH] core/backtrace: Serialise printing backtraces

Oliver O'Halloran oohall at gmail.com
Tue Jul 25 12:05:50 AEST 2017


Add a lock so that only one thread can print a backtrace at a time.
This should prevent multiple threads from garbaling each other's
backtraces.

Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
 core/stack.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/core/stack.c b/core/stack.c
index 17a4ca43985d..bb7fa625a48c 100644
--- a/core/stack.c
+++ b/core/stack.c
@@ -104,12 +104,24 @@ void __print_backtrace(unsigned int pir,
 		*len = l;
 }
 
+/*
+ * To ensure that we always get backtrace output we bypass the usual console
+ * locking paths. The downside is that when multiple threads need to print
+ * a backtrace they garble each other. To prevent this we use a seperate
+ * lock to serialise printing of the dumps.
+ */
+struct lock bt_lock = LOCK_UNLOCKED;
+
 void backtrace(void)
 {
 	unsigned int ents = STACK_BUF_ENTRIES;
 
+	lock(&bt_lock);
+
 	__backtrace(bt_buf, &ents);
 	__print_backtrace(mfspr(SPR_PIR), bt_buf, ents, NULL, NULL, true);
+
+	unlock(&bt_lock);
 }
 
 void __nomcount __stack_chk_fail(void);
-- 
2.9.4



More information about the Skiboot mailing list