From: Steven Rostedt <rostedt@goodmis.org>
To: hujinfei <3288824963@qq.com>
Cc: linux-doc@vger.kernel.org, pmladek@suse.com,
senozhatsky@chromium.org, qujingling@huawei.com,
zhangjiaji1@huawei.com, xushuangxing@huawei.com,
john.ogness@linutronix.de, hujinfei3@huawei.com
Subject: Re: [PATCH] Documentation: printk: warn about lockups from excessive use
Date: Wed, 4 Mar 2026 20:49:18 -0500 [thread overview]
Message-ID: <20260304204918.53abe94c@fedora> (raw)
In-Reply-To: <tencent_D970CEB1BE717D3D5E259943CB4510A99308@qq.com>
On Wed, 4 Mar 2026 22:40:32 +0800
hujinfei <3288824963@qq.com> wrote:
> 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.
You could also add:
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]
-- Steve
>
> Function reference
> ==================
next prev parent reply other threads:[~2026-03-05 1:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260304204918.53abe94c@fedora \
--to=rostedt@goodmis.org \
--cc=3288824963@qq.com \
--cc=hujinfei3@huawei.com \
--cc=john.ogness@linutronix.de \
--cc=linux-doc@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=qujingling@huawei.com \
--cc=senozhatsky@chromium.org \
--cc=xushuangxing@huawei.com \
--cc=zhangjiaji1@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox