Re: [PATCH v6 03/11] printk: console: Implement core per-console loglevel infrastructure

From: Petr Mladek
Date: Thu Nov 14 2024 - 11:52:01 EST


On Fri 2024-11-08 17:10:31, Petr Mladek wrote:
> On Mon 2024-10-28 16:45:37, Chris Down wrote:
> > Consoles can have vastly different latencies and throughputs. For
> > example, writing a message to the serial console can take on the order
> > of tens of milliseconds to get the UART to successfully write a message.
> > While this might be fine for a single, one-off message, this can cause
> > significant application-level stalls in situations where the kernel
> > writes large amounts of information to the console.
> >
> > --- a/drivers/tty/sysrq.c
> > +++ b/drivers/tty/sysrq.c
> > @@ -101,11 +102,25 @@ __setup("sysrq_always_enabled", sysrq_always_enabled_setup);
> > static void sysrq_handle_loglevel(u8 key)
> > {
> > u8 loglevel = key - '0';
> > + int cookie;
> > + int warned = 0;
> > + struct console *con;
> >
> > console_loglevel = CONSOLE_LOGLEVEL_DEFAULT;
> > pr_info("Loglevel set to %u\n", loglevel);
> > console_loglevel = loglevel;
> > +
> > + cookie = console_srcu_read_lock();
> > + for_each_console_srcu(con) {
> > + if (!warned && per_console_loglevel_is_set(con)) {
> > + warned = 1;
> > + pr_warn("Overriding per-console loglevel from sysrq\n");

It just came to my mind. We could use pr_warn_once() and get rid
of the @warned variable. It is slightly less optimal. But this
is a slow path and the code would be easier.

> > + }
> > + WRITE_ONCE(con->level, -1);
> > + }
> > + console_srcu_read_unlock(cookie);
> > }
> > +
>

Best Regards,
Petr