Support qevents
Subsystems (3)
v2 cover Support qevents
To allow configuring user-defined actions as a result of inner workings of a qdisc, a concept of qevents was recently introduced to the kernel. Qevents are attach points for TC blocks, where filters can be put that are executed as the packet hits well-defined points in the qdisc algorithms. The attached blocks can be shared, in a manner similar to clsact ingress and egress blocks, arbitrary classifiers with arbitrary actions can be put on them, etc.
For example:
# tc qdisc add dev eth0 root handle 1: \ red limit 500K avpkt 1K qevent early_drop block 10 # tc filter add block 10 \ matchall action mirred egress mirror dev eth1
This patch set introduces the corresponding iproute2 support. Patch #1 adds the new netlink attribute enumerators. Patch #2 adds a set of helpers to implement qevents, and #3 adds a generic documentation to tc.8. Patch #4 then adds two new qevents to the RED qdisc: mark and early_drop.
Changes from v1 to v2:
- Patch #3:
- s/early/early_drop/ in the example.
Changes from RFC to v1:
- Rename "tail" qevent to "tail_drop".
- Adapt to the new 100-column standard.
- Add a selftest
Petr Machata (4):
uapi: pkt_sched: Add two new RED attributes
tc: Add helpers to support qevent handling
man: tc: Describe qevents
tc: q_red: Add support for qevents "mark" and "early_drop"
include/uapi/linux/pkt_sched.h | 2 + man/man8/tc-red.8 | 18 ++- man/man8/tc.8 | 19 ++++ tc/Makefile | 1 + tc/q_red.c | 30 ++++- tc/tc_qevent.c | 202 +++++++++++++++++++++++++++++++++ tc/tc_qevent.h | 49 ++++++++ 7 files changed, 317 insertions(+), 4 deletions(-) create mode 100644 tc/tc_qevent.c create mode 100644 tc/tc_qevent.h
Signature · 1 line
2.20.1
PATCH v2 1/4 uapi: pkt_sched: Add two new RED attributes
--- include/uapi/linux/pkt_sched.h | 2 ++ 1 file changed, 2 insertions(+)
include/uapi/linux/pkt_sched.h +2 -0
@@ -257,6 +257,8 @@ enum {TCA_RED_STAB ,TCA_RED_MAX_P ,TCA_RED_FLAGS ,/* bitfield32 */ +TCA_RED_EARLY_DROP_BLOCK ,/* u32 */ +TCA_RED_MARK_BLOCK ,/* u32 */ __TCA_RED_MAX, };
Signature · 1 line
2.20.1
PATCH v2 4/4 tc: q_red: Add support for qevents "mark" and "early_drop"
In reply to Petr MachataThe "early_drop" qevent matches packets that have been early-dropped. The "mark" qevent matches packets that have been ECN-marked.
--- man/man8/tc-red.8 | 18 +++++++++++++++++- tc/q_red.c | 30 +++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 4 deletions(-)
man/man8/tc-red.8 +17 -1
@@ -17,7 +17,11 @@ packets rate .B ] [ probability chance -.B ] [ adaptive ] +.B ] [ adaptive ] [ qevent early_drop block +index +.B ] [ qevent mark block +index +.B ] .SH DESCRIPTION Random Early Detection is a classless qdisc which manages its queue size
@@ -134,6 +138,18 @@ Goal of Adaptive RED is to make 'probability' dynamic value between 1% and 50% t .B (max - min) / 2 .fi +.SH QEVENTS +See tc (8) for some general notes about qevents. The RED qdisc supports the +following qevents: + +.TP +early_drop +The associated block is executed when packets are early-dropped. This includes +non-ECT packets in ECN mode. +.TP +mark +The associated block is executed when packets are marked in ECN mode. + .SH EXAMPLE .P
tc/q_red.c +27 -3
@@ -22,6 +22,7 @@#include "utils.h" #include "tc_util.h" +#include "tc_qevent.h" #include "tc_red.h"
@@ -30,11 +31,20 @@ static void explain(void)fprintf (stderr,"Usage: ... red limit BYTES [min BYTES] [max BYTES] avpkt BYTES [burst PACKETS]\n" " [adaptive] [probability PROBABILITY] [bandwidth KBPS]\n" -" [ecn] [harddrop] [nodrop]\n" ); +" [ecn] [harddrop] [nodrop]\n" +" [qevent early_drop block IDX] [qevent mark block IDX]\n" ); }#define RED_SUPPORTED_FLAGS (TC_RED_HISTORIC_FLAGS | TC_RED_NODROP) +static struct qevent_plain qe_early_drop = {}; +static struct qevent_plain qe_mark = {}; +static struct qevent_util qevents[] = { +QEVENT ("early_drop" , plain, &qe_early_drop,TCA_RED_EARLY_DROP_BLOCK ), +QEVENT ("mark" , plain, &qe_mark,TCA_RED_MARK_BLOCK ), + {}, +}; +static int red_parse_opt (struct qdisc_util *qu,int argc,char **argv,struct nlmsghdr *n,const char *dev) {
@@ -51,6 +61,8 @@ static int red_parse_opt(struct qdisc_util *qu, int argc, char **argv,__u32 max_P;struct rtattr *tail; +qevents_init (qevents); +while (argc >0 ) {if (strcmp (*argv,"limit" ) ==0 ) {NEXT_ARG ();
@@ -109,6 +121,11 @@ static int red_parse_opt(struct qdisc_util *qu, int argc, char **argv, flags_bf.value |=TC_RED_ADAPTATIVE ; }else if (strcmp (*argv,"adaptive" ) ==0 ) { flags_bf.value |=TC_RED_ADAPTATIVE ; + }else if (matches (*argv,"qevent" ) ==0 ) { +NEXT_ARG (); +if (qevent_parse (qevents, &argc, &argv)) +return -1 ; +continue ; }else if (strcmp (*argv,"help" ) ==0 ) {explain ();return -1 ;
@@ -162,6 +179,8 @@ static int red_parse_opt(struct qdisc_util *qu, int argc, char **argv, max_P = probability *pow (2 ,32 );addattr_l (n,1024 ,TCA_RED_MAX_P , &max_P,sizeof (max_P));addattr_l (n,1024 ,TCA_RED_FLAGS , &flags_bf,sizeof (flags_bf)); +if (qevents_dump (qevents, n)) +return -1 ;addattr_nest_end (n, tail);return 0 ; }
@@ -203,12 +222,12 @@ static int red_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)print_uint (PRINT_JSON ,"min" ,NULL , qopt->qth_min);print_string (PRINT_FP ,NULL ,"min %s " ,sprint_size (qopt->qth_min, b2));print_uint (PRINT_JSON ,"max" ,NULL , qopt->qth_max); -print_string (PRINT_FP ,NULL ,"max %s " ,sprint_size (qopt->qth_max, b3)); +print_string (PRINT_FP ,NULL ,"max %s" ,sprint_size (qopt->qth_max, b3));tc_red_print_flags (qopt->flags);if (show_details) { -print_uint (PRINT_ANY ,"ewma" ,"ewma %u " , qopt->Wlog); +print_uint (PRINT_ANY ,"ewma" ," ewma %u " , qopt->Wlog);if (max_P)print_float (PRINT_ANY ,"probability" ,"probability %lg " , max_P /pow (2 ,32 ));
@@ -217,6 +236,11 @@ static int red_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)print_uint (PRINT_ANY ,"Scell_log" ,"Scell_log %u" , qopt->Scell_log); } + +qevents_init (qevents); +if (qevents_read (qevents, tb)) +return -1 ; +qevents_print (qevents, f);return 0 ; }
Signature · 1 line
2.20.1
PATCH v2 3/4 man: tc: Describe qevents
In reply to Petr MachataAdd some general remarks about qevents.
---
Notes:
v2:
- s/early/early_drop/ in the example.
man/man8/tc.8 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
man/man8/tc.8 +19 -0
@@ -254,6 +254,25 @@ Traffic control filter that matches every packet. See .BR tc-matchall (8) for details. +.SH QEVENTS +Qdiscs may invoke user-configured actions when certain interesting events +take place in the qdisc. Each qevent can either be unused, or can have a +block attached to it. To this block are then attached filters using the "tc +block BLOCK_IDX" syntax. The block is executed when the qevent associated +with the attachment point takes place. For example, packet could be +dropped, or delayed, etc., depending on the qdisc and the qevent in +question. + +For example: +.PP +.RS +tc qdisc add dev eth0 root handle 1: red limit 500K avpkt 1K \\ + qevent early_drop block 10 +.RE +.RS +tc filter add block 10 matchall action mirred egress mirror dev eth1 +.RE + .SH CLASSLESS QDISCS The classless qdiscs are: .TP
Signature · 1 line
2.20.1
PATCH v2 2/4 tc: Add helpers to support qevent handling
In reply to Petr MachataIntroduce a set of helpers to make it easy to add support for qevents into qdisc.
The idea behind this is that qevent types will be generally reused between qdiscs, rather than each having a completely idiosyncratic set of qevents. The qevent module holds functions for parsing, dumping and formatting of these common qevent types, and for dispatch to the appropriate set of handlers based on the qevent name.
--- tc/Makefile | 1 + tc/tc_qevent.c | 202 +++++++++++++++++++++++++++++++++++++++++++++++++ tc/tc_qevent.h | 49 ++++++++++++ 3 files changed, 252 insertions(+) create mode 100644 tc/tc_qevent.c create mode 100644 tc/tc_qevent.h
tc/Makefile +1 -0
@@ -122,6 +122,7 @@ TCLIB += tc_red.o TCLIB += tc_cbq.o TCLIB += tc_estimator.o TCLIB += tc_stab.o +TCLIB += tc_qevent.o CFLAGS += -DCONFIG_GACT -DCONFIG_GACT_PROB ifneq ($(IPT_LIB_DIR),)
tc/tc_qevent.c new file +202 -0
202 lines not on this page · raw message
tc/tc_qevent.h new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.20.1
David Ahern
AppliedQuoted 15 lines · Petr Machata
To allow configuring user-defined actions as a result of inner workings of a qdisc, a concept of qevents was recently introduced to the kernel. Qevents are attach points for TC blocks, where filters can be put that are executed as the packet hits well-defined points in the qdisc algorithms. The attached blocks can be shared, in a manner similar to clsact ingress and egress blocks, arbitrary classifiers with arbitrary actions can be put on them, etc.
For example:
# tc qdisc add dev eth0 root handle 1: \ red limit 500K avpkt 1K qevent early_drop block 10 # tc filter add block 10 \ matchall action mirred egress mirror dev eth1
Quoted 5 lines
This patch set introduces the corresponding iproute2 support. Patch #1 adds the new netlink attribute enumerators. Patch #2 adds a set of helpers to implement qevents, and #3 adds a generic documentation to tc.8. Patch #4 then adds two new qevents to the RED qdisc: mark and
early_drop.
applied to iproute2-next. Thanks