Skip to content

Commit 15f00c3

Browse files
Andreas Hindborgfbq
authored andcommitted
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. Acked-by: Frederic Weisbecker <frederic@kernel.org> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org> Link: https://lore.kernel.org/r/20250224-hrtimer-v3-v6-12-rc2-v9-4-5bd3bf0ce6cc@kernel.org
1 parent 0488f53 commit 15f00c3

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

rust/kernel/time/hrtimer.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub trait HrTimerCallback {
207207
type Pointer<'a>: RawHrTimerCallback;
208208

209209
/// Called by the timer logic when the timer fires.
210-
fn run(this: <Self::Pointer<'_> as RawHrTimerCallback>::CallbackTarget<'_>)
210+
fn run(this: <Self::Pointer<'_> as RawHrTimerCallback>::CallbackTarget<'_>) -> HrTimerRestart
211211
where
212212
Self: Sized;
213213
}
@@ -313,6 +313,23 @@ pub unsafe trait HasHrTimer<T> {
313313
}
314314
}
315315

316+
/// Restart policy for timers.
317+
pub enum HrTimerRestart {
318+
/// Timer should not be restarted.
319+
NoRestart,
320+
/// Timer should be restarted.
321+
Restart,
322+
}
323+
324+
impl HrTimerRestart {
325+
fn into_c(self) -> bindings::hrtimer_restart {
326+
match self {
327+
HrTimerRestart::NoRestart => bindings::hrtimer_restart_HRTIMER_NORESTART,
328+
HrTimerRestart::Restart => bindings::hrtimer_restart_HRTIMER_RESTART,
329+
}
330+
}
331+
}
332+
316333
/// Use to implement the [`HasHrTimer<T>`] trait.
317334
///
318335
/// 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
@@ -87,8 +87,6 @@ where
8787
// timer. This `T` is contained in an `Arc`.
8888
let receiver = unsafe { ArcBorrow::from_raw(data_ptr) };
8989

90-
T::run(receiver);
91-
92-
bindings::hrtimer_restart_HRTIMER_NORESTART
90+
T::run(receiver).into_c()
9391
}
9492
}

0 commit comments

Comments
 (0)