Re: [PATCH net-next v2 3/6] rust: time: Implement addition of Ktime and Delta

From: Alice Ryhl
Date: Mon Oct 07 2024 - 10:25:04 EST


On Mon, Oct 7, 2024 at 8:17 AM FUJITA Tomonori
<fujita.tomonori@xxxxxxxxx> wrote:
>
> On Sat, 5 Oct 2024 20:36:44 +0200
> Miguel Ojeda <miguel.ojeda.sandonis@xxxxxxxxx> wrote:
>
> > On Sat, Oct 5, 2024 at 2:26 PM FUJITA Tomonori
> > <fujita.tomonori@xxxxxxxxx> wrote:
> >>
> >> + fn add(self, delta: Delta) -> Ktime {
> >> + // SAFETY: FFI call.
> >> + let t = unsafe { bindings::ktime_add_ns(self.inner, delta.as_nanos() as u64) };
> >> + Ktime::from_raw(t)
> >> + }
> >
> > I wonder if we want to use the `ktime` macros/operations for this type
> > or not (even if we still promise it is the same type underneath). It
> > means having to define helpers, adding `unsafe` code and `SAFETY`
> > comments, a call penalty in non-LTO, losing overflow checking (if we
> > want it for these types), and so on.
>
> Yeah, if we are allowed to touch ktime_t directly instead of using the
> accessors, it's great for the rust side.
>
> The timers maintainers, what do you think?

We already do that in the existing code. The Ktime::sub method touches
the ktime_t directly and performs a subtraction using the - operator
rather than call a ktime_ method for it.

Alice