From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753300AbdHODAK (ORCPT ); Mon, 14 Aug 2017 23:00:10 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:37470 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753208AbdHODAE (ORCPT ); Mon, 14 Aug 2017 23:00:04 -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 03/13] printk: add sync printk_emergency API Date: Tue, 15 Aug 2017 11:56:15 +0900 Message-Id: <20170815025625.1977-4-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 We already have `async' printk_emergency_begin(), which returns immediately and does not guarantee that `printk_kthread' will stop by the time it returns. Add `sync' version, which waits for `printk_kthread' to stop. Signed-off-by: Sergey Senozhatsky --- include/linux/console.h | 2 ++ kernel/printk/printk.c | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 07005db4c788..8ce29b2381d2 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -189,6 +189,8 @@ extern void resume_console(void); extern void printk_emergency_begin(void); extern void printk_emergency_end(void); +extern int printk_emergency_begin_sync(void); +extern int printk_emergency_end_sync(void); int mda_console_init(void); void prom_con_init(void); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index a86767d4d619..5d4b4beeebf5 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -485,8 +485,8 @@ static inline bool printk_kthread_should_stop(void) { if (current != printk_kthread) return false; - /* An emergency mode */ - return (atomic_read(&printk_emergency) != 0); + /* An emergency mode or a pending printk_emergency_begin_sync() */ + return (atomic_read(&printk_emergency) != 0 || kthread_should_park()); } /* @@ -509,6 +509,34 @@ void printk_emergency_end(void) } EXPORT_SYMBOL_GPL(printk_emergency_end); +/* + * This disables printing offloading and instead attempts + * to do the usual console_trylock()->console_unlock(). + * + * Note, this does wait for printk_kthread to stop. + */ +int printk_emergency_begin_sync(void) +{ + atomic_inc(&printk_emergency); + if (!printk_kthread) + return -EINVAL; + + return kthread_park(printk_kthread); +} +EXPORT_SYMBOL_GPL(printk_emergency_begin_sync); + +/* This re-enables printk_kthread offloading. */ +int printk_emergency_end_sync(void) +{ + atomic_dec(&printk_emergency); + if (!printk_kthread) + return -EINVAL; + + kthread_unpark(printk_kthread); + return 0; +} +EXPORT_SYMBOL_GPL(printk_emergency_end_sync); + /* * Under heavy printing load or with a slow serial console (or both) * console_unlock() can stall CPUs, which can result in soft/hard-lockups, @@ -2018,6 +2046,12 @@ EXPORT_SYMBOL_GPL(printk_emergency_begin); void printk_emergency_end(void) {} EXPORT_SYMBOL_GPL(printk_emergency_end); +int printk_emergency_begin_sync(void) {} +EXPORT_SYMBOL_GPL(printk_emergency_begin_sync); + +int printk_emergency_end_sync(void) {} +EXPORT_SYMBOL_GPL(printk_emergency_end_sync); + static inline bool console_offload_printing(void) { return false; } #endif /* CONFIG_PRINTK */ -- 2.14.1