mbuf: add accessors for data room and private size

This code retrieving the pool private area is duplicated in many
places, we can use of function for it.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
This commit is contained in:
Olivier Matz 2015-04-22 11:57:20 +02:00 committed by Thomas Monjalon
parent 0a0dfd40ed
commit c511a96a34
11 changed files with 67 additions and 51 deletions

View File

@ -1439,7 +1439,6 @@ rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
int ret;
uint32_t mbp_buf_size;
struct rte_eth_dev *dev;
struct rte_pktmbuf_pool_private *mbp_priv;
struct rte_eth_dev_info dev_info;
/* This function is only safe when called from the primary process
@ -1478,8 +1477,7 @@ rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
(int) sizeof(struct rte_pktmbuf_pool_private));
return -ENOSPC;
}
mbp_priv = rte_mempool_get_priv(mp);
mbp_buf_size = mbp_priv->mbuf_data_room_size;
mbp_buf_size = rte_pktmbuf_data_room_size(mp);
if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "

View File

@ -641,6 +641,47 @@ void rte_pktmbuf_init(struct rte_mempool *mp, void *opaque_arg,
*/
void rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg);
/**
* Get the data room size of mbufs stored in a pktmbuf_pool
*
* The data room size is the amount of data that can be stored in a
* mbuf including the headroom (RTE_PKTMBUF_HEADROOM).
*
* @param mp
* The packet mbuf pool.
* @return
* The data room size of mbufs stored in this mempool.
*/
static inline uint16_t
rte_pktmbuf_data_room_size(struct rte_mempool *mp)
{
struct rte_pktmbuf_pool_private *mbp_priv;
mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp);
return mbp_priv->mbuf_data_room_size;
}
/**
* Get the application private size of mbufs stored in a pktmbuf_pool
*
* The private size of mbuf is a zone located between the rte_mbuf
* structure and the data buffer where an application can store data
* associated to a packet.
*
* @param mp
* The packet mbuf pool.
* @return
* The private size of mbufs stored in this mempool.
*/
static inline uint16_t
rte_pktmbuf_priv_size(struct rte_mempool *mp)
{
struct rte_pktmbuf_pool_private *mbp_priv;
mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp);
return mbp_priv->mbuf_priv_size;
}
/**
* Reset the fields of a packet mbuf to their default values.
*

View File

@ -348,15 +348,13 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
{
struct pmd_internals *internals = dev->data->dev_private;
struct pkt_rx_queue *pkt_q = &internals->rx_queue[rx_queue_id];
struct rte_pktmbuf_pool_private *mbp_priv;
uint16_t buf_size;
pkt_q->mb_pool = mb_pool;
/* Now get the space available for data in the mbuf */
mbp_priv = rte_mempool_get_priv(pkt_q->mb_pool);
buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size -
RTE_PKTMBUF_HEADROOM);
buf_size = (uint16_t)(rte_pktmbuf_data_room_size(pkt_q->mb_pool) -
RTE_PKTMBUF_HEADROOM);
if (ETH_FRAME_LEN > buf_size) {
RTE_LOG(ERR, PMD,

View File

@ -1668,12 +1668,11 @@ eth_em_rx_init(struct rte_eth_dev *dev)
/* Determine RX bufsize. */
rctl_bsize = EM_MAX_BUF_SIZE;
for (i = 0; i < dev->data->nb_rx_queues; i++) {
struct rte_pktmbuf_pool_private *mbp_priv;
uint32_t buf_size;
rxq = dev->data->rx_queues[i];
mbp_priv = rte_mempool_get_priv(rxq->mb_pool);
buf_size = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
buf_size = rte_pktmbuf_data_room_size(rxq->mb_pool) -
RTE_PKTMBUF_HEADROOM;
rctl_bsize = RTE_MIN(rctl_bsize, buf_size);
}

View File

@ -1921,7 +1921,6 @@ eth_igb_rx_init(struct rte_eth_dev *dev)
{
struct e1000_hw *hw;
struct igb_rx_queue *rxq;
struct rte_pktmbuf_pool_private *mbp_priv;
uint32_t rctl;
uint32_t rxcsum;
uint32_t srrctl;
@ -1991,9 +1990,8 @@ eth_igb_rx_init(struct rte_eth_dev *dev)
/*
* Configure RX buffer size.
*/
mbp_priv = rte_mempool_get_priv(rxq->mb_pool);
buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size -
RTE_PKTMBUF_HEADROOM);
buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
RTE_PKTMBUF_HEADROOM);
if (buf_size >= 1024) {
/*
* Configure the BSIZEPACKET field of the SRRCTL
@ -2221,7 +2219,6 @@ eth_igbvf_rx_init(struct rte_eth_dev *dev)
{
struct e1000_hw *hw;
struct igb_rx_queue *rxq;
struct rte_pktmbuf_pool_private *mbp_priv;
uint32_t srrctl;
uint16_t buf_size;
uint16_t rctl_bsize;
@ -2262,9 +2259,8 @@ eth_igbvf_rx_init(struct rte_eth_dev *dev)
/*
* Configure RX buffer size.
*/
mbp_priv = rte_mempool_get_priv(rxq->mb_pool);
buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size -
RTE_PKTMBUF_HEADROOM);
buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
RTE_PKTMBUF_HEADROOM);
if (buf_size >= 1024) {
/*
* Configure the BSIZEPACKET field of the SRRCTL

View File

@ -397,7 +397,6 @@ fm10k_dev_rx_init(struct rte_eth_dev *dev)
uint32_t size;
uint32_t rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY;
uint16_t buf_size;
struct rte_pktmbuf_pool_private *mbp_priv;
/* Disable RXINT to avoid possible interrupt */
for (i = 0; i < hw->mac.max_queues; i++)
@ -425,9 +424,8 @@ fm10k_dev_rx_init(struct rte_eth_dev *dev)
FM10K_WRITE_REG(hw, FM10K_RDLEN(i), size);
/* Configure the Rx buffer size for one buff without split */
mbp_priv = rte_mempool_get_priv(rxq->mp);
buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size -
RTE_PKTMBUF_HEADROOM);
buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
RTE_PKTMBUF_HEADROOM);
FM10K_WRITE_REG(hw, FM10K_SRRCTL(i),
buf_size >> FM10K_SRRCTL_BSIZEPKT_SHIFT);

View File

@ -571,13 +571,11 @@ i40evf_fill_virtchnl_vsi_rxq_info(struct i40e_virtchnl_rxq_info *rxq_info,
rxq_info->queue_id = queue_id;
rxq_info->max_pkt_size = max_pkt_size;
if (queue_id < nb_rxq) {
struct rte_pktmbuf_pool_private *mbp_priv;
rxq_info->ring_len = rxq->nb_rx_desc;
rxq_info->dma_ring_addr = rxq->rx_ring_phys_addr;
mbp_priv = rte_mempool_get_priv(rxq->mp);
rxq_info->databuffer_size =
mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
(rte_pktmbuf_data_room_size(rxq->mp) -
RTE_PKTMBUF_HEADROOM);
}
}

View File

@ -2444,11 +2444,10 @@ i40e_rx_queue_config(struct i40e_rx_queue *rxq)
struct i40e_pf *pf = I40E_VSI_TO_PF(rxq->vsi);
struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
struct rte_eth_dev_data *data = pf->dev_data;
struct rte_pktmbuf_pool_private *mbp_priv =
rte_mempool_get_priv(rxq->mp);
uint16_t buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size -
RTE_PKTMBUF_HEADROOM);
uint16_t len;
uint16_t buf_size, len;
buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
RTE_PKTMBUF_HEADROOM);
switch (pf->flags & (I40E_FLAG_HEADER_SPLIT_DISABLED |
I40E_FLAG_HEADER_SPLIT_ENABLED)) {
@ -2506,7 +2505,6 @@ i40e_rx_queue_init(struct i40e_rx_queue *rxq)
uint16_t pf_q = rxq->reg_idx;
uint16_t buf_size;
struct i40e_hmc_obj_rxq rx_ctx;
struct rte_pktmbuf_pool_private *mbp_priv;
err = i40e_rx_queue_config(rxq);
if (err < 0) {
@ -2553,9 +2551,8 @@ i40e_rx_queue_init(struct i40e_rx_queue *rxq)
rxq->qrx_tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
mbp_priv = rte_mempool_get_priv(rxq->mp);
buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size -
RTE_PKTMBUF_HEADROOM);
buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
RTE_PKTMBUF_HEADROOM);
/* Check if scattered RX needs to be used. */
if ((rxq->max_pkt_len + 2 * I40E_VLAN_TAG_SIZE) > buf_size) {

View File

@ -4203,7 +4203,6 @@ ixgbe_dev_rx_init(struct rte_eth_dev *dev)
{
struct ixgbe_hw *hw;
struct ixgbe_rx_queue *rxq;
struct rte_pktmbuf_pool_private *mbp_priv;
uint64_t bus_addr;
uint32_t rxctrl;
uint32_t fctrl;
@ -4320,9 +4319,8 @@ ixgbe_dev_rx_init(struct rte_eth_dev *dev)
* The value is in 1 KB resolution. Valid values can be from
* 1 KB to 16 KB.
*/
mbp_priv = rte_mempool_get_priv(rxq->mb_pool);
buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size -
RTE_PKTMBUF_HEADROOM);
buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
RTE_PKTMBUF_HEADROOM);
srrctl |= ((buf_size >> IXGBE_SRRCTL_BSIZEPKT_SHIFT) &
IXGBE_SRRCTL_BSIZEPKT_MASK);
@ -4738,7 +4736,6 @@ ixgbevf_dev_rx_init(struct rte_eth_dev *dev)
{
struct ixgbe_hw *hw;
struct ixgbe_rx_queue *rxq;
struct rte_pktmbuf_pool_private *mbp_priv;
uint64_t bus_addr;
uint32_t srrctl, psrtype = 0;
uint16_t buf_size;
@ -4825,9 +4822,8 @@ ixgbevf_dev_rx_init(struct rte_eth_dev *dev)
* The value is in 1 KB resolution. Valid values can be from
* 1 KB to 16 KB.
*/
mbp_priv = rte_mempool_get_priv(rxq->mb_pool);
buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size -
RTE_PKTMBUF_HEADROOM);
buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
RTE_PKTMBUF_HEADROOM);
srrctl |= ((buf_size >> IXGBE_SRRCTL_BSIZEPKT_SHIFT) &
IXGBE_SRRCTL_BSIZEPKT_MASK);

View File

@ -136,7 +136,6 @@ eth_pcap_rx(void *queue,
const u_char *packet;
struct rte_mbuf *mbuf;
struct pcap_rx_queue *pcap_q = queue;
struct rte_pktmbuf_pool_private *mbp_priv;
uint16_t num_rx = 0;
uint16_t buf_size;
@ -157,8 +156,7 @@ eth_pcap_rx(void *queue,
break;
/* Now get the space available for data in the mbuf */
mbp_priv = rte_mempool_get_priv(pcap_q->mb_pool);
buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size -
buf_size = (uint16_t)(rte_pktmbuf_data_room_size(pcap_q->mb_pool) -
RTE_PKTMBUF_HEADROOM);
if (header.len <= buf_size) {

View File

@ -838,14 +838,11 @@ vmxnet3_dev_rx_queue_setup(struct rte_eth_dev *dev,
uint8_t i;
char mem_name[32];
uint16_t buf_size;
struct rte_pktmbuf_pool_private *mbp_priv;
PMD_INIT_FUNC_TRACE();
mbp_priv = (struct rte_pktmbuf_pool_private *)
rte_mempool_get_priv(mp);
buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size -
RTE_PKTMBUF_HEADROOM);
buf_size = rte_pktmbuf_data_room_size(mp) -
RTE_PKTMBUF_HEADROOM;
if (dev->data->dev_conf.rxmode.max_rx_pkt_len > buf_size) {
PMD_INIT_LOG(ERR, "buf_size = %u, max_pkt_len = %u, "