From patchwork Mon Jun 29 09:31:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wenxu X-Patchwork-Id: 1318791 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.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ucloud.cn Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49wMgl5qyMz9sQx for ; Mon, 29 Jun 2020 19:31:31 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id B100388C40; Mon, 29 Jun 2020 09:31:29 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iFToiPTF0x0X; Mon, 29 Jun 2020 09:31:28 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id 0E24488AA7; Mon, 29 Jun 2020 09:31:28 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id F3C7EC07FF; Mon, 29 Jun 2020 09:31:27 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 271B2C016E for ; Mon, 29 Jun 2020 09:31:26 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 15D2188832 for ; Mon, 29 Jun 2020 09:31:26 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ITwoiq4DJUVl for ; Mon, 29 Jun 2020 09:31:25 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from m9784.mail.qiye.163.com (m9784.mail.qiye.163.com [220.181.97.84]) by whitealder.osuosl.org (Postfix) with ESMTPS id CB14088822 for ; Mon, 29 Jun 2020 09:31:24 +0000 (UTC) Received: from localhost.localdomain (unknown [123.59.132.129]) by m9784.mail.qiye.163.com (Hmail) with ESMTPA id 1B4B2420B4; Mon, 29 Jun 2020 17:31:19 +0800 (CST) From: wenxu@ucloud.cn To: simon.horman@netronome.com Date: Mon, 29 Jun 2020 17:31:18 +0800 Message-Id: <1593423078-27413-1-git-send-email-wenxu@ucloud.cn> X-Mailer: git-send-email 1.8.3.1 X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZSVVJQ0NLS0tKS01DSkpOSVlXWShZQU lCN1dZLVlBSVdZDwkaFQgSH1lBWR0iNQs4HD8zSjRMFQ8rFx5NUFANOhxWVlVCQk4oSVlXWQkOFx 4IWUFZNTQpNjo3JCkuNz5ZV1kWGg8SFR0UWUFZNDBZBg++ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6OjY6Tjo6PDgzLy1CEz0cARAM FSwaCRdVSlVKTkJIT0lIS0xCSkNDVTMWGhIXVQweFQMOOw4YFxQOH1UYFUVZV1kSC1lBWUpJSFVO QlVKSElVSklCWVdZCAFZQUlPS0M3Bg++ X-HM-Tid: 0a72ff6aa6f12086kuqy1b4b2420b4 Cc: dev@openvswitch.org Subject: [ovs-dev] [PATCH] lib/tc: only update the stats for non-empty counter 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: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: wenxu A packet with first frag and execute act_ct action. The packet will stole by defrag. So the stats counter for "gact action goto chain" will always 0. The openvswitch update each action in order. So the flower stats finally alway be zero. The rule will be delete adter max-idle time even there are packet executing the action. ovs-appctl dpctl/dump-flows recirc_id(0),in_port(1),eth_type(0x0800),ipv4(dst=11.0.0.7,frag=first), packets:0, bytes:0, used:5.390s, actions:ct(zone=1,nat),recirc(0x4) filter protocol ip pref 2 flower chain 0 handle 0x2 eth_type ipv4 dst_ip 1.1.1.1 ip_flags frag/firstfrag skip_hw not_in_hw action order 1: ct zone 1 nat pipe index 2 ref 1 bind 1 installed 11 sec used 1 sec Action statistics: Sent 15000 bytes 11 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 cookie e04106c2ac41769b278edaa9b5309960 action order 2: gact action goto chain 1 random type none pass val 0 index 2 ref 1 bind 1 installed 11 sec used 11 sec Action statistics: Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 cookie e04106c2ac41769b278edaa9b5309960 Signed-off-by: wenxu --- lib/tc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/tc.c b/lib/tc.c index c2ab775..c96d095 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -1726,8 +1726,10 @@ nl_parse_single_action(struct nlattr *action, struct tc_flower *flower, } bs = nl_attr_get_unspec(stats_attrs[TCA_STATS_BASIC], sizeof *bs); - put_32aligned_u64(&stats->n_packets, bs->packets); - put_32aligned_u64(&stats->n_bytes, bs->bytes); + if (bs->packets) { + put_32aligned_u64(&stats->n_packets, bs->packets); + put_32aligned_u64(&stats->n_bytes, bs->bytes); + } return 0; }