From patchwork Thu Mar 24 08:07:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Cohen X-Patchwork-Id: 554187 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86FD0C433EF for ; Thu, 24 Mar 2022 08:07:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348798AbiCXIJD (ORCPT ); Thu, 24 Mar 2022 04:09:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348793AbiCXIJB (ORCPT ); Thu, 24 Mar 2022 04:09:01 -0400 Received: from mail-0301.mail-europe.com (mail-0301.mail-europe.com [188.165.51.139]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC8339A9A7 for ; Thu, 24 Mar 2022 01:07:30 -0700 (PDT) Date: Thu, 24 Mar 2022 08:07:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1648109247; bh=IwmYMVqeQSJTelQ71b3k0r9jC+rrpKjwIIRKPp2xmJE=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=o9CLaglO3fAcHqtDJLEref4o7uuHxTugXa+B6fMVdt9Xy2h0MBcOMcoJzrTDvNoBU AIiLHT8u0+du93GINYfBaDlVNw0gIJyPc5wXVeOflt+OazYKhlk2wCX0XhUifeR1il 5j1X2mCbOFAfim462VIpywfPbm3nymAEa8qZJhl8dnmWHtCExSSByLXkYR6bwVExeT Y9N4MCl0tZ06eohI+syhpwtxfBS+zZCnjAhVExZNYfQGB3GykGweQ31QX/OP9bHwD2 1YFlkg0gIVEtWeQHS/LuBobZ6ErM16mfAhMAtEhZuitqVVcP0EoZqAsCkrP19S49cO HIOiGkXogSw4A== To: rafael@kernel.org, len.brown@intel.com, pavel@ucw.cz From: David Cohen Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, David Cohen Reply-To: David Cohen Subject: [PATCH v3 1/2] PM: narrow down -DDEBUG on kernel/power/ files Message-ID: <20220324080653.454333-2-dacohen@pm.me> In-Reply-To: <20220324080653.454333-1-dacohen@pm.me> References: <20220324080653.454333-1-dacohen@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The macro -DDEBUG is broadly enabled on kernel/power/ directory if CONFIG_DYNAMIC_DEBUG is enabled. As side effect all debug messages using pr_debug() and dev_dbg() are enabled by default on dynamic debug. We're reworking pm_pr_dbg() to support dynamic debug, where pm_pr_dbg() will print message if either pm_debug_messages_on flag is set or if it's explicitly enabled on dynamic debug's control. That means if we let -DDEBUG broadly set, the pm_debug_messages_on flag will be bypassed by default on pm_pr_dbg() if dynamic debug is also enabled. The files that directly use pr_debug() and dev_dbg() on kernel/power/ are: - swap.c - snapshot.c - energy_model.c And those files do not use pm_pr_dbg(). So if we limit -DDEBUG to them, we keep the same functional behavior while allowing the pm_pr_dbg() refactor. Signed-off-by: David Cohen --- kernel/power/Makefile | 6 +++++- kernel/power/process.c | 3 --- 2 files changed, 5 insertions(+), 4 deletions(-) -- 2.35.1 diff --git a/kernel/power/Makefile b/kernel/power/Makefile index 5899260a8bef..874ad834dc8d 100644 --- a/kernel/power/Makefile +++ b/kernel/power/Makefile @@ -1,6 +1,10 @@ # SPDX-License-Identifier: GPL-2.0 -ccflags-$(CONFIG_PM_DEBUG) := -DDEBUG +ifeq ($(CONFIG_DYNAMIC_DEBUG), y) +CFLAGS_swap.o := -DDEBUG +CFLAGS_snapshot.o := -DDEBUG +CFLAGS_energy_model.o := -DDEBUG +endif KASAN_SANITIZE_snapshot.o := n diff --git a/kernel/power/process.c b/kernel/power/process.c index 11b570fcf049..3068601e585a 100644 --- a/kernel/power/process.c +++ b/kernel/power/process.c @@ -6,9 +6,6 @@ * Originally from swsusp. */ - -#undef DEBUG - #include #include #include From patchwork Thu Mar 24 08:07:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Cohen X-Patchwork-Id: 553982 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE055C433F5 for ; Thu, 24 Mar 2022 08:07:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348836AbiCXIJS (ORCPT ); Thu, 24 Mar 2022 04:09:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346153AbiCXIJL (ORCPT ); Thu, 24 Mar 2022 04:09:11 -0400 Received: from mail-0301.mail-europe.com (mail-0301.mail-europe.com [188.165.51.139]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9E7F9AE62 for ; Thu, 24 Mar 2022 01:07:39 -0700 (PDT) Date: Thu, 24 Mar 2022 08:07:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1648109256; bh=Aof6LmdJY1v75LpCNBvCRmk7t2mbNOHkydhSgp6jXZs=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=dR5r52xBsQx1fRlPZHdnKj31hFLvyhRwJpIPl/wcfRZVqBgpripdgWf36XcmU1gXL IXi7qEsqCQOsYRKdgONgX4sXuLo5p9HwSWFO89IwlNrv+mS4pEzTtIpAYMWFidwjUA V0A2Nk1DMe7ERWs9TT0r95VK5T4Pvsn5xeJpFwwphx8/Y+f9V+tQNSQ3uJhSBN0Anq 9Ki3ARkDez9KX1Fm5SEyYqypQLR2eypsaia0M8897To2d2laxx00dlwzFtDhDA7r16 cAWG6aGIOQsf3HeZwCy3u6wPsRykn7TSk8/UnBZSdEIEvjZjheBmQNV2LvfUPDrsgv 4nKwbGAn+lkTg== To: rafael@kernel.org, len.brown@intel.com, pavel@ucw.cz From: David Cohen Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, David Cohen Reply-To: David Cohen Subject: [PATCH v3 2/2] PM: enable dynamic debug support within pm_pr_dbg() Message-ID: <20220324080653.454333-3-dacohen@pm.me> In-Reply-To: <20220324080653.454333-1-dacohen@pm.me> References: <20220324080653.454333-1-dacohen@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Currently pm_pr_dbg() is used to filter kernel pm debug messages based on pm_debug_messages_on flag. The problem is if we enable/disable this flag it will affect all pm_pr_dbg() calls at once, so we can't individually control them. This patch changes pm_pr_dbg() implementation as such: - If pm_debug_messages_on is enabled, print the message. - If pm_debug_messages_on is disabled and CONFIG_DYNAMIC_DEBUG is enabled, only print the messages explicitly enabled on /sys/kernel/debug/dynamic_debug/control. - If pm_debug_messages_on is disabled and CONFIG_DYNAMIC_DEBUG is disabled, don't print the message. Signed-off-by: David Cohen --- include/linux/suspend.h | 44 ++++++++++++++++++++++++++++++++++++----- kernel/power/main.c | 29 --------------------------- 2 files changed, 39 insertions(+), 34 deletions(-) -- 2.35.1 diff --git a/include/linux/suspend.h b/include/linux/suspend.h index 300273ff40cc..70f2921e2e70 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -542,22 +542,56 @@ static inline void unlock_system_sleep(void) {} #ifdef CONFIG_PM_SLEEP_DEBUG extern bool pm_print_times_enabled; extern bool pm_debug_messages_on; -extern __printf(2, 3) void __pm_pr_dbg(bool defer, const char *fmt, ...); +static inline int pm_dyn_debug_messages_on(void) +{ +#ifdef CONFIG_DYNAMIC_DEBUG + return 1; +#else + return 0; +#endif +} +#ifndef pr_fmt +#define pr_fmt(fmt) "PM: " fmt +#endif +#define __pm_pr_dbg(fmt, ...) \ + do { \ + if (pm_debug_messages_on) \ + printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \ + else if (pm_dyn_debug_messages_on()) \ + pr_debug(fmt, ##__VA_ARGS__); \ + } while (0) +#define __pm_deferred_pr_dbg(fmt, ...) \ + do { \ + if (pm_debug_messages_on) \ + printk_deferred(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \ + } while (0) #else #define pm_print_times_enabled (false) #define pm_debug_messages_on (false) #include -#define __pm_pr_dbg(defer, fmt, ...) \ - no_printk(KERN_DEBUG fmt, ##__VA_ARGS__) +#define __pm_pr_dbg(fmt, ...) \ + no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) +#define __pm_deferred_pr_dbg(fmt, ...) \ + no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #endif +/** + * pm_pr_dbg - print pm sleep debug messages + * + * If pm_debug_messages_on is enabled, print message. + * If pm_debug_messages_on is disabled and CONFIG_DYNAMIC_DEBUG is enabled, + * print message only from instances explicitly enabled on dynamic debug's + * control. + * If pm_debug_messages_on is disabled and CONFIG_DYNAMIC_DEBUG is disabled, + * don't print message. + */ #define pm_pr_dbg(fmt, ...) \ - __pm_pr_dbg(false, fmt, ##__VA_ARGS__) + __pm_pr_dbg(fmt, ##__VA_ARGS__) #define pm_deferred_pr_dbg(fmt, ...) \ - __pm_pr_dbg(true, fmt, ##__VA_ARGS__) + __pm_deferred_pr_dbg(fmt, ##__VA_ARGS__) #ifdef CONFIG_PM_AUTOSLEEP diff --git a/kernel/power/main.c b/kernel/power/main.c index 7e646079fbeb..5242bf2ee469 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c @@ -545,35 +545,6 @@ static int __init pm_debug_messages_setup(char *str) } __setup("pm_debug_messages", pm_debug_messages_setup); -/** - * __pm_pr_dbg - Print a suspend debug message to the kernel log. - * @defer: Whether or not to use printk_deferred() to print the message. - * @fmt: Message format. - * - * The message will be emitted if enabled through the pm_debug_messages - * sysfs attribute. - */ -void __pm_pr_dbg(bool defer, const char *fmt, ...) -{ - struct va_format vaf; - va_list args; - - if (!pm_debug_messages_on) - return; - - va_start(args, fmt); - - vaf.fmt = fmt; - vaf.va = &args; - - if (defer) - printk_deferred(KERN_DEBUG "PM: %pV", &vaf); - else - printk(KERN_DEBUG "PM: %pV", &vaf); - - va_end(args); -} - #else /* !CONFIG_PM_SLEEP_DEBUG */ static inline void pm_print_times_init(void) {} #endif /* CONFIG_PM_SLEEP_DEBUG */