Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4010607pxj; Tue, 8 Jun 2021 04:27:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWG/FYy+EsF0I12QoE5VB105QuGsOC42ILwerIwESaWT2lrkW6psdaPUtZd6WQqcWhCKfe X-Received: by 2002:a05:6402:4414:: with SMTP id y20mr24873905eda.130.1623151665520; Tue, 08 Jun 2021 04:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623151665; cv=none; d=google.com; s=arc-20160816; b=Y8FfdSNbSt+FNprv87JKv7COP3LHr2PET0NADvKmyTdaIFcsh0e4gtbdDT+/hU/Okb 82zfVlCKOeR0hp2ooGTJd0L0ktavdnHrCp3K8q4L6YO+QAWYL746f8rQ0KDnbQK5kbCe +V/U9VRoGihc1tQnB/OywFBKLKD11vtrcJCKEI4JER5St1SyUePDVuEVrwCCLCqGx271 S71oGMqYuA51HtE71/U7kdnco8lVCHwh7uFv2jWNBCm9kzZQ6pQvUYvugLdbqnQtaETW 7wp49cXAvDdcmDnJBMC4r6NWVLYpmojb++wOX+HXSjvFFwTIYDccsejzoVTF24BARXDV D/iw== 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:message-id:subject:cc:to:from:date:dkim-signature; bh=UNAlibUDpLLDX1KGFQEYjEdmHvc7ohyIDGXvDQ+DvHA=; b=jzwkQEapW22EiSiEUhuaXtaKfQRfvjkNNOcKPJ5Gztm/Q7F9BCfP1F11mYnDamXFYm Rq9MzYmHbWW9YEBvx0/uc/wgISj3HYlxwWdSMbnzaWU0Wdo+ZyqTBF9Yo1GHoa9wL8FN o/ggl/E122Ts2R9u7iawlZ0AvF9Ky8JGGMtDjbEcsuWNLG2J+kPFd/9roD1qIDO1mPX5 rLv4Tb7UYDVL3byD710wUiK334tYyyXI3k3gDgyyBBLMryfIJWvqOdiUdFoXFH4GlvB5 orW3zC/Eyo+lvGT5m8kIA97VphocbZJlusugkA4AkLz596GkqdWGok22Bosnrveriw4t utqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ba+NSooc; 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 u1si14029072edp.527.2021.06.08.04.27.21; Tue, 08 Jun 2021 04:27:45 -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=@infradead.org header.s=casper.20170209 header.b=ba+NSooc; 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 S231901AbhFHL0S (ORCPT + 99 others); Tue, 8 Jun 2021 07:26:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231790AbhFHL0S (ORCPT ); Tue, 8 Jun 2021 07:26:18 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B054BC061574; Tue, 8 Jun 2021 04:24:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=UNAlibUDpLLDX1KGFQEYjEdmHvc7ohyIDGXvDQ+DvHA=; b=ba+NSooc4JLoWZ7eNvZsLS0naT 9hfvDe3vU8rUQlf0Uqu6tIqJsEoX3R6MbmUiEw47HmRx07zM3nrD6XVUK6o2szDv7DfCoRvVDqfuu zrJC27G4D6VdE9xS4tpNGE9f7/ncwJTol8OFaN3CKH36WFm1rjwTI15Gojfu9xmALpCr4D79MGMMv HiWU/evjC48blz+xIAiq4jjnS3HwiEjocRU0ybUu3V0CGzr+cxqreQ8yfvD6y6Wobuh9v7hH8v+KU dxfhWjMBbq/yO9gIzQqhlylwxmgGTHsFgwFnlHerv5TwsHce02KokYq1ebh8yd6y9vN01uZTI3EsM ZrTZH7zg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lqZoz-00GsA3-II; Tue, 08 Jun 2021 11:23:07 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id F002F3001E3; Tue, 8 Jun 2021 13:22:58 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id CFD5420245F9F; Tue, 8 Jun 2021 13:22:58 +0200 (CEST) Date: Tue, 8 Jun 2021 13:22:58 +0200 From: Peter Zijlstra To: Marco Elver Cc: "Paul E. McKenney" , Alexander Monakov , Linus Torvalds , Jakub Jelinek , Alan Stern , Segher Boessenkool , 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: References: <20210606185922.GF7746@tucnak> <20210607152806.GS4397@paulmck-ThinkPad-P17-Gen-1> 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 Tue, Jun 08, 2021 at 11:30:36AM +0200, Marco Elver wrote: > The cleaner approach would be an expression wrapper, e.g. "if > (ctrl_depends(A) && B) { ... }". > > I imagine syntactically it'd be similar to __builtin_expect(..). I > think that's also easier to request an extension for, say > __builtin_ctrl_depends(expr). (If that is appealing, we can try and > propose it as std::ctrl_depends() along with std::dependent_ptr<>.) > > Thoughts? Works for me; and note how it mirrors how we implemented volatile_if() in the first place, by doing an expression wrapper. __builtin_ctrl_depends(expr) would have to: - ensure !__builtin_const_p(expr) (A) - imply an acquire compiler fence (B) - ensure cond-branch is emitted (C) *OR* - ensure !__builtin_const_p(expr); (A) - upgrade the load in @expr to load-acquire (D) A) This all hinges on there actually being a LOAD, if expr is constant, we have a malformed program and can emit a compiler error. B) We want to capture any store, not just volatile stores that come after. The example here is a ring-buffer that loads the (head and) tail pointer to check for space and then writes data elements. It would be 'cumbersome' to have all the data writes as volatile. C) We depend on the load-to-branch data dependency to guard the store to provide the LOAD->STORE memory order. D) Upgrading LOAD to LOAD-ACQUIRE also provides LOAD->STORE ordering, but it does require that the compiler has access to the LOAD in the first place, which isn't a given seeing how much asm() we have around. Also the achitecture should have a sheep LOAD-ACQUIRE in the first place, otherwise there's no point. If this is done, the branch is allowed to be optimized away if the compiler so wants. Now, Will will also want to allow the load-acquire to be run-time patched between the RCsc and RCpc variant depending on what ARMv8 extentions are available, which will be 'interesting' (although I can think of ways to actually do that, one would be to keep a special section that tracks the location of these __builtin_ctrl_depends() generated load-acquire instruction).