[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fa80251d787963392044a4d4a5d6c154bf292a04.1764272407.git.chris@chrisdown.name>
Date: Fri, 28 Nov 2025 03:43:39 +0800
From: Chris Down <chris@...isdown.name>
To: Petr Mladek <pmladek@...e.com>
Cc: linux-kernel@...r.kernel.org,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Sergey Senozhatsky <senozhatsky@...omium.org>,
Steven Rostedt <rostedt@...dmis.org>,
John Ogness <john.ogness@...utronix.de>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Tony Lindgren <tony.lindgren@...ux.intel.com>, kernel-team@...com
Subject: [PATCH v8 08/21] printk: Iterate registered consoles for delay
suppression decisions
The printk_delay() function applies boot_delay and printk_delay_msec
delays when messages are printed. Currently it decides whether to skip
the delay by checking if the message would be suppressed based on the
global console_loglevel only. This means delays are applied even for
messages that no console will actually print.
With per-console loglevels, different consoles can have different
filtering thresholds. A message might be suppressed on one console, but
printed on another. In such cases, applying delays based solely on the
global loglevel would be incorrect: we should only delay if at least one
console will actually print the message.
Introduce suppress_message_printing_everywhere() which iterates over all
registered consoles and checks whether the message would be suppressed
on all of them. The delay is now skipped only if the message would not
be printed anywhere.
Reviewed-by: Petr Mladek <pmladek@...e.com>
Signed-off-by: Chris Down <chris@...isdown.name>
---
kernel/printk/printk.c | 38 +++++++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index d9c1bc4a32c4..0d7f3dac8177 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1368,6 +1368,41 @@ static bool suppress_message_printing(int level, int con_eff_level)
return (level >= con_eff_level && !ignore_loglevel);
}
+/**
+ * suppress_message_printing_everywhere - Check if message is suppressed on all consoles
+ *
+ * @level: The loglevel of the message to check
+ *
+ * Iterates over all registered consoles and determines whether the message
+ * would be suppressed on every one of them based on their effective loglevels.
+ *
+ * This is used by printk_delay() to avoid applying delays for messages that
+ * no console will actually print.
+ *
+ * Return: true if the message would be suppressed on all consoles, false if
+ * at least one console would print it
+ */
+static bool suppress_message_printing_everywhere(int level)
+{
+ bool suppress_everywhere = true;
+ struct console *con;
+ int cookie;
+
+ cookie = console_srcu_read_lock();
+
+ for_each_console_srcu(con) {
+ int con_level = console_srcu_read_loglevel(con);
+
+ if (!suppress_message_printing(level, console_effective_loglevel(con_level))) {
+ suppress_everywhere = false;
+ break;
+ }
+ }
+ console_srcu_read_unlock(cookie);
+
+ return suppress_everywhere;
+}
+
#ifdef CONFIG_BOOT_PRINTK_DELAY
static int boot_delay; /* msecs delay after each printk during bootup */
@@ -2199,7 +2234,8 @@ int printk_delay_msec __read_mostly;
static inline void printk_delay(int level)
{
/* If the message is forced (e.g. panic), we must delay */
- if (!is_printk_force_console() && suppress_message_printing(level, console_loglevel))
+ if (!is_printk_force_console() &&
+ suppress_message_printing_everywhere(level))
return;
boot_delay_msec();
--
2.51.2
Powered by blists - more mailing lists