Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp26699061rwd; Mon, 3 Jul 2023 13:36:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6thQfWwLLaY0puOWC2zMCJHASqp6+8N8lcGUrcEPyes2Q0XtIpHvlDaUCVSEC5UnDnblon X-Received: by 2002:a05:6830:118:b0:6b7:155b:1df8 with SMTP id i24-20020a056830011800b006b7155b1df8mr10365427otp.16.1688416592645; Mon, 03 Jul 2023 13:36:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688416592; cv=none; d=google.com; s=arc-20160816; b=nKRoF+KNZ/ZJXvakrE7kid6l8dq8CTLtxlcII4R56LqGel2E3tSF9n6IbaBkJ/Z+wE Hur4ISi2cnSTT+snNM+g4oTQQB51qMxjQYsSqegTNE6YiWDOfv3KBk9A6VEKEZcX+TPY xYOi/pVcV3QuECCkZLIKtctDRnukCU3fUhSaC+2y2CAy8iZ4phjWH2+RoJnzRJF7PDHj c8J77kD6d7r3orV1LmNO4BVYRJzqY6JqYXNoS/EQiWemRRxoaeGQ23rXp8kTaXhNEFjY Dilu1Tsyj4G3fvdWSbBtD2Rmybk4H9O8UkwJeIaSkMXA4MeInui2OhkhW05umFw79c5v SRkQ== 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; bh=pFNv53C526DYSHdWa5aNA3tpfOJ1cweUM83k97LF1P0=; fh=Os2VyqRNld/7j1jCAR3jIloN7Z119KMfdbJtyy6Zm8Y=; b=o2/ocRl5pcd697mc8Xlgkz+SN9qm8HhffdR9Lu8Pe73brnjs2OF7KoM2rulSyaXENm T9uA5VnfpW/n/h5VODH1hup7JklmcNi0mQ9w5D/65DW1gOWrZyidl6ShnDLfDXy6gSlM 8Vp+7cIrkr5r+OoOBKMvq6dBgNdgFU7QKwb88ewOM5w6vyEkX0a3x4xOF9oGef8wJUYK G3Xbnv9zB1EZsWm2kE8Dr4Efbsv0qw1fnwIM5pQfNB9kT/kTH9W+LvJXZgZFzhKhKnhy FPX6PL6fNWMjwhNkVVIwWZ8cTy0cVSG2y7gB6UqVjIGEiAZAFqgZ6wZQ3wX5/Z+kgI4i y8lQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z19-20020a63e113000000b0055b0e39eecdsi13212392pgh.462.2023.07.03.13.36.18; Mon, 03 Jul 2023 13:36:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229534AbjGCU1m (ORCPT + 99 others); Mon, 3 Jul 2023 16:27:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230011AbjGCU1l (ORCPT ); Mon, 3 Jul 2023 16:27:41 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 0092FE6A for ; Mon, 3 Jul 2023 13:27:38 -0700 (PDT) Received: (qmail 1082657 invoked by uid 1000); 3 Jul 2023 16:27:37 -0400 Date: Mon, 3 Jul 2023 16:27:37 -0400 From: Alan Stern To: Olivier Dion Cc: Mathieu Desnoyers , rnk@google.com, Andrea Parri , Will Deacon , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, gcc@gcc.gnu.org, llvm@lists.linux.dev Subject: Re: [RFC] Bridging the gap between the Linux Kernel Memory Consistency Model (LKMM) and C11/C++11 atomics Message-ID: References: <87ttukdcow.fsf@laura> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87ttukdcow.fsf@laura> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 03, 2023 at 03:20:31PM -0400, Olivier Dion wrote: > Hi all, > > This is a request for comments on extending the atomic builtins API to > help avoiding redundant memory barriers. Indeed, there are What atomic builtins API are you talking about? The kernel's? That's what it sounded like when I first read this sentence -- why else post your message on a kernel mailing list? > discrepancies between the Linux kernel consistency memory model (LKMM) > and the C11/C++11 memory consistency model [0]. For example, Indeed. The kernel's usage of C differs from the standard in several respects, and there's no particular reason for its memory model to match the standard's. > fully-ordered atomic operations like xchg and cmpxchg success in LKMM > have implicit memory barriers before/after the operations [1-2], while > atomic operations using the __ATOMIC_SEQ_CST memory order in C11/C++11 > do not have any ordering guarantees of an atomic thread fence > __ATOMIC_SEQ_CST with respect to other non-SEQ_CST operations [3]. After reading what you wrote below, I realized that the API you're thinking of modifying is the one used by liburcu for user programs. It's a shame you didn't mention this in either the subject line or the first few paragraphs of the email; that would have made understanding the message a little easier. In any case, your proposal seems reasonable to me at first glance, with two possible exceptions: 1. I can see why you have special fences for before/after load, store, and rmw operations. But why clear? In what way is clearing an atomic variable different from storing a 0 in it? 2. You don't have a special fence for use after initializing an atomic. This operation can be treated specially, because at the point where an atomic is initialized, it generally has not yet been made visible to any other threads. Therefore the fence which would normally appear after a store (or clear) generally need not appear after an initialization, and you might want to add a special API to force the generation of such a fence. Alan Stern