Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3478imm; Wed, 30 May 2018 16:14:07 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL7xHu8dyn7VLV/qa44JH2/6GTt4B51yEj73E7/sI7sPzH5XEAXGm0kXj6Jo/7LAimQMEMA X-Received: by 2002:a63:6fcf:: with SMTP id k198-v6mr3707920pgc.307.1527722047511; Wed, 30 May 2018 16:14:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527722047; cv=none; d=google.com; s=arc-20160816; b=yIX4UOxTk0rasjaWuoXehN52VzW8f3UeRQk9DU2p/POjA1c8tWE7lOp0BlSHD8oIKe qOoQ5QKBPW8l+7qiJfwweATSqfD7e5m4Gjw61Z112SFvIXodCjsB3ckPVjLlCnDUGbwA vPYLgHzh+u/c/vX/9QTyQm0LaV6ekB0uRelY1iECLPjHTSdF1ikkEMEB+7uTd8VyiHsp DoOnGn5dsMl3QcrLG6rmDkEd5jLn8swk2AmM9O1Ou7VM7NRsNXqclHV6EtguFB79nDQh dOhx99C/ucPyZE5yY6Bx3TUw3nS+wA0qZE2mZVi46HbIwb1aTWajo7EU6IbT1jnjXyoN G0tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:subject:cc:to :from:date:arc-authentication-results; bh=tCrMyUcBSTpT335l/3NhnEFQVcEV+nOQdSCcTiFpktQ=; b=0Ou1Dy3vAM/8B1Ev+Eup6VfmQ6K5iYi85rlskeYnIt8XKN+0jyT881db1M2NQr8rbV 4dX/qE9hP9X+24mMTJP0wajQ7mkk4WSS/vkd9Uv4V3PWFfQ96WS/OsTIBCvGg6SVDfmz n4WG70wsgZRrb7H1NYNJrLqF4IcCV65jyKanpOOirnMy6lK+jNM62zL26UPvOc90nbB/ 316BlHlXShsLv6G9bxYeP2/YQMQPDyANvHE2GyFkwumBggYroEHA4NGojLFu3aRjJ37B 3dRmXHiXah8GxhGtPmd2MkHIPdpAz6kpB6NfQPTwQfJAYvSifvavrJSJ2eHXml+UURSE X4eQ== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b63-v6si36115560plb.566.2018.05.30.16.13.53; Wed, 30 May 2018 16:14:07 -0700 (PDT) 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932641AbeE3XNJ (ORCPT + 99 others); Wed, 30 May 2018 19:13:09 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:57514 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753695AbeE3XNE (ORCPT ); Wed, 30 May 2018 19:13:04 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4UN3aaY146512 for ; Wed, 30 May 2018 19:13:03 -0400 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ja3e3mdxv-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 30 May 2018 19:13:03 -0400 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 30 May 2018 19:13:03 -0400 Received: from b01cxnp22034.gho.pok.ibm.com (9.57.198.24) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 30 May 2018 19:12:58 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4UNCvW2917938 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 30 May 2018 23:12:57 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3BB97B2065; Wed, 30 May 2018 20:14:37 -0400 (EDT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 05773B2066; Wed, 30 May 2018 20:14:37 -0400 (EDT) Received: from paulmck-ThinkPad-W541 (unknown [9.85.143.195]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 30 May 2018 20:14:36 -0400 (EDT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id 9C7AA16C6348; Wed, 30 May 2018 16:14:41 -0700 (PDT) Date: Wed, 30 May 2018 16:14:41 -0700 From: "Paul E. McKenney" To: Linus Torvalds Cc: Alan Stern , Linux Kernel Mailing List , linux-arch , andrea.parri@amarulasolutions.com, Will Deacon , Peter Zijlstra , Boqun Feng , Nick Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Ingo Molnar , Roman Pen Subject: Re: LKMM litmus test for Roman Penyaev's rcu-rr Reply-To: paulmck@linux.vnet.ibm.com References: <20180530183826.GI7063@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 18053023-0040-0000-0000-000004371C2E X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009099; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000264; SDB=6.01040030; UDB=6.00530820; IPR=6.00819163; MB=3.00021384; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-30 23:13:02 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18053023-0041-0000-0000-0000083D4256 Message-Id: <20180530231441.GO7063@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-30_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1805300242 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 30, 2018 at 05:01:01PM -0500, Linus Torvalds wrote: > On Wed, May 30, 2018 at 2:08 PM Alan Stern wrote: > > > > Indeed. The very first line Linus quoted in his first reply to me > > (elided above) was: > > > > Putting this into herd would be extremely difficult, if not impossible, > > because it involves analyzing code that was not executed. > > > > It should be clear from this that I was talking about herd. Not gcc or > > real hardware. > > So what does herd actually work on? The source code or the executable, > or a trace? The source code, that is, the source code of the litmus test. There are definitions for the various Linux operations, partly within the herd tool and partly in the linux.def file in tools/memory-model. The problem we are having is nailing down control dependencies and compiler optimizations. The bit about limiting control dependencies through the end of "if" statement itself works well in a great many cases, but this clearly is not one of them. > I found the herd paper, but I'm on the road helping my daughter in > college move, and I don't have the background to skim the paper > quickly and come up with the obvious answer, so I'l just ask. It is not a short learning curve. > Because I really think that from our memory model standpoint, we > really do have the rule that > > load -> cond -> store > > is ordered - even if the store address and store data is in no way > dependent on the load. The only thing that matters is that there's a > conditional that is dependent on the load in between the load and the > store. > > Note that this is *independent* of how you get to the store. It > doesn't matter if it's a fallthrough conditional jump or a taken > conditional jump, or whether there is a joining. > > The only thing that *does* matter is whether the conditional can be > turned into a "select" statement. If the conditional can be turned > into a data dependency, then the ordering goes away. That is why it > was relevant whether "C" contained a barrier or not (it doesn't even > have to be a *memory* barrier, it just has to be a barrier for code > generation). Another situation is something like this: r1 = READ_ONCE(x); if (r1) r2 = r1 * 3 - 1; else r2 = 42; WRITE_ONCE(y, 5); do_something(r2); Because there are no compiler barriers or volatile accesses in either the "then" clause or the "else" clause, the compiler is within its rights to do this: r1 = READ_ONCE(x); WRITE_ONCE(y, 5); if (r1) r2 = r1 * 3 - 1; else r2 = 42; do_something(r2); Then weakly ordered CPUs can reorder the READ_ONCE() and WRITE_ONCE(). The compiler of course cannot because they are both volatile accesses. > Note that the "C doesn't even have to have a memory barrier" is > important, because the orderin from load->cond->store doesn't actually > have anything to do with any memory ordering imposed by C, it's much > more fundamental than that. If there were volatiles or compiler barriers in the "then" or "else" clauses, or if the store itself was there (and there weren't identical stores in both), then agreed, the compiler cannot do much, nor can the hardware. > > Preserving the order of volatile accesses isn't sufficient. The > > compiler is still allowed to translate > > > > r1 = READ_ONCE(x); > > if (r1) { > > ... > > } > > WRITE_ONCE(y, r2); > > > > into something resembling > > > > r1 = READ_ONCE(x); > > WRITE_ONCE(y, r2); > > if (r1) { > > ... > > } > > Correct. > > What matter is that the code in C (now called "..." above ;^) has a > build-time barrier that means that the compiler cannot do that. > > That barrier can be pretty much anything. The important part is > literally that there's a guarantee that the write cannot be migrated > below the conditional. > > But I don't know what level 'herd' works on. If it doesn't see > compiler barriers (eg our own "barrier()" macro that literally is just > that), only sees the generated code, then it really has no other > information than what he compiler _happened_ to do - it doesn't know > if the compiler did the store after the conditional because it *had* > to do so, or whether it was just a random instruction scheduling > decision. The 'herd' tool works on litmus-test source, and has almost no idea of what compilers get up to. In this particular case, it would be better off being even more ignorant of what compilers get up to. ;-) Thanx, Paul