Skip to contentSkip to conversation

TSN: Add qdisc-based config interfaces for traffic shapers

RFC In review Vinicius Costa Gomes 6 participants 39 messages Sep 1, 2017 – Oct 23, 2017

Subsystems (5)
lore
Share & tools
lore

Vinicius Costa Gomes

author maintainer
#0 lore raw

cover TSN: Add qdisc-based config interfaces for traffic shapers

Hi,

This patchset is an RFC on a proposal of how the Traffic Control subsystem can be used to offload the configuration of traffic shapers into network devices that provide support for them in HW. Our goal here is to start upstreaming support for features related to the Time-Sensitive Networking (TSN) set of standards into the kernel.

As part of this work, we've assessed previous public discussions related to TSN
enabling: patches from Henrik Austad (Cisco), the presentation from Eric Mann at Linux Plumbers 2012, patches from Gangfeng Huang (National Instruments) and the current state of the OpenAVNU project (https://github.com/AVnu/OpenAvnu/).

Please note that the patches provided as part of this RFC are implementing what is needed only for 802.1Qav (FQTSS) only, but we'd like to take advantage of this discussion and share our WIP ideas for the 802.1Qbv and 802.1Qbu interfaces as well. The current patches are only providing support for HW offload of the configs.

Overview
========

Time-sensitive Networking (TSN) is a set of standards that aim to address resources availability for providing bandwidth reservation and bounded latency on Ethernet based LANs. The proposal described here aims to cover mainly what is needed to enable the following standards: 802.1Qat, 802.1Qav, 802.1Qbv and 802.1Qbu.

The initial target of this work is the Intel i210 NIC, but other controllers' datasheet were also taken into account, like the Renesas RZ/A1H RZ/A1M group and the Synopsis DesignWare Ethernet QoS controller.

Proposal
========

Feature-wise, what is covered here are configuration interfaces for HW implementations of the Credit-Based shaper (CBS, 802.1Qav), Time-Aware shaper (802.1Qbv) and Frame Preemption (802.1Qbu). CBS is a per-queue shaper, while Qbv and Qbu must be configured per port, with the configuration covering all queues. Given that these features are related to traffic shaping, and that the traffic control subsystem already provides a queueing discipline that offloads config into the device driver (i.e. mqprio), designing new qdiscs for the specific purpose of offloading the config for each shaper seemed like a good fit.

For steering traffic into the correct queues, we use the socket option SO_PRIORITY and then a mechanism to map priority to traffic classes / Tx queues. The qdisc mqprio is currently used in our tests.

As for the shapers config interface:

* CBS (802.1Qav)

This patchset is proposing a new qdisc called 'cbs'. Its 'tc' cmd line is:

   $ tc qdisc add dev IFACE parent ID cbs locredit N hicredit M sendslope S \
     idleslope I

Note that the parameters for this qdisc are the ones defined by the 802.1Q-2014 spec, so no hardware specific functionality is exposed here.

* Time-aware shaper (802.1Qbv):

The idea we are currently exploring is to add a "time-aware", priority based qdisc, that also exposes the Tx queues available and provides a mechanism for mapping priority <-> traffic class <-> Tx queues in a similar fashion as mqprio. We are calling this qdisc 'taprio', and its 'tc' cmd line would be:

   $ $ tc qdisc add dev ens4 parent root handle 100 taprio num_tc 4    \
     	   map 2 2 1 0 3 3 3 3 3 3 3 3 3 3 3 3                         \
	   queues 0 1 2 3                                              \
     	   sched-file gates.sched [base-time <interval>]               \
           [cycle-time <interval>] [extension-time <interval>]

<file> is multi-line, with each line being of the following format:
<cmd> <gate mask> <interval in nanoseconds>

Qbv only defines one <cmd>: "S" for 'SetGates'

For example:

S 0x01 300
S 0x03 500

This means that there are two intervals, the first will have the gate for traffic class 0 open for 300 nanoseconds, the second will have both traffic classes open for 500 nanoseconds.

Additionally, an option to set just one entry of the gate control list will also be provided by 'taprio':

   $ tc qdisc (...) \
        sched-row <row number> <cmd> <gate mask> <interval>  \
        [base-time <interval>] [cycle-time <interval>] \
        [extension-time <interval>]

* Frame Preemption (802.1Qbu):

To control even further the latency, it may prove useful to signal which traffic classes are marked as preemptable. For that, 'taprio' provides the preemption command so you set each traffic class as preemptable or not:

   $ tc qdisc (...) \
        preemption 0 1 1 1

* Time-aware shaper + Preemption:

As an example of how Qbv and Qbu can be used together, we may specify both the schedule and the preempt-mask, and this way we may also specify the Set-Gates-and-Hold and Set-Gates-and-Release commands as specified in the Qbu spec:

   $ tc qdisc add dev ens4 parent root handle 100 taprio num_tc 4 \
     	   map 2 2 1 0 3 3 3 3 3 3 3 3 3 3 3 3                    \
	   queues 0 1 2 3                                         \
     	   preemption 0 1 1 1                                     \
	   sched-file preempt_gates.sched

<file> is multi-line, with each line being of the following format:
<cmd> <gate mask> <interval in nanoseconds>

For this case, two new commands are introduced:

"H" for 'set gates and hold'
"R" for 'set gates and release'

H 0x01 300
R 0x03 500

Testing this RFC
================

For testing the patches of this RFC only, you can refer to the samples and helper script being added to samples/tsn/ and the use the 'mqprio' qdisc to setup the priorities to Tx queues mapping, together with the 'cbs' qdisc to configure the HW shaper of the i210 controller:

1) Setup priorities to traffic classes to hardware queues mapping

$ tc qdisc replace dev enp3s0 parent root mqprio num_tc 3 \
     map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 queues 1 at 0 1 at 1 2 at 2 hw 0

2) Check scheme. You want to get the inner qdiscs ID from the bottom up

$ tc -g  class show dev enp3s0

Ex.:

+---(802a:3) mqprio
|    +---(802a:6) mqprio
|    +---(802a:7) mqprio
|
+---(802a:2) mqprio
|    +---(802a:5) mqprio
|
+---(802a:1) mqprio
     +---(802a:4) mqprio

* Here '802a:4' is Tx Queue #0 and '802a:5' is Tx Queue #1.

3) Calculate CBS parameters for classes A and B. i.e. BW for A is 20Mbps and for B is 10Mbps:

$ ./samples/tsn/calculate_cbs_params.py -A 20000 -a 1500 -B 10000 -b 1500

4) Configure CBS for traffic class A (priority 3) as provided by the script:

$ tc qdisc replace dev enp3s0 parent 802a:4 cbs locredit -1470 \
     hicredit 30 sendslope -980000 idleslope 20000

5) Configure CBS for traffic class B (priority 2):

$ tc qdisc replace dev enp3s0 parent 802a:5 cbs \
     locredit -1485 hicredit 31 sendslope -990000 idleslope 10000

6) Run Listener, compiled from samples/tsn/listener.c

$ ./listener -i enp3s0

7) Run Talker for class A (prio 3 here), compiled from samples/tsn/talker.c

$ ./talker -i enp3s0 -p 3

* The bandwidth displayed on the listener output at this stage should be very close to the one configured for class A.

8) You can also run a Talker for class B (prio 2 here)

$ ./talker -i enp3s0 -p 2

* The bandwidth displayed on the listener output now should increase to very close to the one configured for class A + class B.

Authors
=======
- Andre Guedes <[email protected]>
- Ivan Briano <[email protected]>
- Jesus Sanchez-Palencia <[email protected]>
- Vinicius Gomes <[email protected]>

Andre Guedes (2):
igb: Add support for CBS offload samples/tsn: Add script for calculating CBS config

Jesus Sanchez-Palencia (1):
sample: Add TSN Talker and Listener examples

Vinicius Costa Gomes (2):
net/sched: Introduce the user API for the CBS shaper net/sched: Introduce Credit Based Shaper (CBS) qdisc

 drivers/net/ethernet/intel/igb/e1000_defines.h |  23 ++
 drivers/net/ethernet/intel/igb/e1000_regs.h    |   8 +
 drivers/net/ethernet/intel/igb/igb.h           |   6 +
 drivers/net/ethernet/intel/igb/igb_main.c      | 349 +++++++++++++++++++++++++
 include/linux/netdevice.h                      |   1 +
 include/uapi/linux/pkt_sched.h                 |  29 ++
 net/sched/Kconfig                              |  11 +
 net/sched/Makefile                             |   1 +
 net/sched/sch_cbs.c                            | 286 ++++++++++++++++++++
 samples/tsn/calculate_cbs_params.py            | 112 ++++++++
 samples/tsn/listener.c                         | 254 ++++++++++++++++++
 samples/tsn/talker.c                           | 136 ++++++++++
 12 files changed, 1216 insertions(+)
 create mode 100644 net/sched/sch_cbs.c
 create mode 100755 samples/tsn/calculate_cbs_params.py
 create mode 100644 samples/tsn/listener.c
 create mode 100644 samples/tsn/talker.c

--
2.14.1

author maintainer
#1 lore raw

RFC 1/5 net/sched: Introduce the user API for the CBS shaper

Export the API necessary for configuring the CBS shaper (implemented in the next patch) via the tc tool.

---
 include/uapi/linux/pkt_sched.h | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
include/uapi/linux/pkt_sched.h +29 -0
index 099bf5528fed..aa4a3e5421be 100644
@@ -871,4 +871,33 @@ struct tc_pie_xstats {
 	__u32 maxq;             /* maximum queue size */
 	__u32 ecn_mark;         /* packets marked with ecn*/
 };
+
+/* CBS */
+/* FIXME: this is only for usage with ndo_setup_tc(), this should be
+ * in another header someplace else. Is pkt_cls.h the right place?
+ */
+struct tc_cbs_qopt_offload {
+	u8		enable;
+	s32		queue;
+	s32		hicredit;
+	s32		locredit;
+	s32		idleslope;
+	s32		sendslope;
+};
+
+struct tc_cbs_qopt {
+	__s32		hicredit;
+	__s32		locredit;
+	__s32		idleslope;
+	__s32		sendslope;
+};
+
+enum {
+	TCA_CBS_UNSPEC,
+	TCA_CBS_PARMS,
+	__TCA_CBS_MAX,
+};
+
+#define TCA_CBS_MAX (__TCA_CBS_MAX - 1)
+
 #endif
Signature · 1 line
2.14.1
author maintainer
#2 lore raw

RFC 2/5 net/sched: Introduce Credit Based Shaper (CBS) qdisc

In reply to Vinicius Costa Gomes

This queueing discipline implements the shaper algorithm defined by the 802.1Q-2014 Section 8.6.8.2 and detailed in Annex L.

It's primary usage is to apply some bandwidth reservation to user defined traffic classes, which are mapped to different queues via the mqprio qdisc.

Initially, it only supports offloading the traffic shaping work to supporting controllers.

Later, when a software implementation is added, the current dependency on being installed "under" mqprio can be lifted.

---
 include/linux/netdevice.h |   1 +
 net/sched/Kconfig         |  11 ++
 net/sched/Makefile        |   1 +
 net/sched/sch_cbs.c       | 286 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 299 insertions(+)
 create mode 100644 net/sched/sch_cbs.c
include/linux/netdevice.h +1 -0
index 35de8312e0b5..dd9a2ecd0c03 100644
@@ -775,6 +775,7 @@ enum tc_setup_type {
 	TC_SETUP_CLSFLOWER,
 	TC_SETUP_CLSMATCHALL,
 	TC_SETUP_CLSBPF,
+	TC_SETUP_CBS,
 };
 
 /* These structures hold the attributes of xdp state that are being passed
net/sched/Kconfig +11 -0
index e70ed26485a2..c03d86a7775e 100644
@@ -172,6 +172,17 @@ config NET_SCH_TBF
 	  To compile this code as a module, choose M here: the
 	  module will be called sch_tbf.
 
+config NET_SCH_CBS
+	tristate "Credit Based Shaper (CBS)"
+	---help---
+	  Say Y here if you want to use the Credit Based Shaper (CBS) packet
+	  scheduling algorithm.
+
+	  See the top of <file:net/sched/sch_cbs.c> for more details.
+
+	  To compile this code as a module, choose M here: the
+	  module will be called sch_cbs.
+
 config NET_SCH_GRED
 	tristate "Generic Random Early Detection (GRED)"
 	---help---
net/sched/Makefile +1 -0
index 7b915d226de7..80c8f92d162d 100644
@@ -52,6 +52,7 @@ obj-$(CONFIG_NET_SCH_FQ_CODEL)	+= sch_fq_codel.o
 obj-$(CONFIG_NET_SCH_FQ)	+= sch_fq.o
 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_CLS_U32)	+= cls_u32.o
 obj-$(CONFIG_NET_CLS_ROUTE4)	+= cls_route.o
net/sched/sch_cbs.c new file +286 -0

286 lines not on this page · raw message

Signature · 1 line
2.14.1
#3 lore raw

Re: [RFC net-next 2/5] net/sched: Introduce Credit Based Shaper (CBS) qdisc

Quoted 7 lines · Vinicius Costa Gomes

This queueing discipline implements the shaper algorithm defined by the 802.1Q-2014 Section 8.6.8.2 and detailed in Annex L.

It's primary usage is to apply some bandwidth reservation to user defined traffic classes, which are mapped to different queues via the mqprio qdisc.

Quoted 8 lines

Initially, it only supports offloading the traffic shaping work to supporting controllers.

Later, when a software implementation is added, the current dependency on being installed "under" mqprio can be lifted.

So, I started testing this in my VM to make sure I didn't do anything silly and it exploded spectacularly as it used the underlying e1000 driver which does not have a ndo_setup_tc present.

I commented inline below, but as a tl;dr

The cbs_init() would call into cbs_change() that would correctly detect that ndo_setup_tc is missing and abort. However, at this stage it would try to desroy the qdisc and in cbs_destroy() there's no such guard leading to a

BUG: unable to handle kernel NULL pointer dereference at 0000000000000010

Fixing that, another NULL would be found when the code walks into qdisc_destroy(q->qdisc).

Apart from this, it loaded fine after some wrestling with tc :)

Awesome! :D

Quoted 25 lines
---
 include/linux/netdevice.h |   1 +
 net/sched/Kconfig         |  11 ++
 net/sched/Makefile        |   1 +
 net/sched/sch_cbs.c       | 286 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 299 insertions(+)
 create mode 100644 net/sched/sch_cbs.c
include/linux/netdevice.h +1 -0
index 35de8312e0b5..dd9a2ecd0c03 100644
@@ -775,6 +775,7 @@ enum tc_setup_type {
 	TC_SETUP_CLSFLOWER,
 	TC_SETUP_CLSMATCHALL,
 	TC_SETUP_CLSBPF,
+	TC_SETUP_CBS,
 };
 
 /* These structures hold the attributes of xdp state that are being passed
net/sched/Kconfig +0 -0
index e70ed26485a2..c03d86a7775e 100644

net/sched/Kconfig config NET_SCH_TBF · line 175

Quoted 4 lines
net/sched/Kconfig +1 -0
@@ -172,6 +172,17 @@ config NET_SCH_TBF
 	  To compile this code as a module, choose M here: the
 	  module will be called sch_tbf.
 
+config NET_SCH_CBS

Shouldn't this depend on NET_SCH_MQPRIO as it is supposed to hook into that?

@@ -173,6 +173,7 @@ config NET_SCH_TBF
module will be called sch_tbf.

config NET_SCH_CBS
+ depends on NET_SCH_MQPRIO
tristate "Credit Based Shaper (CBS)"
---help---
Say Y here if you want to use the Credit Based Shaper (CBS) packet

Quoted 139 lines
net/sched/Kconfig +10 -0
+	tristate "Credit Based Shaper (CBS)"
+	---help---
+	  Say Y here if you want to use the Credit Based Shaper (CBS) packet
+	  scheduling algorithm.
+
+	  See the top of <file:net/sched/sch_cbs.c> for more details.
+
+	  To compile this code as a module, choose M here: the
+	  module will be called sch_cbs.
+
 config NET_SCH_GRED
 	tristate "Generic Random Early Detection (GRED)"
 	---help---
net/sched/Makefile +1 -0
index 7b915d226de7..80c8f92d162d 100644
@@ -52,6 +52,7 @@ obj-$(CONFIG_NET_SCH_FQ_CODEL)	+= sch_fq_codel.o
 obj-$(CONFIG_NET_SCH_FQ)	+= sch_fq.o
 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_CLS_U32)	+= cls_u32.o
 obj-$(CONFIG_NET_CLS_ROUTE4)	+= cls_route.o
net/sched/sch_cbs.c new file +108 -0
new file mode 100644
index 000000000000..1c86a9e14150
@@ -0,0 +1,286 @@
+/*
+ * net/sched/sch_cbs.c	Credit Based Shaper
+ *
+ *		This program is free software; you can redistribute it and/or
+ *		modify it under the terms of the GNU General Public License
+ *		as published by the Free Software Foundation; either version
+ *		2 of the License, or (at your option) any later version.
+ *
+ * Authors:	Vininicius Costa Gomes <[email protected]>
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/skbuff.h>
+#include <net/netlink.h>
+#include <net/sch_generic.h>
+#include <net/pkt_sched.h>
+
+struct cbs_sched_data {
+	struct Qdisc *qdisc; /* Inner qdisc, default - pfifo queue */
+	s32 queue;
+	s32 locredit;
+	s32 hicredit;
+	s32 sendslope;
+	s32 idleslope;
+};
+
+static int cbs_enqueue(struct sk_buff *skb, struct Qdisc *sch,
+		       struct sk_buff **to_free)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+	int ret;
+
+	ret = qdisc_enqueue(skb, q->qdisc, to_free);
+	if (ret != NET_XMIT_SUCCESS) {
+		if (net_xmit_drop_count(ret))
+			qdisc_qstats_drop(sch);
+		return ret;
+	}
+
+	qdisc_qstats_backlog_inc(sch, skb);
+	sch->q.qlen++;
+	return NET_XMIT_SUCCESS;
+}
+
+static struct sk_buff *cbs_dequeue(struct Qdisc *sch)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+	struct sk_buff *skb;
+
+	skb = q->qdisc->ops->peek(q->qdisc);
+	if (skb) {
+		skb = qdisc_dequeue_peeked(q->qdisc);
+		if (unlikely(!skb))
+			return NULL;
+
+		qdisc_qstats_backlog_dec(sch, skb);
+		sch->q.qlen--;
+		qdisc_bstats_update(sch, skb);
+
+		return skb;
+	}
+	return NULL;
+}
+
+static void cbs_reset(struct Qdisc *sch)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+
+	qdisc_reset(q->qdisc);
+}
+
+static const struct nla_policy cbs_policy[TCA_CBS_MAX + 1] = {
+	[TCA_CBS_PARMS]	= { .len = sizeof(struct tc_cbs_qopt) },
+};
+
+static int cbs_change(struct Qdisc *sch, struct nlattr *opt)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+	struct tc_cbs_qopt_offload cbs = { };
+	struct nlattr *tb[TCA_CBS_MAX + 1];
+	const struct net_device_ops *ops;
+	struct tc_cbs_qopt *qopt;
+	struct net_device *dev;
+	int err;
+
+	err = nla_parse_nested(tb, TCA_CBS_MAX, opt, cbs_policy, NULL);
+	if (err < 0)
+		return err;
+
+	err = -EINVAL;
+	if (!tb[TCA_CBS_PARMS])
+		goto done;
+
+	qopt = nla_data(tb[TCA_CBS_PARMS]);
+
+	dev = qdisc_dev(sch);
+	ops = dev->netdev_ops;
+
+	/* FIXME: this means that we can only install this qdisc
+	 * "under" mqprio. Do we need a more generic way to retrieve
+	 * the queue, or do we pass the netdev_queue to the driver?
+	 */
+	cbs.queue = TC_H_MIN(sch->parent) - 1 - netdev_get_num_tc(dev);

net/sched/sch_cbs.c line 118

Quoted 10 lines
net/sched/sch_cbs.c new file +10 -0
+
+	cbs.enable = 1;
+	cbs.hicredit = qopt->hicredit;
+	cbs.locredit = qopt->locredit;
+	cbs.idleslope = qopt->idleslope;
+	cbs.sendslope = qopt->sendslope;
+
+	err = -ENOTSUPP;
+	if (!ops->ndo_setup_tc)
+		goto done;

This confuses tc a bit, and looking at other qdisc schedulers, it seems like EOPNOTSUPP is an alternative, this changes the output from

RTNETLINK answers: Unknown error 524
- to
RTNETLINK answers: Operation not supported

which perhaps is more informative.

Quoted 36 lines
net/sched/sch_cbs.c new file +36 -0
+
+	err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_CBS, &cbs);
+	if (err < 0)
+		goto done;
+
+	q->queue = cbs.queue;
+	q->hicredit = cbs.hicredit;
+	q->locredit = cbs.locredit;
+	q->idleslope = cbs.idleslope;
+	q->sendslope = cbs.sendslope;
+
+done:
+	return err;
+}
+
+static int cbs_init(struct Qdisc *sch, struct nlattr *opt)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+
+	if (!opt)
+		return -EINVAL;
+
+	q->qdisc = fifo_create_dflt(sch, &pfifo_qdisc_ops, 1024);
+	qdisc_hash_add(q->qdisc, true);
+
+	return cbs_change(sch, opt);
+}
+
+static void cbs_destroy(struct Qdisc *sch)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+	struct tc_cbs_qopt_offload cbs = { };
+	struct net_device *dev;
+	int err;
+
+	q->hicredit = 0;

net/sched/sch_cbs.c line 164

Quoted 10 lines
net/sched/sch_cbs.c new file +10 -0
+	q->locredit = 0;
+	q->idleslope = 0;
+	q->sendslope = 0;
+
+	dev = qdisc_dev(sch);
+
+	cbs.queue = q->queue;
+	cbs.enable = 0;
+
+	err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_CBS, &cbs);

This can lead to NULL pointer deref if it is not set (tested for in cbs_change and error there leads us here, which then explodes).

net/sched/sch_cbs.c line 169

Quoted 5 lines
net/sched/sch_cbs.c new file +5 -0
+	if (err < 0)
+		pr_warn("Couldn't reset queue %d to default values\n",
+			cbs.queue);
+
+	qdisc_destroy(q->qdisc);

Same, q->qdisc was NULL when cbs_init() failed.

Quoted 120 lines
net/sched/sch_cbs.c new file +117 -0
+}
+
+static int cbs_dump(struct Qdisc *sch, struct sk_buff *skb)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+	struct nlattr *nest;
+	struct tc_cbs_qopt opt;
+
+	sch->qstats.backlog = q->qdisc->qstats.backlog;
+	nest = nla_nest_start(skb, TCA_OPTIONS);
+	if (!nest)
+		goto nla_put_failure;
+
+	opt.hicredit = q->hicredit;
+	opt.locredit = q->locredit;
+	opt.sendslope = q->sendslope;
+	opt.idleslope = q->idleslope;
+
+	if (nla_put(skb, TCA_CBS_PARMS, sizeof(opt), &opt))
+		goto nla_put_failure;
+
+	return nla_nest_end(skb, nest);
+
+nla_put_failure:
+	nla_nest_cancel(skb, nest);
+	return -1;
+}
+
+static int cbs_dump_class(struct Qdisc *sch, unsigned long cl,
+			  struct sk_buff *skb, struct tcmsg *tcm)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+
+	tcm->tcm_handle |= TC_H_MIN(1);
+	tcm->tcm_info = q->qdisc->handle;
+
+	return 0;
+}
+
+static int cbs_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
+		     struct Qdisc **old)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+
+	if (!new)
+		new = &noop_qdisc;
+
+	*old = qdisc_replace(sch, new, &q->qdisc);
+	return 0;
+}
+
+static struct Qdisc *cbs_leaf(struct Qdisc *sch, unsigned long arg)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+
+	return q->qdisc;
+}
+
+static unsigned long cbs_find(struct Qdisc *sch, u32 classid)
+{
+	return 1;
+}
+
+static int cbs_delete(struct Qdisc *sch, unsigned long arg)
+{
+	return 0;
+}
+
+static void cbs_walk(struct Qdisc *sch, struct qdisc_walker *walker)
+{
+	if (!walker->stop) {
+		if (walker->count >= walker->skip)
+			if (walker->fn(sch, 1, walker) < 0) {
+				walker->stop = 1;
+				return;
+			}
+		walker->count++;
+	}
+}
+
+static const struct Qdisc_class_ops cbs_class_ops = {
+	.graft		=	cbs_graft,
+	.leaf		=	cbs_leaf,
+	.find		=	cbs_find,
+	.delete		=	cbs_delete,
+	.walk		=	cbs_walk,
+	.dump		=	cbs_dump_class,
+};
+
+static struct Qdisc_ops cbs_qdisc_ops __read_mostly = {
+	.next		=	NULL,
+	.cl_ops		=	&cbs_class_ops,
+	.id		=	"cbs",
+	.priv_size	=	sizeof(struct cbs_sched_data),
+	.enqueue	=	cbs_enqueue,
+	.dequeue	=	cbs_dequeue,
+	.peek		=	qdisc_peek_dequeued,
+	.init		=	cbs_init,
+	.reset		=	cbs_reset,
+	.destroy	=	cbs_destroy,
+	.change		=	cbs_change,
+	.dump		=	cbs_dump,
+	.owner		=	THIS_MODULE,
+};
+
+static int __init cbs_module_init(void)
+{
+	return register_qdisc(&cbs_qdisc_ops);
+}
+
+static void __exit cbs_module_exit(void)
+{
+	unregister_qdisc(&cbs_qdisc_ops);
+}
+module_init(cbs_module_init)
+module_exit(cbs_module_exit)
+MODULE_LICENSE("GPL");
Signature · 1 line
2.14.1
Signature · 8 lines
Henrik Austad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20170908/739d17ec/attachment.asc>
author maintainer
#4 lore raw

Re: [RFC net-next 2/5] net/sched: Introduce Credit Based Shaper (CBS) qdisc

Hi Henrik,

Quoted 64 lines · Henrik Austad
Quoted 7 lines · Vinicius Costa Gomes

This queueing discipline implements the shaper algorithm defined by the 802.1Q-2014 Section 8.6.8.2 and detailed in Annex L.

It's primary usage is to apply some bandwidth reservation to user defined traffic classes, which are mapped to different queues via the mqprio qdisc.

Quoted 8 lines

Initially, it only supports offloading the traffic shaping work to supporting controllers.

Later, when a software implementation is added, the current dependency on being installed "under" mqprio can be lifted.

So, I started testing this in my VM to make sure I didn't do anything silly and it exploded spectacularly as it used the underlying e1000 driver which does not have a ndo_setup_tc present.

I commented inline below, but as a tl;dr

The cbs_init() would call into cbs_change() that would correctly detect that ndo_setup_tc is missing and abort. However, at this stage it would try to desroy the qdisc and in cbs_destroy() there's no such guard leading to a

BUG: unable to handle kernel NULL pointer dereference at 0000000000000010

Fixing that, another NULL would be found when the code walks into qdisc_destroy(q->qdisc).

Apart from this, it loaded fine after some wrestling with tc :)

Awesome! :D

Quoted 28 lines
---
 include/linux/netdevice.h |   1 +
 net/sched/Kconfig         |  11 ++
 net/sched/Makefile        |   1 +
 net/sched/sch_cbs.c       | 286 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 299 insertions(+)
 create mode 100644 net/sched/sch_cbs.c
include/linux/netdevice.h +1 -0
index 35de8312e0b5..dd9a2ecd0c03 100644
@@ -775,6 +775,7 @@ enum tc_setup_type {
 	TC_SETUP_CLSFLOWER,
 	TC_SETUP_CLSMATCHALL,
 	TC_SETUP_CLSBPF,
+	TC_SETUP_CBS,
 };
 
 /* These structures hold the attributes of xdp state that are being passed
net/sched/Kconfig +0 -0
index e70ed26485a2..c03d86a7775e 100644
@@ -172,6 +172,17 @@ config NET_SCH_TBF
 	  To compile this code as a module, choose M here: the
 	  module will be called sch_tbf.
 
Quoted 4 lines

net/sched/Kconfig config NET_SCH_TBF · line 175

Quoted 1 line
net/sched/Kconfig +1 -0
+config NET_SCH_CBS

Shouldn't this depend on NET_SCH_MQPRIO as it is supposed to hook into that?

Right now, the CBS shaper only makes sense with mqprio, later it may use some other qdisc (like "taprio" mentioned in the cover letter) to hook into, so, yes, you are right, there's a dependency here, better make it clear. Will fix.

Quoted 163 lines
(quoted diff) +1 -0
@@ -173,6 +173,7 @@ config NET_SCH_TBF
          module will be called sch_tbf.
 
 config NET_SCH_CBS
+       depends on NET_SCH_MQPRIO
        tristate "Credit Based Shaper (CBS)"
        ---help---
          Say Y here if you want to use the Credit Based Shaper (CBS) packet
Quoted 140 lines
net/sched/Kconfig +10 -0
+	tristate "Credit Based Shaper (CBS)"
+	---help---
+	  Say Y here if you want to use the Credit Based Shaper (CBS) packet
+	  scheduling algorithm.
+
+	  See the top of <file:net/sched/sch_cbs.c> for more details.
+
+	  To compile this code as a module, choose M here: the
+	  module will be called sch_cbs.
+
 config NET_SCH_GRED
 	tristate "Generic Random Early Detection (GRED)"
 	---help---
net/sched/Makefile +1 -0
index 7b915d226de7..80c8f92d162d 100644
@@ -52,6 +52,7 @@ obj-$(CONFIG_NET_SCH_FQ_CODEL)	+= sch_fq_codel.o
 obj-$(CONFIG_NET_SCH_FQ)	+= sch_fq.o
 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_CLS_U32)	+= cls_u32.o
 obj-$(CONFIG_NET_CLS_ROUTE4)	+= cls_route.o
net/sched/sch_cbs.c new file +108 -0
new file mode 100644
index 000000000000..1c86a9e14150
@@ -0,0 +1,286 @@
+/*
+ * net/sched/sch_cbs.c	Credit Based Shaper
+ *
+ *		This program is free software; you can redistribute it and/or
+ *		modify it under the terms of the GNU General Public License
+ *		as published by the Free Software Foundation; either version
+ *		2 of the License, or (at your option) any later version.
+ *
+ * Authors:	Vininicius Costa Gomes <[email protected]>
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/skbuff.h>
+#include <net/netlink.h>
+#include <net/sch_generic.h>
+#include <net/pkt_sched.h>
+
+struct cbs_sched_data {
+	struct Qdisc *qdisc; /* Inner qdisc, default - pfifo queue */
+	s32 queue;
+	s32 locredit;
+	s32 hicredit;
+	s32 sendslope;
+	s32 idleslope;
+};
+
+static int cbs_enqueue(struct sk_buff *skb, struct Qdisc *sch,
+		       struct sk_buff **to_free)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+	int ret;
+
+	ret = qdisc_enqueue(skb, q->qdisc, to_free);
+	if (ret != NET_XMIT_SUCCESS) {
+		if (net_xmit_drop_count(ret))
+			qdisc_qstats_drop(sch);
+		return ret;
+	}
+
+	qdisc_qstats_backlog_inc(sch, skb);
+	sch->q.qlen++;
+	return NET_XMIT_SUCCESS;
+}
+
+static struct sk_buff *cbs_dequeue(struct Qdisc *sch)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+	struct sk_buff *skb;
+
+	skb = q->qdisc->ops->peek(q->qdisc);
+	if (skb) {
+		skb = qdisc_dequeue_peeked(q->qdisc);
+		if (unlikely(!skb))
+			return NULL;
+
+		qdisc_qstats_backlog_dec(sch, skb);
+		sch->q.qlen--;
+		qdisc_bstats_update(sch, skb);
+
+		return skb;
+	}
+	return NULL;
+}
+
+static void cbs_reset(struct Qdisc *sch)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+
+	qdisc_reset(q->qdisc);
+}
+
+static const struct nla_policy cbs_policy[TCA_CBS_MAX + 1] = {
+	[TCA_CBS_PARMS]	= { .len = sizeof(struct tc_cbs_qopt) },
+};
+
+static int cbs_change(struct Qdisc *sch, struct nlattr *opt)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+	struct tc_cbs_qopt_offload cbs = { };
+	struct nlattr *tb[TCA_CBS_MAX + 1];
+	const struct net_device_ops *ops;
+	struct tc_cbs_qopt *qopt;
+	struct net_device *dev;
+	int err;
+
+	err = nla_parse_nested(tb, TCA_CBS_MAX, opt, cbs_policy, NULL);
+	if (err < 0)
+		return err;
+
+	err = -EINVAL;
+	if (!tb[TCA_CBS_PARMS])
+		goto done;
+
+	qopt = nla_data(tb[TCA_CBS_PARMS]);
+
+	dev = qdisc_dev(sch);
+	ops = dev->netdev_ops;
+
+	/* FIXME: this means that we can only install this qdisc
+	 * "under" mqprio. Do we need a more generic way to retrieve
+	 * the queue, or do we pass the netdev_queue to the driver?
+	 */
+	cbs.queue = TC_H_MIN(sch->parent) - 1 - netdev_get_num_tc(dev);

net/sched/sch_cbs.c line 118

Quoted 10 lines
net/sched/sch_cbs.c new file +10 -0
+
+	cbs.enable = 1;
+	cbs.hicredit = qopt->hicredit;
+	cbs.locredit = qopt->locredit;
+	cbs.idleslope = qopt->idleslope;
+	cbs.sendslope = qopt->sendslope;
+
+	err = -ENOTSUPP;
+	if (!ops->ndo_setup_tc)
+		goto done;

This confuses tc a bit, and looking at other qdisc schedulers, it seems like EOPNOTSUPP is an alternative, this changes the output from

Quoted 4 lines

RTNETLINK answers: Unknown error 524
- to
RTNETLINK answers: Operation not supported

Yeah, I missed this. Thanks for catching this.

Quoted 43 lines

which perhaps is more informative.

Quoted 41 lines
net/sched/sch_cbs.c new file +41 -0
+
+	err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_CBS, &cbs);
+	if (err < 0)
+		goto done;
+
+	q->queue = cbs.queue;
+	q->hicredit = cbs.hicredit;
+	q->locredit = cbs.locredit;
+	q->idleslope = cbs.idleslope;
+	q->sendslope = cbs.sendslope;
+
+done:
+	return err;
+}
+
+static int cbs_init(struct Qdisc *sch, struct nlattr *opt)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+
+	if (!opt)
+		return -EINVAL;
+
+	q->qdisc = fifo_create_dflt(sch, &pfifo_qdisc_ops, 1024);
+	qdisc_hash_add(q->qdisc, true);
+
+	return cbs_change(sch, opt);
+}
+
+static void cbs_destroy(struct Qdisc *sch)
+{
+	struct cbs_sched_data *q = qdisc_priv(sch);
+	struct tc_cbs_qopt_offload cbs = { };
+	struct net_device *dev;
+	int err;
+
+	q->hicredit = 0;
+	q->locredit = 0;
+	q->idleslope = 0;
+	q->sendslope = 0;
+
+	dev = qdisc_dev(sch);
Quoted 8 lines

net/sched/sch_cbs.c line 164

Quoted 5 lines
net/sched/sch_cbs.c new file +5 -0
+
+	cbs.queue = q->queue;
+	cbs.enable = 0;
+
+	err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_CBS, &cbs);

This can lead to NULL pointer deref if it is not set (tested for in cbs_change and error there leads us here, which then explodes).

Fixed.

Quoted 9 lines

net/sched/sch_cbs.c line 169

Quoted 6 lines
net/sched/sch_cbs.c new file +5 -0
+	if (err < 0)
+		pr_warn("Couldn't reset queue %d to default values\n",
+			cbs.queue);
+
+	qdisc_destroy(q->qdisc);

Same, q->qdisc was NULL when cbs_init() failed.

Fixed the error path, thanks.

Cheers,
--
Vinicius

author maintainer
#5 lore raw

RFC 3/5 igb: Add support for CBS offload

In reply to Vinicius Costa Gomes

From: Andre Guedes <[email protected]>

This patch adds support for Credit-Based Shaper (CBS) qdisc offload from Traffic Control system. This support enable us to leverage the Forwarding and Queuing for Time-Sensitive Streams (FQTSS) features from Intel i210 Ethernet Controller. FQTSS is the former 802.1Qav standard which was merged into 802.1Q in 2014. It enables traffic prioritization and bandwidth reservation via the Credit-Based Shaper which is implemented in hardware by i210 controller.

The patch introduces the igb_setup_tc() function which implements the support for CBS qdisc hardware offload in the IGB driver. CBS offload is the only traffic control offload supported by the driver at the moment.

FQTSS transmission mode from i210 controller is automatically enabled by the IGB driver when the CBS is enabled for the first hardware queue. Likewise, FQTSS mode is automatically disabled when CBS is disabled for the last hardware queue. Changing FQTSS mode requires NIC reset.

FQTSS feature is supported by i210 controller only.

---
 drivers/net/ethernet/intel/igb/e1000_defines.h |  23 ++
 drivers/net/ethernet/intel/igb/e1000_regs.h    |   8 +
 drivers/net/ethernet/intel/igb/igb.h           |   6 +
 drivers/net/ethernet/intel/igb/igb_main.c      | 349 +++++++++++++++++++++++++
 4 files changed, 386 insertions(+)
drivers/net/ethernet/intel/igb/e1000_defines.h +23 -0
index 1de82f247312..83cabff1e0ab 100644
@@ -353,7 +353,18 @@
 #define E1000_RXPBS_CFG_TS_EN           0x80000000
 
 #define I210_RXPBSIZE_DEFAULT		0x000000A2 /* RXPBSIZE default */
+#define I210_RXPBSIZE_MASK		0x0000003F
+#define I210_RXPBSIZE_PB_32KB		0x00000020
 #define I210_TXPBSIZE_DEFAULT		0x04000014 /* TXPBSIZE default */
+#define I210_TXPBSIZE_MASK		0xC0FFFFFF
+#define I210_TXPBSIZE_PB0_8KB		(8 << 0)
+#define I210_TXPBSIZE_PB1_8KB		(8 << 6)
+#define I210_TXPBSIZE_PB2_4KB		(4 << 12)
+#define I210_TXPBSIZE_PB3_4KB		(4 << 18)
+
+#define I210_DTXMXPKTSZ_DEFAULT		0x00000098
+
+#define I210_SR_QUEUES_NUM		2
 
 /* SerDes Control */
 #define E1000_SCTL_DISABLE_SERDES_LOOPBACK 0x0400
@@ -1051,4 +1062,16 @@
 #define E1000_VLAPQF_P_VALID(_n)	(0x1 << (3 + (_n) * 4))
 #define E1000_VLAPQF_QUEUE_MASK	0x03
 
+/* TX Qav Control fields */
+#define E1000_TQAVCTRL_XMIT_MODE	BIT(0)
+#define E1000_TQAVCTRL_DATAFETCHARB	BIT(4)
+#define E1000_TQAVCTRL_DATATRANARB	BIT(8)
+
+/* TX Qav Credit Control fields */
+#define E1000_TQAVCC_IDLESLOPE_MASK	0xFFFF
+#define E1000_TQAVCC_QUEUEMODE		BIT(31)
+
+/* Transmit Descriptor Control fields */
+#define E1000_TXDCTL_PRIORITY		BIT(27)
+
 #endif
drivers/net/ethernet/intel/igb/e1000_regs.h +8 -0
index 58adbf234e07..8eee081d395f 100644
@@ -421,6 +421,14 @@ do { \
 
 #define E1000_I210_FLA		0x1201C
 
+#define E1000_I210_DTXMXPKTSZ	0x355C
+
+#define E1000_I210_TXDCTL(_n)	(0x0E028 + ((_n) * 0x40))
+
+#define E1000_I210_TQAVCTRL	0x3570
+#define E1000_I210_TQAVCC(_n)	(0x3004 + ((_n) * 0x40))
+#define E1000_I210_TQAVHC(_n)	(0x300C + ((_n) * 0x40))
+
 #define E1000_INVM_DATA_REG(_n)	(0x12120 + 4*(_n))
 #define E1000_INVM_SIZE		64 /* Number of INVM Data Registers */
 
drivers/net/ethernet/intel/igb/igb.h +6 -0
index 06ffb2bc713e..92845692087a 100644
@@ -281,6 +281,11 @@ struct igb_ring {
 	u16 count;			/* number of desc. in the ring */
 	u8 queue_index;			/* logical index of the ring*/
 	u8 reg_idx;			/* physical index of the ring */
+	bool cbs_enable;		/* indicates if CBS is enabled */
+	s32 idleslope;			/* idleSlope in kbps */
+	s32 sendslope;			/* sendSlope in kbps */
+	s32 hicredit;			/* hiCredit in bytes */
+	s32 locredit;			/* loCredit in bytes */
 
 	/* everything past this point are written often */
 	u16 next_to_clean;
@@ -621,6 +626,7 @@ struct igb_adapter {
 #define IGB_FLAG_EEE			BIT(14)
 #define IGB_FLAG_VLAN_PROMISC		BIT(15)
 #define IGB_FLAG_RX_LEGACY		BIT(16)
+#define IGB_FLAG_FQTSS			BIT(17)
 
 /* Media Auto Sense */
 #define IGB_MAS_ENABLE_0		0X0001
drivers/net/ethernet/intel/igb/igb_main.c +349 -0

385 lines not on this page · raw message

Signature · 1 line
2.14.1
author maintainer
#6 lore raw

RFC 4/5 sample: Add TSN Talker and Listener examples

In reply to Vinicius Costa Gomes

From: Jesus Sanchez-Palencia <[email protected]>

Add two examples so one can easily test a 'TSN distributed system' running with standard kernel interfaces. Both 'talker' and 'listener' sides are provided, and use a AF_PACKET for Tx / Rx of frames.

Running the examples is rather simple.
For the talker, just the interface and SO_PRIORITY are expected as parameters:

$ ./talker -i enp3s0 -p 3

For the listener, only the interface is needed:

$ ./listener -i enp3s0

The multicast MAC address being used is currently hardcoded on both examples for simplicity.

Note that the listener side uses a BPF filter so only frames sent to the correct "stream" destination address are received by the socket. If you modify the address used by the talker, you must also adapt the BPF filter otherwise no frames will be received by the socket.

The listener example will print the rate of packets reception after every 1 second. This makes it easier to verify if the bandwidth configured for a traffic class is being respected or not.

---
 samples/tsn/listener.c | 254 +++++++++++++++++++++++++++++++++++++++++++++++++
 samples/tsn/talker.c   | 136 ++++++++++++++++++++++++++
 2 files changed, 390 insertions(+)
 create mode 100644 samples/tsn/listener.c
 create mode 100644 samples/tsn/talker.c
samples/tsn/listener.c new file +254 -0
new file mode 100644
index 000000000000..2d17bdfbea99
@@ -0,0 +1,254 @@
+/*
+ * Copyright (c) 2017, Intel Corporation
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *     * Redistributions of source code must retain the above copyright notice,
+ *       this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Intel Corporation nor the names of its contributors
+ *       may be used to endorse or promote products derived from this software
+ *       without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <alloca.h>
+#include <argp.h>
+#include <arpa/inet.h>
+#include <inttypes.h>
+#include <linux/filter.h>
+#include <linux/if.h>
+#include <linux/if_ether.h>
+#include <linux/if_packet.h>
+#include <poll.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/timerfd.h>
+#include <unistd.h>
+
+#define MAX_FRAME_SIZE 1500
+
+/* XXX: If this address is changed, the BPF filter must be adjusted. */
+static uint8_t multicast_macaddr[] = { 0xBB, 0xAA, 0xBB, 0xAA, 0xBB, 0xAA };
+static char ifname[IFNAMSIZ];
+static uint64_t data_count;
+static int arg_count;
+
+/*
+ * BPF Filter so we only receive frames from the destination MAC address of our
+ * SRP stream. This is hardcoded in multicast_macaddr[].
+ */
+static struct sock_filter dst_addr_filter[] = {
+	{ 0x20,  0,  0, 0000000000 }, /* Load DST address: first 32bits only */
+	{ 0x15,  0,  3, 0xbbaabbaa }, /* Compare with first 32bits from MAC */
+	{ 0x28,  0,  0, 0x00000004 }, /* Load DST address: remaining 16bits */
+	{ 0x15,  0,  1, 0x0000bbaa }, /* Compare with last 16bits from MAC */
+	{ 0x06,  0,  0, 0xffffffff },
+	{ 0x06,  0,  0, 0000000000 }, /* Ret 0. Jump here if any mismatches. */
+};
+
+/* BPF program */
+static struct sock_fprog bpf = {
+	.len = 6, /* Number of instructions on BPF filter */
+	.filter = dst_addr_filter,
+};
+
+static struct argp_option options[] = {
+	{"ifname", 'i', "IFNAME", 0, "Network Interface" },
+	{ 0 }
+};
+
+static error_t parser(int key, char *arg, struct argp_state *s)
+{
+	switch (key) {
+	case 'i':
+		strncpy(ifname, arg, sizeof(ifname) - 1);
+		arg_count++;
+		break;
+	case ARGP_KEY_END:
+		if (arg_count < 1)
+			argp_failure(s, 1, 0, "Options missing. Check --help");
+		break;
+	}
+
+	return 0;
+}
+
+static struct argp argp = { options, parser };
+
+static int setup_1s_timer(void)
+{
+	struct itimerspec tspec = { 0 };
+	int fd, res;
+
+	fd = timerfd_create(CLOCK_MONOTONIC, 0);
+	if (fd < 0) {
+		perror("Couldn't create timer");
+		return -1;
+	}
+
+	tspec.it_value.tv_sec = 1;
+	tspec.it_interval.tv_sec = 1;
+
+	res = timerfd_settime(fd, 0, &tspec, NULL);
+	if (res < 0) {
+		perror("Couldn't set timer");
+		close(fd);
+		return -1;
+	}
+
+	return fd;
+}
+
+static int setup_socket(void)
+{
+	struct sockaddr_ll sk_addr = {
+		.sll_family = AF_PACKET,
+		.sll_protocol = htons(ETH_P_TSN),
+	};
+	struct packet_mreq mreq;
+	struct ifreq req;
+	int fd, res;
+
+	fd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_TSN));
+	if (fd < 0) {
+		perror("Couldn't open socket");
+		return -1;
+	}
+
+	res = setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &bpf, sizeof(bpf));
+	if (res < 0) {
+		perror("Couldn't attach bpf filter");
+		goto err;
+	}
+
+	strncpy(req.ifr_name, ifname, sizeof(req.ifr_name));
+	res = ioctl(fd, SIOCGIFINDEX, &req);
+	if (res < 0) {
+		perror("Couldn't get interface index");
+		goto err;
+	}
+
+	sk_addr.sll_ifindex = req.ifr_ifindex;
+	res = bind(fd, (struct sockaddr *) &sk_addr, sizeof(sk_addr));
+	if (res < 0) {
+		perror("Couldn't bind() to interface");
+		goto err;
+	}
+
+	/* Use PACKET_ADD_MEMBERSHIP to add a binding to the Multicast Addr */
+	mreq.mr_ifindex = sk_addr.sll_ifindex;
+	mreq.mr_type = PACKET_MR_MULTICAST;
+	mreq.mr_alen = ETH_ALEN;
+	memcpy(&mreq.mr_address, multicast_macaddr, ETH_ALEN);
+
+	res = setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP,
+				&mreq, sizeof(struct packet_mreq));
+	if (res < 0) {
+		perror("Couldn't set PACKET_ADD_MEMBERSHIP");
+		goto err;
+	}
+
+	return fd;
+
+err:
+	close(fd);
+	return -1;
+}
+
+static void recv_packet(int fd)
+{
+	uint8_t *data = alloca(MAX_FRAME_SIZE);
+	ssize_t n = recv(fd, data, MAX_FRAME_SIZE, 0);
+
+	if (n < 0) {
+		perror("Failed to receive data");
+		return;
+	}
+
+	if (n != MAX_FRAME_SIZE)
+		printf("Size mismatch: expected %d, got %zd\n",
+		       MAX_FRAME_SIZE, n);
+
+	data_count += n;
+}
+
+static void report_bw(int fd)
+{
+	uint64_t expirations;
+	ssize_t n = read(fd, &expirations, sizeof(uint64_t));
+
+	if (n < 0) {
+		perror("Couldn't read timerfd");
+		return;
+	}
+
+	if (expirations != 1)
+		printf("Something went wrong with timerfd\n");
+
+	/* Report how much data was received in 1s. */
+	printf("Data rate: %zu kbps\n", (data_count * 8) / 1000);
+
+	data_count = 0;
+}
+
+int main(int argc, char *argv[])
+{
+	int sk_fd, timer_fd, res;
+	struct pollfd fds[2];
+
+	argp_parse(&argp, argc, argv, 0, NULL, NULL);
+
+	sk_fd = setup_socket();
+	if (sk_fd < 0)
+		return 1;
+
+	timer_fd = setup_1s_timer();
+	if (timer_fd < 0) {
+		close(sk_fd);
+		return 1;
+	}
+
+	fds[0].fd = sk_fd;
+	fds[0].events = POLLIN;
+	fds[1].fd = timer_fd;
+	fds[1].events = POLLIN;
+
+	printf("Waiting for packets...\n");
+
+	while (1) {
+		res = poll(fds, 2, -1);
+		if (res < 0) {
+			perror("Error on poll()");
+			goto err;
+		}
+
+		if (fds[0].revents & POLLIN)
+			recv_packet(fds[0].fd);
+
+		if (fds[1].revents & POLLIN)
+			report_bw(fds[1].fd);
+	}
+
+err:
+	close(timer_fd);
+	close(sk_fd);
+	return 1;
+}
samples/tsn/talker.c new file +136 -0

136 lines not on this page · raw message

Signature · 1 line
2.14.1
author maintainer
#7 lore raw

RFC 5/5 samples/tsn: Add script for calculating CBS config

In reply to Vinicius Costa Gomes

From: Andre Guedes <[email protected]>

Add a script that takes as input the parameters of the Credit-based shaper used on FQTSS - link rate, max frame size of best effort traffic, idleslope and maximum frame size of the time-sensitive traffic class - for SR classes A and B, and calculates how the CBS qdisc must be configured for each traffic class.

For example, if you want to have Class A with a bandwidth of 300 Mbps and Class B of 200 Mbps, and the max frame size of both classes' traffic is 1500 bytes:

$ ./calculate_cbs_params.py -A 300000 -a 1500 -B 200000 -b 1500

would give you the correct cbs qdisc config command lines to be used.

This script is just a helper to ease testing of the TSN samples - talker and listener - and shouldn't be taken as highly accurate.

---
 samples/tsn/calculate_cbs_params.py | 112 ++++++++++++++++++++++++++++++++++++
 1 file changed, 112 insertions(+)
 create mode 100755 samples/tsn/calculate_cbs_params.py
samples/tsn/calculate_cbs_params.py new file +112 -0
new file mode 100755
index 000000000000..9c46210b699f
@@ -0,0 +1,112 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2017, Intel Corporation
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#     * Redistributions of source code must retain the above copyright notice,
+#       this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in the
+#       documentation and/or other materials provided with the distribution.
+#     * Neither the name of Intel Corporation nor the names of its contributors
+#       may be used to endorse or promote products derived from this software
+#       without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import argparse
+import math
+import sys
+
+def print_cbs_params_for_class_a(args):
+    idleslope = args.idleslope_a
+    sendslope = idleslope - args.link_speed
+
+    # According to 802.1Q-2014 spec, Annex L, hiCredit and
+    # loCredit for SR class A are calculated following the
+    # equations L-10 and L-12, respectively.
+    hicredit = math.ceil(idleslope * args.frame_non_sr / args.link_speed)
+    locredit = math.ceil(sendslope * args.frame_a / args.link_speed)
+
+    print("Class A --> # tc qdisc replace dev IFACE parent ID cbs " \
+          "locredit %d hicredit %d sendslope %d idleslope %d" % \
+          (locredit, hicredit, sendslope, idleslope))
+
+def print_cbs_params_for_class_b(args):
+    idleslope = args.idleslope_b
+    sendslope = idleslope - args.link_speed
+
+    # Annex L doesn't present a straightforward equation to
+    # calculate hiCredit for Class B so we have to derive it
+    # based on generic equations presented in that Annex.
+    #
+    # L-3 is the primary equation to calculate hiCredit. Section
+    # L.2 states that the 'maxInterferenceSize' for SR class B
+    # is the maximum burst size for SR class A plus the
+    # maxInterferenceSize from SR class A (which is equal to the
+    # maximum frame from non-SR traffic).
+    #
+    # The maximum burst size for SR class A equation is shown in
+    # L-16. Merging L-16 into L-3 we get the resulting equation
+    # which calculates hiCredit B (refer to section L.3 in case
+    # you're not familiar with the legend):
+    #
+    # hiCredit B = Rb * (     Mo         Ma   )
+    #                     ---------- + ------
+    #                      Ro - Ra       Ro
+    #
+    hicredit = math.ceil(idleslope * \
+               ((args.frame_non_sr / (args.link_speed - args.idleslope_a)) + \
+               (args.frame_a / args.link_speed)))
+
+    # loCredit B is calculated following equation L-2.
+    locredit = math.ceil(sendslope * args.frame_b / args.link_speed)
+
+    print("Class B --> # tc qdisc replace dev IFACE parent ID cbs " \
+          "locredit %d hicredit %d sendslope %d idleslope %d" % \
+          (locredit, hicredit, sendslope, idleslope))
+
+def main():
+    parser = argparse.ArgumentParser()
+
+    parser.add_argument('-S', dest='link_speed', default=1000000.0, type=float,
+                        help='Link speed in kbps (default=1000000)')
+    parser.add_argument('-s', dest='frame_non_sr', default=1500.0, type=float,
+                        help='Maximum frame size from non-SR traffic (MTU size'
+                        ' usually, default=1500)')
+    parser.add_argument('-A', dest='idleslope_a', default=0, type=float,
+                        help='Idleslope for SR class A in kbps')
+    parser.add_argument('-a', dest='frame_a', default=0, type=float,
+                        help='Maximum frame size for SR class A traffic')
+    parser.add_argument('-B', dest='idleslope_b', default=0, type=float,
+                        help='Idleslope for SR class B in kbps')
+    parser.add_argument('-b', dest='frame_b', default=0, type=float,
+                        help='Maximum frame size for SR class B traffic')
+
+    args = parser.parse_args()
+
+    if not len(sys.argv) > 1:
+        parser.print_help()
+    else:
+        print("\nConfiguration lines to be used are:")
+
+    if args.idleslope_a > 0:
+        print_cbs_params_for_class_a(args)
+
+    if args.idleslope_b > 0:
+        print_cbs_params_for_class_b(args)
+
+
+if __name__ == "__main__":
+    main()
Signature · 1 line
2.14.1
#8 lore raw
In reply to Vinicius Costa Gomes

I happy to see this posted. At first glance, it seems like a step in the right direction.

Quoted 1 line · Vinicius Costa Gomes

* Time-aware shaper (802.1Qbv):

...

Quoted 6 lines

S 0x01 300
S 0x03 500

This means that there are two intervals, the first will have the gate for traffic class 0 open for 300 nanoseconds, the second will have both traffic classes open for 500 nanoseconds.

The i210 doesn't support this in HW, or does it?

Quoted 8 lines

* Frame Preemption (802.1Qbu):

To control even further the latency, it may prove useful to signal which traffic classes are marked as preemptable. For that, 'taprio' provides the preemption command so you set each traffic class as preemptable or not:

   $ tc qdisc (...) \
        preemption 0 1 1 1

Neither can the i210 preempt frames, or what am I missing?

The timing of this RFC is good, as I am just finishing up an RFC that implements time-based transmit using the i210. I'll try and get that out ASAP.

Thanks,
Richard

#9 lore raw

Hi Richard,

Quoted 7 lines · Richard Cochran

I happy to see this posted. At first glance, it seems like a step in the right direction.

Quoted 1 line · Vinicius Costa Gomes

* Time-aware shaper (802.1Qbv):

...

Quoted 8 lines
Quoted 6 lines

S 0x01 300
S 0x03 500

This means that there are two intervals, the first will have the gate for traffic class 0 open for 300 nanoseconds, the second will have both traffic classes open for 500 nanoseconds.

The i210 doesn't support this in HW, or does it?

No, it does not. i210 only provides support for a per-packet feature called LaunchTime that can be used control both the fetch and the transmission time of packets.

Quoted 11 lines
Quoted 9 lines

* Frame Preemption (802.1Qbu):

To control even further the latency, it may prove useful to signal which traffic classes are marked as preemptable. For that, 'taprio' provides the preemption command so you set each traffic class as preemptable or not:

   $ tc qdisc (...) \
        preemption 0 1 1 1

Neither can the i210 preempt frames, or what am I missing?

No, it does not.

But when we started working on the shapers we decided to look ahead and try to come up with interfaces that could cover beyond 802.1Qav. These are just some ideas we've been prototyping here together with the 'cbs' qdisc.

Quoted 4 lines

The timing of this RFC is good, as I am just finishing up an RFC that implements time-based transmit using the i210. I'll try and get that out ASAP.

Is it correct to assume you are referring to an interface for Launchtime here?

Thanks,
Jesus

#10 lore raw
Quoted 1 line · Jesus Sanchez-Palencia

Is it correct to assume you are referring to an interface for Launchtime here?

Yes.

Thanks,
Richard

#11 lore raw
In reply to Jesus Sanchez-Palencia
Quoted 4 lines · Jesus Sanchez-Palencia
Quoted 3 lines · Richard Cochran

The timing of this RFC is good, as I am just finishing up an RFC that implements time-based transmit using the i210. I'll try and get that out ASAP.

I have an RFC series ready for net-next, but the the merge window just started. I'll post it when the window closes again...

Thanks,
Richard

#12 lore raw
In reply to Vinicius Costa Gomes
Quoted 7 lines · Vinicius Costa Gomes

Hi,

This patchset is an RFC on a proposal of how the Traffic Control subsystem can be used to offload the configuration of traffic shapers into network devices that provide support for them in HW. Our goal here is to start upstreaming support for features related to the Time-Sensitive Networking (TSN) set of standards into the kernel.

Nice to see that others are working on this as well! :)

A short disclaimer; I'm pretty much anchored in the view "linux is the end-station in a TSN domain", is this your approach as well, or are you looking at this driver to be used in bridges as well? (because that will affect the comments on time-aware shaper and frame preemption)

Yet another disclaimer; I am not a linux networking subsystem expert. Not by a long shot! There are black magic happening in the internals of the networking subsystem that I am not even aware of. So if something I say or ask does not make sense _at_all_, that's probably why..

I do know a tiny bit about TSN though, and I have been messing around with it for a little while, hence my comments below

Quoted 4 lines

As part of this work, we've assessed previous public discussions related to TSN
enabling: patches from Henrik Austad (Cisco), the presentation from Eric Mann at Linux Plumbers 2012, patches from Gangfeng Huang (National Instruments) and the current state of the OpenAVNU project (https://github.com/AVnu/OpenAvnu/).

/me eyes Cc ;p

Quoted 9 lines

Overview
========

Time-sensitive Networking (TSN) is a set of standards that aim to address resources availability for providing bandwidth reservation and bounded latency on Ethernet based LANs. The proposal described here aims to cover mainly what is needed to enable the following standards: 802.1Qat, 802.1Qav, 802.1Qbv and 802.1Qbu.

Quoted 3 lines

The initial target of this work is the Intel i210 NIC, but other controllers' datasheet were also taken into account, like the Renesas RZ/A1H RZ/A1M group and the Synopsis DesignWare Ethernet QoS controller.

NXP has a TSN aware chip on the i.MX7 sabre board as well </fyi>

Quoted 12 lines

Proposal
========

Feature-wise, what is covered here are configuration interfaces for HW implementations of the Credit-Based shaper (CBS, 802.1Qav), Time-Aware shaper (802.1Qbv) and Frame Preemption (802.1Qbu). CBS is a per-queue shaper, while Qbv and Qbu must be configured per port, with the configuration covering all queues. Given that these features are related to traffic shaping, and that the traffic control subsystem already provides a queueing discipline that offloads config into the device driver (i.e. mqprio), designing new qdiscs for the specific purpose of offloading the config for each shaper seemed like a good fit.

just to be clear, you register sch_cbs as a subclass to mqprio, not as a root class?

Quoted 3 lines

For steering traffic into the correct queues, we use the socket option SO_PRIORITY and then a mechanism to map priority to traffic classes / Tx queues. The qdisc mqprio is currently used in our tests.

Right, fair enough, I'd prefer the TSN qdisc to be the root-device and rather have mqprio for high priority traffic and another for 'everything else'', but this would work too. This is not that relevant at this stage I guess :)

Quoted 7 lines

As for the shapers config interface:

* CBS (802.1Qav)

This patchset is proposing a new qdisc called 'cbs'. Its 'tc' cmd line is:

   $ tc qdisc add dev IFACE parent ID cbs locredit N hicredit M sendslope S \
     idleslope I

So this confuses me a bit, why specify sendSlope?

sendSlope = portTransmitRate - idleSlope

and portTransmitRate is the speed of the MAC (which you get from the driver). Adding sendSlope here is just redundant I think.

Also, does this mean that when you create the qdisc, you have locked the bandwidth for the scheduler? Meaning, if I later want to add another stream that requires more bandwidth, I have to close all active streams, reconfigure the qdisc and then restart?

Quoted 2 lines

Note that the parameters for this qdisc are the ones defined by the 802.1Q-2014 spec, so no hardware specific functionality is exposed here.

You do need to know if the link is brought up as 100 or 1000 though - which the driver already knows.

Quoted 6 lines

* Time-aware shaper (802.1Qbv):

The idea we are currently exploring is to add a "time-aware", priority based qdisc, that also exposes the Tx queues available and provides a mechanism for mapping priority <-> traffic class <-> Tx queues in a similar fashion as mqprio. We are calling this qdisc 'taprio', and its 'tc' cmd line would be:

As far as I know, this is not supported by i210, and if time-aware shaping is enabled in the network - you'll be queued on a bridge until the window opens as time-aware shaping is enforced on the tx-port and not on rx. Is this required in this driver?

Quoted 5 lines
   $ $ tc qdisc add dev ens4 parent root handle 100 taprio num_tc 4    \
     	   map 2 2 1 0 3 3 3 3 3 3 3 3 3 3 3 3                         \
	   queues 0 1 2 3                                              \
     	   sched-file gates.sched [base-time <interval>]               \
           [cycle-time <interval>] [extension-time <interval>]

That was a lot of priorities! 802.1Q lists 8 priorities, where does these 16 come from?

You map pri 0,1 to queue 2, pri 2 to queue 1 (Class B), pri 3 to queue 0 (class A) and everythign else to queue 3. This is what I would expect, except for the additional 8 priorities.

Quoted 5 lines

<file> is multi-line, with each line being of the following format:
<cmd> <gate mask> <interval in nanoseconds>

Qbv only defines one <cmd>: "S" for 'SetGates'

Quoted 8 lines

For example:

S 0x01 300
S 0x03 500

This means that there are two intervals, the first will have the gate for traffic class 0 open for 300 nanoseconds, the second will have both traffic classes open for 500 nanoseconds.

Are you aware of any hw except dedicated switching stuff that supports this? (meant as "I'm curious and would like to know")

Quoted 10 lines
   Additionally, an option to set just one entry of the gate control list will
   also be provided by 'taprio':

   $ tc qdisc (...) \
        sched-row <row number> <cmd> <gate mask> <interval>  \
        [base-time <interval>] [cycle-time <interval>] \
        [extension-time <interval>]

* Frame Preemption (802.1Qbu):

So Frame preemption is nice, but my understanding of Qbu is that the real benefit is at the bridges and not in the endpoints. As jumbo-frames is explicitly disallowed in Qav, the maximum latency incurred by a frame in flight is 12us on a 1Gbps link. I am not sure if these 12us is what will be the main delay in your application.

Or have I missed some crucial point here?

Quoted 23 lines

To control even further the latency, it may prove useful to signal which traffic classes are marked as preemptable. For that, 'taprio' provides the preemption command so you set each traffic class as preemptable or not:

   $ tc qdisc (...) \
        preemption 0 1 1 1

* Time-aware shaper + Preemption:

As an example of how Qbv and Qbu can be used together, we may specify both the schedule and the preempt-mask, and this way we may also specify the Set-Gates-and-Hold and Set-Gates-and-Release commands as specified in the Qbu spec:

   $ tc qdisc add dev ens4 parent root handle 100 taprio num_tc 4 \
     	   map 2 2 1 0 3 3 3 3 3 3 3 3 3 3 3 3                    \
	   queues 0 1 2 3                                         \
     	   preemption 0 1 1 1                                     \
	   sched-file preempt_gates.sched

<file> is multi-line, with each line being of the following format:
<cmd> <gate mask> <interval in nanoseconds>

Quoted 7 lines

For this case, two new commands are introduced:

"H" for 'set gates and hold'
"R" for 'set gates and release'

H 0x01 300
R 0x03 500

So my understanding of all of this is that you configure the *total* bandwith for each class when you load the qdisc and then let userspace handle the rest. Is this correct?

In my view, it would be nice if the qdisc had some notion about streams so that you could create a stream, feed frames to it and let the driver pace them out. (The fewer you queue, the shorter the delay). This will also allow you to enforce per-stream bandwidth restrictions. I don't see how you can do this here unless you want to do this in userspace.

Do you have any plans for adding support for multiplexing streams? If you have multiple streams, how do you enforce that one stream does not eat into the bandwidth of another stream? AFAIK, this is something the network must enforce, but I see no option of doing som here.

Quoted 7 lines

Testing this RFC
================

For testing the patches of this RFC only, you can refer to the samples and helper script being added to samples/tsn/ and the use the 'mqprio' qdisc to setup the priorities to Tx queues mapping, together with the 'cbs' qdisc to configure the HW shaper of the i210 controller:

I will test it, feedback will be provided soon! :)

Thanks!
-Henrik

Quoted 38 lines

1) Setup priorities to traffic classes to hardware queues mapping

$ tc qdisc replace dev enp3s0 parent root mqprio num_tc 3 \
     map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 queues 1 at 0 1 at 1 2 at 2 hw 0

2) Check scheme. You want to get the inner qdiscs ID from the bottom up

$ tc -g  class show dev enp3s0

Ex.:

+---(802a:3) mqprio
|    +---(802a:6) mqprio
|    +---(802a:7) mqprio
|
+---(802a:2) mqprio
|    +---(802a:5) mqprio
|
+---(802a:1) mqprio
     +---(802a:4) mqprio

* Here '802a:4' is Tx Queue #0 and '802a:5' is Tx Queue #1.

3) Calculate CBS parameters for classes A and B. i.e. BW for A is 20Mbps and for B is 10Mbps:

$ ./samples/tsn/calculate_cbs_params.py -A 20000 -a 1500 -B 10000 -b 1500

4) Configure CBS for traffic class A (priority 3) as provided by the script:

$ tc qdisc replace dev enp3s0 parent 802a:4 cbs locredit -1470 \
     hicredit 30 sendslope -980000 idleslope 20000

5) Configure CBS for traffic class B (priority 2):

$ tc qdisc replace dev enp3s0 parent 802a:5 cbs \
     locredit -1485 hicredit 31 sendslope -990000 idleslope 10000

6) Run Listener, compiled from samples/tsn/listener.c

$ ./listener -i enp3s0

7) Run Talker for class A (prio 3 here), compiled from samples/tsn/talker.c

$ ./talker -i enp3s0 -p 3
Quoted 8 lines

* The bandwidth displayed on the listener output at this stage should be very close to the one configured for class A.

8) You can also run a Talker for class B (prio 2 here)

$ ./talker -i enp3s0 -p 2

* The bandwidth displayed on the listener output now should increase to very close to the one configured for class A + class B.

Because you grab both class A *and* B, or because B will eat what A does not use?

-H

Quoted 39 lines

Authors
=======
- Andre Guedes <[email protected]>
- Ivan Briano <[email protected]>
- Jesus Sanchez-Palencia <[email protected]>
- Vinicius Gomes <[email protected]>

Andre Guedes (2):
igb: Add support for CBS offload samples/tsn: Add script for calculating CBS config

Jesus Sanchez-Palencia (1):
sample: Add TSN Talker and Listener examples

Vinicius Costa Gomes (2):
net/sched: Introduce the user API for the CBS shaper net/sched: Introduce Credit Based Shaper (CBS) qdisc

 drivers/net/ethernet/intel/igb/e1000_defines.h |  23 ++
 drivers/net/ethernet/intel/igb/e1000_regs.h    |   8 +
 drivers/net/ethernet/intel/igb/igb.h           |   6 +
 drivers/net/ethernet/intel/igb/igb_main.c      | 349 +++++++++++++++++++++++++
 include/linux/netdevice.h                      |   1 +
 include/uapi/linux/pkt_sched.h                 |  29 ++
 net/sched/Kconfig                              |  11 +
 net/sched/Makefile                             |   1 +
 net/sched/sch_cbs.c                            | 286 ++++++++++++++++++++
 samples/tsn/calculate_cbs_params.py            | 112 ++++++++
 samples/tsn/listener.c                         | 254 ++++++++++++++++++
 samples/tsn/talker.c                           | 136 ++++++++++
 12 files changed, 1216 insertions(+)
 create mode 100644 net/sched/sch_cbs.c
 create mode 100755 samples/tsn/calculate_cbs_params.py
 create mode 100644 samples/tsn/listener.c
 create mode 100644 samples/tsn/talker.c

--
2.14.1

Signature · 8 lines
Henrik Austad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20170907/64f4be36/attachment.asc>
#13 lore raw
Quoted 4 lines · Henrik Austad

Also, does this mean that when you create the qdisc, you have locked the bandwidth for the scheduler? Meaning, if I later want to add another stream that requires more bandwidth, I have to close all active streams, reconfigure the qdisc and then restart?

No, just allocate enough bandwidth to accomodate all of the expected streams. The streams can start and stop at will.

Quoted 3 lines

So my understanding of all of this is that you configure the *total* bandwith for each class when you load the qdisc and then let userspace handle the rest. Is this correct?

Nothing wrong with that.

Quoted 10 lines

In my view, it would be nice if the qdisc had some notion about streams so that you could create a stream, feed frames to it and let the driver pace them out. (The fewer you queue, the shorter the delay). This will also allow you to enforce per-stream bandwidth restrictions. I don't see how you can do this here unless you want to do this in userspace.

Do you have any plans for adding support for multiplexing streams? If you have multiple streams, how do you enforce that one stream does not eat into the bandwidth of another stream? AFAIK, this is something the network must enforce, but I see no option of doing som here.

Please, lets keep this simple. Today we have exactly zero user space applications using this kind of bandwidth reservation. The case of wanting the kernel to police individual stream usage does not exist, and probably never will.

For serious TSN use cases, the bandwidth needed by each system and indeed the entire network will be engineered, and we can reasonably expect applications to cooperate in this regard.

Thanks,
Richard

#14 lore raw
Quoted 8 lines · Richard Cochran
Quoted 4 lines · Henrik Austad

Also, does this mean that when you create the qdisc, you have locked the bandwidth for the scheduler? Meaning, if I later want to add another stream that requires more bandwidth, I have to close all active streams, reconfigure the qdisc and then restart?

No, just allocate enough bandwidth to accomodate all of the expected streams. The streams can start and stop at will.

Sure, that'll work.

And if you want to this driver to act as a bridge, how do you accomodate change in network requirements? (i.e. how does this work with switchdev?)
- Or am I overthinking this?

Quoted 5 lines
Quoted 3 lines

So my understanding of all of this is that you configure the *total* bandwith for each class when you load the qdisc and then let userspace handle the rest. Is this correct?

Nothing wrong with that.

Didn't mean to say it was wrong, just making sure I've understood the concept.

Quoted 6 lines
Quoted 6 lines

In my view, it would be nice if the qdisc had some notion about streams so that you could create a stream, feed frames to it and let the driver pace them out. (The fewer you queue, the shorter the delay). This will also allow you to enforce per-stream bandwidth restrictions. I don't see how you can do this here unless you want to do this in userspace.

Quoted 6 lines
Quoted 4 lines

Do you have any plans for adding support for multiplexing streams? If you have multiple streams, how do you enforce that one stream does not eat into the bandwidth of another stream? AFAIK, this is something the network must enforce, but I see no option of doing som here.

Please, lets keep this simple.

Simple is always good

Quoted 4 lines

Today we have exactly zero user space
applications using this kind of bandwidth reservation. The case of wanting the kernel to police individual stream usage does not exist, and probably never will.

That we have *zero* userspace applications today is probably related to the fact that we have exacatly *zero* drivers in the kernel that talks TSN :)

To rephrase a bit, what I'm worried about:

If you have more than 1 application in userspace that wants to send data using this scheduler, how do you ensure fair transmission of frames? (both how much bandwidth they use, but also ordering of frames from each application) Do you expect all of this to be handled in userspace?

Quoted 3 lines

For serious TSN use cases, the bandwidth needed by each system and indeed the entire network will be engineered, and we can reasonably expect applications to cooperate in this regard.

yes.. that'll happen ;)

Quoted 2 lines

Thanks,
Richard

Don't get me wrong, I think it is great that others are working on this! I'm just trying to fully understand the thought that have gone into this and how it is inteded to be used.

I'll get busy testing the code and wrapping my head around the different parameters.

Signature · 8 lines
Henrik Austad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20170907/960e74a4/attachment.asc>
#15 lore raw
Quoted 3 lines · Henrik Austad

On Thu, Sep 07, 2017 at 02:40:18PM +0200, Richard Cochran wrote:
And if you want to this driver to act as a bridge, how do you accomodate change in network requirements? (i.e. how does this work with switchdev?)

To my understanding, this Qdisc idea provides QoS for the host's transmitted traffic, and nothing more.

Quoted 1 line

- Or am I overthinking this?

Being able to configure the external ports of a switchdev is probably a nice feature, but that is another story. (But maybe I misunderstood the authors' intent!)

Quoted 3 lines

If you have more than 1 application in userspace that wants to send data using this scheduler, how do you ensure fair transmission of frames? (both how much bandwidth they use,

There are many ways to handle this, and we shouldn't put any of that policy into the kernel. For example, there might be a monolithic application with configurable threads, or an allocation server that grants bandwidth to applications via IPC, or a multiplexing stream server like jack, pulse, etc, and so on...

Quoted 1 line

but also ordering of frames from each application)

Not sure what you mean by this.

Quoted 1 line

Do you expect all of this to be handled in userspace?

Yes, I do.

Thanks,
Richard

#16 lore raw
Quoted 7 lines · Richard Cochran
Quoted 3 lines · Henrik Austad

On Thu, Sep 07, 2017 at 02:40:18PM +0200, Richard Cochran wrote:
And if you want to this driver to act as a bridge, how do you accomodate change in network requirements? (i.e. how does this work with switchdev?)

To my understanding, this Qdisc idea provides QoS for the host's transmitted traffic, and nothing more.

Ok, then we're on the same page.

Quoted 5 lines
Quoted 1 line

- Or am I overthinking this?

Being able to configure the external ports of a switchdev is probably a nice feature, but that is another story. (But maybe I misunderstood the authors' intent!)

ok, chalk that one up for later perhaps

Quoted 9 lines
Quoted 3 lines

If you have more than 1 application in userspace that wants to send data using this scheduler, how do you ensure fair transmission of frames? (both how much bandwidth they use,

There are many ways to handle this, and we shouldn't put any of that policy into the kernel. For example, there might be a monolithic application with configurable threads, or an allocation server that grants bandwidth to applications via IPC, or a multiplexing stream server like jack, pulse, etc, and so on...

true

Quoted 3 lines
Quoted 1 line

but also ordering of frames from each application)

Not sure what you mean by this.

Fair enough, I'm not that good at making myself clear :)

Let's see if I can make a better attempt:

If you have 2 separate applications that have their own streams going to different endpoints - but both are in the same class, then they will share the qdisc bandwidth.

So application
- A sends frame A1, A2, A3, .. An
- B sends B1, B2, .. Bn

What I was trying to describe was: if application A send 2 frames, and B sends 2 frames at the same time, then you would hope that the order would be A1, B1, A2, B2, and not A1, A2, B1, B2.

None of this would be a problem if you expect a *single* user, like the allocation server you described above. Again, I think this is just me overthinking the problem right now :)

Quoted 3 lines
Quoted 1 line

Do you expect all of this to be handled in userspace?

Yes, I do.

ok, fair enough

Thanks for answering my questions!

Signature · 8 lines
Henrik Austad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20170907/9b81992f/attachment.asc>
#17 lore raw
Quoted 11 lines · Henrik Austad
Quoted 7 lines · Richard Cochran
Quoted 3 lines · Henrik Austad

On Thu, Sep 07, 2017 at 02:40:18PM +0200, Richard Cochran wrote:
And if you want to this driver to act as a bridge, how do you accomodate? change in network requirements? (i.e. how does this work with switchdev?)

?
To my understanding, this Qdisc idea provides QoS for the host's transmitted traffic, and nothing more.

Ok, then we're on the same page.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

- Or am I overthinking this?

?
Being able to configure the external ports of a switchdev is probably a nice feature, but that is another story.? (But maybe I misunderstood the authors' intent!)

ok, chalk that one up for later perhaps

Just to clarify, we've been most focused on end-station use-cases. We've considered some bridge use-cases as well just to verify that the proposed design won't be an issue if someone else goes for it.

- Andre
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3262 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20170907/83455e39/attachment-0001.bin>

#18 lore raw
In reply to Henrik Austad

Hi Henrik,

Thanks for your feedback! I'll address some of your comments below.

Quoted 10 lines · Henrik Austad
Quoted 9 lines

As for the shapers config interface:

?* CBS (802.1Qav)

???This patchset is proposing a new qdisc called 'cbs'. Its 'tc' cmd line is:
???$ tc qdisc add dev IFACE parent ID cbs locredit N hicredit M sendslope S \
?????idleslope I

Quoted 6 lines

So this confuses me a bit, why specify sendSlope?

????sendSlope = portTransmitRate - idleSlope

and portTransmitRate is the speed of the MAC (which you get from the? driver). Adding sendSlope here is just redundant I think.

Yes, this was something we've spent quite a few time discussing before this RFC series. After reading the Annex L from 802.1Q-2014 (operation of CBS algorithm) so many times, we've came up with the rationale explained below.

The rationale here is that sendSlope is just another parameter from CBS algorithm like idleSlope, hiCredit and loCredit. As such,?its calculation should be done at the same "layer" as the others parameters (in this case, user space) in order to keep consistency. Moreover, in this design, the driver layer is dead simple: all the device driver?has to do is applying CBS parameters to hardware. Having any CBS parameter calculation in the driver layer means all device drivers must implement that calculation.

Quoted 4 lines

Also, does this mean that when you create the qdisc, you have locked the? bandwidth for the scheduler? Meaning, if I later want to add another? stream that requires more bandwidth, I have to close all active streams,? reconfigure the qdisc and then restart?

If we want to reserve more bandwidth to "accommodate" a new stream, we don't need to close all active streams. All we have to do is changing the CBS qdisc and pass the new CBS parameters. Here is what the command-line would look like:

$ tc qdisc change dev enp0s4 parent 8001:5 cbs locredit -1470 hicredit 30
sendslope -980000 idleslope 20000

No application/stream is interrupted while new CBS parameters are applied.

Quoted 5 lines
Quoted 2 lines

???Note that the parameters for this qdisc are the ones defined by the ???802.1Q-2014 spec, so no hardware specific functionality is exposed here.

You do need to know if the link is brought up as 100 or 1000 though - which? the driver already knows.

User space knows that information via ethtool or /sys.

Quoted 9 lines
Quoted 7 lines

Testing this RFC
================

For testing the patches of this RFC only, you can refer to the samples and helper script being added to samples/tsn/ and the use the 'mqprio' qdisc to setup the priorities to Tx queues mapping, together with the 'cbs' qdisc to configure the HW shaper of the i210 controller:

I will test it, feedback will be provided soon! :)

That's great! Please let us know if you find any issue and thanks for you support.

Quoted 9 lines
Quoted 6 lines

8) You can also run a Talker for class B (prio 2 here)

$ ./talker -i enp3s0 -p 2

?* The bandwidth displayed on the listener output now should increase to very
???close to the one configured for class A + class B.

Because you grab both class A *and* B, or because B will eat what A does? not use?

Because the listener application grabs both class A and B traffic.

Regards,

Andre
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3262 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20170907/84197122/attachment.bin>

#19 lore raw
Quoted 26 lines · Andre

Hi Henrik,

Thanks for your feedback! I'll address some of your comments below.

Quoted 10 lines · Henrik Austad
Quoted 9 lines

As for the shapers config interface:

?* CBS (802.1Qav)

???This patchset is proposing a new qdisc called 'cbs'. Its 'tc' cmd line is:
???$ tc qdisc add dev IFACE parent ID cbs locredit N hicredit M sendslope S \
?????idleslope I

Quoted 6 lines

So this confuses me a bit, why specify sendSlope?

????sendSlope = portTransmitRate - idleSlope

and portTransmitRate is the speed of the MAC (which you get from the? driver). Adding sendSlope here is just redundant I think.

Yes, this was something we've spent quite a few time discussing before this RFC series. After reading the Annex L from 802.1Q-2014 (operation of CBS algorithm) so many times, we've came up with the rationale explained below.

Quoted 7 lines

The rationale here is that sendSlope is just another parameter from CBS algorithm like idleSlope, hiCredit and loCredit. As such,?its calculation should be done at the same "layer" as the others parameters (in this case, user space) in order to keep consistency. Moreover, in this design, the driver layer is dead simple: all the device driver?has to do is applying CBS parameters to hardware. Having any CBS parameter calculation in the driver layer means all device drivers must implement that calculation.

Ok, that actually makes a lot of sense, and anything that keeps this kind of arithmetic outside the kernel is a good thing!

Thanks for the clarification!

Quoted 5 lines
Quoted 4 lines

Also, does this mean that when you create the qdisc, you have locked the? bandwidth for the scheduler? Meaning, if I later want to add another? stream that requires more bandwidth, I have to close all active streams,? reconfigure the qdisc and then restart?

Quoted 8 lines

If we want to reserve more bandwidth to "accommodate" a new stream, we don't need to close all active streams. All we have to do is changing the CBS qdisc and pass the new CBS parameters. Here is what the command-line would look like:

$ tc qdisc change dev enp0s4 parent 8001:5 cbs locredit -1470 hicredit 30
sendslope -980000 idleslope 20000

No application/stream is interrupted while new CBS parameters are applied.

Ah, good.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

???Note that the parameters for this qdisc are the ones defined by the ???802.1Q-2014 spec, so no hardware specific functionality is exposed here.

You do need to know if the link is brought up as 100 or 1000 though - which? the driver already knows.

User space knows that information via ethtool or /sys.

Fair point.

Quoted 16 lines
Quoted 9 lines
Quoted 7 lines

Testing this RFC
================

For testing the patches of this RFC only, you can refer to the samples and helper script being added to samples/tsn/ and the use the 'mqprio' qdisc to setup the priorities to Tx queues mapping, together with the 'cbs' qdisc to configure the HW shaper of the i210 controller:

I will test it, feedback will be provided soon! :)

That's great! Please let us know if you find any issue and thanks for you support.

Quoted 3 lines
Quoted 3 lines

8) You can also run a Talker for class B (prio 2 here)

$ ./talker -i enp3s0 -p 2
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

?* The bandwidth displayed on the listener output now should increase to very
???close to the one configured for class A + class B.

Because you grab both class A *and* B, or because B will eat what A does? not use?

Because the listener application grabs both class A and B traffic.

Right, got it.

Thanks for the feedback, I'm getting really excited about this! :D

Signature · 8 lines
Henrik Austad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20170908/466ef6a1/attachment.asc>
author maintainer
#20 lore raw
In reply to Henrik Austad
Quoted 40 lines · Henrik Austad
Quoted 7 lines · Vinicius Costa Gomes

Hi,

This patchset is an RFC on a proposal of how the Traffic Control subsystem can be used to offload the configuration of traffic shapers into network devices that provide support for them in HW. Our goal here is to start upstreaming support for features related to the Time-Sensitive Networking (TSN) set of standards into the kernel.

Nice to see that others are working on this as well! :)

A short disclaimer; I'm pretty much anchored in the view "linux is the end-station in a TSN domain", is this your approach as well, or are you looking at this driver to be used in bridges as well? (because that will affect the comments on time-aware shaper and frame preemption)

Yet another disclaimer; I am not a linux networking subsystem expert. Not by a long shot! There are black magic happening in the internals of the networking subsystem that I am not even aware of. So if something I say or ask does not make sense _at_all_, that's probably why..

I do know a tiny bit about TSN though, and I have been messing around with it for a little while, hence my comments below

Quoted 4 lines

As part of this work, we've assessed previous public discussions related to TSN
enabling: patches from Henrik Austad (Cisco), the presentation from Eric Mann at Linux Plumbers 2012, patches from Gangfeng Huang (National Instruments) and the current state of the OpenAVNU project (https://github.com/AVnu/OpenAvnu/).

/me eyes Cc ;p

Quoted 9 lines

Overview
========

Time-sensitive Networking (TSN) is a set of standards that aim to address resources availability for providing bandwidth reservation and bounded latency on Ethernet based LANs. The proposal described here aims to cover mainly what is needed to enable the following standards: 802.1Qat, 802.1Qav, 802.1Qbv and 802.1Qbu.

Quoted 5 lines
Quoted 3 lines

The initial target of this work is the Intel i210 NIC, but other controllers' datasheet were also taken into account, like the Renesas RZ/A1H RZ/A1M group and the Synopsis DesignWare Ethernet QoS controller.

NXP has a TSN aware chip on the i.MX7 sabre board as well </fyi>

Cool. Will take a look.

Quoted 14 lines
Quoted 4 lines

Proposal
========

Quoted 9 lines

Feature-wise, what is covered here are configuration interfaces for HW implementations of the Credit-Based shaper (CBS, 802.1Qav), Time-Aware shaper (802.1Qbv) and Frame Preemption (802.1Qbu). CBS is a per-queue shaper, while Qbv and Qbu must be configured per port, with the configuration covering all queues. Given that these features are related to traffic shaping, and that the traffic control subsystem already provides a queueing discipline that offloads config into the device driver (i.e. mqprio), designing new qdiscs for the specific purpose of offloading the config for each shaper seemed like a good fit.

Quoted 2 lines

just to be clear, you register sch_cbs as a subclass to mqprio, not as a root class?

That's right.

Quoted 9 lines
Quoted 4 lines

For steering traffic into the correct queues, we use the socket option SO_PRIORITY and then a mechanism to map priority to traffic classes / Tx queues. The qdisc mqprio is currently used in our tests.

Right, fair enough, I'd prefer the TSN qdisc to be the root-device and rather have mqprio for high priority traffic and another for 'everything else'', but this would work too. This is not that relevant at this stage I guess :)

That's a scenario I haven't considered, will give it some thought.

Quoted 34 lines
Quoted 8 lines

As for the shapers config interface:

* CBS (802.1Qav)

This patchset is proposing a new qdisc called 'cbs'. Its 'tc' cmd line is:

   $ tc qdisc add dev IFACE parent ID cbs locredit N hicredit M sendslope S \
     idleslope I

So this confuses me a bit, why specify sendSlope?

sendSlope = portTransmitRate - idleSlope

and portTransmitRate is the speed of the MAC (which you get from the driver). Adding sendSlope here is just redundant I think.

Also, does this mean that when you create the qdisc, you have locked the bandwidth for the scheduler? Meaning, if I later want to add another stream that requires more bandwidth, I have to close all active streams, reconfigure the qdisc and then restart?

Quoted 2 lines

Note that the parameters for this qdisc are the ones defined by the 802.1Q-2014 spec, so no hardware specific functionality is exposed here.

You do need to know if the link is brought up as 100 or 1000 though - which the driver already knows.

Quoted 6 lines

* Time-aware shaper (802.1Qbv):

The idea we are currently exploring is to add a "time-aware", priority based qdisc, that also exposes the Tx queues available and provides a mechanism for mapping priority <-> traffic class <-> Tx queues in a similar fashion as mqprio. We are calling this qdisc 'taprio', and its 'tc' cmd line would be:

Quoted 4 lines

As far as I know, this is not supported by i210, and if time-aware shaping is enabled in the network - you'll be queued on a bridge until the window opens as time-aware shaping is enforced on the tx-port and not on rx. Is this required in this driver?

Yeah, i210 doesn't support the time-aware shaper. I think the second part of your question doesn't really apply, then.

Quoted 9 lines
Quoted 6 lines
   $ $ tc qdisc add dev ens4 parent root handle 100 taprio num_tc 4    \
     	   map 2 2 1 0 3 3 3 3 3 3 3 3 3 3 3 3                         \
	   queues 0 1 2 3                                              \
     	   sched-file gates.sched [base-time <interval>]               \
           [cycle-time <interval>] [extension-time <interval>]

That was a lot of priorities! 802.1Q lists 8 priorities, where does these 16 come from?

Even if the 802.1Q only defines 8 priorities, the Linux network stack supports a lot more (and this command line is more than slightly inspired by the mqprio equivalent).

Quoted 15 lines

You map pri 0,1 to queue 2, pri 2 to queue 1 (Class B), pri 3 to queue 0 (class A) and everythign else to queue 3. This is what I would expect, except for the additional 8 priorities.

Quoted 10 lines

<file> is multi-line, with each line being of the following format:
<cmd> <gate mask> <interval in nanoseconds>

   Qbv only defines one <cmd>: "S" for 'SetGates'

   For example:

   S 0x01 300
   S 0x03 500
Quoted 6 lines
Quoted 3 lines

This means that there are two intervals, the first will have the gate for traffic class 0 open for 300 nanoseconds, the second will have both traffic classes open for 500 nanoseconds.

Are you aware of any hw except dedicated switching stuff that supports this? (meant as "I'm curious and would like to know")

Not really. I couldn't find any public documentation about products destined for end stations that support this. I, too, would like to know more.

Quoted 12 lines
Quoted 11 lines
   Additionally, an option to set just one entry of the gate control list will
   also be provided by 'taprio':

   $ tc qdisc (...) \
        sched-row <row number> <cmd> <gate mask> <interval>  \
        [base-time <interval>] [cycle-time <interval>] \
        [extension-time <interval>]

* Frame Preemption (802.1Qbu):

Quoted 7 lines

So Frame preemption is nice, but my understanding of Qbu is that the real benefit is at the bridges and not in the endpoints. As jumbo-frames is explicitly disallowed in Qav, the maximum latency incurred by a frame in flight is 12us on a 1Gbps link. I am not sure if these 12us is what will be the main delay in your application.

Or have I missed some crucial point here?

You didn't seem to have missed anything. What I saw as the biggest point for frame preemption, is when it is used with scheduled traffic, you could keep the preemptable traffic classes gates always open, have a few time windows for periodic traffic, and still have predictable behaviour for an unscheduled "emergency" traffic.

Cheers,
--
Vinicius

#21 lore raw
Quoted 7 lines · Vinicius Costa Gomes
Quoted 7 lines
Quoted 6 lines

* Time-aware shaper (802.1Qbv):

The idea we are currently exploring is to add a "time-aware", priority based qdisc, that also exposes the Tx queues available and provides a mechanism for mapping priority <-> traffic class <-> Tx queues in a similar fashion as mqprio. We are calling this qdisc 'taprio', and its 'tc' cmd line would be:

Quoted 7 lines
Quoted 4 lines

As far as I know, this is not supported by i210, and if time-aware shaping is enabled in the network - you'll be queued on a bridge until the window opens as time-aware shaping is enforced on the tx-port and not on rx. Is this required in this driver?

Yeah, i210 doesn't support the time-aware shaper. I think the second part of your question doesn't really apply, then.

Actually, you can implement 802.1Qbv (as an end station) quite easily using the i210. I'll show how by posting a series after net-next opens up again.

Thanks,
Richard

#22 lore raw
In reply to Vinicius Costa Gomes
Quoted 1 line · Vinicius Costa Gomes

* Time-aware shaper (802.1Qbv):

I just posted a working alternative showing how to handle 802.1Qbv and many other Ethernet field buses.

Quoted 16 lines

The idea we are currently exploring is to add a "time-aware", priority based qdisc, that also exposes the Tx queues available and provides a mechanism for mapping priority <-> traffic class <-> Tx queues in a similar fashion as mqprio. We are calling this qdisc 'taprio', and its 'tc' cmd line would be:

   $ $ tc qdisc add dev ens4 parent root handle 100 taprio num_tc 4    \
     	   map 2 2 1 0 3 3 3 3 3 3 3 3 3 3 3 3                         \
	   queues 0 1 2 3                                              \
     	   sched-file gates.sched [base-time <interval>]               \
           [cycle-time <interval>] [extension-time <interval>]

<file> is multi-line, with each line being of the following format:
<cmd> <gate mask> <interval in nanoseconds>

Qbv only defines one <cmd>: "S" for 'SetGates'

Quoted 8 lines

For example:

S 0x01 300
S 0x03 500

This means that there are two intervals, the first will have the gate for traffic class 0 open for 300 nanoseconds, the second will have both traffic classes open for 500 nanoseconds.

The idea of the schedule file will not work in practice. Consider the fact that the application wants to deliver time critical data in a particular slot. How can it find out a) what the time slots are and
b) when the next slot is scheduled? With this Qdisc, it cannot do this, AFAICT. The admin might delete the file after configuring the Qdisc!

Using the SO_TXTIME option, the application has total control over the scheduling. The great advantages of this approach is that we can support any possible combination of periodic or aperiodic scheduling and we can support any priority scheme user space dreams up.

For example, one can imaging running two or more loops that only occasionally collide. When they do collide, which packet should be sent first? Just let user space decide.

Thanks,
Richard

#23 lore raw
Quoted 5 lines · Richard Cochran
Quoted 1 line · Vinicius Costa Gomes

* Time-aware shaper (802.1Qbv):

I just posted a working alternative showing how to handle 802.1Qbv and many other Ethernet field buses.

Yes, I saw them, grabbing them for testing now - thanks!

Quoted 32 lines
Quoted 16 lines

The idea we are currently exploring is to add a "time-aware", priority based qdisc, that also exposes the Tx queues available and provides a mechanism for mapping priority <-> traffic class <-> Tx queues in a similar fashion as mqprio. We are calling this qdisc 'taprio', and its 'tc' cmd line would be:

   $ $ tc qdisc add dev ens4 parent root handle 100 taprio num_tc 4    \
     	   map 2 2 1 0 3 3 3 3 3 3 3 3 3 3 3 3                         \
	   queues 0 1 2 3                                              \
     	   sched-file gates.sched [base-time <interval>]               \
           [cycle-time <interval>] [extension-time <interval>]

<file> is multi-line, with each line being of the following format:
<cmd> <gate mask> <interval in nanoseconds>

Qbv only defines one <cmd>: "S" for 'SetGates'

Quoted 8 lines

For example:

S 0x01 300
S 0x03 500

This means that there are two intervals, the first will have the gate for traffic class 0 open for 300 nanoseconds, the second will have both traffic classes open for 500 nanoseconds.

The idea of the schedule file will not work in practice. Consider the fact that the application wants to deliver time critical data in a particular slot. How can it find out a) what the time slots are and
b) when the next slot is scheduled? With this Qdisc, it cannot do this, AFAICT. The admin might delete the file after configuring the Qdisc!

Quoted 4 lines

Using the SO_TXTIME option, the application has total control over the scheduling. The great advantages of this approach is that we can support any possible combination of periodic or aperiodic scheduling and we can support any priority scheme user space dreams up.

Using SO_TXTIME makes a lot of sense. TSN has a presentation_time, which you can use to deduce the time it should be transmitted (Class A has a 2ms latency guarantee, B has 50), but given how TSN uses the timestamp, it will wrap every 4.3 seconds, using SO_TXTIME allows you to schedule transmission at a much later time. It should also lessen the dependency on a specific protocol, which is also good.

Quoted 3 lines

For example, one can imaging running two or more loops that only occasionally collide. When they do collide, which packet should be sent first? Just let user space decide.

If 2 userspace apps send to the same Tx-queue with the same priority, would it not make sense to just do FIFO? For all practical purposes, they have the same importance (same SO_PRIORITY, same SO_TXTIME). If the priority differs, then they would be directed to different queues, where one queue will take presedence anyway.

How far into the future would it make sense to schedule packets anyway?

I'll have a look at the other series you just posted!

Signature · 8 lines
Henrik Austad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20170918/4ed5b8c4/attachment.asc>
author maintainer
#24 lore raw
In reply to Richard Cochran

Hi Richard,

Quoted 31 lines · Richard Cochran
Quoted 1 line · Vinicius Costa Gomes

* Time-aware shaper (802.1Qbv):

I just posted a working alternative showing how to handle 802.1Qbv and many other Ethernet field buses.

Quoted 16 lines

The idea we are currently exploring is to add a "time-aware", priority based qdisc, that also exposes the Tx queues available and provides a mechanism for mapping priority <-> traffic class <-> Tx queues in a similar fashion as mqprio. We are calling this qdisc 'taprio', and its 'tc' cmd line would be:

   $ $ tc qdisc add dev ens4 parent root handle 100 taprio num_tc 4    \
     	   map 2 2 1 0 3 3 3 3 3 3 3 3 3 3 3 3                         \
	   queues 0 1 2 3                                              \
     	   sched-file gates.sched [base-time <interval>]               \
           [cycle-time <interval>] [extension-time <interval>]

<file> is multi-line, with each line being of the following format:
<cmd> <gate mask> <interval in nanoseconds>

Qbv only defines one <cmd>: "S" for 'SetGates'

Quoted 8 lines

For example:

S 0x01 300
S 0x03 500

This means that there are two intervals, the first will have the gate for traffic class 0 open for 300 nanoseconds, the second will have both traffic classes open for 500 nanoseconds.

Quoted 6 lines

The idea of the schedule file will not work in practice. Consider the fact that the application wants to deliver time critical data in a particular slot. How can it find out a) what the time slots are and
b) when the next slot is scheduled? With this Qdisc, it cannot do this, AFAICT. The admin might delete the file after configuring the Qdisc!

That's the point, the application does not need to know that, and asking that would be stupid. From the point of view of the Qbv specification, applications only need to care about its basic bandwidth requirements:
its interval, frame size, frames per interval (using the terms of the SRP section of 802.1Q). The traffic schedule is provided (off band) by a "god box" which knows all the requirements of all applications in all the nodes and how they are connected.

(And that's another nice point of how 802.1Qbv works, applications do not need to be changed to use it, and I think we should work to achieve this on the Linux side)

That being said, that only works for kinds of traffic that maps well to this configuration in advance model, which is the model that the IEEE (see 802.1Qcc) and the AVNU Alliance[1] are pushing for.

In the real world, I can see multiple types of applications, some using something like TXTIME, and some configured in advance.

Quoted 5 lines

Using the SO_TXTIME option, the application has total control over the scheduling. The great advantages of this approach is that we can support any possible combination of periodic or aperiodic scheduling and we can support any priority scheme user space dreams up.

It has the disavantage of that the scheduling information has to be in-band with the data. I *really* think that for scheduled traffic, there should be a clear separation, we should not mix the dataflow with scheduling. In short, an application in the network don't need to have all the information necessary to schedule its own traffic well.

I have two points here: 1. I see both "solutions" (taprio and SO_TXTIME) as being ortoghonal and useful, both; 2. trying to make one do the job of the other, however, looks like "If all I have is a hammer, everything looks like a nail".

In short, I see a per-packet transmission time and a per-queue schedule as solutions to different problems.

Quoted 7 lines

For example, one can imaging running two or more loops that only occasionally collide. When they do collide, which packet should be sent first? Just let user space decide.

Thanks,
Richard

Cheers,
--
Vinicius

[1]
http://avnu.org/theory-of-operation-for-tsn-enabled-industrial-systems/

#25 lore raw
Quoted 2 lines · Vinicius Costa Gomes

That's the point, the application does not need to know that, and asking that would be stupid.

On the contrary, this information is essential to the application. Probably you have never seen an actual Ethernet field bus in operation? In any case, you are missing the point.

Quoted 3 lines

(And that's another nice point of how 802.1Qbv works, applications do not need to be changed to use it, and I think we should work to achieve this on the Linux side)

Once you start to care about real time performance, then you need to consider the applications. This is industrial control, not streaming your tunes from your ipod.

Quoted 3 lines

That being said, that only works for kinds of traffic that maps well to this configuration in advance model, which is the model that the IEEE (see 802.1Qcc) and the AVNU Alliance[1] are pushing for.

Again, you are missing the point of what they aiming for. I have looked at a number of production systems, and in each case the developers want total control over the transmission, in order to reduce latency to an absolute minimum. Typically the data to be sent are available only microseconds before the transmission deadline.

Consider OpenAVB on github that people are already using. Take a look at simple_talker.c and explain how "applications do not need to be changed to use it."

Quoted 2 lines

[1]
http://avnu.org/theory-of-operation-for-tsn-enabled-industrial-systems/

Did you even read this?

[page 24]

As described in section 2, some industrial control systems require predictable, very low latency and cycle-to-cycle variation to meet hard real-time application requirements. In these systems, multiple distributed controllers commonly synchronize their sensor/actuator operations with other controllers by scheduling these operations in time, typically using a repeating control cycle.
...
The gate control mechanism is itself a time-aware PTP application operating within a bridge or end station port.

It is an application, not a "god box."

Quoted 2 lines

In short, I see a per-packet transmission time and a per-queue schedule as solutions to different problems.

Well, I can agree with that. For some non real-time applications, bandwidth shaping is enough, and your Qdisc idea is sufficient. For the really challenging TSN targets (industrial control, automotive), your idea of an opaque schedule file won't fly.

Thanks,
Richard

#26 lore raw

Hi all,

Quoted 8 lines · Richard Cochran
Quoted 2 lines · Vinicius Costa Gomes

That's the point, the application does not need to know that, and asking that would be stupid.

On the contrary, this information is essential to the application. Probably you have never seen an actual Ethernet field bus in operation? In any case, you are missing the point.

Quoted 7 lines
Quoted 3 lines

(And that's another nice point of how 802.1Qbv works, applications do not need to be changed to use it, and I think we should work to achieve this on the Linux side)

Once you start to care about real time performance, then you need to consider the applications. This is industrial control, not streaming your tunes from your ipod.

Do not underestimate the need for media over TSN. I fully see your point of real-time systems, but they are not the only valid use-cases for TSN.

Quoted 10 lines
Quoted 3 lines

That being said, that only works for kinds of traffic that maps well to this configuration in advance model, which is the model that the IEEE (see 802.1Qcc) and the AVNU Alliance[1] are pushing for.

Again, you are missing the point of what they aiming for. I have looked at a number of production systems, and in each case the developers want total control over the transmission, in order to reduce latency to an absolute minimum. Typically the data to be sent are available only microseconds before the transmission deadline.

Quoted 3 lines

Consider OpenAVB on github that people are already using. Take a look at simple_talker.c and explain how "applications do not need to be changed to use it."

I do not think simple-talker was everintended to be how users of AVB should be implemented, but as a demonstration of what the protocol could do.

ALSA/V4L2 should supply some interface to this so that you can attach media-applications to it without the application itself having to be "TSN aware".

Quoted 20 lines
Quoted 2 lines

[1]
http://avnu.org/theory-of-operation-for-tsn-enabled-industrial-systems/

Did you even read this?

[page 24]

As described in section 2, some industrial control systems require predictable, very low latency and cycle-to-cycle variation to meet hard real-time application requirements. In these systems, multiple distributed controllers commonly synchronize their sensor/actuator operations with other controllers by scheduling these operations in time, typically using a repeating control cycle.
...
The gate control mechanism is itself a time-aware PTP application operating within a bridge or end station port.

It is an application, not a "god box."

Quoted 7 lines
Quoted 2 lines

In short, I see a per-packet transmission time and a per-queue schedule as solutions to different problems.

Well, I can agree with that. For some non real-time applications, bandwidth shaping is enough, and your Qdisc idea is sufficient. For the really challenging TSN targets (industrial control, automotive), your idea of an opaque schedule file won't fly.

Would it make sense to adapt the proposed Qdisc here as well as the back-o-the-napkin idea in the other thread to to a per-socket queue for each priority and then sort those sockets based on SO_TXTIME?

TSN operates on a per-StreamID basis, and that should map fairly well to a per-socket approach I think (let us just assume that an application that sends TSN traffic will open up a separate socket for each stream.

This should allow a userspace application that is _very_ aware of its timing constraints to send frames exactly when it needs to as you have SO_TXTIME available. It would also let applications that basically want a fine-grained rate control (audio and video comes to mind) to use the same qdisc.

For those sockets that do not support SO_TXTIME, but still map to a priority handled by sch_cbs (or whatever it'll end up being called) you can set the transmit-time to be the time of the last skb in the queue + an delta which will give you the correct rate (TSN operates on observation intervals which you can specify via tc when you create the queues).

Then you can have, as you propose in your other series, a hrtimer that is being called when the next SO_TXTIME enters, grab a skb and move it to the hw-queue. This should also allow you to keep a sorted per-socket queue should an application send frames in the wrong order, without having to rearrange descriptors for the DMA machinery.

If this makes sense, I am more than happy to give it a stab and see how it goes.

-Henrik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20170919/05b03c2f/attachment.asc>

author maintainer
#27 lore raw
In reply to Richard Cochran

Hi Richard,

Quoted 26 lines · Richard Cochran
Quoted 2 lines · Vinicius Costa Gomes

That's the point, the application does not need to know that, and asking that would be stupid.

On the contrary, this information is essential to the application. Probably you have never seen an actual Ethernet field bus in operation? In any case, you are missing the point.

Quoted 3 lines

(And that's another nice point of how 802.1Qbv works, applications do not need to be changed to use it, and I think we should work to achieve this on the Linux side)

Once you start to care about real time performance, then you need to consider the applications. This is industrial control, not streaming your tunes from your ipod.

Quoted 3 lines

That being said, that only works for kinds of traffic that maps well to this configuration in advance model, which is the model that the IEEE (see 802.1Qcc) and the AVNU Alliance[1] are pushing for.

Again, you are missing the point of what they aiming for. I have looked at a number of production systems, and in each case the developers want total control over the transmission, in order to reduce latency to an absolute minimum. Typically the data to be sent are available only microseconds before the transmission deadline.

Quoted 3 lines

Consider OpenAVB on github that people are already using. Take a look at simple_talker.c and explain how "applications do not need to be changed to use it."

Just let me use the mention of OpenAVNU as a hook to explain what we (the team I am part of) are working to do, perhaps it will make our choices and designs clearer.

One of the problems with OpenAVNU is that it's too coupled with the i210 NIC. One of the things we want is to decouple OpenAVNU from the controller. The way we thought best was to propose interfaces (that would work along side to the Linux networking stack) as close as possible to what the current standards define, that means the IEEE 802.1Q family of specifications, in the hope that network controller vendors would also look at the specifications when designing their controllers.

Our objective with the Qdiscs we are proposing (both cbs and taprio) is to provide a sane way to configure controllers that support TSN features (we were looking specifically at the IEEE specs).

After we have some rough consensus on the interfaces to use, then we can start working on OpenAVNU.

Quoted 21 lines
Quoted 3 lines

[1]
http://avnu.org/theory-of-operation-for-tsn-enabled-industrial-systems/

Did you even read this?

[page 24]

As described in section 2, some industrial control systems require predictable, very low latency and cycle-to-cycle variation to meet hard real-time application requirements. In these systems, multiple distributed controllers commonly synchronize their sensor/actuator operations with other controllers by scheduling these operations in time, typically using a repeating control cycle.
...
The gate control mechanism is itself a time-aware PTP application operating within a bridge or end station port.

It is an application, not a "god box."

Quoted 7 lines
Quoted 2 lines

In short, I see a per-packet transmission time and a per-queue schedule as solutions to different problems.

Well, I can agree with that. For some non real-time applications, bandwidth shaping is enough, and your Qdisc idea is sufficient. For the really challenging TSN targets (industrial control, automotive), your idea of an opaque schedule file won't fly.

(Sorry if I am being annoying here, but the idea of an opaque schedule is not ours, that comes from the people who wrote the Qbv specification)

I have a question, what about a controller that doesn't provide a way to set a per-packet transmission time, but it supports Qbv/Qbu. What would be your proposal to configure it?

(I think LaunchTime is something specific to the i210, right?)

Cheers,
--
Vinicius

#28 lore raw
Quoted 3 lines · Vinicius Costa Gomes

One of the problems with OpenAVNU is that it's too coupled with the i210 NIC. One of the things we want is to decouple OpenAVNU from the controller.

Yes, I want that, too.

Quoted 6 lines

The way we thought best was to propose interfaces (that would work along side to the Linux networking stack) as close as possible to what the current standards define, that means the IEEE 802.1Q family of specifications, in the hope that network controller vendors would also look at the specifications when designing their controllers.

These standard define the *behavior*, not the programming APIs. Our task as kernel developers is to invent the best interfaces for supporting 802.1Q and other standards, the hardware capabilities, and the widest range of applications (not jut AVB).

Quoted 3 lines

Our objective with the Qdiscs we are proposing (both cbs and taprio) is to provide a sane way to configure controllers that support TSN features (we were looking specifically at the IEEE specs).

I can see how your proposed Qdiscs are inspired by the IEEE standards. However, in the case of time based transmission, I think there is a better way to do it, namely with SO_TXTIME (which BTW was originally proposed by Eric Mann).

Quoted 2 lines

After we have some rough consensus on the interfaces to use, then we can start working on OpenAVNU.

Did you see my table in the other mail? Any comments?

Quoted 2 lines

(Sorry if I am being annoying here, but the idea of an opaque schedule is not ours, that comes from the people who wrote the Qbv specification)

The schedule is easy to implement using SO_TXTIME.

Quoted 3 lines

I have a question, what about a controller that doesn't provide a way to set a per-packet transmission time, but it supports Qbv/Qbu. What would be your proposal to configure it?

SO_TXTIME will have a generic SW fallback.

BTW, regarding the i210, there is no sensible way to configure both CBS and time based transmission at the same time. The card performs a logical AND to make the launch decision. The effect of this is that each and every packet needs a LaunchTime, and the driver would be forced to guess the time for a packet before entering it into its queue.

So if we end up merging CBS and SO_TXTIME, then we'll have to make them exclusive of each other (in the case of the i210) and manage the i210 queue configurations correctly.

Quoted 1 line

(I think LaunchTime is something specific to the i210, right?)

To my knowledge yes. However, if TSN does take hold, then other MAC vendors will copy it.

Thanks,
Richard

#29 lore raw

Hi Richard,

On 09/19/2017 10:25 PM, Richard Cochran wrote:
(...)

Quoted 14 lines
Quoted 4 lines

I have a question, what about a controller that doesn't provide a way to set a per-packet transmission time, but it supports Qbv/Qbu. What would be your proposal to configure it?

SO_TXTIME will have a generic SW fallback.

BTW, regarding the i210, there is no sensible way to configure both CBS and time based transmission at the same time. The card performs a logical AND to make the launch decision. The effect of this is that each and every packet needs a LaunchTime, and the driver would be forced to guess the time for a packet before entering it into its queue.

Quoted 4 lines

So if we end up merging CBS and SO_TXTIME, then we'll have to make them exclusive of each other (in the case of the i210) and manage the i210 queue configurations correctly.

I've ran some quick tests here having launch time enabled on i210 + our cbs patchset. When valid Launch times are set on each packet you still get the expected behavior, so I'm not sure we should just make them exclusive of each other.

I also did some tests with when you don't set valid launch times, but here using your idea from above, so with the driver calculating a valid launch time (i.e. current NIC time + X ns, varying X across tests) for packets that didn't have it set by the user, and I wasn't too happy with its reliability. It could definitely be improved, but it has left me wondering: instead, what about documenting that if you enable TXTIME, then you *must* provide a valid Launch time for all packets on traffic classes that are affected?

With the SO_TXTIME qdisc idea in place, that could even be enforced before packets were enqueued into the netdevice.

Regards,
Jesus

#30 lore raw
Quoted 7 lines · Jesus Sanchez-Palencia

I also did some tests with when you don't set valid launch times, but here using your idea from above, so with the driver calculating a valid launch time (i.e. current NIC time + X ns, varying X across tests) for packets that didn't have it set by the user, and I wasn't too happy with its reliability. It could definitely be improved, but it has left me wondering: instead, what about documenting that if you enable TXTIME, then you *must* provide a valid Launch time for all packets on traffic classes that are affected?

If txtime is enabled, then CBS is pointless because the txtime already specifies the bandwidth implicitly.

The problem is when one program uses txtime and another uses CBS, then the CBS user will experience really wrong performance.

Thanks,
Richard

#31 lore raw

Hi,

Quoted 11 lines · Richard Cochran
Quoted 7 lines · Jesus Sanchez-Palencia

I also did some tests with when you don't set valid launch times, but here using your idea from above, so with the driver calculating a valid launch time (i.e. current NIC time + X ns, varying X across tests) for packets that didn't have it set by the user, and I wasn't too happy with its reliability. It could definitely be improved, but it has left me wondering: instead, what about documenting that if you enable TXTIME, then you *must* provide a valid Launch time for all packets on traffic classes that are affected?

If txtime is enabled, then CBS is pointless because the txtime already specifies the bandwidth implicitly.

Assuming there is no "interfering" traffic on that traffic class, yes. Otherwise, CBS could be configured just to avoid that outbound traffic ever goes beyond the reserved bandwidth.

Quoted 3 lines

The problem is when one program uses txtime and another uses CBS, then the CBS user will experience really wrong performance.

Good point. We'll need to adjust the launch time for controllers that behave like the i210 then, imo.

Thanks,
Jesus

Quoted 4 lines

Thanks,
Richard

#32 lore raw
In reply to Vinicius Costa Gomes
Quoted 1 line · Vinicius Costa Gomes

(I think LaunchTime is something specific to the i210, right?)

Levi just told us:

Recent SoCs from NXP (the i.MX 6 SoloX, and all the i.MX 7 and 8 parts) support Qav shaping as well as scheduled launch functionality;

Thanks,
Richard

#33 lore raw
In reply to Vinicius Costa Gomes
Quoted 5 lines · Vinicius Costa Gomes

This patchset is an RFC on a proposal of how the Traffic Control subsystem can be used to offload the configuration of traffic shapers into network devices that provide support for them in HW. Our goal here is to start upstreaming support for features related to the Time-Sensitive Networking (TSN) set of standards into the kernel.

Just for the record, here is my score card showing the current status of TSN support in Linux. Comments and corrections are more welcome.

Thanks,
Richard

 | FEATURE                                        | STANDARD            | STATUS                       |
 |------------------------------------------------+---------------------+------------------------------|
 | Synchronization                                | 802.1AS-2011        | Implemented in               |
 |                                                |                     | - Linux kernel PHC subsystem |
 |                                                |                     | - linuxptp (userspace)       |
 |------------------------------------------------+---------------------+------------------------------|
 | Forwarding and Queuing Enhancements            | 802.1Q-2014 sec. 34 | RFC posted (this thread)     |
 | for Time-Sensitive Streams (FQTSS)             |                     |                              |
 |------------------------------------------------+---------------------+------------------------------|
 | Stream Reservation Protocol (SRP)              | 802.1Q-2014 sec. 35 | in Open-AVB [1]              |
 |------------------------------------------------+---------------------+------------------------------|
 | Audio Video Transport Protocol (AVTP)          | IEEE 1722-2011      | DNE                          |
 |------------------------------------------------+---------------------+------------------------------|
 | Audio/Video Device Discovery, Enumeration,     | IEEE 1722.1-2013    | jdksavdecc-c [2]             |
 | Connection Management and Control (AVDECC)     |                     |                              |
 | AVDECC Connection Management Protocol (ACMP)   |                     |                              |
 | AVDECC Enumeration and Control Protocol (AECP) |                     |                              |
 | MAC Address Acquisition Protocol (MAAP)        |                     | in Open-AVB                  |
 |------------------------------------------------+---------------------+------------------------------|
 | Frame Preemption                               | P802.1Qbu           | DNE                          |
 | Scheduled Traffic                              | P802.1Qbv           | RFC posted (SO_TXTIME)       |
 | SRP Enhancements and Performance Improvements  | P802.1Qcc           | DNE                          |

DNE = Does Not Exist (to my knowledge)

1. https://github.com/Avnu/OpenAvnu

(DISCLAIMER from the website:)

It is planned to eventually include the various packet encapsulation types, protocol discovery daemons, libraries to convert media clocks to AVB clocks and vice versa, and drivers.

This repository does not include all components required to build a full production AVB/TSN system (e.g. a turnkey solution to stream stored or live audio or video content). Some simple example applications are provided which illustrate the flow - but a professional Audio/Video system requires a full media stack
- including audio and video inputs and outputs, media processing elements, and various graphical user interfaces. Various companies provide such integrated solutions.

2. https://github.com/jdkoftinoff/jdksavdecc-c

#34 lore raw

TSN Scorecard, was Re: [RFC net-next 0/5] TSN: Add qdisc-based config interfaces for traffic shapers

Quoted 7 lines · Richard Cochran

Just for the record, here is my score card showing the current status of TSN support in Linux. Comments and corrections are more welcome.

Thanks,
Richard

Quoted 6 lines
 | FEATURE                                        | STANDARD            | STATUS                       |
 |------------------------------------------------+---------------------+------------------------------|
 | Synchronization                                | 802.1AS-2011        | Implemented in               |
 |                                                |                     | - Linux kernel PHC subsystem |
 |                                                |                     | - linuxptp (userspace)       |
 |------------------------------------------------+---------------------+------------------------------|

An alternate implementation of the userspace portion of gPTP is also available at [1]

Quoted 5 lines
 | Forwarding and Queuing Enhancements            | 802.1Q-2014 sec. 34 | RFC posted (this thread)     |
 | for Time-Sensitive Streams (FQTSS)             |                     |                              |
 |------------------------------------------------+---------------------+------------------------------|
 | Stream Reservation Protocol (SRP)              | 802.1Q-2014 sec. 35 | in Open-AVB [1]              |
 |------------------------------------------------+---------------------+------------------------------|
Quoted 8 lines
 | Audio Video Transport Protocol (AVTP)          | IEEE 1722-2011      | DNE                          |
 |------------------------------------------------+---------------------+------------------------------|
 | Audio/Video Device Discovery, Enumeration,     | IEEE 1722.1-2013    | jdksavdecc-c [2]             |
 | Connection Management and Control (AVDECC)     |                     |                              |
 | AVDECC Connection Management Protocol (ACMP)   |                     |                              |
 | AVDECC Enumeration and Control Protocol (AECP) |                     |                              |
 | MAC Address Acquisition Protocol (MAAP)        |                     | in Open-AVB                  |
 |------------------------------------------------+---------------------+------------------------------|

All of the above are available to some degree in the AVTP Pipeline part of [1], specifically at this
location: https://github.com/AVnu/OpenAvnu/tree/master/lib/avtp_pipeline

The code is very modular and configurable, although some parts are in better shape than others. The AVTP portion can use the custom userspace driver for the i210, which can be configured to use launch scheduling, or it can use standard kernel interfaces via sendmsg or PACKET_MMAP. It runs as-is when configured for standard interfaces with any network hardware that supports gPTP. I previously implemented a CMSG-based launch time scheduling mechanism like the one you have proposed, and I have a socket backend for it that could easily be ported to your proposal. It is not part of the repository yet since there's no kernel support for it outside of my prototype and your RFC.

It is currently tied to the OpenAvnu gPTP daemon rather than linuxptp, as it uses a shared memory interface to get the current rate-ratio and offset information between the various clocks. There may be better ways to do this, but that's how the initial port of the codebase was done. It would be nice to get it working with linuxptp's userspace tools at some point as well, though.

The libraries under avtp_pipeline are designed to be used separately, but a simple integrated application is provided and is built by the CI system.

In addition to OpenAvnu, Renesas has a number of github repositories with what looks like a fairly complete media streaming system:

https://github.com/renesas-rcar/avb-mse
https://github.com/renesas-rcar/avb-streaming
https://github.com/renesas-rcar/avb-applications

I haven't examined them in great detail yet, though.

Quoted 5 lines
 | Frame Preemption                               | P802.1Qbu           | DNE                          |
 | Scheduled Traffic                              | P802.1Qbv           | RFC posted (SO_TXTIME)       |
 | SRP Enhancements and Performance Improvements  | P802.1Qcc           | DNE                          |

DNE = Does Not Exist (to my knowledge)

Although your SO_TXTIME proposal could certainly form the basis of an endpoint's implementation of Qbv, I think it is a stretch to consider it a Qbv implementation in itself, if that's what you mean by this.

I have been working with colleagues on some experiments relating to a Linux-controlled DSN switch (a Marvell Topaz) that are a part of this effort in TSN:

http://ieee802.org/1/files/public/docs2017/tsn-cgunther-802-3cg-multidrop-0917-v01.pdf

The proper interfaces for the Qbv configuration and managing of switch-level PTP timestamps are not yet in place, so there's nothing even at RFC stage to present yet, but Qbv-capable Linux-managed switch hardware is available and we hope to get some reusable code published even if it's not yet ready to be integrated in the kernel.

Quoted 9 lines

1. https://github.com/Avnu/OpenAvnu

(DISCLAIMER from the website:)

It is planned to eventually include the various packet encapsulation types, protocol discovery daemons, libraries to convert media clocks to AVB clocks and vice versa, and drivers.

Quoted 7 lines

This repository does not include all components required to build a full production AVB/TSN system (e.g. a turnkey solution to stream stored or live audio or video content). Some simple example applications are provided which illustrate the flow - but a professional Audio/Video system requires a full media stack
- including audio and video inputs and outputs, media processing elements, and various graphical user interfaces. Various companies provide such integrated solutions.

A bit of progress has been made since that was written, although it is true that it's still not quite complete and certainly not turnkey. The most glaring absence at the moment is the media clock recovery portion of AVTP, but I am actively working on this.

Quoted 2 lines

2. https://github.com/jdkoftinoff/jdksavdecc-c

This is pulled in as a dependency of the AVDECC code in OpenAvnu; it's used in the command line driven controller, but not in the avtp_pipeline code that implements the endpoint AVDECC behavior. I don't think either are complete by any means, but they are complete enough to be mostly compliant and usable in the subset of behavior they support.

The bulk of the command line controller is a clone of: https://github.com/audioscience/avdecc-lib

Things are maybe a bit farther along than they seemed, but there is still important kernel work to be done to reduce the need for out-of-tree drivers and to get everyone on the same interfaces. I plan to be an active participant going forward.

Levi

#35 lore raw

Re: TSN Scorecard, was Re: [RFC net-next 0/5] TSN: Add qdisc-based config interfaces for traffic shapers

Quoted 2 lines · levipearson at gmail.com

In addition to OpenAvnu, Renesas has a number of github repositories with what looks like a fairly complete media streaming system:

Is it a generic stack or a set of hacks for their HW?

Quoted 2 lines

Although your SO_TXTIME proposal could certainly form the basis of an endpoint's implementation of Qbv, I think it is a stretch to consider it a Qbv implementation in itself, if that's what you mean by this.

No, that is not what I meant. We need some minimal additional kernel support in order to fully implement the TSN family of standards. Of course, the bulk will have to be done in user space. It would be a mistake to cram the stuff that belongs in userland into the kernel.

Looking at the table, and reading your descriptions of the state of OpenAVB, I remained convinced that the kernel needs only three additions:

1. SO_TXTIME
2. CBS Qdisc
3. ALSA support for DAC clock control (but that is another story)

Quoted 4 lines

The proper interfaces for the Qbv configuration and managing of switch-level PTP timestamps are not yet in place, so there's nothing even at RFC stage to present yet, but Qbv-capable Linux-managed switch hardware is available and we hope to get some reusable code published even if it's not yet ready to be integrated in the kernel.

Right, configuring Qbv in an attached DSA switch needs its own interface.

Regarding PHC support for DSA switches, I have something in the works to be published soon.

Quoted 2 lines

A bit of progress has been made since that was written, although it is true that it's still not quite complete and certainly not turnkey.

So OpenAVB is neither complete nor turnkey. That was my impression, too.

Quoted 3 lines

Things are maybe a bit farther along than they seemed, but there is still important kernel work to be done to reduce the need for out-of-tree drivers and to get everyone on the same interfaces. I plan to be an active participant going forward.

You mentioned a couple of different kernel things you implemented. I would encourage you to post the work already done.

Thanks,
Richard

#36 lore raw

Re: TSN Scorecard, was Re: [RFC net-next 0/5] TSN: Add qdisc-based config interfaces for traffic shapers

Hi,

On 09/19/2017 10:49 PM, Richard Cochran wrote:
(...)

Quoted 6 lines

No, that is not what I meant. We need some minimal additional kernel support in order to fully implement the TSN family of standards. Of course, the bulk will have to be done in user space. It would be a mistake to cram the stuff that belongs in userland into the kernel.

Quoted 7 lines

Looking at the table, and reading your descriptions of the state of OpenAVB, I remained convinced that the kernel needs only three additions:

1. SO_TXTIME
2. CBS Qdisc
3. ALSA support for DAC clock control (but that is another story)

We'll be posting the CBS v1 series for review soon.

The current SO_TXTIME RFC for the purpose of Launchtime looks great, and we are looking forward for the v1 + its companion qdisc so we can test / review and provide feedback.

We are still under the impression that a config interface for HW offload of Qbv / Qbu config will be needed, but we'll be deferring the 'taprio' proposal until there are NICs (end stations) that support these standards available. We can revisit it if that ever happens, and if it's still needed, but then taking into account SO_TXTIME (and its related qdisc).

Thanks everyone for all the feedback so far.

Regards,
Jesus

#37 lore raw
In reply to Vinicius Costa Gomes
Quoted 7 lines · Vinicius Costa Gomes

Hi,

This patchset is an RFC on a proposal of how the Traffic Control subsystem can be used to offload the configuration of traffic shapers into network devices that provide support for them in HW. Our goal here is to start upstreaming support for features related to the Time-Sensitive Networking (TSN) set of standards into the kernel.

I'm very excited to see these features moving into the kernel! I am one of the maintainers of the OpenAvnu project and I've been involved in building AVB/TSN systems and working on the standards for around 10 years, so the support that's been slowly making it into more silicon and now Linux drivers is very encouraging.

My team at Harman is working on endpoint code based on what's in the OpenAvnu project and a few Linux-based platforms. The Qav interface you've proposed will fit nicely with our traffic shaper management daemon, which already uses mqprio as a base but uses the htb shaper to approximate the Qav credit-based shaper on platforms where launch time scheduling isn't available.

I've applied your patches and plan on testing them in conjunction with our shaper manager to see if we run into any hitches, but I don't expect any problems.

Quoted 21 lines

As part of this work, we've assessed previous public discussions related to TSN
enabling: patches from Henrik Austad (Cisco), the presentation from Eric Mann at Linux Plumbers 2012, patches from Gangfeng Huang (National Instruments) and the current state of the OpenAVNU project (https://github.com/AVnu/OpenAvnu/).

Please note that the patches provided as part of this RFC are implementing what is needed only for 802.1Qav (FQTSS) only, but we'd like to take advantage of this discussion and share our WIP ideas for the 802.1Qbv and 802.1Qbu interfaces as well. The current patches are only providing support for HW offload of the configs.

Overview
========

Time-sensitive Networking (TSN) is a set of standards that aim to address resources availability for providing bandwidth reservation and bounded latency on Ethernet based LANs. The proposal described here aims to cover mainly what is needed to enable the following standards: 802.1Qat, 802.1Qav, 802.1Qbv and 802.1Qbu.

Quoted 3 lines

The initial target of this work is the Intel i210 NIC, but other controllers' datasheet were also taken into account, like the Renesas RZ/A1H RZ/A1M group and the Synopsis DesignWare Ethernet QoS controller.

Recent SoCs from NXP (the i.MX 6 SoloX, and all the i.MX 7 and 8 parts) support Qav shaping as well as scheduled launch functionality; these are the parts I have been mostly working with. Marvell silicon (some subset of Armada processors and Link Street DSA switches) generally supports traffic shaping as well.

I think a lack of an interface like this has probably slowed upstream driver support for this functionality where it exists; most vendors have an out-of- tree version of their driver with TSN functionality enabled via non-standard interfaces. Hopefully making it available will encourage vendors to upstream their driver support!

Quoted 12 lines

Proposal
========

Feature-wise, what is covered here are configuration interfaces for HW implementations of the Credit-Based shaper (CBS, 802.1Qav), Time-Aware shaper (802.1Qbv) and Frame Preemption (802.1Qbu). CBS is a per-queue shaper, while Qbv and Qbu must be configured per port, with the configuration covering all queues. Given that these features are related to traffic shaping, and that the traffic control subsystem already provides a queueing discipline that offloads config into the device driver (i.e. mqprio), designing new qdiscs for the specific purpose of offloading the config for each shaper seemed like a good fit.

This makes sense to me too. The 802.1Q standards are all based on the sort of mappings between priority, traffic class, and hardware queues that the existing tc infrastructure seems to be modeling. I believe the mqprio module's mapping scheme is flexible enough to meet any TSN needs in conjunction with the other parts of the kernel qdisc system.

Quoted 6 lines

For steering traffic into the correct queues, we use the socket option SO_PRIORITY and then a mechanism to map priority to traffic classes / Txqueues. The qdisc mqprio is currently used in our tests.

As for the shapers config interface:

Quoted 8 lines

* CBS (802.1Qav)

This patchset is proposing a new qdisc called 'cbs'. Its 'tc' cmd line is:

   $ tc qdisc add dev IFACE parent ID cbs locredit N hicredit M sendslope S \
     idleslope I

Note that the parameters for this qdisc are the ones defined by the 802.1Q-2014 spec, so no hardware specific functionality is exposed here.

These parameters look good to me as a baseline; some additional optional parameters may be useful for software-based implementations--such as setting an interval at which to recalculate queues--but those can be discussed later.

Quoted 1 line

* Time-aware shaper (802.1Qbv):

I haven't come across any specific NIC or SoC MAC that does Qbv, but I have been experimenting with an EspressoBin board, which has a "Topaz" DSA switch in it that has some features intended for Qbv support, although they were done with a draft version in mind.

I haven't looked at the interaction between the qdisc subsystem and DSA yet, but this mechanism might be useful to configure Qbv on the slave ports in that context. I've got both the board and the documentation, so I might be able to work on an implementation at some point.

If some endpoint device shows up with direct Qbv support, this interface would probably work well there too, although a talker would need to be able to schedule its transmits pretty precisely to achieve the lowest possible latency.

Quoted 10 lines

The idea we are currently exploring is to add a "time-aware", priority based qdisc, that also exposes the Tx queues available and provides a mechanism for mapping priority <-> traffic class <-> Tx queues in a similar fashion as mqprio. We are calling this qdisc 'taprio', and its 'tc' cmd line would be:

   $ $ tc qdisc add dev ens4 parent root handle 100 taprio num_tc 4    \
     	   map 2 2 1 0 3 3 3 3 3 3 3 3 3 3 3 3                         \
	   queues 0 1 2 3                                              \
     	   sched-file gates.sched [base-time <interval>]               \
           [cycle-time <interval>] [extension-time <interval>]

One concern here is calling the base-time parameter an interval; it's really an absolute time with respect to the PTP timescale. Good documentation will be important to this one, since the specification discusses some subtleties regarding the impact of different time values chosen here.

The format for specifying the actual intervals such as cycle-time could prove to be an important detail as well; Qbv specifies cycle-time as a ratio of two integers expressed in seconds, while extension-time is specified as an integer number of nanoseconds.

Precision with the cycle-time is especially important, since base-time can be almost arbitrarily far in the past or future, and any given cycle start should be calculable from the base-time plus/minus some integer multiple of cycle- time.

Quoted 14 lines

<file> is multi-line, with each line being of the following format:
<cmd> <gate mask> <interval in nanoseconds>

Qbv only defines one <cmd>: "S" for 'SetGates'

For example:

S 0x01 300
S 0x03 500

This means that there are two intervals, the first will have the gate for traffic class 0 open for 300 nanoseconds, the second will have both traffic classes open for 500 nanoseconds.

Quoted 7 lines
   Additionally, an option to set just one entry of the gate control list will
   also be provided by 'taprio':

   $ tc qdisc (...) \
        sched-row <row number> <cmd> <gate mask> <interval>  \
        [base-time <interval>] [cycle-time <interval>] \
        [extension-time <interval>]

If I understand correctly, 'sched-row' is meant to be usable multiple times in a single command and the 'sched-file' option is just a shorthand version for large tables? Or is it meant to update an existing schedule table? It doesn't seem very useful if it can only be specified once when the whole taprio intance is being established.

Quoted 26 lines

* Frame Preemption (802.1Qbu):

To control even further the latency, it may prove useful to signal which traffic classes are marked as preemptable. For that, 'taprio' provides the preemption command so you set each traffic class as preemptable or not:

   $ tc qdisc (...) \
        preemption 0 1 1 1

* Time-aware shaper + Preemption:

As an example of how Qbv and Qbu can be used together, we may specify both the schedule and the preempt-mask, and this way we may also specify the Set-Gates-and-Hold and Set-Gates-and-Release commands as specified in the Qbu spec:

   $ tc qdisc add dev ens4 parent root handle 100 taprio num_tc 4 \
     	   map 2 2 1 0 3 3 3 3 3 3 3 3 3 3 3 3                    \
	   queues 0 1 2 3                                         \
     	   preemption 0 1 1 1                                     \
	   sched-file preempt_gates.sched

<file> is multi-line, with each line being of the following format:
<cmd> <gate mask> <interval in nanoseconds>

Quoted 8 lines

For this case, two new commands are introduced:

"H" for 'set gates and hold'
"R" for 'set gates and release'

H 0x01 300
R 0x03 500

The new Hold and Release gate commands look right, but I'm not sure about the preemption flags. Qbu describes a preemption parameter table indexed by *priority* rather than traffic class or queue. These select which of two MAC service interfaces is used by the frame at the ISS layer, either express or preemptable, at the time the frame is selected for transmit. If my understanding is correct, it's possible to map a preemptable priority as well as an express priority to the same queue, so flagging preemptability at the queue level is not correct.

I'm not aware of any endpoint interfaces that support Qbu either, nor do I know of any switches that support it that someone could experiment with right now, so there's no pressure on getting that interface nailed down yet.

Hopefully you find this feedback useful, and I appreciate the effort taken to get the RFC posted here!

Levi

#38 lore raw
Quoted 3 lines · levipearson at gmail.com

If some endpoint device shows up with direct Qbv support, this interface would probably work well there too, although a talker would need to be able to schedule its transmits pretty precisely to achieve the lowest possible latency.

This is an argument for SO_TXTIME.

Quoted 10 lines

One concern here is calling the base-time parameter an interval; it's really an absolute time with respect to the PTP timescale. Good documentation will be important to this one, since the specification discusses some subtleties regarding the impact of different time values chosen here.

The format for specifying the actual intervals such as cycle-time could prove to be an important detail as well; Qbv specifies cycle-time as a ratio of two integers expressed in seconds, while extension-time is specified as an integer number of nanoseconds.

Quoted 4 lines

Precision with the cycle-time is especially important, since base-time can be almost arbitrarily far in the past or future, and any given cycle start should be calculable from the base-time plus/minus some integer multiple of cycle- time.

The above three points also.

Thanks,
Richard