All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Brownell <david-b@pacbell.net>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	me@felipebalbi.com, linux-kernel@vger.kernel.org,
	linux-input@vger.kernel.org, felipe.balbi@nokia.com,
	dmitry.torokhov@gmail.com, sameo@openedhand.com,
	a.p.zijlstra@chello.nl
Subject: Re: lockdep and threaded IRQs (was: ...)
Date: Sun, 1 Mar 2009 14:11:43 -0800	[thread overview]
Message-ID: <200903011411.43881.david-b@pacbell.net> (raw)
In-Reply-To: <alpine.LFD.2.00.0902282149290.29264@localhost.localdomain>

On Saturday 28 February 2009, Thomas Gleixner wrote:
> > Got a version that applies to mainline GIT?
> 
> http://tglx.de/~tglx/patches.tar.bz2

Very lightly tested patch appended ... it works
with the RTC IRQs, and there's no reason to think
any of the other not-chained-any-longer IRQs would
fail.  This doesn't change anything the irqthread
does, just how it's created and accessed.

- Dave


=====
Minimalist patch to twl4030-irq.c to use the new threaded IRQ
stuff.  For review, not merge; the original irq thread isn't
properly formatted any more -- to make the patch be as small as
possible.

This makes creating the IRQ thread a bit simpler, but the lack
of irq chaining support makes /proc/interrupts be wrong.  The
quickcheck code path necessarily grew longer than the previous
irq_desc.handle() code path.

---
 drivers/mfd/twl4030-irq.c |   88 +++++++++++---------------------------------
 1 file changed, 23 insertions(+), 65 deletions(-)

--- a/drivers/mfd/twl4030-irq.c
+++ b/drivers/mfd/twl4030-irq.c
@@ -172,46 +172,23 @@ static const struct sih sih_modules[6] =
 
 static unsigned twl4030_irq_base;
 
-static struct completion irq_event;
-
 /*
- * This thread processes interrupts reported by the Primary Interrupt Handler.
+ * Threaded IRQ handler, processing interrupts reported by
+ * the Primary Interrupt Handler module.
  */
-static int twl4030_irq_thread(void *data)
+static irqreturn_t twl4030_pih_handler(int irq, void *unused)
 {
-	long irq = (long)data;
-	struct irq_desc *desc = irq_to_desc(irq);
-	static unsigned i2c_errors;
-	const static unsigned max_i2c_errors = 100;
-
-	if (!desc) {
-		pr_err("twl4030: Invalid IRQ: %ld\n", irq);
-		return -EINVAL;
-	}
-
-	current->flags |= PF_NOFREEZE;
-
-	while (!kthread_should_stop()) {
 		int ret;
 		int module_irq;
 		u8 pih_isr;
 
-		/* Wait for IRQ, then read PIH irq status (also blocking) */
-		wait_for_completion_interruptible(&irq_event);
-
+		ret = IRQ_NONE;
 		ret = twl4030_i2c_read_u8(TWL4030_MODULE_PIH, &pih_isr,
 					  REG_PIH_ISR_P1);
 		if (ret) {
 			pr_warning("twl4030: I2C error %d reading PIH ISR\n",
 					ret);
-			if (++i2c_errors >= max_i2c_errors) {
-				printk(KERN_ERR "Maximum I2C error count"
-						" exceeded.  Terminating %s.\n",
-						__func__);
-				break;
-			}
-			complete(&irq_event);
-			continue;
+			goto done;
 		}
 
 		/* these handlers deal with the relevant SIH irq status */
@@ -225,7 +202,7 @@ static int twl4030_irq_thread(void *data
 				if (!d) {
 					pr_err("twl4030: Invalid SIH IRQ: %d\n",
 					       module_irq);
-					return -EINVAL;
+					continue;
 				}
 
 				/* These can't be masked ... always warn
@@ -234,44 +211,31 @@ static int twl4030_irq_thread(void *data
 				if (d->status & IRQ_DISABLED)
 					note_interrupt(module_irq, d,
 							IRQ_NONE);
-				else
+				else {
 					d->handle_irq(module_irq, d);
+					ret = IRQ_HANDLED;
+				}
 			}
 		}
 		local_irq_enable();
 
-		desc->chip->unmask(irq);
-	}
-
-	return 0;
+done:
+	/* unmask the IRQ; it retriggers as needed */
+	enable_irq(irq);
+	return ret;
 }
 
 /*
- * handle_twl4030_pih() is the desc->handle method for the twl4030 interrupt.
- * This is a chained interrupt, so there is no desc->action method for it.
  * Now we need to query the interrupt controller in the twl4030 to determine
  * which module is generating the interrupt request.  However, we can't do i2c
  * transactions in interrupt context, so we must defer that work to a kernel
- * thread.  All we do here is acknowledge and mask the interrupt and wakeup
+ * thread.  All we do here is mask the active-low interrupt and wakeup
  * the kernel thread.
  */
-static void handle_twl4030_pih(unsigned int irq, irq_desc_t *desc)
-{
-	/* Acknowledge, clear *AND* mask the interrupt... */
-	desc->chip->ack(irq);
-	complete(&irq_event);
-}
-
-static struct task_struct *start_twl4030_irq_thread(long irq)
+static irqreturn_t twl4030_pih_quickcheck(int irq, void *unused)
 {
-	struct task_struct *thread;
-
-	init_completion(&irq_event);
-	thread = kthread_run(twl4030_irq_thread, (void *)irq, "twl4030-irq");
-	if (!thread)
-		pr_err("twl4030: could not create irq %ld thread!\n", irq);
-
-	return thread;
+	disable_irq(irq);
+	return IRQ_WAKE_THREAD;
 }
 
 /*----------------------------------------------------------------------*/
@@ -691,7 +655,6 @@ int twl_init_irq(int irq_num, unsigned i
 
 	int			status;
 	int			i;
-	struct task_struct	*task;
 
 	/*
 	 * Mask and clear all TWL4030 interrupts since initially we do
@@ -733,18 +696,13 @@ int twl_init_irq(int irq_num, unsigned i
 		goto fail;
 	}
 
-	/* install an irq handler to demultiplex the TWL4030 interrupt */
-	task = start_twl4030_irq_thread(irq_num);
-	if (!task) {
-		pr_err("twl4030: irq thread FAIL\n");
-		status = -ESRCH;
-		goto fail;
-	}
-
-	set_irq_data(irq_num, task);
-	set_irq_chained_handler(irq_num, handle_twl4030_pih);
+	/* FIXME should be a "chained" handler else irq statistics lie */
+	status = request_threaded_irq(irq_num,
+			twl4030_pih_handler, twl4030_pih_quickcheck,
+			IRQF_THREADED, "twl4030", NULL);
 
-	return status;
+	if (status == 0)
+		return status;
 
 fail:
 	for (i = irq_base; i < irq_end; i++)

  parent reply	other threads:[~2009-03-01 22:11 UTC|newest]

Thread overview: 119+ 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:09         ` Felipe Balbi
2009-02-27 22:12       ` Andrew Morton
2009-02-27 23:20         ` David Brownell
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-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 21:50       ` 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:18           ` David Brownell
2009-02-27 23:32           ` Andrew Morton
2009-02-28  0:01             ` 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: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 [this message]
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:33                           ` David Brownell
2009-03-03  0:44                           ` Ingo Molnar
2009-03-03  0:44                             ` Ingo Molnar
2009-03-03  2:37                             ` David Brownell
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                               ` [patch/rfc 1/2] GENIRQ: add handle_threaded_irq() flow handler David Brownell
2009-03-18 12:00                                 ` 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-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:48                       ` David Brownell
2009-03-02 23:58                       ` Ingo Molnar
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=200903011411.43881.david-b@pacbell.net \
    --to=david-b@pacbell.net \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=felipe.balbi@nokia.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=me@felipebalbi.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.