[PATCH v9 04/13] rust: hrtimer: allow timer restart from timer handler
From: Andreas Hindborg
Date: Mon Feb 24 2025 - 07:11:18 EST
This patch allows timer handlers to report that they want a timer to be
restarted after the timer handler has finished executing.
Also update the `hrtimer` documentation to showcase the new feature.
Acked-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
---
rust/kernel/time/hrtimer.rs | 19 ++++++++++++++++++-
rust/kernel/time/hrtimer/arc.rs | 4 +---
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
index d08fd7de158d..a431c8b728ae 100644
--- a/rust/kernel/time/hrtimer.rs
+++ b/rust/kernel/time/hrtimer.rs
@@ -207,7 +207,7 @@ pub trait HrTimerCallback {
type Pointer<'a>: RawHrTimerCallback;
/// Called by the timer logic when the timer fires.
- fn run(this: <Self::Pointer<'_> as RawHrTimerCallback>::CallbackTarget<'_>)
+ fn run(this: <Self::Pointer<'_> as RawHrTimerCallback>::CallbackTarget<'_>) -> HrTimerRestart
where
Self: Sized;
}
@@ -313,6 +313,23 @@ unsafe fn start(self_ptr: *const Self, expires: Ktime) {
}
}
+/// Restart policy for timers.
+pub enum HrTimerRestart {
+ /// Timer should not be restarted.
+ NoRestart,
+ /// Timer should be restarted.
+ Restart,
+}
+
+impl HrTimerRestart {
+ fn into_c(self) -> bindings::hrtimer_restart {
+ match self {
+ HrTimerRestart::NoRestart => bindings::hrtimer_restart_HRTIMER_NORESTART,
+ HrTimerRestart::Restart => bindings::hrtimer_restart_HRTIMER_RESTART,
+ }
+ }
+}
+
/// Use to implement the [`HasHrTimer<T>`] trait.
///
/// See [`module`] documentation for an example.
diff --git a/rust/kernel/time/hrtimer/arc.rs b/rust/kernel/time/hrtimer/arc.rs
index 5c916489fc13..7152fa414b37 100644
--- a/rust/kernel/time/hrtimer/arc.rs
+++ b/rust/kernel/time/hrtimer/arc.rs
@@ -87,8 +87,6 @@ impl<T> RawHrTimerCallback for Arc<T>
// timer. This `T` is contained in an `Arc`.
let receiver = unsafe { ArcBorrow::from_raw(data_ptr) };
- T::run(receiver);
-
- bindings::hrtimer_restart_HRTIMER_NORESTART
+ T::run(receiver).into_c()
}
}
--
2.47.0