Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: psample: allow using rate as probability

Although not explicitly documented in the psample module itself, the
definition of PSAMPLE_ATTR_SAMPLE_RATE seems inherited from act_sample.

Quoting tc-sample(8):
"RATE of 100 will lead to an average of one sampled packet out of every
100 observed."

With this semantics, the rates that we can express with an unsigned
32-bits number are very unevenly distributed and concentrated towards
"sampling few packets".
For example, we can express a probability of 2.32E-8% but we
cannot express anything between 100% and 50%.

For sampling applications that are capable of sampling a decent
amount of packets, this sampling rate semantics is not very useful.

Add a new flag to the uAPI that indicates that the sampling rate is
expressed in scaled probability, this is:
- 0 is 0% probability, no packets get sampled.
- U32_MAX is 100% probability, all packets get sampled.

Reviewed-by: Aaron Conole <aconole@redhat.com>
Acked-by: Eelco Chaudron <echaudro@redhat.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
Link: https://patch.msgid.link/20240704085710.353845-5-amorenoz@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Adrian Moreno and committed by
Jakub Kicinski
7b1b2b60 c35d86a2

+14 -2
+2 -1
include/net/psample.h
··· 24 24 u8 out_tc_valid:1, 25 25 out_tc_occ_valid:1, 26 26 latency_valid:1, 27 - unused:5; 27 + rate_as_probability:1, 28 + unused:4; 28 29 const u8 *user_cookie; 29 30 u32 user_cookie_len; 30 31 };
+9 -1
include/uapi/linux/psample.h
··· 8 8 PSAMPLE_ATTR_ORIGSIZE, 9 9 PSAMPLE_ATTR_SAMPLE_GROUP, 10 10 PSAMPLE_ATTR_GROUP_SEQ, 11 - PSAMPLE_ATTR_SAMPLE_RATE, 11 + PSAMPLE_ATTR_SAMPLE_RATE, /* u32, ratio between observed and 12 + * sampled packets or scaled probability 13 + * if PSAMPLE_ATTR_SAMPLE_PROBABILITY 14 + * is set. 15 + */ 12 16 PSAMPLE_ATTR_DATA, 13 17 PSAMPLE_ATTR_GROUP_REFCOUNT, 14 18 PSAMPLE_ATTR_TUNNEL, ··· 24 20 PSAMPLE_ATTR_TIMESTAMP, /* u64, nanoseconds */ 25 21 PSAMPLE_ATTR_PROTO, /* u16 */ 26 22 PSAMPLE_ATTR_USER_COOKIE, /* binary, user provided data */ 23 + PSAMPLE_ATTR_SAMPLE_PROBABILITY,/* no argument, interpret rate in 24 + * PSAMPLE_ATTR_SAMPLE_RATE as a 25 + * probability scaled 0 - U32_MAX. 26 + */ 27 27 28 28 __PSAMPLE_ATTR_MAX 29 29 };
+3
net/psample/psample.c
··· 497 497 md->user_cookie)) 498 498 goto error; 499 499 500 + if (md->rate_as_probability) 501 + nla_put_flag(skb, PSAMPLE_ATTR_SAMPLE_PROBABILITY); 502 + 500 503 genlmsg_end(nl_skb, data); 501 504 genlmsg_multicast_netns(&psample_nl_family, group->net, nl_skb, 0, 502 505 PSAMPLE_NL_MCGRP_SAMPLE, GFP_ATOMIC);