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 CA0EFA00BE; Tue, 28 Apr 2020 13:50:55 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DC28F1D59E; Tue, 28 Apr 2020 13:50:54 +0200 (CEST) Received: from mail.chinasoftinc.com (unknown [114.113.233.8]) by dpdk.org (Postfix) with ESMTP id B96461D58F for ; Tue, 28 Apr 2020 13:50:52 +0200 (CEST) Received: from localhost.localdomain (114.119.4.74) by INCCAS002.ito.icss (10.168.0.60) with Microsoft SMTP Server id 14.3.487.0; Tue, 28 Apr 2020 19:50:50 +0800 From: "Wei Hu (Xavier)" To: Date: Tue, 28 Apr 2020 19:50:45 +0800 Message-ID: <20200428115045.31391-1-huwei013@chinasoftinc.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [114.119.4.74] Subject: [dpdk-dev] [PATCH V3] app/testpmd: fix forward stats after clear stats command 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)" Currently, when running start/clear stats&xstats/stop command many times based on testpmd application, there are incorrect forward Rx/Tx-packets stats as below: ---------------------- Forward statistics for port 0 -------------- RX-packets: 18446744073709544808 RX-dropped: 0 TX-packets: 18446744073709536616 TX-dropped: 0 -------------------------------------------------------------------- The root cause as below: 1. The struct rte_port of testpmd.h has a member variable "struct rte_eth_stats stats" to store the last port statistics. 2. When runnig start command, it execute cmd_start_parsed -> start_packet_forwarding -> fwd_stats_reset, which call rte_eth_stats_get API function to save current port statistics. 3. When running stop command, it execute fwd_stats_display, which call rte_eth_stats_get to get current port statistics, and then minus last port statistics. 4. If we run clear stats or xstats after start command, then run stop, it may display above incorrect stats because the current Rx/Tx-packets is lower than the last saved RX/TX-packets(uint64_t overflow). This patch fixes it by clearing last port statistics when executing "clear stats/xstats" command. Fixes: af75078fece3 ("first public release") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng Signed-off-by: Wei Hu (Xavier) --- v2 -> v3: Replace memset operation with calling rte_eth_stats_get API v1 -> v2: Update the title and the documentation (doc/guides/testpmd_app_ug/testpmd_funcs.rst) based on Ferruh Yigit's comment as below: http://patches.dpdk.org/patch/69252/ --- app/test-pmd/config.c | 26 ++++++++++++++++++++- doc/guides/testpmd_app_ug/testpmd_funcs.rst | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 72f25d152..712092fdb 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -234,11 +234,26 @@ nic_stats_display(portid_t port_id) void nic_stats_clear(portid_t port_id) { + int ret; + if (port_id_is_invalid(port_id, ENABLED_WARN)) { print_valid_ports(); return; } - rte_eth_stats_reset(port_id); + + ret = rte_eth_stats_reset(port_id); + if (ret != 0) { + printf("%s: Error: failed to reset stats (port %u): %s", + __func__, port_id, strerror(ret)); + return; + } + + ret = rte_eth_stats_get(port_id, &ports[port_id].stats); + if (ret != 0) { + printf("%s: Error: failed to get stats (port %u): %s", + __func__, port_id, strerror(ret)); + return; + } printf("\n NIC statistics for port %d cleared\n", port_id); } @@ -314,10 +329,19 @@ nic_xstats_clear(portid_t port_id) print_valid_ports(); return; } + ret = rte_eth_xstats_reset(port_id); if (ret != 0) { printf("%s: Error: failed to reset xstats (port %u): %s", __func__, port_id, strerror(ret)); + return; + } + + ret = rte_eth_stats_get(port_id, &ports[port_id].stats); + if (ret != 0) { + printf("%s: Error: failed to get stats (port %u): %s", + __func__, port_id, strerror(ret)); + return; } } diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index a360ecccf..ca83a2ab5 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -237,7 +237,7 @@ Display the RSS hash functions and RSS hash key of a port:: clear port ~~~~~~~~~~ -Clear the port statistics for a given port or for all ports:: +Clear the port statistics and forward engine statistics for a given port or for all ports:: testpmd> clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all) -- 2.23.0