From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753434AbdK3Qyo (ORCPT ); Thu, 30 Nov 2017 11:54:44 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:37162 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750747AbdK3Qyn (ORCPT ); Thu, 30 Nov 2017 11:54:43 -0500 Date: Thu, 30 Nov 2017 08:54:35 -0800 From: "Paul E. McKenney" To: Will Deacon Cc: Alan Stern , Daniel Lustig , Peter Zijlstra , Andrea Parri , Luc Maranget , Jade Alglave , Boqun Feng , Nicholas Piggin , David Howells , Palmer Dabbelt , Kernel development list Subject: Re: Unlock-lock questions and the Linux Kernel Memory Model Reply-To: paulmck@linux.vnet.ibm.com References: <6b068a40-75bb-4152-b1ec-9ef3beacbdd5@nvidia.com> <20171130161401.GP3624@linux.vnet.ibm.com> <20171130164105.GI21983@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171130164105.GI21983@arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 17113016-0008-0000-0000-000002A8B0A0 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008128; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000242; SDB=6.00953460; UDB=6.00481762; IPR=6.00733536; BA=6.00005722; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018269; XFM=3.00000015; UTC=2017-11-30 16:54:40 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17113016-0009-0000-0000-00003775FF89 Message-Id: <20171130165435.GS3624@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-30_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711300221 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 30, 2017 at 04:41:05PM +0000, Will Deacon wrote: > On Thu, Nov 30, 2017 at 08:14:01AM -0800, Paul E. McKenney wrote: > > On Thu, Nov 30, 2017 at 10:20:02AM -0500, Alan Stern wrote: > > > On Wed, 29 Nov 2017, Daniel Lustig wrote: > > > > > > > On 11/29/2017 12:42 PM, Paul E. McKenney wrote: > > > > > On Wed, Nov 29, 2017 at 02:53:06PM -0500, Alan Stern wrote: > > > > >> On Wed, 29 Nov 2017, Peter Zijlstra wrote: > > > > >> > > > > >>> On Wed, Nov 29, 2017 at 11:04:53AM -0800, Daniel Lustig wrote: > > > > >>> > > > > >>>> While we're here, let me ask about another test which isn't directly > > > > >>>> about unlock/lock but which is still somewhat related to this > > > > >>>> discussion: > > > > >>>> > > > > >>>> "MP+wmb+xchg-acq" (or some such) > > > > >>>> > > > > >>>> {} > > > > >>>> > > > > >>>> P0(int *x, int *y) > > > > >>>> { > > > > >>>> WRITE_ONCE(*x, 1); > > > > >>>> smp_wmb(); > > > > >>>> WRITE_ONCE(*y, 1); > > > > >>>> } > > > > >>>> > > > > >>>> P1(int *x, int *y) > > > > >>>> { > > > > >>>> r1 = atomic_xchg_relaxed(y, 2); > > > > >>>> r2 = smp_load_acquire(y); > > > > >>>> r3 = READ_ONCE(*x); > > > > >>>> } > > > > >>>> > > > > >>>> exists (1:r1=1 /\ 1:r2=2 /\ 1:r3=0) > > > > >>>> > > > > >>>> C/C++ would call the atomic_xchg_relaxed part of a release sequence > > > > >>>> and hence would forbid this outcome. > > > > >>> > > > > >>> That's just weird. Either its _relaxed, or its _release. Making _relaxed > > > > >>> mean _release is just daft. > > > > >> > > > > >> The C11 memory model specifically allows atomic operations to be > > > > >> interspersed within a release sequence. But it doesn't say why. > > > > > > > > > > The use case put forward within the committee is for atomic quantities > > > > > with mode bits. The most frequent has the atomic quantity having > > > > > lock-like properties, in which case you don't want to lose the ordering > > > > > effects of the lock handoff just because a mode bit got set or cleared. > > > > > Some claim to actually use something like this, but details have not > > > > > been forthcoming. > > > > > > > > > > I confess to being a bit skeptical. If the mode changes are infrequent, > > > > > the update could just as well be ordered. > > > > > > > > Aren't reference counting implementations which use memory_order_relaxed > > > > for incrementing the count another important use case? Specifically, > > > > the synchronization between a memory_order_release decrement and the > > > > eventual memory_order_acquire/consume free shouldn't be interrupted by > > > > other (relaxed) increments and (release-only) decrements that happen in > > > > between. At least that's my understanding of this use case. I wasn't > > > > there when the C/C++ committee decided this. > > > > > > > > > That said, Daniel, the C++ memory model really does require that the > > > > > above litmus test be forbidden, my denigration of it notwithstanding. > > > > > > > > Yes I agree, that's why I'm curious what the Linux memory model has > > > > in mind here :) > > > > > > Bear in mind that the litmus test above uses xchg, not increment or > > > decrement. This makes a difference as far as the LKMM is concerned, > > > even if not for C/C++. > > > > Finally remembering this discussion... Yes, xchg is special. ;-) > > > > Will, are there plans to bring this sort of thing before the standards > > committee? > > We discussed it, but rejected it mainly because of concerns that there could > be RmW operations that don't necessarily have an order-inducing dependency > in all scenarios. I think the case that was batted around was a saturating > add implemented using cmpxchg. Ah, I do remember now, during the Toronto meeting, correct? So should we consider making LKMM make xchg act in a manner similar to the other atomics, or would you prefer that we keep the current special behavior? Thanx, Paul