From 69986a823d789da3745ab6b4ca6d3e84fe76c1b1 Mon Sep 17 00:00:00 2001 From: Wei Zhao Date: Thu, 21 Sep 2017 14:32:23 +0800 Subject: [PATCH] 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 --- app/test-pmd/config.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 ?