From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DE34207A03; Sat, 22 Feb 2025 11:27:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740223657; cv=none; b=BfFivVdhKBFl5C4r73Uze/pcipxpKvL7klwI27eMeqtlNp2RmghZLm9Ck1Y0hEwD85c1L1rZwgBgIuTKQk42OJh43blARQuxVYCY6KPvMXzjL6+TWkfAYv66RglMkZKu8aLVZkSH0TopEjYln9vi93c/MFSYlQKZ0LZPrGxi/Qg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740223657; c=relaxed/simple; bh=WxrDsmMBLtsWhAj3vyvEabkkXnfwKlhdJ9w+mMMtKY8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=G7Qh+6TPi08Pn6P+YNVlu7NhkRv038i1MgElYM5LI+s60EEY4XVnd4Z9I7mD82i1ZdFnxI1XsVySgGd//QEQB7Izrcx/HoDG4yWdMDP6raGWllhT2HzpK3i1FBaTGe8Ss0PLpkF3vd6nsoUNTJeNpNrAJayw813HzTbWrkpmC3U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iJKGy3qn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iJKGy3qn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 211DFC4CED1; Sat, 22 Feb 2025 11:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740223656; bh=WxrDsmMBLtsWhAj3vyvEabkkXnfwKlhdJ9w+mMMtKY8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=iJKGy3qnJfjsy4/+L1Zetu6p7YcZ+eNuPCwAW/aGB1O1I/VIUgytZvcRlrQweRN6y kUoIxeovt1Jyi8fqYp4Nk29affseuzW/lmRv42jaIIIQIRLxumB7hZKRHA1RuNGfZk cYxN2PhhkEhGH9qYIeR2gXnrPBwOuLtUllVpPIwn6Zx2nGm28Ve1d6iuUbJFVp3o95 zlxl8zD4Yu/GmvBcTVM4m+vbBjRSgxA+jEEC0oxghBSLfqiA7W0Ydhhz0kw+9XnaVn FN3H/AxVxt1msDU3Jp96LxhWAf/2qitm19t1mCraBjWQKgjsqaWM4A6jJmxu4OA9gq rJsulp2aEL9cQ== From: Andreas Hindborg To: "Benno Lossin" Cc: "Miguel Ojeda" , "Anna-Maria Behnsen" , "Frederic Weisbecker" , "Thomas Gleixner" , "Danilo Krummrich" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?Q?Bj?= =?utf-8?Q?=C3=B6rn?= Roy Baron , "Alice Ryhl" , "Trevor Gross" , "Lyude Paul" , "Guangbo Cui" <2407018371@qq.com>, "Dirk Behme" , "Daniel Almeida" , "Tamir Duberstein" , , Subject: Re: [PATCH v8 02/14] rust: hrtimer: introduce hrtimer support In-Reply-To: (Benno Lossin's message of "Sat, 22 Feb 2025 09:37:53 +0000") References: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@kernel.org> <20250218-hrtimer-v3-v6-12-rc2-v8-2-48dedb015eb3@kernel.org> <1id7is_U22yzuGODgkUIoB5AFM6snF9CPu7F_sY7Mfkn3EwQRPfjB5JNkRFYu6DX1N8X_OQvdEB2BT-l3rFhwg==@protonmail.internalid> <87a5afhdq0.fsf@kernel.org> <875xl3fvtm.fsf@kernel.org> <841150db-2f92-4cfe-bb1f-29b34b4662c1@proton.me> <87o6yveble.fsf@kernel.org> User-Agent: mu4e 1.12.7; emacs 29.4 Date: Sat, 22 Feb 2025 12:27:22 +0100 Message-ID: <87mseecj8l.fsf@kernel.org> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain "Benno Lossin" writes: > On 21.02.25 13:17, Andreas Hindborg wrote: >> "Benno Lossin" writes: >> >>> On 21.02.25 11:15, Andreas Hindborg wrote: >>>> Andreas Hindborg writes: >>>> >>>>> "Benno Lossin" writes: >>>>> >>>>>> On 18.02.25 14:27, Andreas Hindborg wrote: >>>>>>> +pub trait HrTimerCallback { >>>>>>> + /// The type whose [`RawHrTimerCallback::run`] method will be invoked when >>>>>>> + /// the timer expires. >>>>>>> + type CallbackTarget<'a>: RawHrTimerCallback; >>>>>>> + >>>>>>> + /// This type is passed to the timer callback function. It may be a borrow >>>>>>> + /// of [`Self::CallbackTarget`], or it may be `Self::CallbackTarget` if the >>>>>>> + /// implementation can guarantee exclusive access to the target during timer >>>>>> >>>>>> Technically "exclusive" access is correct if the `CallbackTarget` is >>>>>> `Pin<&Self>`, since you will get exclusive access to a `Pin<&Self>`, but >>>>>> it might confuse people, because there can be multiple `Pin<&Self>`. So >>>>>> I would just drop the word "exclusive" here. >>>>> >>>>> Yes, maybe it should be "shared or exclusive access, depending on the type"? >>>>> >>>>>> >>>>>>> + /// handler execution. >>>>>>> + type CallbackTargetParameter<'a>; >>>>>> >>>>>> Also why can't this type be an associated type of `HrTimerPointer`? >>>>>> Since this seems to always be constrained in the impls of >>>>>> `RawHrTimerCallback`. >>>>> >>>>> That might be a nice improvement, I'll try that out. >>>> >>>> Looking closer at this, I don't see how to achieve this. We need access >>>> to the type here, because it is used in the signature of `run`. >>>> `HrTimerCallback` has no bounds on it, and that is nice. If we want to >>>> move these associated types, we have to introduce a bound here. >>>> >>>> We need to be generic over the type of the parameter to `run`, and by >>>> the time the user implements this trait, the type must be known and so >>>> the user has to specify somehow. >>> >>> I think if you put the associated type on the `RawHrTimerCallback` >>> trait, it should work. >> >> What would be the signature of `HrTimerCallback::run` in that case? > > /// Implemented by structs that can be the target of a timer callback. > pub trait HrTimerCallback { > /// The type whose [`RawHrTimerCallback::run`] method will be invoked when > /// the timer expires. > type CallbackTarget: RawHrTimerCallback; > > /// Called by the timer logic when the timer fires. > fn run(this: ::CallbackTargetParameter<'_>) > where > Self: Sized; > // also, why does this Sized bound exist here? > } > > That should work, but now the names seem a bit long... How about: > - CallbackTarget -> Pointer > - and then you can also call this the "smart pointer whose `run` > method will be invoked when..." in the docs > - CallbackTargetParameter -> CallbackParameter Right, that works. I thought you wanted to move both the associated types. Best regards, Andreas Hindborg