Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PM / Sleep: Print last wakeup source on failed wakeup_count write

Commit a938da06 introduced a useful little log message to tell
users/debuggers which wakeup source aborted a suspend. However,
this message is only printed if the abort happens during the
in-kernel suspend path (after writing /sys/power/state).

The full specification of the /sys/power/wakeup_count facility
allows user-space power managers to double-check if wakeups have
already happened before it actually tries to suspend (e.g. while it
was running user-space pre-suspend hooks), by writing the last known
wakeup_count value to /sys/power/wakeup_count. This patch changes
the sysfs handler for that node to also print said log message if
that write fails, so that we can figure out the offending wakeup
source for both kinds of suspend aborts.

Signed-off-by: Julius Werner <jwerner@chromium.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Julius Werner and committed by
Rafael J. Wysocki
bb177fed d24c2a4f

+6 -2
+3 -2
drivers/base/power/wakeup.c
··· 659 659 } 660 660 EXPORT_SYMBOL_GPL(pm_wakeup_event); 661 661 662 - static void print_active_wakeup_sources(void) 662 + void pm_print_active_wakeup_sources(void) 663 663 { 664 664 struct wakeup_source *ws; 665 665 int active = 0; ··· 683 683 last_activity_ws->name); 684 684 rcu_read_unlock(); 685 685 } 686 + EXPORT_SYMBOL_GPL(pm_print_active_wakeup_sources); 686 687 687 688 /** 688 689 * pm_wakeup_pending - Check if power transition in progress should be aborted. ··· 710 709 711 710 if (ret) { 712 711 pr_info("PM: Wakeup pending, aborting suspend\n"); 713 - print_active_wakeup_sources(); 712 + pm_print_active_wakeup_sources(); 714 713 } 715 714 716 715 return ret;
+1
include/linux/suspend.h
··· 363 363 extern bool pm_get_wakeup_count(unsigned int *count, bool block); 364 364 extern bool pm_save_wakeup_count(unsigned int count); 365 365 extern void pm_wakep_autosleep_enabled(bool set); 366 + extern void pm_print_active_wakeup_sources(void); 366 367 367 368 static inline void lock_system_sleep(void) 368 369 {
+2
kernel/power/main.c
··· 424 424 if (sscanf(buf, "%u", &val) == 1) { 425 425 if (pm_save_wakeup_count(val)) 426 426 error = n; 427 + else 428 + pm_print_active_wakeup_sources(); 427 429 } 428 430 429 431 out: