From: Frederic Weisbecker <fweisbec@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Steven Rostedt <rostedt@goodmis.org>
Subject: [RFC PATCH 5/5] printk: Wake up klogd with irq_work on nohz CPU
Date: Fri, 12 Oct 2012 20:09:36 +0200 [thread overview]
Message-ID: <1350065376-23353-6-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1350065376-23353-1-git-send-email-fweisbec@gmail.com>
klogd is woken up asynchronously from the tick in order
to do it safely.
However if printk is called when the tick is stopped, the reader
won't be woken up until the next interrupt, which might not fire
before a while. As a result, the user may miss some message.
To fix this we try to schedule the wake up into an irq work
when the tick is stopped and irq work is not implemented on top
of the tick.
Ideally we could always rely on irq work for this to simplify the
code. But this may result in too much interrupts in case we have
a lot of printk calls in a short period of time. So we do this when
the tick is stopped only.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
---
kernel/printk.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/kernel/printk.c b/kernel/printk.c
index 66a2ea3..c8ab918 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -42,6 +42,8 @@
#include <linux/notifier.h>
#include <linux/rculist.h>
#include <linux/poll.h>
+#include <linux/tick.h>
+#include <linux/irq_work.h>
#include <asm/uaccess.h>
@@ -1976,10 +1978,50 @@ int printk_needs_cpu(int cpu)
return __this_cpu_read(printk_pending);
}
+#ifdef CONFIG_IRQ_WORK
+static void wake_klogd_irq_work(struct irq_work *irq_work)
+{
+ printk_tick();
+}
+#endif
+
+/*
+ * When the tick is stopped, we need another way to wake up
+ * klogd safely.
+ */
+static void wake_up_klogd_nohz(void)
+{
+ /*
+ * If irq work is not itself implemented using the tick
+ * it's a safe and fast way to wake up the reader.
+ */
+#ifdef CONFIG_IRQ_WORK
+ if (!arch_irq_work_use_tick()) {
+ static struct irq_work klogd_irq_work = {
+ .func = wake_klogd_irq_work
+ };
+
+ irq_work_queue(&klogd_irq_work);
+ return;
+ }
+#endif
+ /*
+ * Our last resort in the case of idle is to bet
+ * on the fact we haven't yet reached the last need_resched()
+ * check before the CPU goes to halt. This way we go through
+ * another idle loop to recheck printk_needs_cpu().
+ */
+ if (is_idle_task(current))
+ set_need_resched();
+}
+
void wake_up_klogd(void)
{
if (waitqueue_active(&log_wait))
this_cpu_or(printk_pending, PRINTK_PENDING_WAKEUP);
+
+ if (tick_nohz_tick_stopped())
+ wake_up_klogd_nohz();
}
static void console_cont_flush(char *text, size_t size)
--
1.7.5.4
next prev parent reply other threads:[~2012-10-12 18:09 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-12 18:09 [RFC PATCH 0/5] printk: Make it usable on nohz CPUs Frederic Weisbecker
2012-10-12 18:09 ` [RFC PATCH 1/5] irq_work: Move irq_work_raise() declaration/default definition to arch headers Frederic Weisbecker
2012-10-15 16:11 ` Catalin Marinas
2012-10-15 20:02 ` Steven Rostedt
2012-10-15 20:23 ` Frederic Weisbecker
2012-10-15 20:39 ` Steven Rostedt
2012-10-15 21:34 ` Arnd Bergmann
2012-10-15 22:18 ` Frederic Weisbecker
2012-10-16 3:12 ` Mark Brown
2012-10-16 9:25 ` Arnd Bergmann
2012-10-16 15:40 ` Mark Brown
2012-10-12 18:09 ` [RFC PATCH 2/5] irq_work: Only run irq_work from tick if arch needs it Frederic Weisbecker
2012-10-12 18:09 ` [RFC PATCH 3/5] x86: Implement arch_irq_work_use_tick Frederic Weisbecker
2012-10-12 18:09 ` [RFC PATCH 4/5] nohz: Add API to check tick state Frederic Weisbecker
2012-10-12 18:09 ` Frederic Weisbecker [this message]
2012-10-19 15:50 ` [RFC PATCH 0/5] printk: Make it usable on nohz CPUs Frederic Weisbecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1350065376-23353-6-git-send-email-fweisbec@gmail.com \
--to=fweisbec@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®