From: John Ogness <john.ogness@linutronix.de>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
linux-kernel@vger.kernel.org
Cc: Petr Mladek <pmladek@suse.com>,
Steven Rostedt <rostedt@goodmis.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>
Subject: Re: [PATCH v2] printk: Use two irq_works instead per-CPU
Date: Tue, 22 Sep 2026 19:35:26 +0200 [thread overview]
Message-ID: <87zex9tcip.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <20260914143412.1sMcp89V@linutronix.de>
On 2026-09-14, Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 6d3d18a50da74..d5cfd56f1a001 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -4593,31 +4593,26 @@ bool pr_flush(int timeout_ms, bool reset_on_progress)
> /*
> * Delayed printk version, for scheduler-internal messages:
> */
> -#define PRINTK_PENDING_WAKEUP 0x01
> -#define PRINTK_PENDING_OUTPUT 0x02
> +#define PRINTK_PENDING_OUTPUT 0x01
>
> -static DEFINE_PER_CPU(int, printk_pending);
> -
> -static void wake_up_klogd_work_func(struct irq_work *irq_work)
> +static void pending_wake_fn(struct irq_work *irq_work)
> {
> - int pending = this_cpu_xchg(printk_pending, 0);
> -
> - if (pending & PRINTK_PENDING_OUTPUT) {
> - if (force_legacy_kthread()) {
> - if (printk_legacy_kthread)
> - wake_up_interruptible(&legacy_wait);
> - } else {
> - if (console_trylock())
> - console_unlock();
> - }
> - }
> -
> - if (pending & PRINTK_PENDING_WAKEUP)
> - wake_up_interruptible(&log_wait);
> + wake_up_interruptible(&log_wait);
> }
>
> -static DEFINE_PER_CPU(struct irq_work, wake_up_klogd_work) =
> - IRQ_WORK_INIT_LAZY(wake_up_klogd_work_func);
> +static void pending_output_fn(struct irq_work *irq_work)
> +{
> + if (force_legacy_kthread()) {
> + if (printk_legacy_kthread)
> + wake_up_interruptible(&legacy_wait);
> + } else {
> + if (console_trylock())
> + console_unlock();
> + }
> +}
> +
> +static struct irq_work pending_wakeup_work = IRQ_WORK_INIT_LAZY(pending_wake_fn);
> +static struct irq_work pending_output_work = IRQ_WORK_INIT_LAZY(pending_output_fn);
>
> static void __wake_up_klogd(int val)
> {
> @@ -4631,7 +4626,6 @@ static void __wake_up_klogd(int val)
> if (WARN_ON_ONCE(console_irqwork_blocked))
> return;
>
> - preempt_disable();
> /*
> * Guarantee any new records can be seen by tasks preparing to wait
> * before this context checks if the wait queue is empty.
> @@ -4643,12 +4637,11 @@ static void __wake_up_klogd(int val)
> *
> * This pairs with devkmsg_read:A and syslog_print:A.
> */
> - if (wq_has_sleeper(&log_wait) || /* LMM(__wake_up_klogd:A) */
> - (val & PRINTK_PENDING_OUTPUT)) {
> - this_cpu_or(printk_pending, val);
> - irq_work_queue(this_cpu_ptr(&wake_up_klogd_work));
> - }
> - preempt_enable();
> + if (wq_has_sleeper(&log_wait)) /* LMM(__wake_up_klogd:A) */
> + irq_work_queue(&pending_wakeup_work);
> +
> + if (val & PRINTK_PENDING_OUTPUT)
> + irq_work_queue(&pending_output_work);
The ordering of operations has been reverse queued. Perhaps because
irq_work is LIFO (implementation internal detail) and you wanted to
preserve the current ordering? Or maybe this ordering was chosen because
the code looks nicer. Either way, I think it doesn't matter if the
legacy flushing occurs before/after waking the klogd waiter.
Reviewed-by: John Ogness <john.ogness@linutronix.de>
next prev parent reply other threads:[~2026-09-22 17:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 14:34 [PATCH v2] printk: Use two irq_works instead per-CPU Sebastian Andrzej Siewior
2026-09-22 7:08 ` Sebastian Andrzej Siewior
2026-09-22 9:29 ` Petr Mladek
2026-09-22 13:18 ` John Ogness
2026-09-22 10:02 ` Petr Mladek
2026-09-22 10:06 ` Sebastian Andrzej Siewior
2026-09-22 17:35 ` John Ogness [this message]
2026-09-23 7:55 ` Sebastian Andrzej Siewior
2026-09-23 12:16 ` Petr Mladek
2026-09-29 15:11 ` 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=87zex9tcip.fsf@jogness.linutronix.de \
--to=john.ogness@linutronix.de \
--cc=bigeasy@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.