genirq: Simplify wakeup mechanism
authorThomas Gleixner <tglx@linutronix.de>
Fri, 29 Aug 2014 12:00:16 +0000 (14:00 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 1 Sep 2014 11:48:59 +0000 (13:48 +0200)
Currently we suspend wakeup interrupts by lazy disabling them and
check later whether the interrupt has fired, but that's not sufficient
for suspend to idle as there is no way to check that once we
transitioned into the CPU idle state.

So we change the mechanism in the following way:

1) Leave the wakeup interrupts enabled across suspend

2) Add a check to irq_may_run() which is called at the beginning of
   each flow handler whether the interrupt is an armed wakeup source.

   This check is basically free as it just extends the existing check
   for IRQD_IRQ_INPROGRESS. So no new conditional in the hot path.

   If the IRQD_WAKEUP_ARMED flag is set, then the interrupt is
   disabled, marked as pending/suspended and the pm core is notified
   about the wakeup event.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
[ rjw: syscore.c and put irq_pm_check_wakeup() into pm.c ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/syscore.c
include/linux/interrupt.h
kernel/irq/chip.c
kernel/irq/internals.h
kernel/irq/pm.c

index dbb8350ea8dc232d713a10c9a4179e221dbcbb45..8d98a329f6ea63a2daf179bb3f15e5307c6a0d13 100644 (file)
@@ -9,7 +9,7 @@
 #include <linux/syscore_ops.h>
 #include <linux/mutex.h>
 #include <linux/module.h>
-#include <linux/interrupt.h>
+#include <linux/suspend.h>
 #include <trace/events/power.h>
 
 static LIST_HEAD(syscore_ops_list);
@@ -54,9 +54,8 @@ int syscore_suspend(void)
        pr_debug("Checking wakeup interrupts\n");
 
        /* Return error code if there are any wakeup interrupts pending. */
-       ret = check_wakeup_irqs();
-       if (ret)
-               return ret;
+       if (pm_wakeup_pending())
+               return -EBUSY;
 
        WARN_ONCE(!irqs_disabled(),
                "Interrupts enabled before system core suspend.\n");
index 698ad053d064aef74793449f4b4b55018994a908..69517a24bc50678e4f2d69d931b9586cb76a9b69 100644 (file)
@@ -193,11 +193,6 @@ extern void irq_wake_thread(unsigned int irq, void *dev_id);
 /* The following three functions are for the core kernel use only. */
 extern void suspend_device_irqs(void);
 extern void resume_device_irqs(void);
-#ifdef CONFIG_PM_SLEEP
-extern int check_wakeup_irqs(void);
-#else
-static inline int check_wakeup_irqs(void) { return 0; }
-#endif
 
 /**
  * struct irq_affinity_notify - context for notification of IRQ affinity changes
index 6baf860855716578dc3c2756ae66b734d5bb2d18..e7917ff8a486e54884ae07c4381b04bda6cd2ab9 100644 (file)
@@ -344,8 +344,26 @@ static bool irq_check_poll(struct irq_desc *desc)
 
 static bool irq_may_run(struct irq_desc *desc)
 {
-       if (!irqd_irq_inprogress(&desc->irq_data))
+       unsigned int mask = IRQD_IRQ_INPROGRESS | IRQD_WAKEUP_ARMED;
+
+       /*
+        * If the interrupt is not in progress and is not an armed
+        * wakeup interrupt, proceed.
+        */
+       if (!irqd_has_set(&desc->irq_data, mask))
                return true;
+
+       /*
+        * If the interrupt is an armed wakeup source, mark it pending
+        * and suspended, disable it and notify the pm core about the
+        * event.
+        */
+       if (irq_pm_check_wakeup(desc))
+               return false;
+
+       /*
+        * Handle a potential concurrent poll on a different core.
+        */
        return irq_check_poll(desc);
 }
 
index c402502a5111f6c1abc403060ceb4257a793aca0..4332d766619d1c700c600ec0678bc6c3ca47a6fa 100644 (file)
@@ -196,9 +196,11 @@ static inline void kstat_incr_irqs_this_cpu(unsigned int irq, struct irq_desc *d
 }
 
 #ifdef CONFIG_PM_SLEEP
+bool irq_pm_check_wakeup(struct irq_desc *desc);
 void irq_pm_install_action(struct irq_desc *desc, struct irqaction *action);
 void irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action);
 #else
+static inline bool irq_pm_check_wakeup(struct irq_desc *desc) { return false; }
 static inline void
 irq_pm_install_action(struct irq_desc *desc, struct irqaction *action) { }
 static inline void
index 766930eaeed9c99647f5c186fe69ca58c49190d9..3ca5325927045572edfa7d3eebd79f01b2a4c29a 100644 (file)
@@ -9,10 +9,24 @@
 #include <linux/irq.h>
 #include <linux/module.h>
 #include <linux/interrupt.h>
+#include <linux/suspend.h>
 #include <linux/syscore_ops.h>
 
 #include "internals.h"
 
+bool irq_pm_check_wakeup(struct irq_desc *desc)
+{
+       if (irqd_is_wakeup_armed(&desc->irq_data)) {
+               irqd_clear(&desc->irq_data, IRQD_WAKEUP_ARMED);
+               desc->istate |= IRQS_SUSPENDED | IRQS_PENDING;
+               desc->depth++;
+               irq_disable(desc);
+               pm_system_wakeup();
+               return true;
+       }
+       return false;
+}
+
 /*
  * Called from __setup_irq() with desc->lock held after @action has
  * been installed in the action chain.
@@ -54,8 +68,16 @@ static bool suspend_device_irq(struct irq_desc *desc, int irq)
        if (!desc->action || desc->no_suspend_depth)
                return false;
 
-       if (irqd_is_wakeup_set(&desc->irq_data))
+       if (irqd_is_wakeup_set(&desc->irq_data)) {
                irqd_set(&desc->irq_data, IRQD_WAKEUP_ARMED);
+               /*
+                * We return true here to force the caller to issue
+                * synchronize_irq(). We need to make sure that the
+                * IRQD_WAKEUP_ARMED is visible before we return from
+                * suspend_device_irqs().
+                */
+               return true;
+       }
 
        desc->istate |= IRQS_SUSPENDED;
        __disable_irq(desc, irq);
@@ -79,9 +101,13 @@ static bool suspend_device_irq(struct irq_desc *desc, int irq)
  * for this purpose.
  *
  * So we disable all interrupts and mark them IRQS_SUSPENDED except
- * for those which are unused and those which are marked as not
+ * for those which are unused, those which are marked as not
  * suspendable via an interrupt request with the flag IRQF_NO_SUSPEND
- * set.
+ * set and those which are marked as active wakeup sources.
+ *
+ * The active wakeup sources are handled by the flow handler entry
+ * code which checks for the IRQD_WAKEUP_ARMED flag, suspends the
+ * interrupt and notifies the pm core about the wakeup.
  */
 void suspend_device_irqs(void)
 {
@@ -173,26 +199,3 @@ void resume_device_irqs(void)
        resume_irqs(false);
 }
 EXPORT_SYMBOL_GPL(resume_device_irqs);
-
-/**
- * check_wakeup_irqs - check if any wake-up interrupts are pending
- */
-int check_wakeup_irqs(void)
-{
-       struct irq_desc *desc;
-       int irq;
-
-       for_each_irq_desc(irq, desc) {
-               /*
-                * Only interrupts which are marked as wakeup source
-                * and have not been disabled before the suspend check
-                * can abort suspend.
-                */
-               if (irqd_is_wakeup_set(&desc->irq_data)) {
-                       if (desc->depth == 1 && desc->istate & IRQS_PENDING)
-                               return -EBUSY;
-               }
-       }
-
-       return 0;
-}