public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Dipankar Sarma <dipankar@in.ibm.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: Using RCU with rcu_read_lock()?
Date: Fri, 15 Jun 2007 13:12:38 -0700	[thread overview]
Message-ID: <20070615201238.GE9301@linux.vnet.ibm.com> (raw)
In-Reply-To: <20070615192940.GA2996@in.ibm.com>

On Sat, Jun 16, 2007 at 12:59:40AM +0530, Dipankar Sarma wrote:
> On Fri, Jun 15, 2007 at 09:04:19PM +0200, Peter Zijlstra wrote:
> > On Fri, 2007-06-15 at 15:00 -0400, Dmitry Torokhov wrote:
> > > Hi,
> > > 
> > > I have a piece of code that is always called under a spinlock with
> > > interrups disabled. Within that piece of code I iterate through a
> > > list. I have another piece of code that wants to modify that list. I
> > > have 2 options:
> > > 
> > > I don't want to do 1) because the otheir piece of code does not really
> > > care about object owning the spinlock and so acquiring the spinlock is
> > > "not nice". However it is guaranteed that the piece of code that
> > > accesses lock runs atomically with interrupts disabled. So
> > > rcu_read_lock() would be superfluos there.
> > > 
> > > Is it possible to still use list_for_each_rcu() and friends to access
> > > that list without rcu_read_lock()? Or it is betteruse complete RCU
> > > interface and eat cost of couple of extra instrctions?
> > 
> > Yes, preemptible rcu requires that you use the full interface, also, it
> > more clearly documents the code. Trying to find code that breaks these
> > assumptions is very tedious work after the fact.
> > 
> > Please do use the RCU interface in full.
> 
> As Peter said, you should use the strict RCU APIs and not rely
> on the current implementation of RCU to optimize. Things change.
> Plus static/dynamic checking becomes easier that way.

What they said!!!

There are a couple of other options, however:

1.	Use preempt_disable() and preempt_enable() on the read side,
	and synchronize_sched() on the update side.

2.	Use local_irq_save() and local_irq_restore() on the read side,
	and synchronize_sched() on the update side.  Usually not
	competitive -- unless interrupts needed to be disabled for some
	other reason anyway.  Which you in fact say that you do.

I believe that #2 might do what you want.  But please, PLEASE carefully
comment this usage!!!

							Thanx, Paul

  reply	other threads:[~2007-06-15 20:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-15 19:00 Using RCU with rcu_read_lock()? Dmitry Torokhov
2007-06-15 19:04 ` Peter Zijlstra
2007-06-15 19:29   ` Dipankar Sarma
2007-06-15 20:12     ` Paul E. McKenney [this message]
2007-06-15 20:25       ` Dmitry Torokhov
2007-06-15 21:04         ` Paul E. McKenney
2007-06-15 21:09           ` 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=20070615201238.GE9301@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=dipankar@in.ibm.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /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