Message ID | 20221125190948.2062-2-linux@weissschuh.net |
---|---|
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 q4csp4238025wrr; Fri, 25 Nov 2022 11:11:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf6bM/W5IRnd/PNbazJLoEmQlZWr3z1YFPynbEd8vL1PiYBVaRCbTu6RIDMrB6u5romFuEnX X-Received: by 2002:a63:5850:0:b0:46e:f67c:c0a7 with SMTP id i16-20020a635850000000b0046ef67cc0a7mr35523417pgm.464.1669403502630; Fri, 25 Nov 2022 11:11:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669403502; cv=none; d=google.com; s=arc-20160816; b=vtcLSOCevluF6voqqCu1pmkfTw4aGjGTwJkwCt5NmWKQr1Y6wQnxC10GzdZbfzNlea QQ6WaMhokNWsDgqmRMeQ0c9GTVqDIrsL03sUaGj1TDjnVnV4jqSKpelkaPcE2EGaVQ9C cG+yWGjlb73uB6v6hH/dmhaOxHQOs2EMnOfc9FFG1qhgPmOlbxfIlYPx3/C/z6op5tdy gSfGA6X9dl4+F9mIFAb6P5VdHCFtQrIkK6NUJVvuQ8Y3M6Bvc9Er4YovVuI+/PsaY0cm Ka2azA5Fe73CmsKn5P1iTGGFDx5NealpmpPCSND2irUv86YbMTU6pREzacLnkIDkKT64 v15A== 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 :from; bh=AInAeJQRa0wUnLsqszPOtT5W97/Tl9OXthaU8zwZmKI=; b=H1/jTSxumGf3IuXJxo5BPx94hJ1pJiotpv+pDDp0aMACybWuzMrLTePkMEEpiv27R2 /pbW3Sgv90XH+FZL6FuQEU/4fmb6YLtJ7YnpJZ8wU/jMi23h1z4SzJS53Nc9ff+6D9Vt qKAMtPw/sd6JFQwlOAydO8tYhzzyL26FE8w9zghdt0SkXESeeQ75OdnwfMPAsHh8QG94 xrTa7+fH2NfE5m1k/PbDYOkoGOK4+s867QZYwg2/5ZVvyKN/iwP35vAuXvrsWTbbVVsJ VjSVmE9i3KOEqpeJfsZza2q15nBSIRkTq49CLvcG/f9rUOjZCJ+Lk1VFUiZLjTYs9rEI eZwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b=CdjwjO5h; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mu10-20020a17090b388a00b0020d5dfb9d69si5326548pjb.187.2022.11.25.11.11.29; Fri, 25 Nov 2022 11:11:42 -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=fail header.i=@weissschuh.net header.s=mail header.b=CdjwjO5h; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229847AbiKYTKQ (ORCPT <rfc822;zxc52fgh@gmail.com> + 99 others); Fri, 25 Nov 2022 14:10:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbiKYTKO (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 25 Nov 2022 14:10:14 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE920554E9 for <linux-kernel@vger.kernel.org>; Fri, 25 Nov 2022 11:10:12 -0800 (PST) From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net> DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1669403409; bh=Cfs+sOQDL6GBgQ3fenqAT1FujV3he1f3Lpmpy6WNGIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CdjwjO5hHtwgwX90USoA3/oYV6gNtrbEg2T9br83TK4zdDJz6VEWprrsMkCEyvepp PUB2jhZPZu/9ERMHp8awa/NpE4O55WPPfRNpkBArX3qyjoKkMYY6qFKJ6AYFFZNbTp LoHFvTGLPJslEBlrSWMXLfJZLDQva+Kk9Vuypl2s= To: "Rafael J. Wysocki" <rafael@kernel.org>, Pavel Machek <pavel@ucw.cz>, Len Brown <len.brown@intel.com>, linux-pm@vger.kernel.org, Petr Mladek <pmladek@suse.com>, Sergey Senozhatsky <senozhatsky@chromium.org>, Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com> Cc: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>, linux-kernel@vger.kernel.org, Steven Rostedt <rostedt@goodmis.org>, Dwaipayan Ray <dwaipayanray1@gmail.com>, Lukas Bulwahn <lukas.bulwahn@gmail.com> Subject: [PATCH v2 1/3] printk: introduce new macros pr_<level>_cont() Date: Fri, 25 Nov 2022 20:09:46 +0100 Message-Id: <20221125190948.2062-2-linux@weissschuh.net> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221125190948.2062-1-linux@weissschuh.net> References: <20221125190948.2062-1-linux@weissschuh.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Developer-Signature: v=1; a=ed25519-sha256; t=1669403373; l=2153; i=linux@weissschuh.net; s=20211113; h=from:subject; bh=Cfs+sOQDL6GBgQ3fenqAT1FujV3he1f3Lpmpy6WNGIY=; b=HrAjdosSOqn753OZecTREHBNiVZHFXNRlI3g1j+9iLw4cn/f064kUy61f5eptIvvv5OiNU3b0iWm VqdxqwJmBCtf2AP3qCG9Gek6WHudS6izrr6XXVq30kQbg1PoiGz4 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=9LP6KM4vD/8CwHW7nouRBhWLyQLcK1MkP6aTZbzUlj4= Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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?1750496447396228338?= X-GMAIL-MSGID: =?utf-8?q?1750496447396228338?= |
Series |
printk: introduce new macros pr_<level>_cont()
|
|
Commit Message
Thomas Weißschuh
Nov. 25, 2022, 7:09 p.m. UTC
These macros emit continuation messages with explicit levels.
In case the continuation is logged separately from the original message
it will retain its level instead of falling back to KERN_DEFAULT.
This remedies the issue that logs filtered by level contain stray
continuation messages without context.
Suggested-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
include/linux/printk.h | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
Comments
On Fri, 2022-11-25 at 20:09 +0100, Thomas Weißschuh wrote: > These macros emit continuation messages with explicit levels. > In case the continuation is logged separately from the original message > it will retain its level instead of falling back to KERN_DEFAULT. > > This remedies the issue that logs filtered by level contain stray > continuation messages without context. > > Suggested-by: Petr Mladek <pmladek@suse.com> > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > --- > include/linux/printk.h | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/include/linux/printk.h b/include/linux/printk.h > index 8c81806c2e99..8f564c38f121 100644 > --- a/include/linux/printk.h > +++ b/include/linux/printk.h > @@ -537,6 +537,8 @@ struct pi_entry { > * This macro expands to a printk with KERN_CONT loglevel. It should only be > * used when continuing a log message with no newline ('\n') enclosed. Otherwise > * it defaults back to KERN_DEFAULT loglevel. > + * > + * Use the dedicated pr_<level>_cont() macros instead. > */ > #define pr_cont(fmt, ...) \ > printk(KERN_CONT fmt, ##__VA_ARGS__) > @@ -701,6 +703,27 @@ do { \ > no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) > #endif > > +/* > + * Print a continuation message with level. In case the continuation is split > + * from the main message it preserves the level. > + */ > + > +#define pr_emerg_cont(fmt, ...) \ > + printk(KERN_EMERG KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) Aren't this rather backwards? KERN_CONT KERN_<LEVEL> seems to make more sense to me. > +#define pr_alert_cont(fmt, ...) \ > + printk(KERN_ALERT KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > +#define pr_crit_cont(fmt, ...) \ > + printk(KERN_CRIT KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > +#define pr_err_cont(fmt, ...) \ > + printk(KERN_ERR KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > +#define pr_warn_cont(fmt, ...) \ > + printk(KERN_WARN KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > +#define pr_notice_cont(fmt, ...) \ > + printk(KERN_NOTICE KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > +#define pr_info_cont(fmt, ...) \ > + printk(KERN_INFO KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > +/* no pr_debug_ratelimited, it doesn't make sense with CONFIG_DYNAMIC_DEBUG. */ > + > extern const struct file_operations kmsg_fops; > > enum {
On 2022-11-25 12:18-0800, Joe Perches wrote: > On Fri, 2022-11-25 at 20:09 +0100, Thomas Weißschuh wrote: >> These macros emit continuation messages with explicit levels. >> In case the continuation is logged separately from the original message >> it will retain its level instead of falling back to KERN_DEFAULT. >> >> This remedies the issue that logs filtered by level contain stray >> continuation messages without context. >> >> Suggested-by: Petr Mladek <pmladek@suse.com> >> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> >> --- >> include/linux/printk.h | 23 +++++++++++++++++++++++ >> 1 file changed, 23 insertions(+) >> >> diff --git a/include/linux/printk.h b/include/linux/printk.h >> index 8c81806c2e99..8f564c38f121 100644 >> --- a/include/linux/printk.h >> +++ b/include/linux/printk.h >> @@ -537,6 +537,8 @@ struct pi_entry { >> * This macro expands to a printk with KERN_CONT loglevel. It should only be >> * used when continuing a log message with no newline ('\n') enclosed. Otherwise >> * it defaults back to KERN_DEFAULT loglevel. >> + * >> + * Use the dedicated pr_<level>_cont() macros instead. >> */ >> #define pr_cont(fmt, ...) \ >> printk(KERN_CONT fmt, ##__VA_ARGS__) >> @@ -701,6 +703,27 @@ do { \ >> no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) >> #endif >> >> +/* >> + * Print a continuation message with level. In case the continuation is split >> + * from the main message it preserves the level. >> + */ >> + >> +#define pr_emerg_cont(fmt, ...) \ >> + printk(KERN_EMERG KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > > Aren't this rather backwards? > KERN_CONT KERN_<LEVEL> seems to make more sense to me. If nobody else disagrees I'll do this for v3. >> +#define pr_alert_cont(fmt, ...) \ >> + printk(KERN_ALERT KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) >> +#define pr_crit_cont(fmt, ...) \ >> + printk(KERN_CRIT KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) >> +#define pr_err_cont(fmt, ...) \ >> + printk(KERN_ERR KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) >> +#define pr_warn_cont(fmt, ...) \ >> + printk(KERN_WARN KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) >> +#define pr_notice_cont(fmt, ...) \ >> + printk(KERN_NOTICE KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) >> +#define pr_info_cont(fmt, ...) \ >> + printk(KERN_INFO KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) >> +/* no pr_debug_ratelimited, it doesn't make sense with CONFIG_DYNAMIC_DEBUG. */ >> + >> extern const struct file_operations kmsg_fops; >> >> enum { >
On Fri 2022-11-25 21:33:40, Thomas Weißschuh wrote: > On 2022-11-25 12:18-0800, Joe Perches wrote: > > On Fri, 2022-11-25 at 20:09 +0100, Thomas Weißschuh wrote: > >> These macros emit continuation messages with explicit levels. > >> In case the continuation is logged separately from the original message > >> it will retain its level instead of falling back to KERN_DEFAULT. > >> > >> This remedies the issue that logs filtered by level contain stray > >> continuation messages without context. > >> > >> --- a/include/linux/printk.h > >> +++ b/include/linux/printk.h > >> @@ -701,6 +703,27 @@ do { \ > >> no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) > >> #endif > >> > >> +/* > >> + * Print a continuation message with level. In case the continuation is split > >> + * from the main message it preserves the level. > >> + */ > >> + > >> +#define pr_emerg_cont(fmt, ...) \ > >> + printk(KERN_EMERG KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > > > > Aren't this rather backwards? > > KERN_CONT KERN_<LEVEL> seems to make more sense to me. > > If nobody else disagrees I'll do this for v3. I slightly prefer the way how it is now. IMHO, it makes it easier to check the related levels in /sys/kernel/debug/printk/index/vmlinux [*]: <6> kernel/power/process.c:227 thaw_kernel_threads "Restarting kernel threads ... " <6,c> kernel/power/process.c:218 thaw_processes "done.\n" <6> kernel/power/process.c:197 thaw_processes "Restarting tasks ... " <6,c> kernel/power/process.c:176 freeze_kernel_threads "\n" <6,c> kernel/power/process.c:174 freeze_kernel_threads "done." <6> kernel/power/process.c:169 freeze_kernel_threads "Freezing remaining freezable tasks ... " <6,c> kernel/power/process.c:140 freeze_processes "\n" <6,c> kernel/power/process.c:138 freeze_processes "done." <6> kernel/power/process.c:133 freeze_processes "Freezing user space processes ... " <6,c> kernel/power/process.c:105 try_to_freeze_tasks "(elapsed %d.%03d seconds) " That said, I do not want to fight over it. It is hidden behind the API. The only really visible place is the printk index. [*] The index is available only when CONFIG_PRINTK_INDEX is enabled. Best Regards, Petr
On Fri 2022-11-25 20:09:46, Thomas Weißschuh wrote: > These macros emit continuation messages with explicit levels. > In case the continuation is logged separately from the original message > it will retain its level instead of falling back to KERN_DEFAULT. > > This remedies the issue that logs filtered by level contain stray > continuation messages without context. > > Suggested-by: Petr Mladek <pmladek@suse.com> > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > --- > include/linux/printk.h | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/include/linux/printk.h b/include/linux/printk.h > index 8c81806c2e99..8f564c38f121 100644 > --- a/include/linux/printk.h > +++ b/include/linux/printk.h > @@ -537,6 +537,8 @@ struct pi_entry { > * This macro expands to a printk with KERN_CONT loglevel. It should only be > * used when continuing a log message with no newline ('\n') enclosed. Otherwise > * it defaults back to KERN_DEFAULT loglevel. > + * > + * Use the dedicated pr_<level>_cont() macros instead. > */ > #define pr_cont(fmt, ...) \ > printk(KERN_CONT fmt, ##__VA_ARGS__) > @@ -701,6 +703,27 @@ do { \ > no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) > #endif > > +/* > + * Print a continuation message with level. In case the continuation is split > + * from the main message it preserves the level. > + */ > + > +#define pr_emerg_cont(fmt, ...) \ > + printk(KERN_EMERG KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > +#define pr_alert_cont(fmt, ...) \ > + printk(KERN_ALERT KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > +#define pr_crit_cont(fmt, ...) \ > + printk(KERN_CRIT KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > +#define pr_err_cont(fmt, ...) \ > + printk(KERN_ERR KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > +#define pr_warn_cont(fmt, ...) \ > + printk(KERN_WARN KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > +#define pr_notice_cont(fmt, ...) \ > + printk(KERN_NOTICE KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > +#define pr_info_cont(fmt, ...) \ > + printk(KERN_INFO KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > +/* no pr_debug_ratelimited, it doesn't make sense with CONFIG_DYNAMIC_DEBUG. */ I guess that you wanted to write "pr_debug_cont". Also I am not sure what you mean with "doesn't make sense". IMHO, it might make sense. But it would be hard to use and error prone with CONFIG_DYNAMIC_DEBUG. And more importantly, it probably would not work properly. If I get it corretly the dynamic debug messages are printed by the wrapper: void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...) { [...] vaf.fmt = fmt; vaf.va = &args; printk(KERN_DEBUG "%s%pV", dynamic_emit_prefix(descriptor, buf), &vaf); [...] This clearly does not support KERN_CONT in "fmt". I suggest to either remove the comment completely. Or write something like: /* no pr_debug_cont(), can't be supported easily with CONFIG_DYNAMIC_DEBUG */ Best Regards, Petr
On 2022-11-30 14:59+0100, Petr Mladek wrote: > On Fri 2022-11-25 21:33:40, Thomas Weißschuh wrote: >> On 2022-11-25 12:18-0800, Joe Perches wrote: >>> On Fri, 2022-11-25 at 20:09 +0100, Thomas Weißschuh wrote: >>>> These macros emit continuation messages with explicit levels. >>>> In case the continuation is logged separately from the original message >>>> it will retain its level instead of falling back to KERN_DEFAULT. >>>> >>>> This remedies the issue that logs filtered by level contain stray >>>> continuation messages without context. >>>> >>>> --- a/include/linux/printk.h >>>> +++ b/include/linux/printk.h >>>> @@ -701,6 +703,27 @@ do { \ >>>> no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) >>>> #endif >>>> >>>> +/* >>>> + * Print a continuation message with level. In case the continuation is split >>>> + * from the main message it preserves the level. >>>> + */ >>>> + >>>> +#define pr_emerg_cont(fmt, ...) \ >>>> + printk(KERN_EMERG KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) >>> >>> Aren't this rather backwards? >>> KERN_CONT KERN_<LEVEL> seems to make more sense to me. >> >> If nobody else disagrees I'll do this for v3. > > I slightly prefer the way how it is now. IMHO, it makes it easier > to check the related levels in /sys/kernel/debug/printk/index/vmlinux [*]: > > <6> kernel/power/process.c:227 thaw_kernel_threads "Restarting kernel threads ... " > <6,c> kernel/power/process.c:218 thaw_processes "done.\n" > <6> kernel/power/process.c:197 thaw_processes "Restarting tasks ... " > <6,c> kernel/power/process.c:176 freeze_kernel_threads "\n" > <6,c> kernel/power/process.c:174 freeze_kernel_threads "done." > <6> kernel/power/process.c:169 freeze_kernel_threads "Freezing remaining freezable tasks ... " > <6,c> kernel/power/process.c:140 freeze_processes "\n" > <6,c> kernel/power/process.c:138 freeze_processes "done." > <6> kernel/power/process.c:133 freeze_processes "Freezing user space processes ... " > <6,c> kernel/power/process.c:105 try_to_freeze_tasks "(elapsed %d.%03d seconds) " I did not test it (will do so later) but it seems to me that the code in kernel/printk/index.c should do this correctly in either case. At least it tries to: if (flags & LOG_CONT) { /* * LOGLEVEL_DEFAULT here means "use the same level as the * message we're continuing from", not the default message * loglevel, so don't display it as such. */ if (level == LOGLEVEL_DEFAULT) seq_puts(s, "<c>"); else seq_printf(s, "<%d,c>", level); } else seq_printf(s, "<%d>", level); } } I'll try to validate it. If it doesn't work it may make more sense to fix the index file generation. What do you think > That said, I do not want to fight over it. It is hidden behind the > API. The only really visible place is the printk index. > > [*] The index is available only when CONFIG_PRINTK_INDEX is enabled. > > Best Regards, > Petr Thomas
On 2022-11-30 15:23+0100, Petr Mladek wrote: > On Fri 2022-11-25 20:09:46, Thomas Weißschuh wrote: >> These macros emit continuation messages with explicit levels. >> In case the continuation is logged separately from the original message >> it will retain its level instead of falling back to KERN_DEFAULT. >> >> This remedies the issue that logs filtered by level contain stray >> continuation messages without context. >> >> Suggested-by: Petr Mladek <pmladek@suse.com> >> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> >> --- >> include/linux/printk.h | 23 +++++++++++++++++++++++ >> 1 file changed, 23 insertions(+) >> >> diff --git a/include/linux/printk.h b/include/linux/printk.h >> index 8c81806c2e99..8f564c38f121 100644 >> --- a/include/linux/printk.h >> +++ b/include/linux/printk.h >> @@ -537,6 +537,8 @@ struct pi_entry { >> * This macro expands to a printk with KERN_CONT loglevel. It should only be >> * used when continuing a log message with no newline ('\n') enclosed. Otherwise >> * it defaults back to KERN_DEFAULT loglevel. >> + * >> + * Use the dedicated pr_<level>_cont() macros instead. >> */ >> #define pr_cont(fmt, ...) \ >> printk(KERN_CONT fmt, ##__VA_ARGS__) >> @@ -701,6 +703,27 @@ do { \ >> no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) >> #endif >> >> +/* >> + * Print a continuation message with level. In case the continuation is split >> + * from the main message it preserves the level. >> + */ >> + >> +#define pr_emerg_cont(fmt, ...) \ >> + printk(KERN_EMERG KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) >> +#define pr_alert_cont(fmt, ...) \ >> + printk(KERN_ALERT KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) >> +#define pr_crit_cont(fmt, ...) \ >> + printk(KERN_CRIT KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) >> +#define pr_err_cont(fmt, ...) \ >> + printk(KERN_ERR KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) >> +#define pr_warn_cont(fmt, ...) \ >> + printk(KERN_WARN KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) >> +#define pr_notice_cont(fmt, ...) \ >> + printk(KERN_NOTICE KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) >> +#define pr_info_cont(fmt, ...) \ >> + printk(KERN_INFO KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) >> +/* no pr_debug_ratelimited, it doesn't make sense with CONFIG_DYNAMIC_DEBUG. */ > > I guess that you wanted to write "pr_debug_cont". Indeed. > Also I am not sure what you mean with "doesn't make sense". IMHO, it > might make sense. But it would be hard to use and error prone > with CONFIG_DYNAMIC_DEBUG. > > And more importantly, it probably would not work properly. If I get > it corretly the dynamic debug messages are printed by the wrapper: > > void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...) > { > [...] > vaf.fmt = fmt; > vaf.va = &args; > > printk(KERN_DEBUG "%s%pV", dynamic_emit_prefix(descriptor, buf), &vaf); > [...] > > This clearly does not support KERN_CONT in "fmt". Good point. My doubt was more that it would force users to know which message continuations belong together and always enable all of them together with dynamic debug. Which would be very errorprone and annoying to use. But if it doesn't work at all that's an even stronger point. > I suggest to either remove the comment completely. Or write something > like: > > /* no pr_debug_cont(), can't be supported easily with CONFIG_DYNAMIC_DEBUG */ What about: /* no pr_debug_cont(), it's errorprone to use * and can't be supported easily with CONFIG_DYNAMIC_DEBUG */ Thomas
On Wed 2022-11-30 15:50:55, Thomas Weißschuh wrote: > On 2022-11-30 14:59+0100, Petr Mladek wrote: > > On Fri 2022-11-25 21:33:40, Thomas Weißschuh wrote: > >> On 2022-11-25 12:18-0800, Joe Perches wrote: > >>> On Fri, 2022-11-25 at 20:09 +0100, Thomas Weißschuh wrote: > >>>> These macros emit continuation messages with explicit levels. > >>>> In case the continuation is logged separately from the original message > >>>> it will retain its level instead of falling back to KERN_DEFAULT. > >>>> > >>>> This remedies the issue that logs filtered by level contain stray > >>>> continuation messages without context. > >>>> > >>>> --- a/include/linux/printk.h > >>>> +++ b/include/linux/printk.h > >>>> @@ -701,6 +703,27 @@ do { \ > >>>> no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) > >>>> #endif > >>>> > >>>> +/* > >>>> + * Print a continuation message with level. In case the continuation is split > >>>> + * from the main message it preserves the level. > >>>> + */ > >>>> + > >>>> +#define pr_emerg_cont(fmt, ...) \ > >>>> + printk(KERN_EMERG KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > >>> > >>> Aren't this rather backwards? > >>> KERN_CONT KERN_<LEVEL> seems to make more sense to me. > >> > >> If nobody else disagrees I'll do this for v3. > > > > I slightly prefer the way how it is now. IMHO, it makes it easier > > to check the related levels in /sys/kernel/debug/printk/index/vmlinux [*]: > > > > <6> kernel/power/process.c:227 thaw_kernel_threads "Restarting kernel threads ... " > > <6,c> kernel/power/process.c:218 thaw_processes "done.\n" > > <6> kernel/power/process.c:197 thaw_processes "Restarting tasks ... " > > <6,c> kernel/power/process.c:176 freeze_kernel_threads "\n" > > <6,c> kernel/power/process.c:174 freeze_kernel_threads "done." > > <6> kernel/power/process.c:169 freeze_kernel_threads "Freezing remaining freezable tasks ... " > > <6,c> kernel/power/process.c:140 freeze_processes "\n" > > <6,c> kernel/power/process.c:138 freeze_processes "done." > > <6> kernel/power/process.c:133 freeze_processes "Freezing user space processes ... " > > <6,c> kernel/power/process.c:105 try_to_freeze_tasks "(elapsed %d.%03d seconds) " > > I did not test it (will do so later) but it seems to me that the code in > kernel/printk/index.c should do this correctly in either case. At least it > tries to: > > if (flags & LOG_CONT) { > /* > * LOGLEVEL_DEFAULT here means "use the same level as the > * message we're continuing from", not the default message > * loglevel, so don't display it as such. > */ > if (level == LOGLEVEL_DEFAULT) > seq_puts(s, "<c>"); > else > seq_printf(s, "<%d,c>", level); > } else > seq_printf(s, "<%d>", level); > } Great. It makes the index consistent. I should have checked the code ;-) I do not mind then about the ordering in the macro definitions. It really seems to be only an implementation detail. Best Regards, Petr
On Wed 2022-11-30 15:56:33, Thomas Weißschuh wrote: > On 2022-11-30 15:23+0100, Petr Mladek wrote: > > On Fri 2022-11-25 20:09:46, Thomas Weißschuh wrote: > >> These macros emit continuation messages with explicit levels. > >> In case the continuation is logged separately from the original message > >> it will retain its level instead of falling back to KERN_DEFAULT. > >> > >> This remedies the issue that logs filtered by level contain stray > >> continuation messages without context. > >> > >> Suggested-by: Petr Mladek <pmladek@suse.com> > >> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > >> --- > >> include/linux/printk.h | 23 +++++++++++++++++++++++ > >> 1 file changed, 23 insertions(+) > >> > >> diff --git a/include/linux/printk.h b/include/linux/printk.h > >> index 8c81806c2e99..8f564c38f121 100644 > >> --- a/include/linux/printk.h > >> +++ b/include/linux/printk.h > >> @@ -537,6 +537,8 @@ struct pi_entry { > >> * This macro expands to a printk with KERN_CONT loglevel. It should only be > >> * used when continuing a log message with no newline ('\n') enclosed. Otherwise > >> * it defaults back to KERN_DEFAULT loglevel. > >> + * > >> + * Use the dedicated pr_<level>_cont() macros instead. > >> */ > >> #define pr_cont(fmt, ...) \ > >> printk(KERN_CONT fmt, ##__VA_ARGS__) > >> @@ -701,6 +703,27 @@ do { \ > >> no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) > >> #endif > >> > >> +/* > >> + * Print a continuation message with level. In case the continuation is split > >> + * from the main message it preserves the level. > >> + */ > >> + > >> +#define pr_emerg_cont(fmt, ...) \ > >> + printk(KERN_EMERG KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > >> +#define pr_alert_cont(fmt, ...) \ > >> + printk(KERN_ALERT KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > >> +#define pr_crit_cont(fmt, ...) \ > >> + printk(KERN_CRIT KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > >> +#define pr_err_cont(fmt, ...) \ > >> + printk(KERN_ERR KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > >> +#define pr_warn_cont(fmt, ...) \ > >> + printk(KERN_WARN KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > >> +#define pr_notice_cont(fmt, ...) \ > >> + printk(KERN_NOTICE KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > >> +#define pr_info_cont(fmt, ...) \ > >> + printk(KERN_INFO KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) > >> +/* no pr_debug_ratelimited, it doesn't make sense with CONFIG_DYNAMIC_DEBUG. */ > > > > I guess that you wanted to write "pr_debug_cont". > > Indeed. > > > Also I am not sure what you mean with "doesn't make sense". IMHO, it > > might make sense. But it would be hard to use and error prone > > with CONFIG_DYNAMIC_DEBUG. > > > > And more importantly, it probably would not work properly. If I get > > it corretly the dynamic debug messages are printed by the wrapper: > > > > void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...) > > { > > [...] > > vaf.fmt = fmt; > > vaf.va = &args; > > > > printk(KERN_DEBUG "%s%pV", dynamic_emit_prefix(descriptor, buf), &vaf); > > [...] > > > > This clearly does not support KERN_CONT in "fmt". > > Good point. > > My doubt was more that it would force users to know which message > continuations belong together and always enable all of them together with > dynamic debug. > Which would be very errorprone and annoying to use. Yes. This is what I meant with "hard to use" but I was not clear enough :-) > > But if it doesn't work at all that's an even stronger point. > > > I suggest to either remove the comment completely. Or write something > > like: > > > > /* no pr_debug_cont(), can't be supported easily with CONFIG_DYNAMIC_DEBUG */ > > What about: > > /* no pr_debug_cont(), it's errorprone to use > * and can't be supported easily with CONFIG_DYNAMIC_DEBUG */ Sounds good to me. Best Regards, Petr PS: Heh, I just realized that we actually abandoned these changes because the continuous lines in kernel/power/process.c are going to be removed. (/me doing too many things in parallel). Anyway, it is possible that someone would take this patches to fix another continuous lines in the future.
diff --git a/include/linux/printk.h b/include/linux/printk.h index 8c81806c2e99..8f564c38f121 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -537,6 +537,8 @@ struct pi_entry { * This macro expands to a printk with KERN_CONT loglevel. It should only be * used when continuing a log message with no newline ('\n') enclosed. Otherwise * it defaults back to KERN_DEFAULT loglevel. + * + * Use the dedicated pr_<level>_cont() macros instead. */ #define pr_cont(fmt, ...) \ printk(KERN_CONT fmt, ##__VA_ARGS__) @@ -701,6 +703,27 @@ do { \ no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #endif +/* + * Print a continuation message with level. In case the continuation is split + * from the main message it preserves the level. + */ + +#define pr_emerg_cont(fmt, ...) \ + printk(KERN_EMERG KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) +#define pr_alert_cont(fmt, ...) \ + printk(KERN_ALERT KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) +#define pr_crit_cont(fmt, ...) \ + printk(KERN_CRIT KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) +#define pr_err_cont(fmt, ...) \ + printk(KERN_ERR KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) +#define pr_warn_cont(fmt, ...) \ + printk(KERN_WARN KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) +#define pr_notice_cont(fmt, ...) \ + printk(KERN_NOTICE KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) +#define pr_info_cont(fmt, ...) \ + printk(KERN_INFO KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) +/* no pr_debug_ratelimited, it doesn't make sense with CONFIG_DYNAMIC_DEBUG. */ + extern const struct file_operations kmsg_fops; enum {