From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753441AbdHODAk (ORCPT ); Mon, 14 Aug 2017 23:00:40 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34570 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753208AbdHODAi (ORCPT ); Mon, 14 Aug 2017 23:00:38 -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][PATCHv5 09/13] printk: add auto-emergency enforcement mechanism Date: Tue, 15 Aug 2017 11:56:21 +0900 Message-Id: <20170815025625.1977-10-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170815025625.1977-1-sergey.senozhatsky@gmail.com> References: <20170815025625.1977-1-sergey.senozhatsky@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Do not blindly offload printing, but check if offloading has been successful. If we can't offload from this CPU for some time, then we declare printk emergency and switch to old printk behaviour (print all the pending messages with out any offloading). Signed-off-by: Sergey Senozhatsky --- kernel/printk/printk.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 12284aa30025..71950bd85eac 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -558,6 +558,15 @@ static inline void adj_atomic_print_limit(void) #endif } +static inline unsigned long emergency_timeout(unsigned long ts) +{ +#ifdef CONFIG_LOCKUP_DETECTOR + if (watchdog_thresh) + return ts + 2 * watchdog_thresh; +#endif + return ts + 10 * atomic_print_limit; +} + /* * Under heavy printing load or with a slow serial console (or both) * console_unlock() can stall CPUs, which can result in soft/hard-lockups, @@ -571,6 +580,7 @@ static inline bool console_offload_printing(void) { static struct task_struct *printing_task; static unsigned long printing_start_ts; + static unsigned long saved_csw; unsigned long now = local_clock() >> 30LL; /* seconds */ if (printk_kthread_should_stop()) @@ -585,6 +595,7 @@ static inline bool console_offload_printing(void) /* A new task - reset the counters. */ if (printing_task != current) { printing_start_ts = local_clock() >> 30LL; + saved_csw = current->nvcsw + current->nivcsw; printing_task = current; return false; } @@ -598,6 +609,17 @@ static inline bool console_offload_printing(void) if (!time_after_eq(now, printing_start_ts + atomic_print_limit)) return false; + /* + * A trivial emergency enforcement - give up on printk_kthread if + * we can't wake it up. + */ + if (time_after_eq(now, emergency_timeout(printing_start_ts)) && + saved_csw == (current->nvcsw + current->nivcsw)) { + printk_enforce_emergency = true; + pr_crit("Declaring printk emergency mode.\n"); + return true; + } + /* * We try to set `printk_kthread' CPU affinity to any online CPU * except for this_cpu. Because otherwise `printk_kthread' may be -- 2.14.1