Rust timekeeping for v6.17
Andreas Hindborg
reviewerHi Miguel,
Please pull these changes for Rust timekeeping.
This batch of changes makes Instant generic over the clock source. HrTimer also gets the generic treatment, allowing the API to type check the time stamps passed to the API, to statically check whether a relative or absolute time is required.
We also have a fix for 32-bit divisions on 64-bit architectures.
The commits have been in linux-next for at least a week.
The following changes since commit e04c78d86a9699d136910cfc0bdcf01087e3267e:
Linux 6.16-rc2 (2025-06-15 13:49:41 -0700)
are available in the Git repository at:
ssh://github.com/Rust-for-Linux/linux.git tags/rust-timekeeping-for-v6.17
for you to fetch changes up to d4b29ddf82a458935f1bd4909b8a7a13df9d3bdc:
rust: time: Add wrapper for fsleep() function (2025-06-30 13:22:05 +0200)
Best regards,
Andreas Hindborg
----------------------------------------------------------------
rust-timekeeping for v6.17
----------------------------------------------------------------
FUJITA Tomonori (10):
rust: time: Avoid 64-bit integer division on 32-bit architectures
rust: time: Replace ClockId enum with ClockSource trait
rust: time: Make Instant generic over ClockSource
rust: time: Add ktime_get() to ClockSource trait
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: time: Seal the HrTimerMode trait
rust: time: Add wrapper for fsleep() function
rust/helpers/helpers.c | 1 + rust/helpers/time.c | 35 +++++ rust/kernel/time.rs | 233 ++++++++++++++++++---------- rust/kernel/time/delay.rs | 49 ++++++ rust/kernel/time/hrtimer.rs | 302 ++++++++++++++++++++++++------------ 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 +- 9 files changed, 466 insertions(+), 186 deletions(-) create mode 100644 rust/helpers/time.c create mode 100644 rust/kernel/time/delay.rs
Quoted 5 lines · Andreas Hindborg
----------------------------------------------------------------
rust-timekeeping for v6.17----------------------------------------------------------------
The description is empty -- could you please provide a bit of text?
No need to send a new PR, since I know you may be away from your usual office these days -- I can copy it from email.
(Worst case, I will write something myself, but there is still time.)
Thanks!
Cheers,
Miguel
Andreas Hindborg
reviewerHi Miguel,
Quoted 5 lines · Miguel Ojeda
Quoted 4 lines · Andreas Hindborg
----------------------------------------------------------------
rust-timekeeping for v6.17
Quoted 9 lines
Quoted 1 line
----------------------------------------------------------------
The description is empty -- could you please provide a bit of text?
No need to send a new PR, since I know you may be away from your usual office these days -- I can copy it from email.
(Worst case, I will write something myself, but there is still time.)
Sorry for the missing tag text. Let me know if you can use the following bullets:
- Make Instant generic over clock source. This allows the compiler to assert that arithmetic expressions involving the Instant use Instants based on the same clock source.
- Make HrTimer generic over the timer mode. HrTimer timers take a Duration or an Instant when setting the expiry time, depending on the timer mode. With this change, the compiler can check the type matches the timer mode.
- Add an abstraction for fsleep. fsleep is a flexible sleep function that will select an appropriate sleep method depending on the requested sleep time.
- Avoid 64-bit divisions on 32-bit hardware when calculating timestamps.
- Seal the HrTimerMode trait. This prevents users of the HrTimerMode from implementing the trait on their own types.
Best regards,
Andreas Hindborg
Quoted 4 lines · Andreas Hindborg
Sorry for the missing tag text. Let me know if you can use the following bullets:
Quoted 13 lines
- Make
Instantgeneric over clock source. This allows the compiler to assert that arithmetic expressions involving theInstantuseInstantsbased on the same clock source.
- MakeHrTimergeneric over the timer mode.HrTimertimers take aDurationor anInstantwhen setting the expiry time, depending on the timer mode. With this change, the compiler can check the type matches the timer mode.
- Add an abstraction forfsleep.fsleepis a flexible sleep function that will select an appropriate sleep method depending on the requested sleep time.
- Avoid 64-bit divisions on 32-bit hardware when calculating timestamps.
- Seal theHrTimerModetrait. This prevents users of theHrTimerModefrom implementing the trait on their own types.
No worries at all, looks good, thanks!
Cheers,
Miguel
Miguel Ojeda
AppliedQuoted 2 lines · Andreas Hindborg
Please pull these changes for Rust timekeeping.
Merged into rust-next -- thank you!
(I applied the related fix on top.)
Cheers,
Miguel