]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: hrtimer: allow timer restart from timer handler
authorAndreas Hindborg <a.hindborg@kernel.org>
Sun, 9 Mar 2025 15:18:55 +0000 (16:18 +0100)
committerAndreas Hindborg <a.hindborg@kernel.org>
Sat, 22 Mar 2025 11:08:54 +0000 (12:08 +0100)
Allow timer handlers to report that they want a timer to be restarted after
the timer handler has finished executing.

Acked-by: Frederic Weisbecker <frederic@kernel.org>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Tamir Duberstein <tamird@gmail.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Link: https://lore.kernel.org/r/20250309-hrtimer-v3-v6-12-rc2-v12-4-73586e2bd5f1@kernel.org
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
rust/kernel/time/hrtimer.rs
rust/kernel/time/hrtimer/arc.rs

index bfb536f2a4903e160be6d5c59c1fd874fa692f84..bc8f85cededbb94f2155c3659cec63a6bfe236b2 100644 (file)
@@ -212,7 +212,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;
 }
@@ -311,6 +311,24 @@ pub unsafe trait HasHrTimer<T> {
     }
 }
 
+/// Restart policy for timers.
+#[derive(Copy, Clone, PartialEq, Eq, Debug)]
+#[repr(u32)]
+pub enum HrTimerRestart {
+    /// Timer should not be restarted.
+    #[allow(clippy::unnecessary_cast)]
+    NoRestart = bindings::hrtimer_restart_HRTIMER_NORESTART as u32,
+    /// Timer should be restarted.
+    #[allow(clippy::unnecessary_cast)]
+    Restart = bindings::hrtimer_restart_HRTIMER_RESTART as u32,
+}
+
+impl HrTimerRestart {
+    fn into_c(self) -> bindings::hrtimer_restart {
+        self as bindings::hrtimer_restart
+    }
+}
+
 /// Use to implement the [`HasHrTimer<T>`] trait.
 ///
 /// See [`module`] documentation for an example.
index df97fade0aa12de07cc3189df01052d3df319d1a..4a984d85b4a1041ab1880c2377c39b2c6cb9e4cc 100644 (file)
@@ -95,8 +95,6 @@ where
         //    allocation from other `Arc` clones.
         let receiver = unsafe { ArcBorrow::from_raw(data_ptr) };
 
-        T::run(receiver);
-
-        bindings::hrtimer_restart_HRTIMER_NORESTART
+        T::run(receiver).into_c()
     }
 }