Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1159427pxj; Fri, 4 Jun 2021 07:28:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEb1uwzpWkvdHuvp6oUnLBJgQZuvMlwhgWHyQqhT/5xZjFqkHavtS6nfMODjNuqhg5z2ZF X-Received: by 2002:a17:906:8319:: with SMTP id j25mr4335521ejx.479.1622816896692; Fri, 04 Jun 2021 07:28:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622816896; cv=none; d=google.com; s=arc-20160816; b=hx4UMgqIerGxIrjWMUNCaJlenaolqMo7dVheEiw4ql81O4bPLD8BfA8kucoGL2wWIX 0gdUIzRHHBCz6n1MfQUXOgG1PYIEf3eHPwaIY5amrKhnO4UOLT9uWPSAB+xMLQeScWIW JOtsANo7fj5FFRjOkgu+Pch2j9i2Ycz1tWb3M2vJNpXlJZinj7V0bc4Dm2LMOwwHkjbu dEWN6Vrd3OibvIyzNuAu6cuCEXWPAZA6RGewo3CbzP296h+0fP4rTipO0RwXXcJdxaHx HMwRtZi5CLY1XViBc3NdaNSbOynDGPh6PwhhBKxNSvxf2xI6Zs5Zk+muVRwn9G687f1x 8RkA== 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=17qTfK5toc6F6S8J9VkBPcfA0mAigsPa366TQwgnirw=; b=o32E5Z6fHFJuo9cmXkc+9Y/qEGFEdBx5DfcG0Q9BP0uvW8y0+YjFAtIMS9Xd0D+z+g 1epCWnL9uTp2DekDOX2vFPjsAHHRxFPAGfl5WJzNNd3HmLJ+C7PkWoXVdrzYU10/gcbn cD7hCuqPMV3jeSglyW0ZKbvPJ7VE/Bxlqpt4XXZY6sm1jP3ccFR9wihAY2VG8vw+iVd4 yrCLfQFHNGxnOqCvkgh5IOFpzDP000IhGdif+ygsalhmaxocg2gWW0BjRNOpupWu62Uu JeMUvqSw+8yIJuGn4HIkGQRdlp/rshGMNGkD9O3/T7CR+WxpCFFGcQB4sZ5XhfPikgPF PiMA== 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 bl4si5673073ejb.17.2021.06.04.07.27.52; Fri, 04 Jun 2021 07:28:16 -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 S229675AbhFDO1f (ORCPT + 99 others); Fri, 4 Jun 2021 10:27:35 -0400 Received: from netrider.rowland.org ([192.131.102.5]:37213 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S229620AbhFDO1f (ORCPT ); Fri, 4 Jun 2021 10:27:35 -0400 Received: (qmail 1679280 invoked by uid 1000); 4 Jun 2021 10:25:48 -0400 Date: Fri, 4 Jun 2021 10:25:48 -0400 From: Alan Stern To: Peter Zijlstra Cc: Linus Torvalds , will@kernel.org, paulmck@kernel.org, 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, linux-kernel@vger.kernel.org, linux-toolchains@vger.kernel.org, linux-arch@vger.kernel.org Subject: Re: [RFC] LKMM: Add volatile_if() Message-ID: <20210604142548.GD1676809@rowland.harvard.edu> References: 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 12:12:07PM +0200, Peter Zijlstra wrote: > Hi! > > With optimizing compilers becoming more and more agressive and C so far > refusing to acknowledge the concept of control-dependencies even while > we keep growing the amount of reliance on them, things will eventually > come apart. > > There have been talks with toolchain people on how to resolve this; one > suggestion was allowing the volatile qualifier on branch statements like > 'if', but so far no actual compiler has made any progress on this. > > Rather than waiting any longer, provide our own construct based on that > suggestion. The idea is by Alan Stern and refined by Paul and myself. > > Code generation is sub-optimal (for the weak architectures) since we're > forced to convert the condition into another and use a fixed conditional > branch instruction, but shouldn't be too bad. > > Usage of volatile_if requires the @cond to be headed by a volatile load > (READ_ONCE() / atomic_read() etc..) such that the compiler is forced to > emit the load and the branch emitted will have the required > data-dependency. Furthermore, volatile_if() is a compiler barrier, which > should prohibit the compiler from lifting anything out of the selection > statement. > > This construct should place control dependencies on a stronger footing > until such time that the compiler folks get around to accepting them :-) > > I've converted most architectures we care about, and the rest will get > an extra smp_mb() by means of the 'generic' fallback implementation (for > now). > > I've converted the control dependencies I remembered and those found > with a search for smp_acquire__after_ctrl_dep(), there might be more. > > Compile tested only (alpha, arm, arm64, x86_64, powerpc, powerpc64, s390 > and sparc64). > > Suggested-by: Alan Stern > Signed-off-by: Peter Zijlstra (Intel) Is there any interest in doing the same sort of thing for switch statements? A similar approach would probably work, but maybe people don't care about it. Alan