[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87ecw61c8v.fsf@kernel.org>
Date: Fri, 30 May 2025 15:04:00 +0200
From: Andreas Hindborg <a.hindborg@...nel.org>
To: FUJITA Tomonori <fujita.tomonori@...il.com>
Cc: rust-for-linux@...r.kernel.org, boqun.feng@...il.com,
frederic@...nel.org, lyude@...hat.com, tglx@...utronix.de,
anna-maria@...utronix.de, jstultz@...gle.com, sboyd@...nel.org,
ojeda@...nel.org, alex.gaynor@...il.com, gary@...yguo.net,
bjorn3_gh@...tonmail.com, benno.lossin@...ton.me, aliceryhl@...gle.com,
tmgross@...ch.edu, dakr@...nel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v1 3/5] rust: time: Add HrTimerExpires trait
Hi Tomonori,
Thanks for fixing this.
FUJITA Tomonori <fujita.tomonori@...il.com> writes:
> Introduce the `HrTimerExpires` trait to represent types that can be
> used as expiration values for high-resolution timers. Define a
> required method, `as_nanos()`, which returns the expiration time as a
> raw nanosecond value suitable for use with C's hrtimer APIs.
>
> Also extend the `HrTimerMode` to use the `HrTimerExpires` trait.
>
> This refactoring is a preparation for enabling hrtimer code to work
> uniformly with both absolute and relative expiration modes.
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@...il.com>
> ---
> rust/kernel/time.rs | 5 +
> rust/kernel/time/hrtimer.rs | 181 ++++++++++++++++++++++++------------
> 2 files changed, 128 insertions(+), 58 deletions(-)
>
> diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
> index deca2999ced6..ac9551fca14f 100644
> --- a/rust/kernel/time.rs
> +++ b/rust/kernel/time.rs
> @@ -194,6 +194,11 @@ pub fn now() -> Self {
> pub fn elapsed(&self) -> Delta {
> Self::now() - *self
> }
> +
> + #[inline]
> + pub(crate) fn as_nanos(&self) -> i64 {
> + self.inner
> + }
> }
>
> impl<C: ClockSource> core::ops::Sub for Instant<C> {
> diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
> index 24d013e47c7b..55e1825425b6 100644
> --- a/rust/kernel/time/hrtimer.rs
> +++ b/rust/kernel/time/hrtimer.rs
<cut>
> +/// Defines a new `HrTimerMode` implementation with a given expiration type and C mode.
> +#[doc(hidden)]
> +macro_rules! define_hrtimer_mode {
> + (
> + $(#[$meta:meta])*
> + $vis:vis struct $name:ident<$clock:ident> {
> + c = $mode:ident,
> + expires = $expires:ty
> + }
> + ) => {
> + $(#[$meta])*
> + $vis struct $name<$clock: $crate::time::ClockSource>(
> + ::core::marker::PhantomData<$clock>
> + );
I think a macro is too much here. The code would be easier to read
without the macro, and the macro does not remove much code here.
Could you try to do the trait implementations without the macro?
Best regards,
Andreas Hindborg
Powered by blists - more mailing lists