[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250504045959.238068-1-fujita.tomonori@gmail.com>
Date: Sun, 4 May 2025 13:59:53 +0900
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: rust-for-linux@...r.kernel.org
Cc: a.hindborg@...nel.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: [PATCH v1 0/5] rust: time: Convert hrtimer to use Instant and Delta
Convert hrtimer to use `Instant` and `Delta`; remove the use of
`Ktime` from the hrtimer code, which was originally introduced as a
temporary workaround.
hrtimer uses either an `Instant` or a `Delta` as its expiration value,
depending on the mode specified at creation time. This patchset
replaces `HrTimerMode` enum with a trait-based abstraction and
associates each mode with either an `Instant` or a `Delta`. By
leveraging Rust's type system, this change enables `HrTimer` to be
statically associated with a specific `HrTimerMode`, the corresponding
`Instant` or `Delta`, and a `ClockSource`.
The `impl_has_hr_timer` macro is extended to allow specifying the
`HrTimerMode`. In the following example, it guarantees that the
`start()` method for `Foo` only accepts `Instant<Monotonic>`. Using a
`Delta` or an `Instant` with a different clock source will result in a
compile-time error:
struct Foo {
#[pin]
timer: HrTimer<Self>,
}
impl_has_hr_timer! {
impl HasHrTimer<Self> for Foo {
mode = AbsoluteMode<Monotonic>,
self.timer
}
}
This design eliminates runtime mismatches between expires types and
clock sources, and enables stronger type-level guarantees throughout
hrtimer.
This patchset can be applied on top of the typed clock sources patchset:
https://lore.kernel.org/lkml/20250504042436.237756-1-fujita.tomonori@gmail.com/
FUJITA Tomonori (5):
rust: time: Change Delta methods to take &self instead of self
rust: timer: Replace HrTimerMode enum with trait-based mode types
rust: time: Add HrTimerExpires trait
rust: time: Make HasHrTimer generic over HrTimerMode
rust: time: Remove Ktime in hrtimer
rust/kernel/time.rs | 15 +-
rust/kernel/time/hrtimer.rs | 288 ++++++++++++++++++----------
rust/kernel/time/hrtimer/arc.rs | 8 +-
rust/kernel/time/hrtimer/pin.rs | 8 +-
rust/kernel/time/hrtimer/pin_mut.rs | 8 +-
rust/kernel/time/hrtimer/tbox.rs | 8 +-
6 files changed, 225 insertions(+), 110 deletions(-)
base-commit: 7b33a2d9c12023a73b7ba105a3eed77c3527a94e
--
2.43.0
Powered by blists - more mailing lists