From patchwork Tue Jun 2 07:50:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaozhanxu X-Patchwork-Id: 1302246 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=163.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=pg5c+uLi; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49bl3h0sfbz9sSg for ; Tue, 2 Jun 2020 18:06:08 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 728D8860F2; Tue, 2 Jun 2020 08:06:06 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hewxq2COx_bR; Tue, 2 Jun 2020 08:06:05 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id E19BA85A5A; Tue, 2 Jun 2020 08:06:05 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C67B2C0178; Tue, 2 Jun 2020 08:06:05 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id C94DDC016E for ; Tue, 2 Jun 2020 08:06:03 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id B3F0885A4B for ; Tue, 2 Jun 2020 08:06:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4769Y6mOTQSx for ; Tue, 2 Jun 2020 08:06:03 +0000 (UTC) X-Greylist: delayed 00:15:14 by SQLgrey-1.7.6 Received: from m12-12.163.com (m12-12.163.com [220.181.12.12]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 92A8A85A00 for ; Tue, 2 Jun 2020 08:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=qSzCP nszaZm4yIFK3/qUGXhHVp/CIOsuHvtXtUaCiwE=; b=pg5c+uLiRZubEqg41nzUb W7KMFzQaG9avsKH4LDr0t4gHDPCLZF5+50ppTWkJIZ+RrdfSugSchfvQl9HKjODn m2fdJpzrxHDmDfkbePDVWqDb7Sxsu750YeCdsHYaI2PTZi9UC9N5QYcYcUAQoiys siLIfMRIA/Y5/9Wvfaw0Uc= Received: from zhaozhanxu.local.info (unknown [103.37.140.45]) by smtp8 (Coremail) with SMTP id DMCowAC3uVnUBNZeFQJEEg--.13327S2; Tue, 02 Jun 2020 15:50:44 +0800 (CST) From: zhaozhanxu To: ovs-dev@openvswitch.org Date: Tue, 2 Jun 2020 15:50:36 +0800 Message-Id: <20200602075036.78112-1-zhaozhanxu@163.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CM-TRANSID: DMCowAC3uVnUBNZeFQJEEg--.13327S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7JFy7Jr1fZw17ZF1fKF13XFb_yoW8Jry8pF Z8C34fta4UZFsFy3W7uFyfXr18Ca4agF47GayIq34Yk3ZIgr909ryDKrWF9rWUGFWxCan2 yw1Dtw4akFWkArJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziHmhxUUUUU= X-Originating-IP: [103.37.140.45] X-CM-SenderInfo: p2kd06xkdq53i6rwjhhfrp/xtbBFBE3qFaD7H-MfwAAsv Cc: zhaozhanxu Subject: [ovs-dev] [PATCH] ofproto: Fix statistics of datapath operations. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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 Acked-by: Ian Stokes --- 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;