[PATCH] rust: hrtimer: add active() method to query timer state

From: Andreas Hindborg

Date: Sun Feb 15 2026 - 15:30:10 EST


Add an `active()` method to HrTimer that returns true if the timer is in
the started or running states. This wraps the kernel's hrtimer_active()
function.

Also add documentation clarifying the definition of an active timer.

Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
---
rust/kernel/time/hrtimer.rs | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
index 856d2d929a008..b2272b059e504 100644
--- a/rust/kernel/time/hrtimer.rs
+++ b/rust/kernel/time/hrtimer.rs
@@ -66,6 +66,8 @@
//!
//! A `restart` operation on a timer in the **stopped** state is equivalent to a
//! `start` operation.
+//!
+//! A timer is **active** if it is either in the **started** or **running** states.

use super::{ClockSource, Delta, Instant};
use crate::{prelude::*, types::Opaque};
@@ -246,6 +248,14 @@ pub fn expires(&self) -> HrTimerInstant<T>
)
}
}
+
+ /// Query the state of the timer.
+ ///
+ /// Returns `true` if the timer is in the started or running states.
+ pub fn active(&self) -> bool {
+ // SAFETY: By type invariant, `self.timer` is valid.
+ unsafe { bindings::hrtimer_active(self.timer.get()) }
+ }
}

/// Implemented by pointer types that point to structs that contain a [`HrTimer`].

---
base-commit: 05f7e89ab9731565d8a62e3b5d1ec206485eeb0b
change-id: 20260215-hrtimer-active-f183411fe56b

Best regards,
--
Andreas Hindborg <a.hindborg@xxxxxxxxxx>