From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 107C6A0A0E; Wed, 3 Feb 2021 08:47:20 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9AC54240460; Wed, 3 Feb 2021 08:46:57 +0100 (CET) Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by mails.dpdk.org (Postfix) with ESMTP id 03C33240444 for ; Wed, 3 Feb 2021 08:46:52 +0100 (CET) Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4DVtyf6DrYzjH0G; Wed, 3 Feb 2021 15:45:46 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Wed, 3 Feb 2021 15:46:48 +0800 From: Lijun Ou To: CC: , Date: Wed, 3 Feb 2021 15:46:09 +0800 Message-ID: <1612338382-3253-5-git-send-email-oulijun@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1612338382-3253-1-git-send-email-oulijun@huawei.com> References: <1612338382-3253-1-git-send-email-oulijun@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 04/17] net/hns3: add enhance stats function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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: "Min Hu (Connor)" In current HNS3 PMD, Rx/Tx bytes and imissed from packet stats are not implemented. This patch implemented Rx/Tx bytes using soft counters. Rx/Tx bytes stats will be enabled if the macro RTE_LIBRTE_HNS3_PMD_SOFT_COUNTERS is defined. Also, Rx imissed stats was in implemented in this patch. Signed-off-by: Min Hu (Connor) Signed-off-by: Lijun Ou --- drivers/net/hns3/hns3_cmd.h | 7 ++ drivers/net/hns3/hns3_ethdev.c | 7 ++ drivers/net/hns3/hns3_ethdev.h | 1 + drivers/net/hns3/hns3_rxtx.c | 24 ++++++ drivers/net/hns3/hns3_rxtx_vec_neon.h | 15 ++++ drivers/net/hns3/hns3_rxtx_vec_sve.c | 11 +++ drivers/net/hns3/hns3_stats.c | 137 +++++++++++++++++++++++++++++++--- drivers/net/hns3/hns3_stats.h | 8 ++ 8 files changed, 201 insertions(+), 9 deletions(-) diff --git a/drivers/net/hns3/hns3_cmd.h b/drivers/net/hns3/hns3_cmd.h index e473a30..6b1ce22 100644 --- a/drivers/net/hns3/hns3_cmd.h +++ b/drivers/net/hns3/hns3_cmd.h @@ -889,6 +889,13 @@ struct hns3_dev_specs_0_cmd { uint32_t max_tm_rate; }; +struct hns3_query_rpu_cmd { + uint32_t tc_queue_num; + uint32_t rsv1[2]; + uint32_t rpu_rx_pkt_drop_cnt; + uint32_t rsv2[2]; +}; + #define HNS3_MAX_TQP_NUM_HIP08_PF 64 #define HNS3_DEFAULT_TX_BUF 0x4000 /* 16k bytes */ #define HNS3_TOTAL_PKT_BUF 0x108000 /* 1.03125M bytes */ diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c index f85149d..bd998f6 100644 --- a/drivers/net/hns3/hns3_ethdev.c +++ b/drivers/net/hns3/hns3_ethdev.c @@ -4679,6 +4679,13 @@ hns3_init_pf(struct rte_eth_dev *eth_dev) goto err_cmd_init; } + /* Hardware statistics of imissed registers cleared. */ + ret = hns3_update_imissed_stats(hw, true); + if (ret) { + hns3_err(hw, "clear imissed stats failed, ret = %d", ret); + return ret; + } + hns3_config_all_msix_error(hw, true); ret = rte_intr_callback_register(&pci_dev->intr_handle, diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h index e72f3e1..520af20 100644 --- a/drivers/net/hns3/hns3_ethdev.h +++ b/drivers/net/hns3/hns3_ethdev.h @@ -434,6 +434,7 @@ struct hns3_hw { struct hns3_tqp_stats tqp_stats; /* Include Mac stats | Rx stats | Tx stats */ struct hns3_mac_stats mac_stats; + struct hns3_rx_missed_stats imissed_stats; uint32_t fw_version; uint16_t num_msi; diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c index 5e79177..a8bd2cc 100644 --- a/drivers/net/hns3/hns3_rxtx.c +++ b/drivers/net/hns3/hns3_rxtx.c @@ -2181,6 +2181,10 @@ hns3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) cksum_err); hns3_rxd_to_vlan_tci(rxq, rxm, l234_info, &rxd); +#ifdef RTE_LIBRTE_HNS3_PMD_SOFT_COUNTERS + /* Increment bytes counter */ + rxq->basic_stats.bytes += rxm->pkt_len; +#endif rx_pkts[nb_rx++] = rxm; continue; pkt_err: @@ -2401,6 +2405,10 @@ hns3_recv_scattered_pkts(void *rx_queue, cksum_err); hns3_rxd_to_vlan_tci(rxq, first_seg, l234_info, &rxd); +#ifdef RTE_LIBRTE_HNS3_PMD_SOFT_COUNTERS + /* Increment bytes counter */ + rxq->basic_stats.bytes += first_seg->pkt_len; +#endif rx_pkts[nb_rx++] = first_seg; first_seg = NULL; continue; @@ -3516,6 +3524,13 @@ hns3_tx_fill_hw_ring(struct hns3_tx_queue *txq, for (i = 0; i < mainpart; i += PER_LOOP_NUM) { hns3_tx_backup_4mbuf(tx_entry + i, pkts + i); hns3_tx_setup_4bd(txdp + i, pkts + i); + +#ifdef RTE_LIBRTE_HNS3_PMD_SOFT_COUNTERS + /* Increment bytes counter */ + uint32_t j; + for (j = 0; j < PER_LOOP_NUM; j++) + txq->basic_stats.bytes += pkts[i + j]->pkt_len; +#endif } if (unlikely(leftover > 0)) { for (i = 0; i < leftover; i++) { @@ -3523,6 +3538,11 @@ hns3_tx_fill_hw_ring(struct hns3_tx_queue *txq, pkts + mainpart + i); hns3_tx_setup_1bd(txdp + mainpart + i, pkts + mainpart + i); + +#ifdef RTE_LIBRTE_HNS3_PMD_SOFT_COUNTERS + /* Increment bytes counter */ + txq->basic_stats.bytes += pkts[mainpart + i]->pkt_len; +#endif } } } @@ -3661,6 +3681,10 @@ hns3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) desc->tx.tp_fe_sc_vld_ra_ri |= rte_cpu_to_le_16(BIT(HNS3_TXD_FE_B)); +#ifdef RTE_LIBRTE_HNS3_PMD_SOFT_COUNTERS + /* Increment bytes counter */ + txq->basic_stats.bytes += tx_pkt->pkt_len; +#endif nb_hold += i; txq->next_to_use = tx_next_use; txq->tx_bd_ready -= i; diff --git a/drivers/net/hns3/hns3_rxtx_vec_neon.h b/drivers/net/hns3/hns3_rxtx_vec_neon.h index a693b4b..54d358d 100644 --- a/drivers/net/hns3/hns3_rxtx_vec_neon.h +++ b/drivers/net/hns3/hns3_rxtx_vec_neon.h @@ -61,6 +61,11 @@ hns3_xmit_fixed_burst_vec(void *__restrict tx_queue, for (i = 0; i < n; i++, tx_pkts++, tx_desc++) { hns3_vec_tx(tx_desc, *tx_pkts); tx_entry[i].mbuf = *tx_pkts; + +#ifdef RTE_LIBRTE_HNS3_PMD_SOFT_COUNTERS + /* Increment bytes counter */ + txq->basic_stats.bytes += (*tx_pkts)->pkt_len; +#endif } nb_commit -= n; @@ -72,6 +77,11 @@ hns3_xmit_fixed_burst_vec(void *__restrict tx_queue, for (i = 0; i < nb_commit; i++, tx_pkts++, tx_desc++) { hns3_vec_tx(tx_desc, *tx_pkts); tx_entry[i].mbuf = *tx_pkts; + +#ifdef RTE_LIBRTE_HNS3_PMD_SOFT_COUNTERS + /* Increment bytes counter */ + txq->basic_stats.bytes += (*tx_pkts)->pkt_len; +#endif } next_to_use += nb_commit; @@ -116,6 +126,11 @@ hns3_desc_parse_field(struct hns3_rx_queue *rxq, if (likely(bd_base_info & BIT(HNS3_RXD_L3L4P_B))) hns3_rx_set_cksum_flag(pkt, pkt->packet_type, cksum_err); + +#ifdef RTE_LIBRTE_HNS3_PMD_SOFT_COUNTERS + /* Increment bytes counter */ + rxq->basic_stats.bytes += pkt->pkt_len; +#endif } return retcode; diff --git a/drivers/net/hns3/hns3_rxtx_vec_sve.c b/drivers/net/hns3/hns3_rxtx_vec_sve.c index b02bae7..8b9172a 100644 --- a/drivers/net/hns3/hns3_rxtx_vec_sve.c +++ b/drivers/net/hns3/hns3_rxtx_vec_sve.c @@ -58,6 +58,11 @@ hns3_desc_parse_field_sve(struct hns3_rx_queue *rxq, if (likely(key->bd_base_info[i] & BIT(HNS3_RXD_L3L4P_B))) hns3_rx_set_cksum_flag(rx_pkts[i], rx_pkts[i]->packet_type, cksum_err); + +#ifdef RTE_LIBRTE_HNS3_PMD_SOFT_COUNTERS + /* Increment bytes counter */ + rxq->basic_stats.bytes += rx_pkts[i]->pkt_len; +#endif } return retcode; @@ -408,6 +413,12 @@ hns3_tx_fill_hw_ring_sve(struct hns3_tx_queue *txq, svst1_scatter_u64offset_u64(pg, (uint64_t *)&txdp->tx.paylen, offsets, svdup_n_u64(valid_bit)); +#ifdef RTE_LIBRTE_HNS3_PMD_SOFT_COUNTERS + /* Increment bytes counter */ + uint32_t idx; + for (idx = 0; idx < svcntd(); idx++) + txq->basic_stats.bytes += pkts[idx]->pkt_len; +#endif /* update index for next loop */ i += svcntd(); pkts += svcntd(); diff --git a/drivers/net/hns3/hns3_stats.c b/drivers/net/hns3/hns3_stats.c index 3ba09e2..e58ebea 100644 --- a/drivers/net/hns3/hns3_stats.c +++ b/drivers/net/hns3/hns3_stats.c @@ -324,6 +324,12 @@ static const struct hns3_xstats_name_offset hns3_tx_queue_strings[] = { {"TX_QUEUE_FBD", HNS3_RING_TX_FBDNUM_REG} }; +/* The statistic of imissed packet */ +static const struct hns3_xstats_name_offset hns3_imissed_stats_strings[] = { + {"RPU_DROP_CNT", + HNS3_IMISSED_STATS_FIELD_OFFSET(rpu_rx_drop_cnt)}, +}; + #define HNS3_NUM_MAC_STATS (sizeof(hns3_mac_strings) / \ sizeof(hns3_mac_strings[0])) @@ -354,10 +360,14 @@ static const struct hns3_xstats_name_offset hns3_tx_queue_strings[] = { #define HNS3_NUM_TXQ_BASIC_STATS (sizeof(hns3_txq_basic_stats_strings) / \ sizeof(hns3_txq_basic_stats_strings[0])) +#define HNS3_NUM_IMISSED_XSTATS (sizeof(hns3_imissed_stats_strings) / \ + sizeof(hns3_imissed_stats_strings[0])) + #define HNS3_FIX_NUM_STATS (HNS3_NUM_MAC_STATS + HNS3_NUM_ERROR_INT_XSTATS + \ - HNS3_NUM_RESET_XSTATS) + HNS3_NUM_RESET_XSTATS + HNS3_NUM_IMISSED_XSTATS) static void hns3_tqp_stats_clear(struct hns3_hw *hw); +static void hns3_tqp_basic_stats_clear(struct rte_eth_dev *dev); /* * Query all the MAC statistics data of Network ICL command ,opcode id: 0x0034. @@ -514,6 +524,52 @@ hns3_update_tqp_stats(struct hns3_hw *hw) return 0; } +static int +hns3_update_rpu_drop_stats(struct hns3_hw *hw) +{ + struct hns3_rx_missed_stats *stats = &hw->imissed_stats; + struct hns3_query_rpu_cmd *req; + struct hns3_cmd_desc desc; + uint64_t cnt; + uint32_t tc_num; + int ret; + + hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_DFX_RPU_REG_0, true); + req = (struct hns3_query_rpu_cmd *)desc.data; + + /* + * tc_num is 0, means rpu stats of all TC channels will be + * get from firmware + */ + tc_num = 0; + req->tc_queue_num = rte_cpu_to_le_32(tc_num); + ret = hns3_cmd_send(hw, &desc, 1); + if (ret) { + hns3_err(hw, "failed to query RPU stats: %d", ret); + return ret; + } + + cnt = rte_le_to_cpu_32(req->rpu_rx_pkt_drop_cnt); + stats->rpu_rx_drop_cnt += cnt; + + return 0; +} + +int +hns3_update_imissed_stats(struct hns3_hw *hw, bool is_clear) +{ + int ret; + + ret = hns3_update_rpu_drop_stats(hw); + if (ret) + return ret; + + if (is_clear) + memset(&hw->imissed_stats, 0, sizeof(hw->imissed_stats)); + + return 0; +} + /* * Query tqp tx queue statistics ,opcode id: 0x0B03. * Query tqp rx queue statistics ,opcode id: 0x0B13. @@ -530,6 +586,7 @@ hns3_stats_get(struct rte_eth_dev *eth_dev, struct rte_eth_stats *rte_stats) { struct hns3_adapter *hns = eth_dev->data->dev_private; struct hns3_hw *hw = &hns->hw; + struct hns3_rx_missed_stats *imissed_stats = &hw->imissed_stats; struct hns3_tqp_stats *stats = &hw->tqp_stats; struct hns3_rx_queue *rxq; uint64_t cnt; @@ -539,22 +596,48 @@ hns3_stats_get(struct rte_eth_dev *eth_dev, struct rte_eth_stats *rte_stats) /* Update tqp stats by read register */ ret = hns3_update_tqp_stats(hw); if (ret) { - hns3_err(hw, "Update tqp stats fail : %d", ret); + hns3_err(hw, "update tqp stats fail : %d", ret); return ret; } - /* Get the error stats of received packets */ + if (!hns->is_vf) { + /* Update imissed stats */ + ret = hns3_update_imissed_stats(hw, false); + if (ret) { + hns3_err(hw, "update imissed stats failed, ret = %d", + ret); + return ret; + } + + rte_stats->imissed = imissed_stats->rpu_rx_drop_cnt; + } + + /* Get the error stats and bytes of received packets */ for (i = 0; i < eth_dev->data->nb_rx_queues; i++) { rxq = eth_dev->data->rx_queues[i]; if (rxq) { cnt = rxq->err_stats.l2_errors + rxq->err_stats.pkt_len_errors; rte_stats->ierrors += cnt; + +#ifdef RTE_LIBRTE_HNS3_PMD_SOFT_COUNTERS + rte_stats->ibytes += rxq->basic_stats.bytes; +#endif } } +#ifdef RTE_LIBRTE_HNS3_PMD_SOFT_COUNTERS + /* Get the bytes of received packets */ + struct hns3_tx_queue *txq; + for (i = 0; i < eth_dev->data->nb_tx_queues; i++) { + txq = eth_dev->data->tx_queues[i]; + if (txq) + rte_stats->obytes += txq->basic_stats.bytes; + } +#endif + rte_stats->oerrors = 0; - rte_stats->ipackets = stats->rcb_rx_ring_pktnum_rcd - + rte_stats->ipackets = stats->rcb_rx_ring_pktnum_rcd - rte_stats->ierrors; rte_stats->opackets = stats->rcb_tx_ring_pktnum_rcd - rte_stats->oerrors; @@ -583,7 +666,7 @@ hns3_stats_reset(struct rte_eth_dev *eth_dev) desc_reset.data[0] = rte_cpu_to_le_32((uint32_t)i); ret = hns3_cmd_send(hw, &desc_reset, 1); if (ret) { - hns3_err(hw, "Failed to reset RX No.%u queue stat: %d", + hns3_err(hw, "failed to reset RX No.%u queue stat: %d", i, ret); return ret; } @@ -593,12 +676,25 @@ hns3_stats_reset(struct rte_eth_dev *eth_dev) desc_reset.data[0] = rte_cpu_to_le_32((uint32_t)i); ret = hns3_cmd_send(hw, &desc_reset, 1); if (ret) { - hns3_err(hw, "Failed to reset TX No.%u queue stat: %d", + hns3_err(hw, "failed to reset TX No.%u queue stat: %d", i, ret); return ret; } } + if (!hns->is_vf) { + /* + * Note: Reading hardware statistics of imissed registers will + * clear them. + */ + ret = hns3_update_imissed_stats(hw, true); + if (ret) { + hns3_err(hw, "clear imissed stats failed, ret = %d", + ret); + return ret; + } + } + /* * Clear soft stats of rx error packet which will be dropped * in driver. @@ -617,6 +713,7 @@ hns3_stats_reset(struct rte_eth_dev *eth_dev) * their source. */ hns3_tqp_stats_clear(hw); + hns3_tqp_basic_stats_clear(eth_dev); return 0; } @@ -794,7 +891,7 @@ hns3_rxq_basic_stats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, rxq->err_stats.pkt_len_errors; rxq_stats->packets = stats->rcb_rx_ring_pktnum[i] - rxq_stats->errors; - rxq_stats->bytes = 0; + for (j = 0; j < HNS3_NUM_RXQ_BASIC_STATS; j++) { val = (char *)rxq_stats + hns3_rxq_basic_stats_strings[j].offset; @@ -823,7 +920,7 @@ hns3_txq_basic_stats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, txq_stats = &txq->basic_stats; txq_stats->packets = stats->rcb_tx_ring_pktnum[i]; - txq_stats->bytes = 0; + for (j = 0; j < HNS3_NUM_TXQ_BASIC_STATS; j++) { val = (char *)txq_stats + hns3_txq_basic_stats_strings[j].offset; @@ -904,6 +1001,7 @@ hns3_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, struct hns3_adapter *hns = dev->data->dev_private; struct hns3_pf *pf = &hns->pf; struct hns3_hw *hw = &hns->hw; + struct hns3_rx_missed_stats *imissed_stats = &hw->imissed_stats; struct hns3_mac_stats *mac_stats = &hw->mac_stats; struct hns3_reset_stats *reset_stats = &hw->reset.stats; struct hns3_rx_bd_errors_stats *rx_err_stats; @@ -942,6 +1040,21 @@ hns3_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, count++; } + ret = hns3_update_imissed_stats(hw, false); + if (ret) { + hns3_err(hw, "update imissed stats failed, ret = %d", + ret); + return ret; + } + + for (i = 0; i < HNS3_NUM_IMISSED_XSTATS; i++) { + addr = (char *)imissed_stats + + hns3_imissed_stats_strings[i].offset; + xstats[count].value = *(uint64_t *)addr; + xstats[count].id = count; + count++; + } + for (i = 0; i < HNS3_NUM_ERROR_INT_XSTATS; i++) { addr = (char *)&pf->abn_int_stats + hns3_error_int_stats_strings[i].offset; @@ -1084,6 +1197,13 @@ hns3_dev_xstats_get_names(struct rte_eth_dev *dev, count++; } + for (i = 0; i < HNS3_NUM_IMISSED_XSTATS; i++) { + snprintf(xstats_names[count].name, + sizeof(xstats_names[count].name), + "%s", hns3_imissed_stats_strings[i].name); + count++; + } + for (i = 0; i < HNS3_NUM_ERROR_INT_XSTATS; i++) { snprintf(xstats_names[count].name, sizeof(xstats_names[count].name), @@ -1315,7 +1435,6 @@ hns3_dev_xstats_reset(struct rte_eth_dev *dev) if (ret) return ret; - hns3_tqp_basic_stats_clear(dev); hns3_tqp_dfx_stats_clear(dev); /* Clear reset stats */ diff --git a/drivers/net/hns3/hns3_stats.h b/drivers/net/hns3/hns3_stats.h index d213be5..01b4f36 100644 --- a/drivers/net/hns3/hns3_stats.h +++ b/drivers/net/hns3/hns3_stats.h @@ -110,6 +110,10 @@ struct hns3_mac_stats { uint64_t mac_rx_ctrl_pkt_num; }; +struct hns3_rx_missed_stats { + uint64_t rpu_rx_drop_cnt; +}; + /* store statistics names and its offset in stats structure */ struct hns3_xstats_name_offset { char name[RTE_ETH_XSTATS_NAME_SIZE]; @@ -141,6 +145,9 @@ struct hns3_reset_stats; #define HNS3_TXQ_BASIC_STATS_FIELD_OFFSET(f) \ (offsetof(struct hns3_tx_basic_stats, f)) +#define HNS3_IMISSED_STATS_FIELD_OFFSET(f) \ + (offsetof(struct hns3_rx_missed_stats, f)) + int hns3_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats); int hns3_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, unsigned int n); @@ -160,5 +167,6 @@ int hns3_stats_reset(struct rte_eth_dev *dev); void hns3_error_int_stats_add(struct hns3_adapter *hns, const char *err); int hns3_tqp_stats_init(struct hns3_hw *hw); void hns3_tqp_stats_uninit(struct hns3_hw *hw); +int hns3_update_imissed_stats(struct hns3_hw *hw, bool is_clear); #endif /* _HNS3_STATS_H_ */ -- 2.7.4