net/sched: Introduce the taprio scheduler
Subsystems (4)
Vinicius Costa Gomes
maintainercover net/sched: Introduce the taprio scheduler
Hi,
This series provides a set of interfaces that can be used by applications that require (time-based) Scheduled Transmission of packets. It is comprised by 3 new components to the kernel:
- etf: the per-queue TxTime-Based scheduling qdisc;
- taprio: the per-port Time-Aware scheduler qdisc;
- SO_TXTIME: a socket option + cmsg APIs.
ETF and SO_TXTIME are already applied[1] into the net-next tree. This is the remaining piece.
Overview
========
The CBS qdisc proposal RFC [2] included some rough ideas about the design and API of a "taprio" (Time Aware Priority) qdisc. The idea of presenting the taprio ideas at that point (almost 10 months ago!) was to show our vision of how things would fit together going forward.
Quoted 1 line
From that concept stage to this (almost) realised stage the main
differences are:
- As of now, taprio is a software only implementation of a schedule
executor;
- Instead of taprio centralising all the time based decisions, taprio can work together with ETF (the Earliest TxTime First), a qdisc meant to use the LaunchTime (or similar) feature of various network controllers;
In a nutshell, taprio is a root qdisc that can execute a predefined schedule, etf is a qdisc that provides time based admission control and "earliest deadline first" dequeue mode, and SO_TXTIME is a socket option that is used for enabling a socket to be used for time-based transmission and configuring its parameters.
taprio
======
This scheduler allows the network administrator to configure schedules for classes of traffic, the configuration interface is similar to what IEEE 802.1Qbv-2015 defines.
Example configuration:
$ tc qdisc add dev enp2s0 parent root handle 100 taprio \ num_tc 3 \ map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 \ queues 1@0 1@1 2@2 \ sched-file ~/gates.sched \ base-time 1528743495910289987 \ clockid CLOCK_TAI
This qdisc borrows a few concepts from mqprio and so, most the parameters are similar to mqprio. The main difference is the 'sched-file' parameter, one example on a schedule file would be:
gates.sched
-----------
S 01 300000
S 02 300000
S 04 300000
The format of each line is:
<CMD> <GATE MASK> <INTERVAL>
The only supported <CMD> is "S", which means "SetGateStates", following the IEEE 802.1Qbv-2015 definition (Table 8-6). <GATE MASK> is a bitmask where each bit is a associated with a traffic class, so bit 0 (the least significant bit) being "on" means that traffic class 0 is "active" for that schedule entry. <INTERVAL> is a time duration in nanoseconds that specifies for how long that state defined by <CMD> and <GATE MASK> should be held before moving to the next entry.
This schedule is circular, that is, after the last entry is executed it starts from the first one, indefinitely.
The other parameters can be defined as follows:
- base-time: allows that multiple systems can have synchronised
schedules, it specifies the instant when the schedule starts;
- clockid: specifies the reference clock to be used;
A more complete example can be found here, with instructions of how to test it:
https://gist.github.com/jeez/bd3afeff081ba64a695008dd8215866f [3]
The basic design of the scheduler is simple, after we calculate the first expiration of the hrtimer, we set the next expiration to be the previous plus the current entry's interval. At each time the function runs, we set the current_entry, which has a gate_mask (that controls which traffic classes are allowed to "go out" during each interval), and we reuse this callback to "kick" the qdisc (this is the reason that the usual qdisc watchdog isn't used).
Known Issues
============
- As taprio is a software only implementation, and there's another layer of queuing in the network controller, packets can still leave the controller outside their "correct" windows. This happens mostly for low-priority classes, and is more evident if they are 'starved' by the higher priority ones;
- There's no support for changing the schedule during runtime;
This series is also hosted on github and can be found at [4]. The companion iproute2 patches can be found at [5].
Cheers,
Vinicius Costa Gomes
maintainerRFC 1/1 net/sched: Introduce the taprio scheduler
This scheduler allows the network administrator to configure schedules for classes of traffic, the configuration interface is similar to what IEEE 802.1Qbv-2015 defines.
Example configuration:
$ tc qdisc add dev enp2s0 parent root handle 100 taprio \
num_tc 3 \
map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 \
queues 1@0 1@1 2@2 \
sched-file ~/gates.sched \
base-time 1000000 \
clockid CLOCK_TAIThis qdisc borrows a few concepts from mqprio and most the parameters are similar to mqprio. The main difference is the 'sched-file' parameter, one example of a schedule file would be:
gates.sched
-----------
S 01 300000
S 02 300000
S 04 300000
The format of each line is:
<CMD> <GATE MASK> <INTERVAL>
The only supported <CMD> is "S", which means "SetGateStates", following the IEEE 802.1Qbv-2015 definition (Table 8-6). <GATE MASK> is a bitmask where each bit is a associated with a traffic class, so bit 0 (the least significant bit) being "on" means that traffic class 0 is "active" for that schedule entry. <INTERVAL> is a time duration in nanoseconds that specifies for how long that state defined by <CMD> and <GATE MASK> should be held before moving to the next entry.
This schedule is circular, that is, after the last entry is executed it starts from the first one, indefinitely.
The other parameters can be defined as follows:
- base-time: allows that multiple systems can have synchronized schedules, it specifies the instant when the schedule starts;
- clockid: specifies the reference clock to be used;
--- include/uapi/linux/pkt_sched.h | 49 ++ net/sched/Kconfig | 11 + net/sched/Makefile | 1 + net/sched/sch_taprio.c | 952 +++++++++++++++++++++++++++++++++ 4 files changed, 1013 insertions(+) create mode 100644 net/sched/sch_taprio.c
include/uapi/linux/pkt_sched.h +49 -0
@@ -1069,4 +1069,53 @@ enum {CAKE_ATM_MAX }; + +/* TAPRIO */ +enum { +TC_TAPRIO_CMD_SET_GATES =0x00 , +TC_TAPRIO_CMD_SET_AND_HOLD =0x01 , +TC_TAPRIO_CMD_SET_AND_RELEASE =0x02 , +}; + +enum { +TCA_TAPRIO_SCHED_ENTRY_UNSPEC , +TCA_TAPRIO_SCHED_ENTRY_INDEX ,/* u32 */ +TCA_TAPRIO_SCHED_ENTRY_CMD ,/* u8 */ +TCA_TAPRIO_SCHED_ENTRY_GATE_MASK ,/* u32 */ +TCA_TAPRIO_SCHED_ENTRY_INTERVAL ,/* u32 */ + __TCA_TAPRIO_SCHED_ENTRY_MAX, +}; +#define TCA_TAPRIO_SCHED_ENTRY_MAX (__TCA_TAPRIO_SCHED_ENTRY_MAX - 1) + +/* The format for schedule entry list is: +* [TCA_TAPRIO_SCHED_ENTRY_LIST] +* [TCA_TAPRIO_SCHED_ENTRY] +* [TCA_TAPRIO_SCHED_ENTRY_CMD] +* [TCA_TAPRIO_SCHED_ENTRY_GATES] +* [TCA_TAPRIO_SCHED_ENTRY_INTERVAL] +*/ +enum { +TCA_TAPRIO_SCHED_UNSPEC , +TCA_TAPRIO_SCHED_ENTRY , + __TCA_TAPRIO_SCHED_MAX, +}; + +#define TCA_TAPRIO_SCHED_MAX (__TCA_TAPRIO_SCHED_MAX - 1) + +enum { +TCA_TAPRIO_ATTR_UNSPEC , +TCA_TAPRIO_ATTR_PRIOMAP ,/* struct tc_mqprio_qopt */ +TCA_TAPRIO_ATTR_PREEMPT_MASK ,/* which traffic classes are preemptible, u32 */ +TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST ,/* nested of entry */ +TCA_TAPRIO_ATTR_SCHED_BASE_TIME ,/* s64 */ +TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME ,/* s64 */ +TCA_TAPRIO_ATTR_SCHED_EXTENSION_TIME ,/* s64 */ +TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY ,/* single entry */ +TCA_TAPRIO_ATTR_SCHED_CLOCKID ,/* s32 */ +TCA_TAPRIO_PAD , + __TCA_TAPRIO_ATTR_MAX, +}; + +#define TCA_TAPRIO_ATTR_MAX (__TCA_TAPRIO_ATTR_MAX - 1) +#endif
net/sched/Kconfig +11 -0
@@ -194,6 +194,17 @@ config NET_SCH_ETF To compile this code as a module, choose M here: the module will be called sch_etf. +config NET_SCH_TAPRIO + tristate "Time Aware Priority (taprio) Scheduler" + help + Say Y here if you want to use the Time Aware Priority (taprio) packet + scheduling algorithm. + + See the top of <file:net/sched/sch_taprio.c> for more details. + + To compile this code as a module, choose M here: the + module will be called sch_taprio. + config NET_SCH_GRED tristate "Generic Random Early Detection (GRED)" ---help---
net/sched/Makefile +1 -0
@@ -56,6 +56,7 @@ obj-$(CONFIG_NET_SCH_HHF) += sch_hhf.o obj-$(CONFIG_NET_SCH_PIE) += sch_pie.o obj-$(CONFIG_NET_SCH_CBS) += sch_cbs.o obj-$(CONFIG_NET_SCH_ETF) += sch_etf.o +obj-$(CONFIG_NET_SCH_TAPRIO) += sch_taprio.o obj-$(CONFIG_NET_CLS_U32) += cls_u32.o obj-$(CONFIG_NET_CLS_ROUTE4) += cls_route.o
net/sched/sch_taprio.c new file +952 -0
952 lines not on this page · raw message
Signature · 1 line
2.18.0
Jiri Pirko
maintainerQuoted 14 lines · Sat, Jul 14, 2018 at 02:05:36AM CEST, [email protected] wrote:
This scheduler allows the network administrator to configure schedules for classes of traffic, the configuration interface is similar to what IEEE 802.1Qbv-2015 defines.
Example configuration:
$ tc qdisc add dev enp2s0 parent root handle 100 taprio \ num_tc 3 \ map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 \ queues 1@0 1@1 2@2 \ sched-file ~/gates.sched \ base-time 1000000 \ clockid CLOCK_TAI
Quoted 5 lines
This qdisc borrows a few concepts from mqprio and most the parameters are similar to mqprio. The main difference is the 'sched-file' parameter, one example of a schedule file would be:
gates.sched
Any particular reason this has to be in file and not on the cmdline?
Vinicius Costa Gomes
maintainerHi Jiri,
Jiri Pirko <[email protected]> writes:
[...]
Quoted 4 lines
Quoted 2 lines
gates.sched
Any particular reason this has to be in file and not on the cmdline?
The idea here was to keep longer schedules more manageable. And during testing I found it more ergonomic to have a file.
It also has the advantage that the file can be reused by other tools, dump-classifier (awful name, I admit), included in that github gist, is one example, it uses the schedule (and some more information) to calculate which packets would fall outside their "windows" in a pcap dump.
Anyway, if there are use cases that having the schedule in the command line helps, I would be happy to add it.
Cheers,
Quoted 14 lines · Vinicius Costa Gomes
Hi Jiri,
Jiri Pirko <[email protected]> writes:
[...]
Quoted 4 lines
Quoted 2 lines
gates.sched
Any particular reason this has to be in file and not on the cmdline?
The idea here was to keep longer schedules more manageable. And during testing I found it more ergonomic to have a file.
Quoted 8 lines
It also has the advantage that the file can be reused by other tools, dump-classifier (awful name, I admit), included in that github gist, is one example, it uses the schedule (and some more information) to calculate which packets would fall outside their "windows" in a pcap dump.
Anyway, if there are use cases that having the schedule in the command line helps, I would be happy to add it.
FWIW there is some precedent in cls_bpf/act_bpf for allowing specifying potentially long sequences both in command line and as a file (cBPF filters in that case - see man tc-bpf bytecode and bytecode-file).