Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1952244pxj; Sat, 5 Jun 2021 07:59:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzT1xSucoU3GB9l9ITu7i392yJ0PqJgeImKU3c57klsQPaUpka/Jy+Xu4Elx7rabxni6IWx X-Received: by 2002:a17:906:757:: with SMTP id z23mr9234582ejb.537.1622905180860; Sat, 05 Jun 2021 07:59:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622905180; cv=none; d=google.com; s=arc-20160816; b=IUSSbW840qntLIvKuTuMZipjffN5KDJnO10Fn7W78OWSDn6ciI5fYg5FwwsnxZy2D0 id0tkKsDY/487CoWjwAB/LPCCh5+sPzMridDaew88hlm8qbhFPBXqhaRLaShz+Vu9jTc Y8Ux/f4OfIQRTGbPqD5AJ3n/kLERIej+nqnACbXMkFwLCs9hXwbFa62aFKkDaYk5+/Fx i0Lr4en8wy9AMThsdADAPyHvsyValU1RXqCpRujN8obVW66D/lkZbGir3k9jbRhOVHdE KfSW12eHrD9ye2LfCycHz0YQoBJDTOgfAnspDzgj8qsNHUcqH29mDT+GFx2dZeXi6RpV C7Ag== 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=URkLf/p97f98qFnztkI1Fs5wJXuYxYa2IxfTH24JU2g=; b=pTjSQ92dRiwuT7YyiUc9Vm+OkpBonxqUsfFFZqT2gL+jLdWoTY+OzNzeiiHv3W9x+E KRVVRkG3BV+AI5XTcShxpy3Zn7SWrE8zemeht5jzfwsWtg/4xeo0+h7/Po/E+RYQlCF2 Hd7Up+V+RRyMbN6WSyWguxiB2Goais3rf5yenO7vKPtKCRVoTLZIHKo2RQD9b28/wCQD So2osRZp419OIWYcaBiAmHfxY619aHsMm5Sw5xErOYjjCvi+1s6wtGxZxLFkpPnNNX9O 0U5eKH+Bs3Ii96jzu6PcQYt02vpcqkgm9UDzwlwt3ngJADWU1ON6wb7ry/ac46bJ3wyt nnOg== 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 d20si7792290ejo.138.2021.06.05.07.59.17; Sat, 05 Jun 2021 07:59:40 -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 S230010AbhFEO72 (ORCPT + 99 others); Sat, 5 Jun 2021 10:59:28 -0400 Received: from netrider.rowland.org ([192.131.102.5]:38351 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S229998AbhFEO72 (ORCPT ); Sat, 5 Jun 2021 10:59:28 -0400 Received: (qmail 1713364 invoked by uid 1000); 5 Jun 2021 10:57:39 -0400 Date: Sat, 5 Jun 2021 10:57:39 -0400 From: Alan Stern To: Linus Torvalds Cc: "Paul E. McKenney" , 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: <20210605145739.GB1712909@rowland.harvard.edu> References: <20210604155154.GG1676809@rowland.harvard.edu> <20210604182708.GB1688170@rowland.harvard.edu> <20210604205600.GB4397@paulmck-ThinkPad-P17-Gen-1> <20210604214010.GD4397@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 04, 2021 at 03:19:11PM -0700, Linus Torvalds wrote: > Now, part of this is that I do think that in *general* we should never > use this very suble load-cond-store pattern to begin with. We should > strive to use more smp_load_acquire() and smp_store_release() if we > care about ordering of accesses. They are typically cheap enough, and > if there's much of an ordering issue, they are the right things to do. > > I think the whole "load-to-store ordering" subtle non-ordered case is > for very very special cases, when you literally don't have a general > memory ordering, you just have an ordering for *one* very particular > access. Like some of the very magical code in the rw-semaphore case, > or that smp_cond_load_acquire(). > > IOW, I would expect that we have a handful of uses of this thing. And > none of them have that "the conditional store is the same on both > sides" pattern, afaik. > > And immediately when the conditional store is different, you end up > having a dependency on it that orders it. > > But I guess I can accept the above made-up example as an "argument", > even though I feel it is entirely irrelevant to the actual issues and > uses we have. Indeed, the expansion of the currently proposed version of volatile_if (A) { B; } else { C; } is basically the same as if (A) { barrier(); B; } else { barrier(); C; } which is just about as easy to write by hand. (For some reason my fingers don't like typing "volatile_"; the letters tend to get scrambled.) So given that: 1. Reliance on control dependencies is uncommon in the kernel, and 2. The loads in A could just be replaced with load_acquires at a low penalty (or store-releases could go into B and C), it seems that we may not need volatile_if at all! The only real reason for having it in the first place was to avoid the penalty of load-acquire on architectures where it has a significant cost, when the control dependency would provide the necessary ordering for free. Such architectures are getting less and less common. Alan