Skip to content

Commit 94e05a6

Browse files
author
Andreas Hindborg
committed
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: Frederic Weisbecker <[email protected]> Acked-by: Thomas Gleixner <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Reviewed-by: Tamir Duberstein <[email protected]> Reviewed-by: Lyude Paul <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Andreas Hindborg <[email protected]>
1 parent d7bf478 commit 94e05a6

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

rust/kernel/time/hrtimer.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ pub trait HrTimerCallback {
212212
type Pointer<'a>: RawHrTimerCallback;
213213

214214
/// Called by the timer logic when the timer fires.
215-
fn run(this: <Self::Pointer<'_> as RawHrTimerCallback>::CallbackTarget<'_>)
215+
fn run(this: <Self::Pointer<'_> as RawHrTimerCallback>::CallbackTarget<'_>) -> HrTimerRestart
216216
where
217217
Self: Sized;
218218
}
@@ -311,6 +311,24 @@ pub unsafe trait HasHrTimer<T> {
311311
}
312312
}
313313

314+
/// Restart policy for timers.
315+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
316+
#[repr(u32)]
317+
pub enum HrTimerRestart {
318+
/// Timer should not be restarted.
319+
#[allow(clippy::unnecessary_cast)]
320+
NoRestart = bindings::hrtimer_restart_HRTIMER_NORESTART as u32,
321+
/// Timer should be restarted.
322+
#[allow(clippy::unnecessary_cast)]
323+
Restart = bindings::hrtimer_restart_HRTIMER_RESTART as u32,
324+
}
325+
326+
impl HrTimerRestart {
327+
fn into_c(self) -> bindings::hrtimer_restart {
328+
self as bindings::hrtimer_restart
329+
}
330+
}
331+
314332
/// Use to implement the [`HasHrTimer<T>`] trait.
315333
///
316334
/// See [`module`] documentation for an example.

rust/kernel/time/hrtimer/arc.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ where
9595
// allocation from other `Arc` clones.
9696
let receiver = unsafe { ArcBorrow::from_raw(data_ptr) };
9797

98-
T::run(receiver);
99-
100-
bindings::hrtimer_restart_HRTIMER_NORESTART
98+
T::run(receiver).into_c()
10199
}
102100
}

0 commit comments

Comments
 (0)