Re: printk meeting at LPC

From: Sergey Senozhatsky
Date: Tue Sep 17 2019 - 22:37:07 EST


On (09/17/19 22:08), Steven Rostedt wrote:
> > On (09/13/19 15:26), John Ogness wrote:
> > > 2. A kernel thread will be created for each registered console, each
> > > responsible for being the sole printers to their respective
> > > consoles. With this, console printing is _fully_ decoupled from printk()
> > > callers.
> >
> > sysrq over serial?
> >
> > What we currently have is hacky, but, as usual, is a "best effort":
> >
> > >> serial driver IRQ
> >
> > serial_handle_irq() [console driver]
> > uart_handle_sysrq_char()
> > handle_sysrq()
> > printk()
> > call_console_drivers()
> > serial_write() [re-enter console driver]
> >
> > offloading this to kthread may be unreliable.
>
> But we also talked about an "emergency flush" which will not wait for
> the kthreads to finish and just output everything it can find in the
> printk buffers (expecting that the consoles have an "emergency"
> handler. We can add a sysrq to do an emergency flush.

I'm sorry, I wasn't there, so I'm surely is missing on some details.

I agree that when consoles have ->atomic_write then it surely makes sense
to switch to emergency mode. I like the emergency state approach, but I'm
not sure how it can be completely invisible to the rest of the system.
Quoting John:

: Unlike oops_in_progress, this state will not be visible to
: anything outside of the printk infrastructure.

For instance, tty/sysrq must be able to switch printk emergency on/off.
That already means that printk emergency knob should be visible to the
rest of the kernel. A long time ago, we had printk_emergency_begin_sync()
and printk_emergency_end_sync(), which would define reentrable
printk_emergency blocks [1]:

printk_emergency_begin_sync();
handle_sysrq();
printk_emergency_end_sync();

We also figured out that some PM (hibernation/suspend/etc.) stages (very
early and/or very late ones) [2] also should have printk in emergency mode,
plus some other parts of the kernel [3].

[1] https://lore.kernel.org/lkml/20170815025625.1977-4-sergey.senozhatsky@xxxxxxxxx/
[2] https://lore.kernel.org/lkml/20170815025625.1977-7-sergey.senozhatsky@xxxxxxxxx/
[3] https://lore.kernel.org/lkml/20170815025625.1977-8-sergey.senozhatsky@xxxxxxxxx/

-ss