public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] irq: add a new function irq_in_progress to check pending IRQ handlers
@ 2013-06-06  7:38 shuox.liu
  2013-06-06 13:18 ` Thomas Gleixner
  0 siblings, 1 reply; 11+ messages in thread
From: shuox.liu @ 2013-06-06  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: tglx, gregkh, fweisbec, sedat.dilek, yanmin_zhang, srivatsa.bhat,
	Zhang Yanmin, Liu ShuoX

From: Zhang Yanmin <yanmin.zhang@intel.com>

synchronize_irq waits pending IRQ handlers to be finished. If using this
function while holding a resource, the IRQ handler may cause deadlock.

Here we add a new function irq_in_progress which doesn't wait for the handlers
to be finished.

A typical use case at suspend-to-ram:

device driver's irq handler is complicated and might hold a mutex at rare cases.
Its suspend function is called and a suspended flag is set.
In case its IRQ handler is running, suspend function calls irq_in_progress. if
handler is running, abort suspend.
The irq handler checks the suspended flag. If the device is suspended, irq handler
either ignores the interrupt, or wakes up the whole system, and the driver's
resume function could deal with the delayed interrupt handling.

Signed-off-by: Zhang Yanmin <yanmin.zhang@intel.com>
Signed-off-by: Liu ShuoX <shuox.liu@intel.com>
---
 include/linux/hardirq.h |    5 +++++
 kernel/irq/manage.c     |   27 +++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/include/linux/hardirq.h b/include/linux/hardirq.h
index c1d6555..3bd5417 100644
--- a/include/linux/hardirq.h
+++ b/include/linux/hardirq.h
@@ -124,8 +124,13 @@
 
 #if defined(CONFIG_SMP) || defined(CONFIG_GENERIC_HARDIRQS)
 extern void synchronize_irq(unsigned int irq);
+extern int irq_in_progress(unsigned int irq);
 #else
 # define synchronize_irq(irq)	barrier()
+static inline int irq_in_progress(unsigned int irq)
+{
+	return 0;
+}
 #endif
 
 #if defined(CONFIG_TINY_RCU) || defined(CONFIG_TINY_PREEMPT_RCU)
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index fa17855..df18450 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -76,6 +76,33 @@ void synchronize_irq(unsigned int irq)
 }
 EXPORT_SYMBOL(synchronize_irq);
 
+/**
+ *	irq_in_progress - check pending IRQ handlers (on other CPUs)
+ *	@irq: interrupt number to check
+ *
+ *	This function checks any pending IRQ handlers for this interrupt.
+ *	The function does not wait for the IRQ handlers to be finished.
+ */
+int irq_in_progress(unsigned int irq)
+{
+	struct irq_desc *desc = irq_to_desc(irq);
+	int inprogress;
+
+	if (!desc)
+		return 0;
+
+	inprogress = irqd_irq_inprogress(&desc->irq_data);
+	if (!inprogress) {
+		/*
+		 * We made sure that no hardirq handler is running. Now verify
+		 * that no threaded handlers are active.
+		 */
+		inprogress =  atomic_read(&desc->threads_active);
+	}
+	return inprogress;
+}
+EXPORT_SYMBOL(irq_in_progress);
+
 #ifdef CONFIG_SMP
 cpumask_var_t irq_default_affinity;
 
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-06-08  2:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-06  7:38 [PATCH] irq: add a new function irq_in_progress to check pending IRQ handlers shuox.liu
2013-06-06 13:18 ` Thomas Gleixner
2013-06-07  0:53   ` Yanmin Zhang
2013-06-07  1:02     ` Greg KH
2013-06-07  2:37       ` Yanmin Zhang
2013-06-07  3:08         ` Greg KH
2013-06-07  3:18           ` Yanmin Zhang
2013-06-07  4:19             ` Greg KH
2013-06-07  4:54               ` Yanmin Zhang
2013-06-07 15:08                 ` Greg KH
2013-06-08  2:34                   ` Yanmin Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox