From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com [74.125.82.45]) by dpdk.org (Postfix) with ESMTP id 240395FEB for ; Mon, 20 Apr 2015 17:41:50 +0200 (CEST) Received: by wgin8 with SMTP id n8so183396158wgi.0 for ; Mon, 20 Apr 2015 08:41:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mPuH75ohyWyVnk9bXeM6ESg9PS1b+2Dq3FF45xtbq/0=; b=UurPvUTmGv5+dJIINCkUuvz9rlemY/GHTfZwo5D5A30WD3IDjvRbKnbg4IUhAu2oHg 2F2PmrAOTtR69CJ95Lrhy4pM0P4XvPYMPGYyf9QcIwVpfViIgAd3n/h8eGYsWXFGV1Ww 5a8Aop18PYUNeEGeoruOYDpmVFeEm6T0ACGEjH+qVTJmkEjqKS1ghHUgOon/s6Td+azi ufB1XKkF78GU38jJQeqXr8e4ZYewqUAzu2OjBMnAhjx+Hra6Qv6+L5OL33QFVryYFPQV GCsUPl0mFO3I5y4hpQeNFNIoa/IFlJyR71NspmD8TRb84FxedRZ6kxUfR6GJPFcHvLMC 7UHg== X-Gm-Message-State: ALoCoQlwn0vXvv9zjSqu+qTzFLCHD/TrYY9jLCSw7sillKTPHOCcqCSAi1e6ayKef6aUwDAoHzrO X-Received: by 10.180.103.130 with SMTP id fw2mr22616665wib.87.1429544510011; Mon, 20 Apr 2015 08:41:50 -0700 (PDT) Received: from glumotte.dev.6wind.com (6wind.net2.nerim.net. [213.41.180.237]) by mx.google.com with ESMTPSA id fm8sm11258951wib.9.2015.04.20.08.41.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Apr 2015 08:41:49 -0700 (PDT) From: Olivier Matz To: dev@dpdk.org Date: Mon, 20 Apr 2015 17:41:27 +0200 Message-Id: <1429544496-22532-4-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1429544496-22532-1-git-send-email-olivier.matz@6wind.com> References: <1427829784-12323-2-git-send-email-zer0@droids-corp.org> <1429544496-22532-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH v4 03/12] mbuf: add accessors to get data room size and private size X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Apr 2015 15:41:50 -0000 This code retrieving the pool private area is duplicated in many places, we can use of function for it. Signed-off-by: Olivier Matz --- lib/librte_ether/rte_ethdev.c | 4 +-- lib/librte_mbuf/rte_mbuf.h | 41 ++++++++++++++++++++++++++++ lib/librte_pmd_af_packet/rte_eth_af_packet.c | 6 ++-- lib/librte_pmd_e1000/em_rxtx.c | 5 ++-- lib/librte_pmd_e1000/igb_rxtx.c | 12 +++----- lib/librte_pmd_fm10k/fm10k_ethdev.c | 6 ++-- lib/librte_pmd_i40e/i40e_ethdev_vf.c | 6 ++-- lib/librte_pmd_i40e/i40e_rxtx.c | 15 ++++------ lib/librte_pmd_ixgbe/ixgbe_rxtx.c | 12 +++----- lib/librte_pmd_pcap/rte_eth_pcap.c | 5 +--- lib/librte_pmd_vmxnet3/vmxnet3_rxtx.c | 7 ++--- 11 files changed, 67 insertions(+), 52 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index e20cca5..ff06256 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -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 " diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 13fd626..a4146fa 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -642,6 +642,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. * * The given mbuf must have only one segment. diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c b/lib/librte_pmd_af_packet/rte_eth_af_packet.c index f7e9ec9..bdd9628 100644 --- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c +++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c @@ -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, diff --git a/lib/librte_pmd_e1000/em_rxtx.c b/lib/librte_pmd_e1000/em_rxtx.c index 8e20920..64d067c 100644 --- a/lib/librte_pmd_e1000/em_rxtx.c +++ b/lib/librte_pmd_e1000/em_rxtx.c @@ -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); } diff --git a/lib/librte_pmd_e1000/igb_rxtx.c b/lib/librte_pmd_e1000/igb_rxtx.c index 084e45a..80d05c0 100644 --- a/lib/librte_pmd_e1000/igb_rxtx.c +++ b/lib/librte_pmd_e1000/igb_rxtx.c @@ -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 diff --git a/lib/librte_pmd_fm10k/fm10k_ethdev.c b/lib/librte_pmd_fm10k/fm10k_ethdev.c index 1a96cf2..dd4454c 100644 --- a/lib/librte_pmd_fm10k/fm10k_ethdev.c +++ b/lib/librte_pmd_fm10k/fm10k_ethdev.c @@ -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); diff --git a/lib/librte_pmd_i40e/i40e_ethdev_vf.c b/lib/librte_pmd_i40e/i40e_ethdev_vf.c index 4581c5b..473d441 100644 --- a/lib/librte_pmd_i40e/i40e_ethdev_vf.c +++ b/lib/librte_pmd_i40e/i40e_ethdev_vf.c @@ -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); } } diff --git a/lib/librte_pmd_i40e/i40e_rxtx.c b/lib/librte_pmd_i40e/i40e_rxtx.c index abe68f4..493cfa3 100644 --- a/lib/librte_pmd_i40e/i40e_rxtx.c +++ b/lib/librte_pmd_i40e/i40e_rxtx.c @@ -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) { diff --git a/lib/librte_pmd_ixgbe/ixgbe_rxtx.c b/lib/librte_pmd_ixgbe/ixgbe_rxtx.c index 3c61d1c..7f15f15 100644 --- a/lib/librte_pmd_ixgbe/ixgbe_rxtx.c +++ b/lib/librte_pmd_ixgbe/ixgbe_rxtx.c @@ -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); diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_eth_pcap.c index e5d2279..e1aea34 100644 --- a/lib/librte_pmd_pcap/rte_eth_pcap.c +++ b/lib/librte_pmd_pcap/rte_eth_pcap.c @@ -136,9 +136,7 @@ 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; if (unlikely(pcap_q->pcap == NULL || nb_pkts == 0)) return 0; @@ -157,8 +155,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) { diff --git a/lib/librte_pmd_vmxnet3/vmxnet3_rxtx.c b/lib/librte_pmd_vmxnet3/vmxnet3_rxtx.c index a530c80..d8019f5 100644 --- a/lib/librte_pmd_vmxnet3/vmxnet3_rxtx.c +++ b/lib/librte_pmd_vmxnet3/vmxnet3_rxtx.c @@ -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, " -- 2.1.4