From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754351AbdLDNtW (ORCPT ); Mon, 4 Dec 2017 08:49:22 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:40161 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754326AbdLDNtH (ORCPT ); Mon, 4 Dec 2017 08:49:07 -0500 X-Google-Smtp-Source: AGs4zMbQwPXL/JOpljY/UVvyZphJyOkQMKwZ5pgcv5UZiGsgZ5B0g3GqWerPcQndsNYC64YFqLNvgg== From: Sergey Senozhatsky To: Steven Rostedt , Petr Mladek Cc: Jan Kara , Andrew Morton , Peter Zijlstra , Rafael Wysocki , Pavel Machek , Tetsuo Handa , Tejun Heo , linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [RFC][PATCHv6 05/12] printk: enable printk offloading Date: Mon, 4 Dec 2017 22:48:18 +0900 Message-Id: <20171204134825.7822-6-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171204134825.7822-1-sergey.senozhatsky@gmail.com> References: <20171204134825.7822-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 `offloading_enabled' module parameter is set to `false', so no offloading will take place, unless requested by user. Signed-off-by: Sergey Senozhatsky --- kernel/printk/printk.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 16f5f5c7e541..a427cee2aa00 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2914,6 +2914,65 @@ static DEFINE_PER_CPU(struct irq_work, wake_up_klogd_work) = { .flags = IRQ_WORK_LAZY, }; +static int printk_kthread_func(void *data) +{ + while (1) { + set_current_state(TASK_INTERRUPTIBLE); + /* + * We must check `printk_emergency' as well, to let + * printk_emergency_begin() stop active `printk_kthread' at + * some point. Otherwise we can end up in a loop: + * - we bail out of console_unlock() because of + * printk_kthread_should_stop() + * and + * - don't schedule() and attempt to return back + * immediately to console_unlock() because we + * see PRINTK_PENDING_OUTPUT bit set. + */ + if (!test_bit(PRINTK_PENDING_OUTPUT, &printk_pending) || + atomic_read(&printk_emergency) != 0) + schedule(); + + __set_current_state(TASK_RUNNING); + + /* We might have been woken for stop */ + if (kthread_should_park()) + kthread_parkme(); + + console_lock(); + console_unlock(); + + /* We might have been blocked on console_sem */ + if (kthread_should_park()) + kthread_parkme(); + } + + return 0; +} + +/* + * Init printk kthread at late_initcall stage, after core/arch/device/etc. + * initialization. + */ +static int __init init_printk_kthread(void) +{ + struct task_struct *thread; + + if (!alloc_cpumask_var(&printk_offload_cpus, GFP_KERNEL)) + return -ENOMEM; + + thread = kthread_run(printk_kthread_func, NULL, "printk"); + if (IS_ERR(thread)) { + pr_err("printk: unable to create printing thread\n"); + free_cpumask_var(printk_offload_cpus); + return PTR_ERR(thread); + } + + printk_kthread = thread; + return 0; +} +late_initcall(init_printk_kthread); + void wake_up_klogd(void) { preempt_disable(); -- 2.15.1