* [PATCH v2] Adding the routines rte_pktmbuf_alloc_bulk() and rte_pktmbuf_free_bulk() @ 2014-10-06 20:26 Keith Wiles [not found] ` <1412627168-78475-1-git-send-email-keith.wiles-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org> 0 siblings, 1 reply; 2+ messages in thread From: Keith Wiles @ 2014-10-06 20:26 UTC (permalink / raw) To: dev-VfR2kkLFssw Minor helper routines to mirror the mempool routines and remove the code from applications. The ixgbe_rxtx_vec.c routine could be changed to use the ret_pktmbuf_alloc_bulk() routine inplace of rte_mempool_get_bulk(). Combined __rte_mbuf_raw_alloc_bulk into the rte_pktmbuf_alloc_bulk function. Fixed up the comments to state the correct return values. Signed-off-by: Keith Wiles <keith.wiles-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org> --- lib/librte_mbuf/rte_mbuf.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 1c6e115..337611b 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -671,6 +671,44 @@ __rte_pktmbuf_prefree_seg(struct rte_mbuf *m) } /** + * Allocate a list of mbufs from a mempool into a mbuf array. + * + * This mbuf list contains one segment per mbuf, which has a length of 0. The pointer + * to data is initialized to have some bytes of headroom in the buffer + * (if buffer size allows). + * + * The routine is just a simple wrapper routine to reduce code in the application and + * provide a cleaner API for multiple mbuf requests. + * + * @param mp + * The mempool from which the mbuf is allocated. + * @param m_list + * An array of mbuf pointers, cnt must be less then or equal to the size of the array. + * @param cnt + * Number of slots in the m_list array to fill. + * @return + * - cnt is returned if a successful allocation. + * - <0 negative number is an error code. + */ +static inline int __attribute__((always_inline)) +rte_pktmbuf_alloc_bulk(struct rte_mempool *mp, struct rte_mbuf *m_list[], int16_t cnt) +{ + int ret; + + ret = rte_mempool_get_bulk(mp, (void **)m_list, cnt); + if ( ret == 0 ) { + ret = cnt; + while(cnt--) { +#ifdef RTE_MBUF_REFCNT + rte_mbuf_refcnt_set(*m_list, 1); +#endif /* RTE_MBUF_REFCNT */ + rte_pktmbuf_reset(*m_list++); + } + } + return ret; +} + +/** * Free a segment of a packet mbuf into its original mempool. * * Free an mbuf, without parsing other segments in case of chained @@ -708,6 +746,23 @@ static inline void rte_pktmbuf_free(struct rte_mbuf *m) } } +/** + * Free a list of packet mbufs back into its original mempool. + * + * Free a list of mbufs by calling rte_pktmbuf_free() in a loop as a wrapper function. + * + * @param m_list + * An array of rte_mbuf pointers to be freed. + * @param npkts + * Number of packets to free in m_list. + */ +static inline void __attribute__((always_inline)) +rte_pktmbuf_free_bulk(struct rte_mbuf *m_list[], int16_t npkts) +{ + while(npkts--) + rte_pktmbuf_free(*m_list++); +} + #ifdef RTE_MBUF_REFCNT /** -- 2.1.0 ^ permalink raw reply related [flat|nested] 2+ messages in thread
[parent not found: <1412627168-78475-1-git-send-email-keith.wiles-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>]
* Re: [PATCH v2] Adding the routines rte_pktmbuf_alloc_bulk() and rte_pktmbuf_free_bulk() [not found] ` <1412627168-78475-1-git-send-email-keith.wiles-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org> @ 2014-10-07 8:06 ` Richardson, Bruce 0 siblings, 0 replies; 2+ messages in thread From: Richardson, Bruce @ 2014-10-07 8:06 UTC (permalink / raw) To: Wiles, Roger Keith (Wind River), dev-VfR2kkLFssw@public.gmane.org > -----Original Message----- > From: dev [mailto:dev-bounces-VfR2kkLFssw@public.gmane.org] On Behalf Of Keith Wiles > Sent: Monday, October 06, 2014 9:26 PM > To: dev-VfR2kkLFssw@public.gmane.org > Subject: [dpdk-dev] [PATCH v2] Adding the routines rte_pktmbuf_alloc_bulk() > and rte_pktmbuf_free_bulk() > > Minor helper routines to mirror the mempool routines and remove the code > from applications. The ixgbe_rxtx_vec.c routine could be changed to use > the ret_pktmbuf_alloc_bulk() routine inplace of rte_mempool_get_bulk(). > Can we maybe remove the reference to the vector driver for this patch. I don't believe changes there are what we want to do. /Bruce > Combined __rte_mbuf_raw_alloc_bulk into the rte_pktmbuf_alloc_bulk > function. > Fixed up the comments to state the correct return values. > > Signed-off-by: Keith Wiles <keith.wiles-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org> > --- > lib/librte_mbuf/rte_mbuf.h | 55 > ++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 55 insertions(+) > > diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h > index 1c6e115..337611b 100644 > --- a/lib/librte_mbuf/rte_mbuf.h > +++ b/lib/librte_mbuf/rte_mbuf.h > @@ -671,6 +671,44 @@ __rte_pktmbuf_prefree_seg(struct rte_mbuf *m) > } > > /** > + * Allocate a list of mbufs from a mempool into a mbuf array. > + * > + * This mbuf list contains one segment per mbuf, which has a length of 0. The > pointer > + * to data is initialized to have some bytes of headroom in the buffer > + * (if buffer size allows). > + * > + * The routine is just a simple wrapper routine to reduce code in the application > and > + * provide a cleaner API for multiple mbuf requests. > + * > + * @param mp > + * The mempool from which the mbuf is allocated. > + * @param m_list > + * An array of mbuf pointers, cnt must be less then or equal to the size of the > array. > + * @param cnt > + * Number of slots in the m_list array to fill. > + * @return > + * - cnt is returned if a successful allocation. > + * - <0 negative number is an error code. > + */ > +static inline int __attribute__((always_inline)) > +rte_pktmbuf_alloc_bulk(struct rte_mempool *mp, struct rte_mbuf *m_list[], > int16_t cnt) > +{ > + int ret; > + > + ret = rte_mempool_get_bulk(mp, (void **)m_list, cnt); > + if ( ret == 0 ) { > + ret = cnt; > + while(cnt--) { > +#ifdef RTE_MBUF_REFCNT > + rte_mbuf_refcnt_set(*m_list, 1); > +#endif /* RTE_MBUF_REFCNT */ > + rte_pktmbuf_reset(*m_list++); > + } > + } > + return ret; > +} > + > +/** > * Free a segment of a packet mbuf into its original mempool. > * > * Free an mbuf, without parsing other segments in case of chained > @@ -708,6 +746,23 @@ static inline void rte_pktmbuf_free(struct rte_mbuf > *m) > } > } > > +/** > + * Free a list of packet mbufs back into its original mempool. > + * > + * Free a list of mbufs by calling rte_pktmbuf_free() in a loop as a wrapper > function. > + * > + * @param m_list > + * An array of rte_mbuf pointers to be freed. > + * @param npkts > + * Number of packets to free in m_list. > + */ > +static inline void __attribute__((always_inline)) > +rte_pktmbuf_free_bulk(struct rte_mbuf *m_list[], int16_t npkts) > +{ > + while(npkts--) > + rte_pktmbuf_free(*m_list++); > +} > + > #ifdef RTE_MBUF_REFCNT > > /** > -- > 2.1.0 ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-10-07 8:06 UTC | newest] Thread overview: 2+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-10-06 20:26 [PATCH v2] Adding the routines rte_pktmbuf_alloc_bulk() and rte_pktmbuf_free_bulk() Keith Wiles [not found] ` <1412627168-78475-1-git-send-email-keith.wiles-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org> 2014-10-07 8:06 ` Richardson, Bruce
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).