Commit 8d8b2441 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

PM / sleep: Do not print debug messages by default

Debug messages from the system suspend/hibernation infrastructure can
fill up the entire kernel log buffer in some cases and anyway they
are only useful for debugging.  They depend on CONFIG_PM_DEBUG, but
that is set as a rule as some generally useful diagnostic facilities
depend on it too.

For this reason, avoid printing those messages by default, but make
it possible to turn them on as needed with the help of a new sysfs
attribute under /sys/power/.
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent bd8c9ba3
...@@ -273,3 +273,15 @@ Description: ...@@ -273,3 +273,15 @@ Description:
This output is useful for system wakeup diagnostics of spurious This output is useful for system wakeup diagnostics of spurious
wakeup interrupts. wakeup interrupts.
What: /sys/power/pm_debug_messages
Date: July 2017
Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
Description:
The /sys/power/pm_debug_messages file controls the printing
of debug messages from the system suspend/hiberbation
infrastructure to the kernel log.
Writing a "1" to this file enables the debug messages and
writing a "0" (default) to it disables them. Reads from
this file return the current value.
...@@ -418,7 +418,6 @@ static void pm_dev_err(struct device *dev, pm_message_t state, const char *info, ...@@ -418,7 +418,6 @@ static void pm_dev_err(struct device *dev, pm_message_t state, const char *info,
dev_name(dev), pm_verb(state.event), info, error); dev_name(dev), pm_verb(state.event), info, error);
} }
#ifdef CONFIG_PM_DEBUG
static void dpm_show_time(ktime_t starttime, pm_message_t state, static void dpm_show_time(ktime_t starttime, pm_message_t state,
const char *info) const char *info)
{ {
...@@ -432,14 +431,11 @@ static void dpm_show_time(ktime_t starttime, pm_message_t state, ...@@ -432,14 +431,11 @@ static void dpm_show_time(ktime_t starttime, pm_message_t state,
usecs = usecs64; usecs = usecs64;
if (usecs == 0) if (usecs == 0)
usecs = 1; usecs = 1;
pr_info("PM: %s%s%s of devices complete after %ld.%03ld msecs\n",
info ?: "", info ? " " : "", pm_verb(state.event), pm_pr_dbg("%s%s%s of devices complete after %ld.%03ld msecs\n",
usecs / USEC_PER_MSEC, usecs % USEC_PER_MSEC); info ?: "", info ? " " : "", pm_verb(state.event),
usecs / USEC_PER_MSEC, usecs % USEC_PER_MSEC);
} }
#else
static inline void dpm_show_time(ktime_t starttime, pm_message_t state,
const char *info) {}
#endif /* CONFIG_PM_DEBUG */
static int dpm_run_callback(pm_callback_t cb, struct device *dev, static int dpm_run_callback(pm_callback_t cb, struct device *dev,
pm_message_t state, const char *info) pm_message_t state, const char *info)
......
...@@ -492,8 +492,14 @@ static inline void unlock_system_sleep(void) {} ...@@ -492,8 +492,14 @@ static inline void unlock_system_sleep(void) {}
#ifdef CONFIG_PM_SLEEP_DEBUG #ifdef CONFIG_PM_SLEEP_DEBUG
extern bool pm_print_times_enabled; extern bool pm_print_times_enabled;
extern __printf(1, 2) void pm_pr_dbg(const char *fmt, ...);
#else #else
#define pm_print_times_enabled (false) #define pm_print_times_enabled (false)
#include <linux/printk.h>
#define pm_pr_dbg(fmt, ...) \
no_printk(KERN_DEBUG fmt, ##__VA_ARGS__)
#endif #endif
#ifdef CONFIG_PM_AUTOSLEEP #ifdef CONFIG_PM_AUTOSLEEP
......
...@@ -651,7 +651,7 @@ static int load_image_and_restore(void) ...@@ -651,7 +651,7 @@ static int load_image_and_restore(void)
int error; int error;
unsigned int flags; unsigned int flags;
pr_debug("Loading hibernation image.\n"); pm_pr_dbg("Loading hibernation image.\n");
lock_device_hotplug(); lock_device_hotplug();
error = create_basic_memory_bitmaps(); error = create_basic_memory_bitmaps();
...@@ -681,7 +681,7 @@ int hibernate(void) ...@@ -681,7 +681,7 @@ int hibernate(void)
bool snapshot_test = false; bool snapshot_test = false;
if (!hibernation_available()) { if (!hibernation_available()) {
pr_debug("Hibernation not available.\n"); pm_pr_dbg("Hibernation not available.\n");
return -EPERM; return -EPERM;
} }
...@@ -727,7 +727,7 @@ int hibernate(void) ...@@ -727,7 +727,7 @@ int hibernate(void)
else else
flags |= SF_CRC32_MODE; flags |= SF_CRC32_MODE;
pr_debug("Writing image.\n"); pm_pr_dbg("Writing image.\n");
error = swsusp_write(flags); error = swsusp_write(flags);
swsusp_free(); swsusp_free();
if (!error) { if (!error) {
...@@ -739,7 +739,7 @@ int hibernate(void) ...@@ -739,7 +739,7 @@ int hibernate(void)
in_suspend = 0; in_suspend = 0;
pm_restore_gfp_mask(); pm_restore_gfp_mask();
} else { } else {
pr_debug("Image restored successfully.\n"); pm_pr_dbg("Image restored successfully.\n");
} }
Free_bitmaps: Free_bitmaps:
...@@ -747,7 +747,7 @@ int hibernate(void) ...@@ -747,7 +747,7 @@ int hibernate(void)
Thaw: Thaw:
unlock_device_hotplug(); unlock_device_hotplug();
if (snapshot_test) { if (snapshot_test) {
pr_debug("Checking hibernation image\n"); pm_pr_dbg("Checking hibernation image\n");
error = swsusp_check(); error = swsusp_check();
if (!error) if (!error)
error = load_image_and_restore(); error = load_image_and_restore();
...@@ -811,7 +811,7 @@ static int software_resume(void) ...@@ -811,7 +811,7 @@ static int software_resume(void)
goto Unlock; goto Unlock;
} }
pr_debug("Checking hibernation image partition %s\n", resume_file); pm_pr_dbg("Checking hibernation image partition %s\n", resume_file);
if (resume_delay) { if (resume_delay) {
pr_info("Waiting %dsec before reading resume device ...\n", pr_info("Waiting %dsec before reading resume device ...\n",
...@@ -853,10 +853,10 @@ static int software_resume(void) ...@@ -853,10 +853,10 @@ static int software_resume(void)
} }
Check_image: Check_image:
pr_debug("Hibernation image partition %d:%d present\n", pm_pr_dbg("Hibernation image partition %d:%d present\n",
MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device)); MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device));
pr_debug("Looking for hibernation image.\n"); pm_pr_dbg("Looking for hibernation image.\n");
error = swsusp_check(); error = swsusp_check();
if (error) if (error)
goto Unlock; goto Unlock;
...@@ -875,7 +875,7 @@ static int software_resume(void) ...@@ -875,7 +875,7 @@ static int software_resume(void)
goto Close_Finish; goto Close_Finish;
} }
pr_debug("Preparing processes for restore.\n"); pm_pr_dbg("Preparing processes for restore.\n");
error = freeze_processes(); error = freeze_processes();
if (error) if (error)
goto Close_Finish; goto Close_Finish;
...@@ -888,7 +888,7 @@ static int software_resume(void) ...@@ -888,7 +888,7 @@ static int software_resume(void)
/* For success case, the suspend path will release the lock */ /* For success case, the suspend path will release the lock */
Unlock: Unlock:
mutex_unlock(&pm_mutex); mutex_unlock(&pm_mutex);
pr_debug("Hibernation image not present or could not be loaded.\n"); pm_pr_dbg("Hibernation image not present or could not be loaded.\n");
return error; return error;
Close_Finish: Close_Finish:
swsusp_close(FMODE_READ); swsusp_close(FMODE_READ);
...@@ -1012,8 +1012,8 @@ static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr, ...@@ -1012,8 +1012,8 @@ static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr,
error = -EINVAL; error = -EINVAL;
if (!error) if (!error)
pr_debug("Hibernation mode set to '%s'\n", pm_pr_dbg("Hibernation mode set to '%s'\n",
hibernation_modes[mode]); hibernation_modes[mode]);
unlock_system_sleep(); unlock_system_sleep();
return error ? error : n; return error ? error : n;
} }
......
...@@ -361,6 +361,57 @@ static ssize_t pm_wakeup_irq_show(struct kobject *kobj, ...@@ -361,6 +361,57 @@ static ssize_t pm_wakeup_irq_show(struct kobject *kobj,
power_attr_ro(pm_wakeup_irq); power_attr_ro(pm_wakeup_irq);
static bool pm_debug_messages_on __read_mostly;
static ssize_t pm_debug_messages_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
return sprintf(buf, "%d\n", pm_debug_messages_on);
}
static ssize_t pm_debug_messages_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t n)
{
unsigned long val;
if (kstrtoul(buf, 10, &val))
return -EINVAL;
if (val > 1)
return -EINVAL;
pm_debug_messages_on = !!val;
return n;
}
power_attr(pm_debug_messages);
/**
* pm_pr_dbg - Print a suspend debug message to the kernel log.
* @fmt: Message format.
*
* The message will be emitted if enabled through the pm_debug_messages
* sysfs attribute.
*/
void pm_pr_dbg(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;
printk(KERN_DEBUG "PM: %pV", &vaf);
va_end(args);
}
#else /* !CONFIG_PM_SLEEP_DEBUG */ #else /* !CONFIG_PM_SLEEP_DEBUG */
static inline void pm_print_times_init(void) {} static inline void pm_print_times_init(void) {}
#endif /* CONFIG_PM_SLEEP_DEBUG */ #endif /* CONFIG_PM_SLEEP_DEBUG */
...@@ -697,6 +748,7 @@ static struct attribute * g[] = { ...@@ -697,6 +748,7 @@ static struct attribute * g[] = {
#ifdef CONFIG_PM_SLEEP_DEBUG #ifdef CONFIG_PM_SLEEP_DEBUG
&pm_print_times_attr.attr, &pm_print_times_attr.attr,
&pm_wakeup_irq_attr.attr, &pm_wakeup_irq_attr.attr,
&pm_debug_messages_attr.attr,
#endif #endif
#endif #endif
#ifdef CONFIG_FREEZER #ifdef CONFIG_FREEZER
......
...@@ -106,7 +106,7 @@ static void freeze_enter(void) ...@@ -106,7 +106,7 @@ static void freeze_enter(void)
static void s2idle_loop(void) static void s2idle_loop(void)
{ {
pr_debug("PM: suspend-to-idle\n"); pm_pr_dbg("suspend-to-idle\n");
do { do {
freeze_enter(); freeze_enter();
...@@ -124,7 +124,7 @@ static void s2idle_loop(void) ...@@ -124,7 +124,7 @@ static void s2idle_loop(void)
pm_wakeup_clear(false); pm_wakeup_clear(false);
} while (!dpm_suspend_noirq(PMSG_SUSPEND)); } while (!dpm_suspend_noirq(PMSG_SUSPEND));
pr_debug("PM: resume from suspend-to-idle\n"); pm_pr_dbg("resume from suspend-to-idle\n");
} }
void freeze_wake(void) void freeze_wake(void)
...@@ -547,7 +547,7 @@ static int enter_state(suspend_state_t state) ...@@ -547,7 +547,7 @@ static int enter_state(suspend_state_t state)
trace_suspend_resume(TPS("sync_filesystems"), 0, false); trace_suspend_resume(TPS("sync_filesystems"), 0, false);
#endif #endif
pr_debug("PM: Preparing system for sleep (%s)\n", pm_states[state]); pm_pr_dbg("Preparing system for sleep (%s)\n", pm_states[state]);
pm_suspend_clear_flags(); pm_suspend_clear_flags();
error = suspend_prepare(state); error = suspend_prepare(state);
if (error) if (error)
...@@ -557,13 +557,13 @@ static int enter_state(suspend_state_t state) ...@@ -557,13 +557,13 @@ static int enter_state(suspend_state_t state)
goto Finish; goto Finish;
trace_suspend_resume(TPS("suspend_enter"), state, false); trace_suspend_resume(TPS("suspend_enter"), state, false);
pr_debug("PM: Suspending system (%s)\n", pm_states[state]); pm_pr_dbg("Suspending system (%s)\n", pm_states[state]);
pm_restrict_gfp_mask(); pm_restrict_gfp_mask();
error = suspend_devices_and_enter(state); error = suspend_devices_and_enter(state);
pm_restore_gfp_mask(); pm_restore_gfp_mask();
Finish: Finish:
pr_debug("PM: Finishing wakeup.\n"); pm_pr_dbg("Finishing wakeup.\n");
suspend_finish(); suspend_finish();
Unlock: Unlock:
mutex_unlock(&pm_mutex); mutex_unlock(&pm_mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment