rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/5] rust: time: Convert hrtimer to use Instant and Delta
@ 2025-06-10 13:28 FUJITA Tomonori
  2025-06-10 13:28 ` [PATCH v3 1/5] rust: time: Rename Delta's methods from as_* to into_* FUJITA Tomonori
                   ` (6 more replies)
  0 siblings, 7 replies; 30+ messages in thread
From: FUJITA Tomonori @ 2025-06-10 13:28 UTC (permalink / raw)
  To: a.hindborg, alex.gaynor, ojeda
  Cc: aliceryhl, anna-maria, bjorn3_gh, boqun.feng, dakr, frederic,
	gary, jstultz, linux-kernel, lossin, lyude, rust-for-linux, sboyd,
	tglx, tmgross

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>,
        field : 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 (v4):

https://lore.kernel.org/lkml/20250610093258.3435874-1-fujita.tomonori@gmail.com/

v3
- allow optional trailing comma for the field entry in impl_has_hr_timer! macro
v2: https://lore.kernel.org/lkml/20250609102418.3345792-1-fujita.tomonori@gmail.com/
- rebased on 6.16-rc1
- change impl_has_hr_timer! macro format
- remove define_hrtimer_mode! macro
- drop patch to change Delta's methods to take &self instead of self
- add patch to rename Delta's methods from as_* to into_*
v1: https://lore.kernel.org/lkml/20250504045959.238068-1-fujita.tomonori@gmail.com/

FUJITA Tomonori (5):
  rust: time: Rename Delta's methods from as_* to into_*
  rust: time: 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                 |  19 +-
 rust/kernel/time/hrtimer.rs         | 281 ++++++++++++++++++----------
 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, 218 insertions(+), 114 deletions(-)


base-commit: 8bffa361fb76742eb953ca024a9363c6e9357d65
-- 
2.43.0


^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2025-07-11  6:14 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-10 13:28 [PATCH v3 0/5] rust: time: Convert hrtimer to use Instant and Delta FUJITA Tomonori
2025-06-10 13:28 ` [PATCH v3 1/5] rust: time: Rename Delta's methods from as_* to into_* FUJITA Tomonori
2025-06-10 13:28 ` [PATCH v3 2/5] rust: time: Replace HrTimerMode enum with trait-based mode types FUJITA Tomonori
2025-06-10 13:28 ` [PATCH v3 3/5] rust: time: Add HrTimerExpires trait FUJITA Tomonori
2025-06-10 13:28 ` [PATCH v3 4/5] rust: time: Make HasHrTimer generic over HrTimerMode FUJITA Tomonori
2025-06-12 13:45   ` Andreas Hindborg
2025-06-10 13:28 ` [PATCH v3 5/5] rust: time: Remove Ktime in hrtimer FUJITA Tomonori
2025-06-16 22:07 ` [PATCH v3 0/5] rust: time: Convert hrtimer to use Instant and Delta FUJITA Tomonori
2025-06-17  8:06   ` Andreas Hindborg
2025-06-17 10:37 ` Andreas Hindborg
2025-06-24 11:08   ` Miguel Ojeda
2025-06-24 11:14     ` Andreas Hindborg
2025-06-24 12:24       ` Miguel Ojeda
2025-06-24 13:11         ` Andreas Hindborg
2025-06-24 13:41           ` FUJITA Tomonori
2025-06-24 17:56             ` Andreas Hindborg
2025-06-24 19:03               ` Andreas Hindborg
2025-06-24 23:20                 ` FUJITA Tomonori
2025-06-25  8:19                   ` Andreas Hindborg
2025-06-26  0:12                     ` FUJITA Tomonori
2025-07-04  7:20                       ` Andreas Hindborg
2025-07-10 11:59                         ` Andreas Hindborg
2025-07-10 23:00                           ` FUJITA Tomonori
2025-07-11  6:13                             ` Andreas Hindborg
2025-06-24 21:13           ` Miguel Ojeda
2025-06-24 23:30             ` FUJITA Tomonori
2025-06-25  8:11               ` Miguel Ojeda
2025-06-25  8:30                 ` Andreas Hindborg
2025-06-25  8:28             ` Andreas Hindborg
2025-06-24 11:16   ` Andreas Hindborg

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).