Skip to content

Commit 2547781

Browse files
osimarrJarkko Sakkinen
authored andcommitted
PM: sleep: enable dynamic debug support within pm_pr_dbg()
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 <dacohen@pm.me> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 64f9a1e commit 2547781

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

include/linux/suspend.h

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,22 +542,56 @@ static inline void unlock_system_sleep(void) {}
542542
#ifdef CONFIG_PM_SLEEP_DEBUG
543543
extern bool pm_print_times_enabled;
544544
extern bool pm_debug_messages_on;
545-
extern __printf(2, 3) void __pm_pr_dbg(bool defer, const char *fmt, ...);
545+
static inline int pm_dyn_debug_messages_on(void)
546+
{
547+
#ifdef CONFIG_DYNAMIC_DEBUG
548+
return 1;
549+
#else
550+
return 0;
551+
#endif
552+
}
553+
#ifndef pr_fmt
554+
#define pr_fmt(fmt) "PM: " fmt
555+
#endif
556+
#define __pm_pr_dbg(fmt, ...) \
557+
do { \
558+
if (pm_debug_messages_on) \
559+
printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
560+
else if (pm_dyn_debug_messages_on()) \
561+
pr_debug(fmt, ##__VA_ARGS__); \
562+
} while (0)
563+
#define __pm_deferred_pr_dbg(fmt, ...) \
564+
do { \
565+
if (pm_debug_messages_on) \
566+
printk_deferred(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
567+
} while (0)
546568
#else
547569
#define pm_print_times_enabled (false)
548570
#define pm_debug_messages_on (false)
549571

550572
#include <linux/printk.h>
551573

552-
#define __pm_pr_dbg(defer, fmt, ...) \
553-
no_printk(KERN_DEBUG fmt, ##__VA_ARGS__)
574+
#define __pm_pr_dbg(fmt, ...) \
575+
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
576+
#define __pm_deferred_pr_dbg(fmt, ...) \
577+
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
554578
#endif
555579

580+
/**
581+
* pm_pr_dbg - print pm sleep debug messages
582+
*
583+
* If pm_debug_messages_on is enabled, print message.
584+
* If pm_debug_messages_on is disabled and CONFIG_DYNAMIC_DEBUG is enabled,
585+
* print message only from instances explicitly enabled on dynamic debug's
586+
* control.
587+
* If pm_debug_messages_on is disabled and CONFIG_DYNAMIC_DEBUG is disabled,
588+
* don't print message.
589+
*/
556590
#define pm_pr_dbg(fmt, ...) \
557-
__pm_pr_dbg(false, fmt, ##__VA_ARGS__)
591+
__pm_pr_dbg(fmt, ##__VA_ARGS__)
558592

559593
#define pm_deferred_pr_dbg(fmt, ...) \
560-
__pm_pr_dbg(true, fmt, ##__VA_ARGS__)
594+
__pm_deferred_pr_dbg(fmt, ##__VA_ARGS__)
561595

562596
#ifdef CONFIG_PM_AUTOSLEEP
563597

kernel/power/main.c

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -545,35 +545,6 @@ static int __init pm_debug_messages_setup(char *str)
545545
}
546546
__setup("pm_debug_messages", pm_debug_messages_setup);
547547

548-
/**
549-
* __pm_pr_dbg - Print a suspend debug message to the kernel log.
550-
* @defer: Whether or not to use printk_deferred() to print the message.
551-
* @fmt: Message format.
552-
*
553-
* The message will be emitted if enabled through the pm_debug_messages
554-
* sysfs attribute.
555-
*/
556-
void __pm_pr_dbg(bool defer, const char *fmt, ...)
557-
{
558-
struct va_format vaf;
559-
va_list args;
560-
561-
if (!pm_debug_messages_on)
562-
return;
563-
564-
va_start(args, fmt);
565-
566-
vaf.fmt = fmt;
567-
vaf.va = &args;
568-
569-
if (defer)
570-
printk_deferred(KERN_DEBUG "PM: %pV", &vaf);
571-
else
572-
printk(KERN_DEBUG "PM: %pV", &vaf);
573-
574-
va_end(args);
575-
}
576-
577548
#else /* !CONFIG_PM_SLEEP_DEBUG */
578549
static inline void pm_print_times_init(void) {}
579550
#endif /* CONFIG_PM_SLEEP_DEBUG */

0 commit comments

Comments
 (0)