From: Mikulas Patocka <mpatocka@redhat.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Jens Axboe <axboe@kernel.dk>,
linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Eric Dumazet <eric.dumazet@gmail.com>
Subject: Re: [PATCH] percpu-rwsem: use barrier in unlock path
Date: Thu, 18 Oct 2012 12:17:29 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.64.1210181216590.22996@file.rdu.redhat.com> (raw)
In-Reply-To: <1350533619.19292.59.camel@pippen.local.home>
On Thu, 18 Oct 2012, Steven Rostedt wrote:
> On Thu, 2012-10-18 at 10:18 +0800, Lai Jiangshan wrote:
> > >
> > > Looking at the patch, you are correct. The read side doesn't need the
> > > memory barrier as the worse thing that will happen is that it sees the
> > > locked = false, and will just grab the mutex unnecessarily.
> >
> > ---------------------
> > A memory barrier can be added iff these two things are known:
> > 1) it disables the disordering between what and what.
> > 2) what is the corresponding mb() that it pairs with.
> >
>
> OK, I was just looking at the protection and actions of the locked flag,
> but I see what you are saying with the data itself.
>
> > You tried to add a mb() in percpu_up_write(), OK, I know it disables the disordering
> > between the writes to the protected data and the statement "p->locked = false",
> > But I can't find out the corresponding mb() that it pairs with.
> >
> > percpu_down_read() writes to the data
> > The cpu cache/prefetch the data writes to the data
> > which is chaos writes to the data
> > percpu_up_write()
> > mb()
> > p->locked = false;
> > unlikely(p->locked)
> > the cpu see p->lock = false,
> > don't discard the cached/prefetch data
> > this_cpu_inc(*p->counters);
> > the code of read-access to the data
> > ****and we use the chaos data*****
> >
> > So you need to add a mb() after "unlikely(p->locked)".
>
> Does it need a full mb() or could it be just a rmb()? The down_read I
> wouldn't think would need to protect against stores, would it? The
> memory barrier should probably go in front of the unlikely() too. The
> write to p->counters is handled by the synchronized sched, and adding a
> rmb() in front of the unlikely check would keep prefetched data from
> passing this barrier.
>
> This is a perfect example why this primitive should be vetted outside of
> mainline before it gets merged.
>
> -- Steve
If we do synchronize_rcu() in percpu_up_write, we don't need a barrier in
percpu_down_read(). So I would do that.
Mikulas
next prev parent reply other threads:[~2012-10-18 16:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Pine.LNX.4.64.1210151716310.10685@file.rdu.redhat.com>
[not found] ` <Pine.LNX.4.64.1210161924350.20581@file.rdu.redhat.com>
2012-10-17 2:23 ` [PATCH] percpu-rwsem: use barrier in unlock path Linus Torvalds
2012-10-17 5:58 ` Lai Jiangshan
2012-10-17 5:58 ` Lai Jiangshan
2012-10-17 15:07 ` Mikulas Patocka
2012-10-17 20:28 ` Steven Rostedt
2012-10-17 20:28 ` Steven Rostedt
2012-10-18 2:18 ` Lai Jiangshan
2012-10-18 4:13 ` Steven Rostedt
2012-10-18 16:17 ` Mikulas Patocka [this message]
2012-10-18 15:32 ` Mikulas Patocka
2012-10-18 19:56 ` Mikulas Patocka
2012-10-18 16:05 ` Mikulas Patocka
2012-10-17 9:56 ` Alan Cox
2012-10-18 16:00 ` Mikulas Patocka
2012-10-19 18:48 ` Linus Torvalds
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=Pine.LNX.4.64.1210181216590.22996@file.rdu.redhat.com \
--to=mpatocka@redhat.com \
--cc=axboe@kernel.dk \
--cc=eric.dumazet@gmail.com \
--cc=laijs@cn.fujitsu.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).