Skip to content

Commit 0d9597e

Browse files
[sflow + dropmon] added patches for the sFlow dropmon feature
Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
1 parent 10ef390 commit 0d9597e

4 files changed

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

patch/series

+5
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ cisco-Enable-static-memory-reservation-for-OIRable-PCIe-de.patch
140140
cisco-npu-disable-other-bars.patch
141141
cisco-hwmon-pmbus_core-pec-support-check.patch
142142

143+
# sFlow + dropmon support
144+
0001-psample-Encapsulate-packet-metadata-in-a-struct.patch
145+
0002-psample-Add-additional-metadata-attributes.patch
146+
0003-psample-added-define-PSAMPLE_MD_EXTENDED_ATTR.patch
147+
143148
#
144149
# Marvell platform patches for 4.19
145150
armhf_secondary_boot_online.patch

0 commit comments

Comments
 (0)