Message ID | 20221125190948.2062-1-linux@weissschuh.net |
---|---|
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 q4csp4238598wrr; Fri, 25 Nov 2022 11:12:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ZzYr/p8kZLDh6l7Jl6VqCbJdON2mDKew/1XY7PRkInr9zfW6aU+TrgZE+4F2umgT21pIy X-Received: by 2002:a17:902:eb87:b0:17f:9021:dd4e with SMTP id q7-20020a170902eb8700b0017f9021dd4emr29657645plg.141.1669403572312; Fri, 25 Nov 2022 11:12:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669403572; cv=none; d=google.com; s=arc-20160816; b=DC43OhbCjLcMg0636ZMa5Pmke11AKsjkGfeW6nsZVxQNJMHXeEoiovAiwOXRSBABKY iNysiMNfrUWPo4HJNRISIJ1UQwBrtPI9iasmpHWag94dQbyvdgpTIOu/Ke4XnVcEUqLg KZWpzY4JUG3qVtLU1ZUtcaVrAdMOUTd7yQgyVN1C4R0Eh+2D09T9C2YIYJgj+HcYTJ/b /w0zAj+UsKLr4tRDL5mFrvfrziNR7Lddc+IZfT50GjoDPjavro46Rh603KVU1GignHFA n36zhBD+gWNQGcQjMvbj2QNlEwUqqIPUvxE3ND3SvPcniLtRt/znURU2K/BMjh3WHIUc m9AA== 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 :message-id:date:subject:cc:to:dkim-signature:from; bh=9YCiGFFwuQdkFIwvrfU8ECcPflTeT80lQSd8asH4bcg=; b=lxTGvhIcE8dm1JrYdq9qEq6KwMrvbmb4ZAZ2sETtKLBVsfDrVp55uDoiizwBz2qKWw 2tUuaDbaAfy/zXpUqAw8MN3X83uP5xfC4DNfOd/8B6cCWRUb92A17dJywuvskKsdndPO 7ulo5VRlKrz4A8xb/dfn6d5Wc2n28M9BwHovTDhyEr7KwTGWhSMO0h86M7HNro1Gz2Nl EYWcaopK8tcunU+4l9AnsqX6SOUSk0v2HkOrGMUAhrKCAI5P8b3f+7R1mJGi9+wl9byY ARJFoRAoBQTm4xZLMIVw6Lg6cE2CVzYhheiOs3/nvntrPJRp2T3hMyr6qx4a7mZ0KlHW B09Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b="Bq/Y7NRt"; 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 l8-20020a170903120800b00186e34524besi5160370plh.522.2022.11.25.11.12.39; Fri, 25 Nov 2022 11:12:52 -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="Bq/Y7NRt"; 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 S229967AbiKYTKZ (ORCPT <rfc822;zxc52fgh@gmail.com> + 99 others); Fri, 25 Nov 2022 14:10:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229732AbiKYTKP (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 25 Nov 2022 14:10:15 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C95D55C9D; 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=g/SxQQpcICtujmdjN+34deYm/7mbOuynAwNDgxwnZRI=; h=From:To:Cc:Subject:Date:From; b=Bq/Y7NRturTvjRkhWN5xLm7MCA+plFgO7mBnfnJEPJqytptvWZS4NpKEGtEeb8L5+ r8xCRXvbU6Nu5ZWOlx2tS47vqY8egIroPDXME/m8Z/T7PXtN6kBpN9+IKnrZYZTIeA Z/7P3wObBzTderaOTTi5RUATuLPaFHAXUaY1AOmA= 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 0/3] printk: introduce new macros pr_<level>_cont() Date: Fri, 25 Nov 2022 20:09:45 +0100 Message-Id: <20221125190948.2062-1-linux@weissschuh.net> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Developer-Signature: v=1; a=ed25519-sha256; t=1669403373; l=1346; i=linux@weissschuh.net; s=20211113; h=from:subject; bh=g/SxQQpcICtujmdjN+34deYm/7mbOuynAwNDgxwnZRI=; b=cJBM5DFWiGF9QnAVkNtozi6pqByCpuEASnEYQnyrCxmVjHyA1kV5rp0QeDjmRHHqmQ3N1OgkRmMt ipaSdfSSCfm0BDAhn8ROkPjNvwylA/wZdinAiayUOOKci5E9L3nQ 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?1750496520363510404?= |
Series |
printk: introduce new macros pr_<level>_cont()
|
|
Message
Thomas Weißschuh
Nov. 25, 2022, 7:09 p.m. UTC
This series adds new printk wrapper macros pr_<level>_cont(). These create continuation messages with an explicit level. Explicit levels are useful when a continuation message is split from its main message. Without the explicit level KERN_DEFAULT ("warn" by default) is used which can lead to stray partial log messages when filtering by level. Also checkpatch is modified to recommend the new macros over plain pr_cont(). Lastly the new macros are used in kernel/power/process.c as this file uses continuation messages during system suspend-resume which creates a high likelyhood of interspersed messages. Changelog: This was original a single patch but was expanded into a series. v1: https://lore.kernel.org/lkml/20221121050946.3540-1-linux@weissschuh.net/ v1 -> v2: * Introduce new pr_<level>_cont() macros in printk.h * Add checkpatch.pl validation Thomas Weißschuh (3): printk: introduce new macros pr_<level>_cont() checkpatch: handle new pr_<level>_cont macros power: process: use explicit levels for printk continuations include/linux/printk.h | 23 +++++++++++++++++++++++ kernel/power/process.c | 18 +++++++++--------- scripts/checkpatch.pl | 10 ++++++++-- 3 files changed, 40 insertions(+), 11 deletions(-) base-commit: 0b1dcc2cf55ae6523c6fbd0d741b3ac28c9f4536
Comments
On Fri, Nov 25, 2022 at 8:10 PM Thomas Weißschuh <linux@weissschuh.net> wrote: > > This series adds new printk wrapper macros pr_<level>_cont(). > These create continuation messages with an explicit level. > > Explicit levels are useful when a continuation message is split from its main > message. Without the explicit level KERN_DEFAULT ("warn" by default) is used > which can lead to stray partial log messages when filtering by level. > > Also checkpatch is modified to recommend the new macros over plain pr_cont(). > > Lastly the new macros are used in kernel/power/process.c as this file uses > continuation messages during system suspend-resume which creates a high > likelyhood of interspersed messages. Well, if process.c is the only problematic piece of code in this respect, I'm not sure if adding the new infrastructure for its benefit alone is worth it, because it can very well do without pr_cont() at all. Please see the patch below (compiled only, sorry for gmail-induced white space damage). I'll submit it properly later if it works for everyone. --- kernel/power/process.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) Index: linux-pm/kernel/power/process.c =================================================================== --- linux-pm.orig/kernel/power/process.c +++ linux-pm/kernel/power/process.c @@ -27,6 +27,8 @@ unsigned int __read_mostly freeze_timeou static int try_to_freeze_tasks(bool user_only) { + const char *what = user_only ? "user space processes" : + "remaining freezable tasks"; struct task_struct *g, *p; unsigned long end_time; unsigned int todo; @@ -36,6 +38,8 @@ static int try_to_freeze_tasks(bool user bool wakeup = false; int sleep_usecs = USEC_PER_MSEC; + pr_info("Freezing %s\n", what); + start = ktime_get_boottime(); end_time = jiffies + msecs_to_jiffies(freeze_timeout_msecs); @@ -82,9 +86,8 @@ static int try_to_freeze_tasks(bool user elapsed_msecs = ktime_to_ms(elapsed); if (todo) { - pr_cont("\n"); - pr_err("Freezing of tasks %s after %d.%03d seconds " - "(%d tasks refusing to freeze, wq_busy=%d):\n", + pr_err("Freezing %s %s after %d.%03d seconds " + "(%d tasks refusing to freeze, wq_busy=%d):\n", what, wakeup ? "aborted" : "failed", elapsed_msecs / 1000, elapsed_msecs % 1000, todo - wq_busy, wq_busy); @@ -101,8 +104,8 @@ static int try_to_freeze_tasks(bool user read_unlock(&tasklist_lock); } } else { - pr_cont("(elapsed %d.%03d seconds) ", elapsed_msecs / 1000, - elapsed_msecs % 1000); + pr_info("Freezing %s completed (elapsed %d.%03d seconds)\n", + what, elapsed_msecs / 1000, elapsed_msecs % 1000); } return todo ? -EBUSY : 0; @@ -130,14 +133,11 @@ int freeze_processes(void) static_branch_inc(&freezer_active); pm_wakeup_clear(0); - pr_info("Freezing user space processes ... "); pm_freezing = true; error = try_to_freeze_tasks(true); - if (!error) { + if (!error) __usermodehelper_set_disable_depth(UMH_DISABLED); - pr_cont("done."); - } - pr_cont("\n"); + BUG_ON(in_atomic()); /* @@ -166,14 +166,9 @@ int freeze_kernel_threads(void) { int error; - pr_info("Freezing remaining freezable tasks ... "); - pm_nosig_freezing = true; error = try_to_freeze_tasks(false); - if (!error) - pr_cont("done."); - pr_cont("\n"); BUG_ON(in_atomic()); if (error)
On 2022-11-30 18:57+0100, Rafael J. Wysocki wrote: > On Fri, Nov 25, 2022 at 8:10 PM Thomas Weißschuh <linux@weissschuh.net> wrote: >> >> This series adds new printk wrapper macros pr_<level>_cont(). >> These create continuation messages with an explicit level. >> >> Explicit levels are useful when a continuation message is split from its main >> message. Without the explicit level KERN_DEFAULT ("warn" by default) is used >> which can lead to stray partial log messages when filtering by level. >> >> Also checkpatch is modified to recommend the new macros over plain pr_cont(). >> >> Lastly the new macros are used in kernel/power/process.c as this file uses >> continuation messages during system suspend-resume which creates a high >> likelyhood of interspersed messages. > > Well, if process.c is the only problematic piece of code in this > respect, I'm not sure if adding the new infrastructure for its benefit > alone is worth it, because it can very well do without pr_cont() at > all. In general all usages of pr_cont() are problematic. Any continuation can be split from its main message, leading to misleved continuations. process.c is just the one that I noticed reliably hitting this problem on my machine. > Please see the patch below (compiled only, sorry for gmail-induced > white space damage). I'll submit it properly later if it works for > everyone. The patch looks fine to me and getting rid of usages of pr_cont() seems to be the better aproach where it is possible. Petr: do you still want me to submit the new macros even if it is not used directly anymore? > --- > kernel/power/process.c | 25 ++++++++++--------------- > 1 file changed, 10 insertions(+), 15 deletions(-) > > Index: linux-pm/kernel/power/process.c > =================================================================== > --- linux-pm.orig/kernel/power/process.c > +++ linux-pm/kernel/power/process.c > @@ -27,6 +27,8 @@ unsigned int __read_mostly freeze_timeou > > static int try_to_freeze_tasks(bool user_only) > { > + const char *what = user_only ? "user space processes" : > + "remaining freezable tasks"; > struct task_struct *g, *p; > unsigned long end_time; > unsigned int todo; > @@ -36,6 +38,8 @@ static int try_to_freeze_tasks(bool user > bool wakeup = false; > int sleep_usecs = USEC_PER_MSEC; > > + pr_info("Freezing %s\n", what); > + > start = ktime_get_boottime(); > > end_time = jiffies + msecs_to_jiffies(freeze_timeout_msecs); > @@ -82,9 +86,8 @@ static int try_to_freeze_tasks(bool user > elapsed_msecs = ktime_to_ms(elapsed); > > if (todo) { > - pr_cont("\n"); > - pr_err("Freezing of tasks %s after %d.%03d seconds " > - "(%d tasks refusing to freeze, wq_busy=%d):\n", > + pr_err("Freezing %s %s after %d.%03d seconds " > + "(%d tasks refusing to freeze, wq_busy=%d):\n", what, > wakeup ? "aborted" : "failed", > elapsed_msecs / 1000, elapsed_msecs % 1000, > todo - wq_busy, wq_busy); > @@ -101,8 +104,8 @@ static int try_to_freeze_tasks(bool user > read_unlock(&tasklist_lock); > } > } else { > - pr_cont("(elapsed %d.%03d seconds) ", elapsed_msecs / 1000, > - elapsed_msecs % 1000); > + pr_info("Freezing %s completed (elapsed %d.%03d seconds)\n", > + what, elapsed_msecs / 1000, elapsed_msecs % 1000); > } > > return todo ? -EBUSY : 0; > @@ -130,14 +133,11 @@ int freeze_processes(void) > static_branch_inc(&freezer_active); > > pm_wakeup_clear(0); > - pr_info("Freezing user space processes ... "); > pm_freezing = true; > error = try_to_freeze_tasks(true); > - if (!error) { > + if (!error) > __usermodehelper_set_disable_depth(UMH_DISABLED); > - pr_cont("done."); > - } > - pr_cont("\n"); > + > BUG_ON(in_atomic()); > > /* > @@ -166,14 +166,9 @@ int freeze_kernel_threads(void) > { > int error; > > - pr_info("Freezing remaining freezable tasks ... "); > - > pm_nosig_freezing = true; > error = try_to_freeze_tasks(false); > - if (!error) > - pr_cont("done."); > > - pr_cont("\n"); > BUG_ON(in_atomic()); > > if (error)
On Thu 2022-12-01 00:37:15, Thomas Weißschuh wrote: > On 2022-11-30 18:57+0100, Rafael J. Wysocki wrote: > > On Fri, Nov 25, 2022 at 8:10 PM Thomas Weißschuh <linux@weissschuh.net> wrote: > >> > >> This series adds new printk wrapper macros pr_<level>_cont(). > >> These create continuation messages with an explicit level. > >> > >> Explicit levels are useful when a continuation message is split from its main > >> message. Without the explicit level KERN_DEFAULT ("warn" by default) is used > >> which can lead to stray partial log messages when filtering by level. > >> > >> Also checkpatch is modified to recommend the new macros over plain pr_cont(). > >> > >> Lastly the new macros are used in kernel/power/process.c as this file uses > >> continuation messages during system suspend-resume which creates a high > >> likelyhood of interspersed messages. > > > > Well, if process.c is the only problematic piece of code in this > > respect, I'm not sure if adding the new infrastructure for its benefit > > alone is worth it, because it can very well do without pr_cont() at > > all. > > In general all usages of pr_cont() are problematic. > Any continuation can be split from its main message, leading to misleved > continuations. In most cases this happens "only" when a message from another CPU or interrupt context is printed in parallel. > process.c is just the one that I noticed reliably hitting this problem on my > machine. The situation in process.c was even worse. The error message was printed in the middle of the to-be-continued message. As a result, the loglevel of the pr_cont() part was always (reliably) broken when the error message was printed. > > Please see the patch below (compiled only, sorry for gmail-induced > > white space damage). I'll submit it properly later if it works for > > everyone. > > The patch looks fine to me and getting rid of usages of pr_cont() seems to be > the better aproach where it is possible. I agree. It is always better to avoid pr_cont() when possible. > Petr: do you still want me to submit the new macros even if it is not used > directly anymore? Good question. In general, new API should not be added if there is no user. So, I would prefer to do not add the API if the problem will be fixed without it. Best Regards, Petr