Skip to content

Commit 7843e58

Browse files
[sflow + dropmon] added patches for the sFlow + dropmon feature. (sonic-net#276)
* [sflow + dropmon] added patches for the sFlow dropmon feature Signed-off-by: Vadym Hlushko <vadymh@nvidia.com> * [sflow + dropmon] fixed review comments - removed unnecessary patch, added upstream commit id to description Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
1 parent 86c4b66 commit 7843e58

3 files changed

+294
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
From ab65c38369aec72cbaac3e1c9d6731804edfc5b4 Mon Sep 17 00:00:00 2001
2+
From: Ido Schimmel <idosch@nvidia.com>
3+
Date: Sun, 14 Mar 2021 14:19:30 +0200
4+
5+
[backport of upstream commit a03e99d39f1943ec88f6fd3b0b9f34c20663d401]
6+
7+
Subject: [PATCH 1/2] psample: Encapsulate packet metadata in a struct
8+
9+
Currently, callers of psample_sample_packet() pass three metadata
10+
attributes: Ingress port, egress port and truncated size. Subsequent
11+
patches are going to add more attributes (e.g., egress queue occupancy),
12+
which also need an indication whether they are valid or not.
13+
14+
Encapsulate packet metadata in a struct in order to keep the number of
15+
arguments reasonable.
16+
17+
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
18+
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
19+
Signed-off-by: David S. Miller <davem@davemloft.net>
20+
---
21+
drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 8 ++++----
22+
include/net/psample.h | 14 +++++++++-----
23+
net/psample/psample.c | 6 ++++--
24+
net/sched/act_sample.c | 16 ++++++----------
25+
4 files changed, 23 insertions(+), 21 deletions(-)
26+
27+
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
28+
index 1a9978f50..323857943 100644
29+
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
30+
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
31+
@@ -2167,7 +2167,7 @@ void mlxsw_sp_sample_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
32+
{
33+
struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp->ports[local_port];
34+
struct mlxsw_sp_port_sample *sample;
35+
- u32 size;
36+
+ struct psample_metadata md = {};
37+
38+
if (unlikely(!mlxsw_sp_port)) {
39+
dev_warn_ratelimited(mlxsw_sp->bus_info->dev, "Port %d: sample skb received for non-existent port\n",
40+
@@ -2179,9 +2179,9 @@ void mlxsw_sp_sample_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
41+
sample = rcu_dereference(mlxsw_sp_port->sample);
42+
if (!sample)
43+
goto out_unlock;
44+
- size = sample->truncate ? sample->trunc_size : skb->len;
45+
- psample_sample_packet(sample->psample_group, skb, size,
46+
- mlxsw_sp_port->dev->ifindex, 0, sample->rate);
47+
+ md.trunc_size = sample->truncate ? sample->trunc_size : skb->len;
48+
+ md.in_ifindex = mlxsw_sp_port->dev->ifindex;
49+
+ psample_sample_packet(sample->psample_group, skb, sample->rate, &md);
50+
out_unlock:
51+
rcu_read_unlock();
52+
out:
53+
diff --git a/include/net/psample.h b/include/net/psample.h
54+
index 68ae16bb0..ac6dbfb38 100644
55+
--- a/include/net/psample.h
56+
+++ b/include/net/psample.h
57+
@@ -14,6 +14,12 @@ struct psample_group {
58+
struct rcu_head rcu;
59+
};
60+
61+
+struct psample_metadata {
62+
+ u32 trunc_size;
63+
+ int in_ifindex;
64+
+ int out_ifindex;
65+
+};
66+
+
67+
struct psample_group *psample_group_get(struct net *net, u32 group_num);
68+
void psample_group_take(struct psample_group *group);
69+
void psample_group_put(struct psample_group *group);
70+
@@ -21,15 +27,13 @@ void psample_group_put(struct psample_group *group);
71+
#if IS_ENABLED(CONFIG_PSAMPLE)
72+
73+
void psample_sample_packet(struct psample_group *group, struct sk_buff *skb,
74+
- u32 trunc_size, int in_ifindex, int out_ifindex,
75+
- u32 sample_rate);
76+
+ u32 sample_rate, const struct psample_metadata *md);
77+
78+
#else
79+
80+
static inline void psample_sample_packet(struct psample_group *group,
81+
- struct sk_buff *skb, u32 trunc_size,
82+
- int in_ifindex, int out_ifindex,
83+
- u32 sample_rate)
84+
+ struct sk_buff *skb, u32 sample_rate,
85+
+ const struct psample_metadata *md)
86+
{
87+
}
88+
89+
diff --git a/net/psample/psample.c b/net/psample/psample.c
90+
index 482c07f27..065bc887d 100644
91+
--- a/net/psample/psample.c
92+
+++ b/net/psample/psample.c
93+
@@ -356,9 +356,11 @@ static int psample_tunnel_meta_len(struct ip_tunnel_info *tun_info)
94+
#endif
95+
96+
void psample_sample_packet(struct psample_group *group, struct sk_buff *skb,
97+
- u32 trunc_size, int in_ifindex, int out_ifindex,
98+
- u32 sample_rate)
99+
+ u32 sample_rate, const struct psample_metadata *md)
100+
{
101+
+ int out_ifindex = md->out_ifindex;
102+
+ int in_ifindex = md->in_ifindex;
103+
+ u32 trunc_size = md->trunc_size;
104+
#ifdef CONFIG_INET
105+
struct ip_tunnel_info *tun_info;
106+
#endif
107+
diff --git a/net/sched/act_sample.c b/net/sched/act_sample.c
108+
index 3ebf9ede3..2fece01f2 100644
109+
--- a/net/sched/act_sample.c
110+
+++ b/net/sched/act_sample.c
111+
@@ -158,10 +158,8 @@ static int tcf_sample_act(struct sk_buff *skb, const struct tc_action *a,
112+
{
113+
struct tcf_sample *s = to_sample(a);
114+
struct psample_group *psample_group;
115+
+ struct psample_metadata md = {};
116+
int retval;
117+
- int size;
118+
- int iif;
119+
- int oif;
120+
121+
tcf_lastuse_update(&s->tcf_tm);
122+
bstats_cpu_update(this_cpu_ptr(s->common.cpu_bstats), skb);
123+
@@ -172,20 +170,18 @@ static int tcf_sample_act(struct sk_buff *skb, const struct tc_action *a,
124+
/* randomly sample packets according to rate */
125+
if (psample_group && (prandom_u32() % s->rate == 0)) {
126+
if (!skb_at_tc_ingress(skb)) {
127+
- iif = skb->skb_iif;
128+
- oif = skb->dev->ifindex;
129+
+ md.in_ifindex = skb->skb_iif;
130+
+ md.out_ifindex = skb->dev->ifindex;
131+
} else {
132+
- iif = skb->dev->ifindex;
133+
- oif = 0;
134+
+ md.in_ifindex = skb->dev->ifindex;
135+
}
136+
137+
/* on ingress, the mac header gets popped, so push it back */
138+
if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev))
139+
skb_push(skb, skb->mac_len);
140+
141+
- size = s->truncate ? s->trunc_size : skb->len;
142+
- psample_sample_packet(psample_group, skb, size, iif, oif,
143+
- s->rate);
144+
+ md.trunc_size = s->truncate ? s->trunc_size : skb->len;
145+
+ psample_sample_packet(psample_group, skb, s->rate, &md);
146+
147+
if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev))
148+
skb_pull(skb, skb->mac_len);
149+
--
150+
2.17.1
151+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
From d025a830ef465ea7b560742028b46dfc5c334cf1 Mon Sep 17 00:00:00 2001
2+
From: Ido Schimmel <idosch@nvidia.com>
3+
Date: Sun, 14 Mar 2021 14:19:31 +0200
4+
5+
[backport of upstream commit 07e1a5809b595df6e125504dff6245cb2c8ed3de]
6+
7+
Subject: [PATCH 2/2] psample: Add additional metadata attributes
8+
9+
Extend psample to report the following attributes when available:
10+
11+
* Output traffic class as a 16-bit value
12+
* Output traffic class occupancy in bytes as a 64-bit value
13+
* End-to-end latency of the packet in nanoseconds resolution
14+
* Software timestamp in nanoseconds resolution (always available)
15+
* Packet's protocol. Needed for packet dissection in user space (always
16+
available)
17+
18+
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
19+
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
20+
Signed-off-by: David S. Miller <davem@davemloft.net>
21+
---
22+
include/net/psample.h | 7 +++++++
23+
include/uapi/linux/psample.h | 7 +++++++
24+
net/psample/psample.c | 39 +++++++++++++++++++++++++++++++++++-
25+
3 files changed, 52 insertions(+), 1 deletion(-)
26+
27+
diff --git a/include/net/psample.h b/include/net/psample.h
28+
index ac6dbfb38..e328c5127 100644
29+
--- a/include/net/psample.h
30+
+++ b/include/net/psample.h
31+
@@ -18,6 +18,13 @@ struct psample_metadata {
32+
u32 trunc_size;
33+
int in_ifindex;
34+
int out_ifindex;
35+
+ u16 out_tc;
36+
+ u64 out_tc_occ; /* bytes */
37+
+ u64 latency; /* nanoseconds */
38+
+ u8 out_tc_valid:1,
39+
+ out_tc_occ_valid:1,
40+
+ latency_valid:1,
41+
+ unused:5;
42+
};
43+
44+
struct psample_group *psample_group_get(struct net *net, u32 group_num);
45+
diff --git a/include/uapi/linux/psample.h b/include/uapi/linux/psample.h
46+
index bff5032c9..0521691b6 100644
47+
--- a/include/uapi/linux/psample.h
48+
+++ b/include/uapi/linux/psample.h
49+
@@ -13,6 +13,13 @@ enum {
50+
PSAMPLE_ATTR_GROUP_REFCOUNT,
51+
PSAMPLE_ATTR_TUNNEL,
52+
53+
+ PSAMPLE_ATTR_PAD,
54+
+ PSAMPLE_ATTR_OUT_TC, /* u16 */
55+
+ PSAMPLE_ATTR_OUT_TC_OCC, /* u64, bytes */
56+
+ PSAMPLE_ATTR_LATENCY, /* u64, nanoseconds */
57+
+ PSAMPLE_ATTR_TIMESTAMP, /* u64, nanoseconds */
58+
+ PSAMPLE_ATTR_PROTO, /* u16 */
59+
+
60+
__PSAMPLE_ATTR_MAX
61+
};
62+
63+
diff --git a/net/psample/psample.c b/net/psample/psample.c
64+
index 065bc887d..118d5d2a8 100644
65+
--- a/net/psample/psample.c
66+
+++ b/net/psample/psample.c
67+
@@ -8,6 +8,7 @@
68+
#include <linux/kernel.h>
69+
#include <linux/skbuff.h>
70+
#include <linux/module.h>
71+
+#include <linux/timekeeping.h>
72+
#include <net/net_namespace.h>
73+
#include <net/sock.h>
74+
#include <net/netlink.h>
75+
@@ -358,6 +359,7 @@ static int psample_tunnel_meta_len(struct ip_tunnel_info *tun_info)
76+
void psample_sample_packet(struct psample_group *group, struct sk_buff *skb,
77+
u32 sample_rate, const struct psample_metadata *md)
78+
{
79+
+ ktime_t tstamp = ktime_get_real();
80+
int out_ifindex = md->out_ifindex;
81+
int in_ifindex = md->in_ifindex;
82+
u32 trunc_size = md->trunc_size;
83+
@@ -372,10 +374,15 @@ void psample_sample_packet(struct psample_group *group, struct sk_buff *skb,
84+
85+
meta_len = (in_ifindex ? nla_total_size(sizeof(u16)) : 0) +
86+
(out_ifindex ? nla_total_size(sizeof(u16)) : 0) +
87+
+ (md->out_tc_valid ? nla_total_size(sizeof(u16)) : 0) +
88+
+ (md->out_tc_occ_valid ? nla_total_size_64bit(sizeof(u64)) : 0) +
89+
+ (md->latency_valid ? nla_total_size_64bit(sizeof(u64)) : 0) +
90+
nla_total_size(sizeof(u32)) + /* sample_rate */
91+
nla_total_size(sizeof(u32)) + /* orig_size */
92+
nla_total_size(sizeof(u32)) + /* group_num */
93+
- nla_total_size(sizeof(u32)); /* seq */
94+
+ nla_total_size(sizeof(u32)) + /* seq */
95+
+ nla_total_size_64bit(sizeof(u64)) + /* timestamp */
96+
+ nla_total_size(sizeof(u16)); /* protocol */
97+
98+
#ifdef CONFIG_INET
99+
tun_info = skb_tunnel_info(skb);
100+
@@ -425,6 +432,36 @@ void psample_sample_packet(struct psample_group *group, struct sk_buff *skb,
101+
if (unlikely(ret < 0))
102+
goto error;
103+
104+
+ if (md->out_tc_valid) {
105+
+ ret = nla_put_u16(nl_skb, PSAMPLE_ATTR_OUT_TC, md->out_tc);
106+
+ if (unlikely(ret < 0))
107+
+ goto error;
108+
+ }
109+
+
110+
+ if (md->out_tc_occ_valid) {
111+
+ ret = nla_put_u64_64bit(nl_skb, PSAMPLE_ATTR_OUT_TC_OCC,
112+
+ md->out_tc_occ, PSAMPLE_ATTR_PAD);
113+
+ if (unlikely(ret < 0))
114+
+ goto error;
115+
+ }
116+
+
117+
+ if (md->latency_valid) {
118+
+ ret = nla_put_u64_64bit(nl_skb, PSAMPLE_ATTR_LATENCY,
119+
+ md->latency, PSAMPLE_ATTR_PAD);
120+
+ if (unlikely(ret < 0))
121+
+ goto error;
122+
+ }
123+
+
124+
+ ret = nla_put_u64_64bit(nl_skb, PSAMPLE_ATTR_TIMESTAMP,
125+
+ ktime_to_ns(tstamp), PSAMPLE_ATTR_PAD);
126+
+ if (unlikely(ret < 0))
127+
+ goto error;
128+
+
129+
+ ret = nla_put_u16(nl_skb, PSAMPLE_ATTR_PROTO,
130+
+ be16_to_cpu(skb->protocol));
131+
+ if (unlikely(ret < 0))
132+
+ goto error;
133+
+
134+
if (data_len) {
135+
int nla_len = nla_total_size(data_len);
136+
struct nlattr *nla;
137+
--
138+
2.17.1
139+

patch/series

+4
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ cisco-Enable-static-memory-reservation-for-OIRable-PCIe-de.patch
150150
cisco-npu-disable-other-bars.patch
151151
cisco-hwmon-pmbus_core-pec-support-check.patch
152152

153+
# sFlow + dropmon support
154+
0001-psample-Encapsulate-packet-metadata-in-a-struct.patch
155+
0002-psample-Add-additional-metadata-attributes.patch
156+
153157
#
154158
# Marvell platform patches for 4.19
155159
armhf_secondary_boot_online.patch

0 commit comments

Comments
 (0)