[ovs-dev] [PATCH] ofproto: Fix statistics of datapath operations.

zhaozhanxu zhaozhanxu at 163.com
Tue Jun 2 07:50:36 UTC 2020


If 'stats->n_packets' is less than 'op->ukey->stats.n_packets',
the calculation result will be wrong.
'stats->n_bytes' is the same.

Signed-off-by: zhaozhanxu <zhaozhanxu at 163.com>
---
 ofproto/ofproto-dpif-upcall.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c
index 5e08ef10d..80678f843 100644
--- a/ofproto/ofproto-dpif-upcall.c
+++ b/ofproto/ofproto-dpif-upcall.c
@@ -2385,8 +2385,12 @@ push_dp_ops(struct udpif *udpif, struct ukey_op *ops, size_t n_ops)
             transition_ukey(op->ukey, UKEY_EVICTED);
             push->used = MAX(stats->used, op->ukey->stats.used);
             push->tcp_flags = stats->tcp_flags | op->ukey->stats.tcp_flags;
-            push->n_packets = stats->n_packets - op->ukey->stats.n_packets;
-            push->n_bytes = stats->n_bytes - op->ukey->stats.n_bytes;
+            push->n_packets = (stats->n_packets > op->ukey->stats.n_packets
+                               ? stats->n_packets - op->ukey->stats.n_packets
+                               : 0);
+            push->n_bytes = (stats->n_bytes > op->ukey->stats.n_bytes
+                             ? stats->n_bytes - op->ukey->stats.n_bytes
+                             : 0);
             ovs_mutex_unlock(&op->ukey->mutex);
         } else {
             push = stats;
-- 
2.20.1




More information about the dev mailing list