Message ID | 20221123231400.614679-2-john.ogness@linutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3079491wrr; Wed, 23 Nov 2022 15:14:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf7pp+i+OFh73cH48Qya9w1l0biq7KPeCWFrnFgat0J/oRdKlBwqc4GbY18F15Tf/bdoTQOa X-Received: by 2002:a17:906:a983:b0:7b8:31b1:b23f with SMTP id jr3-20020a170906a98300b007b831b1b23fmr9060096ejb.591.1669245296061; Wed, 23 Nov 2022 15:14:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669245296; cv=none; d=google.com; s=arc-20160816; b=Gxb2UWI1ZymwvVQCXUnSf6BkxhYREWuoqwnuq4tlfrhyJw/JDK+aOcOBkJoYRRVKl0 qAxbI+sB9kmqnt+ztR/NwSwfDNW0VjzM7WZzkQmzsLXKPenQg53zZOn9j7waeBaDv2HA 6oqXKwEGdqPNbYkFpTAKaNeRsASNX7Q0BFkz0j6VZOwFPd2ZcTMlIeGIedfonfI0RhA7 PRvKQtTydA3UYwRskzi98vkPLqVYlGIJHS0B5QDSsrssN80BmVx+P9KE+B/qhPYes9tk psz5tGgSn8ZLUury64W2AyMR/mjSZhvuTFYrveBzUDjO2Fm0lESAXqhpB6XqmnxoMGXd TMHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=/iaK6Q3VBEVIk95GUMPiu3drrm6jETQodWaJtL9sezc=; b=tN2A7lDC8RkUaMyYVV7S0Agj1w+1iFX2bdWOPLN+g4ubhOnO72Ew6TOdppaPVK2n7g r2QL3pDr78qWeCyW0mXWRLuW/bfsEYtF/p/c+t0KL5/BwURce/an0sWH65PGQNzWAixo /MkeE83KqkJYkl6le/+pe3RVQSHDRj4U16lJbbcYH1k0dYZxLX0Tyr2Ho7Qfajj2HbK/ 8hiVla5mAllJzbIvWQrapqJiH91TAAkc4HGCf02Y3dqx/AkxDTTkiiSY+cosjTAuJSR5 +eogIn2kn3fob2RLIHaYeFvTSYZdhxx1u6WFXFa5jld/Ju+sMrt6IqVgXYhKVpJWho4r kDAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=RPvCHbze; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=69B7EmoO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m11-20020a170906258b00b0078adad5930esi12079233ejb.255.2022.11.23.15.14.32; Wed, 23 Nov 2022 15:14:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=RPvCHbze; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=69B7EmoO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229720AbiKWXOQ (ORCPT <rfc822;fengqi706@gmail.com> + 99 others); Wed, 23 Nov 2022 18:14:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbiKWXON (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 23 Nov 2022 18:14:13 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48BB49B3B0 for <linux-kernel@vger.kernel.org>; Wed, 23 Nov 2022 15:14:12 -0800 (PST) From: John Ogness <john.ogness@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669245250; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/iaK6Q3VBEVIk95GUMPiu3drrm6jETQodWaJtL9sezc=; b=RPvCHbzeTnVF+1dfTWNpp1u2Ja4oUusnLtx0+NH6sMCxYoOR02JlqMlu3LV9oTETqz4j9n t9Wc/t26f4+a2isGNtBY6ZtXYv9rwvZifPRr+uPZTZ/t7tdUF6eIBaLN6S51VLoT14la88 0LplEnL7XKetw/yLNGMg2E5S/M+D2wzXpJucFLxf2w5ma2O2O2DcP1j+NpSWc7I4+q8TXJ NXs2eeNoeJnOYk23Gj56igQeMgwz4zJlv9LW5qk33hmFyG18sYzE0NYjS+/w1X13Z3SWZ4 76uWOnvJA2OcNSdqvW1ig1eiOkLmFlIHsEm2ym5SwmtL1R9J+L5cMliwc7i19A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669245250; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/iaK6Q3VBEVIk95GUMPiu3drrm6jETQodWaJtL9sezc=; b=69B7EmoOEwgiqYg29s+3eHdc8AjiAjVWVTXwWTObH4kfEJ8gT1qdFR7VycoxkUJPky/uGu ADMt+2TjjCRTz7DQ== To: Petr Mladek <pmladek@suse.com> Cc: Sergey Senozhatsky <senozhatsky@chromium.org>, Steven Rostedt <rostedt@goodmis.org>, Thomas Gleixner <tglx@linutronix.de>, linux-kernel@vger.kernel.org, Greg Kroah-Hartman <gregkh@linuxfoundation.org> Subject: [PATCH printk v2 1/7] printk: Move buffer size defines Date: Thu, 24 Nov 2022 00:19:54 +0106 Message-Id: <20221123231400.614679-2-john.ogness@linutronix.de> In-Reply-To: <20221123231400.614679-1-john.ogness@linutronix.de> References: <20221123231400.614679-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750330555439641824?= X-GMAIL-MSGID: =?utf-8?q?1750330555439641824?= |
Series |
printk: cleanup buffer handling
|
|
Commit Message
John Ogness
Nov. 23, 2022, 11:13 p.m. UTC
From: Thomas Gleixner <tglx@linutronix.de> Move the buffer size defines to console.h in preparation of adding a buffer structure. The new buffer structure will be embedded within struct console. Therefore console.h was chosen as the new home for these defines. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: John Ogness <john.ogness@linutronix.de> --- include/linux/console.h | 14 ++++++++++++++ include/linux/printk.h | 2 -- kernel/printk/printk.c | 4 ---- 3 files changed, 14 insertions(+), 6 deletions(-)
Comments
On Thu 2022-11-24 00:19:54, John Ogness wrote: > From: Thomas Gleixner <tglx@linutronix.de> > > Move the buffer size defines to console.h in preparation of adding a > buffer structure. The new buffer structure will be embedded within > struct console. Therefore console.h was chosen as the new home for > these defines. The buffers are not embedded into struct console in this patchset. Are they going to be added directly or via pointer, please? IMHO, it is always better to hide these implementation details in an internal header or source file. It will be possible if struct console contained on a pointer to the buffers. > Signed-off-by: Thomas Gleixner <tglx@linutronix.de> > Signed-off-by: John Ogness <john.ogness@linutronix.de> > --- > include/linux/console.h | 14 ++++++++++++++ > include/linux/printk.h | 2 -- > kernel/printk/printk.c | 4 ---- > 3 files changed, 14 insertions(+), 6 deletions(-) > > diff --git a/include/linux/console.h b/include/linux/console.h > index 9cea254b34b8..799fc3216aad 100644 > --- a/include/linux/console.h > +++ b/include/linux/console.h > @@ -122,6 +122,20 @@ static inline int con_debug_leave(void) > #define CM_ERASE (2) > #define CM_MOVE (3) > > +#ifdef CONFIG_PRINTK > + > +/* The maximum size of a formatted record (i.e. with prefix added per line) */ > +#define CONSOLE_LOG_MAX 1024 > + > +#else > + > +#define CONSOLE_LOG_MAX 0 > + > +#endif > + > +/* The maximum size of a formatted extended record */ > +#define CONSOLE_EXT_LOG_MAX 8192 It looks strange that we need the buffer for extended messages and not the normal one when !CONFIG_PRINTK. I can't find any reason for this. It looks like a historic inconsistency. CONSOLE_EXT_LOG_MAX was added into printk.h in the commit d43ff430f434d862db59 ("printk: guard the amount written per line by devkmsg_read()"). It didn't have to be in include/linux/printk.h at that time. But nobody cared, including me, I was a greenhorn ;-) Well, it would be nice to fix it when we are moving the definition next to each other. Best Regards, Petr
On 2022-11-24, Petr Mladek <pmladek@suse.com> wrote: >> Move the buffer size defines to console.h in preparation of adding a >> buffer structure. The new buffer structure will be embedded within >> struct console. Therefore console.h was chosen as the new home for >> these defines. > > The buffers are not embedded into struct console in this patchset. > Are they going to be added directly or via pointer, please? By "embedded" I mean added directly. The buffers need to be available immediately and cannot be allocated or assigned dynamically. The console struct is generally defined by drivers with: static struct console my_console = { ... }; I could think of no way to statically define the buffers but keep their sizes hidden. > IMHO, it is always better to hide these implementation details > in an internal header or source file. It will be possible > if struct console contained on a pointer to the buffers. The problem is not pointers, it is static definition (without knowing the size of the thing that is statically defined). The new thread/atomic consoles run in parallel, so they cannot share the single static buffer like we do now. >> --- a/include/linux/console.h >> +++ b/include/linux/console.h >> @@ -122,6 +122,20 @@ static inline int con_debug_leave(void) >> #define CM_ERASE (2) >> #define CM_MOVE (3) >> >> +#ifdef CONFIG_PRINTK >> + >> +/* The maximum size of a formatted record (i.e. with prefix added per line) */ >> +#define CONSOLE_LOG_MAX 1024 >> + >> +#else >> + >> +#define CONSOLE_LOG_MAX 0 >> + >> +#endif >> + >> +/* The maximum size of a formatted extended record */ >> +#define CONSOLE_EXT_LOG_MAX 8192 > > It looks strange that we need the buffer for extended messages > and not the normal one when !CONFIG_PRINTK. I can't find any reason > for this. It looks like a historic inconsistency. Yes, it looked that way to me as well. I will move it under CONFIG_PRINTK for v3. John
On Thu 2022-11-24 13:44:29, John Ogness wrote: > On 2022-11-24, Petr Mladek <pmladek@suse.com> wrote: > >> Move the buffer size defines to console.h in preparation of adding a > >> buffer structure. The new buffer structure will be embedded within > >> struct console. Therefore console.h was chosen as the new home for > >> these defines. > > > > The buffers are not embedded into struct console in this patchset. > > Are they going to be added directly or via pointer, please? > > By "embedded" I mean added directly. The buffers need to be available > immediately and cannot be allocated or assigned dynamically. The console > struct is generally defined by drivers with: > > static struct console my_console = { > ... > }; > > I could think of no way to statically define the buffers but keep their > sizes hidden. > > > IMHO, it is always better to hide these implementation details > > in an internal header or source file. It will be possible > > if struct console contained on a pointer to the buffers. > > The problem is not pointers, it is static definition (without knowing > the size of the thing that is statically defined). The new thread/atomic > consoles run in parallel, so they cannot share the single static buffer > like we do now. Let me to play a devil advocate first: Well, allocation is possible long before scheduling is possible. It is actually available even before early parameters are proceed where the boot consoles are registered. At least it is used when setup_log_buf(1) is called in setup_arch() on x86. The motivation is that only thread/atomic consoles would need the console-specific buffer. The other consoles might share the global one. It would be useful even for atomic consoles. IMHO, most users use generic kernels that support a variety of hardware. They would provide static buffers for many console drivers but only one or two would be used in the end. Also the atomic consoles would need these buffers for each context. It might be even more useful to allocate them dynamically. Or do I miss something, please? That said: I do not have any numbers at hands to show how this is important. Also I do not know if the early allocations have some limits. The static buffers might be acceptable for simplicity and reliability after all. Feel free to keep them static. I would ack the next version of this patch after making the CONSOLE_EXT_LOG_MAX dependent on CONFIG_PRINTK. Best Regards, Petr
On 2022-11-24, Petr Mladek <pmladek@suse.com> wrote: > The motivation is that only thread/atomic consoles would need > the console-specific buffer. The other consoles might share > the global one. I understand what you are saying. I will change it to a pointer and assign it to an internal shared global static buffer on register_console(). Then we can keep the size defines private. For the upcoming thread/atomic consoles, I will setup the sprint-buffers differently. > Also the atomic consoles would need these buffers for each context. > It might be even more useful to allocate them dynamically. Yes, atomic consoles need dedicated per-console, per-cpu, per-context buffers. Some of these are allocated dynamically. I will revisit this with the idea of minimizing static buffers. John
diff --git a/include/linux/console.h b/include/linux/console.h index 9cea254b34b8..799fc3216aad 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -122,6 +122,20 @@ static inline int con_debug_leave(void) #define CM_ERASE (2) #define CM_MOVE (3) +#ifdef CONFIG_PRINTK + +/* The maximum size of a formatted record (i.e. with prefix added per line) */ +#define CONSOLE_LOG_MAX 1024 + +#else + +#define CONSOLE_LOG_MAX 0 + +#endif + +/* The maximum size of a formatted extended record */ +#define CONSOLE_EXT_LOG_MAX 8192 + /* * The interface for a console, or any other device that wants to capture * console messages (printer driver?) diff --git a/include/linux/printk.h b/include/linux/printk.h index 8c81806c2e99..8ef499ab3c1e 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -44,8 +44,6 @@ static inline const char *printk_skip_headers(const char *buffer) return buffer; } -#define CONSOLE_EXT_LOG_MAX 8192 - /* printk's without a loglevel use this.. */ #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 9ec101766471..a4854a60e6d8 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -471,9 +471,6 @@ static struct latched_seq clear_seq = { #define PREFIX_MAX 32 #endif -/* the maximum size of a formatted record (i.e. with prefix added per line) */ -#define CONSOLE_LOG_MAX 1024 - /* the maximum size for a dropped text message */ #define DROPPED_TEXT_MAX 64 @@ -2387,7 +2384,6 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre #else /* CONFIG_PRINTK */ -#define CONSOLE_LOG_MAX 0 #define DROPPED_TEXT_MAX 0 #define printk_time false