From patchwork Mon Mar 9 10:20:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladislav Zolotarov X-Patchwork-Id: 3935 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 35A8C9A9A; Mon, 9 Mar 2015 11:20:42 +0100 (CET) Received: from mail-we0-f182.google.com (mail-we0-f182.google.com [74.125.82.182]) by dpdk.org (Postfix) with ESMTP id 8EF9A9A8F for ; Mon, 9 Mar 2015 11:20:39 +0100 (CET) Received: by wesw62 with SMTP id w62so10181817wes.0 for ; Mon, 09 Mar 2015 03:20:39 -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=3FFSj612K4GrOl68qV1gmCSlum3RdV/a7ETh61o3PbU=; b=khgHQThOBTTCWIi2QpFApFudMoA7QqkOFulWKL7NQ8U/f57cL6Gu4YPImb/Yl/jGgh d7PSvlUW/pHynXqxJfUnEvVvK2xb5kgYFEntKOFYLr7xGGlekKM1dLNIKKYp+sjfJ0pB 908xmB0BEk7sFUQwk0J4fL19qLRwBYCcOu/3FfakwX5fKIrinX+c5Rz9+bW+8lqRkMFa se0NiSgIIiHWgI1AoS/80hqYBaViD0ogNOJPNokFVVi/HQO1gsR9M+CunM+1RTFk2Q06 h9kAl/HOPMrzI6nczbMd9inhWOyfqdN9CoR09ypmwtxzRFbVR4ce4vhjxHM2WsEGkmrD oTyA== X-Gm-Message-State: ALoCoQm/aXvWDpGOluzAs5i3kWXC/4Qu3Z5gos80MSs3hRtyJDkH/jfZvsiigDRAH/Wt2UgKpXeM X-Received: by 10.180.92.136 with SMTP id cm8mr103110153wib.41.1425896439438; Mon, 09 Mar 2015 03:20:39 -0700 (PDT) Received: from vladz-laptop.localdomain ([109.65.117.109]) by mx.google.com with ESMTPSA id md2sm18728782wic.19.2015.03.09.03.20.38 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Mar 2015 03:20:38 -0700 (PDT) From: Vlad Zolotarov To: dev@dpdk.org Date: Mon, 9 Mar 2015 12:20:32 +0200 Message-Id: <1425896433-12452-3-git-send-email-vladz@cloudius-systems.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1425896433-12452-1-git-send-email-vladz@cloudius-systems.com> References: <1425896433-12452-1-git-send-email-vladz@cloudius-systems.com> Subject: [dpdk-dev] [PATCH v5 2/3] ixgbe: Code refactoring 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" - ixgbe_rx_alloc_bufs(): - Reset the rte_mbuf fields only when requested. - Take the RDT update out of the function. - Add the stub when RTE_LIBRTE_IXGBE_RX_ALLOW_BULK_ALLOC is not defined. - ixgbe_recv_scattered_pkts(): - Take the code that updates the fields of the cluster's HEAD buffer into the inline function. Signed-off-by: Vlad Zolotarov New in v3: - ixgbe_rx_alloc_bufs(): Always reset refcnt of the buffers to 1. --- lib/librte_pmd_ixgbe/ixgbe_rxtx.c | 114 +++++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 45 deletions(-) diff --git a/lib/librte_pmd_ixgbe/ixgbe_rxtx.c b/lib/librte_pmd_ixgbe/ixgbe_rxtx.c index 609b5fd..37aca5d 100644 --- a/lib/librte_pmd_ixgbe/ixgbe_rxtx.c +++ b/lib/librte_pmd_ixgbe/ixgbe_rxtx.c @@ -1022,7 +1022,7 @@ ixgbe_rx_scan_hw_ring(struct igb_rx_queue *rxq) } static inline int -ixgbe_rx_alloc_bufs(struct igb_rx_queue *rxq) +ixgbe_rx_alloc_bufs(struct igb_rx_queue *rxq, bool reset_mbuf) { volatile union ixgbe_adv_rx_desc *rxdp; struct igb_rx_entry *rxep; @@ -1043,11 +1043,14 @@ ixgbe_rx_alloc_bufs(struct igb_rx_queue *rxq) for (i = 0; i < rxq->rx_free_thresh; ++i) { /* populate the static rte mbuf fields */ mb = rxep[i].mbuf; + if (reset_mbuf) { + mb->next = NULL; + mb->nb_segs = 1; + mb->port = rxq->port_id; + } + rte_mbuf_refcnt_set(mb, 1); - mb->next = NULL; mb->data_off = RTE_PKTMBUF_HEADROOM; - mb->nb_segs = 1; - mb->port = rxq->port_id; /* populate the descriptors */ dma_addr = rte_cpu_to_le_64(RTE_MBUF_DATA_DMA_ADDR_DEFAULT(mb)); @@ -1055,10 +1058,6 @@ ixgbe_rx_alloc_bufs(struct igb_rx_queue *rxq) rxdp[i].read.pkt_addr = dma_addr; } - /* update tail pointer */ - rte_wmb(); - IXGBE_PCI_REG_WRITE(rxq->rdt_reg_addr, rxq->rx_free_trigger); - /* update state of internal queue structure */ rxq->rx_free_trigger = rxq->rx_free_trigger + rxq->rx_free_thresh; if (rxq->rx_free_trigger >= rxq->nb_rx_desc) @@ -1110,7 +1109,9 @@ rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, /* if required, allocate new buffers to replenish descriptors */ if (rxq->rx_tail > rxq->rx_free_trigger) { - if (ixgbe_rx_alloc_bufs(rxq) != 0) { + uint16_t cur_free_trigger = rxq->rx_free_trigger; + + if (ixgbe_rx_alloc_bufs(rxq, true) != 0) { int i, j; PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u " "queue_id=%u", (unsigned) rxq->port_id, @@ -1130,6 +1131,10 @@ rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, return 0; } + + /* update tail pointer */ + rte_wmb(); + IXGBE_PCI_REG_WRITE(rxq->rdt_reg_addr, cur_free_trigger); } if (rxq->rx_tail >= rxq->nb_rx_desc) @@ -1169,6 +1174,13 @@ ixgbe_recv_pkts_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts, return nb_rx; } +#else +static inline int +ixgbe_rx_alloc_bufs(__rte_unused struct igb_rx_queue *rxq, + __rte_unused bool reset_mbuf) +{ + return -ENOMEM; +} #endif /* RTE_LIBRTE_IXGBE_RX_ALLOW_BULK_ALLOC */ uint16_t @@ -1353,6 +1365,51 @@ ixgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, return (nb_rx); } +/** + * Initialize the first mbuf of the returned packet: + * - RX port identifier, + * - hardware offload data, if any: + * - RSS flag & hash, + * - IP checksum flag, + * - VLAN TCI, if any, + * - error flags. + * @head HEAD of the packet cluster + * @desc HW descriptor to get data from + * @port_id Port ID of the Rx queue + */ +static inline void ixgbe_fill_cluster_head_buf( + struct rte_mbuf *head, + union ixgbe_adv_rx_desc *desc, + uint8_t port_id, + uint32_t staterr) +{ + uint32_t hlen_type_rss; + uint64_t pkt_flags; + + head->port = port_id; + + /* + * The vlan_tci field is only valid when PKT_RX_VLAN_PKT is + * set in the pkt_flags field. + */ + head->vlan_tci = rte_le_to_cpu_16(desc->wb.upper.vlan); + hlen_type_rss = rte_le_to_cpu_32(desc->wb.lower.lo_dword.data); + pkt_flags = rx_desc_hlen_type_rss_to_pkt_flags(hlen_type_rss); + pkt_flags |= rx_desc_status_to_pkt_flags(staterr); + pkt_flags |= rx_desc_error_to_pkt_flags(staterr); + head->ol_flags = pkt_flags; + + if (likely(pkt_flags & PKT_RX_RSS_HASH)) + head->hash.rss = rte_le_to_cpu_32(desc->wb.lower.hi_dword.rss); + else if (pkt_flags & PKT_RX_FDIR) { + head->hash.fdir.hash = + rte_le_to_cpu_16(desc->wb.lower.hi_dword.csum_ip.csum) + & IXGBE_ATR_HASH_MASK; + head->hash.fdir.id = + rte_le_to_cpu_16(desc->wb.lower.hi_dword.csum_ip.ip_id); + } +} + uint16_t ixgbe_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) @@ -1369,12 +1426,10 @@ ixgbe_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, union ixgbe_adv_rx_desc rxd; uint64_t dma; /* Physical address of mbuf data buffer */ uint32_t staterr; - uint32_t hlen_type_rss; uint16_t rx_id; uint16_t nb_rx; uint16_t nb_hold; uint16_t data_len; - uint64_t pkt_flags; nb_rx = 0; nb_hold = 0; @@ -1532,40 +1587,9 @@ ixgbe_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, (uint16_t) (data_len - ETHER_CRC_LEN); } - /* - * Initialize the first mbuf of the returned packet: - * - RX port identifier, - * - hardware offload data, if any: - * - RSS flag & hash, - * - IP checksum flag, - * - VLAN TCI, if any, - * - error flags. - */ - first_seg->port = rxq->port_id; - - /* - * The vlan_tci field is only valid when PKT_RX_VLAN_PKT is - * set in the pkt_flags field. - */ - first_seg->vlan_tci = rte_le_to_cpu_16(rxd.wb.upper.vlan); - hlen_type_rss = rte_le_to_cpu_32(rxd.wb.lower.lo_dword.data); - pkt_flags = rx_desc_hlen_type_rss_to_pkt_flags(hlen_type_rss); - pkt_flags = (pkt_flags | - rx_desc_status_to_pkt_flags(staterr)); - pkt_flags = (pkt_flags | - rx_desc_error_to_pkt_flags(staterr)); - first_seg->ol_flags = pkt_flags; - - if (likely(pkt_flags & PKT_RX_RSS_HASH)) - first_seg->hash.rss = - rte_le_to_cpu_32(rxd.wb.lower.hi_dword.rss); - else if (pkt_flags & PKT_RX_FDIR) { - first_seg->hash.fdir.hash = - rte_le_to_cpu_16(rxd.wb.lower.hi_dword.csum_ip.csum) - & IXGBE_ATR_HASH_MASK; - first_seg->hash.fdir.id = - rte_le_to_cpu_16(rxd.wb.lower.hi_dword.csum_ip.ip_id); - } + /* Initialize the first mbuf of the returned packet */ + ixgbe_fill_cluster_head_buf(first_seg, &rxd, rxq->port_id, + staterr); /* Prefetch data of first segment, if configured to do so. */ rte_packet_prefetch((char *)first_seg->buf_addr +