lkml.org 
[lkml]   [2017]   [Jun]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC][PATCHv4 4/7] printk: enable printk offloading
Date
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@gmail.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
\
 
 \ /
  Last update: 2017-06-05 00:09    [W:0.136 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site