Received: by 10.223.164.202 with SMTP id h10csp88510wrb; Thu, 30 Nov 2017 07:21:18 -0800 (PST) X-Google-Smtp-Source: AGs4zMabY0X2yiq6friqobCCY+yE5tjmYQ5jttCbRuZHdeII+Ww+YTeq3V28dSYK0bJI4b0MGB70 X-Received: by 10.84.216.81 with SMTP id f17mr2969344plj.330.1512055278787; Thu, 30 Nov 2017 07:21:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512055278; cv=none; d=google.com; s=arc-20160816; b=m+5uUBI8Jw1Qpaj1f6TkZcl8j194gqirB2fHCr6/CxV7LWnkOpXfWX8BVVgkJ19fd1 2c/TZg0S2qyzmwtfAld2SXMDif+6JiZ2kqmNNaC7SX1NGjwxWwIohG2UORqIPj6E9FrO aWbNpksA1++8I05n5UXNB76xCYnRDniwmO8J7ejcteJrO3EJah+8M7GYbOu0of94UEsx Cj26uxxu1M1f6O4Qi2sPeErfC37CW31XnUz/2mL8nxjrWjqlpecLgFcpZGuLk5pRhjY/ 34sPTOZ23i6vmAquAPzP5xidrAIc3qEqRjIlvuK8TyrdAOPFWHoGmqqTo1AST+YGt6BJ Fceg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date:arc-authentication-results; bh=x2OSO2hgYaD3keW5JGsRwJWNIXzPBuWAKS+WiiEk6Bw=; b=ECQGCjqKSsvjxXwca6V/d94alNEC1OQMxjfmRYRoAbXLHTcjKgE7uk1cDzOgmtSYSV cS1GStlmr2uPsfYdt0L662OBPQqWFBymQ2MnX/Li/EW0pkv+DmQVVbY4FFx74UItI5vB KUnEQu6pqxvDe7yMahzvu/WiL+kkK4vq6FzYZO3DzEKfR1pcj6j3qXoyuhzA3tJhaGAk B8rAQ+sWShS9LMZKghpBwXqKp9o/PUR5s3KC9nHz8+LEXmkdZz+yEFVAk2m/qEcCHMFm uzWB0lNSsegyzvgLEevVfdOKCzV87diI08xwwX9n/ZSDh+tJfrmrxDvu9covQ7UcICyS Xc0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v22si3394581pfd.212.2017.11.30.07.21.05; Thu, 30 Nov 2017 07:21:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752808AbdK3PUT (ORCPT + 99 others); Thu, 30 Nov 2017 10:20:19 -0500 Received: from iolanthe.rowland.org ([192.131.102.54]:34490 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1752202AbdK3PUD (ORCPT ); Thu, 30 Nov 2017 10:20:03 -0500 Received: (qmail 1577 invoked by uid 2102); 30 Nov 2017 10:20:02 -0500 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 30 Nov 2017 10:20:02 -0500 Date: Thu, 30 Nov 2017 10:20:02 -0500 (EST) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Daniel Lustig cc: "paulmck@linux.vnet.ibm.com" , Peter Zijlstra , Andrea Parri , Luc Maranget , Jade Alglave , Boqun Feng , Nicholas Piggin , Will Deacon , David Howells , Palmer Dabbelt , Kernel development list Subject: Re: Unlock-lock questions and the Linux Kernel Memory Model In-Reply-To: <6b068a40-75bb-4152-b1ec-9ef3beacbdd5@nvidia.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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++. (Also, technically speaking, the litmus test doesn't have any release operations, so no release sequence...) Alan Stern From 1585484837029651126@xxx Thu Nov 30 10:02:48 +0000 2017 X-GM-THRID: 1585255508732072548 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread