Skip to content

Commit fe3d8ad

Browse files
ftang1torvalds
authored andcommitted
console: prevent registered consoles from dumping old kernel message over again
For a platform with many consoles like: "console=tty1 console=ttyMFD2 console=ttyS0 earlyprintk=mrst" Each time when the non "selected_console" (tty1 and ttyMFD2 here) get registered, the existing kernel message will be printed out on registered consoles again, the "mrst" early console will get some same message for 3 times, and "tty1" will get some for twice. As suggested by Andrew Morton, every time a new console is registered, it will be set as the "exclusive" console which will dump the already existing kernel messages. Signed-off-by: Feng Tang <[email protected]> Cc: Greg KH <[email protected]> Cc: Alan Cox <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7bf6939 commit fe3d8ad

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

kernel/printk.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ static unsigned log_start; /* Index into log_buf: next char to be read by syslog
112112
static unsigned con_start; /* Index into log_buf: next char to be sent to consoles */
113113
static unsigned log_end; /* Index into log_buf: most-recently-written-char + 1 */
114114

115+
/*
116+
* If exclusive_console is non-NULL then only this console is to be printed to.
117+
*/
118+
static struct console *exclusive_console;
119+
115120
/*
116121
* Array of consoles built from command line options (console=)
117122
*/
@@ -476,6 +481,8 @@ static void __call_console_drivers(unsigned start, unsigned end)
476481
struct console *con;
477482

478483
for_each_console(con) {
484+
if (exclusive_console && con != exclusive_console)
485+
continue;
479486
if ((con->flags & CON_ENABLED) && con->write &&
480487
(cpu_online(smp_processor_id()) ||
481488
(con->flags & CON_ANYTIME)))
@@ -1230,6 +1237,11 @@ void console_unlock(void)
12301237
local_irq_restore(flags);
12311238
}
12321239
console_locked = 0;
1240+
1241+
/* Release the exclusive_console once it is used */
1242+
if (unlikely(exclusive_console))
1243+
exclusive_console = NULL;
1244+
12331245
up(&console_sem);
12341246
spin_unlock_irqrestore(&logbuf_lock, flags);
12351247
if (wake_klogd)
@@ -1464,6 +1476,12 @@ void register_console(struct console *newcon)
14641476
spin_lock_irqsave(&logbuf_lock, flags);
14651477
con_start = log_start;
14661478
spin_unlock_irqrestore(&logbuf_lock, flags);
1479+
/*
1480+
* We're about to replay the log buffer. Only do this to the
1481+
* just-registered console to avoid excessive message spam to
1482+
* the already-registered consoles.
1483+
*/
1484+
exclusive_console = newcon;
14671485
}
14681486
console_unlock();
14691487
console_sysfs_notify();

0 commit comments

Comments
 (0)