From: Thomas Gleixner <tglx@linutronix.de>
To: Asahi Lina <lina@asahilina.net>, Boqun Feng <boqun.feng@gmail.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@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>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
asahi@lists.linux.dev
Subject: Re: [PATCH] rust: time: New module for timekeeping functions
Date: Tue, 21 Feb 2023 19:45:33 +0100 [thread overview]
Message-ID: <87edqioo1e.ffs@tglx> (raw)
In-Reply-To: <7b93bf74-abdc-f8c1-9a12-7c7f080f9e19@asahilina.net>
On Wed, Feb 22 2023 at 01:31, Asahi Lina wrote:
> On 22/02/2023 01.02, Thomas Gleixner wrote:
>> I'm not rusty enough, but you really want two types:
>>
>> timestamp and timedelta
>>
>> timestamp is an absolute time on a specific clock which is read via
>> now() and you can add time deltas to it. The latter is required for
>> arming an absolute timer on the clock.
>>
>> timedelta is a relative time and completely independent of any
>> clock. That's what you get when you subtract two timestamps, but you can
>> also initialize it from a constant or some other source. timedelta can
>> be used to arm a relative timer on any clock.
>
> If all clocks end up as the same `timestamp` though, then this isn't
> fully safe, because you could subtract `timestamp`s that came from
> different clocks and the result would be meaningless. That's why the
> Rust std Instant is specifically tied to one and only one system clock
> on each platform.
Fine, but do you agree that:
ts1 = tboot.now()
...
ts2 = tboot.now()
xb = ts2 - ts1
then the result x1 cannot be the same data type as ts1, ts2.
From a typesafety perspective
ts1 = treal.now()
...
ts2 = tboot.now()
x = ts2 - ts1
would be an invalid operation, but
ts1 = treal.now()
...
ts2 = treal.now()
xr = ts2 - ts1
is obviously valid.
But xb abd xr are the same datatype because they represent a time delta.
That's the same the Rust std time semantics:
Duration = Instance - Instance valid
Duration = Systemtime - SystemTime valid
Duration = Systemtime - Instance invalid
No?
Thanks,
tglx
next prev parent reply other threads:[~2023-02-21 18:45 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
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 [this message]
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=87edqioo1e.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