From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755019AbbISPdg (ORCPT ); Sat, 19 Sep 2015 11:33:36 -0400 Received: from mail-ob0-f170.google.com ([209.85.214.170]:35975 "EHLO mail-ob0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754824AbbISPde (ORCPT ); Sat, 19 Sep 2015 11:33:34 -0400 Date: Sat, 19 Sep 2015 23:33:10 +0800 From: Boqun Feng To: Will Deacon Cc: "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , Peter Zijlstra , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Thomas Gleixner , "Paul E. McKenney" , Waiman Long Subject: Re: [RFC v2 3/7] powerpc: atomic: Implement atomic{,64}_{add,sub}_return_* variants Message-ID: <20150919153310.GB20458@fixme-laptop.cn.ibm.com> References: <1442418575-12297-1-git-send-email-boqun.feng@gmail.com> <1442418575-12297-4-git-send-email-boqun.feng@gmail.com> <20150918165902.GF12837@arm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="24zk1gE8NUlDmwG9" Content-Disposition: inline In-Reply-To: <20150918165902.GF12837@arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --24zk1gE8NUlDmwG9 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Will, On Fri, Sep 18, 2015 at 05:59:02PM +0100, Will Deacon wrote: > On Wed, Sep 16, 2015 at 04:49:31PM +0100, Boqun Feng wrote: > > On powerpc, we don't need a general memory barrier to achieve acquire a= nd > > release semantics, so __atomic_op_{acquire,release} can be implemented > > using "lwsync" and "isync". >=20 > I'm assuming isync+ctrl isn't transitive, so we need to get to the bottom Actually the transitivity is still guaranteed here, I think ;-) (Before I put my reasoning, I have to admit I just learned about the cumulativity recently, so my reasoning may be wrong. But the good thing is that we have our POWER experts in the CCed. In case I'm wrong, they could correct me.) The thing is, on POWER, transitivity is implemented by a similar but slightly different concept, cumulativity, and as said in the link: http://www.rdrop.com/users/paulmck/scalability/paper/N2745r.2011.03.04a.html """ The ordering done by a memory barrier is said to be =E2=80=9Ccumulative=E2= =80=9D if it also orders storage accesses that are performed by processors and mechanisms other than P1, as follows. * A includes all applicable storage accesses by any such processor or mechanism that have been performed with respect to P1 before the memory barrier is created. * B includes all applicable storage accesses by any such processor or mechanism that are performed after a Load instruction executed by that processor or mechanism has returned the value stored by a store that is in B. """ Please note that the set B can be extended indefinitely without any other cumulative barrier. So for a RELEASE+ACQUIRE pair to a same variable, as long as the barrier in the RELEASE operation is cumumlative, the transitivity is guaranteed. And lwsync is cumulative, so we are fine here. I also wrote a herd litmus to test this. Due to the tool's limitation, I use the xchg_release and xchg_acquire to test. And since herd doesn't support backward branching, some tricks are used here to work around: PPC lwsync+isync-transitivity "" { 0:r1=3D1; 0:r2=3Dx; 0:r3=3D1; 0:r10=3D0 ; 0:r11=3D0; 0:r12=3Da; 1:r1=3D9; 1:r2=3Dx; 1:r3=3D1; 1:r10=3D0 ; 1:r11=3D0; 1:r12=3Da; 2:r1=3D9; 2:r2=3Dx; 2:r3=3D2; 2:r10=3D0 ; 2:r11=3D0; 2:r12=3Da; } P0 | P1 | P2 ; stw r1,0(r2) | lwz r1,0(r2) | ; | lwsync | lwarx r11, r10, r12 ; | lwarx r11,r10,r12 | stwcx. r3, r10, r12 ; | stwcx. r3,r10,r12 | bne Fail ; | | isync ; | | lwz r1, 0(r2) ; | | Fail: ; exists (1:r1=3D1 /\ 1:r11=3D0 /\ 2:r11=3D1 /\ 2:r1 =3D 0) And the result of this litmus is that: Test lwsync+isync-transitivity Allowed States 15 1:r1=3D0; 1:r11=3D0; 2:r1=3D0; 2:r11=3D0; 1:r1=3D0; 1:r11=3D0; 2:r1=3D0; 2:r11=3D1; 1:r1=3D0; 1:r11=3D0; 2:r1=3D1; 2:r11=3D0; 1:r1=3D0; 1:r11=3D0; 2:r1=3D1; 2:r11=3D1; 1:r1=3D0; 1:r11=3D0; 2:r1=3D9; 2:r11=3D0; 1:r1=3D0; 1:r11=3D0; 2:r1=3D9; 2:r11=3D1; 1:r1=3D0; 1:r11=3D2; 2:r1=3D0; 2:r11=3D0; 1:r1=3D0; 1:r11=3D2; 2:r1=3D1; 2:r11=3D0; 1:r1=3D1; 1:r11=3D0; 2:r1=3D0; 2:r11=3D0; 1:r1=3D1; 1:r11=3D0; 2:r1=3D1; 2:r11=3D0; 1:r1=3D1; 1:r11=3D0; 2:r1=3D1; 2:r11=3D1; 1:r1=3D1; 1:r11=3D0; 2:r1=3D9; 2:r11=3D0; 1:r1=3D1; 1:r11=3D0; 2:r1=3D9; 2:r11=3D1; 1:r1=3D1; 1:r11=3D2; 2:r1=3D0; 2:r11=3D0; 1:r1=3D1; 1:r11=3D2; 2:r1=3D1; 2:r11=3D0; No Witnesses Positive: 0 Negative: 29 Condition exists (1:r1=3D1 /\ 1:r11=3D0 /\ 2:r11=3D1 /\ 2:r1=3D0) Observation lwsync+isync-transitivity Never 0 29 ,which means transitivity is guaranteed. Regards, Boqun > of the s390 thread you linked me to before we start spreading this > further: >=20 > https://lkml.org/lkml/2015/9/15/836 >=20 > Will --24zk1gE8NUlDmwG9 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAABCAAGBQJV/YAyAAoJEEl56MO1B/q4yjYIAIE20S89bHV1SyFhi+8LD1Cj 79lafRnPkt26aj8nl3J80Y/VZ4amq4tYVss8DSzYIfg+dVfhi6/jf/BxoJIoHDtk zFIqRV4Ep1uAGV+o9ozIx/ySfl1sc8ozwDRJN+R3A/FOPPBQKgD6hrPGLo8WiCF0 yaUwNreln+yS1zcYnRxUFt9hPlWv4PACYKCf39TgrD9yrR7qkRvex2R2vP1TsDaf rKr8iZ1fbrYLxTXXWdvJm2XtQI6XpvqSRCXS9rbQe6mbszI2uCiSkXrtOTlkuD5B qIM8AU6k6y7ji6z9hBRmU5Ek5wBYSnr+S0mQeElt5/t7wjiXUSbP/GTWSx70pko= =W6P6 -----END PGP SIGNATURE----- --24zk1gE8NUlDmwG9--