All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH 0/4] printk: introduce printing kernel thread
@ 2017-03-06 12:45 Sergey Senozhatsky
  2017-03-06 12:45 ` [RFC][PATCH 1/4] " Sergey Senozhatsky
                   ` (5 more replies)
  0 siblings, 6 replies; 29+ messages in thread
From: Sergey Senozhatsky @ 2017-03-06 12:45 UTC (permalink / raw)
  To: Steven Rostedt, Petr Mladek
  Cc: Andrew Morton, Linus Torvalds, Peter Zijlstra,
	Rafael J . Wysocki, linux-kernel, Sergey Senozhatsky,
	Sergey Senozhatsky

Hello,

	RFC

	This patch set adds a printk() kernel thread which lets us to
print kernel messages to the console from a non-atomic/schedule-able
context, avoiding different sort of lockups, stalls, etc.


The patch set is in [RFC] stage - it may contain ugly and dumb ideas.
The reason I decided to take a step back is because we've been using
printk kthread in development/production for ~10 months now and there
are some observations from my side, which I want to list/outline.

 1) We had a `bool' flag to temporarily disable printk offloading (in suspend,
 hibernate, etc.) to address a bug reported by Viresh Kumar [1]. Turned out
 that our in-house kernel tweaks/ad hocs in PM code introduce nested sections
 that disable/enable printk offloading and thus `bool' flag can re-enable
 printk-kthread too early. (it wasn't me who added those PM 'tweaks' :)).

 Would there be any objections if we switch to `int' flag and allow nested
 printk-kthread enable/disable sections?


 2) Just letting you know,
 printk kthread changes the behavior of printk in one _corner case_.
 The corner case is quite interesting and actually consists of two corner
 cases. Suppose on SMP system there is only one CPU that printk()-s a lot,
 the rest of CPUs don't lock console_sem and don't printk(). Previously
 that printing CPU had been throttling itself (*) because of console drivers
 call for every printk():

          CPU0

       printk("a")
        console_unlock()
         call_console_drivers("a")

         ...

       printk("z")
        console_unlock()
         call_console_drivers("z")

 * Given that no other CPU locks the console_sem.

 With printk kthread the case turns into this one:

          CPU0                               CPU1

       printk("a")
       wake_up printk_kthread
       ...                               printk_kthread
       printk("k")                        console_unlock()
       ...                                 call_console_drivers("a")
       printk("z")                         call_console_drivers("b")
                                           call_console_drivers("c")
                                           ...


 The second 'corner case' part here is that CPU0 may be much faster
 than printing CPU, which may result in dropped printk messages.

 This all is absolutely possible even with out the printk-kthread.
 A single console_lock() call from CPUx will result in exactly the
 same condition. So it's not necessarily a regression. But there may
 be some scenarios in the kernel that may suffer from this change.
 From the top of my head -- sysrq backtrace dump, and, probably, OOM
 print out and backtrace dump.

 sysrq is potentially even trickier. can we always wake_up() kernel
 thread from sysrq? there probably might be cases when we can't rely
 on the scheduler.

 So may be we would want to export disable/enable printk-kthread offloading
 symbols and let people use them in appropriate places.

 What do you think?


 3) A minor one,
 'async printk' is, apparently, a confusing name. people assume that the
 opposite to 'asynchronous printk' is 'synchronous printk'. which is not
 the case. printk may accidentally be synchronous but in general there is
 no way to make it always synchronous on SMP system for all CPUs (well,
 except for wrapping every printk() in console_lock()/console_unlock(),
 probably), because it's up to the CPU that holds the console_sem to print
 kernel messages from console_unlock() at some point. so in some sense it's
 asynchronous by design. printk-kthread targets different aims anyway.
 but still I would probably prefer to avoid this confusion.



[1] this is from the days when printk-kthread had RT prio
    lkml.kernel.org/r/20160714221251.GE3057@ubuntu



= Patches 0001/0002 just introduce the printk kthread, it's not eanbled yet.

= Patch 0003 is incomplete and a bit ugly. I need to think more. It exposes
some printk internals and in general I'm not really happy with it. PM parts,
probably, can be kept within the printk.c. For example, disable printk-kthread
in suspend_console() and enable it in resume_console(). unlike sysrq though.

= Patch 0004 enables printk-kthread.


Sergey Senozhatsky (4):
  printk: introduce printing kernel thread
  printk: offload printing from wake_up_klogd_work_func()
  kernel, power: disable printk_kthread in unsafe places
  printk: enable printk offloading

 include/linux/console.h  |   3 ++
 kernel/kexec_core.c      |   4 ++
 kernel/power/hibernate.c |   8 +++
 kernel/power/suspend.c   |   4 ++
 kernel/printk/printk.c   | 133 ++++++++++++++++++++++++++++++++++++++++++++---
 5 files changed, 144 insertions(+), 8 deletions(-)

-- 
2.12.0

^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2017-04-04 13:00 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-06 12:45 [RFC][PATCH 0/4] printk: introduce printing kernel thread Sergey Senozhatsky
2017-03-06 12:45 ` [RFC][PATCH 1/4] " Sergey Senozhatsky
2017-03-22 16:40   ` Petr Mladek
2017-03-23  5:12     ` Sergey Senozhatsky
2017-03-23 10:40       ` Petr Mladek
2017-03-24  5:20         ` Sergey Senozhatsky
2017-03-06 12:45 ` [RFC][PATCH 2/4] printk: offload printing from wake_up_klogd_work_func() Sergey Senozhatsky
2017-03-17 12:19   ` Petr Mladek
2017-03-18  9:57     ` Sergey Senozhatsky
2017-03-20 16:09       ` Petr Mladek
2017-03-21  4:01         ` Sergey Senozhatsky
2017-03-23  9:00         ` Sergey Senozhatsky
2017-03-23 12:11           ` Petr Mladek
2017-03-06 12:45 ` [RFC][PATCH 3/4] kernel, power: disable printk_kthread in unsafe places Sergey Senozhatsky
2017-03-22 15:38   ` Petr Mladek
2017-03-22 15:38     ` Petr Mladek
2017-03-06 12:45 ` [RFC][PATCH 4/4] printk: enable printk offloading Sergey Senozhatsky
2017-03-22 15:43   ` Petr Mladek
2017-03-22 16:40     ` Sergey Senozhatsky
2017-03-22 17:59 ` [RFC][PATCH 0/4] printk: introduce printing kernel thread Peter Zijlstra
2017-03-23  4:09   ` Sergey Senozhatsky
2017-03-23  8:51     ` Peter Zijlstra
2017-03-24  1:59       ` Sergey Senozhatsky
2017-03-24  4:43         ` Sergey Senozhatsky
2017-03-24 14:43         ` Petr Mladek
2017-03-25  0:18           ` Sergey Senozhatsky
2017-03-23 12:01   ` Petr Mladek
2017-04-03 11:53 ` Sergey Senozhatsky
2017-04-04 12:59   ` Petr Mladek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.