[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 06/13] range: Introduce range_inverse_array()
From: |
Eric Auger |
Subject: |
Re: [PATCH 06/13] range: Introduce range_inverse_array() |
Date: |
Mon, 4 Sep 2023 16:21:44 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 |
Hi Philippe,
On 9/4/23 10:18, Philippe Mathieu-Daudé wrote:
> On 4/9/23 10:03, Eric Auger wrote:
>> This helper reverses an array of regions, turning original
>> regions into holes and original holes into actual regions,
>> covering the whole UINT64_MAX span.
>>
>> Signed-off-by: Eric Auger <eric.auger@redhat.com>
>> ---
>> include/qemu/range.h | 3 +++
>> util/range.c | 35 +++++++++++++++++++++++++++++++++++
>> 2 files changed, 38 insertions(+)
>>
>> diff --git a/include/qemu/range.h b/include/qemu/range.h
>> index 7e2b1cc447..fc1d3dabe6 100644
>> --- a/include/qemu/range.h
>> +++ b/include/qemu/range.h
>> @@ -219,4 +219,7 @@ static inline int ranges_overlap(uint64_t first1,
>> uint64_t len1,
>> GList *range_list_insert(GList *list, Range *data);
>> +void range_inverse_array(uint32_t nr_ranges, Range *ranges,
>> + uint32_t *nr_inv_ranges, Range **inv_ranges);
>> +
>> #endif
>> diff --git a/util/range.c b/util/range.c
>> index 098d9d2dc0..11c4ff0b78 100644
>> --- a/util/range.c
>> +++ b/util/range.c
>> @@ -70,3 +70,38 @@ GList *range_list_insert(GList *list, Range *data)
>> return list;
>> }
>> +
>> +/*
>> + * Inverse an array of sorted ranges over the UINT64_MAX span, ie.
>> + * original ranges becomes holes in the newly allocated inv_ranges
>> + */
>
> Most of the functions are described in the header; could you move this
> description with the declaration?
this is the case for all static inline primitives but not for
range_list_insert(), hence that choice. Now I don't have a strong opinion.
>
>> +void range_inverse_array(uint32_t nr_ranges, Range *ranges,
>> + uint32_t *nr_inv_ranges, Range **inv_ranges)
>> +{
>> + Range *resv;
>> + int i = 0, j = 0;
>> +
>> + resv = g_malloc0_n(nr_ranges + 1, sizeof(Range));
>> +
>> + /* first range lob is greater than 0, insert a first range */
>> + if (range_lob(&ranges[0]) > 0) {
>> + range_set_bounds(&resv[i++], 0,
>> + range_lob(&ranges[0]) - 1);
>> + }
>> +
>> + /* insert a range inbetween each original range */
>> + for (; j < nr_ranges - 1; j++) {
>> + if (range_compare(&ranges[j], &ranges[j + 1])) {
>> + range_set_bounds(&resv[i++], range_upb(&ranges[j]) + 1,
>> + range_lob(&ranges[j + 1]) - 1);
>> + }
>> + }
>> + /* last range upb is less than UINT64_MAX, insert a last range */
>
> In order to use this new function with variable range sizes,
> can we pass UINT64_MAX as an 'inv_range_upb' argument?
Indeed I hesitated to bring enhanced comodity by letting the caller pass
the upper bound and allow values less than UINT64_MAX. But I was afraid
this would complexify the implementation, hence the current choice. I
will have a look & see.
Thanks
Eric
>
>> + if (range_upb(&ranges[nr_ranges - 1]) < UINT64_MAX) {
>> + range_set_bounds(&resv[i++],
>> + range_upb(&ranges[nr_ranges - 1]) + 1,
>> UINT64_MAX);
>> + }
>> + *nr_inv_ranges = i;
>> + resv = g_realloc(resv, i * sizeof(Range));
>> + *inv_ranges = resv;
>> +}
>
- Re: [PATCH 01/13] memory: Let ReservedRegion use Range, (continued)
- [PATCH 02/13] memory: Introduce memory_region_iommu_set_iova_ranges, Eric Auger, 2023/09/04
- [PATCH 04/13] virtio-iommu: Rename reserved_regions into prop_resv_regions, Eric Auger, 2023/09/04
- [PATCH 03/13] vfio: Collect container iova range info, Eric Auger, 2023/09/04
- [PATCH 05/13] virtio-iommu: Introduce per IOMMUDevice reserved regions, Eric Auger, 2023/09/04
- [PATCH 06/13] range: Introduce range_inverse_array(), Eric Auger, 2023/09/04
- [PATCH 09/13] util/reserved-region: Add new ReservedRegion helpers, Eric Auger, 2023/09/04
- [PATCH 07/13] virtio-iommu: Implement set_iova_ranges() callback, Eric Auger, 2023/09/04
- [PATCH 11/13] test: Add some tests for range and resv-mem helpers, Eric Auger, 2023/09/04
- [PATCH 13/13] vfio: Remove 64-bit IOVA address space assumption, Eric Auger, 2023/09/04
- [PATCH 08/13] range: Make range_compare() public, Eric Auger, 2023/09/04
- [PATCH 12/13] virtio-iommu: Resize memory region according to the max iova info, Eric Auger, 2023/09/04
- [PATCH 10/13] virtio-iommu: Consolidate host reserved regions and property set ones, Eric Auger, 2023/09/04
- Re: [PATCH 00/13] VIRTIO-IOMMU/VFIO: Don't assume 64b IOVA space, YangHang Liu, 2023/09/05