Re: [PATCH v4 19/20] rust: time: add arch_timer_get_rate wrapper

From: Deborah Brouwer

Date: Mon Apr 27 2026 - 19:35:31 EST


On Mon, Apr 27, 2026 at 09:42:52AM +0200, Andreas Hindborg wrote:
> "Deborah Brouwer" <deborah.brouwer@xxxxxxxxxxxxx> writes:
>
> > Provide a safe Rust wrapper for arch_timer_get_rate().
> >
> > The underlying C helper 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@xxxxxxxxxxxxx>
>
> Looks good to me, but it is weird that this is defined for non-arm targets.
>
> Even if this is available for all architectures in C code, would it make
> sense to gate it on the target being Arm in Rust?

In Tyr, I’m calling time::arch_timer_get_rate() unconditionally and using
it as an optional source (falling back to the GPU timer when it is not available).
If we gated the Rust API on ARM targets, that would require adding
target-specific cfgs at each call site or break non-ARM builds.

Since the API already models absence as None, my thinking was to keep it available
on all targets and let callers fall back, as Tyr does with the GPU clock.

>
>
> Best regards,
> Andreas Hindborg
>