Skip to contentSkip to conversation

Add support for threaded interrupt handlers - V3

PATCH In review Thomas Gleixner 3 participants 11 messages Mar 23, 2009 – Mar 25, 2009

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

cover Add support for threaded interrupt handlers - V3

This patch series implements support for threaded irq handlers for the generic IRQ layer.

Changes vs. V2:
- review comments addressed
- simplified design
- synchronize_irq adapted to threaded handlers

Threaded interrupt handlers are not only interesting in the preempt-rt context. Threaded interrupt handlers can help to address common problems in the interrupt handling code:

- move long running handlers out of the hard interrupt context

- avoid complex hardirq -> tasklet/softirq interaction and locking problems by integration of this functionality into the threaded handler code

- improved debugability of the kernel: faulty handlers do not take down the system.

- allows prioritizing of the handlers which share an interrupt line

The implementation provides an opt-in mechanism to convert drivers to the threaded interrupt handler model contrary to the preempt-rt patch where the threaded handlers are enabled by a brute force switch. The brute force switch is suboptimal as it does not change the interrupt handler -> tasklet/softirq interaction problems, but was the only way which was possible for the limited man power of the preempt-rt developers.

Converting an interrupt to threaded makes only sense when the handler code takes advantage of it by integrating tasklet/softirq functionality and simplifying the locking.

When a driver wants to use threaded interrupt handlers it needs to provide a separate thread function, which is called from the per device thread created in irq_request_threaded(). The primary handler still needs to be supplied. It checks whether the interrupt was originated from the device or not.

In case it was originated from the device the primary handler must disable the interrupt at the device level and return IRQ_WAKE_THREAD. The generic interrupt handling core then sets the IRQF_RUNTHREAD in the irqaction of the handler and wakes the associated thread.

The irqaction is referenced in the threads task_struct. The reference is used to prevent further referencing of the thread in the interrupt code in the case of segfault to make sure that the system (minus the now dead interrupt handler) survives and debug information can be retrieved. In the best case the driver can be restarted, but dont expect that as a given.

The code was tested with a converted USB EHCI driver. The EHCI shares an interrupt line with another device and both the threaded and the non threaded handlers coexist nicely.

Further the AHCI driver for ICH chipsets was converted and tested. Interestingly enough this conversion did not cause worse benchmark results with iobench and fio compared to the non threaded mainline handler.

I'm still looking into a clean solution for the threaded demultiplex handler case which was brought up by Dave to allow both the handling of the demultiplexed devices in the context of the demultiplexer interrupt thread and the wakeup of separate handler threads. But this is an orthogonal extension of the existing patch set and does not change the general design.

The patches apply on
git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git irq/threaded

The irq/threaded branch contains the generic irq related changes which are already queued for .30

Thanks,

tglx

#1 lore raw

PATCH 1/2 genirq: add threaded interrupt handler support

Add support for threaded interrupt handlers:

A device driver can request that its main interrupt handler runs in a thread. To achive this the device driver requests the interrupt with request_threaded_irq() and provides additionally to the handler a thread function. The handler function is called in hard interrupt context and needs to check whether the interrupt originated from the device. If the interrupt originated from the device then the handler can either return IRQ_HANDLED or IRQ_WAKE_THREAD. IRQ_HANDLED is returned when no further action is required. IRQ_WAKE_THREAD causes the genirq code to invoke the threaded (main) handler. When IRQ_WAKE_THREAD is returned handler must have disabled the interrupt on the device level. This is mandatory for shared interrupt handlers, but we need to do it as well for obscure x86 hardware where disabling an interrupt on the IO_APIC level redirects the interrupt to the legacy PIC interrupt lines.

---
 include/linux/hardirq.h   |    2 
 include/linux/interrupt.h |   37 ++++++++
 include/linux/irq.h       |    5 +
 include/linux/irqreturn.h |    2 
 include/linux/sched.h     |    5 +
 kernel/exit.c             |    2 
 kernel/irq/handle.c       |   31 +++++++
 kernel/irq/manage.c       |  193 ++++++++++++++++++++++++++++++++++++++++++----
 8 files changed, 260 insertions(+), 17 deletions(-)
include/linux/hardirq.h +1 -1
Index: linux-2.6-tip/include/linux/hardirq.h
===================================================================
@@ -105,7 +105,7 @@
 # define IRQ_EXIT_OFFSET HARDIRQ_OFFSET
 #endif
 
-#ifdef CONFIG_SMP
+#if defined(CONFIG_SMP) || defined(CONFIG_GENERIC_HARDIRQS)
 extern void synchronize_irq(unsigned int irq);
 #else
 # define synchronize_irq(irq)	barrier()
include/linux/interrupt.h +35 -2
Index: linux-2.6-tip/include/linux/interrupt.h
===================================================================
@@ -59,6 +59,16 @@
 #define IRQF_NOBALANCING	0x00000800
 #define IRQF_IRQPOLL		0x00001000
 
+/*
+ * Bits used by threaded handlers:
+ * IRQTF_RUNTHREAD - signals that the interrupt handler thread should run
+ * IRQTF_DIED      - handler thread died
+ */
+enum {
+	IRQTF_RUNTHREAD,
+	IRQTF_DIED,
+};
+
 typedef irqreturn_t (*irq_handler_t)(int, void *);
 
 /**
@@ -71,6 +81,9 @@ typedef irqreturn_t (*irq_handler_t)(int
  * @next:	pointer to the next irqaction for shared interrupts
  * @irq:	interrupt number
  * @dir:	pointer to the proc/irq/NN/name entry
+ * @thread_fn:	interupt handler function for threaded interrupts
+ * @thread:	thread pointer for threaded interrupts
+ * @thread_flags:	flags related to @thread
  */
 struct irqaction {
 	irq_handler_t handler;
@@ -81,11 +94,31 @@ struct irqaction {
 	struct irqaction *next;
 	int irq;
 	struct proc_dir_entry *dir;
+	irq_handler_t thread_fn;
+	struct task_struct *thread;
+	unsigned long thread_flags;
 };
 
 extern irqreturn_t no_action(int cpl, void *dev_id);
-extern int __must_check request_irq(unsigned int, irq_handler_t handler,
-		       unsigned long, const char *, void *);
+
+extern int __must_check
+request_threaded_irq(unsigned int irq, irq_handler_t handler,
+		     irq_handler_t thread_fn,
+		     unsigned long flags, const char *name, void *dev);
+
+static inline int __must_check
+request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
+	    const char *name, void *dev)
+{
+	return request_threaded_irq(irq, handler, NULL, flags, name, dev);
+}
+
+#ifdef CONFIG_GENERIC_HARDIRQS
+extern void exit_irq_thread(void);
+#else
+static inline void exit_irq_thread(void) { }
+#endif
+
 extern void free_irq(unsigned int, void *);
 
 struct device;
include/linux/irq.h +5 -0
Index: linux-2.6-tip/include/linux/irq.h
===================================================================
@@ -20,6 +20,7 @@
 #include <linux/irqreturn.h>
 #include <linux/irqnr.h>
 #include <linux/errno.h>
+#include <linux/wait.h>
 
 #include <asm/irq.h>
 #include <asm/ptrace.h>
@@ -155,6 +156,8 @@ struct irq_2_iommu;
  * @affinity:		IRQ affinity on SMP
  * @cpu:		cpu index useful for balancing
  * @pending_mask:	pending rebalanced interrupts
+ * @threads_active:	number of irqaction threads currently running
+ * @wait_for_threads:	wait queue for sync_irq to wait for threaded handlers
  * @dir:		/proc/irq/ procfs entry
  * @name:		flow handler name for /proc/interrupts output
  */
@@ -186,6 +189,8 @@ struct irq_desc {
 	cpumask_var_t		pending_mask;
 #endif
 #endif
+	atomic_t		threads_active;
+	wait_queue_head_t       wait_for_threads;
 #ifdef CONFIG_PROC_FS
 	struct proc_dir_entry	*dir;
 #endif
include/linux/irqreturn.h +2 -0
Index: linux-2.6-tip/include/linux/irqreturn.h
===================================================================
@@ -5,10 +5,12 @@
  * enum irqreturn
  * @IRQ_NONE		interrupt was not from this device
  * @IRQ_HANDLED		interrupt was handled by this device
+ * @IRQ_WAKE_THREAD	handler requests to wake the handler thread
  */
 enum irqreturn {
 	IRQ_NONE,
 	IRQ_HANDLED,
+	IRQ_WAKE_THREAD,
 };
 
 typedef enum irqreturn irqreturn_t;
include/linux/sched.h +5 -0
Index: linux-2.6-tip/include/linux/sched.h
===================================================================
@@ -1292,6 +1292,11 @@ struct task_struct {
 /* Protection of (de-)allocation: mm, files, fs, tty, keyrings */
 	spinlock_t alloc_lock;
 
+#ifdef CONFIG_GENERIC_HARDIRQS
+	/* IRQ handler threads */
+	struct irqaction *irqaction;
+#endif
+
 	/* Protection of the PI data structures: */
 	spinlock_t pi_lock;
 
kernel/exit.c +2 -0
Index: linux-2.6-tip/kernel/exit.c
===================================================================
@@ -1037,6 +1037,8 @@ NORET_TYPE void do_exit(long code)
 		schedule();
 	}
 
+	exit_irq_thread();
+
 	exit_signals(tsk);  /* sets PF_EXITING */
 	/*
 	 * tsk->flags are checked in the futex code to protect against
kernel/irq/handle.c +30 -1
Index: linux-2.6-tip/kernel/irq/handle.c
===================================================================
@@ -358,8 +358,37 @@ irqreturn_t handle_IRQ_event(unsigned in
 
 	do {
 		ret = action->handler(irq, action->dev_id);
-		if (ret == IRQ_HANDLED)
+
+		switch (ret) {
+		case IRQ_WAKE_THREAD:
+			/*
+			 * Wake up the handler thread for this
+			 * action. In case the thread crashed and was
+			 * killed we just pretend that we handled the
+			 * interrupt. The hardirq handler above has
+			 * disabled the device interrupt, so no irq
+			 * storm is lurking.
+			 */
+			if (likely(!test_bit(IRQTF_DIED,
+					     &action->thread_flags))) {
+				set_bit(IRQTF_RUNTHREAD, &action->thread_flags);
+				wake_up_process(action->thread);
+			}
+
+			/*
+			 * Set it to handled so the spurious check
+			 * does not trigger.
+			 */
+			ret = IRQ_HANDLED;
+			/* Fall through to add to randomness */
+		case IRQ_HANDLED:
 			status |= action->flags;
+			break;
+
+		default:
+			break;
+		}
+
 		retval |= ret;
 		action = action->next;
 	} while (action);
kernel/irq/manage.c +179 -13

308 lines not on this page · raw message

#2 lore raw

Re: [patch 1/2] genirq: add threaded interrupt handler support

I like the API and concept of the patch a lot.

some minor comments:

kernel/irq/handle.c irqreturn_t handle_IRQ_event(unsigned in · line 371

Quoted 10 lines
kernel/irq/handle.c +10 -0
+		switch (ret) {
+		case IRQ_WAKE_THREAD:
+			/*
+			 * Wake up the handler thread for this
+			 * action. In case the thread crashed and was
+			 * killed we just pretend that we handled the
+			 * interrupt. The hardirq handler above has
+			 * disabled the device interrupt, so no irq
+			 * storm is lurking.
+			 */

We probably wants some sort of error check to catch drivers returning IRQ_WAKE_THREAD without actually defining a threaded handler here.

kernel/irq/manage.c int __irq_set_trigger(struct irq_desc *d · line 419

Quoted 10 lines
kernel/irq/manage.c +10 -0
+static inline int irq_thread_should_run(struct irqaction *action)
+{
+	return test_and_clear_bit(IRQTF_RUNTHREAD, &action->thread_flags);
+}
+
+static int irq_wait_for_interrupt(struct irqaction *action)
+{
+	while (!kthread_should_stop()) {
+		set_current_state(TASK_INTERRUPTIBLE);
+		if (irq_thread_should_run(action)) {

Does adding the helper for one use really help readability?

kernel/irq/manage.c int __irq_set_trigger(struct irq_desc *d · line 423

Quoted 4 lines
kernel/irq/manage.c +4 -0
+			__set_current_state(TASK_RUNNING);
+			return 0;
+		} else
+			schedule();

No need for the else here :)

Quoted 6 lines
kernel/irq/manage.c +6 -0
+	if (new->thread_fn) {
+		struct task_struct *t;
+
+		t = kthread_create(irq_thread, new, "irq/%d-%s", irq,
+				   new->name);
+		if (IS_ERR(t))

kernel/irq/manage.c __setup_irq(unsigned int irq, struct irq · line 551

Quoted 10 lines
kernel/irq/manage.c +10 -0
+			return PTR_ERR(t);
+		/*
+		 * We keep the reference to the task struct even if
+		 * the thread dies to avoid that the interrupt code
+		 * references an already freed task_struct.
+		 */
+		get_task_struct(t);
+		new->thread = t;
+		wake_up_process(t);
+	}

We should really introduce a refcounted variant of the kthread helpers. Not an argument against the patch, just a public mental note.

Quoted 9 lines

/**
- * request_irq - allocate an interrupt line
+ * request_threaded_irq - allocate an interrupt line
* @irq: Interrupt line to allocate
- * @handler: Function to be called when the IRQ occurs
+ * @handler: Function to be called when the IRQ occurs.
+ * Primary handler for threaded interrupts
+ * @thread_fn: Function called from the irq handler thread
+ * If NULL, no irq thread is created

The indentation is messed up here.

#3 lore raw

Re: [patch 1/2] genirq: add threaded interrupt handler support

Christoph,

Quoted 4 lines · Christoph Hellwig

I like the API and concept of the patch a lot.

some minor comments:

Quoted 13 lines

kernel/irq/handle.c irqreturn_t handle_IRQ_event(unsigned in · line 371

Quoted 10 lines
kernel/irq/handle.c +10 -0
+		switch (ret) {
+		case IRQ_WAKE_THREAD:
+			/*
+			 * Wake up the handler thread for this
+			 * action. In case the thread crashed and was
+			 * killed we just pretend that we handled the
+			 * interrupt. The hardirq handler above has
+			 * disabled the device interrupt, so no irq
+			 * storm is lurking.
+			 */

We probably wants some sort of error check to catch drivers returning IRQ_WAKE_THREAD without actually defining a threaded handler here.

Yep, got lost in the restructuring.

Quoted 4 lines
Quoted 4 lines
kernel/irq/manage.c +4 -0
+static inline int irq_thread_should_run(struct irqaction *action)
+{
+	return test_and_clear_bit(IRQTF_RUNTHREAD, &action->thread_flags);
+}
Quoted 8 lines

kernel/irq/manage.c int __irq_set_trigger(struct irq_desc *d · line 419

Quoted 6 lines
kernel/irq/manage.c +6 -0
+
+static int irq_wait_for_interrupt(struct irqaction *action)
+{
+	while (!kthread_should_stop()) {
+		set_current_state(TASK_INTERRUPTIBLE);
+		if (irq_thread_should_run(action)) {

Does adding the helper for one use really help readability?

:)

Quoted 6 lines

kernel/irq/manage.c int __irq_set_trigger(struct irq_desc *d · line 423

Quoted 4 lines
kernel/irq/manage.c +4 -0
+			__set_current_state(TASK_RUNNING);
+			return 0;
+		} else
+			schedule();

No need for the else here :)

Sigh. I was staring at this construct for a while because it looked strange :)

Quoted 11 lines
Quoted 11 lines
kernel/irq/manage.c +11 -0
+	if (new->thread_fn) {
+		struct task_struct *t;
+
+		t = kthread_create(irq_thread, new, "irq/%d-%s", irq,
+				   new->name);
+		if (IS_ERR(t))
+			return PTR_ERR(t);
+		/*
+		 * We keep the reference to the task struct even if
+		 * the thread dies to avoid that the interrupt code
+		 * references an already freed task_struct.
Quoted 8 lines

kernel/irq/manage.c __setup_irq(unsigned int irq, struct irq · line 551

Quoted 5 lines
kernel/irq/manage.c +5 -0
+		 */
+		get_task_struct(t);
+		new->thread = t;
+		wake_up_process(t);
+	}

We should really introduce a refcounted variant of the kthread helpers. Not an argument against the patch, just a public mental note.

Thought about that already, but did not come around to implement it.

Quoted 11 lines
Quoted 9 lines

/**
- * request_irq - allocate an interrupt line
+ * request_threaded_irq - allocate an interrupt line
* @irq: Interrupt line to allocate
- * @handler: Function to be called when the IRQ occurs
+ * @handler: Function to be called when the IRQ occurs.
+ * Primary handler for threaded interrupts
+ * @thread_fn: Function called from the irq handler thread
+ * If NULL, no irq thread is created

The indentation is messed up here.

Thanks for the review !

tglx

#4 lore raw

genirq: add threaded interrupt handler support - review fixups

Delta patch to address the review comments.

- Implement warning when IRQ_WAKE_THREAD is requested and no thread handler installed
- coding style fixes

LKML-Reference: <[email protected]>

include/linux/interrupt.h +2 -0
Index: linux-2.6-tip/include/linux/interrupt.h
===================================================================
@@ -63,10 +63,12 @@
  * Bits used by threaded handlers:
  * IRQTF_RUNTHREAD - signals that the interrupt handler thread should run
  * IRQTF_DIED      - handler thread died
+ * IRQTF_WARNED    - warning "IRQ_WAKE_THREAD w/o thread_fn" has been printed
  */
 enum {
 	IRQTF_RUNTHREAD,
 	IRQTF_DIED,
+	IRQTF_WARNED,
 };
 
 typedef irqreturn_t (*irq_handler_t)(int, void *);
kernel/irq/handle.c +24 -5
Index: linux-2.6-tip/kernel/irq/handle.c
===================================================================
@@ -338,6 +338,15 @@ irqreturn_t no_action(int cpl, void *dev
 	return IRQ_NONE;
 }
 
+static void warn_no_thread(unsigned int irq, struct irqaction *action)
+{
+	if (test_and_set_bit(IRQTF_WARNED, &action->thread_flags))
+		return;
+
+	printk(KERN_WARNING "IRQ %d device %s returned IRQ_WAKE_THREAD "
+	       "but no thread function available.", irq, action->name);
+}
+
 /**
  * handle_IRQ_event - irq action chain handler
  * @irq:	the interrupt number
@@ -361,6 +370,21 @@ irqreturn_t handle_IRQ_event(unsigned in
 		switch (ret) {
 		case IRQ_WAKE_THREAD:
 			/*
+			 * Set result to handled so the spurious check
+			 * does not trigger.
+			 */
+			ret = IRQ_HANDLED;
+
+			/*
+			 * Catch drivers which return WAKE_THREAD but
+			 * did not set up a thread function
+			 */
+			if (unlikely(!action->thread_fn)) {
+				warn_no_thread(irq, action);
+				break;
+			}
+
+			/*
 			 * Wake up the handler thread for this
 			 * action. In case the thread crashed and was
 			 * killed we just pretend that we handled the
@@ -374,11 +398,6 @@ irqreturn_t handle_IRQ_event(unsigned in
 				wake_up_process(action->thread);
 			}
 
-			/*
-			 * Set it to handled so the spurious check
-			 * does not trigger.
-			 */
-			ret = IRQ_HANDLED;
 			/* Fall through to add to randomness */
 		case IRQ_HANDLED:
 			status |= action->flags;
kernel/irq/manage.c +7 -10
Index: linux-2.6-tip/kernel/irq/manage.c
===================================================================
@@ -407,20 +407,17 @@ int __irq_set_trigger(struct irq_desc *d
 	return ret;
 }
 
-static inline int irq_thread_should_run(struct irqaction *action)
-{
-	return test_and_clear_bit(IRQTF_RUNTHREAD, &action->thread_flags);
-}
-
 static int irq_wait_for_interrupt(struct irqaction *action)
 {
 	while (!kthread_should_stop()) {
 		set_current_state(TASK_INTERRUPTIBLE);
-		if (irq_thread_should_run(action)) {
+
+		if (test_and_clear_bit(IRQTF_RUNTHREAD,
+				       &action->thread_flags)) {
 			__set_current_state(TASK_RUNNING);
 			return 0;
-		} else
-			schedule();
+		}
+		schedule();
 	}
 	return -1;
 }
@@ -820,8 +817,8 @@ EXPORT_SYMBOL(free_irq);
  *	@irq: Interrupt line to allocate
  *	@handler: Function to be called when the IRQ occurs.
  *		  Primary handler for threaded interrupts
- *      @thread_fn: Function called from the irq handler thread
- *                  If NULL, no irq thread is created
+ *	@thread_fn: Function called from the irq handler thread
+ *		    If NULL, no irq thread is created
  *	@irqflags: Interrupt type flags
  *	@devname: An ascii name for the claiming device
  *	@dev_id: A cookie passed back to the handler function
#5 lore raw

PATCH 2/2 genirq: add support for threaded interrupts to devres

In reply to Thomas Gleixner

Impact: support threaded interrupts in devres

Some devices use devres_request_irq() for to install their interrupt handler. Add support for threaded interrupts to devres as well.

[tglx - simplified and adapted to latest threadirq version]

---
 include/linux/interrupt.h |   17 ++++++++++++++---
 kernel/irq/devres.c       |   16 ++++++++++------
 2 files changed, 24 insertions(+), 9 deletions(-)
include/linux/interrupt.h +14 -3
Index: linux-2.6-tip/include/linux/interrupt.h
===================================================================
@@ -123,9 +123,20 @@ extern void free_irq(unsigned int, void 
 
 struct device;
 
-extern int __must_check devm_request_irq(struct device *dev, unsigned int irq,
-			    irq_handler_t handler, unsigned long irqflags,
-			    const char *devname, void *dev_id);
+extern int __must_check
+devm_request_threaded_irq(struct device *dev, unsigned int irq,
+			  irq_handler_t handler, irq_handler_t thread_fn,
+			  unsigned long irqflags, const char *devname,
+			  void *dev_id);
+
+static inline int __must_check
+devm_request_irq(struct device *dev, unsigned int irq, irq_handler_t handler,
+		 unsigned long irqflags, const char *devname, void *dev_id)
+{
+	return devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
+					 devname, dev_id);
+}
+
 extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id);
 
 /*
kernel/irq/devres.c +10 -6
Index: linux-2.6-tip/kernel/irq/devres.c
===================================================================
@@ -26,10 +26,12 @@ static int devm_irq_match(struct device 
 }
 
 /**
- *	devm_request_irq - allocate an interrupt line for a managed device
+ *	devm_request_threaded_irq - allocate an interrupt line for a managed device
  *	@dev: device to request interrupt for
  *	@irq: Interrupt line to allocate
  *	@handler: Function to be called when the IRQ occurs
+ *	@thread_fn: function to be called in a threaded interrupt context. NULL
+ *		    for devices which handle everything in @handler
  *	@irqflags: Interrupt type flags
  *	@devname: An ascii name for the claiming device
  *	@dev_id: A cookie passed back to the handler function
@@ -42,9 +44,10 @@ static int devm_irq_match(struct device 
  *	If an IRQ allocated with this function needs to be freed
  *	separately, dev_free_irq() must be used.
  */
-int devm_request_irq(struct device *dev, unsigned int irq,
-		     irq_handler_t handler, unsigned long irqflags,
-		     const char *devname, void *dev_id)
+int devm_request_threaded_irq(struct device *dev, unsigned int irq,
+			      irq_handler_t handler, irq_handler_t thread_fn,
+			      unsigned long irqflags, const char *devname,
+			      void *dev_id)
 {
 	struct irq_devres *dr;
 	int rc;
@@ -54,7 +57,8 @@ int devm_request_irq(struct device *dev,
 	if (!dr)
 		return -ENOMEM;
 
-	rc = request_irq(irq, handler, irqflags, devname, dev_id);
+	rc = request_threaded_irq(irq, handler, thread_fn, irqflags, devname,
+				  dev_id);
 	if (rc) {
 		devres_free(dr);
 		return rc;
@@ -66,7 +70,7 @@ int devm_request_irq(struct device *dev,
 
 	return 0;
 }
-EXPORT_SYMBOL(devm_request_irq);
+EXPORT_SYMBOL(devm_request_threaded_irq);
 
 /**
  *	devm_free_irq - free an interrupt
#6 lore raw
In reply to Thomas Gleixner

It still looks OK as a basic extension handling one common model.

Once this is on track to merge (when?), I'd hope various I2C and SPI device drivers would start to convert. The most common example might be handling RTC alarms from the numerous I2C and SPI based RTCs.

(The ones that don't need to manage an irq_chip across that queued-message bus, and demux its IRQs. PMICs are a bit more likely to need to demux lots of IRQs.)

Quoted 6 lines · Thomas Gleixner

I'm still looking into a clean solution for the threaded demultiplex handler case which was brought up by Dave to allow both the handling of the demultiplexed devices in the context of the demultiplexer interrupt thread and the wakeup of separate handler threads. But this is an orthogonal extension of the existing patch set and does not change the general design.

No comments on the patch I sent?

http://marc.info/?l=linux-kernel&m=123734579014392&w=2

Or is that what you meant by "orthogonal"? Admittedly that patch sort of begs the question about which request_irq() variant should be used for such demuxed IRQs; the "current" assumption is that request_irq() suffices, but that could be improved so the handle_threaded_irq() flow handler could use the action->thread_fn not action->handler.

- Dave

#7 lore raw
Quoted 9 lines · David Brownell
Quoted 6 lines · Thomas Gleixner

I'm still looking into a clean solution for the threaded demultiplex handler case which was brought up by Dave to allow both the handling of the demultiplexed devices in the context of the demultiplexer interrupt thread and the wakeup of separate handler threads. But this is an orthogonal extension of the existing patch set and does not change the general design.

No comments on the patch I sent?

Looked at it briefly, but I still try to figure out what the best solution for this will be. As I said I'd like to support both variants:

1) demux handlers run in the primary interrupt thread context
2) demux handlers kick their own handler threads

Quoted 6 lines

Or is that what you meant by "orthogonal"? Admittedly that patch sort of begs the question about which request_irq() variant should be used for such demuxed IRQs; the "current" assumption is that request_irq() suffices, but that could be improved so the handle_threaded_irq() flow handler could use the action->thread_fn not action->handler.

I don't want to special case that. See above.

Thanks,

tglx

#8 lore raw
Quoted 9 lines · Thomas Gleixner
Quoted 8 lines · David Brownell
Quoted 6 lines · Thomas Gleixner

I'm still looking into a clean solution for the threaded demultiplex handler case which was brought up by Dave to allow both the handling of the demultiplexed devices in the context of the demultiplexer interrupt thread and the wakeup of separate handler threads. But this is an orthogonal extension of the existing patch set and does not change the general design.

Quoted 8 lines
Quoted 1 line

No comments on the patch I sent?

Looked at it briefly, but I still try to figure out what the best solution for this will be. As I said I'd like to support both variants:

1) demux handlers run in the primary interrupt thread context
2) demux handlers kick their own handler threads

I have no need for the latter, at least in current systems. The IRQs are neither frequent nor time-critical, else they'd not be managed via I2C in the first place ... even high speed I2C (these mostly use 2.6 Mbit/sec, not 100 Kbit/sec) isn't as quick as accessing any kind of local PIC.

The simplest case, FWIW, is with chips like the mcp23s08 GPIO expanders, or their I2C siblings: just one level of dispatch needed. The Linux driver for those chips doesn't yet support its IRQs, primarily because genirq doesn't cope with such stuff very well yet. (You might want to think about something a lot simpler than TWL4030-family PMICs!)

Quoted 8 lines
Quoted 6 lines

Or is that what you meant by "orthogonal"? Admittedly that patch sort of begs the question about which request_irq() variant should be used for such demuxed IRQs; the "current" assumption is that request_irq() suffices, but that could be improved so the handle_threaded_irq() flow handler could use the action->thread_fn not action->handler.

I don't want to special case that. See above.

What's a special case though? If you're serious about wanting to support more than one case, it's always going to be possible to call some of them "special". As in, "threaded IRQs are a special case in genirq". That should not mean they don't get handled.

- Dave

#9 lore raw
Quoted 12 lines · David Brownell
Quoted 11 lines · Thomas Gleixner
Quoted 9 lines · David Brownell
Quoted 6 lines · Thomas Gleixner

I'm still looking into a clean solution for the threaded demultiplex handler case which was brought up by Dave to allow both the handling of the demultiplexed devices in the context of the demultiplexer interrupt thread and the wakeup of separate handler threads. But this is an orthogonal extension of the existing patch set and does not change the general design.

No comments on the patch I sent?

Quoted 8 lines
Quoted 6 lines

Looked at it briefly, but I still try to figure out what the best solution for this will be. As I said I'd like to support both variants:

1) demux handlers run in the primary interrupt thread context
2) demux handlers kick their own handler threads

I have no need for the latter, at least in current systems.

Groan, the fact that you do not need it is definitely _not_ a good reason to just add a irq_is_sufficient_for_dave_handler.

Quoted 7 lines
Quoted 1 line

I don't want to special case that. See above.

What's a special case though? If you're serious about wanting to support more than one case, it's always going to be possible to call some of them "special". As in, "threaded IRQs are a special case in genirq". That should not mean they don't get handled.

I don't like the idea of another action dispatcher in a special case handler. The goal is to reuse the code i.e. simple_handler and handle_IRQ_event. It just needs some thoughts to implement it in a sane way.

Thanks,

tglx

#10 lore raw
Quoted 4 lines · Thomas Gleixner
Quoted 1 line

I have no need for the latter, at least in current systems.

Groan, the fact that you do not need it is definitely _not_ a good reason to just add a irq_is_sufficient_for_dave_handler.

Groan ... don't *you* be puttin' words in *my* mouth.

When I've been in the position you're now in, I've found it useful to know the actual requirements of interface users. Without knowing that, it's kind of hard to deliver a usable solution, n'est-ce pas?

I'm fairly certain you've seen systems that needlessly pulled in complicating requirements, and thereby caused trouble. If you can provide something to efficiently address both modes, fine. But "the latter" seems like one of those needless complicating additions, which could easily slow progress.

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

I don't want to special case that. See above.

What's a special case though? If you're serious about wanting to support more than one case, it's always going to be possible to call some of them "special". As in, "threaded IRQs are a special case in genirq". That should not mean they don't get handled.

Quoted 4 lines

I don't like the idea of another action dispatcher in a special case handler. The goal is to reuse the code i.e. simple_handler and handle_IRQ_event. It just needs some thoughts to implement it in a sane way.

You were the one to suggest a flow handler specifically for cases like this, though ... you seem to have changed your mind on this topic. ISTR the rationale was to get past the current IRQF_DISABLED special casing found in handle_IRQ_event(), by using a flow handler which didn't call that routine.

- Dave