From: "Gary Guo" <gary@garyguo.net>
To: "Andreas Hindborg" <a.hindborg@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"FUJITA Tomonori" <fujita.tomonori@gmail.com>,
"Frederic Weisbecker" <frederic@kernel.org>,
"Lyude Paul" <lyude@redhat.com>,
"Thomas Gleixner" <tglx@kernel.org>,
"Anna-Maria Behnsen" <anna-maria@linutronix.de>,
"John Stultz" <jstultz@google.com>,
"Stephen Boyd" <sboyd@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>
Cc: <rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] rust: hrtimer: add active() method to query timer state
Date: Fri, 27 Feb 2026 14:23:40 +0000 [thread overview]
Message-ID: <DGPT98PHCRJK.24W50V2JKRE8K@garyguo.net> (raw)
In-Reply-To: <20260215-hrtimer-active-v1-1-a754d10492c2@kernel.org>
On Sun Feb 15, 2026 at 8:29 PM GMT, Andreas Hindborg wrote:
> 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@kernel.org>
> ---
> 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.
This could be `#[inline]`.
> + pub fn active(&self) -> bool {
> + // SAFETY: By type invariant, `self.timer` is valid.
Perhaps also mention that this function is safe to call without exclusive
requirement, as this is a common requiremnt for many other hrtimer functions.
Best,
Gary
> + 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,
next prev parent reply other threads:[~2026-02-27 14:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-15 20:29 Andreas Hindborg
2026-02-15 20:59 ` Miguel Ojeda
2026-02-28 2:22 ` FUJITA Tomonori
2026-02-28 3:04 ` Miguel Ojeda
2026-02-28 4:57 ` FUJITA Tomonori
2026-03-01 11:31 ` Alice Ryhl
2026-02-27 14:23 ` Gary Guo [this message]
2026-02-28 4:57 ` FUJITA Tomonori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DGPT98PHCRJK.24W50V2JKRE8K@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=anna-maria@linutronix.de \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=frederic@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=tglx@kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®