Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp1565328lqs; Sat, 15 Jun 2024 15:12:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVyIrHGpPxWZgeCevADKHfmredV8dqBSg3fcS1+BtuwJuyLiCRRqX9rNxbUHqx8ZjfjQ3KGruUYxJGS8mOW80WnERGojGSpfdVtz9LK8A== X-Google-Smtp-Source: AGHT+IEOKsKpYS6d1p4KIZmW60E/UfCiOBfOfLGGNq4pyQADu5ZkMweNFu4te0T6Z/uJEWtBci1k X-Received: by 2002:a05:622a:15cd:b0:440:97b5:cb with SMTP id d75a77b69052e-442160b43c5mr104191981cf.32.1718489576168; Sat, 15 Jun 2024 15:12:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718489576; cv=pass; d=google.com; s=arc-20160816; b=wKtrMG7JFpJRe/gWBp/qwq/ssafn+YKSZNN7uNwpL/B+BwiTqFVVWo1nr85OzA7bMN 6flfF/lpPdMmx8NtET0y/PzRRANa6PkNJj3ChuP+slRH16jxiVCwi6rFN2pGLoRJMHsF yK0xf+gYygrd7OglEjDk9Zirh7nenBTc8tZmh6wVlPG+iENJH3AqxgYi9zSbR68lzMxR 0XA9fGnPVJlsj8zquvtdotw26GvWdYAHEDoMAI/gzmLjXQ+06nvW+Gy0qTxlwG1KxTvs QIyfWIGhItD5qn/LvIzGcc//V1iXW/bQ1z3aUivLxfiT14rXI8aIAuNZFDmeHcnEI4XV P6lg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature; bh=VQbZ8odua1hQgPb+pK/nZMpMy6s0hU++zOMWAbph2Ak=; fh=p31NjFUeQdoN+TqpGs9MKF2xartjB9iUcJCTw2FLi34=; b=dwKJJKebH0Ze0XCi/g5z2PFzNcWVoOku+ptzjWITyHtL/REKGue3JIGMDuaXP15tty bZwXHsNXFrNzt3X3RTpQmxxR3aNsBnVRd9/sFMneTDjmQoZ3sogHiahrV/UD1jaOy1Hb YG/AOeMiuiO+DIQoaynbhkoW9PHm7ZJCHFI6VZK3f2bH+cSh2Rcgb7p+ABkfz+so7jw3 BVOcDfz2dx7wnMQP0+ZZFDCQbw149I9vC2zSxNA+F1Hhs2wPhh5pCNp94avtRyYV+KgC bljYb8AoXIhWyOt440+HZA6Zre4Pqud8tcVavcivtLiZtAATbBo1ZbMdfOaABdZDMEuY Rytw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Eux/TtLv"; 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-216028-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-216028-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-442179d261fsi54197541cf.40.2024.06.15.15.12.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 15:12:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-216028-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Eux/TtLv"; 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-216028-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-216028-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id CDC281C20AAC for ; Sat, 15 Jun 2024 22:12:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6C6326A347; Sat, 15 Jun 2024 22:12:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Eux/TtLv" Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) (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 B91961773A; Sat, 15 Jun 2024 22:12:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718489560; cv=none; b=Hnqy6Ce2wFBMAtTnZULFqf39PRUS8ZRnrVIr1YhlKKhDJ9D6GZhxj5wKVJ4aRvmPiam9QISyucH40V0p5i0X4iQaT+0YAZvX1K1v8fR3faqf+aKb0EkceheT7ee0CChJ6dRxrg2waKqmc/bGWTK/YYZ4axxV+vMLbXu2gr54ggo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718489560; c=relaxed/simple; bh=lHxr0MwsemA2ZMnqJsxiMmV5XulPnNeOMTCLuiEYGpo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=l41UMoK4APSA13FYJGYjlFu0TNq6/7/sK5Jbs2zh4ou/Vw3veK/grHgE4O5sS6Q9aEBpqQX0Gr7yLMULUGmeGqIUWyupipDSMEOMul5nY0ZA10i/GRSb1UGueSMjsnFMRboInNfCdsk1MT27jlsTyzQSkGDBOFDJ/6P42AJWRlQ= 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=Eux/TtLv; arc=none smtp.client-ip=209.85.219.51 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-qv1-f51.google.com with SMTP id 6a1803df08f44-6ae259b1c87so36347206d6.1; Sat, 15 Jun 2024 15:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718489558; x=1719094358; darn=vger.kernel.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=VQbZ8odua1hQgPb+pK/nZMpMy6s0hU++zOMWAbph2Ak=; b=Eux/TtLvuTusRZoxAFHYLpBs35dyCC8YSls+jMkP7QQwd1yQhU3u4RT+l+NjUgYqYi nF3p/Iw5KYi4ch9YRhx8F5O1ppWIyZym3+x9xTFa7dpgbtJT+Xzi3NJSDO2O/LVNF7tB d/b/6s3Nd6KN0pD1Pqwf5KLd4d0oupIxJH2g22vECnKRlt0McP18nh39PPtHGWSPkIF0 25FlbbW+YwWqky7FGZy+GpUZjkySk/UZGpkaHB/myTimima29cCKc7AxE7jNYGYJ4UIx 0w2EqeFp/HgTkqJPQP3n/1WXkK183ApHhln1kGLif5uODEA/5l8vcKH28Kgs6OiwQC1R V1Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718489558; x=1719094358; 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=VQbZ8odua1hQgPb+pK/nZMpMy6s0hU++zOMWAbph2Ak=; b=t0U4lkC0E+gn8bn/wqxA48oqM22JVcwVQVH+d5ZS4op/TjVq7cnkemdwDBQU6LFXRj Yj8BlLwPuRL+/XUPQbJn1SYDKw+gN5Iu/IPfgpMbRVIDyMrYS7wGAZj77XSGEkB9n1qR AifQJ3VXXGXxQsek3NOgoPynyVH8P0X4LHRCQETgLSHUeM8PlTEnRs0VKq5pSovVNT0t EM7WRaxBOKASNaWOSXBoq32A/vFUYgNwWauXMyEcdLKp9DI8QLRt2CuIQyi0/6ysMqtp weLG4cTiT7pcxpmhR2F9/O7r676kM+lED856VqexhOl3CwCjdJavtqaMQwRIZWbN//Pi HOrw== X-Forwarded-Encrypted: i=1; AJvYcCXR4369Dw27eFJwqdcNzuH6jlSouVZz+mn6p5olpMNW1h4nDO09OmpiczJjTEwDeteHVuKnrkJE01cMrNVSCvR5M/Jsjh/8mtcCtlLNlCToJTvMcJreOb1h+u6XCGGgZCBWdfa/ow3Ne+VzByPRh9NVMHMkmXDVM1yyVnkxGHe+OxnrGyALTN8Dji6VZ8zMY5xgQVe2QB5ThxmU0TJwnm1pQjWWMgLohQ== X-Gm-Message-State: AOJu0YwD0mtqcEhllUz5u34AX/EEFYmt49gbvPlDYu4QV1Zqx8kskRL2 gGq9HoSk8nSkfm7cA5n7dhnkb7PeTPpXq2/KB3yihVz+pPT3Uxnn X-Received: by 2002:a0c:c486:0:b0:6af:33ed:87de with SMTP id 6a1803df08f44-6b2af2eef89mr96166876d6.20.1718489557589; Sat, 15 Jun 2024 15:12:37 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b2a5ee01d9sm36048266d6.111.2024.06.15.15.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 15:12:36 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfauth.nyi.internal (Postfix) with ESMTP id BB4DA120006D; Sat, 15 Jun 2024 18:12:35 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sat, 15 Jun 2024 18:12:35 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvvddgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggugfgjsehtkeertddttdejnecuhfhrohhmpeeuohhq uhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrf grthhtvghrnhepvefghfeuveekudetgfevudeuudejfeeltdfhgfehgeekkeeigfdukefh gfegleefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epsghoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedt ieegqddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfh higihmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 15 Jun 2024 18:12:34 -0400 (EDT) Date: Sat, 15 Jun 2024 15:12:33 -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-3-boqun.feng@gmail.com> <20240613144432.77711a3a@eugeo> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Sat, Jun 15, 2024 at 07:09:30AM +0000, Benno Lossin wrote: > On 15.06.24 03:33, Boqun Feng wrote: > > 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`. > > I think this is a non-issue. We have two options of counteracting this: > 1. We can just point this out in reviews and force people to use > `Atomic` with a concrete type. In cases where there really is the > need to be generic, we can have it. > 2. We can add a private trait in the bounds for the generic, nobody > outside of the module can access it and thus they need to use a > concrete type: > > // needs a better name > trait Integer {} > impl Integer for i32 {} > impl Integer for i64 {} > > pub struct Atomic { > /* ... */ > } > > And then in the other module, you can't do this (with compiler error): > > pub struct Refcount { > // ^^^^^^^ not found in this scope > // note: trait `crate::atomic::Integer` exists but is inaccessible > refcount: Atomic, > data: UnsafeCell, > } > > I think that we can start with approach 2 and if we find a use-case > where generics are really unavoidable, we can either put it in the same > module as `Atomic`, or change the access of `Integer`. > What's the issue of having AtomicI32 and AtomicI64 first then? We don't need to do 1 or 2 until the real users show up. And I'd like also to point out that there are a few more trait bound designs needed for Atomic, for example, Atomic and Atomic have different sets of API (no inc_unless_negative() for u32). Don't make me wrong, I have no doubt we can handle this in the type system, but given the design work need, won't it make sense that we take baby steps on this? We can first introduce AtomicI32 and AtomicI64 which already have real users, and then if there are some values of generic atomics, we introduce them and have proper discussion on design. To me, it's perfectly fine that Atomic{I32,I64} co-exist with Atomic. What's the downside? A bit specific example would help me understand the real concern here. Regards, Boqun > --- > Cheers, > Benno > > > 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. >