From: Andreas Hindborg <a.hindborg@kernel.org>
To: "Lyude Paul" <lyude@redhat.com>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
"Boqun Feng" <boqun.feng@gmail.com>,
"Frederic Weisbecker" <frederic@kernel.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Anna-Maria Behnsen" <anna-maria@linutronix.de>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>
Subject: Re: [PATCH 6/6] rust: hrtimer: Add HrTimerCallback::expires()
Date: Tue, 08 Apr 2025 14:16:11 +0200 [thread overview]
Message-ID: <8734eij1bo.fsf@kernel.org> (raw)
In-Reply-To: <20250402214109.653341-7-lyude@redhat.com> (Lyude Paul's message of "Wed, 02 Apr 2025 17:40:34 -0400")
"Lyude Paul" <lyude@redhat.com> writes:
> This adds the ability to read the expiry time of the current timer from the
> HrTimerCallbackContext.
>
> Signed-off-by: Lyude Paul <lyude@redhat.com>
> ---
> rust/kernel/time/hrtimer.rs | 29 +++++++++++++++++++++++++++--
> 1 file changed, 27 insertions(+), 2 deletions(-)
>
> diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
> index d52cbb6cfc57f..e28b7895d8f37 100644
> --- a/rust/kernel/time/hrtimer.rs
> +++ b/rust/kernel/time/hrtimer.rs
> @@ -69,7 +69,7 @@
>
> use super::ClockId;
> use crate::{init::PinInit, prelude::*, time::Ktime, types::Opaque};
> -use core::{marker::PhantomData, ptr::NonNull};
> +use core::{marker::PhantomData, ptr::{NonNull, addr_of}};
>
> /// A timer backed by a C `struct hrtimer`.
> ///
> @@ -131,7 +131,7 @@ unsafe fn raw_get(this: *const Self) -> *mut bindings::hrtimer {
> // SAFETY: The field projection to `timer` does not go out of bounds,
> // because the caller of this function promises that `this` points to an
> // allocation of at least the size of `Self`.
> - unsafe { Opaque::raw_get(core::ptr::addr_of!((*this).timer)) }
> + unsafe { Opaque::raw_get(addr_of!((*this).timer)) }
> }
>
> /// Cancel an initialized and potentially running timer.
> @@ -163,6 +163,31 @@ pub(crate) unsafe fn raw_cancel(this: *const Self) -> bool {
> // handled on the C side.
> unsafe { bindings::hrtimer_cancel(c_timer_ptr) != 0 }
> }
> +
> + /// Return the time expiry for the given timer pointer.
> + ///
> + /// This value should only be used as a snapshot, as the actual expiry time could change after
> + /// this function is called.
> + ///
> + /// # Safety
> + ///
> + /// `self_ptr` must point to a valid `Self`.
> + unsafe fn raw_expires(self_ptr: *const Self) -> Ktime {
> + // SAFETY: self_ptr points to an allocation of at least `HrTimer` size.
> + let c_timer_ptr = unsafe { HrTimer::raw_get(self_ptr) };
> +
> + // SAFETY: There's no actual locking here, a racy read is fine and expected.
> + Ktime::from_raw(unsafe { core::ptr::read(addr_of!((*c_timer_ptr).node.expires)) })
From what I have picked up about racy reads lately, this should probably
be a `read_once` when we get that. For now you should use
`core::ptr::read_volatile` with a `FIXME(read_volatile)`.
Best regards,
Andreas Hindborg
next prev parent reply other threads:[~2025-04-08 12:16 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <f6qilrOyPKqI41LxEG6tS9lHm1gKZ1uxYBqonJEDGUzfNeg7JTLx0ygMtZCymEQv07RW8nGgFqhspMslAh8hAg==@protonmail.internalid>
2025-04-02 21:40 ` [PATCH 0/6] rust/hrtimer: Various hrtimer + time additions Lyude Paul
2025-04-02 21:40 ` [PATCH 1/6] rust: time: Add Ktime::from_ns() Lyude Paul
2025-04-02 21:40 ` [PATCH 2/6] rust: hrtimer: Add HrTimerCallbackContext and ::forward() Lyude Paul
2025-04-03 11:25 ` Thomas Gleixner
2025-04-08 11:47 ` Andreas Hindborg
2025-04-08 21:55 ` Lyude Paul
2025-04-09 7:49 ` Andreas Hindborg
2025-04-09 16:58 ` Lyude Paul
2025-04-09 17:15 ` Lyude Paul
2025-04-10 6:21 ` Andreas Hindborg
2025-04-11 20:48 ` Lyude Paul
2025-04-02 21:40 ` [PATCH 3/6] rust: hrtimer: Add HrTimerClockBase Lyude Paul
2025-04-08 11:58 ` Andreas Hindborg
2025-04-02 21:40 ` [PATCH 4/6] rust: hrtimer: Add HrTimerClockBase::time() Lyude Paul
2025-04-08 12:00 ` Andreas Hindborg
2025-04-09 18:39 ` Lyude Paul
2025-04-02 21:40 ` [PATCH 5/6] rust: hrtimer: Add HrTimerCallbackContext::forward_now() Lyude Paul
2025-04-08 12:05 ` Andreas Hindborg
2025-04-02 21:40 ` [PATCH 6/6] rust: hrtimer: Add HrTimerCallback::expires() Lyude Paul
2025-04-08 12:16 ` Andreas Hindborg [this message]
2025-04-08 11:51 ` [PATCH 0/6] rust/hrtimer: Various hrtimer + time additions Andreas Hindborg
2025-04-08 21:47 ` Lyude Paul
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=8734eij1bo.fsf@kernel.org \
--to=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=anna-maria@linutronix.de \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=frederic@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tglx@linutronix.de \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.