From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84EADC4743D for ; Sat, 5 Jun 2021 14:57:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AD9661287 for ; Sat, 5 Jun 2021 14:57:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230034AbhFEO73 (ORCPT ); Sat, 5 Jun 2021 10:59:29 -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