Skip to contentSkip to conversation

PM / Sleep: Print name of wakeup source that aborts suspend

PATCH Superseded Todd Poynor 2 participants 4 messages Jul 18, 2012 – Jul 20, 2012

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM / Sleep: Print name of wakeup source that aborts suspend

Print active wakeup sources, or the most recently active wakeup source, when a PM transition is aborted due to wakeup source events.

---
 drivers/base/power/wakeup.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

A driver or app may repeatedly request a wakeup source while the system is attempting to enter suspend, which may indicate a bug or at least point out a highly active system component that is responsible for decreased battery life on a mobile device. Even when the incidence of suspend abort is not severe, identifying wakeup sources that frequently abort suspend can be a useful clue for power management analysis.

In some cases the existing stats can point out the offender where there is an unexpectedly high activation count that stands out from the others, but in other cases the wakeup source frequently taken just after the rest of the system thinks its time to suspend might not stand out in the overall stats.

It is also often useful to have information about what's been happening recently, rather than totals of all activity for the system boot.

It's suggested to (optionally?) dump a line about which wakeup source aborted suspend to aid analysis of these situations.

drivers/base/power/wakeup.c +29 -0
index cbb463b..c079ffe 100644
@@ -649,6 +649,31 @@ void pm_wakeup_event(struct device *dev, unsigned int msec)
 }
 EXPORT_SYMBOL_GPL(pm_wakeup_event);
 
+static void print_active_wakeup_sources(void)
+{
+	struct wakeup_source *ws;
+	int active = 0;
+	struct wakeup_source *last_activity_ws = NULL;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
+		if (ws->active) {
+			pr_info("active wakeup source: %s\n", ws->name);
+			active = 1;
+		} else if (!active &&
+			   (!last_activity_ws ||
+			    ws->last_time.tv64 >
+			    last_activity_ws->last_time.tv64)) {
+			last_activity_ws = ws;
+		}
+	}
+
+	if (!active && last_activity_ws)
+		pr_info("last active wakeup source: %s\n",
+			last_activity_ws->name);
+	rcu_read_unlock();
+}
+
 /**
  * pm_wakeup_pending - Check if power transition in progress should be aborted.
  *
@@ -671,6 +696,10 @@ bool pm_wakeup_pending(void)
 		events_check_enabled = !ret;
 	}
 	spin_unlock_irqrestore(&events_lock, flags);
+
+	if (ret)
+		print_active_wakeup_sources();
+
 	return ret;
 }
 
Signature · 1 line
1.7.7.3
#1 lore raw
Quoted 38 lines · Todd Poynor

Print active wakeup sources, or the most recently active wakeup source, when a PM transition is aborted due to wakeup source events.

---
 drivers/base/power/wakeup.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

A driver or app may repeatedly request a wakeup source while the system is attempting to enter suspend, which may indicate a bug or at least point out a highly active system component that is responsible for decreased battery life on a mobile device. Even when the incidence of suspend abort is not severe, identifying wakeup sources that frequently abort suspend can be a useful clue for power management analysis.

In some cases the existing stats can point out the offender where there is an unexpectedly high activation count that stands out from the others, but in other cases the wakeup source frequently taken just after the rest of the system thinks its time to suspend might not stand out in the overall stats.

It is also often useful to have information about what's been happening recently, rather than totals of all activity for the system boot.

It's suggested to (optionally?) dump a line about which wakeup source aborted suspend to aid analysis of these situations.

drivers/base/power/wakeup.c +1 -0
index cbb463b..c079ffe 100644
@@ -649,6 +649,31 @@ void pm_wakeup_event(struct device *dev, unsigned int msec)
 }
 EXPORT_SYMBOL_GPL(pm_wakeup_event);
 
+static void print_active_wakeup_sources(void)

drivers/base/power/wakeup.c void pm_wakeup_event(struct device *dev, unsigned int msec) · line 662

Quoted 10 lines
drivers/base/power/wakeup.c +10 -0
+{
+	struct wakeup_source *ws;
+	int active = 0;
+	struct wakeup_source *last_activity_ws = NULL;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
+		if (ws->active) {
+			pr_info("active wakeup source: %s\n", ws->name);
+			active = 1;

Can we do a break here? Or do we want to get all of them?

drivers/base/power/wakeup.c void pm_wakeup_event(struct device *dev, unsigned int msec) · line 666

Quoted 4 lines
drivers/base/power/wakeup.c +4 -0
+		} else if (!active &&
+			   (!last_activity_ws ||
+			    ws->last_time.tv64 >
+			    last_activity_ws->last_time.tv64)) {

ktime_to_ns() anyone?

Quoted 14 lines
drivers/base/power/wakeup.c +10 -0
+			last_activity_ws = ws;
+		}
+	}
+
+	if (!active && last_activity_ws)
+		pr_info("last active wakeup source: %s\n",
+			last_activity_ws->name);
+	rcu_read_unlock();
+}
+
 /**
  * pm_wakeup_pending - Check if power transition in progress should be aborted.
  *

drivers/base/power/wakeup.c bool pm_wakeup_pending(void) · line 704

Quoted 9 lines
drivers/base/power/wakeup.c +4 -0
@@ -671,6 +696,10 @@ bool pm_wakeup_pending(void)
 		events_check_enabled = !ret;
 	}
 	spin_unlock_irqrestore(&events_lock, flags);
+
+	if (ret)
+		print_active_wakeup_sources();
+
 	return ret;
 }

There is no way this or equivalent can go into v3.6. It may go into v3.7, but there's a plenty of time for that.

Thanks,
Rafael

#2 lore raw
Quoted 1 line · Rafael J. Wysocki

On Wednesday, July 18, 2012, Todd Poynor wrote:

...

Quoted 4 lines
Quoted 4 lines
drivers/base/power/wakeup.c +4 -0
+{
+	struct wakeup_source *ws;
+	int active = 0;
+	struct wakeup_source *last_activity_ws = NULL;
Quoted 8 lines

drivers/base/power/wakeup.c void pm_wakeup_event(struct device *dev, unsigned int msec) · line 662

Quoted 6 lines
drivers/base/power/wakeup.c +6 -0
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
+		if (ws->active) {
+			pr_info("active wakeup source: %s\n", ws->name);
+			active = 1;

Can we do a break here? Or do we want to get all of them?

I haven't seen more than 3 activated during suspend entry at a time, but could just list one. I haven't made that change yet but will if it's preferred.

Quoted 7 lines

drivers/base/power/wakeup.c void pm_wakeup_event(struct device *dev, unsigned int msec) · line 666

Quoted 5 lines
drivers/base/power/wakeup.c +4 -0
+		} else if (!active &&
+			   (!last_activity_ws ||
+			    ws->last_time.tv64 >
+			    last_activity_ws->last_time.tv64)) {

ktime_to_ns() anyone?

Sure, I avoided it because some configs do math on each of these, but perhaps most implementations implement it as a NOP.

Quoted 19 lines
Quoted 19 lines
drivers/base/power/wakeup.c +11 -0
+			last_activity_ws = ws;
+		}
+	}
+
+	if (!active && last_activity_ws)
+		pr_info("last active wakeup source: %s\n",
+			last_activity_ws->name);
+	rcu_read_unlock();
+}
+
 /**
  * pm_wakeup_pending - Check if power transition in progress should be aborted.
  *
@@ -671,6 +696,10 @@ bool pm_wakeup_pending(void)
 		events_check_enabled = !ret;
 	}
 	spin_unlock_irqrestore(&events_lock, flags);
+
Quoted 8 lines

drivers/base/power/wakeup.c bool pm_wakeup_pending(void) · line 704

Quoted 5 lines
drivers/base/power/wakeup.c +3 -0
+	if (ret)
+		print_active_wakeup_sources();
+
 	return ret;
 }

There is no way this or equivalent can go into v3.6. It may go into v3.7, but there's a plenty of time for that.

Sounds fine, thanks.

Quoted 3 lines

Thanks,
Rafael

Todd

#3 lore raw
Quoted 16 lines · Todd Poynor
Quoted 1 line · Rafael J. Wysocki

On Wednesday, July 18, 2012, Todd Poynor wrote:

...

Quoted 4 lines
Quoted 4 lines
drivers/base/power/wakeup.c +4 -0
+{
+	struct wakeup_source *ws;
+	int active = 0;
+	struct wakeup_source *last_activity_ws = NULL;
Quoted 8 lines

drivers/base/power/wakeup.c void pm_wakeup_event(struct device *dev, unsigned int msec) · line 662

Quoted 6 lines
drivers/base/power/wakeup.c +6 -0
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
+		if (ws->active) {
+			pr_info("active wakeup source: %s\n", ws->name);
+			active = 1;

Can we do a break here? Or do we want to get all of them?

Quoted 3 lines

I haven't seen more than 3 activated during suspend entry at a time, but could just list one. I haven't made that change yet but will if it's preferred.

That depend on what your needs are. For debugging purposes it probably is better to print them all.

Thanks,
Rafael