Re: [PATCH] printk: stop spining waiter when console resume to flush prb

From: Sergey Senozhatsky
Date: Mon May 10 2021 - 04:26:56 EST


On (21/05/07 18:36), Petr Mladek wrote:
> > console_unlock()
> > {
> > ...
> >
> > if (printed_messages > limit && !console_lock_spinning_disable_and_check()) {
> > printk_safe_exit_irqrestore(flags);
> >
> > console_locked = 0;
> > up_console_sem();
> >
> > defer_console_output();
> > return;
> > }
> >
> > ...
> > }
>
> No, please, no.
>

Well, the alternative patch set just gives everyone an API that selectively
downgrades printk() to pre-console_sem_owner age: when console_unlock()
would never handover the printing duty. It'll take no time until this
function will pop up somewhere where we don't want it to be used.

E.g.

rcu_read_lock();
...
console_unlock_preemptible();
...
rcu_read_unlock();

lockdep_assert_preemption_enabled() is not entirely reliable - it
depends on __lockdep_enabled, provided that system in question has
CONFIG_PROVE_LOCKING set.

> Not to say, that defer_console_output() would trigger IRQ on the same
> CPU again and again.

You mean only on archs that have arch_irq_work_raise()?

It queues the work IF we have pending messages AND there are NO active
console_sem waiters spinning on consolse_sem waiting for us to handover
the printing duty. And IRQ shall write to consoles only N messages out
of possibly M pending messages (M > N). N, obviously, should be small,
e.g. 42 lines: if after 42 printed lines we didn't handover printing
to another context then - queue another IRQ work and iret. But it keeps
the console_owner mechanism enabled.