Skip to contentSkip to conversation

Report interrupt that caused system wakeup

PATCH Superseded Alexandra Yates 4 participants 7 messages Sep 10, 2015 – Sep 11, 2015 1 message not in the archive

Subsystems (5)

v7 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [PATCH V7] Report interrupt that caused system wakeup

#1 lore raw

PATCH v7 1/1 Report interrupt that caused system wakeup

This feature reports which IRQ cause the system to wakeup from sleep last time it was suspended.

It adds a new sysfs attribute under /sys/power/ named: pm_last_wakeup_irq when read, will return the IRQ that caused the system to wakeup. That will be useful for system wakeup diagnostics.

---
 Documentation/ABI/testing/sysfs-power | 11 +++++++++++
 drivers/base/power/wakeup.c           | 12 ++++++++++++
 include/linux/suspend.h               |  8 +++++++-
 kernel/irq/pm.c                       |  4 ++--
 kernel/power/main.c                   | 19 +++++++++++++++++++
 5 files changed, 51 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-power +11 -0
index f455181..4f9cc3a 100644
@@ -256,3 +256,14 @@ Description:
 		Writing a "1" enables this printing while writing a "0"
 		disables it.  The default value is "0".  Reading from this file
 		will display the current value.
+
+What:		/sys/power/pm_last_wakeup_irqs
+Date:		April 2015
+Contact:	Alexandra Yates <[email protected]>
+Description:
+		The /sys/power/pm_last_wakeup_irqs file allows user space
+		to identify and report the IRQs responsible for waking the
+		system up from sleep. The IRQD_WAKEUP_TRIGGERED flag is set and
+		reported when the given IRQ fires after it has been armed for
+		system wakeup. This output is useful for system wakeup
+		diagnostics.
drivers/base/power/wakeup.c +12 -0
index 51f15bc..f663fb1 100644
@@ -870,6 +870,18 @@ void pm_wakeup_clear(void)
 	pm_abort_suspend = false;
 }
 
+void pm_system_irq_wakeup(unsigned int irq_number)
+{
+	if (wakeup_irq == 0)
+		wakeup_irq = irq_number;
+	pm_system_wakeup();
+}
+
+void pm_last_wakeup_irq_reset(void)
+{
+	wakeup_irq = 0;
+}
+
 /**
  * pm_get_wakeup_count - Read the number of registered wakeup events.
  * @count: Address to store the value at.
include/linux/suspend.h +7 -1
index 5efe743..eb5ad3b 100644
@@ -371,6 +371,9 @@ static inline bool hibernation_available(void) { return false; }
 
 extern struct mutex pm_mutex;
 
+/* IRQ number which causes system wakeup  */
+extern unsigned int wakeup_irq;
+
 #ifdef CONFIG_PM_SLEEP
 void save_processor_state(void);
 void restore_processor_state(void);
@@ -378,7 +381,7 @@ void restore_processor_state(void);
 /* kernel/power/main.c */
 extern int register_pm_notifier(struct notifier_block *nb);
 extern int unregister_pm_notifier(struct notifier_block *nb);
-
+extern void pm_last_wakeup_irq_reset(void);
 #define pm_notifier(fn, pri) {				\
 	static struct notifier_block fn##_nb =			\
 		{ .notifier_call = fn, .priority = pri };	\
@@ -391,6 +394,7 @@ extern bool events_check_enabled;
 extern bool pm_wakeup_pending(void);
 extern void pm_system_wakeup(void);
 extern void pm_wakeup_clear(void);
+extern void pm_system_irq_wakeup(unsigned int);
 extern bool pm_get_wakeup_count(unsigned int *count, bool block);
 extern bool pm_save_wakeup_count(unsigned int count);
 extern void pm_wakep_autosleep_enabled(bool set);
@@ -440,6 +444,8 @@ static inline int unregister_pm_notifier(struct notifier_block *nb)
 static inline bool pm_wakeup_pending(void) { return false; }
 static inline void pm_system_wakeup(void) {}
 static inline void pm_wakeup_clear(void) {}
+static inline void pm_system_irq_wakeup(unsigned int) {}
+static inline void pm_last_wakeup_irq_reset(void){};
 
 static inline void lock_system_sleep(void) {}
 static inline void unlock_system_sleep(void) {}
kernel/irq/pm.c +2 -2
index d22786a..18178d7 100644
@@ -21,7 +21,7 @@ bool irq_pm_check_wakeup(struct irq_desc *desc)
 		desc->istate |= IRQS_SUSPENDED | IRQS_PENDING;
 		desc->depth++;
 		irq_disable(desc);
-		pm_system_wakeup();
+		pm_system_irq_wakeup(irq_desc_get_irq(desc));
 		return true;
 	}
 	return false;
@@ -118,7 +118,7 @@ void suspend_device_irqs(void)
 {
 	struct irq_desc *desc;
 	int irq;
-
+	pm_last_wakeup_irq_reset();
 	for_each_irq_desc(irq, desc) {
 		unsigned long flags;
 		bool sync;
kernel/power/main.c +19 -0
index 63d395b..d2bd164 100644
@@ -272,6 +272,24 @@ static inline void pm_print_times_init(void)
 {
 	pm_print_times_enabled = !!initcall_debug;
 }
+
+unsigned int wakeup_irq;
+EXPORT_SYMBOL_GPL(wakeup_irq);
+static ssize_t pm_last_wakeup_irq_show(struct kobject *kobj,
+					struct kobj_attribute *attr,
+					char *buf)
+{
+	return wakeup_irq ? sprintf(buf, "%u\n", wakeup_irq) : -EINVAL;
+}
+
+static ssize_t pm_last_wakeup_irq_store(struct kobject *kobj,
+					struct kobj_attribute *attr,
+					const char *buf, size_t n)
+{
+	return -EINVAL;
+}
+power_attr(pm_last_wakeup_irq);
+
 #else /* !CONFIG_PM_SLEEP_DEBUG */
 static inline void pm_print_times_init(void) {}
 #endif /* CONFIG_PM_SLEEP_DEBUG */
@@ -604,6 +622,7 @@ static struct attribute * g[] = {
 #endif
 #ifdef CONFIG_PM_SLEEP_DEBUG
 	&pm_print_times_attr.attr,
+	&pm_last_wakeup_irq_attr.attr,
 #endif
 #endif
 #ifdef CONFIG_FREEZER
Signature · 1 line
1.9.1
#2 lore raw

On (09/09/15 19:48), Alexandra Yates wrote:

[..]

Review

Quoted 7 lines
(quoted diff) +7 -0
+static ssize_t pm_last_wakeup_irq_store(struct kobject *kobj,
+					struct kobj_attribute *attr,
+					const char *buf, size_t n)
+{
+	return -EINVAL;
+}
+power_attr(pm_last_wakeup_irq);

a side note,
do you guys want to define a power_attr_ro() macro and to drop 'return -EINVAL' *_show() functions: pm_trace_dev_match_store() and pm_last_wakeup_irq_store()?

---

 kernel/power/main.c  | 9 +--------
 kernel/power/power.h | 9 +++++++++
 2 files changed, 10 insertions(+), 8 deletions(-)
kernel/power/main.c +1 -8
index 63d395b..0217a5c 100644
@@ -548,14 +548,7 @@ static ssize_t pm_trace_dev_match_show(struct kobject *kobj,
 	return show_trace_dev_match(buf, PAGE_SIZE);
 }
 
-static ssize_t
-pm_trace_dev_match_store(struct kobject *kobj, struct kobj_attribute *attr,
-			 const char *buf, size_t n)
-{
-	return -EINVAL;
-}
-
-power_attr(pm_trace_dev_match);
+power_attr_ro(pm_trace_dev_match);
 
 #endif /* CONFIG_PM_TRACE */
 
kernel/power/power.h +9 -0
index caadb56..efe1b3b 100644
@@ -77,6 +77,15 @@ static struct kobj_attribute _name##_attr = {	\
 	.store	= _name##_store,		\
 }
 
+#define power_attr_ro(_name) \
+static struct kobj_attribute _name##_attr = {	\
+	.attr	= {				\
+		.name = __stringify(_name),	\
+		.mode = S_IRUGO,		\
+	},					\
+	.show	= _name##_show,			\
+}
+
 /* Preferred image size in bytes (default 500 MB) */
 extern unsigned long image_size;
 /* Size of memory reserved for drivers (default SPARE_PAGES x PAGE_SIZE) */
#3 lore raw
In reply to Alexandra Yates
Quoted 2 lines · Alexandra Yates

This feature reports which IRQ cause the system to wakeup from sleep last time it was suspended.

I thought you said V7 of this patch was written based on the feedback I provided. Obviously that is not true.

This feature does NOT report which IRQ caused the system to wake up from sleep the last time it was suspended! All it does is report one of the IRQs which have occurred since the last time the system started a sleep transition.

Alan Stern

#4 lore raw

Hi Alan,

Quoted 6 lines · Alan Stern
Quoted 2 lines · Alexandra Yates

This feature reports which IRQ cause the system to wakeup from sleep last time it was suspended.

I thought you said V7 of this patch was written based on the feedback I provided. Obviously that is not true.

Yes, that was the intention.

Quoted 4 lines

This feature does NOT report which IRQ caused the system to wake up from sleep the last time it was suspended! All it does is report one of the IRQs which have occurred since the last time the system started a sleep transition.

I'm not sure why you say this, please elaborate further.

The way I understand the code and proposed solution is that when the system goes into freeze mode, at that point wakeup_irq is set to 0.

Once the system sees an interrupt at wakeup from freeze. wakeup_irq is set to the irq_number that caused the wakeup. This path of code is protected by spin lock,

which should protect the code path from other IRQs that came after the first IRQ. This is only set once. When other IRQs come and the wakeup_irq is set then the code doesn't store them.

Quoted 7 lines

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Thank you,
<Alexandra>
#5 lore raw
Quoted 10 lines · Alexandra Yates

Hi Alan,

Quoted 6 lines · Alan Stern
Quoted 2 lines · Alexandra Yates

This feature reports which IRQ cause the system to wakeup from sleep last time it was suspended.

I thought you said V7 of this patch was written based on the feedback I provided. Obviously that is not true.

Yes, that was the intention.

Quoted 8 lines
Quoted 4 lines

This feature does NOT report which IRQ caused the system to wake up from sleep the last time it was suspended! All it does is report one of the IRQs which have occurred since the last time the system started a sleep transition.

I'm not sure why you say this, please elaborate further.

The way I understand the code and proposed solution is that when the system goes into freeze mode, at that point wakeup_irq is set to 0.

I'm not sure what you mean by "freeze mode". Do you mean that all the user processes have been frozen?

Quoted 4 lines

Once the system sees an interrupt at wakeup from freeze. wakeup_irq is set to
the irq_number that caused the wakeup. This path of code is protected by spin lock,

The spin lock doesn't help if multiple IRQs have already been raised. How do you know which one caused the system to wake up?

Quoted 2 lines

which should protect the code path from other IRQs that came after the first IRQ.

Why so? Waking up from sleep is a slow procedure; there is time for several IRQs to be asserted before the system is ready to handle any of them. How do you know the first IRQ to be handled is the one that caused the wake up?

Quoted 3 lines

This is only set once. When other IRQs come and the wakeup_irq is set then the code
doesn't store them.

What if the system entered freeze mode but then returned to normal operation without ever going to sleep, because an IRQ occurred first? Wouldn't you then store that IRQ? But that IRQ did not cause the system to wake up, because the system never went to sleep.

Alan Stern

#6 lore raw
Quoted 9 lines · Alan Stern
Quoted 7 lines · Alexandra Yates

Hi Alan,

Quoted 4 lines · Alan Stern
Quoted 2 lines · Alexandra Yates

This feature reports which IRQ cause the system to wakeup from sleep last time it was suspended.

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

I thought you said V7 of this patch was written based on the feedback I provided. Obviously that is not true.

Yes, that was the intention.

Quoted 4 lines

This feature does NOT report which IRQ caused the system to wake up from sleep the last time it was suspended! All it does is report one of the IRQs which have occurred since the last time the system started a sleep transition.

It doesn't do that. It reports one of the IRQs that were armed for system wakeup and have occurred since suspend_device_irqs() was last called (and obviously before the subsequent resume_device_irqs() which clears the "armed for system wakeup" flag).

Quoted 8 lines
Quoted 4 lines

I'm not sure why you say this, please elaborate further.

The way I understand the code and proposed solution is that when the system goes into freeze mode, at that point wakeup_irq is set to 0.

I'm not sure what you mean by "freeze mode". Do you mean that all the user processes have been frozen?

Quoted 7 lines
Quoted 4 lines

Once the system sees an interrupt at wakeup from freeze. wakeup_irq is set to
the irq_number that caused the wakeup. This path of code is protected by spin lock,

The spin lock doesn't help if multiple IRQs have already been raised. How do you know which one caused the system to wake up?

Actually, we don't, which is a good point.

However, the purpose of this mechanism is mostly debugging spurious wakeup events and recording just the first wakeup interrupt we see should be sufficient for that.

Spurious wakeup interrupts that always come it along with legitimate ones are not really so much interesting from that angle. :-)

Quoted 8 lines
Quoted 2 lines

which should protect the code path from other IRQs that came after the first IRQ.

Why so? Waking up from sleep is a slow procedure; there is time for several IRQs to be asserted before the system is ready to handle any of them. How do you know the first IRQ to be handled is the one that caused the wake up?

Quoted 7 lines
Quoted 3 lines

This is only set once. When other IRQs come and the wakeup_irq is set then the code
doesn't store them.

What if the system entered freeze mode but then returned to normal operation without ever going to sleep, because an IRQ occurred first? Wouldn't you then store that IRQ?

If the IRQ has been armed for system wakeup, that counts as a wakeup from sleep.

Quoted 2 lines

But that IRQ did not cause the system to wake up, because the system never went to sleep.

I guess we should just say in the changelog and the documentation that we report that first wakeup interrupt we've seen in the last cycle (which may not be the first one that really occured in some cases).

Thanks,
Rafael

#7 lore raw
Quoted 31 lines · Rafael J. Wysocki
Quoted 2 lines

The spin lock doesn't help if multiple IRQs have already been raised. How do you know which one caused the system to wake up?

Actually, we don't, which is a good point.

However, the purpose of this mechanism is mostly debugging spurious wakeup events and recording just the first wakeup interrupt we see should be sufficient for that.

Spurious wakeup interrupts that always come it along with legitimate ones are not really so much interesting from that angle. :-)

Quoted 8 lines
Quoted 2 lines

which should protect the code path from other IRQs that came after the first IRQ.

Why so? Waking up from sleep is a slow procedure; there is time for several IRQs to be asserted before the system is ready to handle any of them. How do you know the first IRQ to be handled is the one that caused the wake up?

Quoted 7 lines
Quoted 3 lines

This is only set once. When other IRQs come and the wakeup_irq is set then the code
doesn't store them.

What if the system entered freeze mode but then returned to normal operation without ever going to sleep, because an IRQ occurred first? Wouldn't you then store that IRQ?

If the IRQ has been armed for system wakeup, that counts as a wakeup from sleep.

Quoted 6 lines
Quoted 2 lines

But that IRQ did not cause the system to wake up, because the system never went to sleep.

I guess we should just say in the changelog and the documentation that we report that first wakeup interrupt we've seen in the last cycle (which may not be the first one that really occured in some cases).

The patch itself is perfectly okay, as far as I can tell. I just didn't like the description, because it made claims that generally aren't true. The new description in the V8 submission is a lot better.

Alan Stern