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.
Showing the changes to include/uapi (1 of 3 files). Show all
Unified · Split
| @@ -8,7 +8,11 @@ enum { · 7 unmodified lines | |||
| 8 | PSAMPLE_ATTR_ORIGSIZE, | 8 | PSAMPLE_ATTR_ORIGSIZE, |
| 9 | PSAMPLE_ATTR_SAMPLE_GROUP, | 9 | PSAMPLE_ATTR_SAMPLE_GROUP, |
| 10 | PSAMPLE_ATTR_GROUP_SEQ, | 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 | PSAMPLE_ATTR_DATA, | 16 | PSAMPLE_ATTR_DATA, |
| 13 | PSAMPLE_ATTR_GROUP_REFCOUNT, | 17 | PSAMPLE_ATTR_GROUP_REFCOUNT, |
| 14 | PSAMPLE_ATTR_TUNNEL, | 18 | PSAMPLE_ATTR_TUNNEL, |
| @@ -20,6 +24,10 @@ enum { · 5 unmodified lines | |||
| 20 | PSAMPLE_ATTR_TIMESTAMP, /* u64, nanoseconds */ | 24 | PSAMPLE_ATTR_TIMESTAMP, /* u64, nanoseconds */ |
| 21 | PSAMPLE_ATTR_PROTO, /* u16 */ | 25 | PSAMPLE_ATTR_PROTO, /* u16 */ |
| 22 | PSAMPLE_ATTR_USER_COOKIE, /* binary, user provided data */ | 26 | PSAMPLE_ATTR_USER_COOKIE, /* binary, user provided data */ |
| 27 | PSAMPLE_ATTR_SAMPLE_PROBABILITY,/* no argument, interpret rate in | ||
| 28 | * PSAMPLE_ATTR_SAMPLE_RATE as a | ||
| 29 | * probability scaled 0 - U32_MAX. | ||
| 30 | */ | ||
| 23 | 31 | ||
| 24 | __PSAMPLE_ATTR_MAX | 32 | __PSAMPLE_ATTR_MAX |
| 25 | }; | 33 | }; |