Netdev List
 help / color / mirror / Atom feed
From: Adrian Moreno <amorenoz@redhat.com>
To: netdev@vger.kernel.org, dev@openvswitch.org
Cc: Adrian Moreno <amorenoz@redhat.com>,
	cmi@nvidia.com, yotam.gi@gmail.com, i.maximets@ovn.org,
	aconole@redhat.com, echaudro@redhat.com, horms@kernel.org
Subject: [RFC PATCH 4/4] net:openvswitch: Add multicasted packets to stats
Date: Thu,  7 Mar 2024 16:18:48 +0100	[thread overview]
Message-ID: <20240307151849.394962-5-amorenoz@redhat.com> (raw)
In-Reply-To: <20240307151849.394962-1-amorenoz@redhat.com>

If we mix multicasted and unicasted statistics, there could be a serious
discrepancy between the stats reported by the kernel and the ones read
by userspace, leading to increased confusion.

Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
---
 include/uapi/linux/openvswitch.h | 2 ++
 net/openvswitch/datapath.c       | 9 ++++++---
 net/openvswitch/vport.c          | 8 ++++++++
 net/openvswitch/vport.h          | 1 +
 4 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/include/uapi/linux/openvswitch.h b/include/uapi/linux/openvswitch.h
index 77525a1c648a..25e35b627fe5 100644
--- a/include/uapi/linux/openvswitch.h
+++ b/include/uapi/linux/openvswitch.h
@@ -288,10 +288,12 @@ enum ovs_vport_attr {
  * enum ovs_vport_upcall_attr - attributes for %OVS_VPORT_UPCALL* commands
  * @OVS_VPORT_UPCALL_SUCCESS: 64-bit upcall success packets.
  * @OVS_VPORT_UPCALL_FAIL: 64-bit upcall fail packets.
+ * @OVS_VPORT_UPCALL_MCAST: 64-bit multicasted upcall packets.
  */
 enum ovs_vport_upcall_attr {
 	OVS_VPORT_UPCALL_ATTR_SUCCESS,
 	OVS_VPORT_UPCALL_ATTR_FAIL,
+	OVS_VPORT_UPCALL_ATTR_MCAST,
 	__OVS_VPORT_UPCALL_ATTR_MAX
 };
 
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index 5171aefa6a7c..a457a07adb52 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -217,7 +217,7 @@ static struct vport *new_vport(const struct vport_parms *parms)
 
 static void ovs_vport_update_upcall_stats(struct sk_buff *skb,
 					  const struct dp_upcall_info *upcall_info,
-					  bool upcall_result)
+					  bool mcast, bool upcall_result)
 {
 	struct vport *p = OVS_CB(skb)->input_vport;
 	struct vport_upcall_stats_percpu *stats;
@@ -229,7 +229,10 @@ static void ovs_vport_update_upcall_stats(struct sk_buff *skb,
 	stats = this_cpu_ptr(p->upcall_stats);
 	u64_stats_update_begin(&stats->syncp);
 	if (upcall_result)
-		u64_stats_inc(&stats->n_success);
+		if (mcast)
+			u64_stats_inc(&stats->n_mcast);
+		else
+			u64_stats_inc(&stats->n_success);
 	else
 		u64_stats_inc(&stats->n_fail);
 	u64_stats_update_end(&stats->syncp);
@@ -336,7 +339,7 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb,
 	else
 		err = queue_gso_packets(dp, skb, key, upcall_info, cutlen);
 
-	ovs_vport_update_upcall_stats(skb, upcall_info, !err);
+	ovs_vport_update_upcall_stats(skb, upcall_info, mcast, !err);
 	if (err)
 		goto err;
 
diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
index 972ae01a70f7..b78287e443d1 100644
--- a/net/openvswitch/vport.c
+++ b/net/openvswitch/vport.c
@@ -315,6 +315,7 @@ int ovs_vport_get_upcall_stats(struct vport *vport, struct sk_buff *skb)
 
 	__u64 tx_success = 0;
 	__u64 tx_fail = 0;
+	__u64 mcast = 0;
 
 	for_each_possible_cpu(i) {
 		const struct vport_upcall_stats_percpu *stats;
@@ -325,6 +326,7 @@ int ovs_vport_get_upcall_stats(struct vport *vport, struct sk_buff *skb)
 			start = u64_stats_fetch_begin(&stats->syncp);
 			tx_success += u64_stats_read(&stats->n_success);
 			tx_fail += u64_stats_read(&stats->n_fail);
+			mcast  += u64_stats_read(&stats->n_mcast);
 		} while (u64_stats_fetch_retry(&stats->syncp, start));
 	}
 
@@ -343,6 +345,12 @@ int ovs_vport_get_upcall_stats(struct vport *vport, struct sk_buff *skb)
 		nla_nest_cancel(skb, nla);
 		return -EMSGSIZE;
 	}
+
+	if (nla_put_u64_64bit(skb, OVS_VPORT_UPCALL_ATTR_MCAST, mcast,
+			      OVS_VPORT_ATTR_PAD)) {
+		nla_nest_cancel(skb, nla);
+		return -EMSGSIZE;
+	}
 	nla_nest_end(skb, nla);
 
 	return 0;
diff --git a/net/openvswitch/vport.h b/net/openvswitch/vport.h
index 3e71ca8ad8a7..e9817b2b3b61 100644
--- a/net/openvswitch/vport.h
+++ b/net/openvswitch/vport.h
@@ -151,6 +151,7 @@ struct vport_upcall_stats_percpu {
 	struct u64_stats_sync syncp;
 	u64_stats_t n_success;
 	u64_stats_t n_fail;
+	u64_stats_t n_mcast;
 };
 
 struct vport *ovs_vport_alloc(int priv_size, const struct vport_ops *,
-- 
2.44.0


  parent reply	other threads:[~2024-03-07 15:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07 15:18 [RFC PATCH 0/4] net: openvswitch: Add sample multicasting Adrian Moreno
2024-03-07 15:18 ` [RFC PATCH 1/4] net:openvswitch: Support multicasting userspace Adrian Moreno
2024-03-07 15:18 ` [RFC PATCH 2/4] openvswitch:trace: Add ovs_dp_monitor tracepoint Adrian Moreno
2024-03-07 15:18 ` [RFC PATCH 3/4] net:openvswitch: Avoid extra copy if no listeners Adrian Moreno
2024-03-07 15:18 ` Adrian Moreno [this message]
2024-03-07 16:54 ` [RFC PATCH 0/4] net: openvswitch: Add sample multicasting Ilya Maximets
2024-03-07 20:59   ` Adrian Moreno
2024-03-07 21:29     ` Ilya Maximets
2024-03-08 14:24       ` Ilya Maximets
2024-03-13  8:28         ` Adrian Moreno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240307151849.394962-5-amorenoz@redhat.com \
    --to=amorenoz@redhat.com \
    --cc=aconole@redhat.com \
    --cc=cmi@nvidia.com \
    --cc=dev@openvswitch.org \
    --cc=echaudro@redhat.com \
    --cc=horms@kernel.org \
    --cc=i.maximets@ovn.org \
    --cc=netdev@vger.kernel.org \
    --cc=yotam.gi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox