aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-07-18 20:38:44 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-07-21 20:31:27 -0400
commit8d8b2441db9647890251538f60b75a4e45fdef8d (patch)
tree57f0acb27062c75ece6982231b81d67f7909f834
parentbd8c9ba3b1e2037af5af4e48aea1087212838179 (diff)
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: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--Documentation/ABI/testing/sysfs-power12
-rw-r--r--drivers/base/power/main.c12
-rw-r--r--include/linux/suspend.h6
-rw-r--r--kernel/power/hibernate.c24
-rw-r--r--kernel/power/main.c52
-rw-r--r--kernel/power/suspend.c10
6 files changed, 91 insertions, 25 deletions
diff --git a/Documentation/ABI/testing/sysfs-power b/Documentation/ABI/testing/sysfs-power
index f523e5a3ac33..713cab1d5f12 100644
--- a/Documentation/ABI/testing/sysfs-power
+++ b/Documentation/ABI/testing/sysfs-power
@@ -273,3 +273,15 @@ Description:
273 273
274 This output is useful for system wakeup diagnostics of spurious 274 This output is useful for system wakeup diagnostics of spurious
275 wakeup interrupts. 275 wakeup interrupts.
276
277What: /sys/power/pm_debug_messages
278Date: July 2017
279Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
280Description:
281 The /sys/power/pm_debug_messages file controls the printing
282 of debug messages from the system suspend/hiberbation
283 infrastructure to the kernel log.
284
285 Writing a "1" to this file enables the debug messages and
286 writing a "0" (default) to it disables them. Reads from
287 this file return the current value.
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index c99f8730de82..4f5fc212d684 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -418,7 +418,6 @@ static void pm_dev_err(struct device *dev, pm_message_t state, const char *info,
418 dev_name(dev), pm_verb(state.event), info, error); 418 dev_name(dev), pm_verb(state.event), info, error);
419} 419}
420 420
421#ifdef CONFIG_PM_DEBUG
422static void dpm_show_time(ktime_t starttime, pm_message_t state, 421static void dpm_show_time(ktime_t starttime, pm_message_t state,
423 const char *info) 422 const char *info)
424{ 423{
@@ -432,14 +431,11 @@ static void dpm_show_time(ktime_t starttime, pm_message_t state,
432 usecs = usecs64; 431 usecs = usecs64;
433 if (usecs == 0) 432 if (usecs == 0)
434 usecs = 1; 433 usecs = 1;
435 pr_info("PM: %s%s%s of devices complete after %ld.%03ld msecs\n", 434
436 info ?: "", info ? " " : "", pm_verb(state.event), 435 pm_pr_dbg("%s%s%s of devices complete after %ld.%03ld msecs\n",
437 usecs / USEC_PER_MSEC, usecs % USEC_PER_MSEC); 436 info ?: "", info ? " " : "", pm_verb(state.event),
437 usecs / USEC_PER_MSEC, usecs % USEC_PER_MSEC);
438} 438}
439#else
440static inline void dpm_show_time(ktime_t starttime, pm_message_t state,
441 const char *info) {}
442#endif /* CONFIG_PM_DEBUG */
443 439
444static int dpm_run_callback(pm_callback_t cb, struct device *dev, 440static int dpm_run_callback(pm_callback_t cb, struct device *dev,
445 pm_message_t state, const char *info) 441 pm_message_t state, const char *info)
diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index 2159f6841768..707e4cdf21c2 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -492,8 +492,14 @@ static inline void unlock_system_sleep(void) {}
492 492
493#ifdef CONFIG_PM_SLEEP_DEBUG 493#ifdef CONFIG_PM_SLEEP_DEBUG
494extern bool pm_print_times_enabled; 494extern bool pm_print_times_enabled;
495extern __printf(1, 2) void pm_pr_dbg(const char *fmt, ...);
495#else 496#else
496#define pm_print_times_enabled (false) 497#define pm_print_times_enabled (false)
498
499#include <linux/printk.h>
500
501#define pm_pr_dbg(fmt, ...) \
502 no_printk(KERN_DEBUG fmt, ##__VA_ARGS__)
497#endif 503#endif
498 504
499#ifdef CONFIG_PM_AUTOSLEEP 505#ifdef CONFIG_PM_AUTOSLEEP
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index e1914c7b85b1..e19ee179d211 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -651,7 +651,7 @@ static int load_image_and_restore(void)
651 int error; 651 int error;
652 unsigned int flags; 652 unsigned int flags;
653 653
654 pr_debug("Loading hibernation image.\n"); 654 pm_pr_dbg("Loading hibernation image.\n");
655 655
656 lock_device_hotplug(); 656 lock_device_hotplug();
657 error = create_basic_memory_bitmaps(); 657 error = create_basic_memory_bitmaps();
@@ -681,7 +681,7 @@ int hibernate(void)
681 bool snapshot_test = false; 681 bool snapshot_test = false;
682 682
683 if (!hibernation_available()) { 683 if (!hibernation_available()) {
684 pr_debug("Hibernation not available.\n"); 684 pm_pr_dbg("Hibernation not available.\n");
685 return -EPERM; 685 return -EPERM;
686 } 686 }
687 687
@@ -727,7 +727,7 @@ int hibernate(void)
727 else 727 else
728 flags |= SF_CRC32_MODE; 728 flags |= SF_CRC32_MODE;
729 729
730 pr_debug("Writing image.\n"); 730 pm_pr_dbg("Writing image.\n");
731 error = swsusp_write(flags); 731 error = swsusp_write(flags);
732 swsusp_free(); 732 swsusp_free();
733 if (!error) { 733 if (!error) {
@@ -739,7 +739,7 @@ int hibernate(void)
739 in_suspend = 0; 739 in_suspend = 0;
740 pm_restore_gfp_mask(); 740 pm_restore_gfp_mask();
741 } else { 741 } else {
742 pr_debug("Image restored successfully.\n"); 742 pm_pr_dbg("Image restored successfully.\n");
743 } 743 }
744 744
745 Free_bitmaps: 745 Free_bitmaps:
@@ -747,7 +747,7 @@ int hibernate(void)
747 Thaw: 747 Thaw:
748 unlock_device_hotplug(); 748 unlock_device_hotplug();
749 if (snapshot_test) { 749 if (snapshot_test) {
750 pr_debug("Checking hibernation image\n"); 750 pm_pr_dbg("Checking hibernation image\n");
751 error = swsusp_check(); 751 error = swsusp_check();
752 if (!error) 752 if (!error)
753 error = load_image_and_restore(); 753 error = load_image_and_restore();
@@ -811,7 +811,7 @@ static int software_resume(void)
811 goto Unlock; 811 goto Unlock;
812 } 812 }
813 813
814 pr_debug("Checking hibernation image partition %s\n", resume_file); 814 pm_pr_dbg("Checking hibernation image partition %s\n", resume_file);
815 815
816 if (resume_delay) { 816 if (resume_delay) {
817 pr_info("Waiting %dsec before reading resume device ...\n", 817 pr_info("Waiting %dsec before reading resume device ...\n",
@@ -853,10 +853,10 @@ static int software_resume(void)
853 } 853 }
854 854
855 Check_image: 855 Check_image:
856 pr_debug("Hibernation image partition %d:%d present\n", 856 pm_pr_dbg("Hibernation image partition %d:%d present\n",
857 MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device)); 857 MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device));
858 858
859 pr_debug("Looking for hibernation image.\n"); 859 pm_pr_dbg("Looking for hibernation image.\n");
860 error = swsusp_check(); 860 error = swsusp_check();
861 if (error) 861 if (error)
862 goto Unlock; 862 goto Unlock;
@@ -875,7 +875,7 @@ static int software_resume(void)
875 goto Close_Finish; 875 goto Close_Finish;
876 } 876 }
877 877
878 pr_debug("Preparing processes for restore.\n"); 878 pm_pr_dbg("Preparing processes for restore.\n");
879 error = freeze_processes(); 879 error = freeze_processes();
880 if (error) 880 if (error)
881 goto Close_Finish; 881 goto Close_Finish;
@@ -888,7 +888,7 @@ static int software_resume(void)
888 /* For success case, the suspend path will release the lock */ 888 /* For success case, the suspend path will release the lock */
889 Unlock: 889 Unlock:
890 mutex_unlock(&pm_mutex); 890 mutex_unlock(&pm_mutex);
891 pr_debug("Hibernation image not present or could not be loaded.\n"); 891 pm_pr_dbg("Hibernation image not present or could not be loaded.\n");
892 return error; 892 return error;
893 Close_Finish: 893 Close_Finish:
894 swsusp_close(FMODE_READ); 894 swsusp_close(FMODE_READ);
@@ -1012,8 +1012,8 @@ static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr,
1012 error = -EINVAL; 1012 error = -EINVAL;
1013 1013
1014 if (!error) 1014 if (!error)
1015 pr_debug("Hibernation mode set to '%s'\n", 1015 pm_pr_dbg("Hibernation mode set to '%s'\n",
1016 hibernation_modes[mode]); 1016 hibernation_modes[mode]);
1017 unlock_system_sleep(); 1017 unlock_system_sleep();
1018 return error ? error : n; 1018 return error ? error : n;
1019} 1019}
diff --git a/kernel/power/main.c b/kernel/power/main.c
index 42bd800a6755..5ce00902c7e3 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -361,6 +361,57 @@ static ssize_t pm_wakeup_irq_show(struct kobject *kobj,
361 361
362power_attr_ro(pm_wakeup_irq); 362power_attr_ro(pm_wakeup_irq);
363 363
364static bool pm_debug_messages_on __read_mostly;
365
366static ssize_t pm_debug_messages_show(struct kobject *kobj,
367 struct kobj_attribute *attr, char *buf)
368{
369 return sprintf(buf, "%d\n", pm_debug_messages_on);
370}
371
372static ssize_t pm_debug_messages_store(struct kobject *kobj,
373 struct kobj_attribute *attr,
374 const char *buf, size_t n)
375{
376 unsigned long val;
377
378 if (kstrtoul(buf, 10, &val))
379 return -EINVAL;
380
381 if (val > 1)
382 return -EINVAL;
383
384 pm_debug_messages_on = !!val;
385 return n;
386}
387
388power_attr(pm_debug_messages);
389
390/**
391 * pm_pr_dbg - Print a suspend debug message to the kernel log.
392 * @fmt: Message format.
393 *
394 * The message will be emitted if enabled through the pm_debug_messages
395 * sysfs attribute.
396 */
397void pm_pr_dbg(const char *fmt, ...)
398{
399 struct va_format vaf;
400 va_list args;
401
402 if (!pm_debug_messages_on)
403 return;
404
405 va_start(args, fmt);
406
407 vaf.fmt = fmt;
408 vaf.va = &args;
409
410 printk(KERN_DEBUG "PM: %pV", &vaf);
411
412 va_end(args);
413}
414
364#else /* !CONFIG_PM_SLEEP_DEBUG */ 415#else /* !CONFIG_PM_SLEEP_DEBUG */
365static inline void pm_print_times_init(void) {} 416static inline void pm_print_times_init(void) {}
366#endif /* CONFIG_PM_SLEEP_DEBUG */ 417#endif /* CONFIG_PM_SLEEP_DEBUG */
@@ -697,6 +748,7 @@ static struct attribute * g[] = {
697#ifdef CONFIG_PM_SLEEP_DEBUG 748#ifdef CONFIG_PM_SLEEP_DEBUG
698 &pm_print_times_attr.attr, 749 &pm_print_times_attr.attr,
699 &pm_wakeup_irq_attr.attr, 750 &pm_wakeup_irq_attr.attr,
751 &pm_debug_messages_attr.attr,
700#endif 752#endif
701#endif 753#endif
702#ifdef CONFIG_FREEZER 754#ifdef CONFIG_FREEZER
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index d0c0b96c2383..4f10773322fa 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -106,7 +106,7 @@ static void freeze_enter(void)
106 106
107static void s2idle_loop(void) 107static void s2idle_loop(void)
108{ 108{
109 pr_debug("PM: suspend-to-idle\n"); 109 pm_pr_dbg("suspend-to-idle\n");
110 110
111 do { 111 do {
112 freeze_enter(); 112 freeze_enter();
@@ -124,7 +124,7 @@ static void s2idle_loop(void)
124 pm_wakeup_clear(false); 124 pm_wakeup_clear(false);
125 } while (!dpm_suspend_noirq(PMSG_SUSPEND)); 125 } while (!dpm_suspend_noirq(PMSG_SUSPEND));
126 126
127 pr_debug("PM: resume from suspend-to-idle\n"); 127 pm_pr_dbg("resume from suspend-to-idle\n");
128} 128}
129 129
130void freeze_wake(void) 130void freeze_wake(void)
@@ -547,7 +547,7 @@ static int enter_state(suspend_state_t state)
547 trace_suspend_resume(TPS("sync_filesystems"), 0, false); 547 trace_suspend_resume(TPS("sync_filesystems"), 0, false);
548#endif 548#endif
549 549
550 pr_debug("PM: Preparing system for sleep (%s)\n", pm_states[state]); 550 pm_pr_dbg("Preparing system for sleep (%s)\n", pm_states[state]);
551 pm_suspend_clear_flags(); 551 pm_suspend_clear_flags();
552 error = suspend_prepare(state); 552 error = suspend_prepare(state);
553 if (error) 553 if (error)
@@ -557,13 +557,13 @@ static int enter_state(suspend_state_t state)
557 goto Finish; 557 goto Finish;
558 558
559 trace_suspend_resume(TPS("suspend_enter"), state, false); 559 trace_suspend_resume(TPS("suspend_enter"), state, false);
560 pr_debug("PM: Suspending system (%s)\n", pm_states[state]); 560 pm_pr_dbg("Suspending system (%s)\n", pm_states[state]);
561 pm_restrict_gfp_mask(); 561 pm_restrict_gfp_mask();
562 error = suspend_devices_and_enter(state); 562 error = suspend_devices_and_enter(state);
563 pm_restore_gfp_mask(); 563 pm_restore_gfp_mask();
564 564
565 Finish: 565 Finish:
566 pr_debug("PM: Finishing wakeup.\n"); 566 pm_pr_dbg("Finishing wakeup.\n");
567 suspend_finish(); 567 suspend_finish();
568 Unlock: 568 Unlock:
569 mutex_unlock(&pm_mutex); 569 mutex_unlock(&pm_mutex);