public inbox for linux-doc@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Documentation: printk: warn about lockups from excessive use
@ 2026-03-04 14:40 hujinfei
  2026-03-04 21:18 ` Randy Dunlap
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: hujinfei @ 2026-03-04 14:40 UTC (permalink / raw)
  To: linux-doc
  Cc: pmladek, senozhatsky, qujingling, zhangjiaji1, xushuangxing,
	rostedt, john.ogness, hujinfei3

From: hujinfei <hujinfei3@huawei.com>

Add a section 'Avoiding lockups from excessive printk() use' to
printk-basics.rst, explaining the risk of calling printk() in hot paths
with slow consoles and suggesting alternatives like ratelimited printing,
tracepoints, nbcon, and log level filtering.

Signed-off-by: hujinfei <hujinfei3@huawei.com>
---
 Documentation/core-api/printk-basics.rst | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/Documentation/core-api/printk-basics.rst b/Documentation/core-api/printk-basics.rst
index 2dde24ca7..a9da8c336 100644
--- a/Documentation/core-api/printk-basics.rst
+++ b/Documentation/core-api/printk-basics.rst
@@ -103,6 +103,28 @@ For debugging purposes there are also two conditionally-compiled macros:
 pr_debug() and pr_devel(), which are compiled-out unless ``DEBUG`` (or
 also ``CONFIG_DYNAMIC_DEBUG`` in the case of pr_debug()) is defined.
 
+Avoiding lockups from excessive printk() use
+============================================
+
+Do not use ``printk()`` in hot paths such as interrupt handlers, timer callbacks,
+or high-frequency network receive routines. When a slow console (e.g., ``console=ttyS0``)
+is active, ``printk()`` may synchronously acquire ``console_sem`` and block while
+flushing messages, potentially disabling interrupts long enough to trigger hard or
+soft lockup detectors.
+
+To avoid this:
+
+- Avoid ``printk()`` in hot paths and interrupt contexts.
+- Use rate-limited variants (e.g., pr_xxx_ratelimited()) or one-time macros (e.g., pr_*_once()).
+- Assign lower log levels (e.g., ``KERN_DEBUG``) to non-essential messages and filter
+  console output via ``console_loglevel``.
+- Use consoles that implement the non-blocking ``nbcon`` API (indicated by ``CON_NBCON``),
+  which offload message printing to a dedicated kernel thread outside emergency contexts.
+  Note that asynchronous printing increases the risk of message loss during crashes;
+  increasing the kernel log buffer size may help retain more messages.
+
+Temporary debugging may use ``trace_printk()``, but it must not appear in mainline
+code. See the section about ``trace_printk()`` in Documentation/trace/debugging.rst.
 
 Function reference
 ==================
-- 
2.33.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [PATCH] Documentation: printk: warn about lockups from excessive use
@ 2026-03-05  6:41 hujinfei
  2026-03-05 23:25 ` Randy Dunlap
  2026-03-10 15:31 ` Petr Mladek
  0 siblings, 2 replies; 7+ messages in thread
From: hujinfei @ 2026-03-05  6:41 UTC (permalink / raw)
  To: linux-doc
  Cc: pmladek, senozhatsky, qujingling, zhangjiaji1, xushuangxing,
	rostedt, john.ogness, hujinfei3

From: hujinfei <hujinfei3@huawei.com>

Add a section 'Avoiding lockups from excessive printk() use' to
printk-basics.rst, explaining the risk of calling printk() in hot paths
with slow consoles and suggesting alternatives like ratelimited printing,
tracepoints, nbcon, and log level filtering.

Signed-off-by: hujinfei <hujinfei3@huawei.com>
---
 Documentation/core-api/printk-basics.rst | 29 ++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/Documentation/core-api/printk-basics.rst b/Documentation/core-api/printk-basics.rst
index 2dde24ca7..f6ca1bc55 100644
--- a/Documentation/core-api/printk-basics.rst
+++ b/Documentation/core-api/printk-basics.rst
@@ -103,6 +103,35 @@ For debugging purposes there are also two conditionally-compiled macros:
 pr_debug() and pr_devel(), which are compiled-out unless ``DEBUG`` (or
 also ``CONFIG_DYNAMIC_DEBUG`` in the case of pr_debug()) is defined.
 
+Avoiding lockups from excessive printk() use
+============================================
+
+Do not use ``printk()`` in hot paths such as interrupt handlers, timer
+callbacks, or high-frequency network receive routines. When a slow console
+(e.g., ``console=ttyS0``) is active, ``printk()`` may synchronously acquire
+``console_sem`` and block while flushing messages, potentially disabling
+interrupts long enough to trigger hard or soft lockup detectors.
+
+To avoid this:
+
+- Avoid ``printk()`` in hot paths and interrupt contexts.
+- Use rate-limited variants (e.g., ``pr_xxx_ratelimited()``) or one-time macros
+  (e.g., ``pr_xxx_once()``).
+- Assign lower log levels (e.g., ``KERN_DEBUG``) to non-essential messages and
+  filter console output via ``console_loglevel``.
+- Use consoles that implement the non-blocking ``nbcon`` API (indicated by
+  ``CON_NBCON``), which offload message printing to a dedicated kernel thread
+  outside emergency contexts. Note that asynchronous printing increases the risk
+  of message loss during crashes; increasing the kernel log buffer size may help
+  retain more messages.
+
+Temporary debugging may use ``trace_printk()``, but it must not appear in
+mainline code. See the section about ``trace_printk()`` in
+``Documentation/trace/debugging.rst``.
+
+If more permanent output is needed in a hot path, trace events can be used. See
+``Documentation/trace/events.rst`` and
+``samples/trace_events/trace-events-sample.[ch]``.
 
 Function reference
 ==================
-- 
2.33.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-03-13 10:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-04 14:40 [PATCH] Documentation: printk: warn about lockups from excessive use hujinfei
2026-03-04 21:18 ` Randy Dunlap
2026-03-05  1:49 ` Steven Rostedt
2026-03-13 10:27 ` John Ogness
  -- strict thread matches above, loose matches on Subject: below --
2026-03-05  6:41 hujinfei
2026-03-05 23:25 ` Randy Dunlap
2026-03-10 15:31 ` Petr Mladek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox