From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Paul E. McKenney" Subject: Re: [RFC][PATCH 0/5] arch: atomic rework Date: Mon, 24 Feb 2014 09:28:56 -0800 Message-ID: <20140224172856.GP8264@linux.vnet.ibm.com> References: <1393095223.28840.4914.camel@triegel.csb> <20140223003933.GQ4250@linux.vnet.ibm.com> <20140223063426.GT4250@linux.vnet.ibm.com> Reply-To: paulmck@linux.vnet.ibm.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Content-Disposition: inline In-Reply-To: To: Michael Matz Cc: Linus Torvalds , Richard Biener , Torvald Riegel , Will Deacon , Peter Zijlstra , Ramana Radhakrishnan , David Howells , "linux-arch@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "akpm@linux-foundation.org" , "mingo@kernel.org" , "gcc@gcc.gnu.org" List-Id: linux-arch.vger.kernel.org On Mon, Feb 24, 2014 at 05:55:50PM +0100, Michael Matz wrote: > Hi, > > On Mon, 24 Feb 2014, Linus Torvalds wrote: > > > > To me that reads like > > > > > > int i; > > > int *q = &i; > > > int **p = &q; > > > > > > atomic_XXX (p, CONSUME); > > > > > > orders against accesses '*p', '**p', '*q' and 'i'. Thus it seems they > > > want to say that it orders against aliased storage - but then go further > > > and include "indirectly through a chain of pointers"?! Thus an > > > atomic read of a int * orders against any 'int' memory operation but > > > not against 'float' memory operations? > > > > No, it's not about type at all, and the "chain of pointers" can be > > much more complex than that, since the "int *" can point to within an > > object that contains other things than just that "int" (the "int" can > > be part of a structure that then has pointers to other structures > > etc). > > So, let me try to poke holes into your definition or increase my > understanding :) . You said "chain of pointers"(dereferences I assume), > e.g. if p is result of consume load, then access to > p->here->there->next->prev->stuff is supposed to be ordered with that load > (or only when that last load/store itself is also an atomic load or > store?). > > So, what happens if the pointer deref chain is partly hidden in some > functions: > > A * adjustptr (B *ptr) { return &ptr->here->there->next; } > B * p = atomic_XXX (&somewhere, consume); > adjustptr(p)->prev->stuff = bla; > > As far as I understood you, this whole ptrderef chain business would be > only an optimization opportunity, right? So if the compiler can't be sure > how p is actually used (as in my function-using case, assume adjustptr is > defined in another unit), then the consume load would simply be > transformed into an acquire (or whatever, with some barrier I mean)? Only > _if_ the compiler sees all obvious uses of p (indirectly through pointer > derefs) can it, yeah, do what with the consume load? Good point, I left that out of my list. Adding it: 13. By default, pointer chains do not propagate into or out of functions. In implementations having attributes, a [[carries_dependency]] may be used to mark a function argument or return as passing a pointer chain into or out of that function. If a function does not contain memory_order_consume loads and also does not contain [[carries_dependency]] attributes, then that function may be compiled using any desired dependency-breaking optimizations. The ordering effects are implementation defined when a given pointer chain passes into or out of a function through a parameter or return not marked with a [[carries_dependency]] attributed. Note that this last paragraph differs from the current standard, which would require ordering regardless. Thanx, Paul From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from e34.co.us.ibm.com ([32.97.110.152]:59300 "EHLO e34.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752362AbaBXR3C (ORCPT ); Mon, 24 Feb 2014 12:29:02 -0500 Received: from /spool/local by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 24 Feb 2014 10:29:02 -0700 Date: Mon, 24 Feb 2014 09:28:56 -0800 From: "Paul E. McKenney" Subject: Re: [RFC][PATCH 0/5] arch: atomic rework Message-ID: <20140224172856.GP8264@linux.vnet.ibm.com> Reply-To: paulmck@linux.vnet.ibm.com References: <1393095223.28840.4914.camel@triegel.csb> <20140223003933.GQ4250@linux.vnet.ibm.com> <20140223063426.GT4250@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-arch-owner@vger.kernel.org List-ID: To: Michael Matz Cc: Linus Torvalds , Richard Biener , Torvald Riegel , Will Deacon , Peter Zijlstra , Ramana Radhakrishnan , David Howells , "linux-arch@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "akpm@linux-foundation.org" , "mingo@kernel.org" , "gcc@gcc.gnu.org" Message-ID: <20140224172856.Rb3pDUOwbBm19MPasMQpHYuWPe4kh6WhX5R3aqn9Abk@z> On Mon, Feb 24, 2014 at 05:55:50PM +0100, Michael Matz wrote: > Hi, > > On Mon, 24 Feb 2014, Linus Torvalds wrote: > > > > To me that reads like > > > > > > int i; > > > int *q = &i; > > > int **p = &q; > > > > > > atomic_XXX (p, CONSUME); > > > > > > orders against accesses '*p', '**p', '*q' and 'i'. Thus it seems they > > > want to say that it orders against aliased storage - but then go further > > > and include "indirectly through a chain of pointers"?! Thus an > > > atomic read of a int * orders against any 'int' memory operation but > > > not against 'float' memory operations? > > > > No, it's not about type at all, and the "chain of pointers" can be > > much more complex than that, since the "int *" can point to within an > > object that contains other things than just that "int" (the "int" can > > be part of a structure that then has pointers to other structures > > etc). > > So, let me try to poke holes into your definition or increase my > understanding :) . You said "chain of pointers"(dereferences I assume), > e.g. if p is result of consume load, then access to > p->here->there->next->prev->stuff is supposed to be ordered with that load > (or only when that last load/store itself is also an atomic load or > store?). > > So, what happens if the pointer deref chain is partly hidden in some > functions: > > A * adjustptr (B *ptr) { return &ptr->here->there->next; } > B * p = atomic_XXX (&somewhere, consume); > adjustptr(p)->prev->stuff = bla; > > As far as I understood you, this whole ptrderef chain business would be > only an optimization opportunity, right? So if the compiler can't be sure > how p is actually used (as in my function-using case, assume adjustptr is > defined in another unit), then the consume load would simply be > transformed into an acquire (or whatever, with some barrier I mean)? Only > _if_ the compiler sees all obvious uses of p (indirectly through pointer > derefs) can it, yeah, do what with the consume load? Good point, I left that out of my list. Adding it: 13. By default, pointer chains do not propagate into or out of functions. In implementations having attributes, a [[carries_dependency]] may be used to mark a function argument or return as passing a pointer chain into or out of that function. If a function does not contain memory_order_consume loads and also does not contain [[carries_dependency]] attributes, then that function may be compiled using any desired dependency-breaking optimizations. The ordering effects are implementation defined when a given pointer chain passes into or out of a function through a parameter or return not marked with a [[carries_dependency]] attributed. Note that this last paragraph differs from the current standard, which would require ordering regardless. Thanx, Paul