Skip to content

rust/hrtimer: Various hrtimer + time additions

Lyude Paul lkml rust-for-linux 8 versions – Applied

Status from this message: Applied, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v9 Latest7 patches 6 repliesApplied
  2. v87 patches 1 replySuperseded
  3. v77 patches 4 repliesSuperseded
Earlier versions · 5
VersionPostedPatchesRepliesStatus
v67 patches14 repliesSuperseded
v57 patches7 repliesSuperseded
v47 patches1 replySuperseded
v28 patches19 repliesSuperseded
v16 patches15 repliesSuperseded

Changes in v9 from the cover letter

* Correct outdated comments in Instant::from_ktime()

Patches in v9 Applied

#Subject and filesSizeRepliesApplied
1/7rust: hrtimer: Document the return value for HrTimerHandle::cancel()rust/kernel/time/hrtimer.rs+2 -00 replies
2/7rust: hrtimer: Add HrTimerInstantrust/kernel/time/hrtimer.rs+5 -00 replies
3/7rust: hrtimer: Add HrTimer::raw_forward() and forward()rust/kernel/time/hrtimer.rs+40 -00 replies
4/7rust: hrtimer: Add HrTimerCallbackContext and ::forward()rust/kernel/time/hrtimer.rs rust/kernel/time/hrtimer/arc.rs rust/kernel/time/hrtimer/pin.rs +2 more+93 -90 replies
5/7rust: hrtimer: Add forward_now() to HrTimer and HrTimerCallbackContextrust/kernel/time/hrtimer.rs+19 -00 replies
6/7rust: time: Add Instant::from_ktime()rust/kernel/time.rs+23 -04 replies
7/7rust: hrtimer: Add HrTimer::expires()rust/kernel/time.rs rust/kernel/time/hrtimer.rs+23 -11 reply

Reviews trailers per patch

All 7 patches have a Reviewed-by or Acked-by.

PatchAndreas HindborgDaniel AlmeidaFUJITA TomonoriAlice Ryhl
1/7R-b R-b
2/7R-b R-b
3/7R-b
4/7R-b R-b
5/7R-b R-b
6/7R-b R-b R-b
7/7R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v9 thread

Cover letter [PATCH v9 0/7] rust/hrtimer: Various hrtimer + time additions

This is a collection of various bindings that I added to hrtimer when I was originally getting it ready to be used in rvkms. I've mostly been waiting for Andreas's hrtimer series to go upstream before submitting these.

All of these are currently being used within rvkms for vblank emulation.

Previous versions:
Version 1: https://lkml.org/lkml/2025/4/2/1474
Version 2: https://lkml.org/lkml/2025/4/15/1750
Version 3 (only a revision of one patch): https://lkml.org/lkml/2025/4/15/1780
Version 4: https://lkml.org/lkml/2025/4/29/1715
Version 5: https://lkml.org/lkml/2025/6/13/1785
Version 6: https://lkml.org/lkml/2025/7/24/1390
Version 7: https://lkml.org/lkml/2025/8/13/1875
Version 8: https://lkml.org/lkml/2025/8/19/1817

Usage example:
(keep in mind, I haven't rebased the example entirely - but the only
differences there is a few comments)

https://gitlab.freedesktop.org/lyudess/linux/-/tree/rvkms-slim/rust/kernel?ref_type=heads

Lyude Paul (7):
rust: hrtimer: Document the return value for HrTimerHandle::cancel()
rust: hrtimer: Add HrTimerInstant
rust: hrtimer: Add HrTimer::raw_forward() and forward()
rust: hrtimer: Add HrTimerCallbackContext and ::forward()
rust: hrtimer: Add forward_now() to HrTimer and HrTimerCallbackContext
rust: time: Add Instant::from_ktime()
rust: hrtimer: Add HrTimer::expires()

Patches changed since V8:
rust: time: Add Instant::from_ktime()

These patches still need re-review!

rust: hrtimer: Add HrTimer::expires()
rust: time: Add Instant::from_ktime()

Changelog:
rust: hrtimer: Document the return value for HrTimerHandle::cancel()
V4:
* Reword to "Returns true if the timer was running."
rust: hrtimer: Add HrTimerInstant
V4:
* Fix the safety contract for raw_forward()
* Require Pin<&mut Self>, not &mut self
* Drop incorrect UniquePin example
* Rewrite documentation a bit (re: Andreas)
V6:
* Remove the reference to HrTimerCallbackContext::forward() until this function gets added.
V7:
* Split up Timer::forward() a bit, apply Andreas's SAFETY comment recommendations
rust: hrtimer: Add HrTimer::raw_forward() and forward()
rust: hrtimer: Add HrTimerCallbackContext and ::forward()
V2:
* Improve SAFETY comments for HrTimerCallbackContext uses (I forgot to mention that we're within RawHrTimerCallback::run()
* Split forward into forward() and raw_forward() since we're going to have two contexts that we can call forward() from now.
* Clarify contexts in which certain hrtimer methods can be called.
* Make sure that we use a mutable reference for forward() here - just in case :).
* Rename interval to duration
V3:
* Rename duration -back- to interval (now that I actually have read hrtimer_forward's source, interval does make more sense than duration considering the fact we return the number of overruns that occurred according to the given interval).
* Rewrite documentation a bit (re: Andreas)
V5:
* Fix unbounded T on HrTimerCallbackContext
V6:
* Move reference to HrTimerCallbackContext::forward() in HrTimer::forward() comments into this commit so rustdoc doesn't fail.
* Deduplicate documentation for HrTimerCallbackContext::forward()
* Add missing changelog note

rust: hrtimer: Add forward_now() to HrTimer and HrTimerCallbackContext
V2:
* Change from Ktime to Delta
* Make sure that forward_now() takes a mutable reference to the timer struct
* Reword this to point out that we're adding forward_now() to both callback context and mutable timer reference
* Rename interval to duration
V4:
* Fix rust documentation for HrTimerCallbackContext (forgot to update both forward_now() declarations)
* Use Pin<&mut Self> for context-less forward.
V6:
* Drop raw_cb_time(), use Instant::now() instead
* Split out expires() from this patch, at some point it seems I mistakenly combined it with this patch
V7:
* Remove leftover comment about raw_cb_time from patch description

rust: time: Add Instant::from_ktime()
V4:
* Turn from_nanos() into an unsafe function in order to ensure that we uphold the invariants of Instant
V5:
* Add debug_assert!() to from_nanos
V8:
* Change name of function from Instant::from_nanos() to Instant::from_ktime()
V9:
* Correct outdated comments in Instant::from_ktime()

rust: hrtimer: Add HrTimer::expires()
V8:
* Fix bogus safety comment I noticed after Fujita's comments. In expires() we're not guaranteed to get a non-negative ktime_t because of ktime_t itself, we're guaranteed to get one because a negative expiration time for a timer doesn't make sense.

Lyude Paul (7):
rust: hrtimer: Document the return value for HrTimerHandle::cancel()
rust: hrtimer: Add HrTimerInstant
rust: hrtimer: Add HrTimer::raw_forward() and forward()
rust: hrtimer: Add HrTimerCallbackContext and ::forward()
rust: hrtimer: Add forward_now() to HrTimer and HrTimerCallbackContext
rust: time: Add Instant::from_ktime()
rust: hrtimer: Add HrTimer::expires()

 rust/kernel/time.rs                 |  22 ++++
 rust/kernel/time/hrtimer.rs         | 152 +++++++++++++++++++++++++++-
 rust/kernel/time/hrtimer/arc.rs     |   9 +-
 rust/kernel/time/hrtimer/pin.rs     |   9 +-
 rust/kernel/time/hrtimer/pin_mut.rs |  12 ++-
 rust/kernel/time/hrtimer/tbox.rs    |   9 +-
 6 files changed, 204 insertions(+), 9 deletions(-)

base-commit: c17b750b3ad9f45f2b6f7e6f7f4679844244f0b9

Signature · 1 line
2.50.0