Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp258433pxu; Tue, 6 Oct 2020 05:53:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuc3ibF9cdoMaS4ZLtM25efOOPZKzwMa5X7EpTpdhOmRnt/6VnMjnrUN3LnnUcIJkZVkyB X-Received: by 2002:a17:906:3882:: with SMTP id q2mr4991617ejd.452.1601988801432; Tue, 06 Oct 2020 05:53:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601988801; cv=none; d=google.com; s=arc-20160816; b=kvaCMs0FYVOs0sYs8WfWKqA9y20Nr89eLTdm7YtTxA2DyLR3cbSRIIIzVVmy5NnNJ1 rxWHC5YHXZySGWYCj7qprJ1QhBO2uyFObGf8+PkY0TX63CAU/buzFq7saqCFKUtRmbvo FyKKb25qKJGhoZrjTH6T6ovP2Qwx+lSx/Ywl8yUojlTPAPCXL0+WdUxD8nmE8apMSR6g R0h+PCGQ0qFks3xOG4/Vp7B2wvkfp1Ig/zEsZhQiWUiiceR1Txsx3GRWS1RMbMsbT8UZ i0t5UGUMNfRAaxc5WobjTgAX9oBG0iQsFOitkuBN/ZmY0hKHD9O1WRAQwLaQpjuOEKPl MPIQ== 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=qDc+AIaaMA1eRYekIMmjuHMkS5vyUZUb+XBM0u3GjIU=; b=Uh2tLEA4tNL1x+gnCWNx1zTXYRBXIQd+z2xqpfqNdTWSalVCl9ZppclxCdmv3VYRlh VDXo16maCBs+CMVdh39/E9yeKZj/qKMqiLHqaEu/JNpVKKgrl7LXdfT/s548tobvGs6u vfZKsQMQx7jJcOOl6R9ijbBtTjyVcm+IXnIVyUInnGkuCF24EKkRPqA5K72KKsKTJsgc SgmkidBiR7oiWDYHBXt0bq61SzBx1BhDsuhje3a5h2w1itZHipenxnpJBlWMhdayhgM9 d3JctAzEzondVSzdOQDKIE12pWfX4Z1pXEfyEcE5uQcK2FWTfObslkHhoqgjIETh6ZZc 0b/w== 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 p9si2028394eja.248.2020.10.06.05.52.58; Tue, 06 Oct 2020 05:53: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 S1726603AbgJFMuQ (ORCPT + 99 others); Tue, 6 Oct 2020 08:50:16 -0400 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:42834 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726386AbgJFMuQ (ORCPT ); Tue, 6 Oct 2020 08:50:16 -0400 Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 096Cn7rx005828; Tue, 6 Oct 2020 14:49:07 +0200 Date: Tue, 6 Oct 2020 14:49:07 +0200 From: Willy Tarreau To: David Laight Cc: "'Peter Zijlstra'" , "linux-toolchains@vger.kernel.org" , Will Deacon , Paul McKenney , "linux-kernel@vger.kernel.org" , "stern@rowland.harvard.edu" , "parri.andrea@gmail.com" , "boqun.feng@gmail.com" , "npiggin@gmail.com" , "dhowells@redhat.com" , "j.alglave@ucl.ac.uk" , "luc.maranget@inria.fr" , "akiyks@gmail.com" , "dlustig@nvidia.com" , "joel@joelfernandes.org" , "torvalds@linux-foundation.org" Subject: Re: Control Dependencies vs C Compilers Message-ID: <20201006124907.GA5822@1wt.eu> References: <20201006114710.GQ2628@hirez.programming.kicks-ass.net> <3dfe7daed3c44f46a6989b6513ad7bb0@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3dfe7daed3c44f46a6989b6513ad7bb0@AcuMS.aculab.com> User-Agent: Mutt/1.6.1 (2016-04-27) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 06, 2020 at 12:37:06PM +0000, David Laight wrote: > > Our Documentation/memory-barriers.txt has a Control Dependencies section > > (which I shall not replicate here for brevity) which lists a number of > > caveats. But in general the work-around we use is: > > > > x = READ_ONCE(*foo); > > if (x > 42) > > WRITE_ONCE(*bar, 1); > > An alternative is to 'persuade' the compiler that > any 'tracked' value for a local variable is invalid. > Rather like the way that barrier() 'invalidates' memory. > So you generate: > > x = *foo > asm ("" : "+r" (x)); > if (x > 42) > *bar = 1; > > Since the "+r" constraint indicates that the value of 'x' > might have changed it can't optimise based on any > presumed old value. > (Unless it looks inside the asm opcodes...) I'm using exactly this in userland to prevent the compiler from guessing what I'm doing with a variable, and it's also useful sometimes to shut up certain warnings when I know a condition is satisfied but can hardly be expressed in a way to please the compiler. Overall I find that it's no big deal and forces the developer to think twice before doing it, which is probably a good thing in general. Willy