Skip to contentSkip to conversation

disentangle printk's whilst oopsing on SMP

PATCH New David Howells 1 participant 1 message Jun 17, 2003

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 disentangle printk's whilst oopsing on SMP

Hi Linus,

The attached patch stops printk's issued on different processors from becoming char-by-char interleaved whilst one of them is oopsing.

David

kernel/printk.c +7 -2
diff -uNr linux-2.5.72/kernel/printk.c linux-2.5.72-auto/kernel/printk.c
@@ -373,6 +373,9 @@
 		logged_chars++;
 }
 
+/* cpu currently holding logbuf_lock */
+static volatile int printk_cpu = -1;
+
 /*
  * This is printk.  It can be called from any context.  We want it to work.
  * 
@@ -395,8 +398,9 @@
 	static char printk_buf[1024];
 	static int log_level_unknown = 1;
 
-	if (oops_in_progress) {
-		/* If a crash is occurring, make sure we can't deadlock */
+	if (oops_in_progress && printk_cpu==smp_processor_id()) {
+		/* If a crash is occurring during printk() on this CPU,
+		 * make sure we can't deadlock */
 		spin_lock_init(&logbuf_lock);
 		/* And make sure that we print immediately */
 		init_MUTEX(&console_sem);
@@ -404,6 +408,7 @@
 
 	/* This stops the holder of console_sem just where we want him */
 	spin_lock_irqsave(&logbuf_lock, flags);
+	printk_cpu = smp_processor_id();
 
 	/* Emit the output into the temporary buffer */
 	va_start(args, fmt);