net/sched: taprio change schedules
Subsystems (4)
Vinicius Costa Gomes
maintainercover net/sched: taprio change schedules
Hi,
Changes from RFC:
- Removed the patches for taprio offloading, because of the lack of in-tree users;
- Updated the links to point to the PATCH version of this series;
Original cover letter:
Overview
--------
This RFC has two objectives, it adds support for changing the running schedules during "runtime", explained in more detail later, and proposes an interface between taprio and the drivers for hardware offloading.
These two different features are presented together so it's clear what the "final state" would look like. But after the RFC stage, they can be proposed (and reviewed) separately.
Changing the schedules without disrupting traffic is important for handling dynamic use cases, for example, when streams are added/removed and when the network configuration changes.
Hardware offloading support allows schedules to be more precise and have lower resource usage.
Changing schedules
------------------
The same as the other interfaces we proposed, we try to use the same concepts as the IEEE 802.1Q-2018 specification. So, for changing schedules, there are an "oper" (operational) and an "admin" schedule. The "admin" schedule is mutable and not in use, the "oper" schedule is immutable and is in use.
That is, when the user first adds an schedule it is in the "admin" state, and it becomes "oper" when its base-time (basically when it starts) is reached.
What this means is that now it's possible to create taprio with a schedule:
$ tc qdisc add dev IFACE 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 \
base-time 10000000 \
sched-entry S 03 300000 \
sched-entry S 02 300000 \
sched-entry S 06 400000 \
clockid CLOCK_TAIAnd then, later, after the previous schedule is "promoted" to "oper", add a new ("admin") schedule to be used some time later:
$ tc qdisc change dev IFACE parent root handle 100 taprio \
base-time 1553121866000000000 \
sched-entry S 02 500000 \
sched-entry S 0f 400000 \
clockid CLOCK_TAIWhen enabling the ability to change schedules, it makes sense to add two more defined knobs to schedules: "cycle-time" allows to truncate a cycle to some value, so it repeats after a well-defined value; "cycle-time-extension" controls how much an entry can be extended if it's the last one before the change of schedules, the reason is to avoid a very small cycle when transitioning from a schedule to another.
With these, taprio in the software mode should provide a fairly complete implementation of what's defined in the Enhancements for Scheduled Traffic parts of the specification.
Hardware offload
----------------
Some workloads require better guarantees from their schedules than what's provided by the software implementation. This series proposes an interface for configuring schedules into compatible network controllers.
This part is proposed together with the support for changing schedules, because it raises questions like, should the "qdisc" side be responsible of providing visibility into the schedules or should it be the driver?
In this proposal, the driver is called passing the new schedule as soon as it is validated, and the "core" qdisc takes care of displaying (".dump()") the correct schedules at all times. It means that some logic would need to be duplicated in the driver, if the hardware doesn't have support for multiple schedules. But as taprio doesn't have enough information about the underlying controller to know how much in advance a schedule needs to be informed to the hardware, it feels like a fair compromise.
The hardware offloading part of this proposal also tries to define an interface for frame-preemption and how it interacts with the scheduling of traffic, see Section 8.6.8.4 of IEEE 802.1Q-2018 for more information.
One important difference between the qdisc interface and the qdisc-driver interface, is that the "gate mask" on the qdisc side references traffic classes, that is bit 0 of the gate mask means Traffic Class 0, and in the driver interface, it specifies the queues, that is bit 0 means queue 0. That is to say that taprio converts the references to traffic classes to references to queues before sending the offloading request to the driver.
Request for help
----------------
I would like that interested driver maintainers could take a look at the proposed interface and see if it's going to be too awkward for any particular device. Also, pointers to available documentation would be appreciated. The idea here is to start a discussion so we can have an interface that would work for multiple vendors.
Links
-----
kernel patches:
https://github.com/vcgomes/net-next/tree/taprio-add-support-for-change-v3
iproute2 patches:
https://github.com/vcgomes/iproute2/tree/taprio-add-support-for-change-v3
Vinicius Costa Gomes (4):
taprio: Fix potencial use of invalid memory during dequeue()
taprio: Add support adding an admin schedule
taprio: Add support for setting the cycle-time manually
taprio: Add support for cycle-time-extension
include/uapi/linux/pkt_sched.h | 13 + net/sched/sch_taprio.c | 605 ++++++++++++++++++++++----------- 2 files changed, 412 insertions(+), 206 deletions(-)
Signature · 1 line
2.21.0
Vinicius Costa Gomes
maintainerPATCH 1/4 taprio: Fix potencial use of invalid memory during dequeue()
Right now, this isn't a problem, but the next commit allows schedules to be added during runtime. When a new schedule transitions from the inactive to the active state ("admin" -> "oper") the previous one can be freed, if it's freed just after the RCU read lock is released, we may access an invalid entry.
So, we should take care to protect the dequeue() flow, so all the places that access the entries are protected by the RCU read lock.
--- net/sched/sch_taprio.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
net/sched/sch_taprio.c +8 -6
@@ -136,8 +136,8 @@ static struct sk_buff *taprio_dequeue(struct Qdisc *sch) {struct taprio_sched *q =qdisc_priv (sch);struct net_device *dev =qdisc_dev (sch); +struct sk_buff *skb =NULL ;struct sched_entry *entry; -struct sk_buff *skb;u32 gate_mask;int i;
@@ -154,10 +154,9 @@ static struct sk_buff *taprio_dequeue(struct Qdisc *sch)* "AdminGateSates" */ gate_mask = entry ? entry->gate_mask :TAPRIO_ALL_GATES_OPEN ; -rcu_read_unlock ();if (!gate_mask) -return NULL ; + goto done;for (i =0 ; i < dev->num_tx_queues; i++) {struct Qdisc *child = q->qdiscs[i];
@@ -197,16 +196,19 @@ static struct sk_buff *taprio_dequeue(struct Qdisc *sch) skb = child->ops->dequeue (child);if (unlikely (!skb)) -return NULL ; + goto done;qdisc_bstats_update (sch, skb);qdisc_qstats_backlog_dec (sch, skb); sch->q.qlen--; -return skb; + goto done; } -return NULL ; +done: +rcu_read_unlock (); + +return skb; }static enum hrtimer_restart advance_sched (struct hrtimer *timer)
Signature · 1 line
2.21.0
Vinicius Costa Gomes
maintainerPATCH 2/4 taprio: Add support adding an admin schedule
In reply to Vinicius Costa GomesThe IEEE 802.1Q-2018 defines two "types" of schedules, the "Oper" (from operational?) and "Admin" ones. Up until now, 'taprio' only had support for the "Oper" one, added when the qdisc is created. This adds support for the "Admin" one, which allows the .change() operation to be supported.
Just for clarification, some quick (and dirty) definitions, the "Oper" schedule is the currently (as in this instant) running one, and it's read-only. The "Admin" one is the one that the system configurator has installed, it can be changed, and it will be "promoted" to "Oper" when it's 'base-time' is reached.
The idea behing this patch is that calling something like the below, (after taprio is already configured with an initial schedule):
$ tc qdisc change taprio dev IFACE parent root \
base-time X \
sched-entry <CMD> <GATES> <INTERVAL> \
...Will cause a new admin schedule to be created and programmed to be "promoted" to "Oper" at instant X. If an "Admin" schedule already exists, it will be overwritten with the new parameters.
Up until now, there was some code that was added to ease the support of changing a single entry of a schedule, but was ultimately unused. Now, that we have support for "change" with more well thought semantics, updating a single entry seems to be less useful.
So we remove what is in practice dead code, and return a "not supported" error if the user tries to use it. If changing a single entry would make the user's life easier we may ressurrect this idea, but at this point, removing it simplifies the code.
For now, only the schedule specific bits are allowed to be added for a new schedule, that means that 'clockid', 'num_tc', 'map' and 'queues' cannot be modified.
Example:
$ tc qdisc change dev IFACE parent root handle 100 taprio \
base-time $BASE_TIME \
sched-entry S 00 500000 \
sched-entry S 0f 500000 \
clockid CLOCK_TAIThe only change in the netlink API introduced by this change is the introduction of an "admin" type in the response to a dump request, that type allows userspace to separate the "oper" schedule from the "admin" schedule. If userspace doesn't support the "admin" type, it will only display the "oper" schedule.
--- include/uapi/linux/pkt_sched.h | 11 + net/sched/sch_taprio.c | 511 ++++++++++++++++++++------------- 2 files changed, 329 insertions(+), 193 deletions(-)
include/uapi/linux/pkt_sched.h +11 -0
@@ -1148,6 +1148,16 @@ enum {#define TCA_TAPRIO_SCHED_MAX (__TCA_TAPRIO_SCHED_MAX - 1) +/* The format for the admin sched (dump only): +* [TCA_TAPRIO_SCHED_ADMIN_SCHED] +* [TCA_TAPRIO_ATTR_SCHED_BASE_TIME] +* [TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST] +* [TCA_TAPRIO_ATTR_SCHED_ENTRY] +* [TCA_TAPRIO_ATTR_SCHED_ENTRY_CMD] +* [TCA_TAPRIO_ATTR_SCHED_ENTRY_GATES] +* [TCA_TAPRIO_ATTR_SCHED_ENTRY_INTERVAL] +*/ +enum {TCA_TAPRIO_ATTR_UNSPEC ,TCA_TAPRIO_ATTR_PRIOMAP ,/* struct tc_mqprio_qopt */
@@ -1156,6 +1166,7 @@ enum {TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY ,/* single entry */ TCA_TAPRIO_ATTR_SCHED_CLOCKID ,/* s32 */ TCA_TAPRIO_PAD , +TCA_TAPRIO_ATTR_ADMIN_SCHED ,/* The admin sched, only used in dump */ __TCA_TAPRIO_ATTR_MAX, };
net/sched/sch_taprio.c +318 -193
740 lines not on this page · raw message
Signature · 1 line
2.21.0
Vinicius Costa Gomes
maintainerPATCH 3/4 taprio: Add support for setting the cycle-time manually
In reply to Vinicius Costa GomesIEEE 802.1Q-2018 defines that a the cycle-time of a schedule may be overridden, so the schedule is truncated to a determined "width".
--- include/uapi/linux/pkt_sched.h | 1 + net/sched/sch_taprio.c | 59 +++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 8 deletions(-)
include/uapi/linux/pkt_sched.h +1 -0
@@ -1167,6 +1167,7 @@ enum {TCA_TAPRIO_ATTR_SCHED_CLOCKID ,/* s32 */ TCA_TAPRIO_PAD ,TCA_TAPRIO_ATTR_ADMIN_SCHED ,/* The admin sched, only used in dump */ +TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME ,/* s64 */ __TCA_TAPRIO_ATTR_MAX, };
net/sched/sch_taprio.c +51 -8
128 lines not on this page · raw message
Signature · 1 line
2.21.0
Vinicius Costa Gomes
maintainerPATCH 4/4 taprio: Add support for cycle-time-extension
In reply to Vinicius Costa GomesIEEE 802.1Q-2018 defines the concept of a cycle-time-extension, so the last entry of a schedule before the start of a new schedule can be extended, so "too-short" entries can be avoided.
--- include/uapi/linux/pkt_sched.h | 1 + net/sched/sch_taprio.c | 35 ++++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-)
include/uapi/linux/pkt_sched.h +1 -0
@@ -1168,6 +1168,7 @@ enum {TCA_TAPRIO_PAD ,TCA_TAPRIO_ATTR_ADMIN_SCHED ,/* The admin sched, only used in dump */ TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME ,/* s64 */ +TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION ,/* s64 */ __TCA_TAPRIO_ATTR_MAX, };
net/sched/sch_taprio.c +29 -6
@@ -48,6 +48,7 @@ struct sched_gate_list {size_t num_entries;ktime_t cycle_close_time;s64 cycle_time; +s64 cycle_time_extension;s64 base_time; };
@@ -290,7 +291,7 @@ static bool should_change_schedules(const struct sched_gate_list *admin,const struct sched_gate_list *oper, ktime_t close_time) { - ktime_t next_base_time; + ktime_t next_base_time, extension_time;if (!admin)return false;
@@ -303,6 +304,20 @@ static bool should_change_schedules(const struct sched_gate_list *admin,if (ktime_compare (next_base_time, close_time) <=0 )return true; +/* This is the cycle_time_extension case, if the close_time +* plus the amount that can be extended would fall after the +* next schedule base_time, we can extend the current schedule +* for that amount. +*/ + extension_time =ktime_add_ns (close_time, oper->cycle_time_extension); + +/* FIXME: the IEEE 802.1Q-2018 Specification isn't clear about +* how precisely the extension should be made. So after +* conformance testing, this logic may change. +*/ +if (ktime_compare (next_base_time, extension_time) <=0 ) +return true; +return false; }
@@ -390,11 +405,12 @@ static const struct nla_policy taprio_policy[TCA_TAPRIO_ATTR_MAX + 1] = { [TCA_TAPRIO_ATTR_PRIOMAP ] = { .len =sizeof (struct tc_mqprio_qopt ) }, - [TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST] = { .type = NLA_NESTED }, - [TCA_TAPRIO_ATTR_SCHED_BASE_TIME] = { .type = NLA_S64 }, - [TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY] = { .type = NLA_NESTED }, - [TCA_TAPRIO_ATTR_SCHED_CLOCKID] = { .type = NLA_S32 }, - [TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME] = { .type = NLA_S64 }, + [TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST] = { .type = NLA_NESTED }, + [TCA_TAPRIO_ATTR_SCHED_BASE_TIME] = { .type = NLA_S64 }, + [TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY] = { .type = NLA_NESTED }, + [TCA_TAPRIO_ATTR_SCHED_CLOCKID] = { .type = NLA_S32 }, + [TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME] = { .type = NLA_S64 }, + [TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION] = { .type = NLA_S64 }, }; static int fill_sched_entry(struct nlattr **tb, struct sched_entry *entry,
@@ -496,6 +512,9 @@ static int parse_taprio_schedule(struct nlattr **tb,if (tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME ]) new->base_time =nla_get_s64 (tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME ]); +if (tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION ]) + new->cycle_time_extension =nla_get_s64 (tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION ]); +if (tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME ]) new->cycle_time =nla_get_s64 (tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME ]);
@@ -1008,6 +1027,10 @@ static int dump_schedule(struct sk_buff *msg, root->cycle_time, TCA_TAPRIO_PAD))return -1 ; +if (nla_put_s64 (msg,TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION , + root->cycle_time_extension,TCA_TAPRIO_PAD )) +return -1 ; + entry_list =nla_nest_start_noflag (msg,TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST );if (!entry_list)
Signature · 1 line
2.21.0
David Miller
maintainerFrom: Vinicius Costa Gomes <[email protected]>
Date: Mon, 29 Apr 2019 15:48:29 -0700
Quoted 7 lines
Overview
--------This RFC has two objectives, it adds support for changing the running schedules during "runtime", explained in more detail later, and proposes an interface between taprio and the drivers for hardware offloading.
...
Series applied.
Hi Vinicius,
Quoted 138 lines · Vinicius Costa Gomes
Hi,
Changes from RFC:
- Removed the patches for taprio offloading, because of the lack ofin-tree user > - Updated the links to point to the PATCH version of this series;Original cover letter:
Overview
--------This RFC has two objectives, it adds support for changing the running schedules during "runtime", explained in more detail later, and proposes an interface between taprio and the drivers for hardware offloading.
These two different features are presented together so it's clear what the "final state" would look like. But after the RFC stage, they can be proposed (and reviewed) separately.
Changing the schedules without disrupting traffic is important for handling dynamic use cases, for example, when streams are added/removed and when the network configuration changes.
Hardware offloading support allows schedules to be more precise and have lower resource usage.
Changing schedules
------------------The same as the other interfaces we proposed, we try to use the same concepts as the IEEE 802.1Q-2018 specification. So, for changing schedules, there are an "oper" (operational) and an "admin" schedule. The "admin" schedule is mutable and not in use, the "oper" schedule is immutable and is in use.
That is, when the user first adds an schedule it is in the "admin" state, and it becomes "oper" when its base-time (basically when it starts) is reached.
What this means is that now it's possible to create taprio with a schedule:
$ tc qdisc add dev IFACE 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 \ base-time 10000000 \ sched-entry S 03 300000 \ sched-entry S 02 300000 \ sched-entry S 06 400000 \ clockid CLOCK_TAIAnd then, later, after the previous schedule is "promoted" to "oper", add a new ("admin") schedule to be used some time later:
$ tc qdisc change dev IFACE parent root handle 100 taprio \ base-time 1553121866000000000 \ sched-entry S 02 500000 \ sched-entry S 0f 400000 \ clockid CLOCK_TAIWhen enabling the ability to change schedules, it makes sense to add two more defined knobs to schedules: "cycle-time" allows to truncate a cycle to some value, so it repeats after a well-defined value; "cycle-time-extension" controls how much an entry can be extended if it's the last one before the change of schedules, the reason is to avoid a very small cycle when transitioning from a schedule to another.
With these, taprio in the software mode should provide a fairly complete implementation of what's defined in the Enhancements for Scheduled Traffic parts of the specification.
Hardware offload
----------------Some workloads require better guarantees from their schedules than what's provided by the software implementation. This series proposes an interface for configuring schedules into compatible network controllers.
This part is proposed together with the support for changing schedules, because it raises questions like, should the "qdisc" side be responsible of providing visibility into the schedules or should it be the driver?
In this proposal, the driver is called passing the new schedule as soon as it is validated, and the "core" qdisc takes care of displaying (".dump()") the correct schedules at all times. It means that some logic would need to be duplicated in the driver, if the hardware doesn't have support for multiple schedules. But as taprio doesn't have enough information about the underlying controller to know how much in advance a schedule needs to be informed to the hardware, it feels like a fair compromise.
The hardware offloading part of this proposal also tries to define an interface for frame-preemption and how it interacts with the scheduling of traffic, see Section 8.6.8.4 of IEEE 802.1Q-2018 for more information.
One important difference between the qdisc interface and the qdisc-driver interface, is that the "gate mask" on the qdisc side references traffic classes, that is bit 0 of the gate mask means Traffic Class 0, and in the driver interface, it specifies the queues, that is bit 0 means queue 0. That is to say that taprio converts the references to traffic classes to references to queues before sending the offloading request to the driver.
Request for help
----------------I would like that interested driver maintainers could take a look at the proposed interface and see if it's going to be too awkward for any particular device. Also, pointers to available documentation would be appreciated. The idea here is to start a discussion so we can have an interface that would work for multiple vendors.
Links
-----kernel patches:
https://github.com/vcgomes/net-next/tree/taprio-add-support-for-change-v3iproute2 patches:
https://github.com/vcgomes/iproute2/tree/taprio-add-support-for-change-v3Vinicius Costa Gomes (4):
taprio: Fix potencial use of invalid memory duringdequeue()
taprio: Add support adding an admin schedule
taprio: Add support for setting the cycle-time manually
taprio: Add support for cycle-time-extension
Quoted 4 lines
include/uapi/linux/pkt_sched.h | 13 + net/sched/sch_taprio.c | 605 ++++++++++++++++++++++----------- 2 files changed, 412 insertions(+), 206 deletions(-)
Ok. I saw this one after I replied to your RFC. So I will pull v3 of your branch instead of v2 for my investigation.
Thanks and regards,
Murali