Re: [PATCH v2] printk: Relocate wake_klogd check close to the end of console_unlock()
From: Sergey Senozhatsky
Date: Thu Feb 08 2018 - 09:53:16 EST
On (02/08/18 14:04), Petr Mladek wrote:
> We mark for waking up klogd whenever we see a new message sequence in
> the main loop. However, the actual wakeup is always at the end of the
> function and we can easily test for the wakeup condition when we do
> the final should-we-repeat check.
>
> Move the wake_klogd condition check out of the main loop. This avoids
> doing the same thing repeatedly and groups similar checks into a
> common place.
>
> This fixes a race introduced by the commit dbdda842fe96f8932 ("printk: Add
> console owner and waiter logic to load balance console writes").
> The current console owner might process the newly added message before
> the related printk() start waiting for the console lock. Then the lock
> is passed without waking klogd. The new owner sees the already updated
> seen_seq and does not know that the wakeup is needed.
I need to do more "research" on this. I though about it some time ago,
and I think that waking up klogd _only_ when we don't have any pending
logbuf messages still can be pretty late. Can't it? We can spin in
console_unlock() printing loop for a long time, probably passing
console_sem ownership between CPUs, without waking up the log_wait waiter.
May be we can wake it up from the printing loop, outside of logbuf_lock,
and let klogd to compete for logbuf_lock with the printing CPU. Why do
we wake it up only when we are done pushing messages to a potentially
slow serial console?
-ss