Skip to contentSkip to conversation

net/sched: Introduce the taprio scheduler

RFC In review Vinicius Costa Gomes 2 participants 9 messages Jul 14, 2018 – Jul 25, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover net/sched: Introduce the taprio scheduler

Hi,

This is iproute2 side of the taprio RFC series.

Please see the kernel side cover letter for more information about how to test this.

Cheers,

#1 lore raw

RFC 1/5 utils: Implement get_s64()

Add this helper to read signed 64-bit integers from a string.

---
 include/utils.h |  1 +
 lib/utils.c     | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
include/utils.h +1 -0
index 8cb4349e..58574a05 100644
@@ -139,6 +139,7 @@ int get_time_rtt(unsigned *val, const char *arg, int *raw);
 #define get_byte get_u8
 #define get_ushort get_u16
 #define get_short get_s16
+int get_s64(__s64 *val, const char *arg, int base);
 int get_u64(__u64 *val, const char *arg, int base);
 int get_u32(__u32 *val, const char *arg, int base);
 int get_s32(__s32 *val, const char *arg, int base);
lib/utils.c +21 -0
index 02ce6772..02836d6e 100644
@@ -382,6 +382,27 @@ int get_u8(__u8 *val, const char *arg, int base)
 	return 0;
 }
 
+int get_s64(__s64 *val, const char *arg, int base)
+{
+	long res;
+	char *ptr;
+
+	errno = 0;
+
+	if (!arg || !*arg)
+		return -1;
+	res = strtoll(arg, &ptr, base);
+	if (!ptr || ptr == arg || *ptr)
+		return -1;
+	if ((res == LLONG_MIN || res == LLONG_MAX) && errno == ERANGE)
+		return -1;
+	if (res > INT64_MAX || res < INT64_MIN)
+		return -1;
+
+	*val = res;
+	return 0;
+}
+
 int get_s32(__s32 *val, const char *arg, int base)
 {
 	long res;
Signature · 1 line
2.18.0
#2 lore raw

RFC 2/5 include: Add helper to retrieve a __s64 from a netlink msg

In reply to Vinicius Costa Gomes

This allows signed 64-bit integers to be retrieved from a netlink message.

---
 include/libnetlink.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/libnetlink.h +7 -0
index 9d9249e6..88164975 100644
@@ -185,6 +185,13 @@ static inline __u64 rta_getattr_u64(const struct rtattr *rta)
 	memcpy(&tmp, RTA_DATA(rta), sizeof(__u64));
 	return tmp;
 }
+static inline __s64 rta_getattr_s64(const struct rtattr *rta)
+{
+	__s64 tmp;
+
+	memcpy(&tmp, RTA_DATA(rta), sizeof(__s64));
+	return tmp;
+}
 static inline const char *rta_getattr_str(const struct rtattr *rta)
 {
 	return (const char *)RTA_DATA(rta);
Signature · 1 line
2.18.0
#3 lore raw

RFC 3/5 libnetlink: Add helper for getting a __s32 from netlink msgs

In reply to Vinicius Costa Gomes

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

This function retrieves a signed 32-bit integer from a netlink message and returns it.

---
 include/libnetlink.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/libnetlink.h +7 -0
index 88164975..114a816e 100644
@@ -185,6 +185,13 @@ static inline __u64 rta_getattr_u64(const struct rtattr *rta)
 	memcpy(&tmp, RTA_DATA(rta), sizeof(__u64));
 	return tmp;
 }
+static inline __s32 rta_getattr_s32(const struct rtattr *rta)
+{
+	__s32 tmp;
+
+	memcpy(&tmp, RTA_DATA(rta), sizeof(__s32));
+	return tmp;
+}
 static inline __s64 rta_getattr_s64(const struct rtattr *rta)
 {
 	__s64 tmp;
Signature · 1 line
2.18.0
#4 lore raw

RFC 4/5 include: add definitions for taprio [DO NOT COMMIT]

In reply to Vinicius Costa Gomes

DO NOT COMMIT

This patch exists only to ease the testing, until this header is updated with the definitions from the kernel.

---
 include/uapi/linux/pkt_sched.h | 48 ++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
include/uapi/linux/pkt_sched.h +48 -0
index 37b5096a..8ca988cb 100644
@@ -934,4 +934,52 @@ enum {
 
 #define TCA_CBS_MAX (__TCA_CBS_MAX - 1)
 
+/* TAPRIO */
+enum {
+	TC_TAPRIO_CMD_SET_GATES = 0x00,
+	TC_TAPRIO_CMD_SET_AND_HOLD = 0x01,
+	TC_TAPRIO_CMD_SET_AND_RELEASE = 0x02,
+};
+
+enum {
+	TCA_TAPRIO_SCHED_ENTRY_UNSPEC,
+	TCA_TAPRIO_SCHED_ENTRY_INDEX, /* u32 */
+	TCA_TAPRIO_SCHED_ENTRY_CMD, /* u8 */
+	TCA_TAPRIO_SCHED_ENTRY_GATE_MASK, /* u32 */
+	TCA_TAPRIO_SCHED_ENTRY_INTERVAL, /* u32 */
+	__TCA_TAPRIO_SCHED_ENTRY_MAX,
+};
+#define TCA_TAPRIO_SCHED_ENTRY_MAX (__TCA_TAPRIO_SCHED_ENTRY_MAX - 1)
+
+/* The format for schedule entry list is:
+ * [TCA_TAPRIO_SCHED_ENTRY_LIST]
+ *   [TCA_TAPRIO_SCHED_ENTRY]
+ *     [TCA_TAPRIO_SCHED_ENTRY_CMD]
+ *     [TCA_TAPRIO_SCHED_ENTRY_GATES]
+ *     [TCA_TAPRIO_SCHED_ENTRY_INTERVAL]
+ */
+enum {
+	TCA_TAPRIO_SCHED_UNSPEC,
+	TCA_TAPRIO_SCHED_ENTRY,
+	__TCA_TAPRIO_SCHED_MAX,
+};
+
+#define TCA_TAPRIO_SCHED_MAX (__TCA_TAPRIO_SCHED_MAX - 1)
+
+enum {
+	TCA_TAPRIO_ATTR_UNSPEC,
+	TCA_TAPRIO_ATTR_PRIOMAP, /* struct tc_mqprio_qopt */
+	TCA_TAPRIO_ATTR_PREEMPT_MASK, /* which traffic classes are preemptible, u32 */
+	TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST, /* nested of entry */
+	TCA_TAPRIO_ATTR_SCHED_BASE_TIME, /* s64 */
+	TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME, /* s64 */
+	TCA_TAPRIO_ATTR_SCHED_EXTENSION_TIME, /* s64 */
+	TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY, /*  */
+	TCA_TAPRIO_ATTR_SCHED_CLOCKID, /* s32 */
+	TCA_TAPRIO_PAD,
+	__TCA_TAPRIO_ATTR_MAX,
+};
+
+#define TCA_TAPRIO_ATTR_MAX (__TCA_TAPRIO_ATTR_MAX - 1)
+
 #endif
Signature · 1 line
2.18.0
#5 lore raw

RFC 5/5 tc: Add support for configuring the taprio scheduler

In reply to Vinicius Costa Gomes

This traffic scheduler allows traffic classes states (transmission allowed/not allowed, in the simplest case) to be scheduled, according to a pre-generated time sequence. This is the basis of the IEEE 802.1Qbv specification.

If the controller supports it, traffic can be also marked as preemptable/not preemptable, and the states for each entry in the time sequence gains a couple more commands. This maps to the functionality defined by the IEEE 802.1Qbu specification.

The syntax is:

tc qdisc add dev DEV parent NODE taprio num_tc NUMBER map P0 P1 ...

	queues TC0 TC1 TC2 ...
	[ [sched-file file] | [sched-row INDEX CMD GATE-MASK INTERVAL]
	[ base-time TIME ] [ extension-time TIME ] [ cycle-time TIME ]
	[ preemption TC0 TC1 TC2 ... ]
	clockid CLOCKID

The parameters should be similar to what the IEEE 802.1Q family of specification define.

---
 tc/Makefile   |   1 +
 tc/q_taprio.c | 450 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 451 insertions(+)
 create mode 100644 tc/q_taprio.c
tc/Makefile +1 -0
index dfd00267..6534d69b 100644
@@ -71,6 +71,7 @@ TCMODULES += q_clsact.o
 TCMODULES += e_bpf.o
 TCMODULES += f_matchall.o
 TCMODULES += q_cbs.o
+TCMODULES += q_taprio.o
 
 TCSO :=
 ifeq ($(TC_CONFIG_ATM),y)
tc/q_taprio.c new file +450 -0

450 lines not on this page · raw message

Signature · 1 line
2.18.0
#6 lore raw

Re: [RFC iproute2-next v1 5/5] tc: Add support for configuring the taprio scheduler

Quoted 11 lines · On Fri, 13 Jul 2018 17:06:11 -0700 Vinicius Costa Gomes…
tc/q_taprio.c new file +11 -0
+	while (fscanf(f, "%ms %x %" PRIu32 "\n", &cmd_str, &gatemask, &interval) != EOF)  {
+		struct rtattr *entry;
+
+		err = str_to_entry_cmd(cmd_str);
+		free(cmd_str);
+
+		if (err < 0)
+			return err;
+
+		cmd = err;
+

tc/q_taprio.c line 129

Quoted 10 lines
tc/q_taprio.c new file +10 -0
+		entry = addattr_nest(n, 1024, TCA_TAPRIO_SCHED_ENTRY);
+
+		addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_INDEX, &index, sizeof(index));
+		addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_CMD, &cmd, sizeof(cmd));
+		addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_GATE_MASK, &gatemask, sizeof(gatemask));
+		addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_INTERVAL, &interval, sizeof(interval));
+
+		addattr_nest_end(n, entry);
+	}
+

Why not just use batch mode? Introducing another input mode in tc that is only in one qdisc seems like a bad idea.

Quoted 41 lines
tc/q_taprio.c new file +41 -0
+
+static int taprio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
+{
+	struct rtattr *tb[TCA_TAPRIO_ATTR_MAX + 1];
+	struct tc_mqprio_qopt *qopt = 0;
+	__s64 cycle_time = 0, extension_time = 0, base_time = 0;
+	__s32 clockid = CLOCKID_INVALID;
+	__u32 preempt_mask = 0;
+	int i;
+
+	if (opt == NULL)
+		return 0;
+
+	parse_rtattr_nested(tb, TCA_TAPRIO_ATTR_MAX, opt);
+
+	if (tb[TCA_TAPRIO_ATTR_PRIOMAP] == NULL)
+		return -1;
+
+	qopt = RTA_DATA(tb[TCA_TAPRIO_ATTR_PRIOMAP]);
+
+	fprintf(f, "tc %u map ", qopt->num_tc);
+	for (i = 0; i <= TC_PRIO_MAX; i++)
+		fprintf(f, "%u ", qopt->prio_tc_map[i]);
+	fprintf(f, "\n	queues:");
+	for (i = 0; i < qopt->num_tc; i++)
+		fprintf(f, "(%u:%u) ", qopt->offset[i],
+			qopt->offset[i] + qopt->count[i] - 1);
+
+	if (tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME])
+		cycle_time = rta_getattr_s64(tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME]);
+
+	if (tb[TCA_TAPRIO_ATTR_SCHED_EXTENSION_TIME])
+		extension_time = rta_getattr_s64(tb[TCA_TAPRIO_ATTR_SCHED_EXTENSION_TIME]);
+
+	if (tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME])
+		base_time = rta_getattr_s64(tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME]);
+
+	if (tb[TCA_TAPRIO_ATTR_PREEMPT_MASK])
+		preempt_mask = rta_getattr_s64(tb[TCA_TAPRIO_ATTR_PREEMPT_MASK]);
+
+	if (tb[TCA_TAPRIO_ATTR_SCHED_CLOCKID])

tc/q_taprio.c line 443

Quoted 10 lines
tc/q_taprio.c new file +10 -0
+		clockid = rta_getattr_s32(tb[TCA_TAPRIO_ATTR_SCHED_CLOCKID]);
+
+	fprintf(f, "\n	clockid %s ", get_clock_name(clockid));
+
+	fprintf(f, "\n	base-time %lld cycle-time %lld extension-time %lld ",
+		base_time, cycle_time, extension_time);
+
+	fprintf(f, "\n	preempt-mask 0x%x ", preempt_mask);
+
+	return print_sched_list(f, tb[TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST]);

Please implement JSON output using json_print functions.

#7 lore raw

Re: [RFC iproute2-next v1 5/5] tc: Add support for configuring the taprio scheduler

Hi,

Quoted 19 lines · Stephen Hemminger
Quoted 16 lines · On Fri, 13 Jul 2018 17:06:11 -0700 Vinicius Costa Gomes…
tc/q_taprio.c new file +16 -0
+	while (fscanf(f, "%ms %x %" PRIu32 "\n", &cmd_str, &gatemask, &interval) != EOF)  {
+		struct rtattr *entry;
+
+		err = str_to_entry_cmd(cmd_str);
+		free(cmd_str);
+
+		if (err < 0)
+			return err;
+
+		cmd = err;
+
+		entry = addattr_nest(n, 1024, TCA_TAPRIO_SCHED_ENTRY);
+
+		addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_INDEX, &index, sizeof(index));
+		addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_CMD, &cmd, sizeof(cmd));
+		addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_GATE_MASK, &gatemask, sizeof(gatemask));
Quoted 8 lines

tc/q_taprio.c line 129

Quoted 5 lines
tc/q_taprio.c new file +5 -0
+		addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_INTERVAL, &interval, sizeof(interval));
+
+		addattr_nest_end(n, entry);
+	}
+

Why not just use batch mode? Introducing another input mode in tc that is only in one qdisc seems like a bad idea.

Seems that I have missed batch mode. I am going to play with it a little and see how things would look.

Quoted 47 lines
Quoted 47 lines
tc/q_taprio.c new file +46 -0
+
+static int taprio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
+{
+	struct rtattr *tb[TCA_TAPRIO_ATTR_MAX + 1];
+	struct tc_mqprio_qopt *qopt = 0;
+	__s64 cycle_time = 0, extension_time = 0, base_time = 0;
+	__s32 clockid = CLOCKID_INVALID;
+	__u32 preempt_mask = 0;
+	int i;
+
+	if (opt == NULL)
+		return 0;
+
+	parse_rtattr_nested(tb, TCA_TAPRIO_ATTR_MAX, opt);
+
+	if (tb[TCA_TAPRIO_ATTR_PRIOMAP] == NULL)
+		return -1;
+
+	qopt = RTA_DATA(tb[TCA_TAPRIO_ATTR_PRIOMAP]);
+
+	fprintf(f, "tc %u map ", qopt->num_tc);
+	for (i = 0; i <= TC_PRIO_MAX; i++)
+		fprintf(f, "%u ", qopt->prio_tc_map[i]);
+	fprintf(f, "\n	queues:");
+	for (i = 0; i < qopt->num_tc; i++)
+		fprintf(f, "(%u:%u) ", qopt->offset[i],
+			qopt->offset[i] + qopt->count[i] - 1);
+
+	if (tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME])
+		cycle_time = rta_getattr_s64(tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME]);
+
+	if (tb[TCA_TAPRIO_ATTR_SCHED_EXTENSION_TIME])
+		extension_time = rta_getattr_s64(tb[TCA_TAPRIO_ATTR_SCHED_EXTENSION_TIME]);
+
+	if (tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME])
+		base_time = rta_getattr_s64(tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME]);
+
+	if (tb[TCA_TAPRIO_ATTR_PREEMPT_MASK])
+		preempt_mask = rta_getattr_s64(tb[TCA_TAPRIO_ATTR_PREEMPT_MASK]);
+
+	if (tb[TCA_TAPRIO_ATTR_SCHED_CLOCKID])
+		clockid = rta_getattr_s32(tb[TCA_TAPRIO_ATTR_SCHED_CLOCKID]);
+
+	fprintf(f, "\n	clockid %s ", get_clock_name(clockid));
+
+	fprintf(f, "\n	base-time %lld cycle-time %lld extension-time %lld ",
Quoted 8 lines

tc/q_taprio.c line 443

Quoted 5 lines
tc/q_taprio.c new file +5 -0
+		base_time, cycle_time, extension_time);
+
+	fprintf(f, "\n	preempt-mask 0x%x ", preempt_mask);
+
+	return print_sched_list(f, tb[TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST]);

Please implement JSON output using json_print functions.

Sure. Will do.

Cheers,

#8 lore raw

Re: [RFC iproute2-next v1 5/5] tc: Add support for configuring the taprio scheduler

Hi,

Quoted 4 lines · Vinicius Costa Gomes

Hi,

Stephen Hemminger <[email protected]> writes:

[...]

Quoted 7 lines
Quoted 3 lines

Why not just use batch mode? Introducing another input mode in tc that is only in one qdisc seems like a bad idea.

Seems that I have missed batch mode. I am going to play with it a little and see how things would look.

I finally had the chance to play with this, and indeed batch mode is quite nice. Will replace the custom file input mode on the next iteration. Thanks.

Cheers,