From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754134AbbLKG2o (ORCPT ); Fri, 11 Dec 2015 01:28:44 -0500 Received: from mail-pf0-f170.google.com ([209.85.192.170]:35433 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752611AbbLKG2m (ORCPT ); Fri, 11 Dec 2015 01:28:42 -0500 Date: Fri, 11 Dec 2015 15:29:46 +0900 From: Sergey Senozhatsky To: Jan Kara Cc: Andrew Morton , Petr Mladek , KY Srinivasan , Steven Rostedt , linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: Re: [PATCH 1/7] printk: Hand over printing to console if printing too long Message-ID: <20151211062946.GA7160@swordfish> References: <20151210145251.GA540@swordfish> <20151211042728.GA543@swordfish> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151211042728.GA543@swordfish> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (12/11/15 13:27), Sergey Senozhatsky wrote: [..] > > static bool cpu_stop_printing(int printed_chars) > > { > > /* Oops? Print everything now to maximize chances user will see it */ > > if (oops_in_progress) > > return false; > > if (!printk_offload_chars || printed_chars < printk_offload_chars) > > return false; > > /* > > * Make sure we load fresh value of printing_tasks_spinning. Matches > > * the barrier in printing_task() > > */ > > smp_rmb(); > > if (atomic_read(&printing_tasks_spinning)) > > return true; > > wake_up(&print_queue); > > > - return false; > + return true; > > } *just as an idea*, I was thinking about having two different offload limits -- for user space processes doing console_unlock() for whatever reason (printk in syscall or because of console_lock, etc.) and for KTHREADS. the kernel threads can have normal offload_limit, while user space processes can return back from syscal sooner (doing only half of printk worload, for example). but this is probably too `custom', though sort of make some sense. (compile tested only) --- kernel/printk/printk.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 79915da..cff1dd1 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -330,6 +330,7 @@ static struct kernel_param_ops offload_chars_ops = { * 0.1s maximum latency due to printing. */ static unsigned int __read_mostly printk_offload_chars = 1000; +static unsigned int __read_mostly printk_offload_limits[2] = {500, 1000}; module_param_cb(offload_chars, &offload_chars_ops, &printk_offload_chars, S_IRUGO | S_IWUSR); @@ -343,10 +344,14 @@ MODULE_PARM_DESC(offload_chars, "offload printing to console to a different" */ static bool cpu_stop_printing(int printed_chars) { + bool type = current->flags & PF_KTHREAD; + /* Oops? Print everything now to maximize chances user will see it */ if (oops_in_progress) return false; - if (!printk_offload_chars || printed_chars < printk_offload_chars) + if (!printk_offload_chars) + return false; + if (printed_chars < printk_offload_limits[type]) return false; /* * Make sure we load fresh value of printing_tasks_spinning. Matches @@ -2995,6 +3000,12 @@ out_err: return ret; } +static void offload_limits_set(void) +{ + printk_offload_limits[0] = printk_offload_chars >> 1; + printk_offload_limits[1] = printk_offload_chars; +} + static int offload_chars_set(const char *val, const struct kernel_param *kp) { int ret; @@ -3006,6 +3017,8 @@ static int offload_chars_set(const char *val, const struct kernel_param *kp) mutex_unlock(&printing_kthread_mutex); return ret; } + + offload_limits_set(); ret = printk_start_offload_kthreads(); mutex_unlock(&printing_kthread_mutex); return ret; @@ -3014,11 +3027,13 @@ static int offload_chars_set(const char *val, const struct kernel_param *kp) static void printk_offload_init(void) { mutex_lock(&printing_kthread_mutex); + offload_limits_set(); if (num_possible_cpus() <= 1) { /* Offloading doesn't make sense. Disable print offloading. */ printk_offload_chars = 0; - } else + } else { printk_start_offload_kthreads(); + } mutex_unlock(&printing_kthread_mutex); } -- 2.6.4