Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3348773pxj; Mon, 7 Jun 2021 08:30:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJWddr+FuGwDL2RAVedbykSmZmr7HcPOYzJ2GJ3s99eN+a49NfMEZpjJBtFhjsEhi95jbY X-Received: by 2002:aa7:d798:: with SMTP id s24mr16321397edq.243.1623079801979; Mon, 07 Jun 2021 08:30:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623079801; cv=none; d=google.com; s=arc-20160816; b=dqpll0ukAUt2KMvNAipnowX6JE/rk6YsN3upjZkqYujPycWjCLIKHFZqIRYa134BWV Nr80GYqf6xuLPkUzugRYkH3UqlDQurwLcr2uYgb+MWPdrFdQkwpSdy9IKRYr8XC9ODoy XcP6y6u4FENRiDjgiSJBKYtFhUICZOKNJK0ZxeoOV1GU8nNV2AVWbUjQYK2xc0CzTaNO TbMAfJ0jY/9nDjYmk7MYqw+0/NBAhU5YclC3NJNbMzjrdalrS3eQx61LgKqU6kxzv6m8 Ikb8AufGQ3MdTLIcSWZoesfIvFnDOBow50038JL5m2qhOFO0lpRtAwF5K2PvZmEOgnYM AbWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=ryzNQcYeT77CH5iIvplCsMxzCYKWFbTPKef1nfvkEp0=; b=sZQgR6iPxOUsnFjhnWHqVT07bTi6ya0q1PKwpcaZHJ3XY5vgp3tyevuITNPpo3xB+l TaeVb/r8c43sL6+KSXFvec5Q2khw+8AD8WnAV84PoQ2KIYGvKmGCAPcHyHUbbncXtX1n PswSptnAcf17od7jb6cmsDBZgeXWgYqPDJyzH0cXtBkeBcbSKM4kBVzIp3O6A8W/y9Vc ow03zMxNSgqMVua4XQ5VdowjF1UPAN87cuGlKDNays7V6uKwbK0ONbq4JkR3TeMC4O+o VK18xiASeH8DI50ROtxM/MK05oai9PK3ndXrX5ntpYoKuUXAvm8ufVWQaaJezLpLCPwx 7jow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=erJwQ9z2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y18si12342546edr.488.2021.06.07.08.29.39; Mon, 07 Jun 2021 08:30:01 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=erJwQ9z2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230465AbhFGPaC (ORCPT + 99 others); Mon, 7 Jun 2021 11:30:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:36598 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230212AbhFGP36 (ORCPT ); Mon, 7 Jun 2021 11:29:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A633B61107; Mon, 7 Jun 2021 15:28:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623079686; bh=+irQ4OfSn/B6So3CGtbHcUXwW+NtMEimNFyHIBqUBjs=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=erJwQ9z21n0vQpmOSUgxYBNBRUEQljLOQvTy2TcYiCKL1RW//dElzpi2Yi1NBQb1m eq3fBeN/ewjvsZPQ8WDg3vzFO+uSci2boCnj77F8B5stCgacfJsc4kKwAjuO8zulOl HfimBd9N/Y5xGG6ywtecZYe9d63Cif0IhTyPdp2j92FTiDp7U8UysdARbOFR/IWp48 5mkUT23BvsIn0iLOXNtCDeIU68dVuhKEHM7zJMXue1ZWWV6uXq5sdT27gVCJRtW5hB NjrDbSYlid9UZFpcuKcNIAkvuthDlhXHJpXJxIkRdmqnMarz5MhIBB7EyHAwW9ZDBM thMmYpaZoKpUA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 7E6175C0395; Mon, 7 Jun 2021 08:28:06 -0700 (PDT) Date: Mon, 7 Jun 2021 08:28:06 -0700 From: "Paul E. McKenney" To: Marco Elver Cc: Alexander Monakov , Linus Torvalds , Jakub Jelinek , Alan Stern , Segher Boessenkool , Peter Zijlstra , Will Deacon , 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: <20210607152806.GS4397@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20210605145739.GB1712909@rowland.harvard.edu> <20210606001418.GH4397@paulmck-ThinkPad-P17-Gen-1> <20210606012903.GA1723421@rowland.harvard.edu> <20210606185922.GF7746@tucnak> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 07, 2021 at 10:27:10AM +0200, Marco Elver wrote: > On Mon, 7 Jun 2021 at 10:02, Alexander Monakov wrote: > > On Sun, 6 Jun 2021, Linus Torvalds wrote: > [...] > > > On Sun, Jun 6, 2021 at 2:19 PM Alexander Monakov wrote: > [...] > > > Btw, since we have compiler people on line, the suggested 'barrier()' > > > isn't actually perfect for this particular use: > > > > > > #define barrier() __asm__ __volatile__("" : : "i" (__COUNTER__) : "memory") > > > > > > in the general barrier case, we very much want to have that "memory" > > > clobber, because the whole point of the general barrier case is that > > > we want to make sure that the compiler doesn't cache memory state > > > across it (ie the traditional use was basically what we now use > > > "cpu_relax()" for, and you would use it for busy-looping on some > > > condition). > > > > > > In the case of "volatile_if()", we actually would like to have not a > > > memory clobber, but a "memory read". IOW, it would be a barrier for > > > any writes taking place, but reads can move around it. > > > > > > I don't know of any way to express that to the compiler. We've used > > > hacks for it before (in gcc, BLKmode reads turn into that kind of > > > barrier in practice, so you can do something like make the memory > > > input to the asm be a big array). But that turned out to be fairly > > > unreliable, so now we use memory clobbers even if we just mean "reads > > > random memory". > > > > So the barrier which is a compiler barrier but not a machine barrier is > > __atomic_signal_fence(model), but internally GCC will not treat it smarter > > than an asm-with-memory-clobber today. > > FWIW, Clang seems to be cleverer about it, and seems to do the optimal > thing if I use a __atomic_signal_fence(__ATOMIC_RELEASE): > https://godbolt.org/z/4v5xojqaY Indeed it does! But I don't know of a guarantee for that helpful behavior. Thanx, Paul