From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754271AbdLDNsx (ORCPT ); Mon, 4 Dec 2017 08:48:53 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:43912 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752874AbdLDNsp (ORCPT ); Mon, 4 Dec 2017 08:48:45 -0500 X-Google-Smtp-Source: AGs4zMboKk3jA116MDKIJW1+JDBogu9lNLF5kPHAHZqlxRuRJTWdOI9kW9NKP9xG8Tx/Fm6/LjoeuA== From: Sergey Senozhatsky To: Steven Rostedt , Petr Mladek Cc: Jan Kara , Andrew Morton , Peter Zijlstra , Rafael Wysocki , Pavel Machek , Tetsuo Handa , Tejun Heo , linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [RFC][PATCHv6 01/12] printk: move printk_pending out of per-cpu Date: Mon, 4 Dec 2017 22:48:14 +0900 Message-Id: <20171204134825.7822-2-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171204134825.7822-1-sergey.senozhatsky@gmail.com> References: <20171204134825.7822-1-sergey.senozhatsky@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Do not keep `printk_pending' in per-CPU area. We set the following bits of printk_pending: a) PRINTK_PENDING_WAKEUP when we need to wakeup klogd b) PRINTK_PENDING_OUTPUT when there is a pending output from deferred printk and we need to call console_unlock(). So none of the bits control/represent a state of a particular CPU and, basically, they should be global instead. Besides we will use `printk_pending' to control printk kthread, so this patch is also a preparation work. Signed-off-by: Sergey Senozhatsky Suggested-by: Petr Mladek --- kernel/printk/printk.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 8aa27be96012..81c19e51a4a4 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -401,6 +401,14 @@ DEFINE_RAW_SPINLOCK(logbuf_lock); } while (0) #ifdef CONFIG_PRINTK +/* + * Delayed printk version, for scheduler-internal messages: + */ +#define PRINTK_PENDING_WAKEUP 0x01 +#define PRINTK_PENDING_OUTPUT 0x02 + +static unsigned long printk_pending; + DECLARE_WAIT_QUEUE_HEAD(log_wait); /* the next printk record to read by syslog(READ) or /proc/kmsg */ static u64 syslog_seq; @@ -2677,25 +2685,15 @@ static int __init printk_late_init(void) late_initcall(printk_late_init); #if defined CONFIG_PRINTK -/* - * Delayed printk version, for scheduler-internal messages: - */ -#define PRINTK_PENDING_WAKEUP 0x01 -#define PRINTK_PENDING_OUTPUT 0x02 - -static DEFINE_PER_CPU(int, printk_pending); - static void wake_up_klogd_work_func(struct irq_work *irq_work) { - int pending = __this_cpu_xchg(printk_pending, 0); - - if (pending & PRINTK_PENDING_OUTPUT) { + if (test_and_clear_bit(PRINTK_PENDING_OUTPUT, &printk_pending)) { /* If trylock fails, someone else is doing the printing */ if (console_trylock()) console_unlock(); } - if (pending & PRINTK_PENDING_WAKEUP) + if (test_and_clear_bit(PRINTK_PENDING_WAKEUP, &printk_pending)) wake_up_interruptible(&log_wait); } @@ -2708,7 +2706,7 @@ void wake_up_klogd(void) { preempt_disable(); if (waitqueue_active(&log_wait)) { - this_cpu_or(printk_pending, PRINTK_PENDING_WAKEUP); + set_bit(PRINTK_PENDING_WAKEUP, &printk_pending); irq_work_queue(this_cpu_ptr(&wake_up_klogd_work)); } preempt_enable(); @@ -2721,7 +2719,7 @@ int vprintk_deferred(const char *fmt, va_list args) r = vprintk_emit(0, LOGLEVEL_SCHED, NULL, 0, fmt, args); preempt_disable(); - __this_cpu_or(printk_pending, PRINTK_PENDING_OUTPUT); + set_bit(PRINTK_PENDING_OUTPUT, &printk_pending); irq_work_queue(this_cpu_ptr(&wake_up_klogd_work)); preempt_enable(); -- 2.15.1