Commit d01ff281 authored by John Ogness's avatar John Ogness Committed by Petr Mladek
Browse files

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 6690d6b5 ("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: default avatarPetr Mladek <pmladek@suse.com>
Signed-off-by: default avatarJohn Ogness <john.ogness@linutronix.de>
Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/stable/20251113160351.113031-2-john.ogness%40linutronix.de


Tested-by: default avatarSherry Sun <sherry.sun@nxp.com>
Link: https://patch.msgid.link/20251113160351.113031-2-john.ogness@linutronix.de


Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
parent 48e3694a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1849,7 +1849,7 @@ void nbcon_device_release(struct console *con)
			if (console_trylock())
				console_unlock();
		} else if (ft.legacy_offload) {
			printk_trigger_flush();
			defer_console_output();
		}
	}
	console_srcu_read_unlock(cookie);
+22 −1
Original line number Diff line number Diff line
@@ -4567,8 +4567,29 @@ void defer_console_output(void)
	__wake_up_klogd(PRINTK_PENDING_WAKEUP | PRINTK_PENDING_OUTPUT);
}

/**
 * printk_trigger_flush - Attempt to flush printk buffer to consoles.
 *
 * If possible, flush the printk buffer to all consoles in the caller's
 * context. If offloading is available, trigger deferred printing.
 *
 * This is best effort. Depending on the system state, console states,
 * and caller context, no actual flushing may result from this call.
 */
void printk_trigger_flush(void)
{
	struct console_flush_type ft;

	printk_get_console_flush_type(&ft);
	if (ft.nbcon_atomic)
		nbcon_atomic_flush_pending();
	if (ft.nbcon_offload)
		nbcon_kthreads_wake();
	if (ft.legacy_direct) {
		if (console_trylock())
			console_unlock();
	}
	if (ft.legacy_offload)
		defer_console_output();
}