From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 17754C27C6E for ; Sat, 15 Jun 2024 01:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Nl32RvA7/8lBmewSY1/SnN35QBeCzByhM9oh3NCck0A=; b=fBm9W/bGDd+xEFW6YS24HC8Dg+ QP4iznp8O670cl72Kr100g7cClysBvePxEWdIE1xsF0kigF0TMjPIM3gWw83vlShPOjyLPwIrzYaw 3IK/j5/j1YwkWGebfaGndAg26TUcKTLCofG1YbJW3F2O21w/CSJzYD/3nE/0brfNK3Xv8UknHJrNE J7Lh3L1iIn945wQryn/uSoqjxVduDHGML4rgjdAJBeb/hRMqqcrFfgaudP3EMcNObXI6FfnmEV+35 mnRitk42dnZf5ae9njgotVTSabe/u7x0830++l4g1zN3yHc6LpDRu69St90VeaGK3GhJYYic9mggY V/hMGD1w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sIIIA-00000004PeO-3G1L; Sat, 15 Jun 2024 01:33:18 +0000 Received: from mail-qv1-xf34.google.com ([2607:f8b0:4864:20::f34]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sIII8-00000004PdB-0K3w for linux-arm-kernel@lists.infradead.org; Sat, 15 Jun 2024 01:33:17 +0000 Received: by mail-qv1-xf34.google.com with SMTP id 6a1803df08f44-6b064841f81so21799986d6.1 for ; Fri, 14 Jun 2024 18:33:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718415194; x=1719019994; darn=lists.infradead.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :feedback-id:from:to:cc:subject:date:message-id:reply-to; bh=Nl32RvA7/8lBmewSY1/SnN35QBeCzByhM9oh3NCck0A=; b=VtY8yiLz7hfN1AeYZoIPaUHmfjjiRVIRoiAEmqH7x3yVUehTB2mCwncgzvaJV6nZYN J5Dlf+cED9IbsQMAX3E+9OWShXU74y2cm03hJaB8jReJ0UQviolvbyZLqMpTe3P59TCk uSOmRI6uxgM/5cCkSYjtfgF7BY6fNkdbUJJnj3EZDng2D59lUtXZivz5Z3V8LfMPoVqk hVK0nn/kpZuKpB99mQClmiICw8BWjK3HTrJ13CzcdG1DI3ZYSuqgs6A87Qvl8Aetb0Kw ARFlOfj9Qlcs61wIW+TUlp4TY/XRGudVqsV4Iu6sWhixqqVawNG4fIusgqgYijG49kKS CDmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718415194; x=1719019994; h=in-reply-to:content-transfer-encoding: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=Nl32RvA7/8lBmewSY1/SnN35QBeCzByhM9oh3NCck0A=; b=AjChAO5/3z4G97QS5LKf06veclUulPkenuLXofDQFAhY5rxHVLr7GYTU8ewoZlSn/X wC0z+zymlHT92ubOy+FsW2aiJih7T9fZDRhqgJIGcpbG16GI7HBtaEpKAQzjkgpTOUbk h6F6z/Z7iVqkCSfmUKXnEcozWxQoKGDXAQ9GIFPLwnVar0IgvIaeigG+Cd2yFj7XL22T EqY//z8JT9P8a9+wP3H26rFWkFsSB64999skaR7I4gwI60oZL+NZs460OZzZlGCiTJTw XeGm4GsQPo0Wlj7K4T5dam7rrmDkM1WJYYDNv/7qFHqHh2zvh/+80yvtQ2ETmb+hOiBG 2BDA== X-Forwarded-Encrypted: i=1; AJvYcCXE9UScNBYb6SR0lwyW4kqweUZI3gMoKcvqPWXOAzZ3l+RfMEssDpvnlL77VviKldnWnys2SkVS29Ts35OHU9B+ysfbMUzuHS+zmLg5rtE+F/dp72Q= X-Gm-Message-State: AOJu0YzLCrMyYdc6qIQ+cS/rJ3M+B6Wbv2OdXQIss0AsopNMZi5uRB7C chJmpJEb5wCOxhBoYOZtZBOJJxWZ2JP4/9GzKf7FMQx9kCPr7O6A X-Google-Smtp-Source: AGHT+IHusve5yBDJq/XFnwBg2V+Vmg3WpZo51eIFcVWMMwJppFqQKmZbR+WS7jABk1wBgQwKzARILQ== X-Received: by 2002:a05:6214:d89:b0:6a0:c903:7226 with SMTP id 6a1803df08f44-6b2afceb0edmr56977236d6.34.1718415194197; Fri, 14 Jun 2024 18:33:14 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b2a5c466ccsm25109666d6.71.2024.06.14.18.33.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 18:33:13 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfauth.nyi.internal (Postfix) with ESMTP id EDBEC120006A; Fri, 14 Jun 2024 21:33:12 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 14 Jun 2024 21:33:13 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvtddggeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggugfgjsehtkeertddttdejnecuhfhrohhmpeeuohhq uhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrf grthhtvghrnhepvefghfeuveekudetgfevudeuudejfeeltdfhgfehgeekkeeigfdukefh gfegleefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epsghoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedt ieegqddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfh higihmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 14 Jun 2024 21:33:10 -0400 (EDT) Date: Fri, 14 Jun 2024 18:33:10 -0700 From: Boqun Feng To: Benno Lossin Cc: Miguel Ojeda , Gary Guo , 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 , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , 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, Mark Rutland , 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, Trevor Gross , dakr@redhat.com Subject: Re: [RFC 2/2] rust: sync: Add atomic support Message-ID: References: <20240612223025.1158537-1-boqun.feng@gmail.com> <20240612223025.1158537-3-boqun.feng@gmail.com> <20240613144432.77711a3a@eugeo> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240614_183316_169752_1D3343D6 X-CRM114-Status: GOOD ( 28.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Jun 14, 2024 at 09:22:24PM +0000, Benno Lossin wrote: > On 14.06.24 16:33, Boqun Feng wrote: > > On Fri, Jun 14, 2024 at 11:59:58AM +0200, Miguel Ojeda wrote: > >> On Thu, Jun 13, 2024 at 9:05 PM Boqun Feng wrote: > >>> > >>> Does this make sense? > >> > >> Implementation-wise, if you think it is simpler or more clear/elegant > >> to have the extra lower level layer, then that sounds fine. > >> > >> However, I was mainly talking about what we would eventually expose to > >> users, i.e. do we want to provide `Atomic` to begin with? If yes, > > > > The truth is I don't know ;-) I don't have much data on which one is > > better. Personally, I think AtomicI32 and AtomicI64 make the users have > > to think about size, alignment, etc, and I think that's important for > > atomic users and people who review their code, because before one uses > > atomics, one should ask themselves: why don't I use a lock? Atomics > > provide the ablities to do low level stuffs and when doing low level > > stuffs, you want to be more explicit than ergonomic. > > How would this be different with `Atomic` and `Atomic`? Just The difference is that with Atomic{I32,I64} APIs, one has to choose (and think about) the size when using atomics, and cannot leave that option open. It's somewhere unconvenient, but as I said, atomics variables are different. For example, if someone is going to implement a reference counter struct, they can define as follow: struct Refcount { refcount: AtomicI32, data: UnsafeCell } but with atomic generic, people can leave that option open and do: struct Refcount { refcount: Atomic, data: UnsafeCell } while it provides configurable options for experienced users, but it also provides opportunities for sub-optimal types, e.g. Refcount: on ll/sc architectures, because `data` and `refcount` can be in the same machine-word, the accesses of `refcount` are affected by the accesses of `data`. The point I'm trying to make here is: when you are using atomics, you care about performance a lot (otherwise, why don't you use a lock?), and because of that, you should care about the size of the atomics, because it may affect the performance significantly. Regards, Boqun > because the underlying `Atomic` type is generic shouldn't change > this, right? > > --- > Cheers, > Benno >