lkml.org 
[lkml]   [2013]   [Jun]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] irq: add a new function irq_in_progress to check pending IRQ handlers
Date
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


\
 
 \ /
  Last update: 2013-06-06 10:41    [W:0.049 / U:3.824 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site