Re: [PATCH] rust: time: Seal the ClockSource trait

From: Boqun Feng
Date: Thu Jun 19 2025 - 09:40:58 EST


On Thu, Jun 19, 2025 at 02:57:12PM +0200, Andreas Hindborg wrote:
[...]
> >>
> >>
> >> pub trait ClockSource {
> >> /// The kernel clock ID associated with this clock source.
> >> ///
> >> /// This constant corresponds to the C side `clockid_t` value.
> >> const ID: bindings::clockid_t;
> >>
> >> The constant used to identify the clock source when calling into C APIs.
> >
> > Ah, I see. Sorry to ask another question, but can we require
> > correlation between ID and the value fetched by `ktime_get`?
>
> Yes, I think we should. As in, `ClockSource::ktime_get` must return the
> time associated with the clock specified by `ClockSource::ID`.
>
> >The value
> > fetched by ktime_get is opaque, isn't it?
>
> It is, but the implementation must still fetch the correct counter, right?
> Not sure if it could lead to UB if it did not though 🤷
>

The reason that we need ktime_get() to return value in [0, KTIME_MAX) is
because Instant's type invariants (and Instant's type invariants is for
subtraction not overflowing), so I would say this is not a safety
requirement for impl ClockSource.

Regards,
Boqun

>
> Best regards,
> Andreas Hindborg
>
>
>