src/dpdk/lib/librte_mbuf/rte_mbuf.c
struct rte_mempool *
rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
	int socket_id, const char *ops_name)
{
	struct rte_mempool *mp;
	struct rte_pktmbuf_pool_private mbp_priv;
	const char *mp_ops_name = ops_name;
	unsigned elt_size;
	int ret;

	if (RTE_ALIGN(priv_size, RTE_MBUF_PRIV_ALIGN) != priv_size) {
		RTE_LOG(ERR, MBUF, "mbuf priv_size=%u is not aligned\n",
			priv_size);
		rte_errno = EINVAL;
		return NULL;
	}
	elt_size = sizeof(struct rte_mbuf) + (unsigned)priv_size +
		(unsigned)data_room_size;
	memset(&mbp_priv, 0, sizeof(mbp_priv));
	mbp_priv.mbuf_data_room_size = data_room_size;
	mbp_priv.mbuf_priv_size = priv_size;

	mp = rte_mempool_create_empty(name, n, elt_size, cache_size,
		 sizeof(struct rte_pktmbuf_pool_private), socket_id, 0);
	if (mp == NULL)
		return NULL;

	if (mp_ops_name == NULL)
		mp_ops_name = rte_mbuf_best_mempool_ops();
	ret = rte_mempool_set_ops_byname(mp, mp_ops_name, NULL);
	if (ret != 0) {
		RTE_LOG(ERR, MBUF, "error setting mempool handler\n");
		rte_mempool_free(mp);
		rte_errno = -ret;
		return NULL;
	}
	rte_pktmbuf_pool_init(mp, &mbp_priv);

	ret = rte_mempool_populate_default(mp);
	if (ret < 0) {
		rte_mempool_free(mp);
		rte_errno = -ret;
		return NULL;
	}

	rte_mempool_obj_iter(mp, rte_pktmbuf_init, NULL);

	return mp;
}
/* Helper to create a mbuf pool with given mempool ops name*/
Helper to create a mbuf pool with given mempool ops name
Helper to create a mbuf pool with given mempool ops name
struct rte_mempool *
rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
	int socket_id, const char *ops_name)
{
	struct rte_mempool *mp;
	struct rte_pktmbuf_pool_private mbp_priv;
	const char *mp_ops_name = ops_name;
	unsigned elt_size;
	int ret;
	if (RTE_ALIGN(priv_size, RTE_MBUF_PRIV_ALIGN) != priv_size) {
		RTE_LOG(ERR, MBUF, "mbuf priv_size=%u is not aligned\n",
			priv_size);
		rte_errno = EINVAL;
		return NULL;
	}
	elt_size = sizeof(struct rte_mbuf) + (unsigned)priv_size +
		(unsigned)data_room_size;
	memset(&mbp_priv, 0, sizeof(mbp_priv));
	mbp_priv.mbuf_data_room_size = data_room_size;
	mbp_priv.mbuf_priv_size = priv_size;
	mp = rte_mempool_create_empty(name, n, elt_size, cache_size,
		 sizeof(struct rte_pktmbuf_pool_private), socket_id, 0);
	if (mp == NULL)
		return NULL;
	if (mp_ops_name == NULL)
		mp_ops_name = rte_mbuf_best_mempool_ops();
	ret = rte_mempool_set_ops_byname(mp, mp_ops_name, NULL);
	if (ret != 0) {
		RTE_LOG(ERR, MBUF, "error setting mempool handler\n");
		rte_mempool_free(mp);
		rte_errno = -ret;
		return NULL;
	}
	rte_pktmbuf_pool_init(mp, &mbp_priv);
	ret = rte_mempool_populate_default(mp);
	if (ret < 0) {
		rte_mempool_free(mp);
		rte_errno = -ret;
		return NULL;
	}
	rte_mempool_obj_iter(mp, rte_pktmbuf_init, NULL);
	return mp;
}
struct rte_mempool * rte_pktmbuf_pool_create_by_ops ( const char * name , unsigned int n , unsigned int cache_size , uint16_t priv_size , uint16_t data_room_size , int socket_id , const char * ops_name ) { struct rte_mempool * mp ; struct rte_pktmbuf_pool_private mbp_priv ; const char * mp_ops_name = ops_name ; unsigned elt_size ; int ret ; if ( RTE_ALIGN ( priv_size , RTE_MBUF_PRIV_ALIGN ) != priv_size ) { RTE_LOG ( ERR , MBUF , " \n " , priv_size ) ; rte_errno = EINVAL ; return NULL ; } elt_size = sizeof ( struct rte_mbuf ) + ( unsigned ) priv_size + ( unsigned ) data_room_size ; memset ( & mbp_priv , 0 , sizeof ( mbp_priv ) ) ; mbp_priv . mbuf_data_room_size = data_room_size ; mbp_priv . mbuf_priv_size = priv_size ; mp = rte_mempool_create_empty ( name , n , elt_size , cache_size , sizeof ( struct rte_pktmbuf_pool_private ) , socket_id , 0 ) ; if ( mp == NULL ) return NULL ; if ( mp_ops_name == NULL ) mp_ops_name = rte_mbuf_best_mempool_ops ( ) ; ret = rte_mempool_set_ops_byname ( mp , mp_ops_name , NULL ) ; if ( ret != 0 ) { RTE_LOG ( ERR , MBUF , " \n " ) ; rte_mempool_free ( mp ) ; rte_errno = - ret ; return NULL ; } rte_pktmbuf_pool_init ( mp , & mbp_priv ) ; ret = rte_mempool_populate_default ( mp ) ; if ( ret < 0 ) { rte_mempool_free ( mp ) ; rte_errno = - ret ; return NULL ; } rte_mempool_obj_iter ( mp , rte_pktmbuf_init , NULL ) ; return mp ; }
Helper to create a mbuf pool with given mempool ops name
Helper to create a mbuf pool with given mempool ops name