From: FUJITA Tomonori <tomo@flapping.org>
To: laura.nao@collabora.com
Cc: dakr@kernel.org, aliceryhl@google.com,
daniel.almeida@collabora.com, airlied@gmail.com, simona@ffwll.ch,
ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net,
bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, tmgross@umich.edu, tamird@kernel.org,
acourbot@nvidia.com, work@onurozkan.dev,
fujita.tomonori@gmail.com, frederic@kernel.org, lyude@redhat.com,
tglx@kernel.org, anna-maria@linutronix.de, jstultz@google.com,
sboyd@kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, driver-core@lists.linux.dev,
rust-for-linux@vger.kernel.org, kernel@collabora.com,
deborah.brouwer@collabora.com
Subject: Re: [PATCH 7/9] rust: time: add arch_timer_get_rate wrapper
Date: Tue, 22 Sep 2026 23:23:19 +0900 (JST) [thread overview]
Message-ID: <20260922.232319.1364383574405174986.tomo@flapping.org> (raw)
In-Reply-To: <20260915-tyr-interfaces-v1-7-5d28f1f75aca@collabora.com>
On Tue, 15 Sep 2026 12:57:40 +0200
Laura Nao <laura.nao@collabora.com> wrote:
> From: Deborah Brouwer <deborah.brouwer@collabora.com>
>
> Provide a safe Rust wrapper for arch_timer_get_rate().
>
> The Rust binding calls a C helper that returns 0 when the ARM
> architectural timer is not available or not yet initialized. Map this to
> Option<u32> to make the absence of a valid rate explicit to Rust callers.
>
> This allows Rust drivers to query the system timer frequency and
> select appropriate time sources when programming hardware timeouts.
>
> Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
> Signed-off-by: Laura Nao <laura.nao@collabora.com>
> ---
> rust/helpers/time.c | 6 ++++++
> rust/kernel/time.rs | 30 ++++++++++++++++++++++++++++++
> 2 files changed, 36 insertions(+)
(snip)
> +/// Returns the ARM architecture timer frequency in Hz, if available.
> +///
> +/// This function queries the system-wide ARM architecture timer frequency.
> +/// The architecture timer provides a consistent time source across all CPU cores.
> +///
> +/// Returns `None` if:
> +/// - The ARM architecture timer is not available (`CONFIG_ARM_ARCH_TIMER` not enabled)
> +/// - The timer rate is zero (not initialized)
> +///
> +/// # Examples
> +///
> +/// ```
> +/// use kernel::time::arch_timer_get_rate;
> +///
> +/// if let Some(rate) = arch_timer_get_rate() {
> +/// // Use `rate`.
> +/// }
> +/// ```
> +pub fn arch_timer_get_rate() -> Option<u32> {
> + // SAFETY: The C helper is available in all configs; it calls
> + // `arch_timer_get_rate()`, which falls back to an inline stub returning 0
> + // when CONFIG_ARM_ARCH_TIMER is disabled.
A SAFETY comment states why the unsafe call is sound. This one
explains why the helper is available in all configs.
How about:
// SAFETY: It is always safe to call `arch_timer_get_rate()`.
It just returns a variable without any lock. rust/kernel/time.rs
already does this for `ktime_get()` and `ktime_to_us()`.
> + let rate = unsafe { bindings::arch_timer_get_rate() };
> + if rate == 0 {
> + None
> + } else {
> + Some(rate)
> + }
> +}
> +
> impl Delta {
> /// A span of time equal to zero.
> pub const ZERO: Self = Self { value: 0 };
>
This puts the new function between `impl ops::Div for Delta` and
`impl Delta`, so it splits the `Delta` blocks.
`msecs_to_jiffies()` is the only other free function in this file and it
is at the top, next to the type aliases. Please put
`arch_timer_get_rate()` there,
next prev parent reply other threads:[~2026-09-22 14:23 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 10:57 [PATCH 0/9] drm/tyr: add CSF firmware interface support Laura Nao
2026-09-15 10:57 ` [PATCH 1/9] drm/tyr: validate presence of CSF shared section Laura Nao
2026-09-23 13:59 ` Daniel Almeida
2026-09-15 10:57 ` [PATCH 2/9] rust: io: drop the CONFIG_64BIT restriction on system memory u64 access Laura Nao
2026-09-15 11:18 ` Gary Guo
2026-09-21 10:06 ` Laura Nao
2026-09-15 10:57 ` [PATCH 3/9] drm/tyr: add MappedBo, a kernel BO with an always-valid CPU mapping Laura Nao
2026-09-23 20:43 ` Daniel Almeida
2026-09-15 10:57 ` [PATCH 4/9] drm/tyr: add McuVa and claim-checked MappedBo views Laura Nao
2026-09-23 20:42 ` Daniel Almeida
2026-09-15 10:57 ` [PATCH 5/9] drm/tyr: drop unused KernelBo::bo() function Laura Nao
2026-09-23 20:45 ` Daniel Almeida
2026-09-15 10:57 ` [PATCH 6/9] drm/tyr: add CSF firmware interface support Laura Nao
2026-09-15 10:57 ` [PATCH 7/9] rust: time: add arch_timer_get_rate wrapper Laura Nao
2026-09-22 12:57 ` Andreas Hindborg
2026-09-22 14:23 ` FUJITA Tomonori [this message]
2026-09-22 19:56 ` Gary Guo
2026-09-15 10:57 ` [PATCH 8/9] drm/tyr: program CSF global interface Laura Nao
2026-09-15 10:57 ` [PATCH 9/9] drm/tyr: wait for global interface readiness Laura Nao
2026-09-23 8:50 ` Alice Ryhl
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=20260922.232319.1364383574405174986.tomo@flapping.org \
--to=tomo@flapping.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=anna-maria@linutronix.de \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=deborah.brouwer@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=driver-core@lists.linux.dev \
--cc=frederic@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=jstultz@google.com \
--cc=kernel@collabora.com \
--cc=laura.nao@collabora.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=simona@ffwll.ch \
--cc=tamird@kernel.org \
--cc=tglx@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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®