NVIDIA GPU driver infrastructure
 help / color / mirror / Atom feed
From: "Eliot Courtney" <ecourtney@nvidia.com>
To: "Alexandre Courbot" <acourbot@nvidia.com>,
	"Eliot Courtney" <ecourtney@nvidia.com>
Cc: "Alice Ryhl" <aliceryhl@google.com>,
	"Burak Emir" <burak.emir@gmail.com>,
	"Yury Norov" <yury.norov@gmail.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Onur Özkan" <work@onurozkan.dev>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>, "Zhi Wang" <zhiw@nvidia.com>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
	dri-devel <dri-devel-bounces@lists.freedesktop.org>
Subject: Re: [PATCH v12 2/2] gpu: nova-core: add ChannelIdPool
Date: Tue, 17 Nov 2026 23:09:18 +0900	[thread overview]
Message-ID: <DMXJNIU3BIOR.3K9YLK44LPFDY@nvidia.com> (raw)
In-Reply-To: <DMXJHYY9ZTRO.3G2LTK1PPDIV7@nvidia.com>

On Tue Nov 17, 2026 at 11:02 PM JST, Alexandre Courbot wrote:
> On Thu Nov 12, 2026 at 9:37 PM JST, Eliot Courtney wrote:
>> Add `ChannelIdPool` which adds automatic tracking and releasing of
>> channel IDs on top of `IdPool`. This is necessary for apportioning
>> ranges of channel IDs to be used in e.g. vGPU.
>>
>> Channel IDs are allocated as a contiguous sequence with a specific
>> length and sometimes a specific alignment [1] for vGPU. The ID space is
>> small (limited to 2048) and allocation is not on a hot path, so a
>> bitmap-backed `IdPool` is a better fit than IDA/xarray (which allocate a
>> single ID within a range, not a contiguous sequence) or a maple tree
>> (where aligned allocation needs an alloc_range()+erase() retry loop that
>> essentially reimplements bitmap_find_next_zero_area()) [2]. It is
>> also faster than maple tree [3].
>>
>> Link: https://lore.kernel.org/all/84bc8bd2-e292-4b84-9580-a1b5df4c5bdc@nvidia.com/ # [1]
>> Link: https://lore.kernel.org/all/20260710-chid-maple-v1-1-4ee869055268@nvidia.com/ # [2]
>> Link: https://lore.kernel.org/all/20260717053241.916441-1-ynorov@nvidia.com/ # [3]
>> Reviewed-by: Alice Ryhl <aliceryhl@google.com>
>> Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
>
> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
>
> This series looks ready to apply, but one question below:
>
>> +#[kunit_tests(nova_core_channel)]
>> +mod tests {
>> +    use super::*;
>> +    use kernel::sizes::SizeConstants;
>> +
>> +    #[test]
>> +    fn chid_reservation() -> Result {
>> +        let pool = KBox::pin_init(ChannelIdPool::new(cv!(2048)), GFP_KERNEL)?;
>> +
>> +        let first = pool.reserve_ids(cv!(48), Alignment::SZ_1)?;
>> +        assert_eq!(0, first.start);
>> +        assert_eq!(48, first.len());
>> +        assert_eq!(48, first.end);
>
> I could simplify this into
>
>     assert_eq!(0..48, *first);
>
>> +
>> +        let second = pool.reserve_ids(cv!(48), Alignment::SZ_1)?;
>> +        assert!(first.end <= second.start || second.end <= first.start);
>> +
>> +        let first_start = first.start;
>> +        drop(first);
>> +        assert_eq!(
>> +            first_start,
>> +            pool.reserve_ids(cv!(48), Alignment::SZ_1)?.start
>> +        );
>> +        Ok(())
>> +    }
>> +
>> +    #[test]
>> +    fn chid_reservation_drop() -> Result {
>> +        let pool = KBox::pin_init(ChannelIdPool::new(cv!(8)), GFP_KERNEL)?;
>> +
>> +        let a = pool.reserve_ids(cv!(3), Alignment::SZ_1)?;
>> +        let b = pool.reserve_ids(cv!(3), Alignment::SZ_1)?;
>> +        let c = pool.reserve_ids(cv!(2), Alignment::SZ_1)?;
>> +        assert_eq!(0, a.start);
>> +        assert_eq!(3, b.start);
>> +        assert_eq!(6, c.start);
>
> And these ones into:
>
>     assert_eq!(0..3, *a);
>     assert_eq!(3..6, *b);
>     assert_eq!(6..8, *c);
>
> Most of the tests could be changed to be done on ranges, which have the
> benefit of checking the first and last indices, as well as the length in
> one go and provide better coverage. I have done the change locally and
> checked that it worked. Would you be ok if I converted all the relevant
> `assert_eq!` statements upon applying?

Yes absolutely no worries. Thanks!

      reply	other threads:[~2026-11-17 14:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 12:37 [PATCH v12 0/2] rust: Add support for reserving of ranges of IDs Eliot Courtney
2026-11-12 12:37 ` [PATCH v12 1/2] rust: id_pool: do not round capacity up to BitmapVec::MAX_INLINE_LEN Eliot Courtney
2026-11-12 12:37 ` [PATCH v12 2/2] gpu: nova-core: add ChannelIdPool Eliot Courtney
2026-11-17 14:02   ` Alexandre Courbot
2026-11-17 14:09     ` Eliot Courtney [this message]

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=DMXJNIU3BIOR.3K9YLK44LPFDY@nvidia.com \
    --to=ecourtney@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=burak.emir@gmail.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel-bounces@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nova-gpu@lists.linux.dev \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    --cc=work@onurozkan.dev \
    --cc=yury.norov@gmail.com \
    --cc=zhiw@nvidia.com \
    /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