From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933359AbdCXEoK (ORCPT ); Fri, 24 Mar 2017 00:44:10 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:35267 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752839AbdCXEoC (ORCPT ); Fri, 24 Mar 2017 00:44:02 -0400 Date: Fri, 24 Mar 2017 13:43:59 +0900 From: Sergey Senozhatsky To: Peter Zijlstra , Petr Mladek Cc: Steven Rostedt , Andrew Morton , Linus Torvalds , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: Re: [RFC][PATCH 0/4] printk: introduce printing kernel thread Message-ID: <20170324044359.GA448@jagdpanzerIV.localdomain> References: <20170306124554.828-1-sergey.senozhatsky@gmail.com> <20170322175920.bcltzwega6dts2n4@hirez.programming.kicks-ass.net> <20170323040958.GB2519@jagdpanzerIV.localdomain> <20170323085143.2cpxgtlmhhrvrcbw@hirez.programming.kicks-ass.net> <20170324015936.GA366@jagdpanzerIV.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170324015936.GA366@jagdpanzerIV.localdomain> User-Agent: Mutt/1.8.0 (2017-02-23) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (03/24/17 10:59), Sergey Senozhatsky wrote: [..] > and we can jump between rescue-normal printk modes, so this should > also return back the throttling of tasks which printk() a lot (item > (2) in patch set cover letter) that we used to have. ok, I obviously lied here "this should also return back the throttling". throttling is a bit hard to implement properly. automatic printk rescue mode on console output stall [when we can't wake_up printk_kthread] is not so difficult. something like below. may be it's too simple minded. // it does not handle throttling. --- kernel/printk/printk.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e84b9fbb298f..005741486376 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -447,6 +447,12 @@ static char __log_buf[__LOG_BUF_LEN] __aligned(LOG_ALIGN); static char *log_buf = __log_buf; static u32 log_buf_len = __LOG_BUF_LEN; +/* + * How many pending messages we can have in the logbuf before we + * switch to printk rescue mode (stop waking up printk_kthread). + */ +#define CONSOLE_STALL_MESSAGES_LIMIT 50 + static struct task_struct *printk_kthread __read_mostly; /* * We can't call into the scheduler (wake_up() printk kthread) during @@ -1739,6 +1745,11 @@ static size_t log_output(int facility, int level, enum log_flags lflags, const c return log_store(facility, level, lflags, 0, dict, dictlen, text, text_len); } +static bool console_output_stall(void) +{ + return (log_next_seq - console_seq) > CONSOLE_STALL_MESSAGES_LIMIT; +} + asmlinkage int vprintk_emit(int facility, int level, const char *dict, size_t dictlen, const char *fmt, va_list args) @@ -1750,6 +1761,7 @@ asmlinkage int vprintk_emit(int facility, int level, unsigned long flags; int printed_len = 0; bool in_sched = false; + bool printk_stall; if (level == LOGLEVEL_SCHED) { level = LOGLEVEL_DEFAULT; @@ -1811,6 +1823,7 @@ asmlinkage int vprintk_emit(int facility, int level, printed_len += log_output(facility, level, lflags, dict, dictlen, text, text_len); + printk_stall = console_output_stall(); set_bit(PRINTK_PENDING_OUTPUT, &printk_pending); logbuf_unlock_irqrestore(flags); @@ -1824,7 +1837,7 @@ asmlinkage int vprintk_emit(int facility, int level, * from a dedicated printk_kthread, which always runs in * schedulable context. */ - if (printk_kthread_enabled()) { + if (!printk_stall && printk_kthread_enabled()) { printk_safe_enter_irqsave(flags); wake_up_process(printk_kthread); printk_safe_exit_irqrestore(flags); -- 2.12.1