Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1611719 > unrolled thread
| Started by | Sergey Senozhatsky <sergey.senozhatsky@gmail.com> |
|---|---|
| First post | 2017-03-29 11:30 +0200 |
| Last post | 2017-04-04 17:20 +0200 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[RFC][PATCHv2 3/8] printk: offload printing from wake_up_klogd_work_func() Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-03-29 11:30 +0200
Re: [RFC][PATCHv2 3/8] printk: offload printing from wake_up_klogd_work_func() Petr Mladek <pmladek@suse.com> - 2017-03-31 17:00 +0200
Re: [RFC][PATCHv2 3/8] printk: offload printing from wake_up_klogd_work_func() Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-04-04 17:20 +0200
| From | Sergey Senozhatsky <sergey.senozhatsky@gmail.com> |
|---|---|
| Date | 2017-03-29 11:30 +0200 |
| Subject | [RFC][PATCHv2 3/8] printk: offload printing from wake_up_klogd_work_func() |
| Message-ID | <tqi5s-4RU-9@gated-at.bofh.it> |
Offload printing of printk_deferred() messages from IRQ context
to a schedulable printing kthread, when possible (the same way
we do it in vprintk_emit()). Otherwise, console_unlock() can
force the printing CPU to spend unbound amount of time flushing
kernel messages from IRQ context.
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
kernel/printk/printk.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index ab6b3b2a68c6..1927b5cb5cbe 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2741,8 +2741,16 @@ static void wake_up_klogd_work_func(struct irq_work *irq_work)
* If trylock fails, someone else is doing the printing.
* PRINTK_PENDING_OUTPUT bit is cleared by console_unlock().
*/
- if (console_trylock())
- console_unlock();
+ if (printk_kthread_enabled()) {
+ wake_up_process(printk_kthread);
+ } else {
+ /*
+ * If trylock fails, someone else is doing the
+ * printing
+ */
+ if (console_trylock())
+ console_unlock();
+ }
}
if (test_and_clear_bit(PRINTK_PENDING_WAKEUP, &printk_pending))
--
2.12.2
[toc] | [next] | [standalone]
| From | Petr Mladek <pmladek@suse.com> |
|---|---|
| Date | 2017-03-31 17:00 +0200 |
| Subject | Re: [RFC][PATCHv2 3/8] printk: offload printing from wake_up_klogd_work_func() |
| Message-ID | <tr6bU-5VY-21@gated-at.bofh.it> |
| In reply to | #1611719 |
On Wed 2017-03-29 18:25:06, Sergey Senozhatsky wrote:
> Offload printing of printk_deferred() messages from IRQ context
> to a schedulable printing kthread, when possible (the same way
> we do it in vprintk_emit()). Otherwise, console_unlock() can
> force the printing CPU to spend unbound amount of time flushing
> kernel messages from IRQ context.
>
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> ---
> kernel/printk/printk.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index ab6b3b2a68c6..1927b5cb5cbe 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -2741,8 +2741,16 @@ static void wake_up_klogd_work_func(struct irq_work *irq_work)
> * If trylock fails, someone else is doing the printing.
> * PRINTK_PENDING_OUTPUT bit is cleared by console_unlock().
> */
> - if (console_trylock())
> - console_unlock();
> + if (printk_kthread_enabled()) {
> + wake_up_process(printk_kthread);
Note that the relation between printk_kthread_enabled()
and wake_up_process() is racy. The conditions might change
between these two calls. It looks fine here, well almost.
The critical point is in vprintk_emit(). It must use the emergency
mode (call the consoles directly) when it is called from a process
that started the emergency mode.
We could be more relaxed here. IMHO, the only sensitive situation
is if printk_deferred() is used in the emergency context.
We might want to use the emergency mode here as well but
it is not guaranteed. printk_emergency might get cleared
in the meantime.
A solution might be to add one more bit, e.g.
PRINTK_PENDING_EMERGENCY_OUTPUT. We should force the emergency mode
here when it is set. It should be cleared together with the normal
PRINTK_PENDING_OUTPUT.
Or do you think that this is a corner case that we could
ignore for now?
Otherwise, it looks fine to me.
Best Regards,
Petr
[toc] | [prev] | [next] | [standalone]
| From | Sergey Senozhatsky <sergey.senozhatsky@gmail.com> |
|---|---|
| Date | 2017-04-04 17:20 +0200 |
| Subject | Re: [RFC][PATCHv2 3/8] printk: offload printing from wake_up_klogd_work_func() |
| Message-ID | <tsypr-6A1-5@gated-at.bofh.it> |
| In reply to | #1614088 |
Hi Petr,
sorry for the delay.
On (03/31/17 16:56), Petr Mladek wrote:
[..]
> > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> > index ab6b3b2a68c6..1927b5cb5cbe 100644
> > --- a/kernel/printk/printk.c
> > +++ b/kernel/printk/printk.c
> > @@ -2741,8 +2741,16 @@ static void wake_up_klogd_work_func(struct irq_work *irq_work)
> > * If trylock fails, someone else is doing the printing.
> > * PRINTK_PENDING_OUTPUT bit is cleared by console_unlock().
> > */
> > - if (console_trylock())
> > - console_unlock();
> > + if (printk_kthread_enabled()) {
> > + wake_up_process(printk_kthread);
>
> Note that the relation between printk_kthread_enabled()
> and wake_up_process() is racy. The conditions might change
> between these two calls. It looks fine here, well almost.
>
> The critical point is in vprintk_emit(). It must use the emergency
> mode (call the consoles directly) when it is called from a process
> that started the emergency mode.
hm, we don't guarantee this. printk(), both in threaded and in
emergency modes, can fail to acquire console_sem.
> We could be more relaxed here. IMHO, the only sensitive situation
> is if printk_deferred() is used in the emergency context.
> We might want to use the emergency mode here as well but
> it is not guaranteed.
hm, I don't think any path does
printk_emergency_begin()
printk_deferred()
printk_emergency_end()
and expects logbuf output to be flushed by the time it does
printk_emergency_end(). it's most likely something like this
printk_emergency_begin()
printk()
printk_emergency_end()
the expectations here are more reasonable, but still, no
guarantees are provided (even in non-kthreaded printk mode).
> A solution might be to add one more bit, e.g.
> PRINTK_PENDING_EMERGENCY_OUTPUT. We should force the emergency mode
> here when it is set. It should be cleared together with the normal
> PRINTK_PENDING_OUTPUT.
>
> Or do you think that this is a corner case that we could
> ignore for now?
hm, I guess we don't really count on irq_work in emergency
situations. but I need more time to think. good questions, Petr.
-ss
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web