> -----Original Message-----
> From: Paul Szczepanek <paul.szczepa...@arm.com>
> Sent: Thursday, May 30, 2024 12:18 AM
> To: Morten Brørup <m...@smartsharesystems.com>; dev@dpdk.org; Du, Frank
> <frank...@intel.com>
> Cc: n...@arm.com; Ferruh Yigit <ferruh.yi...@amd.com>; Andrew Rybchenko
> <andrew.rybche...@oktetlabs.ru>; Burakov, Anatoly
> <anatoly.bura...@intel.com>; Loftus, Ciara <ciara.lof...@intel.com>
> Subject: Re: [PATCH v12 2/6] mempool: add functions to get extra mempool info
> 
> 
> 
> 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/MW4PR11MB58724AC82A34A3EEFEF78E898EF22@
> MW4P
> > R11MB5872.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;
> }

Thanks. It looks great. I will rebase the XDP patch to use the new API once it 
get merged.

Reply via email to