On Sat 2025-12-27 09:16:11, Marcos Paulo de Souza wrote:
> This change partially reverts commit 9e70a5e109a4
> ("printk: Add per-console suspended state"). The intent of the original
> commit was to move the management of the console suspended state to the
> consoles themselves to be able to use SRCU instead of console lock.
>
> But having a global state is still useful when checking if the global
> suspend was triggered by power management. This way, instead of setting
> the state of each individual console, the code would only set/read from the
> global state.
>
> Along with this change, two more fixes are necessary: change
> console_{suspend,resume} to set/clear CON_SUSPEND instead of setting
> CON_ENABLED and change show_cons_active to call __console_is_usable to
> check console usefulness.
I would invert the logic a bit. I think that the main motivation
is to replace CON_ENABLE -> CON_SUSPEND.
<proposal>
The flag CON_ENABLE is cleared when serial drivers get suspended. This
"hack" has been added by the commit 33c0d1b0c3ebb6 ("[PATCH] Serial
driver stuff") back in v2.5.28.
Stop hijacking CON_ENABLE flag and use the CON_SUSPEND flag instead.
Still allow to distinguish when:
- the backing device is being suspended, see console_suspend().
- the power management wants to calm down all consoles using
a big-hammer, see console_suspend_all().
And restore the global "consoles_suspended" flag which was removed
by the commit 9e70a5e109a4 ("printk: Add per-console suspended state").
The difference is that accesses to the new global flag are
synchronized the same way as to the CON_SUSPEND flag. It allows
to read it under console_srcu_read_lock().
Finally, use __console_is_usable() in show_cons_active(). It is the
last location where the CON_ENABLED flag was checked directly.
The patch should not change the existing behavior because all users check
the state of the console using console_is_usable().
</proposal>
> diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
> index e2d92cf70eb7..7d2bded75b75 100644
> --- a/drivers/tty/tty_io.c
> +++ b/drivers/tty/tty_io.c
> @@ -3552,9 +3552,9 @@ static ssize_t show_cons_active(struct device *dev,
> for_each_console(c) {
> if (!c->device)
> continue;
> - if (!(c->flags & CON_NBCON) && !c->write)
> - continue;
> - if ((c->flags & CON_ENABLED) == 0)
> + if (!__console_is_usable(c, c->flags,
> + consoles_suspended,
> + NBCON_USE_ANY))
It would be better to move this into a separate patch.
> continue;
> cs[i++] = c;
> if (i >= ARRAY_SIZE(cs))
Otherwise, it looks good.
Best Regards,
Petr