public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Josh Triplett <josh@joshtriplett.org>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu,
	laijs@cn.fujitsu.com, dipankar@in.ibm.com,
	akpm@linux-foundation.org, mathieu.desnoyers@polymtl.ca,
	dvhltc@us.ibm.com, niv@us.ibm.com, tglx@linutronix.de,
	peterz@infradead.org, rostedt@goodmis.org,
	Valdis.Kletnieks@vt.edu, dhowells@redhat.com
Subject: Re: [PATCH tip/core/rcu 2/3] rcu: add debug check for too many rcu_read_unlock()
Date: Tue, 5 Jan 2010 08:21:37 -0800	[thread overview]
Message-ID: <20100105162137.GC6714@linux.vnet.ibm.com> (raw)
In-Reply-To: <20100105022814.GA11554@feather>

On Mon, Jan 04, 2010 at 06:28:15PM -0800, Josh Triplett wrote:
> On Mon, Jan 04, 2010 at 06:19:19PM -0800, Paul E. McKenney wrote:
> > On Mon, Jan 04, 2010 at 06:03:08PM -0800, Josh Triplett wrote:
> > > On Mon, Jan 04, 2010 at 04:04:01PM -0800, Paul E. McKenney wrote:
> > > > From: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > > > 
> > > > TREE_PREEMPT_RCU maintains an rcu_read_lock_nesting counter in the
> > > > task structure, which happens to be a signed int.  So this patch adds a
> > > > check for this counter being negative at the end of __rcu_read_unlock().
> > > > This check is under CONFIG_PROVE_LOCKING, so can be thought of as being
> > > > part of lockdep.
> > > > 
> > > > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > > > ---
> > > >  kernel/rcutree_plugin.h |    3 +++
> > > >  1 files changed, 3 insertions(+), 0 deletions(-)
> > > > 
> > > > diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
> > > > index f11ebd4..e77cdf3 100644
> > > > --- a/kernel/rcutree_plugin.h
> > > > +++ b/kernel/rcutree_plugin.h
> > > > @@ -304,6 +304,9 @@ void __rcu_read_unlock(void)
> > > >  	if (--ACCESS_ONCE(t->rcu_read_lock_nesting) == 0 &&
> > > >  	    unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
> > > >  		rcu_read_unlock_special(t);
> > > > +#ifdef CONFIG_PROVE_LOCKING
> > > > +	WARN_ON_ONCE(ACCESS_ONCE(t->rcu_read_lock_nesting) < 0);
> > > > +#endif /* #ifdef CONFIG_PROVE_LOCKING */
> > > >  }
> > > >  EXPORT_SYMBOL_GPL(__rcu_read_unlock);
> > > 
> > > Given that you *already* need to access t->rcu_read_lock_nesting here,
> > > why not just do the test all the time?  Ideally you could access
> > > t->rcu_read_lock_nesting once, decrement it, and test for both 0 and
> > > negative.
> > 
> > Because I was paranoid about the extra branch.  Perhaps needlessly
> > paranoid, but this is rcu_read_unlock() we are talking about here.  ;-)
> > 
> > You seem to be suggesting making the first test be "<=", then
> > sorting things out later, but given that both the equals-zero and the
> > greater-than-zero cases are quite common, I couldn't figure out how to
> > avoid the extra test and branch in the common case.  Hence the #ifdef.
> 
> No, I think you could simply read the predecremented value into a local
> variable, test it once with == 0, then have the WARN_ON_ONCE, and hope
> that the compiler figures out it can just test the register once and
> then do multiple jumps on the same flags.
> 
> You could try it and see what code it generates.

I agree that a smart compiler could share condition-code state, but
there still will be the extra branch.  (Keep in mind that this is a
.h file, so #ifdef is permitted -- though I might nevertheless make
a one-line function/macro.)

						Thanx, Paul

  reply	other threads:[~2010-01-05 16:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-05  0:03 [PATCH tip/core/rcu 0/3] rcu: improve diagnostics and documentation of source files Paul E. McKenney
2010-01-05  0:04 ` [PATCH tip/core/rcu 1/3] rcu: make MAINTAINERS file match new RCU reality Paul E. McKenney
2010-01-13 10:27   ` [tip:core/rcu] rcu: Make " tip-bot for Paul E. McKenney
2010-01-05  0:04 ` [PATCH tip/core/rcu 2/3] rcu: add debug check for too many rcu_read_unlock() Paul E. McKenney
2010-01-05  2:03   ` Josh Triplett
2010-01-05  2:19     ` Paul E. McKenney
2010-01-05  2:28       ` Josh Triplett
2010-01-05 16:21         ` Paul E. McKenney [this message]
2010-01-05 17:08           ` Josh Triplett
2010-01-13 10:27   ` [tip:core/rcu] rcu: Add " tip-bot for Paul E. McKenney
2010-01-05  0:04 ` [PATCH tip/core/rcu 3/3] rcu: give different levels of the rcu_node hierarchy distinct lockdep names Paul E. McKenney
2010-01-13 10:28   ` [tip:core/rcu] rcu: Give " tip-bot for 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=20100105162137.GC6714@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=dipankar@in.ibm.com \
    --cc=dvhltc@us.ibm.com \
    --cc=josh@joshtriplett.org \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@polymtl.ca \
    --cc=mingo@elte.hu \
    --cc=niv@us.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --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