From: Thomas Gleixner <tglx@linutronix.de>
To: "Asahi Lina" <lina@asahilina.net>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"John Stultz" <jstultz@google.com>,
"Stephen Boyd" <sboyd@kernel.org>
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
asahi@lists.linux.dev, Asahi Lina <lina@asahilina.net>
Subject: Re: [PATCH] rust: time: New module for timekeeping functions
Date: Tue, 21 Feb 2023 13:32:51 +0100 [thread overview]
Message-ID: <87v8jvnqq4.ffs@tglx> (raw)
In-Reply-To: <20230221-gpu-up-time-v1-1-bf8fe74b7f55@asahilina.net>
On Tue, Feb 21 2023 at 16:06, Asahi Lina wrote:
> +
> +use crate::bindings;
> +use core::time::Duration;
> +
> +/// Returns the kernel time elapsed since boot, excluding time spent sleeping, as a [`Duration`].
> +pub fn ktime_get() -> Duration {
> + // SAFETY: Function has no side effects and no inputs.
> + Duration::from_nanos(unsafe { bindings::ktime_get() }.try_into().unwrap())
Why is this a Duration? From the spec:
Duration
A Duration type to represent a span of time, typically used for
system timeouts.
Instant
A measurement of a monotonically nondecreasing clock. Opaque and
useful only with Duration.
In my understanding 'Duration' is a time span between two points, while
ktime_get() and ktime_get_boottime() return the current time of
monotonically nondecreasing clocks, i.e. they fall into the 'Instant'
category.
Now the problem is that 'Instant' in it's specification is bound to
CLOCK_MONOTONIC and there is no way to express CLOCK_BOOTTIME, but
that's a shortcoming of the spec which ignores CLOCK_BOOTTIME
completely. IOW, that's also a problem for user space.
This makes sense vs. the other representation:
SystemTime
A measurement of the system clock, useful for talking to
external entities like the file system or other processes.
This maps to CLOCK_REALTIME and CLOCK_TAI, i.e. ktime_get_real_ns() and
ktime_get_clocktai().
Similar to 'Instant' 'SystemTime' is strictly bound to CLOCK_REALTIME
by specification and there is no way to read CLOCK_TAI.
Please fix this in the spec and do not try to work around that by
pretending that a clock read is a 'Duration'.
> +}
> +
> +/// Returns the kernel time elapsed since boot, including time spent sleeping, as a [`Duration`].
> +pub fn ktime_get_boottime() -> Duration {
> + Duration::from_nanos(
> + // SAFETY: Function has no side effects and no variable inputs.
> + unsafe { bindings::ktime_get_with_offset(bindings::tk_offsets_TK_OFFS_BOOT) }
No. Please use ktime_get_boottime() and not the timekeeping internal function.
Thanks,
tglx
next prev parent reply other threads:[~2023-02-21 12:33 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-21 7:06 [PATCH] rust: time: New module for timekeeping functions Asahi Lina
2023-02-21 7:25 ` Eric Curtin
2023-02-21 11:23 ` Björn Roy Baron
2023-02-21 12:32 ` Thomas Gleixner [this message]
2023-02-21 14:06 ` Boqun Feng
2023-02-21 16:02 ` Thomas Gleixner
2023-02-21 16:31 ` Asahi Lina
2023-02-21 18:45 ` Thomas Gleixner
2023-02-21 21:33 ` Heghedus Razvan
2023-02-22 0:01 ` Thomas Gleixner
2023-02-22 19:55 ` Gary Guo
2023-02-21 22:29 ` Miguel Ojeda
2023-02-22 0:24 ` Thomas Gleixner
2023-02-22 2:54 ` Boqun Feng
2023-02-22 4:45 ` Asahi Lina
2023-02-22 5:20 ` Boqun Feng
2023-02-22 6:52 ` Heghedus Razvan
2023-02-22 12:29 ` Miguel Ojeda
2023-02-22 12:28 ` Miguel Ojeda
2023-02-21 16:27 ` Asahi Lina
2023-02-21 16:37 ` Asahi Lina
2023-02-21 19:00 ` Thomas Gleixner
2023-02-21 19:49 ` Boqun Feng
2023-02-22 4:56 ` Asahi Lina
2023-02-22 8:33 ` Thomas Gleixner
2023-02-21 17:13 ` Josh Stone
2023-02-21 21:46 ` Thomas Gleixner
2023-02-22 9:43 ` Gaelan Steele
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=87v8jvnqq4.ffs@tglx \
--to=tglx@linutronix.de \
--cc=alex.gaynor@gmail.com \
--cc=asahi@lists.linux.dev \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=jstultz@google.com \
--cc=lina@asahilina.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=wedsonaf@gmail.com \
/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