From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754421AbdLDNtp (ORCPT ); Mon, 4 Dec 2017 08:49:45 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:40306 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752640AbdLDNtj (ORCPT ); Mon, 4 Dec 2017 08:49:39 -0500 X-Google-Smtp-Source: AGs4zMYOyFk7KCtLJPtJJyVguKoyrwU+n5700e7dWVkmT4jvzfSIm+OTDB5WtuzeM9jqd+jfmqUq4w== 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 09/12] printk: do not cond_resched() when we can offload Date: Mon, 4 Dec 2017 22:48:22 +0900 Message-Id: <20171204134825.7822-10-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 console_unlock() may sleep with console_sem locked, which is a bit counter intuitive: we neither print pending logbuf messages to the serial console, nor let anyone else to do it for us. With printing offloading enabled, however, we can disable preemption, because we know for sure how long we can stay in console_unlock() and that eventually we will offload to another task. Signed-off-by: Sergey Senozhatsky --- kernel/printk/printk.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 4d91182e25e3..2a12d4c02da1 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2074,6 +2074,7 @@ int printk_emergency_end_sync(void) { return 0; } EXPORT_SYMBOL_GPL(printk_emergency_end_sync); static bool should_handoff_printing(u64 printing_start_ts) { return false; } +static bool printk_offloading_enabled(void) { return false; } #endif /* CONFIG_PRINTK */ #ifdef CONFIG_EARLY_PRINTK @@ -2385,6 +2386,14 @@ void console_unlock(void) * and cleared after the the "again" goto label. */ do_cond_resched = console_may_schedule; + /* + * Forbid scheduling under the console_sem lock when offloading + * is enabled. Scheduling will just slow down the print out in + * this case. + */ + if (printk_offloading_enabled()) + do_cond_resched = 0; + again: console_may_schedule = 0; @@ -2400,6 +2409,7 @@ void console_unlock(void) return; } + preempt_disable(); for (;;) { struct printk_log *msg; size_t ext_len = 0; @@ -2461,8 +2471,11 @@ void console_unlock(void) do_handoff = should_handoff_printing(printing_start_ts); printk_safe_exit_irqrestore(flags); - if (!do_handoff && do_cond_resched) + if (!do_handoff && do_cond_resched) { + preempt_enable(); cond_resched(); + preempt_disable(); + } } console_locked = 0; @@ -2473,6 +2486,7 @@ void console_unlock(void) raw_spin_unlock(&logbuf_lock); up_console_sem(); + preempt_enable(); /* * Someone could have filled up the buffer again, so re-check -- 2.15.1