From: Wei Zhao Date: Thu, 21 Sep 2017 06:32:23 +0000 (+0800) Subject: app/testpmd: fix packet throughput after stats reset X-Git-Tag: spdx-start~1883 X-Git-Url: http://git.droids-corp.org/?p=dpdk.git;a=commitdiff_plain;h=69986a823d789da3745ab6b4ca6d3e84fe76c1b1 app/testpmd: fix packet throughput after stats reset Testpmd calculates packet throughput by getting a diff of previous stats value and current one. If a stats clear called after previous sample taken, the diff will be negative and throughput calculation will be wrong. If current stats value is smaller than previous one, set throughput to zero. Fixes: 0e106980301d ("app/testpmd: show throughput in port stats") Cc: stable@dpdk.org Signed-off-by: Wei Zhao Reviewed-by: Ferruh Yigit --- diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index ca83eef99c..e8e311cb54 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -203,8 +203,10 @@ nic_stats_display(portid_t port_id) if (diff_cycles > 0) diff_cycles = prev_cycles[port_id] - diff_cycles; - diff_pkts_rx = stats.ipackets - prev_pkts_rx[port_id]; - diff_pkts_tx = stats.opackets - prev_pkts_tx[port_id]; + diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ? + (stats.ipackets - prev_pkts_rx[port_id]) : 0; + diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ? + (stats.opackets - prev_pkts_tx[port_id]) : 0; prev_pkts_rx[port_id] = stats.ipackets; prev_pkts_tx[port_id] = stats.opackets; mpps_rx = diff_cycles > 0 ?