From: Andreas Hindborg <a.hindborg@kernel.org>
To: FUJITA Tomonori <fujita.tomonori@gmail.com>
Cc: rust-for-linux@vger.kernel.org, boqun.feng@gmail.com,
frederic@kernel.org, lyude@redhat.com, tglx@linutronix.de,
anna-maria@linutronix.de, jstultz@google.com, sboyd@kernel.org,
ojeda@kernel.org, alex.gaynor@gmail.com, gary@garyguo.net,
bjorn3_gh@protonmail.com, benno.lossin@proton.me,
aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 3/5] rust: time: Add HrTimerExpires trait
Date: Fri, 30 May 2025 15:04:00 +0200 [thread overview]
Message-ID: <87ecw61c8v.fsf@kernel.org> (raw)
In-Reply-To: <20250504045959.238068-4-fujita.tomonori@gmail.com> (FUJITA Tomonori's message of "Sun, 4 May 2025 13:59:56 +0900")
Hi Tomonori,
Thanks for fixing this.
FUJITA Tomonori <fujita.tomonori@gmail.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@gmail.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
next prev parent reply other threads:[~2025-05-30 13:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-04 4:59 [PATCH v1 0/5] rust: time: Convert hrtimer to use Instant and Delta FUJITA Tomonori
2025-05-04 4:59 ` [PATCH v1 1/5] rust: time: Change Delta methods to take &self instead of self FUJITA Tomonori
2025-06-02 8:23 ` Alice Ryhl
2025-06-02 12:19 ` Andreas Hindborg
2025-06-03 13:31 ` FUJITA Tomonori
2025-05-04 4:59 ` [PATCH v1 2/5] rust: timer: Replace HrTimerMode enum with trait-based mode types FUJITA Tomonori
2025-06-02 12:53 ` Andreas Hindborg
2025-05-04 4:59 ` [PATCH v1 3/5] rust: time: Add HrTimerExpires trait FUJITA Tomonori
2025-05-30 13:04 ` Andreas Hindborg [this message]
2025-06-03 13:51 ` FUJITA Tomonori
2025-06-03 16:28 ` Andreas Hindborg
2025-05-04 4:59 ` [PATCH v1 4/5] rust: time: Make HasHrTimer generic over HrTimerMode FUJITA Tomonori
2025-06-02 12:41 ` Andreas Hindborg
2025-06-03 14:08 ` FUJITA Tomonori
2025-06-03 16:30 ` Andreas Hindborg
2025-05-04 4:59 ` [PATCH v1 5/5] rust: time: Remove Ktime in hrtimer FUJITA Tomonori
2025-06-02 12:41 ` Andreas Hindborg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ecw61c8v.fsf@kernel.org \
--to=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=anna-maria@linutronix.de \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=frederic@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=tglx@linutronix.de \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).