Skip to content

implement threaded console printing

John Ogness linux-amlogic linux-arm-msm linux-riscv lkml rcu 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest15 patches 5 repliesIn review
  2. v315 patches 21 repliesSuperseded
  3. v212 patches 24 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v113 patches73 repliesSuperseded

Changes in v4 from the cover letter

- For defer_console_output(), call allow_direct_printing() instead of only checking @printk_prefer_direct.

- Remove console_lock_single_hold() and console_unlock_single_release() functions. Use the console_lock for console_stop(), console_start(), unregister_console(), printk_kthread_func().

- Introduce macros console_flags_set() and console_flags_clear() to adjust con->flags using READ_ONCE()/WRITE_ONCE() in order to guarantee consistent values for the variable. (This does not make the RMW operations atomic, but the console_lock and con->lock are still used to synchronize between tasks that modify con->flags.)

- Add and/or expand comments for allow_direct_printing(), console_cpu_notify(), __console_unlock(), console_stop(), console_start(), unregister_console(), printk_kthread_func(), defer_console_output().

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/15printk: rename cpulock functionsinclude/linux/printk.h kernel/printk/printk.c lib/dump_stack.c +1 more+73 -600 replies
2/15printk: cpu sync always disable interruptsinclude/linux/printk.h+9 -90 replies
3/15printk: add missing memory barrier to wake_up_klogd()kernel/printk/printk.c+36 -30 replies
4/15printk: wake up all waiterskernel/printk/printk.c+1 -10 replies
5/15printk: wake waiters for safe and NMI contextskernel/printk/printk.c+16 -120 replies
6/15printk: get caller_id/timestamp after migration disablekernel/printk/printk.c+6 -40 replies
7/15printk: call boot_delay_msec() in printk_delay()kernel/printk/printk.c+4 -30 replies
8/15printk: add con_printk() macro for console detailskernel/printk/printk.c+7 -60 replies
9/15printk: refactor and rework printing logicinclude/linux/console.h kernel/printk/printk.c+230 -2130 replies
10/15printk: move buffer definitions into console_emit_next_record() callerkernel/printk/printk.c+43 -170 replies
11/15printk: add pr_flush()include/linux/printk.h kernel/printk/printk.c+90 -00 replies
12/15printk: add functions to prefer direct printingdrivers/tty/sysrq.c include/linux/printk.h kernel/hung_task.c +6 more+78 -20 replies
13/15printk: add kthread console printersinclude/linux/console.h kernel/printk/printk.c+309 -221 reply
14/15printk: extend console_lock for proper kthread supportinclude/linux/console.h kernel/printk/printk.c+248 -6344 replies
15/15printk: remove @console_lockedkernel/printk/printk.c+14 -150 replies

Reviews trailers per patch

All 15 patches have a Reviewed-by or Acked-by.

PatchPetr MladekPaul E. McKenneySergey SenozhatskyMarek Szyprowski
1/15R-b
2/15R-b R-b
3/15R-b
4/15R-b
5/15R-b
6/15R-b R-b
7/15R-b R-b
8/15R-b
9/15R-b
10/15R-b
11/15R-b
12/15R-b A-b
13/15R-b
14/15R-b R-b T-b T-b
15/15R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v4 thread

Cover letter [PATCH printk v4 00/15] implement threaded console printing

This is v4 of a series to implement a kthread for each registered console. v3 is here [0]. The kthreads locklessly retrieve the records from the printk ringbuffer and also do not cause any lock contention between each other. 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. Also, during normal operation, printk() callers are completely decoupled from console printing.

There are situations where kthread printing is not sufficient. For example, during panic situations, where the kthreads may not get a chance to schedule. In such cases, the current method of attempting to print directly within the printk() caller context is used. New functions printk_prefer_direct_enter() and printk_prefer_direct_exit() are made available to mark areas of the kernel where direct printing is preferred. (These should only be areas that do not occur during normal operation.)

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.

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.

John Ogness

[0] https://lore.kernel.org/lkml/[email protected]

Changes since v3:

- For defer_console_output(), call allow_direct_printing() instead of only checking @printk_prefer_direct.

- Remove console_lock_single_hold() and console_unlock_single_release() functions. Use the console_lock for console_stop(), console_start(), unregister_console(), printk_kthread_func().

- Introduce macros console_flags_set() and console_flags_clear() to adjust con->flags using READ_ONCE()/WRITE_ONCE() in order to guarantee consistent values for the variable. (This does not make the RMW operations atomic, but the console_lock and con->lock are still used to synchronize between tasks that modify con->flags.)

- Add and/or expand comments for allow_direct_printing(), console_cpu_notify(), __console_unlock(), console_stop(), console_start(), unregister_console(), printk_kthread_func(), defer_console_output().

John Ogness (15):
printk: rename cpulock functions
printk: cpu sync always disable interrupts
printk: add missing memory barrier to wake_up_klogd()
printk: wake up all waiters
printk: wake waiters for safe and NMI contexts
printk: get caller_id/timestamp after migration disable
printk: call boot_delay_msec() in printk_delay()
printk: add con_printk() macro for console details
printk: refactor and rework printing logic
printk: move buffer definitions into console_emit_next_record() caller
printk: add pr_flush()
printk: add functions to prefer direct printing
printk: add kthread console printers
printk: extend console_lock for proper kthread support
printk: remove @console_locked

 drivers/tty/sysrq.c     |    2 +
 include/linux/console.h |   19 +
 include/linux/printk.h  |   82 ++-
 kernel/hung_task.c      |   11 +-
 kernel/panic.c          |    4 +
 kernel/printk/printk.c  | 1234 +++++++++++++++++++++++++++++----------
 kernel/rcu/tree_stall.h |    2 +
 kernel/reboot.c         |   14 +-
 kernel/watchdog.c       |    4 +
 kernel/watchdog_hld.c   |    4 +
 lib/dump_stack.c        |    4 +-
 lib/nmi_backtrace.c     |    4 +-
 12 files changed, 1059 insertions(+), 325 deletions(-)

base-commit: 84d7df104dbab9c3dda8f2c5b46f9a6fc256fe02

Signature · 1 line
2.30.2