From: John Ogness Date: Tue, 12 Feb 2019 15:29:51 +0100 Subject: [PATCH 13/25] printk: track seq per console Origin: https://www.kernel.org/pub/linux/kernel/projects/rt/5.4/older/patches-5.4.13-rt7.tar.xz Allow each console to track which seq record was last printed. This simplifies identifying dropped records. Signed-off-by: John Ogness Signed-off-by: Sebastian Andrzej Siewior --- include/linux/console.h | 1 + kernel/printk/printk.c | 30 +++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) --- a/include/linux/console.h +++ b/include/linux/console.h @@ -153,6 +153,7 @@ struct console { short flags; short index; int cflag; + unsigned long printk_seq; void *data; struct console *next; }; --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1507,6 +1507,16 @@ SYSCALL_DEFINE3(syslog, int, type, char return do_syslog(type, buf, len, SYSLOG_FROM_READER); } +static void print_console_dropped(struct console *con, u64 count) +{ + char text[64]; + int len; + + len = sprintf(text, "** %llu printk message%s dropped **\n", + count, count > 1 ? "s" : ""); + con->write(con, text, len); +} + static void format_text(struct printk_log *msg, u64 seq, char *ext_text, size_t *ext_len, char *text, size_t *len, bool time) @@ -1540,7 +1550,7 @@ static void format_text(struct printk_lo * log_buf[start] to log_buf[end - 1]. * The console_lock must be held. */ -static void call_console_drivers(const char *ext_text, size_t ext_len, +static void call_console_drivers(u64 seq, const char *ext_text, size_t ext_len, const char *text, size_t len) { struct console *con; @@ -1558,6 +1568,19 @@ static void call_console_drivers(const c if (!cpu_online(raw_smp_processor_id()) && !(con->flags & CON_ANYTIME)) continue; + if (con->printk_seq >= seq) + continue; + + con->printk_seq++; + if (con->printk_seq < seq) { + print_console_dropped(con, seq - con->printk_seq); + con->printk_seq = seq; + } + + /* for supressed messages, only seq is updated */ + if (len == 0 && ext_len == 0) + continue; + if (con->flags & CON_EXTENDED) con->write(con, ext_text, ext_len); else @@ -1797,7 +1820,7 @@ static ssize_t msg_print_ext_header(char static ssize_t msg_print_ext_body(char *buf, size_t size, char *dict, size_t dict_len, char *text, size_t text_len) { return 0; } -static void call_console_drivers(const char *ext_text, size_t ext_len, +static void call_console_drivers(u64 seq, const char *ext_text, size_t ext_len, const char *text, size_t len) {} static size_t msg_print_text(const struct printk_log *msg, bool syslog, bool time, char *buf, size_t size) { return 0; } @@ -2550,8 +2573,9 @@ static int printk_kthread_func(void *dat &len, printk_time); console_lock(); + call_console_drivers(master_seq, ext_text, + ext_len, text, len); if (len > 0 || ext_len > 0) { - call_console_drivers(ext_text, ext_len, text, len); boot_delay_msec(msg->level); printk_delay(); }