Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2360330rwb; Mon, 19 Sep 2022 04:06:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4bLOwqdXgGHT9vxChEpIQFZkQnOepArZGHLO3+08TC16EJn1jBOjrfeFpxyS9LCMonSQ1d X-Received: by 2002:a05:6402:270d:b0:452:2b68:90a0 with SMTP id y13-20020a056402270d00b004522b6890a0mr15260175edd.132.1663585582545; Mon, 19 Sep 2022 04:06:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663585582; cv=none; d=google.com; s=arc-20160816; b=I8JbEFjh/EgFgMsTXP8yn5oYy56jCsSDMgElHAgMEiQfjYrIiSVTvwA80S2a+sCfAi ug0pjSeRIG1g+C9W098GAoxko+X2+8ERMfURCVINoMnluMNMyOknRU3WEvlnPx5fNYhS b2vvYtZEiWFHqY9rqABE5OeTVPkGyVbL9pcUafWkywxzLqYr9c0UGMspf/XodQwOYVlW lcpc+O1/OvWa9uWsssNtxK2NLUam7M61xD1jtqujv3G89lY0l3M9tPGi5heXGgu00YjL CDI6C/CC8DJd7a/VSSgK62zZh4bNFd/KX3wQOTwsKyR1KWPF/5n75ljO+HdBfnPOh+1T NZVQ== 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=YOTFQL5o5jEs+7jz+YoectNCuvyj33bVFuVLnBFO+1g=; b=ZJcrc+ylkT7dYlyoeuznDDaO2ENBU2auYs+AveTbY/XyxTziKYOyO62WgxB7p8q8cw VBbNDKXKZoBaLV4x62F1xcCceEpiOOxuKcZcr0/fS9dHza0+A1T/AuNAqKoyvd7O1My6 a7IItYipt91B+6Rjdx4odv1ng76sEHGX1N+j7tv2Sz/zOelxjcoXbqUS2BN+69wzsfhh uG3UwzofSajcGoK6AxuLXtvoO/1nThIoQk6EGanTjRc5RrSyDUt+7K2btPhyx3wgtHsS jeHV8b1d0BscrkJx7BQlUAqtIBmSADtqd0oEmtzi4n079/Va3FNwUrMO0f8NHbkRAXSl +hKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=azxceoLc; 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 hq42-20020a1709073f2a00b00774195db4e7si15366631ejc.117.2022.09.19.04.05.57; Mon, 19 Sep 2022 04:06:22 -0700 (PDT) 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=azxceoLc; 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 S229746AbiISK0R (ORCPT + 99 others); Mon, 19 Sep 2022 06:26:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231497AbiISKUm (ORCPT ); Mon, 19 Sep 2022 06:20:42 -0400 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 DD8F02656D for ; Mon, 19 Sep 2022 03:18:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663582696; 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=YOTFQL5o5jEs+7jz+YoectNCuvyj33bVFuVLnBFO+1g=; b=azxceoLcfn5HwKDym5l4D8e4WrNvy+2kodEktAzKmaclBObQCtmEerxguPaFEUCizQ/nbH bXiKBK1OfEKdxNgN2yvqxJUH2b+OSqyST3ikVuK556tkonmxjXV8LmwynFx/kBpWa9hDKw v8CjAsDOyUUR0045pKmLWK6W0kM2AEs= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-265-tu2EifqwPQ6jw7edLgupoA-1; Mon, 19 Sep 2022 06:18:13 -0400 X-MC-Unique: tu2EifqwPQ6jw7edLgupoA-1 Received: by mail-ej1-f72.google.com with SMTP id qw34-20020a1709066a2200b0077e0e8a55b4so8273507ejc.21 for ; Mon, 19 Sep 2022 03:18:13 -0700 (PDT) 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; bh=YOTFQL5o5jEs+7jz+YoectNCuvyj33bVFuVLnBFO+1g=; b=dJJkgDIRG60RtMn2Zv82Me8MR3aTQbFwWDBJ3r7gqza5IVEp2sBZr3fbPK3L1uRsTz rSAVkcn4/mdoTgIn/2bA64/XdigfKKdDRA1dfqSrAqKwlPa6LPxyAcUI7u7jPiQ9Dfhx jNJ1yyc9OclIP4FaU5IuQAwQGvqyfoInzF/kxPFB2WP+X5v7HalQI9TG0wAe2UZTVvcn WFmiatWYGPGM0+7tWvqz7B43en+kzw2qFGBuVuv1XqVcMSy5SW5XNK1sS1zyy8SNIvRP +XryIrjsmJGe/FNpSJKe0YgqGel+7SN356xeFvOW+p+rq0Yg6D0ggHybeqs9+Ch3o7gF eRQg== X-Gm-Message-State: ACrzQf3SGTnoVwrQ4jINwqeBF+0s1+2PAbIwfr2AO78gKrIYtPjKdzIC ukLzRHwoEqsN8pBqb2lVU6y2HOWbkERqMfUmZG99jyjpf3WrT6dQ/PIJQAsYP0U/3lU3aV8VtvY ipAZ+pVn2Esrv26jHOu/kjeR5 X-Received: by 2002:a17:907:97cd:b0:780:6829:cb9d with SMTP id js13-20020a17090797cd00b007806829cb9dmr12454924ejc.344.1663582692264; Mon, 19 Sep 2022 03:18:12 -0700 (PDT) X-Received: by 2002:a17:907:97cd:b0:780:6829:cb9d with SMTP id js13-20020a17090797cd00b007806829cb9dmr12454906ejc.344.1663582691962; Mon, 19 Sep 2022 03:18:11 -0700 (PDT) Received: from [10.39.192.161] (5920ab7b.static.cust.trined.nl. [89.32.171.123]) by smtp.gmail.com with ESMTPSA id e10-20020a1709062c0a00b0073d638a7a89sm15454862ejh.99.2022.09.19.03.18.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Sep 2022 03:18:11 -0700 (PDT) From: Eelco Chaudron To: wangchuanlei Cc: pshelar@ovn.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dev@openvswitch.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [ovs-dev] [PATCH] [PATCH 1/2] openvswitch: Add support to count upall packets Date: Mon, 19 Sep 2022 12:18:10 +0200 X-Mailer: MailMate (1.14r5915) Message-ID: <4B4708B6-C411-4AAF-B141-5D0C275483F4@redhat.com> In-Reply-To: <20220914121459.1384093-1-wangchuanlei@inspur.com> References: <20220914121459.1384093-1-wangchuanlei@inspur.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 14 Sep 2022, at 14:14, wangchuanlei wrote: > Add support to count upcall packets on every interface. > I always encounter high cpu use of ovs-vswictchd, this > help to check which interface send too many packets > without open vlog/set switch, and have no influence > on datapath. Hi, I did not do a full review, but I think we should not try to make the sam= e mistake as before and embed a structure inside a netlink message. You are adding =E2=80=9Cstruct ovs_vport_upcall_stats=E2=80=9D but in the= ory, you could have just added the new entry to =E2=80=9Covs_vport_stats=E2= =80=9D. But this is breaking userspace as it expects an exact structure s= ize :( So I think the right approach would be to have =E2=80=9COVS_VPORT_ATTR_UP= CALL_STATS=E2=80=9D be an NLA_NESTED type, and have individual stat attri= butes as NLA_U64 (or whatever type you need). What is also confusing is that you use upcall_packets in ovs_vport_upcall= _stats, which to me are the total of up calls, but you called it n_missed= in your stats. I think you should try to avoid missed in the upcall path= , and just call it n_upcall_packets also. In addition, I think you should keep two types of statics, and make them = available, namely the total number of upcalls and the total of upcall fai= lures. Cheers, Eelco > Signed-off-by: wangchuanlei > --- > include/uapi/linux/openvswitch.h | 5 ++++ > net/openvswitch/datapath.c | 45 ++++++++++++++++++++++++++++++++= > net/openvswitch/datapath.h | 10 +++++++ > net/openvswitch/vport.c | 31 ++++++++++++++++++++++ > net/openvswitch/vport.h | 4 +++ > 5 files changed, 95 insertions(+) > > diff --git a/include/uapi/linux/openvswitch.h b/include/uapi/linux/open= vswitch.h > index 94066f87e9ee..8ec45511bc41 100644 > --- a/include/uapi/linux/openvswitch.h > +++ b/include/uapi/linux/openvswitch.h > @@ -126,6 +126,10 @@ struct ovs_vport_stats { > __u64 tx_dropped; /* no space available in linux */ > }; > > +struct ovs_vport_upcall_stats { > + __u64 upcall_packets; /* total packets upcalls */ > +}; > + > /* Allow last Netlink attribute to be unaligned */ > #define OVS_DP_F_UNALIGNED (1 << 0) > > @@ -277,6 +281,7 @@ 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 > }; > > diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c > index c8a9075ddd0a..f4e1f67dc57a 100644 > --- a/net/openvswitch/datapath.c > +++ b/net/openvswitch/datapath.c > @@ -209,6 +209,23 @@ 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) > +{ > + 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; > + u64 *stats_counter_upcall; > + > + vport_stats =3D this_cpu_ptr(p->vport_upcall_stats_percpu); > + stats_counter_upcall =3D &vport_stats->n_missed; > + u64_stats_update_begin(&vport_stats->syncp); > + (*stats_counter_upcall)++; > + u64_stats_update_end(&vport_stats->syncp); > + } > +} > + > void ovs_dp_detach_port(struct vport *p) > { > ASSERT_OVSL(); > @@ -216,6 +233,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); > } > @@ -308,6 +328,8 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_bu= ff *skb, > if (err) > goto err; > > + ovs_vport_upcalls(skb, upcall_info); > + > return 0; > > err: > @@ -1825,6 +1847,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_portids; > + } > + > err =3D ovs_dp_cmd_fill_info(dp, reply, info->snd_portid, > info->snd_seq, 0, OVS_DP_CMD_NEW); > BUG_ON(err < 0); > @@ -2068,6 +2097,7 @@ 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 vport_upcall_stats; > int err; > > ovs_header =3D genlmsg_put(skb, portid, seq, &dp_vport_genl_family, > @@ -2097,6 +2127,13 @@ static int ovs_vport_cmd_fill_info(struct vport = *vport, struct sk_buff *skb, > OVS_VPORT_ATTR_PAD)) > goto nla_put_failure; > > + ovs_vport_get_upcall_stats(vport, &vport_upcall_stats); > + if (nla_put_64bit(skb, OVS_VPORT_ATTR_UPCALL_STATS, > + sizeof(struct ovs_vport_upcall_stats), > + &vport_upcall_stats, > + OVS_VPORT_ATTR_PAD)) > + goto nla_put_failure; > + > if (ovs_vport_get_upcall_portids(vport, skb)) > goto nla_put_failure; > > @@ -2278,6 +2315,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); > diff --git a/net/openvswitch/datapath.h b/net/openvswitch/datapath.h > index 0cd29971a907..57fc002142a3 100644 > --- a/net/openvswitch/datapath.h > +++ b/net/openvswitch/datapath.h > @@ -50,6 +50,16 @@ struct dp_stats_percpu { > struct u64_stats_sync syncp; > }; > > +/** > + * struct vport_upcall_stats_percpu - per-cpu packet upcall statistics= for > + * a given vport. > + * @n_missed: Number of packets that upcall to userspace. > + */ > +struct vport_upcall_stats_percpu { > + u64 n_missed; > + 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..c05056f907f0 100644 > --- a/net/openvswitch/vport.c > +++ b/net/openvswitch/vport.c > @@ -284,6 +284,37 @@ 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_packets =3D 0; > + > + for_each_possible_cpu(i) { > + const struct vport_upcall_stats_percpu *percpu_upcall_stats; > + struct vport_upcall_stats_percpu local_stats; > + unsigned int start; > + > + percpu_upcall_stats =3D per_cpu_ptr(vport->vport_upcall_stats_percpu= , i); > + do { > + start =3D u64_stats_fetch_begin_irq(&percpu_upcall_stats->syncp); > + local_stats =3D *percpu_upcall_stats; > + } while (u64_stats_fetch_retry_irq(&percpu_upcall_stats->syncp, star= t)); > + > + stats->upcall_packets +=3D local_stats.n_missed; > + } > +} > + > /** > * ovs_vport_get_options - retrieve device options > * > diff --git a/net/openvswitch/vport.h b/net/openvswitch/vport.h > index 7d276f60c000..6defacd6d718 100644 > --- a/net/openvswitch/vport.h > +++ b/net/openvswitch/vport.h > @@ -32,6 +32,9 @@ 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_set_options(struct vport *, struct nlattr *options); > int ovs_vport_get_options(const struct vport *, struct sk_buff *); > > @@ -78,6 +81,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 > > _______________________________________________ > dev mailing list > dev@openvswitch.org > https://mail.openvswitch.org/mailman/listinfo/ovs-dev