printk: Reduce pr_flush() pooling time
authorPetr Mladek <pmladek@suse.com>
Fri, 6 Oct 2023 08:21:51 +0000 (10:21 +0200)
committerPetr Mladek <pmladek@suse.com>
Wed, 11 Oct 2023 12:04:10 +0000 (14:04 +0200)
commit29fda1ad2a64a62e1c51d61207396e2de1c67362
tree573ef8f7c3ba7ef2389fcffabd97255033e25ced
parent054c22bd784d6953ac85f545bed4a2a27b0e4ddb
printk: Reduce pr_flush() pooling time

pr_flush() does not guarantee that all messages would really get flushed
to the console. The best it could do is to wait with a given timeout.[*]

The current interval 100ms for checking the progress might seem too
long in some situations. For example, such delays are not appreciated
during suspend and resume especially when the consoles have been flushed
"long" time before the check.

On the other hand, the sleeping wait might be useful in other situations.
Especially, it would allow flushing the messages using printk kthreads
on the same CPU[*].

Use msleep(1) as a compromise.

Also measure the time using jiffies. msleep() does not guarantee
precise wakeup after the given delay. It might be much longer,
especially for times < 20s. See Documentation/timers/timers-howto.rst
for more details.

Note that msecs_to_jiffies() already translates a negative value into
an infinite timeout.

[*] console_unlock() does not guarantee flushing the consoles since
    the commit dbdda842fe96f893 ("printk: Add console owner and waiter
    logic to load balance console writes").

    It would be possible to guarantee it another way. For example,
    the spinning might be enabled only when the console_lock has been
    taken via console_trylock().

    But the load balancing is helpful. And more importantly, the flush
    with a timeout has been added as a preparation step for introducing
    printk kthreads.

Signed-off-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: John Ogness <john.ogness@linutronix.de>
Link: https://lore.kernel.org/r/20231006082151.6969-3-pmladek@suse.com
kernel/printk/printk.c