Skip to content

Commit d01ff28

Browse files
jognesspmladek
authored andcommitted
printk: Allow printk_trigger_flush() to flush all types
Currently printk_trigger_flush() only triggers legacy offloaded flushing, even if that may not be the appropriate method to flush for currently registered consoles. (The function predates the NBCON consoles.) Since commit 6690d6b ("printk: Add helper for flush type logic") there is printk_get_console_flush_type(), which also considers NBCON consoles and reports all the methods of flushing appropriate based on the system state and consoles available. Update printk_trigger_flush() to use printk_get_console_flush_type() to appropriately flush registered consoles. Suggested-by: Petr Mladek <pmladek@suse.com> Signed-off-by: John Ogness <john.ogness@linutronix.de> Reviewed-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/stable/20251113160351.113031-2-john.ogness%40linutronix.de Tested-by: Sherry Sun <sherry.sun@nxp.com> Link: https://patch.msgid.link/20251113160351.113031-2-john.ogness@linutronix.de Signed-off-by: Petr Mladek <pmladek@suse.com>
1 parent 48e3694 commit d01ff28

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

kernel/printk/nbcon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,7 @@ void nbcon_device_release(struct console *con)
18491849
if (console_trylock())
18501850
console_unlock();
18511851
} else if (ft.legacy_offload) {
1852-
printk_trigger_flush();
1852+
defer_console_output();
18531853
}
18541854
}
18551855
console_srcu_read_unlock(cookie);

kernel/printk/printk.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4567,9 +4567,30 @@ void defer_console_output(void)
45674567
__wake_up_klogd(PRINTK_PENDING_WAKEUP | PRINTK_PENDING_OUTPUT);
45684568
}
45694569

4570+
/**
4571+
* printk_trigger_flush - Attempt to flush printk buffer to consoles.
4572+
*
4573+
* If possible, flush the printk buffer to all consoles in the caller's
4574+
* context. If offloading is available, trigger deferred printing.
4575+
*
4576+
* This is best effort. Depending on the system state, console states,
4577+
* and caller context, no actual flushing may result from this call.
4578+
*/
45704579
void printk_trigger_flush(void)
45714580
{
4572-
defer_console_output();
4581+
struct console_flush_type ft;
4582+
4583+
printk_get_console_flush_type(&ft);
4584+
if (ft.nbcon_atomic)
4585+
nbcon_atomic_flush_pending();
4586+
if (ft.nbcon_offload)
4587+
nbcon_kthreads_wake();
4588+
if (ft.legacy_direct) {
4589+
if (console_trylock())
4590+
console_unlock();
4591+
}
4592+
if (ft.legacy_offload)
4593+
defer_console_output();
45734594
}
45744595

45754596
int vprintk_deferred(const char *fmt, va_list args)

0 commit comments

Comments
 (0)