Re: [PATCH] synchronize_irq needs a barrier

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Benjamin Herrenschmidt <benh@...>
Cc: Herbert Xu <herbert@...>, <akpm@...>, Linux Kernel Mailing List <linux-kernel@...>, <linuxppc-dev@...>, Ingo Molnar <mingo@...>, Thomas Gleixner <tglx@...>
Date: Thursday, October 18, 2007 - 7:39 pm

On Fri, 19 Oct 2007, Benjamin Herrenschmidt wrote:

So how about something like this (untested! not necessarily very well 
thought through either!)

Basic notion: the only thing that serializes the IRQ_INPROGRESS flag is 
the descriptor lock. And we don't have to (or even want to!) hold it while 
waiting for the thing, but we want to *have*held*it* in between whatever 
we're synchronizing with.

The internal irq handler functions already held the lock when they did 
whatever they need to serialize - and they are possibly performance 
critical too - so they use the "internal" function that doesn't get the 
lock unnecessarily again.

Hmm? 

		Linus

---
 kernel/irq/manage.c |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 80eab7a..f3e9575 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -14,6 +14,18 @@
 
 #include "internals.h"
 
+/*
+ * Internally wait for IRQ_INPROGRESS to go away on other CPU's,
+ * after having serialized with the descriptor lock.
+ */
+static inline void do_synchronize_irq(struct irq_desc *desc)
+{
+#ifdef CONFIG_SMP
+	while (desc->status & IRQ_INPROGRESS)
+		cpu_relax();
+#endif
+}
+
 #ifdef CONFIG_SMP
 
 /**
@@ -28,13 +40,15 @@
  */
 void synchronize_irq(unsigned int irq)
 {
+	unsigned long flags;
 	struct irq_desc *desc = irq_desc + irq;
 
 	if (irq >= NR_IRQS)
 		return;
 
-	while (desc->status & IRQ_INPROGRESS)
-		cpu_relax();
+	spin_lock_irqsave(&desc->lock, flags);
+	spin_unlock_irqrestore(&desc->lock, flags);
+	do_synchronize_irq(desc);
 }
 EXPORT_SYMBOL(synchronize_irq);
 
@@ -129,7 +143,7 @@ void disable_irq(unsigned int irq)
 
 	disable_irq_nosync(irq);
 	if (desc->action)
-		synchronize_irq(irq);
+		do_synchronize_irq(desc);
 }
 EXPORT_SYMBOL(disable_irq);
 
@@ -443,7 +457,7 @@ void free_irq(unsigned int irq, void *dev_id)
 			unregister_handler_proc(irq, action);
 
 			/* Make sure it's not being used on another CPU */
-			synchronize_irq(irq);
+			do_synchronize_irq(desc);
 #ifdef CONFIG_DEBUG_SHIRQ
 			/*
 			 * It's a shared IRQ -- the driver ought to be
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Wed Oct 17, 9:25 pm)
Re: [PATCH] synchronize_irq needs a barrier, Maxim Levitsky, (Fri Oct 19, 10:02 pm)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Fri Oct 19, 11:56 pm)
Re: [PATCH] synchronize_irq needs a barrier, Maxim Levitsky, (Sat Oct 20, 12:24 am)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Sat Oct 20, 1:04 am)
Re: [PATCH] synchronize_irq needs a barrier, Maxim Levitsky, (Sat Oct 20, 1:36 am)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Sat Oct 20, 1:46 am)
Re: [PATCH] synchronize_irq needs a barrier, Maxim Levitsky, (Sat Oct 20, 2:06 am)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Sat Oct 20, 2:13 am)
Re: [PATCH] synchronize_irq needs a barrier, Herbert Xu, (Fri Oct 19, 11:37 pm)
Re: [PATCH] synchronize_irq needs a barrier, Linus Torvalds, (Fri Oct 19, 10:25 pm)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Sat Oct 20, 12:04 am)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Sat Oct 20, 12:09 am)
Re: [PATCH] synchronize_irq needs a barrier, Maxim Levitsky, (Fri Oct 19, 11:10 pm)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Sat Oct 20, 12:06 am)
Re: [PATCH] synchronize_irq needs a barrier, Linus Torvalds, (Wed Oct 17, 10:12 pm)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Wed Oct 17, 10:40 pm)
Re: [PATCH] synchronize_irq needs a barrier, Herbert Xu, (Thu Oct 18, 10:35 am)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Thu Oct 18, 5:35 pm)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Wed Oct 17, 10:57 pm)
Re: [PATCH] synchronize_irq needs a barrier, Herbert Xu, (Thu Oct 18, 10:56 am)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Thu Oct 18, 6:05 pm)
Re: [PATCH] synchronize_irq needs a barrier, Linus Torvalds, (Thu Oct 18, 6:52 pm)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Thu Oct 18, 7:17 pm)
Re: [PATCH] synchronize_irq needs a barrier, Linus Torvalds, (Thu Oct 18, 7:39 pm)
Re: [PATCH] synchronize_irq needs a barrier, Herbert Xu, (Thu Oct 18, 10:32 pm)
Re: [PATCH] synchronize_irq needs a barrier, Linus Torvalds, (Thu Oct 18, 10:55 pm)
Re: [PATCH] synchronize_irq needs a barrier, Linus Torvalds, (Thu Oct 18, 11:26 pm)
Re: [PATCH] synchronize_irq needs a barrier, Herbert Xu, (Fri Oct 19, 12:20 am)
[NET]: Fix possible dev_deactivate race condition, Herbert Xu, (Fri Oct 19, 1:36 am)
Re: [NET]: Fix possible dev_deactivate race condition, Peter Zijlstra, (Fri Oct 19, 3:35 am)
Re: [NET]: Fix possible dev_deactivate race condition, David Miller, (Fri Oct 19, 1:38 am)
Re: [PATCH] synchronize_irq needs a barrier, Herbert Xu, (Fri Oct 19, 12:48 am)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Fri Oct 19, 12:58 am)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Sun Oct 21, 5:10 pm)
[IRQ]: Fix synchronize_irq races with IRQ handler, Herbert Xu, (Mon Oct 22, 11:26 pm)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Fri Oct 19, 12:35 am)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Fri Oct 19, 12:29 am)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Fri Oct 19, 12:11 am)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Fri Oct 19, 12:26 am)
Re: [PATCH] synchronize_irq needs a barrier, Herbert Xu, (Fri Oct 19, 1:53 am)
Re: [PATCH] synchronize_irq needs a barrier, Nick Piggin, (Thu Oct 18, 10:52 pm)
Re: [PATCH] synchronize_irq needs a barrier, Herbert Xu, (Thu Oct 18, 11:28 pm)
Re: [PATCH] synchronize_irq needs a barrier, Nick Piggin, (Fri Oct 19, 12:49 am)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Thu Oct 18, 7:52 pm)
Re: [PATCH] synchronize_irq needs a barrier, Andrew Morton, (Wed Oct 17, 9:45 pm)
Re: [PATCH] synchronize_irq needs a barrier, Benjamin Herrenschmidt, (Wed Oct 17, 9:55 pm)