Re: [PATCH v12 2/2] gpu: nova-core: add ChannelIdPool
From: Eliot Courtney
Date: Tue Nov 17 2026 - 09:09:34 EST
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@xxxxxxxxxx/ # [1]
>> Link: https://lore.kernel.org/all/20260710-chid-maple-v1-1-4ee869055268@xxxxxxxxxx/ # [2]
>> Link: https://lore.kernel.org/all/20260717053241.916441-1-ynorov@xxxxxxxxxx/ # [3]
>> Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
>> Signed-off-by: Eliot Courtney <ecourtney@xxxxxxxxxx>
>
> Reviewed-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
>
> 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!