From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from e18.ny.us.ibm.com (e18.ny.us.ibm.com [129.33.205.208]) (using TLSv1.2 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id C1B661A007F for ; Wed, 17 Feb 2016 06:36:44 +1100 (AEDT) Received: from localhost by e18.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 16 Feb 2016 14:36:41 -0500 Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 838D4C90041 for ; Tue, 16 Feb 2016 14:36:37 -0500 (EST) Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u1GJade732440572 for ; Tue, 16 Feb 2016 19:36:39 GMT Received: from d01av01.pok.ibm.com (localhost [127.0.0.1]) by d01av01.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u1GJab5Z014131 for ; Tue, 16 Feb 2016 14:36:39 -0500 Date: Tue, 16 Feb 2016 11:36:44 -0800 From: "Paul E. McKenney" To: Linus Torvalds Cc: Will Deacon , Andy.Glew@imgtec.com, Leonid Yegoshin , Peter Zijlstra , "linux-arch@vger.kernel.org" , Arnd Bergmann , David Miller , "linux-arm-kernel@lists.infradead.org" , linux-metag@vger.kernel.org, linux-mips , linux-xtensa@linux-xtensa.org, ppc-dev , graham.whaley@gmail.com, Peter Anvin , Ingo Molnar Subject: Re: Writes, smp_wmb(), and transitivity? Message-ID: <20160216193644.GV6719@linux.vnet.ibm.com> Reply-To: paulmck@linux.vnet.ibm.com References: <20160215175825.GA15878@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On Tue, Feb 16, 2016 at 10:59:08AM -0800, Linus Torvalds wrote: > On Mon, Feb 15, 2016 at 9:58 AM, Paul E. McKenney > wrote: > > > > Two threads: > > > > int a, b; > > > > void thread0(void) > > { > > WRITE_ONCE(a, 1); > > smp_wmb(); > > WRITE_ONCE(b, 2); > > } > > > > void thread1(void) > > { > > WRITE_ONCE(b, 1); > > smp_wmb(); > > WRITE_ONCE(a, 2); > > } > > > > /* After all threads have completed and the dust has settled... */ > > > > BUG_ON(a == 1 && b == 1); > > So the more I look at that kind of litmus test, the less I think that > we should care, because I can't come up with a scenario in where that > kind of test makes sense. without even a possibility of any causal > relationship between the two, I can't say why we'd ever care about the > ordering of the (independent) writes to the individual variables. > > If somebody can make up a causal chain, things differ. But as long as > all the CPU's are just doing locally ordered writes, I don't think we > need to care about a global store ordering. Works for me! (Yes, I can artificially generate a use case for this thing, but all the ones I have come up with have some better and more sane way to get the job done. So I completely agree with your not caring about it.) So for transitivity, we focus on causal chains, where one task writes to some variable that the next task reads. In addition, if all threads use full memory barriers throughout, as in smp_mb(), then full ordering is of course provided regardless of the pattern of reads and writes. Thanx, Paul