* [PATCH v3 0/6] printk: nbcon: deprecate boot_delay in favour of printk_delay
@ 2026-07-12 10:20 Andrew Murray
2026-07-12 10:20 ` [PATCH v3 1/6] printk: sysctl: use unsigned int for printk_delay Andrew Murray
` (5 more replies)
0 siblings, 6 replies; 11+ messages in thread
From: Andrew Murray @ 2026-07-12 10:20 UTC (permalink / raw)
To: Petr Mladek, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jonathan Corbet, Shuah Khan, Russell King, Florian Fainelli,
Broadcom internal kernel review list, Ray Jui, Scott Branden,
Andrew Morton, Greg Kroah-Hartman, Sebastian Andrzej Siewior,
Clark Williams
Cc: linux-kernel, linux-doc, linux-arm-kernel, linux-rpi-kernel,
linux-rt-devel, Andrew Murray
The boot_delay (BOOT_PRINTK_DELAY) kernel parameter and printk_delay
sysctl are two distinct mechanisms for providing similar functionality
which add a delay prior to each printed printk message.
boot_delay provides a kernel parameter for delaying printk output from
kernel start through to boot (SYSTEM_RUNNING), whereas printk_delay is
configurable only via sysctl and thus is only used post boot.
However, since the introduction of nbcon and the legacy printer thread
for PREEMPT_RT kernels, printk records are now emited to the console
asynchronously to the caller of printk. Thus, any printk delay added by
boot_delay/printk_delay continues to slow down the calling process but
may not have any impact to the rate in which records are emited to the
console, especially for slow consoles.
To address these issues, let's deprecate boot_delay, extend printk_delay
to be useable from kernel start and ensure that delays occur at the point
where console messages are printed rather than queued.
Please note that this patchset results in delays occuring after a message
is printed rather than, as it is now, before.
Signed-off-by: Andrew Murray <amurray@thegoodpenguin.co.uk>
---
Please see the following related work for additional context:
- https://lore.kernel.org/all/20260503214214.3475670-1-rdunlap@infradead.org/
- https://lore.kernel.org/all/20260505-printk_delay-v1-1-5dba51d7f17c@thegoodpenguin.co.uk/
---
Changes in v1:
- Rebased onto v7.2-rc2
- Moved emitted field from nbcon_write_context to nbcon_context
- Fixed comparison of char field that used > operator
- Used unsigned int and bounds checking for printk/boot delay
- Moved delays prior to allowing handover
- Added additional information into commit messages
- Link to v2: https://lore.kernel.org/lkml/20260630-deprecate_boot_delay-v2-0-f9883d36aa4b@thegoodpenguin.co.uk
Changes in v2:
- Rebased onto v7.2-rc1
- Correctly handle negative values for printk_delay_msec (patch 2)
- Add missing newline in pr_warn (patch 2)
- Improved patch descriptions for (patches 2 and 3)
- Use new emitted flag in nbcon_context/nbcon_write_context in place of backlog && wctxt.len checks (patch 3)
- Use unsigned char for unsafe_takeover field instead of bool in nbcon_write_context (patch 3)
- Move printk_delay_msec and printk_delay from printk.h to internal.h (patch 3)
- Revert regression added in v1 to __nbcon_atomic_flush_pending_con (patch 3)
- Move printk_delay later in console_emit_next_record ensuring delay is always after emit (across nbcon/legacy) (patch 3)
- Fixed typo in documentation s/boot_delay/printk_delay/g in printk_delay= section (patch 4)
- Link to v1: https://lore.kernel.org/r/20260601-deprecate_boot_delay-v1-0-c34c187142a6@thegoodpenguin.co.uk
---
Andrew Murray (6):
printk: sysctl: use unsigned int for printk_delay
printk: add bounds checking to boot_delay
printk: remove BOOT_PRINTK_DELAY config option
printk: deprecate boot_delay in favour of printk_delay
printk: nbcon: move printk_delay to console emiting code
Documentation/kernel-parameters: add/update printk_delay/boot_delay
Documentation/admin-guide/kernel-parameters.txt | 31 +++++++--
arch/arm/configs/bcm2835_defconfig | 1 -
include/linux/console.h | 5 +-
include/linux/printk.h | 1 -
kernel/printk/internal.h | 6 ++
kernel/printk/nbcon.c | 13 ++++
kernel/printk/printk.c | 89 ++++++++++++++++---------
kernel/printk/sysctl.c | 4 +-
lib/Kconfig.debug | 18 -----
9 files changed, 108 insertions(+), 60 deletions(-)
---
base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda
change-id: 20260711-printkcleanup-cbe3fda4a2bc
Best regards,
--
Andrew Murray <amurray@thegoodpenguin.co.uk>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 1/6] printk: sysctl: use unsigned int for printk_delay
2026-07-12 10:20 [PATCH v3 0/6] printk: nbcon: deprecate boot_delay in favour of printk_delay Andrew Murray
@ 2026-07-12 10:20 ` Andrew Murray
2026-07-16 13:01 ` Petr Mladek
2026-07-12 10:20 ` [PATCH v3 2/6] printk: add bounds checking to boot_delay Andrew Murray
` (4 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Andrew Murray @ 2026-07-12 10:20 UTC (permalink / raw)
To: Petr Mladek, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jonathan Corbet, Shuah Khan, Russell King, Florian Fainelli,
Broadcom internal kernel review list, Ray Jui, Scott Branden,
Andrew Morton, Greg Kroah-Hartman, Sebastian Andrzej Siewior,
Clark Williams
Cc: linux-kernel, linux-doc, linux-arm-kernel, linux-rpi-kernel,
linux-rt-devel, Andrew Murray
As the printk_delay sysctl represents a duration in milliseconds,
let's set its type to be unsigned int.
Signed-off-by: Andrew Murray <amurray@thegoodpenguin.co.uk>
---
include/linux/printk.h | 2 +-
kernel/printk/printk.c | 4 ++--
kernel/printk/sysctl.c | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/linux/printk.h b/include/linux/printk.h
index f594c1266bfd411f2238b45374e8a71222f0407c..ea52dc72b73b64898f82a0319b01c27323b18dee 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -188,7 +188,7 @@ extern int __printk_ratelimit(const char *func);
extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
unsigned int interval_msec);
-extern int printk_delay_msec;
+extern unsigned int printk_delay_msec;
extern int dmesg_restrict;
extern void wake_up_klogd(void);
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 2fe9a963c823a41e7df10c29939a2abb55462859..31aabdf8248cc39c54ee11685d4a37deac1c174c 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2117,14 +2117,14 @@ static u8 *__printk_recursion_counter(void)
local_irq_restore(flags); \
} while (0)
-int printk_delay_msec __read_mostly;
+unsigned int printk_delay_msec __read_mostly;
static inline void printk_delay(int level)
{
boot_delay_msec(level);
if (unlikely(printk_delay_msec)) {
- int m = printk_delay_msec;
+ unsigned int m = printk_delay_msec;
while (m--) {
mdelay(1);
diff --git a/kernel/printk/sysctl.c b/kernel/printk/sysctl.c
index f15732e93c2e9c0865c42e4af9cb6458d4402c0a..56c3db63b3f8c6c5fddc4e4de1f41c6102f0f4b1 100644
--- a/kernel/printk/sysctl.c
+++ b/kernel/printk/sysctl.c
@@ -44,9 +44,9 @@ static const struct ctl_table printk_sysctls[] = {
{
.procname = "printk_delay",
.data = &printk_delay_msec,
- .maxlen = sizeof(int),
+ .maxlen = sizeof(unsigned int),
.mode = 0644,
- .proc_handler = proc_dointvec_minmax,
+ .proc_handler = proc_douintvec_minmax,
.extra1 = SYSCTL_ZERO,
.extra2 = (void *)&ten_thousand,
},
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 2/6] printk: add bounds checking to boot_delay
2026-07-12 10:20 [PATCH v3 0/6] printk: nbcon: deprecate boot_delay in favour of printk_delay Andrew Murray
2026-07-12 10:20 ` [PATCH v3 1/6] printk: sysctl: use unsigned int for printk_delay Andrew Murray
@ 2026-07-12 10:20 ` Andrew Murray
2026-07-16 13:13 ` Petr Mladek
2026-07-12 10:20 ` [PATCH v3 3/6] printk: remove BOOT_PRINTK_DELAY config option Andrew Murray
` (3 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Andrew Murray @ 2026-07-12 10:20 UTC (permalink / raw)
To: Petr Mladek, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jonathan Corbet, Shuah Khan, Russell King, Florian Fainelli,
Broadcom internal kernel review list, Ray Jui, Scott Branden,
Andrew Morton, Greg Kroah-Hartman, Sebastian Andrzej Siewior,
Clark Williams
Cc: linux-kernel, linux-doc, linux-arm-kernel, linux-rpi-kernel,
linux-rt-devel, Andrew Murray
As the boot_delay kernel parameter represents a duration in
milliseconds, let's set its type to be unsigned int and add
bounds checking.
Please note that the existing pr_debug will only be displayed
when boot_delay is non-zero:
pr_debug("printk_delay: %u, preset_lpj: %ld, lpj: %lu, "
"HZ: %d, loops_per_msec: %llu\n",
printk_delay_msec, preset_lpj, lpj, HZ, loops_per_msec);
Signed-off-by: Andrew Murray <amurray@thegoodpenguin.co.uk>
---
kernel/printk/printk.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 31aabdf8248cc39c54ee11685d4a37deac1c174c..8be562c9be277670ba3209ed1f810fc87175848a 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1291,19 +1291,22 @@ static bool suppress_message_printing(int level)
#ifdef CONFIG_BOOT_PRINTK_DELAY
-static int boot_delay; /* msecs delay after each printk during bootup */
+static unsigned int boot_delay; /* msecs delay after each printk during bootup */
static unsigned long long loops_per_msec; /* based on boot_delay */
static int __init boot_delay_setup(char *str)
{
unsigned long lpj;
+ int boot_delay_val;
lpj = preset_lpj ? preset_lpj : 1000000; /* some guess */
loops_per_msec = (unsigned long long)lpj / 1000 * HZ;
- get_option(&str, &boot_delay);
- if (boot_delay > 10 * 1000)
- boot_delay = 0;
+ get_option(&str, &boot_delay_val);
+ if (boot_delay_val < 0 || boot_delay_val > 10 * 1000)
+ return 0;
+
+ boot_delay = (unsigned int)boot_delay_val;
pr_debug("boot_delay: %u, preset_lpj: %ld, lpj: %lu, "
"HZ: %d, loops_per_msec: %llu\n",
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 3/6] printk: remove BOOT_PRINTK_DELAY config option
2026-07-12 10:20 [PATCH v3 0/6] printk: nbcon: deprecate boot_delay in favour of printk_delay Andrew Murray
2026-07-12 10:20 ` [PATCH v3 1/6] printk: sysctl: use unsigned int for printk_delay Andrew Murray
2026-07-12 10:20 ` [PATCH v3 2/6] printk: add bounds checking to boot_delay Andrew Murray
@ 2026-07-12 10:20 ` Andrew Murray
2026-07-12 10:20 ` [PATCH v3 4/6] printk: deprecate boot_delay in favour of printk_delay Andrew Murray
` (2 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Andrew Murray @ 2026-07-12 10:20 UTC (permalink / raw)
To: Petr Mladek, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jonathan Corbet, Shuah Khan, Russell King, Florian Fainelli,
Broadcom internal kernel review list, Ray Jui, Scott Branden,
Andrew Morton, Greg Kroah-Hartman, Sebastian Andrzej Siewior,
Clark Williams
Cc: linux-kernel, linux-doc, linux-arm-kernel, linux-rpi-kernel,
linux-rt-devel, Andrew Murray
The boot_delay (BOOT_PRINTK_DELAY) kernel parameter and printk_delay sysctl
are two distinct mechanisms for providing similar functionality which add a
delay prior to each printed printk message.
In preparation of combining them into a single configurable feature, let's
first remove the kconfig option BOOT_PRINTK_DELAY.
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Andrew Murray <amurray@thegoodpenguin.co.uk>
---
Documentation/admin-guide/kernel-parameters.txt | 2 +-
arch/arm/configs/bcm2835_defconfig | 1 -
kernel/printk/printk.c | 2 +-
lib/Kconfig.debug | 18 ------------------
4 files changed, 2 insertions(+), 21 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index b5493a7f8f22812833308b22f2cc35b0a42e55b2..2884103b93bca7b76cd3a93946276074cf62d0a1 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -651,7 +651,7 @@ Kernel parameters
boot_delay= [KNL,EARLY]
Milliseconds to delay each printk during boot.
- Only works if CONFIG_BOOT_PRINTK_DELAY is enabled,
+ Only works if GENERIC_CALIBRATE_DELAY is enabled,
and you may also have to specify "lpj=". Boot_delay
values larger than 10 seconds (10000) are assumed
erroneous and ignored.
diff --git a/arch/arm/configs/bcm2835_defconfig b/arch/arm/configs/bcm2835_defconfig
index 4a8ac09843d73280cc42dbbf63fe3cc9f31dacd2..51a1e94d5aa6c22202778082b877a202a6b9c04d 100644
--- a/arch/arm/configs/bcm2835_defconfig
+++ b/arch/arm/configs/bcm2835_defconfig
@@ -174,7 +174,6 @@ CONFIG_NLS_UTF8=y
CONFIG_DMA_CMA=y
CONFIG_CMA_SIZE_MBYTES=32
CONFIG_PRINTK_TIME=y
-CONFIG_BOOT_PRINTK_DELAY=y
CONFIG_DYNAMIC_DEBUG=y
CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
# CONFIG_ENABLE_MUST_CHECK is not set
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 8be562c9be277670ba3209ed1f810fc87175848a..28e6dff2faa7d4294c1b2ebe2844ce5d4dc0e05a 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1289,7 +1289,7 @@ static bool suppress_message_printing(int level)
return (level >= console_loglevel && !ignore_loglevel);
}
-#ifdef CONFIG_BOOT_PRINTK_DELAY
+#ifdef CONFIG_GENERIC_CALIBRATE_DELAY
static unsigned int boot_delay; /* msecs delay after each printk during bootup */
static unsigned long long loops_per_msec; /* based on boot_delay */
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 1244dcac2294ad99fda37fa6767c9e76f16a4d14..b552ea51cd53b79cf5d58b8c4deff409b1982862 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -99,24 +99,6 @@ config MESSAGE_LOGLEVEL_DEFAULT
by default. To change that, use loglevel=<x> in the kernel bootargs,
or pick a different CONSOLE_LOGLEVEL_DEFAULT configuration value.
-config BOOT_PRINTK_DELAY
- bool "Delay each boot printk message by N milliseconds"
- depends on DEBUG_KERNEL && PRINTK && GENERIC_CALIBRATE_DELAY
- help
- This build option allows you to read kernel boot messages
- by inserting a short delay after each one. The delay is
- specified in milliseconds on the kernel command line,
- using "boot_delay=N".
-
- It is likely that you would also need to use "lpj=M" to preset
- the "loops per jiffy" value.
- See a previous boot log for the "lpj" value to use for your
- system, and then set "lpj=M" before setting "boot_delay=N".
- NOTE: Using this option may adversely affect SMP systems.
- I.e., processors other than the first one may not boot up.
- BOOT_PRINTK_DELAY also may cause LOCKUP_DETECTOR to detect
- what it believes to be lockup conditions.
-
config DYNAMIC_DEBUG
bool "Enable dynamic printk() support"
default n
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 4/6] printk: deprecate boot_delay in favour of printk_delay
2026-07-12 10:20 [PATCH v3 0/6] printk: nbcon: deprecate boot_delay in favour of printk_delay Andrew Murray
` (2 preceding siblings ...)
2026-07-12 10:20 ` [PATCH v3 3/6] printk: remove BOOT_PRINTK_DELAY config option Andrew Murray
@ 2026-07-12 10:20 ` Andrew Murray
2026-07-16 13:36 ` Petr Mladek
2026-07-12 10:20 ` [PATCH v3 5/6] printk: nbcon: move printk_delay to console emiting code Andrew Murray
2026-07-12 10:20 ` [PATCH v3 6/6] Documentation/kernel-parameters: add/update printk_delay/boot_delay Andrew Murray
5 siblings, 1 reply; 11+ messages in thread
From: Andrew Murray @ 2026-07-12 10:20 UTC (permalink / raw)
To: Petr Mladek, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jonathan Corbet, Shuah Khan, Russell King, Florian Fainelli,
Broadcom internal kernel review list, Ray Jui, Scott Branden,
Andrew Morton, Greg Kroah-Hartman, Sebastian Andrzej Siewior,
Clark Williams
Cc: linux-kernel, linux-doc, linux-arm-kernel, linux-rpi-kernel,
linux-rt-devel, Andrew Murray
The boot_delay (BOOT_PRINTK_DELAY) kernel parameter and printk_delay sysctl
are two distinct mechanisms for providing similar functionality which add a
delay prior to each printed printk message.
boot_delay provides a kernel parameter for delaying printk output from
kernel start through to boot (SYSTEM_RUNNING), whereas printk_delay is
configurable only via sysctl and thus is only used post boot.
Let's deprecate the boot_delay feature in favour of printk_delay. In order
to preserve functionality, we'll also extend printk_delay such that it can
additionally configured via an early kernel parameter.
Behavior change:
The delay enabled by both "boot_delay" and "printk_delay" continues
working even in SYSTEM_RUNNING state. It must be explicitly stopped
by setting printk_delay=0 via sysctl.
The delay is skipped when the message is suppressed in all system
states. It used to skipped only for the boot_delay.
Signed-off-by: Andrew Murray <amurray@thegoodpenguin.co.uk>
---
kernel/printk/printk.c | 81 +++++++++++++++++++++++++++++++-------------------
1 file changed, 51 insertions(+), 30 deletions(-)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 28e6dff2faa7d4294c1b2ebe2844ce5d4dc0e05a..4517266e9ca112e0dcb0163a99dd0e8d50931848 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1291,43 +1291,28 @@ static bool suppress_message_printing(int level)
#ifdef CONFIG_GENERIC_CALIBRATE_DELAY
-static unsigned int boot_delay; /* msecs delay after each printk during bootup */
static unsigned long long loops_per_msec; /* based on boot_delay */
-static int __init boot_delay_setup(char *str)
+static void __init printk_delay_calculate(void)
{
unsigned long lpj;
- int boot_delay_val;
lpj = preset_lpj ? preset_lpj : 1000000; /* some guess */
loops_per_msec = (unsigned long long)lpj / 1000 * HZ;
- get_option(&str, &boot_delay_val);
- if (boot_delay_val < 0 || boot_delay_val > 10 * 1000)
- return 0;
-
- boot_delay = (unsigned int)boot_delay_val;
-
- pr_debug("boot_delay: %u, preset_lpj: %ld, lpj: %lu, "
+ pr_debug("printk_delay: %u, preset_lpj: %ld, lpj: %lu, "
"HZ: %d, loops_per_msec: %llu\n",
- boot_delay, preset_lpj, lpj, HZ, loops_per_msec);
- return 0;
+ printk_delay_msec, preset_lpj, lpj, HZ, loops_per_msec);
}
-early_param("boot_delay", boot_delay_setup);
-static void boot_delay_msec(int level)
+static void early_boot_delay_msec(void)
{
unsigned long long k;
unsigned long timeout;
- bool suppress = !is_printk_force_console() &&
- suppress_message_printing(level);
-
- if ((boot_delay == 0 || system_state >= SYSTEM_RUNNING) || suppress)
- return;
- k = (unsigned long long)loops_per_msec * boot_delay;
+ k = (unsigned long long)loops_per_msec * printk_delay_msec;
- timeout = jiffies + msecs_to_jiffies(boot_delay);
+ timeout = jiffies + msecs_to_jiffies(printk_delay_msec);
while (k) {
k--;
cpu_relax();
@@ -1342,11 +1327,37 @@ static void boot_delay_msec(int level)
}
}
#else
-static inline void boot_delay_msec(int level)
+static inline void __init printk_delay_calculate(void)
+{
+}
+
+static inline void early_boot_delay_msec(void)
{
}
#endif
+static int __init printk_delay_setup(char *str)
+{
+ int printk_delay_val = 0;
+
+ get_option(&str, &printk_delay_val);
+ if (printk_delay_val < 0 || printk_delay_val > 10 * 1000)
+ return 0;
+
+ printk_delay_msec = (unsigned int)printk_delay_val;
+ printk_delay_calculate();
+
+ return 0;
+}
+early_param("printk_delay", printk_delay_setup);
+
+static int __init boot_delay_setup(char *str)
+{
+ pr_warn("boot_delay will soon be deprecated, please use printk_delay instead\n");
+ return printk_delay_setup(str);
+}
+early_param("boot_delay", boot_delay_setup);
+
static bool printk_time = IS_ENABLED(CONFIG_PRINTK_TIME);
module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);
@@ -2122,18 +2133,28 @@ static u8 *__printk_recursion_counter(void)
unsigned int printk_delay_msec __read_mostly;
+static inline void late_boot_delay_msec(void)
+{
+ unsigned int m = printk_delay_msec;
+
+ while (m--) {
+ mdelay(1);
+ touch_nmi_watchdog();
+ }
+}
+
static inline void printk_delay(int level)
{
- boot_delay_msec(level);
+ bool suppress = !is_printk_force_console() &&
+ suppress_message_printing(level);
- if (unlikely(printk_delay_msec)) {
- unsigned int m = printk_delay_msec;
+ if (likely(!printk_delay_msec) || suppress)
+ return;
- while (m--) {
- mdelay(1);
- touch_nmi_watchdog();
- }
- }
+ if (system_state < SYSTEM_RUNNING)
+ early_boot_delay_msec();
+ else
+ late_boot_delay_msec();
}
#define CALLER_ID_MASK 0x80000000
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 5/6] printk: nbcon: move printk_delay to console emiting code
2026-07-12 10:20 [PATCH v3 0/6] printk: nbcon: deprecate boot_delay in favour of printk_delay Andrew Murray
` (3 preceding siblings ...)
2026-07-12 10:20 ` [PATCH v3 4/6] printk: deprecate boot_delay in favour of printk_delay Andrew Murray
@ 2026-07-12 10:20 ` Andrew Murray
2026-07-12 10:20 ` [PATCH v3 6/6] Documentation/kernel-parameters: add/update printk_delay/boot_delay Andrew Murray
5 siblings, 0 replies; 11+ messages in thread
From: Andrew Murray @ 2026-07-12 10:20 UTC (permalink / raw)
To: Petr Mladek, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jonathan Corbet, Shuah Khan, Russell King, Florian Fainelli,
Broadcom internal kernel review list, Ray Jui, Scott Branden,
Andrew Morton, Greg Kroah-Hartman, Sebastian Andrzej Siewior,
Clark Williams
Cc: linux-kernel, linux-doc, linux-arm-kernel, linux-rpi-kernel,
linux-rt-devel, Andrew Murray
The printk_delay and boot_delay features are helpful for debugging
as kernel output can be slowed down during boot allowing messages to
be seen before scrolling off the screen, or to correlate timing between
some physical event and console output.
However, since the introduction of nbcon and the legacy printer thread
for PREEMPT_RT kernels, printk records are now emited to the console
asynchronously to the caller of printk. Thus, any printk delay added by
boot_delay/printk_delay continues to slow down the calling process but
may not have any impact to the rate in which records are emited to the
console.
Let's address this by moving the printk delay from the calling code
to the console emiting code instead. Whilst this ensures that delays
are still observed (especially for slower consoles), it doesn't improve
the use-case of using boot_delay/printk_delay to correlate timings
between physical events and console output.
Behavior change:
Please note that printk delays now occur after messages are emitted
rather than before.
Please also note that the printk delays occur within the printk_safe
(irqs off) context.
Signed-off-by: Andrew Murray <amurray@thegoodpenguin.co.uk>
---
include/linux/console.h | 5 ++++-
include/linux/printk.h | 1 -
kernel/printk/internal.h | 6 ++++++
kernel/printk/nbcon.c | 13 +++++++++++++
kernel/printk/printk.c | 17 +++++++++--------
5 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/include/linux/console.h b/include/linux/console.h
index d624200cfc1708bf73925892a466efe0c95c5586..0f7a69bd1a42af38208fdb28971114f76f99a968 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -266,6 +266,8 @@ struct printk_buffers;
* might cause a system freeze when the console
* is used later.
* @backlog: Ringbuffer has pending records
+ * @emitted: The context attempted to emit the message. Might
+ * be incomplete.
* @pbufs: Pointer to the text buffer for this context
* @seq: The sequence number to print for this context
*/
@@ -278,6 +280,7 @@ struct nbcon_context {
/* members set by emit */
unsigned int backlog : 1;
+ unsigned char emitted : 1;
/* members set by acquire */
struct printk_buffers *pbufs;
@@ -298,7 +301,7 @@ struct nbcon_write_context {
struct nbcon_context __private ctxt;
char *outbuf;
unsigned int len;
- bool unsafe_takeover;
+ unsigned char unsafe_takeover : 1;
#ifdef CONFIG_PRINTK_EXECUTION_CTX
int cpu;
pid_t pid;
diff --git a/include/linux/printk.h b/include/linux/printk.h
index ea52dc72b73b64898f82a0319b01c27323b18dee..8885e11367d50ea1cd7642249852d011e589adb4 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -188,7 +188,6 @@ extern int __printk_ratelimit(const char *func);
extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
unsigned int interval_msec);
-extern unsigned int printk_delay_msec;
extern int dmesg_restrict;
extern void wake_up_klogd(void);
diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h
index 85fbf1801cbe070ad96d253bccdf775a11bf945a..c3586f8b8360208902bbbd4607413997bcbd5fb9 100644
--- a/kernel/printk/internal.h
+++ b/kernel/printk/internal.h
@@ -33,6 +33,8 @@ int devkmsg_sysctl_set_loglvl(const struct ctl_table *table, int write,
# define force_legacy_kthread() (false)
#endif
+extern unsigned int printk_delay_msec;
+
#ifdef CONFIG_PRINTK
#ifdef CONFIG_PRINTK_CALLER
@@ -131,6 +133,8 @@ static inline void nbcon_kthread_wake(struct console *con)
rcuwait_wake_up(&con->rcuwait); /* LMM(nbcon_kthread_wake:A) */
}
+void printk_delay(bool use_atomic);
+
#else
#define PRINTK_PREFIX_MAX 0
@@ -162,6 +166,8 @@ static inline bool nbcon_legacy_emit_next_record(struct console *con, bool *hand
static inline void nbcon_kthread_wake(struct console *con) { }
static inline void nbcon_kthreads_wake(void) { }
+static inline void printk_delay(bool use_atomic) { }
+
#endif /* CONFIG_PRINTK */
extern bool have_boot_console;
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 4b03b019cd5ee25d68e9ace84392045e91241a7f..c8427906b1c54fb00d005ef87f7280e89fae2579 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -1069,6 +1069,8 @@ static bool nbcon_emit_next_record(struct nbcon_write_context *wctxt, bool use_a
else
con->write_thread(con, wctxt);
+ ctxt->emitted = 1;
+
if (!wctxt->outbuf) {
/*
* Ownership was lost and reacquired by the driver. Handle it
@@ -1267,11 +1269,16 @@ static int nbcon_kthread_func(void *__console)
con_flags = console_srcu_read_flags(con);
+ ctxt->emitted = 0;
+
if (console_is_usable(con, con_flags, false))
backlog = nbcon_emit_one(&wctxt, false);
console_srcu_read_unlock(cookie);
+ if (backlog && ctxt->emitted)
+ printk_delay(false);
+
cond_resched();
} while (backlog);
@@ -1525,6 +1532,8 @@ bool nbcon_legacy_emit_next_record(struct console *con, bool *handover,
}
progress = nbcon_emit_one(&wctxt, use_atomic);
+ if (progress && ctxt->emitted)
+ printk_delay(use_atomic);
if (use_atomic) {
start_critical_timings();
@@ -1584,6 +1593,8 @@ static int __nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)
if (!nbcon_context_try_acquire(ctxt, false))
return -EPERM;
+ ctxt->emitted = 0;
+
/*
* nbcon_emit_next_record() returns false when
* the console was handed over or taken over.
@@ -1600,6 +1611,8 @@ static int __nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)
if (nbcon_seq_read(con) < stop_seq)
err = -ENOENT;
break;
+ } else if (ctxt->emitted) {
+ printk_delay(true);
}
}
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 4517266e9ca112e0dcb0163a99dd0e8d50931848..5df09e56cf8abc2d0555b6950eed4e483ba56d4b 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2143,18 +2143,17 @@ static inline void late_boot_delay_msec(void)
}
}
-static inline void printk_delay(int level)
+void printk_delay(bool use_atomic)
{
- bool suppress = !is_printk_force_console() &&
- suppress_message_printing(level);
-
- if (likely(!printk_delay_msec) || suppress)
+ if (likely(!printk_delay_msec))
return;
if (system_state < SYSTEM_RUNNING)
early_boot_delay_msec();
- else
+ else if (use_atomic)
late_boot_delay_msec();
+ else
+ msleep(printk_delay_msec);
}
#define CALLER_ID_MASK 0x80000000
@@ -2474,8 +2473,6 @@ asmlinkage int vprintk_emit(int facility, int level,
ft.legacy_direct = false;
}
- printk_delay(level);
-
printed_len = vprintk_store(facility, level, dev_info, fmt, args);
if (ft.nbcon_atomic)
@@ -3185,6 +3182,8 @@ static bool console_emit_next_record(struct console *con, bool *handover, int co
*/
con->write(con, outbuf, pmsg.outbuf_len);
+ printk_delay(true);
+
con->seq = pmsg.seq + 1;
} else {
/*
@@ -3206,6 +3205,7 @@ static bool console_emit_next_record(struct console *con, bool *handover, int co
printk_legacy_allow_spinlock_enter();
con->write(con, outbuf, pmsg.outbuf_len);
printk_legacy_allow_spinlock_exit();
+ printk_delay(true);
start_critical_timings();
@@ -3214,6 +3214,7 @@ static bool console_emit_next_record(struct console *con, bool *handover, int co
*handover = console_lock_spinning_disable_and_check(cookie);
printk_safe_exit_irqrestore(flags);
}
+
skip:
return true;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 6/6] Documentation/kernel-parameters: add/update printk_delay/boot_delay
2026-07-12 10:20 [PATCH v3 0/6] printk: nbcon: deprecate boot_delay in favour of printk_delay Andrew Murray
` (4 preceding siblings ...)
2026-07-12 10:20 ` [PATCH v3 5/6] printk: nbcon: move printk_delay to console emiting code Andrew Murray
@ 2026-07-12 10:20 ` Andrew Murray
2026-07-14 21:51 ` Steven Rostedt
5 siblings, 1 reply; 11+ messages in thread
From: Andrew Murray @ 2026-07-12 10:20 UTC (permalink / raw)
To: Petr Mladek, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jonathan Corbet, Shuah Khan, Russell King, Florian Fainelli,
Broadcom internal kernel review list, Ray Jui, Scott Branden,
Andrew Morton, Greg Kroah-Hartman, Sebastian Andrzej Siewior,
Clark Williams
Cc: linux-kernel, linux-doc, linux-arm-kernel, linux-rpi-kernel,
linux-rt-devel, Andrew Murray
boot_delay has been deprecated in favour of an extended printk_delay,
let's update kernel-parameters to reflect the addition of printk_delay
and the deprecation of boot_delay.
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Andrew Murray <amurray@thegoodpenguin.co.uk>
---
Documentation/admin-guide/kernel-parameters.txt | 31 +++++++++++++++++++++----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 2884103b93bca7b76cd3a93946276074cf62d0a1..1118feda87b1b04543b1da0bd52c090b1fddaeac 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -650,11 +650,19 @@ Kernel parameters
See Documentation/block/cmdline-partition.rst
boot_delay= [KNL,EARLY]
- Milliseconds to delay each printk during boot.
- Only works if GENERIC_CALIBRATE_DELAY is enabled,
- and you may also have to specify "lpj=". Boot_delay
- values larger than 10 seconds (10000) are assumed
- erroneous and ignored.
+ Milliseconds to delay each printk during and post boot.
+ Boot time delays only work if GENERIC_CALIBRATE_DELAY
+ is enabled.
+
+ Once booted the delay can be removed or adjusted via
+ the printk_delay sysctl.
+
+ Please note that you may also have to specify "lpj=".
+ Boot_delay values larger than 10 seconds (10000) are
+ assumed erroneous and ignored.
+
+ This will soon be deprecated, please use printk_delay
+ instead.
Format: integer
bootconfig [KNL,EARLY]
@@ -5468,6 +5476,19 @@ Kernel parameters
printk.time= Show timing data prefixed to each printk message line
Format: <bool> (1/Y/y=enable, 0/N/n=disable)
+ printk_delay= [KNL,EARLY]
+ Milliseconds to delay each printk during and post boot.
+ Boot time delays only work if GENERIC_CALIBRATE_DELAY
+ is enabled.
+
+ Once booted the delay can be removed or adjusted via
+ the printk_delay sysctl.
+
+ Please note that you may also have to specify "lpj=".
+ printk_delay values larger than 10 seconds (10000) are
+ assumed erroneous and ignored.
+ Format: integer
+
proc_mem.force_override= [KNL]
Format: {always | ptrace | never}
Traditionally /proc/pid/mem allows memory permissions to be
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v3 6/6] Documentation/kernel-parameters: add/update printk_delay/boot_delay
2026-07-12 10:20 ` [PATCH v3 6/6] Documentation/kernel-parameters: add/update printk_delay/boot_delay Andrew Murray
@ 2026-07-14 21:51 ` Steven Rostedt
0 siblings, 0 replies; 11+ messages in thread
From: Steven Rostedt @ 2026-07-14 21:51 UTC (permalink / raw)
To: Andrew Murray
Cc: Petr Mladek, John Ogness, Sergey Senozhatsky, Jonathan Corbet,
Shuah Khan, Russell King, Florian Fainelli,
Broadcom internal kernel review list, Ray Jui, Scott Branden,
Andrew Morton, Greg Kroah-Hartman, Sebastian Andrzej Siewior,
Clark Williams, linux-kernel, linux-doc, linux-arm-kernel,
linux-rpi-kernel, linux-rt-devel
On Sun, 12 Jul 2026 11:20:37 +0100
Andrew Murray <amurray@thegoodpenguin.co.uk> wrote:
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index 2884103b93bca7b76cd3a93946276074cf62d0a1..1118feda87b1b04543b1da0bd52c090b1fddaeac 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -650,11 +650,19 @@ Kernel parameters
> See Documentation/block/cmdline-partition.rst
>
> boot_delay= [KNL,EARLY]
> - Milliseconds to delay each printk during boot.
> - Only works if GENERIC_CALIBRATE_DELAY is enabled,
> - and you may also have to specify "lpj=". Boot_delay
> - values larger than 10 seconds (10000) are assumed
> - erroneous and ignored.
> + Milliseconds to delay each printk during and post boot.
> + Boot time delays only work if GENERIC_CALIBRATE_DELAY
> + is enabled.
> +
> + Once booted the delay can be removed or adjusted via
> + the printk_delay sysctl.
> +
> + Please note that you may also have to specify "lpj=".
> + Boot_delay values larger than 10 seconds (10000) are
> + assumed erroneous and ignored.
> +
> + This will soon be deprecated, please use printk_delay
> + instead.
> Format: integer
>
> bootconfig [KNL,EARLY]
> @@ -5468,6 +5476,19 @@ Kernel parameters
> printk.time= Show timing data prefixed to each printk message line
> Format: <bool> (1/Y/y=enable, 0/N/n=disable)
>
> + printk_delay= [KNL,EARLY]
> + Milliseconds to delay each printk during and post boot.
> + Boot time delays only work if GENERIC_CALIBRATE_DELAY
> + is enabled.
> +
> + Once booted the delay can be removed or adjusted via
> + the printk_delay sysctl.
> +
> + Please note that you may also have to specify "lpj=".
> + printk_delay values larger than 10 seconds (10000) are
> + assumed erroneous and ignored.
> + Format: integer
> +
The two parameters descriptions are identical. They should show something
different. Is it just that the "boot_delay" name is getting deprecated?
-- Steve
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 1/6] printk: sysctl: use unsigned int for printk_delay
2026-07-12 10:20 ` [PATCH v3 1/6] printk: sysctl: use unsigned int for printk_delay Andrew Murray
@ 2026-07-16 13:01 ` Petr Mladek
0 siblings, 0 replies; 11+ messages in thread
From: Petr Mladek @ 2026-07-16 13:01 UTC (permalink / raw)
To: Andrew Murray
Cc: Steven Rostedt, John Ogness, Sergey Senozhatsky, Jonathan Corbet,
Shuah Khan, Russell King, Florian Fainelli,
Broadcom internal kernel review list, Ray Jui, Scott Branden,
Andrew Morton, Greg Kroah-Hartman, Sebastian Andrzej Siewior,
Clark Williams, linux-kernel, linux-doc, linux-arm-kernel,
linux-rpi-kernel, linux-rt-devel
On Sun 2026-07-12 11:20:32, Andrew Murray wrote:
> As the printk_delay sysctl represents a duration in milliseconds,
> let's set its type to be unsigned int.
>
> Signed-off-by: Andrew Murray <amurray@thegoodpenguin.co.uk>
Makes sense:
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 2/6] printk: add bounds checking to boot_delay
2026-07-12 10:20 ` [PATCH v3 2/6] printk: add bounds checking to boot_delay Andrew Murray
@ 2026-07-16 13:13 ` Petr Mladek
0 siblings, 0 replies; 11+ messages in thread
From: Petr Mladek @ 2026-07-16 13:13 UTC (permalink / raw)
To: Andrew Murray
Cc: Steven Rostedt, John Ogness, Sergey Senozhatsky, Jonathan Corbet,
Shuah Khan, Russell King, Florian Fainelli,
Broadcom internal kernel review list, Ray Jui, Scott Branden,
Andrew Morton, Greg Kroah-Hartman, Sebastian Andrzej Siewior,
Clark Williams, linux-kernel, linux-doc, linux-arm-kernel,
linux-rpi-kernel, linux-rt-devel
On Sun 2026-07-12 11:20:33, Andrew Murray wrote:
> As the boot_delay kernel parameter represents a duration in
> milliseconds, let's set its type to be unsigned int and add
> bounds checking.
>
> Please note that the existing pr_debug will only be displayed
> when boot_delay is non-zero:
>
> pr_debug("printk_delay: %u, preset_lpj: %ld, lpj: %lu, "
> "HZ: %d, loops_per_msec: %llu\n",
> printk_delay_msec, preset_lpj, lpj, HZ, loops_per_msec);
>
> Signed-off-by: Andrew Murray <amurray@thegoodpenguin.co.uk>
> ---
> kernel/printk/printk.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 31aabdf8248cc39c54ee11685d4a37deac1c174c..8be562c9be277670ba3209ed1f810fc87175848a 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -1291,19 +1291,22 @@ static bool suppress_message_printing(int level)
>
> #ifdef CONFIG_BOOT_PRINTK_DELAY
>
> -static int boot_delay; /* msecs delay after each printk during bootup */
> +static unsigned int boot_delay; /* msecs delay after each printk during bootup */
> static unsigned long long loops_per_msec; /* based on boot_delay */
>
> static int __init boot_delay_setup(char *str)
> {
> unsigned long lpj;
> + int boot_delay_val;
As Sashiko AI pointed out [1], the variable should get initialized:
int boot_delay_val = 0;
get_option() keeps the original (random) value, for example, when the given
string is empty.
[1] https://sashiko.dev/#/patchset/20260712-printkcleanup-v3-0-574547b8f71b%40thegoodpenguin.co.uk
> lpj = preset_lpj ? preset_lpj : 1000000; /* some guess */
> loops_per_msec = (unsigned long long)lpj / 1000 * HZ;
>
> - get_option(&str, &boot_delay);
> - if (boot_delay > 10 * 1000)
> - boot_delay = 0;
> + get_option(&str, &boot_delay_val);
> + if (boot_delay_val < 0 || boot_delay_val > 10 * 1000)
> + return 0;
> +
> + boot_delay = (unsigned int)boot_delay_val;
>
> pr_debug("boot_delay: %u, preset_lpj: %ld, lpj: %lu, "
> "HZ: %d, loops_per_msec: %llu\n",
The problem gets fixed in 4th patch. But should fix it here as well
to do not break bisection. Also later changes might get reverted from
other reasons, ...
With the initialized variable:
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 4/6] printk: deprecate boot_delay in favour of printk_delay
2026-07-12 10:20 ` [PATCH v3 4/6] printk: deprecate boot_delay in favour of printk_delay Andrew Murray
@ 2026-07-16 13:36 ` Petr Mladek
0 siblings, 0 replies; 11+ messages in thread
From: Petr Mladek @ 2026-07-16 13:36 UTC (permalink / raw)
To: Andrew Murray
Cc: Steven Rostedt, John Ogness, Sergey Senozhatsky, Jonathan Corbet,
Shuah Khan, Russell King, Florian Fainelli,
Broadcom internal kernel review list, Ray Jui, Scott Branden,
Andrew Morton, Greg Kroah-Hartman, Sebastian Andrzej Siewior,
Clark Williams, linux-kernel, linux-doc, linux-arm-kernel,
linux-rpi-kernel, linux-rt-devel
On Sun 2026-07-12 11:20:35, Andrew Murray wrote:
> The boot_delay (BOOT_PRINTK_DELAY) kernel parameter and printk_delay sysctl
> are two distinct mechanisms for providing similar functionality which add a
> delay prior to each printed printk message.
>
> boot_delay provides a kernel parameter for delaying printk output from
> kernel start through to boot (SYSTEM_RUNNING), whereas printk_delay is
> configurable only via sysctl and thus is only used post boot.
>
> Let's deprecate the boot_delay feature in favour of printk_delay. In order
> to preserve functionality, we'll also extend printk_delay such that it can
> additionally configured via an early kernel parameter.
>
> Behavior change:
>
> The delay enabled by both "boot_delay" and "printk_delay" continues
> working even in SYSTEM_RUNNING state. It must be explicitly stopped
> by setting printk_delay=0 via sysctl.
>
> The delay is skipped when the message is suppressed in all system
> states. It used to skipped only for the boot_delay.
s/used to skipped/used to be skipped/
> Signed-off-by: Andrew Murray <amurray@thegoodpenguin.co.uk>
The code changes look good to me. With the above typo fix:
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-07-16 13:36 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-12 10:20 [PATCH v3 0/6] printk: nbcon: deprecate boot_delay in favour of printk_delay Andrew Murray
2026-07-12 10:20 ` [PATCH v3 1/6] printk: sysctl: use unsigned int for printk_delay Andrew Murray
2026-07-16 13:01 ` Petr Mladek
2026-07-12 10:20 ` [PATCH v3 2/6] printk: add bounds checking to boot_delay Andrew Murray
2026-07-16 13:13 ` Petr Mladek
2026-07-12 10:20 ` [PATCH v3 3/6] printk: remove BOOT_PRINTK_DELAY config option Andrew Murray
2026-07-12 10:20 ` [PATCH v3 4/6] printk: deprecate boot_delay in favour of printk_delay Andrew Murray
2026-07-16 13:36 ` Petr Mladek
2026-07-12 10:20 ` [PATCH v3 5/6] printk: nbcon: move printk_delay to console emiting code Andrew Murray
2026-07-12 10:20 ` [PATCH v3 6/6] Documentation/kernel-parameters: add/update printk_delay/boot_delay Andrew Murray
2026-07-14 21:51 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox