[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DBKQP426YEFZ.3EBGU020XKF3M@nvidia.com>
Date: Fri, 25 Jul 2025 10:20:08 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "Lyude Paul" <lyude@...hat.com>, <rust-for-linux@...r.kernel.org>,
"Thomas Gleixner" <tglx@...utronix.de>, "Boqun Feng"
<boqun.feng@...il.com>, <linux-kernel@...r.kernel.org>, "Andreas Hindborg"
<a.hindborg@...nel.org>, "FUJITA Tomonori" <fujita.tomonori@...il.com>
Cc: "Frederic Weisbecker" <frederic@...nel.org>, "Anna-Maria Behnsen"
<anna-maria@...utronix.de>, "John Stultz" <jstultz@...gle.com>, "Stephen
Boyd" <sboyd@...nel.org>, "Miguel Ojeda" <ojeda@...nel.org>, "Alex Gaynor"
<alex.gaynor@...il.com>, "Gary Guo" <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Benno Lossin"
<lossin@...nel.org>, "Alice Ryhl" <aliceryhl@...gle.com>, "Trevor Gross"
<tmgross@...ch.edu>, "Danilo Krummrich" <dakr@...nel.org>
Subject: Re: [PATCH 2/2] rust: time: Implement basic arithmetic operations
for Delta
On Fri Jul 25, 2025 at 3:54 AM JST, Lyude Paul wrote:
> While rvkms is only going to be using a few of these, since Deltas are
> basically the same as i64 it's easy enough to just implement all of the
> basic arithmetic operations for Delta types.
>
> Note that for division and remainders, we currently limit these operations
> to CONFIG_64BIT as u64 / u64 and u64 % u64 is not supported on all 32 bit
> platforms natively. The correct solution we want to aim for here in the
> future is to use the kernel's math library for performing these operations
> so they're emulated on 32 bit platforms.
>
> Signed-off-by: Lyude Paul <lyude@...hat.com>
> ---
> rust/kernel/time.rs | 86 +++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 86 insertions(+)
>
> diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
> index ac5cab62070c6..8ece5a5d5a11b 100644
> --- a/rust/kernel/time.rs
> +++ b/rust/kernel/time.rs
> @@ -251,6 +251,92 @@ pub struct Delta {
> nanos: i64,
> }
>
> +impl ops::Add for Delta {
> + type Output = Self;
> +
> + fn add(self, rhs: Self) -> Self {
> + Self {
> + nanos: self.nanos + rhs.nanos,
Should we use saturating ops here as well?
Powered by blists - more mailing lists