Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933585AbdGTGNf (ORCPT ); Thu, 20 Jul 2017 02:13:35 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:36408 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932387AbdGTGNc (ORCPT ); Thu, 20 Jul 2017 02:13:32 -0400 Date: Thu, 20 Jul 2017 14:14:34 +0800 From: Boqun Feng To: "Paul E. McKenney" Cc: Akira Yokosawa , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] documentation: Fix two-CPU control-dependency example Message-ID: <20170720061434.zjjrkkdu7cqkxx6c@tardis> References: <0d60072f-3848-a2b7-ce18-e1ed317b5c09@gmail.com> <20170719174334.GH3730@linux.vnet.ibm.com> <101f5108-663e-7fa4-ac2b-e790320e4e6f@gmail.com> <20170719215602.GK3730@linux.vnet.ibm.com> <20170720013112.fmrml6abdhi2nqdt@tardis> <20170720054704.GM3730@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170720054704.GM3730@linux.vnet.ibm.com> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1664 Lines: 72 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! 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 > > > > > > > > > > > > > > > > > > > >