From patchwork Sun Mar 6 05:52:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Cohen X-Patchwork-Id: 548804 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 4FCD1C433EF for ; Sun, 6 Mar 2022 05:52:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230466AbiCFFxV (ORCPT ); Sun, 6 Mar 2022 00:53:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229841AbiCFFxV (ORCPT ); Sun, 6 Mar 2022 00:53:21 -0500 Received: from mail-41104.protonmail.ch (mail-41104.protonmail.ch [185.70.41.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E74226D4 for ; Sat, 5 Mar 2022 21:52:27 -0800 (PST) Received: from mail-0201.mail-europe.com (mail-0201.mail-europe.com [51.77.79.158]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by mail-41104.protonmail.ch (Postfix) with ESMTPS id 4KB9j62wBGz4xFfc for ; Sun, 6 Mar 2022 05:52:26 +0000 (UTC) Authentication-Results: mail-41104.protonmail.ch; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="R3pLfFH/" Date: Sun, 06 Mar 2022 05:52:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1646545941; bh=jlHvcCrmUJa3Tgqz2MiMzMxuvjdRv3ydQ/NyZc+5Npo=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID; b=R3pLfFH/NetUj6mPXDbbD8SQJCLX+gkdh8pi4P3/DIfBMMoccXIOkQbvv+qYorcPh I0G8ftBHaEgMVeDFu3BTku24W+oBLibBJPtOVoUBU0NnOmu51fML9+ehXtb9JQh4Ta oC762S1ljBSBDGwoOkdZqNIf5P8cFobNBN/iHj9Fo32MPrGEoncVBCo27JH+sf2JYI 8jCO8VpwC7EL6yGIe8qRgQusJ8f8JYLYXgRPHmBlsv5QxjSwAZ/GFAOlTfhCArEbo7 vBLFOaeDfwLxqD7kW0I84uOeZiRSt5BldujmMME7MDG/LCB51O/Q8445jsh26867vE VhRsQznCbra2A== To: rafael@kernel.org, pavel@ucw.cz, len.brown@intel.com From: David Cohen Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, David Cohen Reply-To: David Cohen Subject: [PATCH] PM: fix dynamic debug within pm_pr_debug() Message-ID: <20220306055207.386821-1-dacohen@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Currently, pm_pr_debug() and pm_deferred_pr_debug() use __pm_pr_debug() to filter pm debug messages based on pm_debug_messages_on flag. According to __pm_pr_debug() implementation, pm_deferred_pr_debug() indirectly calls printk_deferred() within __pm_pr_debug() which doesn't support dynamic debug, but pm_pr_debug() indirectly calls pr_debug() which does support dynamic debug. The problem is if we enable/disable dynamic debug inside __pm_pr_debug() it will affect all pm_pr_debug() calls at once, so we can't individually control them. This patch changes __pm_pr_debug() implementation into macros to make pr_debug() to be directly called by all pr_pm_debug() cases. As a direct side effect all pr_pm_debug() can be individually controlled by dynamic debug feature. Signed-off-by: David Cohen --- include/linux/suspend.h | 19 +++++++++++++++---- kernel/power/main.c | 29 ----------------------------- 2 files changed, 15 insertions(+), 33 deletions(-) -- 2.35.1 diff --git a/include/linux/suspend.h b/include/linux/suspend.h index 300273ff40cc..d727d3c867e3 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -542,22 +542,33 @@ 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, ...); +#define __pm_pr_dbg(fmt, ...) \ + do { \ + if (pm_debug_messages_on) \ + pr_debug("PM: " fmt, ##__VA_ARGS__); \ + } while(0) +#define __pm_deferred_pr_dbg(fmt, ...) \ + do { \ + if (pm_debug_messages_on) \ + printk_deferred(KERN_DEBUG "PM: " 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, ...) \ +#define __pm_pr_dbg(fmt, ...) \ + no_printk(KERN_DEBUG fmt, ##__VA_ARGS__) +#define __pm_deferred_pr_dbg(fmt, ...) \ no_printk(KERN_DEBUG fmt, ##__VA_ARGS__) #endif #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 */