[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZgMOSQFZl3Hwev0Z@boqun-archlinux>
Date: Tue, 26 Mar 2024 11:04:57 -0700
From: Boqun Feng <boqun.feng@...il.com>
To: Benno Lossin <benno.lossin@...ton.me>
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
Thomas Gleixner <tglx@...utronix.de>,
Alice Ryhl <aliceryhl@...gle.com>, 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>,
Andreas Hindborg <a.hindborg@...sung.com>,
John Stultz <jstultz@...gle.com>, Stephen Boyd <sboyd@...nel.org>,
Valentin Obst <kernel@...entinobst.de>,
Heghedus Razvan <heghedus.razvan@...tonmail.com>,
Asahi Lina <lina@...hilina.net>
Subject: Re: [PATCH 5/5] rust: time: Add Instant::elapsed() for monotonic
clocks
On Tue, Mar 26, 2024 at 11:00:52AM -0700, Boqun Feng wrote:
[...]
> >
> > Now that I thought a bit more about the design, I think allowing
> > negative durations is a bad idea.
> > Do you disagree?
> >
>
> So yes, I don't think allowing negative duration is really good design.
> But as I mentioned in the cover letter, I hope to support cases where:
>
> d = ts2 - ts1;
> ts = ts3 + d;
>
> (where ts1, ts2, ts3 is Instant, and d is of course Duration)
>
> without any branch instruction in the asm code. It's useful in the case
To be accurate, the "ts = ts3 + d" can have (and should have) a branch
to check overflows (and reset to KTIME_MAX if so), but that's the only
branch.
Regards,
Boqun
> where ts1 is a old time base, and ts3 is the new one, and you want to
> "remain" the delta between ts2 and t1 and apply that on ts3. To me there
> are three options to achieve that: 1) allow negative durations (this
> also mirrors what `ktime_t` represents for timedelta AKAIU), 2) have
> a timedelta type that differs from Duration, and it can be negative, 3)
> provide a function to do the above calculation for `Instant`. I choose
> the first one because it's quick and simple (also easy to map to
> `ktime_t`). But I don't have my own preference on these three options.
>
> Regards,
> Boqun
>
> > If there is a case where you have a non-monotonic clock, or you are not
> > sure if two timestamps are in the correct relation, we could have a
> > function that returns a `Option<Duration>` or `Result<Duration>`.
> >
> > --
> > Cheers,
> > Benno
> >
> > > + /// ```
> > > + pub fn elapsed(&self) -> Duration {
> > > + T::now() - *self
> > > + }
> > > +}
> > > +
> > > /// Contains the various clock source types available to the kernel.
> > > pub mod clock {
> > > use super::*;
> > > --
> > > 2.44.0
> > >
Powered by blists - more mailing lists