Commit 94e05a66 authored by Andreas Hindborg's avatar Andreas Hindborg
Browse files

rust: hrtimer: allow timer restart from timer handler



Allow timer handlers to report that they want a timer to be restarted after
the timer handler has finished executing.

Acked-by: default avatarFrederic Weisbecker <frederic@kernel.org>
Acked-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarBenno Lossin <benno.lossin@proton.me>
Reviewed-by: default avatarTamir Duberstein <tamird@gmail.com>
Reviewed-by: default avatarLyude Paul <lyude@redhat.com>
Link: https://lore.kernel.org/r/20250309-hrtimer-v3-v6-12-rc2-v12-4-73586e2bd5f1@kernel.org


Signed-off-by: default avatarAndreas Hindborg <a.hindborg@kernel.org>
parent d7bf4786
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -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 @@ unsafe fn start(this: *const Self, expires: Ktime) {
    }
}

/// 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.
+1 −3
Original line number Diff line number Diff line
@@ -95,8 +95,6 @@ impl<T> RawHrTimerCallback for Arc<T>
        //    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()
    }
}