This is the next part of our printk-rework effort (points 2 and 6 of the LPC 2019 summary [0]). This series implements a kthread for each registered console. The kthreads locklessly retrieve the records from the printk ringbuffer and also do not cause any lock contention between one another. This allows consoles to run at full speed. For example, a netconsole is able to dump records much faster than a serial or vt console. There are situations where kthread printing is not sufficient. For example, during early boot before kthreads exist or during panic situations, where the kthreads may not get a chance to schedule. In these cases, the current method of printing directly within the printk() caller context is used. New functions printk_direct_enter() and printk_direct_exit() are made available to mark areas of the kernel where direct printing should be used. This series also introduces pr_flush(): a might_sleep() function that will block until all active printing threads have caught up to the latest record at the time of the pr_flush() call. This function is useful, for example, to wait until pending records are flushed to consoles before suspending. And finally, this series introduces a new console flag CON_MIGHT_SLEEP that can be set by consoles that only want their write() callback called in sleepable contexts. This was requested by Daniel Vetter [1] due to the many and growing number of deadlock situations in the fbcon code. Note that this series does *not* increase the reliability of console printing. Rather it focuses on the non-interference aspect of printk() by decoupling printk() callers from printing (during normal operation). Nonetheless, the reliability aspect should not worsen due to this series (with perhaps the exception of the fbcon, which will only print from sleepable contexts). [0] https://lore.kernel.org/lkml/87k1acz5rx.fsf@xxxxxxxxxxxxx [1] https://lore.kernel.org/all/YYuS1uNhxWOEX1Ci@phenom.ffwll.local John Ogness (13): printk: rename cpulock functions printk: cpu sync always disable interrupts printk: use percpu flag instead of cpu_online() printk: get caller_id/timestamp after migration disable printk: call boot_delay_msec() in printk_delay() printk: refactor and rework printing logic printk: move buffer definitions into console_emit_next_record() caller printk: add pr_flush() printk: add functions to allow direct printing printk: add kthread console printers printk: reimplement console_lock for proper kthread support printk: remove @console_locked console: introduce CON_MIGHT_SLEEP for vt drivers/tty/sysrq.c | 2 + drivers/tty/vt/vt.c | 2 +- include/linux/console.h | 22 +- include/linux/printk.h | 70 ++-- kernel/hung_task.c | 11 +- kernel/printk/printk.c | 903 +++++++++++++++++++++++++++++----------- kernel/rcu/tree_stall.h | 2 + kernel/reboot.c | 14 +- kernel/watchdog.c | 4 + kernel/watchdog_hld.c | 4 + lib/dump_stack.c | 6 +- lib/nmi_backtrace.c | 6 +- 12 files changed, 765 insertions(+), 281 deletions(-) base-commit: a229327733b86aa585effdb0d27a87b12aa51597 -- 2.30.2