[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241017-hrtimer-v3-v6-12-rc2-v3-5-59a75cbb44da@kernel.org>
Date: Thu, 17 Oct 2024 15:04:32 +0200
From: Andreas Hindborg <a.hindborg@...nel.org>
To: Miguel Ojeda <ojeda@...nel.org>,
Anna-Maria Behnsen <anna-maria@...utronix.de>,
Frederic Weisbecker <frederic@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>
Cc: Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>, Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>, Lyude Paul <lyude@...hat.com>,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
Andreas Hindborg <a.hindborg@...nel.org>
Subject: [PATCH v3 05/13] rust: hrtimer: allow timer restart from timer
handler
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@...nel.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
Powered by blists - more mailing lists