From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (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 D193C5BAFC for ; Mon, 25 Mar 2024 21:00:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711400434; cv=none; b=hX1SKROxHurcPULQZmkZyKmQvyqem4icwST5JXSCymwdnjtgj4wSnIrZXq7L12wCQiHaiKKIeNZHSMTa5HxhTiamH+jUibqNbPM+HxK/QZln9tkKTj1CSsWeiv1Klj3PMJmSTJzfK9ywA1eJY5EUObbg1wB8p35IPPj2Hhmu76c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711400434; 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=ENPCBUeMI0Jcximb1DrcYWIt/JOtw+zi8dYR5rqRLPM3++Z7vMIby2McIuWoUiMHZJR/rx7w7rodSlLxqhO8+S4Yd9+/USqp5v6nsE91/FgLHVCymz6lce3PVfQtCsVCcPs3vaqCpF9jKHzQPvbmrJhM5XL22RBwNe0Tt6cUnTs= 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=g7PEy1Dm; arc=none smtp.client-ip=209.85.222.178 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g7PEy1Dm" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-78a01a3012aso339323185a.2 for ; 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=lists.linux.dev; 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=g7PEy1Dma3RsXTe/CB4tEHXBTAlubBuERqZhSlKWnofmDG4yVxUtZkEAWbDZCflLkd MSvFQ6EhFSF0/ecICndrQ8hK23CLK0Mh/mEI8m8IxyCzr4r/e/kdSZ7jSZDUrEbDtPzi 7FhsjBIsMlDdLHoicCEyCk1a3FfB0t7SaiI1jXmgsG8aRJfz+NeuHNaK7UExr1b3zvTK m5whebEe90sWZnY3+ijaKw50OMZLQqx4lquSMu8z7h+k5Bsn8NRS7pleZttTgy8AcaeV 4yi92Swv2ZCYAcEVUv8kfcuTihNCavJxyqiONy2Y6NrsPUecl8J53j5MPM+sgV2wJBmX XgWA== 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=jqG1/ehYnl+QsyAlEOkaQFha5fGeNfbKpryX5f79cUomXKCW2a52tyfCBFJ/rOZdgn wDV00F2a/UZOjCoHLI9IxrMKO7sReV9VsEOzwXBtr3m6ATt6fPjXQ/XVk6H88xn2i4W/ UnXSDD73czIChcrR+TNMMFDdtrco54Y9WDPDI6yzgF3Z9p23ih7EfUHWcpYRoITcOYi+ Bhockaakyav7Jq7s+rv0+tM6OiLgbOoaMiBVDSSagGAR0wft/mQUsPTUwgyhEVOjNM1a 3MKzlrc5VPx5dEj5z0yH/JVgfCtvI7Z4b6bYvF8qU2+8yPtWIiVkmvHVkASZv6onhtPG vJ2A== X-Forwarded-Encrypted: i=1; AJvYcCX5CovYY5KNo6pGkSh1bkuA+0bjAM3l6ARGNktwF7NXtSgjl5A6kC/IGh8ufl86uZWZfua3sDN64KPHdFclmzON54Xohw== X-Gm-Message-State: AOJu0YxDW2H8iewjXdT4te+5Jd1gzu3V9uWoS+ejZqT24IY0clOO428W 22tYOnW5JVuS0q/E+41A1kRSrFhnVGsGgA59wJN+iC9n2vIIcwJA X-Google-Smtp-Source: AGHT+IEmrJY2YuqwFggGagE/+e8uVbOWYgKk3UIvG8boqku1ije64OUVXZ9orjGM9gQQ0wlamMqAZQ== 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: llvm@lists.linux.dev 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.