mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Daniel Brooks" <db48x@db48x.net>
Cc: "Danilo Krummrich" <dakr@kernel.org>,
	"David Airlie" <airlied@gmail.com>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Ben Skeggs" <bskeggs@nvidia.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Simona Vetter" <simona@ffwll.ch>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
	nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH RFC v3 6/7] gpu: nova-core: add basic timer device
Date: Fri, 21 Mar 2025 12:09:59 +0900	[thread overview]
Message-ID: <D8LM4KOZULK7.XUJ0HXIYZH71@nvidia.com> (raw)
In-Reply-To: <87v7s3zoha.fsf@db48x.net>

On Fri Mar 21, 2025 at 12:54 AM JST, Daniel Brooks wrote:
> Alexandre Courbot <acourbot@nvidia.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!

  reply	other threads:[~2025-03-21  3:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-20 13:39 [RFC PATCH v3 0/7] gpu: nova-core: register definitions and basic timer and falcon devices Alexandre Courbot
2025-03-20 13:39 ` [PATCH RFC v3 1/7] rust: add useful ops for u64 Alexandre Courbot
2025-03-20 13:39 ` [PATCH RFC v3 2/7] rust: make ETIMEDOUT error available Alexandre Courbot
2025-03-20 13:39 ` [PATCH RFC v3 3/7] gpu: nova-core: derive useful traits for Chipset Alexandre Courbot
2025-03-20 13:39 ` [PATCH RFC v3 4/7] gpu: nova-core: add missing GA100 definition Alexandre Courbot
2025-03-20 13:39 ` [PATCH RFC v3 5/7] gpu: nova-core: use register!() to define register layout Alexandre Courbot
2025-03-20 13:39 ` [PATCH RFC v3 6/7] gpu: nova-core: add basic timer device Alexandre Courbot
2025-03-20 15:54   ` Daniel Brooks
2025-03-21  3:09     ` Alexandre Courbot [this message]
2025-03-20 18:17   ` Boqun Feng
2025-03-21  5:41     ` Alexandre Courbot
2025-03-21 16:20       ` Daniel Brooks
2025-03-24  1:03         ` Alexandre Courbot
2025-03-20 13:39 ` [PATCH RFC v3 7/7] gpu: nova-core: add falcon register definitions and probe code Alexandre Courbot

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=D8LM4KOZULK7.XUJ0HXIYZH71@nvidia.com \
    --to=acourbot@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=airlied@gmail.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=bskeggs@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=db48x@db48x.net \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tmgross@umich.edu \
    /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

all inboxes | Powered by JetHome®