[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87edqioo1e.ffs@tglx>
Date: Tue, 21 Feb 2023 19:45:33 +0100
From: Thomas Gleixner <tglx@...utronix.de>
To: Asahi Lina <lina@...hilina.net>, Boqun Feng <boqun.feng@...il.com>
Cc: Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Wedson Almeida Filho <wedsonaf@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
John Stultz <jstultz@...gle.com>,
Stephen Boyd <sboyd@...nel.org>, linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org, asahi@...ts.linux.dev
Subject: Re: [PATCH] rust: time: New module for timekeeping functions
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
Powered by blists - more mailing lists