From: shuox.liu@intel.com
To: linux-kernel@vger.kernel.org
Cc: tglx@linutronix.de, gregkh@linuxfoundation.org,
fweisbec@gmail.com, sedat.dilek@gmail.com,
yanmin_zhang@linux.intel.com, srivatsa.bhat@linux.vnet.ibm.com,
Zhang Yanmin <yanmin.zhang@intel.com>,
Liu ShuoX <shuox.liu@intel.com>
Subject: [PATCH] irq: add a new function irq_in_progress to check pending IRQ handlers
Date: Thu, 6 Jun 2013 15:38:16 +0800 [thread overview]
Message-ID: <1370504296-24389-1-git-send-email-shuox.liu@intel.com> (raw)
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
next reply other threads:[~2013-06-06 7:43 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-06 7:38 shuox.liu [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1370504296-24389-1-git-send-email-shuox.liu@intel.com \
--to=shuox.liu@intel.com \
--cc=fweisbec@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sedat.dilek@gmail.com \
--cc=srivatsa.bhat@linux.vnet.ibm.com \
--cc=tglx@linutronix.de \
--cc=yanmin.zhang@intel.com \
--cc=yanmin_zhang@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®