DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Wei Hu (Xavier)" <huwei013@chinasoftinc.com>
To: <dev@dpdk.org>
Subject: [dpdk-dev] [PATCH] app/testpmd: fix Rx/Tx stats after clear stats command
Date: Fri, 24 Apr 2020 19:07:50 +0800	[thread overview]
Message-ID: <20200424110750.42456-1-huwei013@chinasoftinc.com> (raw)

From: Chengwen Feng <fengchengwen@huawei.com>

Currently, when running start/clear stats&xstats/stop command many times
based on testpmd application, there are incorrect RX/TX-packets stats as
below:
---------------------- Forward statistics for port 0  --------------
RX-packets: 18446744073709544808 RX-dropped: 0             ...ignore
TX-packets: 18446744073709536616 TX-dropped: 0             ...ignore
--------------------------------------------------------------------

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 <fengchengwen@huawei.com>
Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
---
 app/test-pmd/config.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 72f25d152..0d2375607 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -234,10 +234,16 @@ nic_stats_display(portid_t port_id)
 void
 nic_stats_clear(portid_t port_id)
 {
+	struct rte_port *port;
+
 	if (port_id_is_invalid(port_id, ENABLED_WARN)) {
 		print_valid_ports();
 		return;
 	}
+
+	port = &ports[port_id];
+	/* clear last port statistics because eth stats reset */
+	memset(&port->stats, 0, sizeof(port->stats));
 	rte_eth_stats_reset(port_id);
 	printf("\n  NIC statistics for port %d cleared\n", port_id);
 }
@@ -308,12 +314,17 @@ nic_xstats_display(portid_t port_id)
 void
 nic_xstats_clear(portid_t port_id)
 {
+	struct rte_port *port;
 	int ret;
 
 	if (port_id_is_invalid(port_id, ENABLED_WARN)) {
 		print_valid_ports();
 		return;
 	}
+
+	port = &ports[port_id];
+	/* clear last port statistics because eth xstats(include stats) reset */
+	memset(&port->stats, 0, sizeof(port->stats));
 	ret = rte_eth_xstats_reset(port_id);
 	if (ret != 0) {
 		printf("%s: Error: failed to reset xstats (port %u): %s",
-- 
2.23.0


             reply	other threads:[~2020-04-24 11:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-24 11:07 Wei Hu (Xavier) [this message]
2020-04-24 16:12 ` Ferruh Yigit
2020-04-26  1:36   ` Wei Hu (Xavier)
2020-04-26  1:58     ` Ferruh Yigit
2020-04-26  9:22   ` Wei Hu (Xavier)
2020-04-27 14:00     ` Ferruh Yigit
2020-04-28  8:42       ` Wei Hu (Xavier)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200424110750.42456-1-huwei013@chinasoftinc.com \
    --to=huwei013@chinasoftinc.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).