On 29/05/2024 14:56, Morten Brørup wrote:
>> From: Paul Szczepanek [mailto:paul.szczepa...@arm.com]
>> Sent: Wednesday, 29 May 2024 12.23
>>
>> Add two functions:
>> - rte_mempool_get_mem_range - get virtual memory range
>> of the objects in the mempool,
>> - rte_mempool_get_obj_alignment - get alignment of
>> objects in the mempool.
>>
>> Add two tests that test these new functions.
>>
>> Signed-off-by: Paul Szczepanek <paul.szczepa...@arm.com>
>> Reviewed-by: Jack Bond-Preston <jack.bond-pres...@foss.arm.com>
>> Reviewed-by: Nathan Brown <nathan.br...@arm.com>
>> ---
>>
>> +/**
>> + * @warning
>> + * @b EXPERIMENTAL: this API may change without prior notice.
>> + *
>> + * Get information about the memory range used by the mempool.
>> + *
>> + * @param[in] mp
>> + *   Pointer to an initialized mempool.
>> + * @param[out] mem_range_start
>> + *   Returns lowest address in mempool.
>> + * @param[out] mem_range_length
>> + *   Returns the length of the memory range containing all the addresses
>> + *   in the memory pool.
>> + * @return
>> + *   0 on success, -EINVAL if arguments are not valid.
>> + *
>> + **/
>> +__rte_experimental
>> +int rte_mempool_get_mem_range(struct rte_mempool *mp,
>> +            void **mem_range_start, size_t *mem_range_length);
> 
> Paul,
> 
> Could you please add one more output parameter "bool *mem_range_contiguous" 
> to this function, returning true if the memory chunks are contiguous.
> 
> It will be useful instead of implementing get_memhdr_info() locally in this 
> other patch series:
> https://inbox.dpdk.org/dev/mw4pr11mb58724ac82a34a3eefef78e898e...@mw4pr11mb5872.namprd11.prod.outlook.com/
> 
> Please coordinate this change directly with Frank Du <frank...@intel.com>.
> 
> -Morten
> 

Does this work for you?

int rte_mempool_get_mem_range(struct rte_mempool *mp,
                void **mem_range_start, size_t *mem_range_length,
                bool *contiguous)
{
        if (mp == NULL)
                return -EINVAL;

        void *address_low = (void *)UINTPTR_MAX;
        void *address_high = 0;
        size_t address_diff = 0;
        size_t mem_total_size = 0;
        struct rte_mempool_memhdr *hdr;

        /* go through memory chunks and find the lowest and highest addresses */
        STAILQ_FOREACH(hdr, &mp->mem_list, next) {
                if (address_low > hdr->addr)
                        address_low = hdr->addr;
                if (address_high < RTE_PTR_ADD(hdr->addr, hdr->len))
                        address_high = RTE_PTR_ADD(hdr->addr, hdr->len);
                mem_total_size += hdr->len;
        }

        /* check if mempool was not populated yet (no memory chunks) */
        if (address_low == (void *)UINTPTR_MAX)
                return -EINVAL;

        address_diff = (size_t)RTE_PTR_DIFF(address_high, address_low);
        if (mem_range_start != NULL)
                *mem_range_start = address_low;
        if (mem_range_length != NULL)
                *mem_range_length = address_diff;
        if (contiguous != NULL)
                *contiguous = (mem_total_size == address_diff) ? true : false;

        return 0;
}

Reply via email to