Re: [PATCH v9 07/13] rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&T>`

From: Andreas Hindborg
Date: Tue Feb 25 2025 - 04:10:26 EST


"Lyude Paul" <lyude@xxxxxxxxxx> writes:

> On Mon, 2025-02-24 at 13:03 +0100, Andreas Hindborg wrote:
>> Allow pinned references to structs that contain a `HrTimer` node to be
>> scheduled with the `hrtimer` subsystem.
>>
>> Acked-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
>> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
>> ---
>> rust/kernel/time/hrtimer.rs | 2 +
>> rust/kernel/time/hrtimer/pin.rs | 99 +++++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 101 insertions(+)
>>
>> diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
>> index 64b769ad59cc..52a3dd1c3984 100644
>> --- a/rust/kernel/time/hrtimer.rs
>> +++ b/rust/kernel/time/hrtimer.rs
>> @@ -428,3 +428,5 @@ unsafe fn raw_get_timer(ptr: *const Self) ->
>>
>> mod arc;
>> pub use arc::ArcHrTimerHandle;
>> +mod pin;
>> +pub use pin::PinHrTimerHandle;
>> diff --git a/rust/kernel/time/hrtimer/pin.rs b/rust/kernel/time/hrtimer/pin.rs
>> new file mode 100644
>> index 000000000000..6c9f2190f8e1
>> --- /dev/null
>> +++ b/rust/kernel/time/hrtimer/pin.rs
>> @@ -0,0 +1,99 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +
>> +use super::HasHrTimer;
>> +use super::HrTimer;
>> +use super::HrTimerCallback;
>> +use super::HrTimerHandle;
>> +use super::RawHrTimerCallback;
>> +use super::UnsafeHrTimerPointer;
>> +use crate::time::Ktime;
>> +use core::pin::Pin;
>> +
>> +/// A handle for a `Pin<&HasHrTimer>`. When the handle exists, the timer might be
>> +/// running.
>> +pub struct PinHrTimerHandle<'a, T>
>> +where
>> + T: HasHrTimer<T>,
>> +{
>> + pub(crate) inner: Pin<&'a T>,
>> +}
>
> Any reason this isn't just:
>
> pub struct PinHrTimerHandle<'a, T: HasHrTimer<T>>(Pin<&'a T>)
> where
> T: HasHrTimer<T>;
>
> With that nit (feel free to take it or leave it) resolved:

I had review comments in the past asking me to not use tuple structs.
The rationale being that the name carries context/intent. In this
particular case, I don't think the name helps a lot, but I also don't
mind having it there.

>
> Reviewed-by: Lyude Paul <lyude@xxxxxxxxxx>

Thanks you!


Best regards,
Andreas Hindborg