Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1503244

[PATCH 3/3] early_printk: Add simple serialization to early_vprintk()

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject [PATCH 3/3] early_printk: Add simple serialization to early_vprintk()
Date 2016-10-18 19:20 +0200
Message-ID <stGds-4O9-33@gated-at.bofh.it> (permalink)
References <stGdr-4O9-19@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


In order to avoid multiple CPUs banging on the serial port at the same
time, add simple serialization. This explicitly deals with nested
contexts (like IRQs etc.).

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 kernel/printk/printk.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -356,14 +356,28 @@ static int __init force_early_printk_set
 }
 early_param("force_early_printk", force_early_printk_setup);
 
+static int early_printk_cpu = -1;
+
 static int early_vprintk(const char *fmt, va_list args)
 {
+	int n, cpu, old;
 	char buf[512];
-	int n;
+
+	cpu = get_cpu();
+	for (;;) {
+		old = cmpxchg(&early_printk_cpu, -1, cpu);
+		if (old == -1 || old == cpu)
+			break;
+
+		cpu_relax();
+	}
 
 	n = vscnprintf(buf, sizeof(buf), fmt, args);
 	early_console->write(early_console, buf, n);
 
+	smp_store_release(&early_printk_cpu, old);
+	put_cpu();
+
 	return n;
 }
 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/3] make printk work again Peter Zijlstra <peterz@infradead.org> - 2016-10-18 19:20 +0200
  [PATCH 1/3] printk: Fix kdb_trap_printk placement Peter Zijlstra <peterz@infradead.org> - 2016-10-18 19:20 +0200
    Re: [PATCH 1/3] printk: Fix kdb_trap_printk placement Petr Mladek <pmladek@suse.com> - 2016-10-19 16:50 +0200
      Re: [PATCH 1/3] printk: Fix kdb_trap_printk placement Peter Zijlstra <peterz@infradead.org> - 2016-10-19 17:20 +0200
    Re: [PATCH 1/3] printk: Fix kdb_trap_printk placement Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-10-20 15:10 +0200
  [PATCH 3/3] early_printk: Add simple serialization to early_vprintk() Peter Zijlstra <peterz@infradead.org> - 2016-10-18 19:20 +0200
    Re: [PATCH 3/3] early_printk: Add simple serialization to  early_vprintk() Steven Rostedt <rostedt@goodmis.org> - 2016-10-18 19:30 +0200
      Re: [PATCH 3/3] early_printk: Add simple serialization to  early_vprintk() Peter Zijlstra <peterz@infradead.org> - 2016-10-18 19:40 +0200
        Re: [PATCH 3/3] early_printk: Add simple serialization to  early_vprintk() Steven Rostedt <rostedt@goodmis.org> - 2016-10-18 20:00 +0200
  [PATCH 2/3] early_printk: Add force_early_printk kernel parameter Peter Zijlstra <peterz@infradead.org> - 2016-10-18 19:20 +0200
  Re: [PATCH 0/3] make printk work again Peter Zijlstra <peterz@infradead.org> - 2016-10-19 16:30 +0200
  Re: [PATCH 0/3] make printk work again Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-10-19 16:30 +0200
  Re: [PATCH 0/3] make printk work again Jan Kara <jack@suse.cz> - 2016-10-19 17:00 +0200
    Re: [PATCH 0/3] make printk work again Peter Zijlstra <peterz@infradead.org> - 2016-10-19 18:20 +0200

csiph-web