Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp8571880rwb; Thu, 24 Nov 2022 01:07:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf68mqyibDElL37j5rk9lRSH6lv9Azp2Kx5clNKLh3vgqJJ6mC6fr9On9e+ScxPtfOLJIN5n X-Received: by 2002:a17:906:2b56:b0:78d:b6ea:174e with SMTP id b22-20020a1709062b5600b0078db6ea174emr17644909ejg.95.1669280836288; Thu, 24 Nov 2022 01:07:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669280836; cv=none; d=google.com; s=arc-20160816; b=HMlhBfpJh+9JJ2b4cdf9z7m0VJldq4dPhyxVbibkjVNE28G5Pi0QT8a+tyUaZSf3qE jnP+2O04Y5kBtG3LkegwyTbXrMZbBkfXkU4LCiBDoYT1icfHOoQVljx6LeANmzaXFqzN FFf79cXiR8FZ36AMhZB5vAhUwYLIRpsAnGoPl3NEmVVDKIMHV5Z3zxEd6jdXJXM9TFDu W5UU1r9HK2XtpM0lE9TMY8SmDJxFmX4fpLB7NtPxqHLwDoJKUr5xpg750ajRWtIS6iHa BOqZbAGo1On+4w94GEjcMIkabay4xVOfH4baV5GenWoSLPa+H/3RysGq7Y7tz9XR1fNd PkMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7BSse/GgXaVxARdtvwgzu/g/qTpt/zDvXHsnw/jcFqA=; b=aGRPdwNAYJFYvVQ1GUvWY6iyiYbHltxO7GbsFhST/aukqXZcdYUoJ2krZxgQudZWt1 ybw5x5vpC6Iw5TX8Ov1FtveQTOCnQee7ZxEPtDhUVDsosm6Oh3bf+3/DQZt3UUQjSCyQ Mxfv8cGQ7HghmeMJJCQ9eDhTVbAV1+QPN1T0+AuJQhza03VMzg4O1EDbCaWUNXlLaa1g gEXy7jaHnqaGY02kYAY9muPK19zQMr4NRGL9w2V/qXgZH855LdNqhC/9H16vf4xOM9BF DTuBa7DXMhC747FSfWetMSNMo+plXsjrf5/3+fMfvEeTbEMG3aswUnvZWGhAmno4m65U hJfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VAWZp+ig; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e5-20020a17090658c500b00783645da4e5si52455ejs.582.2022.11.24.01.06.41; Thu, 24 Nov 2022 01:07:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VAWZp+ig; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229685AbiKXH7r (ORCPT + 87 others); Thu, 24 Nov 2022 02:59:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbiKXH7o (ORCPT ); Thu, 24 Nov 2022 02:59:44 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 633D7C5627 for ; Wed, 23 Nov 2022 23:58:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669276725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7BSse/GgXaVxARdtvwgzu/g/qTpt/zDvXHsnw/jcFqA=; b=VAWZp+igEEw/Ipp49xAAFI6QuOkO+nvv2FGzGatiQ+u9xNUu2EzWacHPiZi1f4GHQ+4yQW xIZXQ9cDDrnJ63AqSBmshUjtg/onP1QHT5+SeKjsctWXWqzaTlZ0LEIPeH9qlOYUg/pL3l QYO6Z+Rc07rzDmIu2vzIb/46UgWT4is= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-263-qKxmjG-aP2u_-xtKpjk0Rg-1; Thu, 24 Nov 2022 02:58:44 -0500 X-MC-Unique: qKxmjG-aP2u_-xtKpjk0Rg-1 Received: by mail-ed1-f69.google.com with SMTP id r12-20020a05640251cc00b00463699c95aeso517201edd.18 for ; Wed, 23 Nov 2022 23:58:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7BSse/GgXaVxARdtvwgzu/g/qTpt/zDvXHsnw/jcFqA=; b=V4PSNDLZPmpeGoNPP60hk6So2GqAfDMDiEoiU8ZOo/1iowhKa9gBlgT2hOk1IHm53Z ju6E/QeF1FjcykUAJjwMwkUaK89ANUqkUcu9fEcUuMBmK/rZFSDv/vdDErt57KgYD1Us qqwGVIj9UjAsp+7Z0QSL7v58pBqDJ+bjTzLc0wZKMPtQs2Myes9e6owqhgC48y6X/nXU O0mEZgm9BrLvgD3SwOt4DOLyGVTh1X00BYwEzLZyXZNmqRv1CWyUZW3YBTvW9ktopj79 1JMXOntjZvLwKlj1ugUZcNRdwDx2dC2oaQKHiuZZIEu4r1JQ2HhqY5z5brzO6/PogPb2 2i0g== X-Gm-Message-State: ANoB5pkBt/r1oFPhnMQhNZ8fB1Zbnf/Jn4OphvVJxrYHBVykr3TPWxgK Efmv8QSWx/FENqjaRpKd6XFPYVROBzD9X3sSlCpjHsqaVjekUi72SCIyC9UuyWU6DEEYfQrRpZS NpdhiH8aE/JpXJyjVSbKIYCU5 X-Received: by 2002:a17:906:4e14:b0:7b2:b15e:8ab1 with SMTP id z20-20020a1709064e1400b007b2b15e8ab1mr19062773eju.659.1669276722781; Wed, 23 Nov 2022 23:58:42 -0800 (PST) X-Received: by 2002:a17:906:4e14:b0:7b2:b15e:8ab1 with SMTP id z20-20020a1709064e1400b007b2b15e8ab1mr19062751eju.659.1669276722416; Wed, 23 Nov 2022 23:58:42 -0800 (PST) Received: from [10.39.192.198] (5920ab7b.static.cust.trined.nl. [89.32.171.123]) by smtp.gmail.com with ESMTPSA id t12-20020aa7d4cc000000b00458824aee80sm217618edr.38.2022.11.23.23.58.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Nov 2022 23:58:41 -0800 (PST) From: Eelco Chaudron To: wangchuanlei Cc: pabeni@redhat.com, pshelar@ovn.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, wangpeihui@inspur.com, netdev@vger.kernel.org, dev@openvswitch.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] [openvswitch v4] openvswitch: Add support to count upcall packets Date: Thu, 24 Nov 2022 08:58:40 +0100 X-Mailer: MailMate (1.14r5927) Message-ID: <2E85BE67-3BA6-465B-8F39-218E733DBEFA@redhat.com> In-Reply-To: <20221123091843.3414856-1-wangchuanlei@inspur.com> References: <20221123091843.3414856-1-wangchuanlei@inspur.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23 Nov 2022, at 10:18, wangchuanlei wrote: > Add support to count upall packets, when kmod of openvswitch > upcall to userspace , here count the number of packets for > upcall succeed and failed, which is a better way to see how > many packets upcalled to userspace(ovs-vswitchd) on every > interfaces. > > Here optimize the function used by comments of v3. > > Changes since v3: > - use nested NLA_NESTED attribute in netlink message > > Changes since v2: > - add count of upcall failed packets > > Changes since v1: > - add count of upcall succeed packets There is already a review from Alexander, so I only commented on some thi= ngs that caught my attention after glazing over the patch. I will do a full review of the next revisions. //Eelco > Signed-off-by: wangchuanlei > --- > include/uapi/linux/openvswitch.h | 19 ++++++++++++ > net/openvswitch/datapath.c | 52 ++++++++++++++++++++++++++++++++= > net/openvswitch/datapath.h | 12 ++++++++ > net/openvswitch/vport.c | 48 +++++++++++++++++++++++++++++ > net/openvswitch/vport.h | 6 ++++ > 5 files changed, 137 insertions(+) > > diff --git a/include/uapi/linux/openvswitch.h b/include/uapi/linux/open= vswitch.h > index 94066f87e9ee..fa13bce15fae 100644 > --- a/include/uapi/linux/openvswitch.h > +++ b/include/uapi/linux/openvswitch.h > @@ -126,6 +126,11 @@ struct ovs_vport_stats { > __u64 tx_dropped; /* no space available in linux */ > }; > > +struct ovs_vport_upcall_stats { > + uint64_t upcall_success; /* total packets upcalls succeed */ > + uint64_t upcall_fail; /* total packets upcalls failed */ > +}; This is no longer a user API data structure, so it should be removed from= this include. > + > /* Allow last Netlink attribute to be unaligned */ > #define OVS_DP_F_UNALIGNED (1 << 0) > > @@ -277,11 +282,25 @@ enum ovs_vport_attr { > OVS_VPORT_ATTR_PAD, > OVS_VPORT_ATTR_IFINDEX, > OVS_VPORT_ATTR_NETNSID, > + OVS_VPORT_ATTR_UPCALL_STATS, /* struct ovs_vport_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* comm= ands > + * @OVS_VPORT_UPCALL_SUCCESS: 64-bit upcall success packets. > + * @OVS_VPORT_UPCALL_FAIL: 64-bit upcall fail packets. > + */ > +enum ovs_vport_upcall_attr { > + OVS_VPORT_UPCALL_SUCCESS, /* 64-bit upcall success packets */ > + OVS_VPORT_UPCALL_FAIL, /* 64-bit upcall fail packets */ > + __OVS_VPORT_UPCALL_MAX > +}; Here you have comments ending with and without a dot (.), maybe make it u= niform. Maybe the comment on the structure can be removed as they are explained r= ight above? > + > +#define OVS_VPORT_UPCALL_MAX (__OVS_VPORT_UPCALL_MAX-1) > + > enum { > OVS_VXLAN_EXT_UNSPEC, > OVS_VXLAN_EXT_GBP, /* Flag or __u32 */ > diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c > index c8a9075ddd0a..5254c51cfa60 100644 > --- a/net/openvswitch/datapath.c > +++ b/net/openvswitch/datapath.c > @@ -209,6 +209,25 @@ static struct vport *new_vport(const struct vport_= parms *parms) > return vport; > } > > +static void ovs_vport_upcalls(struct sk_buff *skb, > + const struct dp_upcall_info *upcall_info, > + bool upcall_success) > +{ > + if (upcall_info->cmd =3D=3D OVS_PACKET_CMD_MISS || > + upcall_info->cmd =3D=3D OVS_PACKET_CMD_ACTION) { > + const struct vport *p =3D OVS_CB(skb)->input_vport; > + struct vport_upcall_stats_percpu *vport_stats; > + > + vport_stats =3D this_cpu_ptr(p->vport_upcall_stats_percpu); > + u64_stats_update_begin(&vport_stats->syncp); > + if (upcall_success) > + u64_stats_inc(&vport_stats->n_upcall_success); > + else > + u64_stats_inc(&vport_stats->n_upcall_fail); > + u64_stats_update_end(&vport_stats->syncp); > + } > +} > + > void ovs_dp_detach_port(struct vport *p) > { > ASSERT_OVSL(); > @@ -216,6 +235,9 @@ void ovs_dp_detach_port(struct vport *p) > /* First drop references to device. */ > hlist_del_rcu(&p->dp_hash_node); > > + /* Free percpu memory */ > + free_percpu(p->vport_upcall_stats_percpu); > + > /* Then destroy it. */ > ovs_vport_del(p); > } > @@ -305,6 +327,8 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_bu= ff *skb, > err =3D queue_userspace_packet(dp, skb, key, upcall_info, cutlen); > else > err =3D queue_gso_packets(dp, skb, key, upcall_info, cutlen); > + > + ovs_vport_upcalls(skb, upcall_info, !err); > if (err) > goto err; > > @@ -1825,6 +1849,13 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, s= truct genl_info *info) > goto err_destroy_portids; > } > > + vport->vport_upcall_stats_percpu =3D > + netdev_alloc_pcpu_stats(struct vport_upcall_stats_percpu); > + if (!vport->vport_upcall_stats_percpu) { > + err =3D -ENOMEM; > + goto err_destroy_upcall_stats; > + } > + > err =3D ovs_dp_cmd_fill_info(dp, reply, info->snd_portid, > info->snd_seq, 0, OVS_DP_CMD_NEW); > BUG_ON(err < 0); > @@ -1837,6 +1868,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, st= ruct genl_info *info) > ovs_notify(&dp_datapath_genl_family, reply, info); > return 0; > > +err_destroy_upcall_stats: > err_destroy_portids: > kfree(rcu_dereference_raw(dp->upcall_portids)); > err_unlock_and_destroy_meters: > @@ -2068,6 +2100,8 @@ static int ovs_vport_cmd_fill_info(struct vport *= vport, struct sk_buff *skb, > { > struct ovs_header *ovs_header; > struct ovs_vport_stats vport_stats; > + struct ovs_vport_upcall_stats stat; > + struct nlattr *nla; > int err; > > ovs_header =3D genlmsg_put(skb, portid, seq, &dp_vport_genl_family, > @@ -2097,6 +2131,15 @@ static int ovs_vport_cmd_fill_info(struct vport = *vport, struct sk_buff *skb, > OVS_VPORT_ATTR_PAD)) > goto nla_put_failure; > > + nla =3D nla_nest_start_noflag(skb, OVS_VPORT_ATTR_UPCALL_STATS); > + if (!nla) > + goto nla_put_failure; > + > + ovs_vport_get_upcall_stats(vport, &stat); > + if (ovs_vport_put_upcall_stats(skb, &stat)) > + goto nla_put_failure; > + nla_nest_end(skb, nla); > + > if (ovs_vport_get_upcall_portids(vport, skb)) > goto nla_put_failure; > > @@ -2278,6 +2321,14 @@ static int ovs_vport_cmd_new(struct sk_buff *skb= , struct genl_info *info) > goto exit_unlock_free; > } > > + vport->vport_upcall_stats_percpu =3D > + netdev_alloc_pcpu_stats(struct vport_upcall_stats_percpu); > + > + if (!vport->vport_upcall_stats_percpu) { > + err =3D -ENOMEM; > + goto exit_unlock_free; > + } > + > err =3D ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), > info->snd_portid, info->snd_seq, 0, > OVS_VPORT_CMD_NEW, GFP_KERNEL); > @@ -2507,6 +2558,7 @@ static const struct nla_policy vport_policy[OVS_V= PORT_ATTR_MAX + 1] =3D { > [OVS_VPORT_ATTR_OPTIONS] =3D { .type =3D NLA_NESTED }, > [OVS_VPORT_ATTR_IFINDEX] =3D { .type =3D NLA_U32 }, > [OVS_VPORT_ATTR_NETNSID] =3D { .type =3D NLA_S32 }, > + [OVS_VPORT_ATTR_UPCALL_STATS] =3D { .type =3D NLA_NESTED }, > }; > > static const struct genl_small_ops dp_vport_genl_ops[] =3D { > diff --git a/net/openvswitch/datapath.h b/net/openvswitch/datapath.h > index 0cd29971a907..933dec5e4175 100644 > --- a/net/openvswitch/datapath.h > +++ b/net/openvswitch/datapath.h > @@ -50,6 +50,18 @@ struct dp_stats_percpu { > struct u64_stats_sync syncp; > }; > > +/** > + * struct vport_upcall_stats_percpu - per-cpu packet upcall statistics= for > + * a given vport. > + * @n_upcall_success: Number of packets that upcall to userspace succe= ed. > + * @n_upcall_fail: Number of packets that upcall to userspace faile= d. > + */ > +struct vport_upcall_stats_percpu { > + u64_stats_t n_upcall_success; > + u64_stats_t n_upcall_fail; > + struct u64_stats_sync syncp; > +}; > + > /** > * struct dp_nlsk_pids - array of netlink portids of for a datapath. > * This is used when OVS_DP_F_DISPATCH_UPCALL_PE= R_CPU > diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c > index 82a74f998966..a69c9356b57c 100644 > --- a/net/openvswitch/vport.c > +++ b/net/openvswitch/vport.c > @@ -284,6 +284,54 @@ void ovs_vport_get_stats(struct vport *vport, stru= ct ovs_vport_stats *stats) > stats->tx_packets =3D dev_stats->tx_packets; > } > > +/** > + * ovs_vport_get_upcall_stats - retrieve upcall stats > + * > + * @vport: vport from which to retrieve the stats > + * @ovs_vport_upcall_stats: location to store stats > + * > + * Retrieves upcall stats for the given device. > + * > + * Must be called with ovs_mutex or rcu_read_lock. > + */ > +void ovs_vport_get_upcall_stats(struct vport *vport, struct ovs_vport_= upcall_stats *stats) > +{ > + int i; > + > + stats->upcall_success =3D 0; > + stats->upcall_fail =3D 0; > + > + for_each_possible_cpu(i) { > + const struct vport_upcall_stats_percpu *percpu_upcall_stats; > + unsigned int start; > + > + percpu_upcall_stats =3D per_cpu_ptr(vport->vport_upcall_stats_percpu= , i); > + do { > + start =3D u64_stats_fetch_begin(&percpu_upcall_stats->syncp); > + stats->upcall_success +=3D > + u64_stats_read(&percpu_upcall_stats->n_upcall_success); > + stats->upcall_fail +=3D u64_stats_read(&percpu_upcall_stats->n_upca= ll_fail); > + } while (u64_stats_fetch_retry(&percpu_upcall_stats->syncp, start));= > + } > +} > + > +int ovs_vport_put_upcall_stats(struct sk_buff *skb, > + struct ovs_vport_upcall_stats *stats) > +{ > + if (nla_put_u64_64bit(skb, OVS_VPORT_UPCALL_SUCCESS, stats->upcall_su= ccess, > + OVS_VPORT_ATTR_PAD)) > + goto nla_put_failure; > + > + if (nla_put_u64_64bit(skb, OVS_VPORT_UPCALL_FAIL, stats->upcall_fail,= > + OVS_VPORT_ATTR_PAD)) > + goto nla_put_failure; > + > + return 0; > + > +nla_put_failure: > + return -EMSGSIZE; > +} > + > /** > * ovs_vport_get_options - retrieve device options > * > diff --git a/net/openvswitch/vport.h b/net/openvswitch/vport.h > index 7d276f60c000..02cf8c589588 100644 > --- a/net/openvswitch/vport.h > +++ b/net/openvswitch/vport.h > @@ -32,6 +32,11 @@ struct vport *ovs_vport_locate(const struct net *net= , const char *name); > > void ovs_vport_get_stats(struct vport *, struct ovs_vport_stats *); > > +void ovs_vport_get_upcall_stats(struct vport *vport, > + struct ovs_vport_upcall_stats *stats); > +int ovs_vport_put_upcall_stats(struct sk_buff *skb, > + struct ovs_vport_upcall_stats *stats); > + > int ovs_vport_set_options(struct vport *, struct nlattr *options); > int ovs_vport_get_options(const struct vport *, struct sk_buff *); > > @@ -78,6 +83,7 @@ struct vport { > struct hlist_node hash_node; > struct hlist_node dp_hash_node; > const struct vport_ops *ops; > + struct vport_upcall_stats_percpu __percpu *vport_upcall_stats_percpu;= > > struct list_head detach_list; > struct rcu_head rcu; > -- = > 2.27.0