Skip to contentSkip to conversation

add hook to generic irq code (free_irq)

PATCH In review Chris Wedgwood 3 participants 7 messages Oct 20, 2004 – Jan 13, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add hook to generic irq code (free_irq)

This is needed because some architectures (well, presently only UML) needs to be notified as things are freed.

Signed-off-by [email protected]

I can't say I'm 100% happy about this, either the name or a somewhat ugly hook that is called with a spinlock held but for lack of any better suggestions...

Comments?

 include/asm-i386/hardirq.h   |    3 +++
 include/asm-ppc/hardirq.h    |    3 +++
 include/asm-ppc64/hardirq.h  |    3 +++
 include/asm-x86_64/hardirq.h |    4 ++++
 kernel/irq/manage.c          |    1 +
 5 files changed, 14 insertions(+)
include/asm-i386/hardirq.h +3 -0
diff -Nru a/include/asm-i386/hardirq.h b/include/asm-i386/hardirq.h
@@ -16,4 +16,7 @@
 
 void ack_bad_irq(unsigned int irq);
 
+/* NOP */
+#define platform_free_irq_notify(i, d)
+
 #endif /* __ASM_HARDIRQ_H */
include/asm-ppc/hardirq.h +3 -0
diff -Nru a/include/asm-ppc/hardirq.h b/include/asm-ppc/hardirq.h
@@ -27,5 +27,8 @@
 	BUG();
 }
 
+/* NOP */
+#define platform_free_irq_notify(i, d)
+
 #endif /* __ASM_HARDIRQ_H */
 #endif /* __KERNEL__ */
include/asm-ppc64/hardirq.h +3 -0
diff -Nru a/include/asm-ppc64/hardirq.h b/include/asm-ppc64/hardirq.h
@@ -25,4 +25,7 @@
 	BUG();
 }
 
+/* NOP */
+#define platform_free_irq_notify(i, d)
+
 #endif /* __ASM_HARDIRQ_H */
include/asm-x86_64/hardirq.h +4 -0
diff -Nru a/include/asm-x86_64/hardirq.h b/include/asm-x86_64/hardirq.h
@@ -36,4 +36,8 @@
 #endif
 #endif
 }
+
+/* NOP */
+#define platform_irq_free_notify(i, d)
+
 #endif /* __ASM_HARDIRQ_H */
kernel/irq/manage.c +1 -0
diff -Nru a/kernel/irq/manage.c b/kernel/irq/manage.c
@@ -260,6 +260,7 @@
 				else
 					desc->handler->disable(irq);
 			}
+			platform_free_irq_notify(irq, dev_id);
 			spin_unlock_irqrestore(&desc->lock,flags);
 			unregister_handler_proc(irq, action);
 
#1 lore raw
Quoted 9 lines · Chris Wedgwood

This is needed because some architectures (well, presently only UML) needs to be notified as things are freed.

Signed-off-by [email protected]

I can't say I'm 100% happy about this, either the name or a somewhat ugly hook that is called with a spinlock held but for lack of any better suggestions...

This looks rather bogus to me. What prevents UML from doing it's work at the struct hw_interrupt_type level?

#2 lore raw
Quoted 2 lines · Christoph Hellwig

This looks rather bogus to me. What prevents UML from doing it's work at the struct hw_interrupt_type level?

Probably nothing, it's just not clear to me how that would work or should look. Let me poke about and see if I can figure it out.

#3 lore raw

RFC 1/1 add struct hw_interrupt_type->release

In reply to Christoph Hellwig

Review line 262

Quoted 5 lines · Chris Wedgwood

+++ b/kernel/irq/manage.c 2004-10-19 17:47:40 -07:00

(quoted diff) +0 -0
@@ -260,6 +260,7 @@
 				else
 					desc->handler->disable(irq);
 			}
                       ^^^
Quoted 4 lines
(quoted diff) +1 -0
+			platform_free_irq_notify(irq, dev_id);
 			spin_unlock_irqrestore(&desc->lock,flags);
 			unregister_handler_proc(irq, action);
 
Quoted 2 lines · Christoph Hellwig

This looks rather bogus to me. What prevents UML from doing it's work at the struct hw_interrupt_type level?

the ^^^ marked part reads something like if (!desc->action) { ... } presumably meaning the shutdown/disable is only done when the very last user of an interrupt source is removed

UML needs to be notified when *any* user is removed so either need some way to tell the generic code this or perhaps we could introduce another op to hw_interrupt_type along the lines of ->release like this:

===== include/linux/irq.h 1.12 vs edited =====

include/linux/irq.h +1 -0
@@ -47,6 +47,7 @@ struct hw_interrupt_type {
 	void (*ack)(unsigned int irq);
 	void (*end)(unsigned int irq);
 	void (*set_affinity)(unsigned int irq, cpumask_t dest);
+	void (*release)(unsigned int irq, void *dev_id);
 };
 
 typedef struct hw_interrupt_type  hw_irq_controller;

===== kernel/irq/manage.c 1.1 vs edited =====

kernel/irq/manage.c +4 -0
@@ -253,6 +253,10 @@ void free_irq(unsigned int irq, void *de
 
 			/* Found it - now remove it from the list of entries */
 			*pp = action->next;
+
+			if (desc->handler->release)
+				desc->handler->release(irq, dev_id);
+
 			if (!desc->action) {
 				desc->status |= IRQ_DISABLED;
 				if (desc->handler->shutdown)
#4 lore raw

RFC 1/1 UML converstion to generic irq code (requires hw_interrupt_type->release(...) patch)

Quoted 3 lines

UML needs to be notified when *any* user is removed so either need some way to tell the generic code this or perhaps we could introduce another op to hw_interrupt_type along the lines of ->release like

[...]

and the UML changes to support this:

 arch/um/Kconfig               |    5 
 arch/um/include/irq_user.h    |    2 
 arch/um/kernel/irq.c          |  650 +-----------------------------------------
 arch/um/kernel/irq_user.c     |    2 
 arch/um/kernel/process_kern.c |    1 
 include/asm-um/hardirq.h      |   28 +
 6 files changed, 51 insertions(+), 637 deletions(-)

(actually, i think there is an uninteresting/obvious hunk missing, i'll resend send all this properly after feedback though)

===== arch/um/Kconfig 1.18 vs edited =====

arch/um/Kconfig +5 -0
@@ -1,3 +1,8 @@
+# UML uses the generic IRQ sugsystem
+config GENERIC_HARDIRQS
+	bool
+	default y
+
 config USERMODE
 	bool
 	default y

===== arch/um/include/irq_user.h 1.4 vs edited =====

arch/um/include/irq_user.h +1 -1
@@ -10,7 +10,7 @@
 
 extern void sigio_handler(int sig, union uml_pt_regs *regs);
 extern int activate_fd(int irq, int fd, int type, void *dev_id);
-extern void free_irq_by_irq_and_dev(int irq, void *dev_id);
+extern void free_irq_by_irq_and_dev(unsigned int irq, void *dev_id);
 extern void free_irq_by_fd(int fd);
 extern void reactivate_fd(int fd, int irqnum);
 extern void deactivate_fd(int fd, int irqnum);

===== arch/um/kernel/irq.c 1.21 vs edited =====

arch/um/kernel/irq.c +20 -630

695 lines not on this page · raw message

===== arch/um/kernel/irq_user.c 1.11 vs edited =====

arch/um/kernel/irq_user.c +1 -1
@@ -263,7 +263,7 @@
 	return((irq->irq == data->irq) && (irq->id == data->dev));
 }
 
-void free_irq_by_irq_and_dev(int irq, void *dev)
+void free_irq_by_irq_and_dev(unsigned int irq, void *dev)
 {
 	struct irq_and_dev data = ((struct irq_and_dev) { .irq  = irq,
 							  .dev  = dev });

===== arch/um/kernel/process_kern.c 1.23 vs edited =====

arch/um/kernel/process_kern.c +0 -1
@@ -206,7 +206,6 @@
 		 * although we are an idle CPU, we do not want to
 		 * get into the scheduler unnecessarily.
 		 */
-		irq_stat[smp_processor_id()].idle_timestamp = jiffies;
 		if(need_resched())
 			schedule();
 		

===== include/asm-um/hardirq.h 1.1 vs edited =====

include/asm-um/hardirq.h +24 -4
@@ -1,6 +1,26 @@
-#ifndef __UM_HARDIRQ_H
-#define __UM_HARDIRQ_H
+/* (c) 2004 [email protected], GPLv2 blah blah */
 
-#include "asm/arch/hardirq.h"
+#ifndef __ASM_UM_HARDIRQ_H
+#define __ASM_UM_HARDIRQ_H
 
-#endif
+#include <linux/config.h>
+#include <linux/threads.h>
+#include <linux/irq.h>
+
+/* NOTE: When SMP works again we might want to make this
+ * ____cacheline_aligned or maybe use per_cpu state? --cw */
+typedef struct {
+	unsigned int __softirq_pending;
+} irq_cpustat_t;
+
+#include <linux/irq_cpustat.h>
+
+/* As this would be very strange for UML to get we BUG() after the
+ * printk. */
+static inline void ack_bad_irq(unsigned int irq)
+{
+	printk(KERN_ERR "unexpected IRQ %02x\n", irq);
+	BUG();
+}
+
+#endif /* __ASM_UM_HARDIRQ_H */
#5 lore raw

Re: [RFC] add struct hw_interrupt_type->release

In reply to Chris Wedgwood
Quoted 18 lines · Chris Wedgwood

Review line 262

Quoted 5 lines · Chris Wedgwood

+++ b/kernel/irq/manage.c 2004-10-19 17:47:40 -07:00

(quoted diff) +0 -0
@@ -260,6 +260,7 @@
 				else
 					desc->handler->disable(irq);
 			}
                       ^^^
Quoted 4 lines
(quoted diff) +1 -0
+			platform_free_irq_notify(irq, dev_id);
 			spin_unlock_irqrestore(&desc->lock,flags);
 			unregister_handler_proc(irq, action);
 
Quoted 2 lines · Christoph Hellwig

This looks rather bogus to me. What prevents UML from doing it's work at the struct hw_interrupt_type level?

Quoted 8 lines

the ^^^ marked part reads something like if (!desc->action) { ... } presumably meaning the shutdown/disable is only done when the very last user of an interrupt source is removed

UML needs to be notified when *any* user is removed so either need some way to tell the generic code this or perhaps we could introduce another op to hw_interrupt_type along the lines of ->release like this:

Care to explain why it needs that? How exactly is UML using hardirqs, they seems to fit very badly into the concept of a usermode kernel if you ask me. Maybe UML would be better off to not use hardirqs at all, ala s390.

#6 lore raw

Re: [RFC] add struct hw_interrupt_type->release

Quoted 29 lines · Christoph Hellwig <hch <at> infradead.org> writes:
Quoted 18 lines · Chris Wedgwood

Review

Quoted 5 lines · Chris Wedgwood

+++ b/kernel/irq/manage.c 2004-10-19 17:47:40 -07:00
<at> <at> -260,6 +260,7 <at> <at>

(quoted diff) +0 -0
 				else
 					desc->handler->disable(irq);
 			}
                       ^^^
Quoted 4 lines
(quoted diff) +1 -0
+			platform_free_irq_notify(irq, dev_id);
 			spin_unlock_irqrestore(&desc->lock,flags);
 			unregister_handler_proc(irq, action);
Quoted 2 lines · Christoph Hellwig

This looks rather bogus to me. What prevents UML from doing it's work at the struct hw_interrupt_type level?

Quoted 8 lines

the ^^^ marked part reads something like if (!desc->action) { ... } presumably meaning the shutdown/disable is only done when the very last user of an interrupt source is removed

UML needs to be notified when *any* user is removed so either need some way to tell the generic code this or perhaps we could introduce another op to hw_interrupt_type along the lines of ->release like this:

Quoted 6 lines

Care to explain why it needs that? How exactly is UML using hardirqs, they seems to fit very badly into the concept of a usermode kernel if you ask me.

Maybe UML would be better off to not use hardirqs at all, ala s390.

I don't know about s390, however we have another developer in UML which has experience with Linux on that platform... I'll ask him.

However, the main idea is if an hardirq is raised, something has happened on a certain file descriptor, associated with the IRQ; the definition of "something has happened" is the one which holds for poll(), which is used to implement this (see arch/um/kernel/irq_user.c:activate_fd() ).

So, it is clear the need we have?

One real example is for /dev/tty1, when it's emulated by an xterm: we use an IRQ to wait for when we receive on a socket the fd of the pipe which connects us with the xterm. (The actual datas are not passed through the IRQ).

However, any plan about removing the hardirqs from UML is low-priority for me... we have the main need to get the code stable, afterwards to add new missing important features, and at the end to rewrite such things... at least until when we see the need for such a rewrite.

But the idea is not bad, I think (I am a newcomer, so I don't know why and when it was born, for this you could ask to Jeff Dike, if you want).