From patchwork Thu Dec 15 01:01:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangchuanlei X-Patchwork-Id: 1715995 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NXYpy4DqZz23yy for ; Thu, 15 Dec 2022 12:02:02 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 27E2A81FD6; Thu, 15 Dec 2022 01:02:00 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 27E2A81FD6 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id i_OzJWcqnjgu; Thu, 15 Dec 2022 01:01:56 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id EB05181FCC; Thu, 15 Dec 2022 01:01:55 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org EB05181FCC Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A1B59C0033; Thu, 15 Dec 2022 01:01:55 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id CAB5CC002D for ; Thu, 15 Dec 2022 01:01:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id A486A41897 for ; Thu, 15 Dec 2022 01:01:53 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org A486A41897 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jdSsfvhBg8Oq for ; Thu, 15 Dec 2022 01:01:50 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 664884188A Received: from ssh248.corpemail.net (ssh248.corpemail.net [210.51.61.248]) by smtp4.osuosl.org (Postfix) with ESMTPS id 664884188A for ; Thu, 15 Dec 2022 01:01:50 +0000 (UTC) Received: from ([60.208.111.195]) by ssh248.corpemail.net ((D)) with ASMTP (SSL) id JDQ00145; Thu, 15 Dec 2022 09:01:45 +0800 Received: from localhost.localdomain (10.180.204.101) by jtjnmail201607.home.langchao.com (10.100.2.7) with Microsoft SMTP Server id 15.1.2507.16; Thu, 15 Dec 2022 09:01:45 +0800 From: wangchuanlei To: , Date: Wed, 14 Dec 2022 20:01:40 -0500 Message-ID: <20221215010140.127922-1-wangchuanlei@inspur.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Originating-IP: [10.180.204.101] tUid: 202212150901452185e5095177547db3bd15236c1d6e71 X-Abuse-Reports-To: service@corp-email.com Abuse-Reports-To: service@corp-email.com X-Complaints-To: service@corp-email.com X-Report-Abuse-To: service@corp-email.com Subject: [ovs-dev] [PATCH] [ovs-dev v2] dpctl: Add support to count upcall packets 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" Add support to count upall packets, when kmod of openvswitch upcall to count the number of packets for upcall succeed and failed, which is a better way to see how many packets upcalled on every interfaces. Signed-off-by: wangchuanlei --- ovs-kmod already support count statistic of interfaces, the link is below, and this commit is the part of userspace. https://git.kernel.org/netdev/net-next/c/1933ea365aa7 note: this commit is compatible with old version of ovs-kmod, that is, even the kernel is older, and do not support count statistic of interfaces(do not have the code in upper link), this part of code is still stable! include/linux/openvswitch.h | 19 +++++++++++++++++++ include/openvswitch/netdev.h | 3 +++ lib/dpctl.c | 2 ++ lib/dpif-netlink.c | 13 +++++++++++++ lib/dpif-netlink.h | 2 ++ lib/netdev-linux.c | 8 ++++++++ 6 files changed, 47 insertions(+) diff --git a/include/linux/openvswitch.h b/include/linux/openvswitch.h index 8bb5abdc8..ff2dc58c9 100644 --- a/include/linux/openvswitch.h +++ b/include/linux/openvswitch.h @@ -141,6 +141,11 @@ struct ovs_vport_stats { __u64 tx_dropped; /* no space available in linux */ }; +struct ovs_vport_upcall_stats { + uint64_t tx_success; /* total packets upcall succeed */ + uint64_t tx_fail; /* total packets upcall failed */ +}; + /* Allow last Netlink attribute to be unaligned */ #define OVS_DP_F_UNALIGNED (1 << 0) @@ -301,11 +306,25 @@ enum ovs_vport_attr { OVS_VPORT_ATTR_PAD, OVS_VPORT_ATTR_IFINDEX, OVS_VPORT_ATTR_NETNSID, + OVS_VPORT_ATTR_UPCALL_STATS, __OVS_VPORT_ATTR_MAX }; #define OVS_VPORT_ATTR_MAX (__OVS_VPORT_ATTR_MAX - 1) +/** +* enum OVS_VPORT_UPCALL_ATTR -- attributes for %OVS_VPORT_UPCALL* commands +* @OVS_VPORT_UPCALL_ATTR_SUCCESS: 64-bit upcall success packets. +* @OVS_VPORT_UPCALL_ATTR_FAIL: 64-bit upcall fail packets. +*/ +enum OVS_VPORT_UPCALL_ATTR { + OVS_VPORT_UPCALL_ATTR_SUCCESS, + OVS_VPORT_UPCALL_ATTR_FAIL, + __OVS_VPORT_UPCALL_ATTR_MAX, +}; + +#define OVS_VPORT_UPCALL_ATTR_MAX (__OVS_VPORT_UPCALL_ATTR_MAX - 1) + enum { OVS_VXLAN_EXT_UNSPEC, OVS_VXLAN_EXT_GBP, diff --git a/include/openvswitch/netdev.h b/include/openvswitch/netdev.h index 0c10f7b48..ed1bf73dc 100644 --- a/include/openvswitch/netdev.h +++ b/include/openvswitch/netdev.h @@ -87,6 +87,9 @@ struct netdev_stats { uint64_t rx_oversize_errors; uint64_t rx_fragmented_errors; uint64_t rx_jabber_errors; + + uint64_t tx_upcall_success; + uint64_t tx_upcall_fail; }; /* Structure representation of custom statistics counter */ diff --git a/lib/dpctl.c b/lib/dpctl.c index 29041fa3e..d03d84fe6 100644 --- a/lib/dpctl.c +++ b/lib/dpctl.c @@ -742,6 +742,8 @@ show_dpif(struct dpif *dpif, struct dpctl_params *dpctl_p) dpctl_print(dpctl_p, "\n"); print_stat(dpctl_p, " collisions:", s.collisions); + print_stat(dpctl_p, " upcall success:", s.tx_upcall_success); + print_stat(dpctl_p, " upcall fail:", s.tx_upcall_fail); dpctl_print(dpctl_p, "\n"); print_stat(dpctl_p, " RX bytes:", s.rx_bytes); diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 026b0daa8..492f0ee72 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -4685,6 +4685,8 @@ dpif_netlink_vport_from_ofpbuf(struct dpif_netlink_vport *vport, .optional = true }, [OVS_VPORT_ATTR_OPTIONS] = { .type = NL_A_NESTED, .optional = true }, [OVS_VPORT_ATTR_NETNSID] = { .type = NL_A_U32, .optional = true }, + [OVS_VPORT_ATTR_UPCALL_STATS] = { .type = NL_A_NESTED, + .optional = true }, }; dpif_netlink_vport_init(vport); @@ -4716,6 +4718,17 @@ dpif_netlink_vport_from_ofpbuf(struct dpif_netlink_vport *vport, if (a[OVS_VPORT_ATTR_STATS]) { vport->stats = nl_attr_get(a[OVS_VPORT_ATTR_STATS]); } + if (a[OVS_VPORT_ATTR_UPCALL_STATS]) { + const struct nlattr *nla; + size_t left; + NL_NESTED_FOR_EACH (nla, left, a[OVS_VPORT_ATTR_UPCALL_STATS]) { + if (nl_attr_type(nla) == OVS_VPORT_UPCALL_ATTR_SUCCESS) { + vport->upcall_stats.tx_success = nl_attr_get_u64(nla); + } else if (nl_attr_type(nla) == OVS_VPORT_UPCALL_ATTR_FAIL) { + vport->upcall_stats.tx_fail = nl_attr_get_u64(nla); + } + } + } if (a[OVS_VPORT_ATTR_OPTIONS]) { vport->options = nl_attr_get(a[OVS_VPORT_ATTR_OPTIONS]); vport->options_len = nl_attr_get_size(a[OVS_VPORT_ATTR_OPTIONS]); diff --git a/lib/dpif-netlink.h b/lib/dpif-netlink.h index 24294bc42..1dae371a0 100644 --- a/lib/dpif-netlink.h +++ b/lib/dpif-netlink.h @@ -44,6 +44,8 @@ struct dpif_netlink_vport { uint32_t n_upcall_pids; const uint32_t *upcall_pids; /* OVS_VPORT_ATTR_UPCALL_PID. */ const struct ovs_vport_stats *stats; /* OVS_VPORT_ATTR_STATS. */ + struct ovs_vport_upcall_stats upcall_stats; + /* OVS_VPORT_ATTR_UPCALL_STATS. */ const struct nlattr *options; /* OVS_VPORT_ATTR_OPTIONS. */ size_t options_len; }; diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 59e8dc0ae..dc2865466 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -2181,6 +2181,13 @@ netdev_stats_from_ovs_vport_stats(struct netdev_stats *dst, dst->tx_window_errors = 0; } +static void netdev_stats_from_ovs_vport_upcall_stats(struct netdev_stats *dst, + struct dpif_netlink_vport *vport) +{ + dst->tx_upcall_success = vport->upcall_stats.tx_success; + dst->tx_upcall_fail = vport->upcall_stats.tx_fail; +} + static int get_stats_via_vport__(const struct netdev *netdev, struct netdev_stats *stats) { @@ -2197,6 +2204,7 @@ get_stats_via_vport__(const struct netdev *netdev, struct netdev_stats *stats) } netdev_stats_from_ovs_vport_stats(stats, reply.stats); + netdev_stats_from_ovs_vport_upcall_stats(stats, &reply); ofpbuf_delete(buf);