From: Wei Hu (Xavier) Date: Wed, 9 Sep 2020 09:23:33 +0000 (+0800) Subject: net/hns3: reduce address calculation in Rx X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=323df8941b57027752ee9d191f1ac6f359bd524e;p=dpdk.git net/hns3: reduce address calculation in Rx 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) --- diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h index 9e49e2886b..3cb05355e1 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 fe2a7a4191..703b12a445 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 @@ pkt_err: 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 a2d6514b9d..c1a34e2f69 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;