From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Boqun Feng <boqun.feng@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Will Deacon <will.deacon@arm.com>,
linux-kernel@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Randy Dunlap <rdunlap@infradead.org>
Subject: Re: [RFC][PATCH v3]: documentation,atomic: Add new documents
Date: Mon, 31 Jul 2017 10:43:45 -0700 [thread overview]
Message-ID: <20170731174345.GL3730@linux.vnet.ibm.com> (raw)
In-Reply-To: <20170731110403.ou3zqsp3uviqorkz@tardis>
On Mon, Jul 31, 2017 at 07:04:03PM +0800, Boqun Feng wrote:
> On Mon, Jul 31, 2017 at 11:05:35AM +0200, Peter Zijlstra wrote:
> > On Wed, Jul 26, 2017 at 08:47:50PM +0800, Boqun Feng wrote:
> >
> > > > +
> > > > +Further, while something like:
> > > > +
> > > > + smp_mb__before_atomic();
> > > > + atomic_dec(&X);
> > > > +
> > > > +is a 'typical' RELEASE pattern, the barrier is strictly stronger than
> > > > +a RELEASE. Similarly for something like:
> > > > +
> > >
> > > .. at here. Maybe you planned to put stronger ACQUIRE pattern?
> >
> > Yes, although I struggled to find a sensible one. The problem is that
> > ACQUIRE is on loads and value returning atomics have an ACQUIRE variant,
> > so why would you ever want to use smp_mb__after_atomic() for this.
> >
> >
> > That is, the best I could come up with is something like:
> >
> > val = atomic_fetch_or_relaxed(1, &var);
> > smp_mb__after_atomic();
> >
> > But in that case we should've just written:
> >
> > val = atomic_fetch_or_acquire(1, &var);
> >
>
> Agreed.
>
> And besides, in memory-barriers.txt, the wording is:
>
> (*) smp_mb__before_atomic();
> (*) smp_mb__after_atomic();
>
> These are for use with atomic (such as add, subtract, increment and
> decrement) functions that don't return a value, especially when used for
> reference counting.
>
> So actually, using smp_mb__after_atomic() for ACQUIRE is a misuse.
You lost me on this one.
Why wouldn't the following have ACQUIRE semantics?
atomic_inc(&var);
smp_mb__after_atomic();
Is the issue that there is no actual value returned or some such?
> > Suggestions?
>
> As a result, I think it's better we say smp_mb__{before,after}_atomic()
> are only for 1) non-value-returning RmW atomic ops, 2)
> {set,clear,change}_bit and 3) internal use of atomic primitives(e.g. the
> generic version of fully ordered atomics).
>
> 1) prevents people to use it for an ACQUIRE, but allows for a RELEASE.
> 1) & 2) makes atomic_t.txt consistent with memory-barriers.txt
> 3) explains our usage of those barriers internally.
>
> Thoughts?
So if I have something like this, the assertion really can trigger?
WRITE_ONCE(x, 1); atomic_inc(&y);
r0 = xchg_release(&y, 5); smp_mb__after_atomic();
r1 = READ_ONCE(x);
WARN_ON(r0 == 0 && r1 == 0);
I must confess that I am not seeing why we would want to allow this
outcome.
Thanx, Paul
next prev parent reply other threads:[~2017-07-31 17:45 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-09 9:24 [RFC][PATCH]: documentation,atomic: Add a new atomic_t document Peter Zijlstra
2017-06-09 11:05 ` [RFC][PATCH] atomic: Fix atomic_set_release() for 'funny' architectures Peter Zijlstra
2017-06-09 11:13 ` Peter Zijlstra
2017-06-09 17:28 ` Vineet Gupta
2017-06-09 17:28 ` Vineet Gupta
2017-06-09 18:49 ` Peter Zijlstra
2017-06-09 18:49 ` Peter Zijlstra
2017-06-09 18:58 ` James Bottomley
2017-06-09 14:03 ` Chris Metcalf
2017-08-10 12:10 ` [tip:locking/core] locking/atomic: " tip-bot for Peter Zijlstra
2017-06-09 15:44 ` [RFC][PATCH]: documentation,atomic: Add a new atomic_t document Will Deacon
2017-06-09 19:36 ` Peter Zijlstra
2017-06-11 13:56 ` Boqun Feng
2017-06-12 14:49 ` Peter Zijlstra
2017-06-13 6:39 ` Boqun Feng
2017-06-14 12:33 ` Will Deacon
2017-07-12 12:53 ` Boqun Feng
2017-07-12 13:08 ` Peter Zijlstra
2017-07-12 19:13 ` Paul E. McKenney
2017-07-26 11:53 ` [RFC][PATCH v3]: documentation,atomic: Add new documents Peter Zijlstra
2017-07-26 12:47 ` Boqun Feng
2017-07-31 9:05 ` Peter Zijlstra
2017-07-31 11:04 ` Boqun Feng
2017-07-31 17:43 ` Paul E. McKenney [this message]
2017-08-01 2:14 ` Boqun Feng
2017-08-01 9:01 ` Peter Zijlstra
2017-08-01 10:19 ` Will Deacon
2017-08-01 11:47 ` Peter Zijlstra
2017-08-01 12:17 ` Will Deacon
2017-08-01 12:52 ` Peter Zijlstra
2017-08-01 16:14 ` Paul E. McKenney
2017-08-01 16:42 ` Peter Zijlstra
2017-08-01 16:53 ` Will Deacon
2017-08-01 22:18 ` Paul E. McKenney
2017-08-02 8:46 ` Will Deacon
2017-08-01 18:37 ` Paul E. McKenney
2017-08-02 9:45 ` Will Deacon
2017-08-02 16:17 ` Paul E. McKenney
2017-08-03 14:05 ` Boqun Feng
2017-08-03 14:55 ` Paul E. McKenney
2017-08-03 16:12 ` Will Deacon
2017-08-03 16:58 ` Paul E. McKenney
2017-08-01 13:35 ` Paul E. McKenney
2017-07-26 16:28 ` Randy Dunlap
2017-06-09 18:15 ` [RFC][PATCH]: documentation,atomic: Add a new atomic_t document Randy Dunlap
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=20170731174345.GL3730@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=tglx@linutronix.de \
--cc=will.deacon@arm.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.