From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754311AbbLJPMe (ORCPT ); Thu, 10 Dec 2015 10:12:34 -0500 Received: from mail-pf0-f182.google.com ([209.85.192.182]:33963 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751187AbbLJPL5 (ORCPT ); Thu, 10 Dec 2015 10:11:57 -0500 Date: Fri, 11 Dec 2015 00:10:25 +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 5/7] printk: Add config option for disabling printk offloading Message-ID: <20151210151025.GD540@swordfish> Reply-To: 1445835169-8203-6-git-send-email-jack@suse.com MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 > Necessity for offloading of printing was observed only for large > systems. So add a config option (disabled by default) which removes most > of the overhead added by this functionality. to be folded: - add spin_lock_init_print_lock() to be called from zap_lock() - move PRINTK_OFFLOAD defines up, so zap_lock() sees them --- kernel/printk/printk.c | 119 ++++++++++++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 56 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 2a500a5..86f5abf 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -333,7 +333,66 @@ module_param_cb(offload_chars, &offload_chars_ops, &printk_offload_chars, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(offload_chars, "offload printing to console to a different" " cpu after this number of characters"); -#endif + +/* + * Returns true iff there is other cpu waiting to take over printing. This + * function also takes are of setting PRINTK_HANDOVER_B if we want to hand over + * printing to some other cpu. + */ +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; +} + +static bool cpu_should_cond_resched(bool do_cond_resched) +{ + /* Oops? Print everything now to maximize chances user will see it */ + if (oops_in_progress) + return false; + if (!printk_offload_chars && do_cond_resched) + return true; + return false; +} + +#define spin_lock_print_lock(flags) raw_spin_lock_irqsave(&print_lock, flags) + +#define spin_unlock_print_lock(flags) raw_spin_unlock_irqrestore(&print_lock, flags) + +#define spin_lock_init_print_lock() raw_spin_lock_init(&print_lock) + +#else /* !CONFIG_PRINTK_OFFLOAD */ + +static bool cpu_stop_printing(int printed_chars) +{ + return false; +} + +static bool cpu_should_cond_resched(bool do_cond_resched) +{ + return do_cond_resched && !oops_in_progress; +} + +#define spin_lock_print_lock(flags) local_irq_save(flags) + +#define spin_unlock_print_lock(flags) local_irq_restore(flags) + +#define spin_lock_init_print_lock() + +#endif /* CONFIG_PRINTK_OFFLOAD */ /* Return log buffer address */ char *log_buf_addr_get(void) @@ -1531,7 +1590,7 @@ static void zap_locks(void) /* If a crash is occurring, make sure we can't deadlock */ raw_spin_lock_init(&logbuf_lock); /* And make sure that we print immediately */ - raw_spin_lock_init(&print_lock); + spin_lock_init_print_lock(); sema_init(&console_sem, 1); } @@ -2265,58 +2324,6 @@ out: raw_spin_unlock_irqrestore(&logbuf_lock, flags); } -#ifdef CONFIG_PRINTK_OFFLOAD -/* - * Returns true iff there is other cpu waiting to take over printing. This - * function also takes are of setting PRINTK_HANDOVER_B if we want to hand over - * printing to some other cpu. - */ -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; -} - -static bool cpu_should_cond_resched(bool do_cond_resched) -{ - /* Oops? Print everything now to maximize chances user will see it */ - if (oops_in_progress) - return false; - if (!printk_offload_chars && do_cond_resched) - return true; - return false; -} - -#define spin_lock_print_lock(flags) raw_spin_lock_irqsave(&print_lock, flags) - -#define spin_unlock_print_lock(flags) raw_spin_unlock_irqrestore(&print_lock, flags) - -#else - -static bool cpu_stop_printing(int printed_chars) -{ - return false; -} - -#define spin_lock_print_lock(flags) local_irq_save(flags) - -#define spin_unlock_print_lock(flags) local_irq_restore(flags) - -#endif - /** * console_unlock - unlock the console system * @@ -2440,9 +2447,9 @@ skip: printed_chars += len; if (unlikely(cpu_should_cond_resched(do_cond_resched))) { - raw_spin_unlock_irqrestore(&print_lock, flags); + spin_unlock_print_lock(flags); cond_resched(); - raw_spin_lock_irqsave(&print_lock, flags); + spin_lock_print_lock(flags); } } -- 2.6.3