Re: [PATCH 2/7] printk: Use consoles_suspended flag when suspending/resuming all consoles

Petr Mladek
2025-06-25T08:49:04Z

On Tue 2025-06-24 13:10:25, John Ogness wrote:
> On 2025-06-24, Petr Mladek <pmladek@suse.com> wrote:
> >> > Variant C:
> >> > ==========
> >> >
> >> > Remove even @flags parameter from console_is_usable() and read both
> >> > values there directly.
> >> >
> >> > Many callers read @flags only because they call console_is_usable().
> >> > The change would simplify the code.
> >> >
> >> > But there are few exceptions:
> >> >
> >> > 2. Another exception is __pr_flush() where console_is_usable() is
> >> > called twice with @use_atomic set "true" and "false".
> >> >
> >> > We would want to read "con->flags" only once here. A solution
> >> > would be to add a parameter to check both con->write_atomic
> >> > and con->write_thread in a single call.
> >>
> >> Or it could become a bitmask of printing types to check:
> >>
> >> #define ATOMIC_PRINTING 0x1
> >> #define NONATOMIC_PRINTING 0x2
> >>
> >> and then __pr_flush() looks like:
> >>
> >> if (!console_is_usable(c, flags, ATOMIC_PRINTING|NONATOMIC_PRINTING)
> >
> > I like this. It will help even in all other cases when one mode is needed.
> > I mean that, for example:
> >
> > console_is_usable(c, flags, ATOMIC_PRINTING)
> >
> > is more self-explaining than
> >
> > console_is_usable(c, flags, true)
>
> After I wrote that suggestion, I decided that the naming is not
> good. There is always confusion about what "atomic printing" means. For
> that reason the parameter was changed to "use_atomic". Basically we are
> specifying which callback to use and not the purpose. It is a bit tricky
> because legacy consoles do not have an atomic callback, i.e. the
> parameter only has meaning for nbcon consoles.
>
> Perhaps these macros would be more suitable:
>
> #define NBCON_USE_ATOMIC 0x1
> #define NBCON_USE_THREAD 0x2

I personally prefer this variant.

> or
>
> #define NBCON_USE_WRITE_ATOMIC 0x1
> #define NBCON_USE_WRITE_THREAD 0x2

This one sounds more precise but it very long.

> or
>
> #define NBCON_ATOMIC_CB 0x1
> #define NBCON_THREAD_CB 0x2
>
> or
>
> #define NBCON_ATOMIC_FUNC 0x1
> #define NBCON_THREAD_FUNC 0x2
>
> Hopefully that gives Petr enough ideas that he can come up with good
> naming. ;-)

I thought about better names yesterday but I somehow did not have
inspiration ;-) Thanks for coming with the variants.

Best Regards,
Petr