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.
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
rust/kernel/hrtimer.rs | 28 +++++++++++++++++++++++++++-
rust/kernel/hrtimer/arc.rs | 4 +---
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/rust/kernel/hrtimer.rs b/rust/kernel/hrtimer.rs
index 6427b0450c694105190c8cddea0c768ab195aca2..eeed2afd501b64b94d57cc658616659e28785078 100644
--- a/rust/kernel/hrtimer.rs
+++ b/rust/kernel/hrtimer.rs
@@ -176,7 +176,7 @@ pub trait TimerCallback {
type CallbackTargetParameter<'a>;
/// Called by the timer logic when the timer fires.
- fn run(this: Self::CallbackTargetParameter<'_>)
+ fn run(this: Self::CallbackTargetParameter<'_>) -> TimerRestart
where
Self: Sized;
}
@@ -270,6 +270,32 @@ unsafe fn start(self_ptr: *const Self, expires: Ktime) {
}
}
+/// Restart policy for timers.
+pub enum TimerRestart {
+ /// Timer should not be restarted.
+ NoRestart,
+ /// Timer should be restarted.
+ Restart,
+}
+
+impl From<u32> for TimerRestart {
+ fn from(value: bindings::hrtimer_restart) -> Self {
+ match value {
+ 0 => Self::NoRestart,
+ _ => Self::Restart,
+ }
+ }
+}
+
+impl From<TimerRestart> for bindings::hrtimer_restart {
+ fn from(value: TimerRestart) -> Self {
+ match value {
+ TimerRestart::NoRestart => bindings::hrtimer_restart_HRTIMER_NORESTART,
+ TimerRestart::Restart => bindings::hrtimer_restart_HRTIMER_RESTART,
+ }
+ }
+}
+
/// Use to implement the [`HasTimer<T>`] trait.
///
/// See [`module`] documentation for an example.
diff --git a/rust/kernel/hrtimer/arc.rs b/rust/kernel/hrtimer/arc.rs
index 881de053ecad866a26e46a0123ec2bf38511c2bc..c6283bd0dbb10dbc733c3f4092f107db2f3c5c5f 100644
--- a/rust/kernel/hrtimer/arc.rs
+++ b/rust/kernel/hrtimer/arc.rs
@@ -82,8 +82,6 @@ impl<U> RawTimerCallback for Arc<U>
// timer. This `U` is contained in an `Arc`.
let receiver = unsafe { ArcBorrow::from_raw(data_ptr) };
- U::run(receiver);
-
- bindings::hrtimer_restart_HRTIMER_NORESTART
+ U::run(receiver).into()
}
}
--
2.46.0