From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 23558A04B9; Mon, 7 Sep 2020 11:09:21 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BD6D01C0DC; Mon, 7 Sep 2020 11:09:08 +0200 (CEST) Received: from mail.chinasoftinc.com (unknown [114.113.233.8]) by dpdk.org (Postfix) with ESMTP id 9B76C1C0D2 for ; Mon, 7 Sep 2020 11:09:06 +0200 (CEST) Received: from localhost.localdomain (65.49.108.226) by INCCAS002.ito.icss (10.168.0.60) with Microsoft SMTP Server id 14.3.487.0; Mon, 7 Sep 2020 17:09:03 +0800 From: "Wei Hu (Xavier)" To: CC: Date: Mon, 7 Sep 2020 17:08:19 +0800 Message-ID: <20200907090825.1761-3-huwei013@chinasoftinc.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20200907090825.1761-1-huwei013@chinasoftinc.com> References: <20200907090825.1761-1-huwei013@chinasoftinc.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [65.49.108.226] Subject: [dpdk-dev] [PATCH 2/8] net/hns3: reduce address calculation in Rx X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: "Wei Hu (Xavier)" This patch adds the internal function named hns3_write_reg_opt to avoid performance loss from address calculation during register access in the '.rx_pkt_burst' ops implementation function named hns3_recv_pkts. In addition, because hardware always access register in little-endian mode based on hns3 network engine, so driver should also call rte_cpu_to_le_32 to convert data in little-endian mode before writing register and call rte_le_to_cpu_32 to convert data after reading from register. Here the driver encapsulates the data conversion operation in the register read/write operation function as below: hns3_write_reg hns3_write_reg_opt hns3_read_reg Therefore, when calling these functions, conversion is not required again. Signed-off-by: Chengwen Feng Signed-off-by: Wei Hu (Xavier) --- drivers/net/hns3/hns3_ethdev.h | 29 +++++++++++++++++++++++++++-- drivers/net/hns3/hns3_rxtx.c | 14 +++----------- drivers/net/hns3/hns3_rxtx.h | 1 + 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h index 9e49e28..3cb0535 100644 --- a/drivers/net/hns3/hns3_ethdev.h +++ b/drivers/net/hns3/hns3_ethdev.h @@ -708,14 +708,39 @@ struct hns3_adapter { #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) +/* + * Because hardware always access register in little-endian mode based on hns3 + * network engine, so driver should also call rte_cpu_to_le_32 to convert data + * in little-endian mode before writing register and call rte_le_to_cpu_32 to + * convert data after reading from register. + * + * Here the driver encapsulates the data conversion operation in the register + * read/write operation function as below: + * hns3_write_reg + * hns3_write_reg_opt + * hns3_read_reg + * Therefore, when calling these functions, conversion is not required again. + */ static inline void hns3_write_reg(void *base, uint32_t reg, uint32_t value) { - rte_write32(value, (volatile void *)((char *)base + reg)); + rte_write32(rte_cpu_to_le_32(value), + (volatile void *)((char *)base + reg)); +} + +/* + * The optimized function for writing registers used in the '.rx_pkt_burst' and + * '.tx_pkt_burst' ops implementation function. + */ +static inline void hns3_write_reg_opt(volatile void *addr, uint32_t value) +{ + rte_io_wmb(); + rte_write32_relaxed(rte_cpu_to_le_32(value), addr); } static inline uint32_t hns3_read_reg(void *base, uint32_t reg) { - return rte_read32((volatile void *)((char *)base + reg)); + uint32_t read_val = rte_read32((volatile void *)((char *)base + reg)); + return rte_le_to_cpu_32(read_val); } #define hns3_write_dev(a, reg, value) \ diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c index fe2a7a4..703b12a 100644 --- a/drivers/net/hns3/hns3_rxtx.c +++ b/drivers/net/hns3/hns3_rxtx.c @@ -1323,6 +1323,8 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc, rxq->configured = true; rxq->io_base = (void *)((char *)hw->io_base + HNS3_TQP_REG_OFFSET + idx * HNS3_TQP_REG_SIZE); + rxq->io_head_reg = (volatile void *)((char *)rxq->io_base + + HNS3_RING_RX_HEAD_REG); rxq->rx_buf_len = rx_buf_size; rxq->l2_errors = 0; rxq->pkt_len_errors = 0; @@ -1472,16 +1474,6 @@ hns3_dev_supported_ptypes_get(struct rte_eth_dev *dev) return NULL; } -static void -hns3_clean_rx_buffers(struct hns3_rx_queue *rxq, int count) -{ - rxq->next_to_use += count; - if (rxq->next_to_use >= rxq->nb_rx_desc) - rxq->next_to_use -= rxq->nb_rx_desc; - - hns3_write_dev(rxq, HNS3_RING_RX_HEAD_REG, count); -} - static int hns3_handle_bdinfo(struct hns3_rx_queue *rxq, struct rte_mbuf *rxm, uint32_t bd_base_info, uint32_t l234_info, @@ -1844,7 +1836,7 @@ hns3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) rxq->rx_free_hold += nb_rx_bd; if (rxq->rx_free_hold > rxq->rx_free_thresh) { - hns3_clean_rx_buffers(rxq, rxq->rx_free_hold); + hns3_write_reg_opt(rxq->io_head_reg, rxq->rx_free_hold); rxq->rx_free_hold = 0; } diff --git a/drivers/net/hns3/hns3_rxtx.h b/drivers/net/hns3/hns3_rxtx.h index a2d6514..c1a34e2 100644 --- a/drivers/net/hns3/hns3_rxtx.h +++ b/drivers/net/hns3/hns3_rxtx.h @@ -231,6 +231,7 @@ struct hns3_entry { struct hns3_rx_queue { void *io_base; + volatile void *io_head_reg; struct hns3_adapter *hns; struct rte_mempool *mb_pool; struct hns3_desc *rx_ring; -- 2.9.5