All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-rt-users@vger.kernel.org, mingo@elte.hu,
	tglx@linutronix.de, dvhltc@us.ibm.com, tytso@us.ibm.com,
	a.p.zijlstra@chello.nl, dmitry.torokhov@gmail.com,
	akpm@linux-foundation.org, nickpiggin@yahoo.com.au
Subject: Re: [PATCH RFC -rt] updated synchronize_all_irqs implementation
Date: Tue, 25 Sep 2007 12:34:54 -0700	[thread overview]
Message-ID: <20070925193454.GH8432@linux.vnet.ibm.com> (raw)
In-Reply-To: <Pine.LNX.4.58.0709251317080.5676@gandalf.stny.rr.com>

On Tue, Sep 25, 2007 at 01:22:03PM -0400, Steven Rostedt wrote:
> 
> --
> >
> > Passes light testing (five rounds of kernbench) on an x86_64 box.
> >
> > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > ---
> >
> >  include/linux/hardirq.h |    4 +++-
> >  kernel/irq/handle.c     |    2 ++
> >  kernel/irq/manage.c     |   25 +++++++++++++++++++++++++
> >  3 files changed, 30 insertions(+), 1 deletion(-)
> >
> > diff -urpNa -X dontdiff linux-2.6.23-rc4-rt1/include/linux/hardirq.h linux-2.6.23-rc4-rt1-sairq/include/linux/hardirq.h
> > --- linux-2.6.23-rc4-rt1/include/linux/hardirq.h	2007-09-20 17:34:52.000000000 -0700
> > +++ linux-2.6.23-rc4-rt1-sairq/include/linux/hardirq.h	2007-09-20 18:35:53.000000000 -0700
> > @@ -105,8 +105,10 @@
> >
> >  #ifdef CONFIG_SMP
> >  extern void synchronize_irq(unsigned int irq);
> > +extern void synchronize_all_irqs(void);
> >  #else
> > -# define synchronize_irq(irq)	barrier()
> > +# define synchronize_irq(irq)		barrier()
> > +# define synchronize_all_irqs(irq)	barrier()
> >  #endif
> >
> >  struct task_struct;
> > diff -urpNa -X dontdiff linux-2.6.23-rc4-rt1/kernel/irq/handle.c linux-2.6.23-rc4-rt1-sairq/kernel/irq/handle.c
> > --- linux-2.6.23-rc4-rt1/kernel/irq/handle.c	2007-09-20 17:34:51.000000000 -0700
> > +++ linux-2.6.23-rc4-rt1-sairq/kernel/irq/handle.c	2007-09-22 23:34:13.000000000 -0700
> > @@ -150,7 +150,9 @@ irqreturn_t handle_IRQ_event(unsigned in
> >  	do {
> >  		unsigned int preempt_count = preempt_count();
> >
> > +		rcu_read_lock();
> >  		ret = action->handler(irq, action->dev_id);
> > +		rcu_read_unlock();
> >  		if (preempt_count() != preempt_count) {
> >  			stop_trace();
> >  			print_symbol("BUG: unbalanced irq-handler preempt count in %s!\n", (unsigned long) action->handler);
> > diff -urpNa -X dontdiff linux-2.6.23-rc4-rt1/kernel/irq/manage.c linux-2.6.23-rc4-rt1-sairq/kernel/irq/manage.c
> > --- linux-2.6.23-rc4-rt1/kernel/irq/manage.c	2007-09-20 17:34:51.000000000 -0700
> > +++ linux-2.6.23-rc4-rt1-sairq/kernel/irq/manage.c	2007-09-22 23:34:15.000000000 -0700
> > @@ -45,6 +45,30 @@ void synchronize_irq(unsigned int irq)
> >  EXPORT_SYMBOL(synchronize_irq);
> >
> >  /**
> > + *	synchronize_all_irqs - wait for all pending IRQ handlers (on other CPUs)
> > + *
> > + *	This function waits for any pending IRQ handlers for this interrupt
> > + *	to complete before returning. If you use this function while
> > + *	holding a resource the IRQ handler may need you will deadlock.
> > + *	If you use this function from an IRQ handler, you will immediately
> > + *	self-deadlock.
> > + *
> > + *	Note that this function waits for -handlers-, not for pending
> > + *	interrupts, and most especially not for pending interrupts that
> > + *	have not yet been delivered to the CPU.  So if an interrupt
> > + *	handler was just about to start executing when this function was
> > + *	called, and if there are no other interrupt handlers executing,
> > + *	this function is within its rights to return immediately.
> > + */
> > +void synchronize_all_irqs(void)
> > +{
> > +	if (hardirq_preemption)
> > +		synchronize_rcu();	/* wait for threaded irq handlers. */
> > +	synchronize_sched();		/* wait for hardware irq handlers. */
> 
> I don't undrestand the synchronize_sched part above. How does that wait
> for all hardware irq handlers? Wouldn't the synchronize_rcu be sufficient?

In practice, given the current implementations of RCU, agreed.  However,
an RCU implementation would be within its rights to return immediately
from synchronize_rcu() if it could somehow deduce that there happened
to be no RCU read-side critical sections in progress at that moment.
This could leave hardware interrupt handlers still running on other CPUs.

In fact, the QRCU implementation (http://lkml.org/lkml/2007/2/25/18)
is an example RCU implementation that is capable of returning from
synchronize_qrcu() extremely quickly if there are no QRCU readers (a
few tens of nanoseconds on a recent x86-64 box).  Hardware irq handlers
could easily be running for much longer (like if they take even a single
cache miss).

That said, having serialized delay that is almost never necessary is
not such a good thing.  One thing I could do would be to open-code
synchronize_rcu() in synchronize_all_irqs(), so that the delays for RCU
and for synchronize_sched() happened in parallel.  Something like:

	void synchronize_all_irqs(void)
	{
		struct rcu_synchronize rcu;

		if (hardirq_preemption) {
			init_completion(&rcu.completion);
			/* Will wake me after RCU finished */
			call_rcu(&rcu.head, wakeme_after_rcu);
		}

		/* wait for hardware irq handlers. */

		synchronize_sched();

		/* wait for threaded irq handlers. */

		if (hardirq_preemption)
			wait_for_completion(&rcu.completion);

	}

This would of course require that synchronize_all_irqs() be in the
RCU code rather than the irq code so that it could access the static
wakeme_after_rcu() definition and the rcu_synchronize structure.

Thoughts?

						Thanx, Paul

> > +EXPORT_SYMBOL_GPL(synchronize_all_irqs);
> > +
> > +/**
> >   *	irq_can_set_affinity - Check if the affinity of a given irq can be set
> >   *	@irq:		Interrupt to check
> >   *
> > @@ -886,3 +910,4 @@ void __init early_init_hardirqs(void)
> >  	for (i = 0; i < NR_IRQS; i++)
> >  		init_waitqueue_head(&irq_desc[i].wait_for_handler);
> >  }
> > +
> > -
> > To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> >
> >
> -
> To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2007-09-25 19:35 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-21  5:46 [PATCH RFC -rt] synchronize_all_irqs implementation Paul E. McKenney
2007-09-23 17:34 ` [PATCH RFC -rt] updated " Paul E. McKenney
2007-09-25 17:22   ` Steven Rostedt
2007-09-25 19:34     ` Paul E. McKenney [this message]
2007-09-25 20:02       ` Steven Rostedt
2007-09-25 23:24         ` Peter Zijlstra
2007-09-26  1:11           ` Paul E. McKenney
2007-09-26  8:28             ` Peter Zijlstra
2007-09-26 13:03               ` Paul E. McKenney
2007-09-26 13:16                 ` Dmitry Torokhov
2007-09-26 15:56                   ` Paul E. McKenney
2007-09-26 17:19                     ` Dmitry Torokhov
2007-09-26 17:43                       ` Paul E. McKenney
2007-09-26 17:47                         ` Steven Rostedt
2007-09-26 17:44                       ` Steven Rostedt
2007-09-26 19:55                         ` Paul E. McKenney
2007-09-26 20:54                           ` Peter Zijlstra
2007-09-26 21:07                             ` Steven Rostedt
2007-09-26 21:42                               ` Paul E. McKenney
2007-09-27 14:24                                 ` Dmitry Torokhov
2007-09-27 14:28                                   ` Steven Rostedt
2007-09-27 14:32                                     ` Dmitry Torokhov
2007-09-26 21:22                             ` Paul E. McKenney

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=20070925193454.GH8432@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=dvhltc@us.ibm.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=nickpiggin@yahoo.com.au \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=tytso@us.ibm.com \
    /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.