[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20170602090345.624-5-sergey.senozhatsky@gmail.com>
Date: Fri, 2 Jun 2017 18:03:42 +0900
From: Sergey Senozhatsky <sergey.senozhatsky@...il.com>
To: Petr Mladek <pmladek@...e.com>,
Steven Rostedt <rostedt@...dmis.org>
Cc: Jan Kara <jack@...e.cz>, Andrew Morton <akpm@...ux-foundation.org>,
Peter Zijlstra <peterz@...radead.org>,
"Rafael J . Wysocki" <rjw@...ysocki.net>,
Eric Biederman <ebiederm@...ssion.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Jiri Slaby <jslaby@...e.com>, Pavel Machek <pavel@....cz>,
Andreas Mohr <andi@...as.de>,
Tetsuo Handa <penguin-kernel@...ove.SAKURA.ne.jp>,
linux-kernel@...r.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>
Subject: [RFC][PATCHv4 4/7] printk: enable printk offloading
Initialize kernel printing thread and make printk offloading
possible. By default `atomic_print_limit' is set to 0, so no
offloading will take place, unless requested by user.
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@...il.com>
---
kernel/printk/printk.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index a1d3a69a023b..ed0df3d21215 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2942,6 +2942,60 @@ static DEFINE_PER_CPU(struct irq_work, wake_up_klogd_work) = {
.flags = IRQ_WORK_LAZY,
};
+static void printk_kthread_func(unsigned int cpu)
+{
+ while (1) {
+ set_current_state(TASK_INTERRUPTIBLE);
+ if (!test_bit(PRINTK_PENDING_OUTPUT, &printk_pending))
+ schedule();
+
+ __set_current_state(TASK_RUNNING);
+
+ if (kthread_should_stop())
+ break;
+
+ if (kthread_should_park()) {
+ kthread_parkme();
+ /* We might have been woken for stop */
+ continue;
+ }
+
+ console_lock();
+ console_unlock();
+ }
+}
+
+static int printk_kthread_should_run(unsigned int cpu)
+{
+ return test_bit(PRINTK_PENDING_OUTPUT, &printk_pending);
+}
+
+static struct smp_hotplug_thread printk_kthreads = {
+ .store = &printk_kthread,
+ .thread_should_run = printk_kthread_should_run,
+ .thread_fn = printk_kthread_func,
+ .thread_comm = "printk/%u",
+};
+
+/*
+ * Init printk kthread at late_initcall stage, after core/arch/device/etc.
+ * initialization.
+ */
+static int __init init_printk_kthreads(void)
+{
+ cpumask_copy(&printk_cpumask, cpu_possible_mask);
+
+ if (smpboot_register_percpu_thread_cpumask(&printk_kthreads,
+ &printk_cpumask)) {
+ printk_enforce_emergency = true;
+ pr_err("printk: failed to create threads\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+late_initcall(init_printk_kthreads);
+
void wake_up_klogd(void)
{
preempt_disable();
--
2.13.0
Powered by blists - more mailing lists