Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3041170lqp; Mon, 25 Mar 2024 18:18:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU1dIl1LYgTxyC1/nVg3Fs/4O8gxmudL5r0GhUwbmGCsjq4mG9d93Ux7fz1NfPDv6fKIPWA3PS0YhQKLNVWi5znTp+Oti3tpPFWutl4KA== X-Google-Smtp-Source: AGHT+IHKeNbjJNx0VdL3hg9+8DyrcpuQz0p6P7EHkdBWjXf/+Iyw1yWOGV9gENXTjoNZPW5XvflR X-Received: by 2002:a05:6a21:164e:b0:1a3:a76b:337c with SMTP id no14-20020a056a21164e00b001a3a76b337cmr1637195pzb.16.1711415936112; Mon, 25 Mar 2024 18:18:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711415936; cv=pass; d=google.com; s=arc-20160816; b=nVXJ9I0hpAEOo43ENY5du54kyIkJ5KQEVmo3LrwgD5XFXoEbk4gav6M8whYrZzM+qk N6yBHp9+S2fH08e1y4pVwqH02gZk7vBNhq/OBRiiMVy7zOII7eeRlHkhyKwmCCFnov54 a/kkrKGnUw8s/FEisscTFVSUeLqwuaMYkP0fR/SisiafDBI1/Ej5Q35tqSPpQjjwOX90 tEaEu9ilfSLGIgfage3iZS/XC+cBmNA77+tO6ylwoOSqNujnqTwszGB/ogpJ7w2u82VT FxrC3yG8wi7OuGIfXB52DGWYl1Oomtqjw1EfxC5ckTWtNxa/bOKsUOFR1gOzNT56/kdG qBdA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature; bh=0aIiJsbK/FOYiRULxUQpBOQ0+fV2pbpaO5YH9xL5kFE=; fh=QK/rIjIVZKlgcyvC23RoFXraw71WdgowvXVbyee8dBY=; b=BJczXIcjgtAv31V3GC+TDLqOTx57iquFisg4op+N+yRZeVcHyPZdzMqZoEsbRbZrUW ilSjGipkhYd0s6cSH2RLbhnog+04IL5+hkzDLVAdNiUVHZwubCGetbAmYC7YiKFEefDN EQ1MGIN1q9eAPc7iUxEkg4SPRItJGux+tBl2JlMpiM/nW2MP7SGckUnU3spH0MYtsdZn u+Dwgll8K4oGxDf/dB1SKQ8GoIsSbSLew65PhaHnyMZNBMGtEg5ZdaJ4dk6i13UweVCu NwC1VdrnKaa5ckILpgbFF5zZP9AljKW/qTA0AQLaRGa1wS9FEl2uq88L1SrT1zgDWKM9 qNuw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nGzjJ8NC; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-117997-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117997-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id n25-20020aa78a59000000b006e8f51c12easi6077162pfa.300.2024.03.25.18.18.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 18:18:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117997-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nGzjJ8NC; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-117997-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117997-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 9825FB4485E for ; Mon, 25 Mar 2024 21:00:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 199FD5EE64; Mon, 25 Mar 2024 21:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nGzjJ8NC" Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE11D5BAFA; Mon, 25 Mar 2024 21:00:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711400435; cv=none; b=gY+9J64wP3Av0s/RifNHikfB+IJpBA3SOsXH2iJAYf7BowOouPyYQNf6xNRxTFq2gFQdfhtzkVzxcGBjXyV9YNrnBRglTmqzJOA4EvrKNwiLzSRtmTmbzMyq53ke/XBDWpanxHRJWqhdKLsCzPtk77skVPmW+B8qIi5WkEanveA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711400435; c=relaxed/simple; bh=4/DCfORHZvvO5HUER8a/EYr7x51a5ySHQFviZ6wk7tU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LFD8bqJeoWDYZAQsX9eTZr6lY9yNzalylIKBwdC94QamIILfO5ytrd8CTp9M2ST5sS+ZeqOSKB0jvwdT4ddfQLVLRbU7HgxWdNxgjhF+4evOgbw0i3iIpa5dU0nauCi77dBkL8094zh3twR646oVbd5QwsKNPdsGQqye5iAlcA0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nGzjJ8NC; arc=none smtp.client-ip=209.85.222.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-78a01a3012aso339323285a.2; Mon, 25 Mar 2024 14:00:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711400432; x=1712005232; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=0aIiJsbK/FOYiRULxUQpBOQ0+fV2pbpaO5YH9xL5kFE=; b=nGzjJ8NCiv1FyRq5tzrvDyMvLDsN8QDz3EwXuqD+36BHZAizW4rtV9N+Fagx4kk+GF rUK+Y50Bu1PLFTLzHvyTZWrcrhsF8Y+mRXuUEC3qRalgUwxnWrHpbwV7kGL5/3eH3FKO KWIxdxkP7clhSH2FDHGiG9mdETSPdlYMQplxltjjApgtJC5OXtoWEeCM9F60pZ2cVBWs dQUAIwQ80uDdKypN7dyJMolhgul2348YZpyK8my3PX3OfYHCFCTa1dOcqrQ7+N/Bw2S9 1a32TRNTiJNXd44cWjR19cF7ukLM1YKqS2dgY8M+gNZSSO41VJ5VNYs5oMu4+eqcxx4N /Mdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400432; x=1712005232; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0aIiJsbK/FOYiRULxUQpBOQ0+fV2pbpaO5YH9xL5kFE=; b=mlSaU2jdAMtvll4tO9TWn3HevnPmo5lAyMRYiFZFnsGuDX1hlRExyFJ7BttNQqaG6V tB78yfXGR7ato/QUG/wwYSmLhHBtrgXqURu0OVVyjU7TunIcsZnDnF0+HhN9W7s2NGLI qxyC4mcQ0aMywT2RLXo5vMAcyCuryjw9oly1KFwV8WwsfxAVb8MHIwDxK8AsznWddfAk oEqlyNY41hCFFObFJINgzEJKGXrHI6q1SWvj+vM+gVTiMyofMshyWuVM4f/K1sAsi58y eBZWWjIONVzF87kJwCFt+giXOVLgY3rGiU6V1esB54Z01xDg6HFCBRtZ+uas8Eqd661E t9uw== X-Forwarded-Encrypted: i=1; AJvYcCVj0lb1JefuJC4I/U4Twty9rtdzWfcmeKLaxef3rkmG95zuwi0aLhw31W/uyyRKh0G3N+Zuwz3B0vtyrINu02CzaRxSc5KYyWqBw+J+lKxow2bbUef2qB27iD7RTMe5XW5mT0y1tNVUbyufHNax8elJuh+Sni31JRNaMsSxLmSCSANOo4jiHzw= X-Gm-Message-State: AOJu0YzUBYyTUmGqPRvINHst9N0D5vzU+zIhIVZ+J02/7Ic0wSvjg0Ic +b/HSFmWWHHWxdezUvzcOHhEjTle0p3OE+fxUIgiTiMpcnpCcV6B X-Received: by 2002:ae9:ee13:0:b0:78a:5ed7:be26 with SMTP id i19-20020ae9ee13000000b0078a5ed7be26mr974913qkg.65.1711400431680; Mon, 25 Mar 2024 14:00:31 -0700 (PDT) Received: from fauth1-smtp.messagingengine.com (fauth1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id k1-20020a05620a0b8100b0078a4fe9bf69sm1715548qkh.57.2024.03.25.14.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 14:00:31 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfauth.nyi.internal (Postfix) with ESMTP id 1821F1200043; Mon, 25 Mar 2024 17:00:30 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 25 Mar 2024 17:00:30 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudduuddgkeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeffleejleehveelteeltedugffhhedvkefgvdehfeeiffeihfeigfdvtdeu hfdtteenucffohhmrghinhepkhgvrhhnvghlrdhorhhgpdhgihhthhhusgdrtghomhenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhn odhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejje ekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhn rghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 25 Mar 2024 17:00:26 -0400 (EDT) Date: Mon, 25 Mar 2024 13:59:55 -0700 From: Boqun Feng To: Mark Rutland Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , "Bj\"orn Roy Baron" , Benno Lossin , Andreas Hindborg , Alice Ryhl , Alan Stern , Andrea Parri , Will Deacon , Peter Zijlstra , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , Joel Fernandes , Nathan Chancellor , Nick Desaulniers , kent.overstreet@gmail.com, Greg Kroah-Hartman , elver@google.com, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Catalin Marinas , torvalds@linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org Subject: Re: [WIP 0/3] Memory model and atomic API in Rust Message-ID: References: <20240322233838.868874-1-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Mar 25, 2024 at 10:44:45AM +0000, Mark Rutland wrote: [...] > > > > * I choose to re-implement atomics in Rust `asm` because we are still > > figuring out how we can make it easy and maintainable for Rust to call > > a C function _inlinely_ (Gary makes some progress [2]). Otherwise, > > atomic primitives would be function calls, and that can be performance > > bottleneck in a few cases. > > I don't think we want to maintain two copies of each architecture's atomics. > This gets painful very quickly (e.g. as arm64's atomics get patched between > LL/SC and LSE forms). > No argument here ;-) > Can we start off with out-of-line atomics, and see where the bottlenecks are? > > It's relatively easy to do that today, at least for the atomic*_*() APIs: > > https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/commit/?h=atomics/outlined&id=e0a77bfa63e7416d610769aa4ab62bc06993ce56 > > ... which IIUC covers the "AtomicI32, AtomicI64 and AtomicUsize" cases you > mention above. > Thanks! Yes, I know I should check with you before I finalize the implementation ;-) I will try to integrate that but things to notice: * For module usage, we need to EXPORT_SYMBOL_GPL() all the atomics, I'm OK with that, but I don't know how others feel about it. * Alice reported performance gap between inline and out-of-line refcount operations in Rust binder driver: https://github.com/Darksonn/linux/commit/b4be1bd6c44225bf7276a4666fd30b8da9cba517 I don't know how much worse since I don't have the data, but that's one of the reasons I started with inline asm. That being said, I totally agree that we could start with out-of-line atomics, and maybe provide inline version for performance critical paths. Hoping is we can figure out how Rust could inline a C function eventually. Regards, Boqun > Mark.