From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751280AbdFBJGG (ORCPT ); Fri, 2 Jun 2017 05:06:06 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:35468 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750884AbdFBJEv (ORCPT ); Fri, 2 Jun 2017 05:04:51 -0400 From: Sergey Senozhatsky To: Petr Mladek , Steven Rostedt Cc: Jan Kara , Andrew Morton , Peter Zijlstra , "Rafael J . Wysocki" , Eric Biederman , Greg Kroah-Hartman , Jiri Slaby , Pavel Machek , Andreas Mohr , Tetsuo Handa , linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [RFC][PATCHv4 4/7] printk: enable printk offloading Date: Fri, 2 Jun 2017 18:03:42 +0900 Message-Id: <20170602090345.624-5-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170602090345.624-1-sergey.senozhatsky@gmail.com> References: <20170602090345.624-1-sergey.senozhatsky@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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