public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Brownell <david-b@pacbell.net>
To: Ingo Molnar <mingo@elte.hu>,
	linux-kernel@vger.kernel.org, tglx@linutronix.de
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	me@felipebalbi.com, dmitry.torokhov@gmail.com,
	sameo@openedhand.com
Subject: [patch/rfc 1/2] GENIRQ: add handle_threaded_irq() flow handler
Date: Tue, 17 Mar 2009 19:19:47 -0700	[thread overview]
Message-ID: <200903171919.48030.david-b@pacbell.net> (raw)
In-Reply-To: <200903171914.53688.david-b@pacbell.net>

From: David Brownell <dbrownell@users.sourceforge.net>

Define a new flow handler, handle_threaded_irq(), for IRQ threads
to use when chaining IRQs.

Unlike existing flow handlers, handle_simple_irq() and siblings,
this one is used only from sleep-capable contexts.  It always calls
irqaction handlers from that same (shared) sleep-capable context.

This is independent of Thomas' irq threading patchset, and can be
viewed as a complement to it.  This adds support for IRQs whose
handlers must *ONLY* ever run in thread contexts ... instead of
offloading code from hardirq context into a thread.  Another way
this differs is that it doesn't create more kernel threads; it
only leverages an existing thread.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
---
 include/linux/irq.h |    7 ++++-
 kernel/irq/chip.c   |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 2 deletions(-)

--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -283,8 +283,8 @@ static inline int irq_balancing_disabled
 extern int handle_IRQ_event(unsigned int irq, struct irqaction *action);
 
 /*
- * Built-in IRQ handlers for various IRQ types,
- * callable via desc->chip->handle_irq()
+ * IRQ flow handlers for various IRQ types, callable via
+ * generic_handle_irq*() or desc->handle_irq()
  */
 extern void handle_level_irq(unsigned int irq, struct irq_desc *desc);
 extern void handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc);
@@ -293,6 +293,9 @@ extern void handle_simple_irq(unsigned i
 extern void handle_percpu_irq(unsigned int irq, struct irq_desc *desc);
 extern void handle_bad_irq(unsigned int irq, struct irq_desc *desc);
 
+/* Flow handler that must only be called from sleeping context */
+extern void handle_threaded_irq(unsigned int irq, struct irq_desc *desc);
+
 /*
  * Monolithic do_IRQ implementation.
  */
--- a/kernel/irq/chip.c
+++ b/kernel/irq/chip.c
@@ -295,6 +295,67 @@ static inline void mask_ack_irq(struct i
 }
 
 /**
+ *	handle_threaded_irq - flow handler reusing current irq thread
+ *	@irq:	the interrupt number
+ *	@desc:	the interrupt description structure for this irq
+ *	Context: irq thread, with IRQs enabled
+ *
+ *	IRQ threads which demultiplex IRQs may use this flow handler
+ *	to chain those demultiplexed IRQs to subsidiary handlers, when
+ *	all that IRQ dispatch logic must run in sleeping contexts.
+ *
+ *	Examples include some multifunction I2C and SPI based devices
+ *	(where access to registers, including ones involved in IRQ
+ *	dispatching, requires sleeping) that have multiple independent
+ *	maskable interupts.
+ *
+ *	The irq thread using this flow handler must handle any ack,
+ *	clear, mask or unmask issues needed.
+ */
+void
+handle_threaded_irq(unsigned int irq, struct irq_desc *desc)
+{
+	struct irqaction *action;
+	irqreturn_t action_ret;
+
+	spin_lock_irq(&desc->lock);
+
+	if (unlikely(desc->status & IRQ_INPROGRESS))
+		goto out_unlock;
+	desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
+	kstat_incr_irqs_this_cpu(irq, desc);
+
+	action = desc->action;
+	if (unlikely(!action || (desc->status & IRQ_DISABLED)))
+		goto out_unlock;
+
+	desc->status |= IRQ_INPROGRESS;
+	spin_unlock_irq(&desc->lock);
+
+	/* simplified handle_IRQ_event():  no random sampling;
+	 * IRQs are always enabled so action->handler may sleep;
+	 * no hooks for handing off to yet another irq thread.
+	 */
+	action_ret = IRQ_NONE;
+	do {
+		/* REVISIT can we get some explicit knowledge that this
+		 * handler expects to run in thread context?  Maybe an
+		 * IRQF_THREADED check, or a new handler type ...
+		 */
+		action_ret |= action->handler(irq, action->dev_id);
+		action = action->next;
+	} while (action);
+
+	if (!noirqdebug)
+		note_interrupt(irq, desc, action_ret);
+
+	spin_lock_irq(&desc->lock);
+	desc->status &= ~IRQ_INPROGRESS;
+out_unlock:
+	spin_unlock_irq(&desc->lock);
+}
+
+/**
  *	handle_simple_irq - Simple and software-decoded IRQs.
  *	@irq:	the interrupt number
  *	@desc:	the interrupt description structure for this irq


  reply	other threads:[~2009-03-18  3:07 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-27 19:28 [PATCH 1/2] input: misc: add twl4030-pwrbutton driver Felipe Balbi
2009-02-27 19:28 ` [PATCH 2/2] mfd: twl4030: add twl4030-pwrbutton as our child Felipe Balbi
2009-02-27 20:36   ` Andrew Morton
2009-02-27 21:58     ` David Brownell
2009-02-27 22:09       ` Felipe Balbi
2009-02-27 22:12       ` Andrew Morton
2009-02-27 23:20         ` David Brownell
2009-02-27 23:42           ` Andrew Morton
2009-07-22 19:27             ` Trilok Soni
2009-07-22 22:25               ` David Brownell
2009-02-27 20:33 ` [PATCH 1/2] input: misc: add twl4030-pwrbutton driver Andrew Morton
2009-02-27 20:37   ` Felipe Balbi
2009-02-27 21:50     ` lockdep and threaded IRQs (was: [PATCH 1/2] input: misc: add twl4030-pwrbutton driver) David Brownell
2009-02-27 22:09       ` Andrew Morton
2009-02-27 23:18         ` lockdep and threaded IRQs (was: ...) David Brownell
2009-02-27 23:32           ` Andrew Morton
2009-02-28  0:01             ` Andrew Morton
2009-02-28  2:30               ` David Brownell
2009-02-28  2:39                 ` Andrew Morton
2009-02-28  4:46                   ` David Brownell
2009-02-28  5:12                     ` Andrew Morton
2009-02-28  6:17                       ` David Brownell
2009-02-28 11:13                     ` Thomas Gleixner
2009-02-28 12:16                       ` David Brownell
2009-02-28 16:42                         ` Thomas Gleixner
2009-02-28 20:02                           ` David Brownell
2009-02-28 20:55                             ` Thomas Gleixner
2009-02-28 21:13                               ` Thomas Gleixner
2009-02-28 22:37                                 ` David Brownell
2009-02-28 22:05                               ` David Brownell
2009-03-01  9:43                                 ` Thomas Gleixner
2009-03-01 22:54                                   ` David Brownell
2009-03-02 13:16                                     ` Peter Zijlstra
2009-03-02 21:04                                       ` David Brownell
2009-03-02 21:16                                         ` Peter Zijlstra
2009-03-02 21:29                                           ` Andrew Morton
2009-03-02 21:37                                           ` David Brownell
2009-03-02 21:41                                             ` Peter Zijlstra
2009-03-02 22:09                                               ` David Brownell
2009-03-02 22:19                                                 ` Peter Zijlstra
2009-03-02 22:40                                                   ` David Brownell
2009-03-02 22:51                                                     ` Peter Zijlstra
2009-03-02 23:29                                                       ` David Brownell
2009-03-03  7:45                                                         ` Peter Zijlstra
2009-03-02 22:46                                                   ` lockdep and threaded IRQs David Miller
2009-03-02 22:57                                                     ` Andrew Morton
2009-03-02 23:07                                                       ` Peter Zijlstra
2009-03-02 23:02                                                     ` Peter Zijlstra
2009-03-02 23:35                                           ` lockdep and threaded IRQs (was: ...) Alan Cox
2009-03-01 22:11                               ` David Brownell
2009-02-28 11:48                     ` lockdep and threaded IRQs Stefan Richter
2009-02-28 20:19                       ` David Brownell
2009-02-28 21:10                         ` Stefan Richter
2009-03-02 13:16           ` lockdep and threaded IRQs (was: ...) Peter Zijlstra
2009-03-02 22:10             ` David Brownell
2009-03-02 22:25               ` Peter Zijlstra
2009-03-02 23:20                 ` David Brownell
2009-03-02 23:26                   ` Ingo Molnar
2009-03-02 23:42                     ` David Brownell
2009-03-02 23:53                       ` Ingo Molnar
2009-03-03  0:33                         ` David Brownell
2009-03-03  0:44                           ` Ingo Molnar
2009-03-03  2:37                             ` David Brownell
2009-03-03  9:27                               ` Peter Zijlstra
2009-03-03  9:45                                 ` Ingo Molnar
2009-03-03  9:47                                 ` Alan Cox
2009-03-03 10:03                                   ` Ingo Molnar
2009-03-03 10:30                                     ` Alan Cox
2009-03-03 10:39                                       ` Peter Zijlstra
2009-03-03 10:48                                       ` Ingo Molnar
2009-03-03 11:13                                         ` Alan Cox
2009-03-03 11:33                                           ` Ingo Molnar
2009-03-03 11:19                                         ` Ingo Molnar
2009-03-18  1:04                                         ` David Brownell
2009-03-18  2:00                             ` David Brownell
2009-03-18  2:14                             ` [patch/rfc 0/2] handle_threaded_irq() David Brownell
2009-03-18  2:19                               ` David Brownell [this message]
2009-03-18 12:00                                 ` [patch/rfc 1/2] GENIRQ: add handle_threaded_irq() flow handler Felipe Balbi
2009-03-18 18:31                                   ` David Brownell
2009-03-18 18:32                                     ` Felipe Balbi
2009-03-18  2:22                               ` [patch/rfc 2/2] twl4030: use new " David Brownell
2009-03-03 11:53                       ` lockdep and threaded IRQs (was: ...) Thomas Gleixner
2009-03-05  2:49                         ` David Brownell
2009-03-06 14:40                           ` Thomas Gleixner
2009-03-18  3:06                             ` David Brownell
2009-03-02 23:48                     ` David Brownell
2009-03-02 23:58                       ` Ingo Molnar
2009-03-02 15:13           ` [PATCH] genirq: assert that irq handlers are indeed run in hardirq context Peter Zijlstra
2009-03-02 19:48             ` David Brownell
2009-03-02 22:01             ` [tip:irq/genirq] genirq: assert that irq handlers are indeed running " Peter Zijlstra
2009-03-02 23:15             ` Peter Zijlstra
2009-04-10  7:11               ` Eric Miao
2009-04-10  9:57                 ` Thomas Gleixner
2009-02-28 11:20       ` lockdep and threaded IRQs Stefan Richter
2009-02-28 20:10         ` David Brownell
2009-02-28  5:51 ` [PATCH 1/2] input: misc: add twl4030-pwrbutton driver Trilok Soni
2009-02-28 12:05   ` [PATCH] mfd: twl4030: add twl4030-pwrbutton as our child Felipe Balbi
2009-02-28 22:23 ` [PATCH 1/2] input: misc: add twl4030-pwrbutton driver Dmitry Torokhov
2009-03-01  0:30   ` Felipe Balbi
2009-03-01  0:58     ` Dmitry Torokhov
2009-03-01 14:40       ` Felipe Balbi
2009-03-04  9:00         ` Dmitry Torokhov
2009-03-04 10:12           ` Felipe Balbi
2009-03-05  1:38             ` David Brownell
2009-03-05 23:54           ` David Brownell
2009-03-06  9:43             ` Dmitry Torokhov

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=200903171919.48030.david-b@pacbell.net \
    --to=david-b@pacbell.net \
    --cc=a.p.zijlstra@chello.nl \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=me@felipebalbi.com \
    --cc=mingo@elte.hu \
    --cc=sameo@openedhand.com \
    --cc=tglx@linutronix.de \
    /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