[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20170720125219.GO3730@linux.vnet.ibm.com>
Date: Thu, 20 Jul 2017 05:52:19 -0700
From: "Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>
To: Boqun Feng <boqun.feng@...il.com>
Cc: Akira Yokosawa <akiyks@...il.com>, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] documentation: Fix two-CPU control-dependency example
On Thu, Jul 20, 2017 at 02:14:34PM +0800, Boqun Feng wrote:
> On Wed, Jul 19, 2017 at 10:47:04PM -0700, Paul E. McKenney wrote:
> [...]
> > > Hi Paul,
> > >
> > > I know the compiler could optimize atomics in very interesting ways, but
> > > this case is about volatile, so I guess our case is still fine? ;-)
> >
> > Hello, Boqun,
> >
> > When I asked that question, the answer I got was "the compiler must
> > emit the load instruction, but is under no obligation to actually use the
> > value loaded".
> >
> > I don't happen to like that answer, by the way. ;-)
> >
>
> Me neither, seems to me the kernel happens to work well at
> compiler-optimization's mercy ;-/
>
> With claim like that, compiler could do optimization as turning:
>
> struct task_struct *owner;
>
> for (;;) {
> owner = READ_ONCE(lock->owner);
> if (owner && !mutex_spin_on_owner(lock, owner))
> break;
> /* ... */
>
> into:
>
> struct task_struct *owner;
>
> owner = READ_ONCE(lock->owner);
>
> for (;;READ_ONCE(lock->owner)) {
> if (owner && !mutex_spin_on_owner(lock, owner))
> break;
> /* ... */
>
> Because the load executed in every loop, and they just happen to choose
> not to use the values. And this is within their rights!
Well, this is one reason that I attend standards-committee meetings.
As does Will Deacon. That way, there is someone there to protest when
people argue that the above behavior is just fine. ;-)
Thanx, Paul
> Regards,
> Boqun
>
> > Thanx, Paul
> >
> > > > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0062r1.html
> > > >
> > >
> > > Great material to wake up mind in the morning! Thanks.
> > >
> > > Regards,
> > > Boqun
> > >
> > > > What are your thoughts on this?
> > > >
> > > > Thanx, Paul
> > > >
> > > > > Thanks, Akira
> > > > >
> > > > > > That said, I very much welcome critical reviews of memory-barriers.txt,
> > > > > > so please do feel free to continue doing that!
> > > > > >
> > > > > > Thanx, Paul
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Powered by blists - more mailing lists