public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
* Lock contention with console kthreads
@ 2025-09-09 20:14 Andrew Murray
  2025-09-10  9:14 ` Petr Mladek
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Murray @ 2025-09-09 20:14 UTC (permalink / raw)
  To: John Ogness, senozhatsky, pmladek, rostedt
  Cc: linux-serial, Andrew Murray, Michael Cobb

Hello,

Since commit 5f53ca3ff83b ("printk: Implement legacy printer kthread
for PREEMPT_RT"), and only when PREEMPT_RT is enabled, legacy consoles
use a kthread to write out to the device. This is beneficial for boot
time when using a slow console such as a serial port. However, this
gain can be short-lived as console_on_rootfs in init/main.c appears to
act as a synchronisation point.

legacy_kthread_func holds console_lock when flushing, and is held for
a long period of time during boot. Towards the end of boot,
console_on_rootfs is called which calls filp_open("/devconsole"). This
does a tty_lookup_driver which uses the console_device function to
obtain the tty_driver. console_device attempts to acquire
console_lock. At this point in time, with a (very) slow UART, progress
through kernel_init_freeable is halted waiting for the lock,
eliminating the gains of offloading to a kthread. If this could be
avoided, then boot time would be improved.

I also see something similar with an nbcon console (with
b63e6f60eab45b16a1bf734fef9035a4c4187cd5 on 8250), with
console_on_rootfs being held up by the writeout, as far as I can tell
this is due to lock contention in many places, for example with long
delays acquiring uart_port_lock_irq.

These issues can easily be reproduced by adding 'initcall_debug=1
loglevel=10' on a 8250 console at 9600 bps.

I know the legacy printer and nbcon work relate to PREEMPT_RT rather
than boot time, and so I thought I'd point out my observations as it
seems we're pretty close to getting boot time benefits from this work
as well.

Assuming my observations are correct, are these known issues, is there
any interest in accepting patches to address them? Or pointers for a
direction forward?

Andrew Murray

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

end of thread, other threads:[~2025-09-11 10:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-09 20:14 Lock contention with console kthreads Andrew Murray
2025-09-10  9:14 ` Petr Mladek
2025-09-10  9:39   ` John Ogness
2025-09-11 10:12     ` Andrew Murray

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