Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1267865pxj; Fri, 4 Jun 2021 09:59:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgbXx489Wix6/kc5VFtOehQO8hRnsrcJjnYZ8F3W1aGZDMaqmO9NEJlwZR6FVGRjZt2De8 X-Received: by 2002:a17:906:7f8d:: with SMTP id f13mr5212888ejr.272.1622825961226; Fri, 04 Jun 2021 09:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622825961; cv=none; d=google.com; s=arc-20160816; b=yE5wtToZ7l8DCfC8GRpmF1MR61nUesGMduwyj/fLTHh+1Ifani/EG8hKstZLwUwp9M 74+90iCXAA0iR6P8jEcDsveAvsHyP4iIxKZTDrhQ4opBjHUEGYIGWIkw1ivy8RwZR+Lf EMTROTtR1tbEFqEiYOu25gjUinTOOXou1qYTZgh3twqv8GkLnrOm+oLAQjU1ywHoNQPW SQInm8KrDSpxELCKy4mT8vrk93/q3gyanv5c1b/b5LIuCbbNqoeTPvDKHvnWaqvMmQiY /FZ5pQCZ8ApJhQSGDrbwvZlUzdoMSsAvrdvOmy5f9GTKOetq+filCT/dmoFys7yXxJDO JoVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=jmmH+utmP8503yCemTLvJfvIZ4Pye1SdcLOGBwbCxk4=; b=v+dJ5Jh2+QhaajqiEMF9UGn/650dcS85Q6frTPByJulATOfdTESlh1p9hcCS6mNgIb w27ie1gulwkuoz8ogZ6xL0/Iy4eyipiAJzjMRDg+U012Qx4X+69c9iptoRm9IXZheDtW wGVuJF7zNiut6sgVI0P/5IZmvB4XJLqg5cg/bOc9PEPziEXOpGv/5NE9Fnxgu3rKW3Lr bmB1Z2uE9rCLvLEh8/L1iSzllhkVbkZoonj0niIcI/kXc/11RYHkfqeHPVB499eU9hbg 6xtD4nG6ZzBZSO8hLWwREyMchWFl8A96GDgHhyfrjvxP8ITu6Oa6VoTp+SrKqbEf7BZi apkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l18si5105772edr.482.2021.06.04.09.58.58; Fri, 04 Jun 2021 09:59:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230425AbhFDQ7H (ORCPT + 99 others); Fri, 4 Jun 2021 12:59:07 -0400 Received: from gate.crashing.org ([63.228.1.57]:36210 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229864AbhFDQ7G (ORCPT ); Fri, 4 Jun 2021 12:59:06 -0400 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 154GqohH027719; Fri, 4 Jun 2021 11:52:50 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 154GqmG1027681; Fri, 4 Jun 2021 11:52:48 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Fri, 4 Jun 2021 11:52:42 -0500 From: Segher Boessenkool To: Peter Zijlstra Cc: Linus Torvalds , Will Deacon , "Paul E. McKenney" , Alan Stern , Andrea Parri , Boqun Feng , Nick Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Linux Kernel Mailing List , linux-toolchains@vger.kernel.org, linux-arch Subject: Re: [RFC] LKMM: Add volatile_if() Message-ID: <20210604165242.GI18427@gate.crashing.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 04, 2021 at 06:37:22PM +0200, Peter Zijlstra wrote: > On Fri, Jun 04, 2021 at 09:30:01AM -0700, Linus Torvalds wrote: > > Why is "volatile_if()" not just > > > > #define barier_true() ({ barrier(); 1; }) > > > > #define volatile_if(x) if ((x) && barrier_true()) > > > > because that should essentially cause the same thing - the compiler > > should be *forced* to create one conditional branch (because "barrier" > > is an asm that can't be done on the false side, so it can't do it with > > arithmetic or other games), and after that we're done. > > > > No need for per-architecture "asm goto" games. No new memory barriers. > > No actual new code generation (except for the empty asm volatile that > > is a barrier). > > Because we weren't sure compilers weren't still allowed to optimize the > branch away. barrier_true is a volatile asm, so it should be executed on the real machine exactly as often as on the abstract machine (and in order with other side effects). And the && short-circuits, so you will always have the same effect as a branch. But there of course is nothing that forces there to be a branch (as a silly example, the compiler could convert some control flow to go via computed return addresses). Segher