mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andreas Hindborg <a.hindborg@kernel.org>
To: FUJITA Tomonori <tomo@flapping.org>
Cc: mike@fireburn.co.uk, rust-for-linux@vger.kernel.org,
	boqun@kernel.org, fujita.tomonori@gmail.com, frederic@kernel.org,
	lyude@redhat.com, tglx@kernel.org, anna-maria@linutronix.de,
	jstultz@google.com, sboyd@kernel.org, ojeda@kernel.org,
	gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org,
	aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org,
	daniel.almeida@collabora.com, tamird@kernel.org,
	acourbot@nvidia.com, work@onurozkan.dev,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 9/9] rust: time: add ktime_get_real_seconds
Date: Tue, 08 Sep 2026 15:01:16 +0200	[thread overview]
Message-ID: <87h5jzx5gj.fsf@t14s.mail-host-address-is-not-set> (raw)
In-Reply-To: <20260908.201400.2113025819273270637.tomo@flapping.org>

FUJITA Tomonori <tomo@flapping.org> writes:

> On Thu, 27 Aug 2026 15:39:53 +0200
> Andreas Hindborg <a.hindborg@kernel.org> wrote:
>
>> "Mike Lothian" <mike@fireburn.co.uk> writes:
>> 
>>> Reading an `Instant<RealTime>` is the wrong tool for a caller that only
>>> wants a calendar time in seconds: it takes a full nanosecond timestamp and
>>> then needs a 64-bit division to get back to what the timekeeping core
>>> already maintains as a plain seconds field.
>>>
>>> Wrap `ktime_get_real_seconds()`, which is that field. Document the property
>>> that matters at the call site and that the type cannot express: the value
>>> follows CLOCK_REALTIME, so it is not monotonic and can move in either
>>> direction.
>> 
>> We recently added the concept of `TimeUnit`. For now it is exposed via
>> `Delta<U: TimeUnit>`. We could extend this to `Instant` as well to have
>> a seconds based `Instant`.
>
> I don't think that is a good idea.
>
> `Instant` is a point in time that exists to produce a `Delta`: `now()` is its
> only constructor,

`Instant` is a point in time. `ktime_get_real_seconds` return a point in
time. Whether the constructor is `Delta::now` or should be
`Instant::now` could be discussed.

> and what you do with it is `elapsed()`

I don't see the issue with `Instant<RealSeconds>::elapsed()`. You would
get a duration of seconds that has elapsed since the instant? Of course
you get all the inaccuracy that comes with using seconds resolution.

> or `Instant -
> Instant`.

Same.

> So a seconds based `Instant` has to define what `Instant - Instant`
> returns,

A `Delta<Seconds>` would be the obvious choice? I perfer `Seconds` and
`NanoSeconds`, but the abbreviated pattern is already prevalent, so
probably best to go with that.

> and `Delta<Sec>` would have no consumer.

True, but OK I guess.

> Every interface that takes a
> span takes a `Delta<Nsec>`: `fsleep()`, `udelay()`, `HrTimer::forward()`,
> `read_poll_timeout()`.

That is fine. Those APIs do not have to take `Delta<Seconds>`, they can
keep taking `Delta<Nsec>`

> `Delta` also already treats seconds as an input format
> rather than a unit, since `Delta::from_secs()` returns a
> `Delta<Nsec>`.

That is fine. In the context of `Delta::from_secs` the argument is a
duration. `Instant<Seconds>` is a logically different concept. It is a
point in time, not a duration.

> That is
> the difference from `Delta<Jiffy>`, which earned a type because the C side takes
> jiffies at the boundary and the conversion is lossy; `time64_t` is an `i64` and
> seconds to nanoseconds is exact.

Yes, we made `Delta<Jiffy>` from a need to pass a jiffy based duration
to C code. That should not prevent us from having a seconds based `Instant`.

If you are concerned about the dead code in a seconds based `Delta`, we
can gate the impls.

> And that is not how `ktime_get_real_seconds()` is used in the first place. Its
> callers need a calendar value in seconds because something outside the kernel
> fixes the format: an on-disk field, a value passed to firmware, or a userspace
> ABI field. Many of them compare it against an expiry time that came from the
> wire or from disk.

Again, sure, that is why we originally introduced these types. But I
don't think we should gate our time representing types on the rationale
of the first use case. We should represent points in time and duration
of time with a single set of types.

> Does that make sense?

I think I understand your concern, but I do not share it.

I would appreciate others to chime in on this - in either direction. How
should we represent time in general.


Best regards,
Andreas Hindborg


  reply	other threads:[~2026-09-08 13:01 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260826162851.2497-1-mike@fireburn.co.uk>
2026-08-26 16:28 ` [PATCH 1/9] rust: sync: completion: add single-shot and timed operations Mike Lothian
2026-08-26 16:28 ` [PATCH 2/9] rust: hrtimer: add ArcHrTimerHandle::restart Mike Lothian
2026-08-27 13:27   ` Andreas Hindborg
     [not found]     ` <3-IkUMhanJhClxwXLNvuF1-ncsHt6uM6GRmW78t81tKgo_5IO80fRJ9HZROE5RwlmxZhufdPXswcExj5j65ejw==@protonmail.internalid>
     [not found]       ` <CAHbf0-F-KNQu5NrFcUw1JOwaVQJq5hS+d9OHTmV3J2Pi+hfOqA@mail.gmail.com>
2026-08-31 16:54         ` Andreas Hindborg
2026-09-02 12:49           ` Mike Lothian
2026-08-26 16:28 ` [PATCH 3/9] rust: random: add a safe get_random_bytes wrapper Mike Lothian
2026-08-26 16:28 ` [PATCH 4/9] rust: xxhash: add a safe xxh64 wrapper Mike Lothian
2026-08-26 16:28 ` [PATCH 5/9] rust: workqueue: make OwnedQueue thread-safe Mike Lothian
2026-08-26 16:28 ` [PATCH 6/9] rust: io: add checked offset copy helpers Mike Lothian
2026-08-26 16:28 ` [PATCH 7/9] rust: hrtimer: expose interrupt state in hard callbacks Mike Lothian
2026-08-27 13:34   ` Andreas Hindborg
2026-08-26 16:28 ` [PATCH 8/9] rust: error: expose EPROTO Mike Lothian
2026-08-26 16:34   ` Miguel Ojeda
2026-08-26 16:28 ` [PATCH 9/9] rust: time: add ktime_get_real_seconds Mike Lothian
2026-08-27 13:39   ` Andreas Hindborg
2026-09-08 11:14     ` FUJITA Tomonori
2026-09-08 13:01       ` Andreas Hindborg [this message]
2026-10-30  7:57         ` Mike Lothian
2026-10-30 10:05           ` FUJITA Tomonori
2026-10-30 18:59             ` Boqun Feng
2026-10-31  0:39               ` FUJITA Tomonori
2026-09-08 11:19   ` FUJITA Tomonori

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=87h5jzx5gj.fsf@t14s.mail-host-address-is-not-set \
    --to=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.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=frederic@kernel.org \
    --cc=fujita.tomonori@gmail.com \
    --cc=gary@garyguo.net \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=lyude@redhat.com \
    --cc=mike@fireburn.co.uk \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tamird@kernel.org \
    --cc=tglx@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=tomo@flapping.org \
    --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®