[PATCH v7 05/14] rust: hrtimer: allow timer restart from timer handler
From: Andreas Hindborg
Date: Mon Feb 03 2025 - 10:19:31 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.
Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
---
rust/kernel/time/hrtimer.rs | 28 +++++++++++++++++++++++++++-
rust/kernel/time/hrtimer/arc.rs | 4 +---
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
index 3494c00481a4bd25735edf44b6bdcbec9810243e..3ed7f5ee92fc5f9f4cc108c373ac40480f5307d1 100644
--- a/rust/kernel/time/hrtimer.rs
+++ b/rust/kernel/time/hrtimer.rs
@@ -183,7 +183,7 @@ pub trait HrTimerCallback {
type CallbackTargetParameter<'a>;
/// Called by the timer logic when the timer fires.
- fn run(this: Self::CallbackTargetParameter<'_>)
+ fn run(this: Self::CallbackTargetParameter<'_>) -> HrTimerRestart
where
Self: Sized;
}
@@ -278,6 +278,32 @@ 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 From<bindings::hrtimer_restart> for HrTimerRestart {
+ fn from(value: u32) -> Self {
+ match value {
+ bindings::hrtimer_restart_HRTIMER_NORESTART => Self::NoRestart,
+ _ => Self::Restart,
+ }
+ }
+}
+
+impl From<HrTimerRestart> for bindings::hrtimer_restart {
+ fn from(value: HrTimerRestart) -> Self {
+ match value {
+ 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 d1c90631d00362bdc38be1ccc75429ae294ab544..109eded0e73be853313abbe1a3540a5b1b8706d7 100644
--- a/rust/kernel/time/hrtimer/arc.rs
+++ b/rust/kernel/time/hrtimer/arc.rs
@@ -82,8 +82,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()
}
}
--
2.47.0