[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <D8LM4KOZULK7.XUJ0HXIYZH71@nvidia.com>
Date: Fri, 21 Mar 2025 12:09:59 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "Daniel Brooks" <db48x@...8x.net>
Cc: "Danilo Krummrich" <dakr@...nel.org>, "David Airlie"
<airlied@...il.com>, "John Hubbard" <jhubbard@...dia.com>, "Ben Skeggs"
<bskeggs@...dia.com>, "Miguel Ojeda" <ojeda@...nel.org>, "Alex Gaynor"
<alex.gaynor@...il.com>, "Boqun Feng" <boqun.feng@...il.com>, "Gary Guo"
<gary@...yguo.net>, Björn Roy Baron
<bjorn3_gh@...tonmail.com>, "Benno Lossin" <benno.lossin@...ton.me>,
"Andreas Hindborg" <a.hindborg@...nel.org>, "Alice Ryhl"
<aliceryhl@...gle.com>, "Trevor Gross" <tmgross@...ch.edu>, "Simona Vetter"
<simona@...ll.ch>, <linux-kernel@...r.kernel.org>,
<rust-for-linux@...r.kernel.org>, <nouveau@...ts.freedesktop.org>,
<dri-devel@...ts.freedesktop.org>
Subject: Re: [PATCH RFC v3 6/7] gpu: nova-core: add basic timer device
On Fri Mar 21, 2025 at 12:54 AM JST, Daniel Brooks wrote:
> Alexandre Courbot <acourbot@...dia.com> writes:
>
>> +impl Add<Duration> for Timestamp {
>> + type Output = Self;
>> +
>> + fn add(mut self, rhs: Duration) -> Self::Output {
>> + let mut nanos = rhs.as_nanos();
>> + while nanos > u64::MAX as u128 {
>> + self.0 = self.0.wrapping_add(nanos as u64);
>> + nanos -= u64::MAX as u128;
>> + }
>> +
>> + Timestamp(self.0.wrapping_add(nanos as u64))
>> + }
>> +}
>
> Perhaps I missed something, but couldn’t you simplify this method like
> this:
>
> fn add(mut self, rhs: Duration) -> Self::Output {
> let stamp = self.0 as u128;
> Timestamp(stamp.wrapping_add(rhs.as_nanos()) as u64)
> }
You are absolutely right, this loop will just wrap self.0 to the same value
after the initial pass.
... or at least it would if there weren't two bugs in it. >_<
- It adds the lower part of nanos while substracting u64::MAX from rhs,
which is completely wrong;
- Substracting u64::MAX is also wrong, it should be u64::MAX as u128 +
1.
So thanks a lot for pointing this out!
Powered by blists - more mailing lists