Skip to contentSkip to conversation

Update headers with taprio changes [DO NOT MERGE]

PATCH Applied Vinicius Costa Gomes 2 participants 4 messages Apr 29, 2019 – May 4, 2019

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

PATCH 1/3 Update headers with taprio changes [DO NOT MERGE]

This will be updated when the kernel headers are updated.

---
 include/uapi/linux/pkt_sched.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
include/uapi/linux/pkt_sched.h +18 -0
index 7ee74c34..ac9f7eab 100644
@@ -1148,6 +1148,19 @@ enum {
 
 #define TCA_TAPRIO_SCHED_MAX (__TCA_TAPRIO_SCHED_MAX - 1)
 
+/* The format for the admin sched (dump only):
+ * [TCA_TAPRIO_SCHED_ADMIN_SCHED]
+ *   [TCA_TAPRIO_ATTR_SCHED_BASE_TIME]
+ *   [TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST]
+ *     [TCA_TAPRIO_ATTR_SCHED_ENTRY]
+ *       [TCA_TAPRIO_ATTR_SCHED_ENTRY_CMD]
+ *       [TCA_TAPRIO_ATTR_SCHED_ENTRY_GATES]
+ *       [TCA_TAPRIO_ATTR_SCHED_ENTRY_INTERVAL]
+ */
+
+#define TCA_TAPRIO_ATTR_OFFLOAD_FLAG_FULL_OFFLOAD 0x1
+#define TCA_TAPRIO_ATTR_OFFLOAD_FLAG_TXTIME_OFFLOAD 0x2
+
 enum {
 	TCA_TAPRIO_ATTR_UNSPEC,
 	TCA_TAPRIO_ATTR_PRIOMAP, /* struct tc_mqprio_qopt */
@@ -1156,6 +1169,11 @@ enum {
 	TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY, /* single entry */
 	TCA_TAPRIO_ATTR_SCHED_CLOCKID, /* s32 */
 	TCA_TAPRIO_PAD,
+	TCA_TAPRIO_ATTR_ADMIN_SCHED, /* The admin sched, only used in dump */
+	TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME, /* s64 */
+	TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION, /* s64 */
+	TCA_TAPRIO_ATTR_FRAME_PREEMPTION, /* u32 */
+	TCA_TAPRIO_ATTR_OFFLOAD_FLAGS, /* u32 */
 	__TCA_TAPRIO_ATTR_MAX,
 };
 
Signature · 1 line
2.21.0
#1 lore raw

PATCH 2/3 taprio: Add support for changing schedules

This allows for a new schedule to be specified during runtime, without removing the current one.

For that, the semantics of the 'tc qdisc change' operation in the context of taprio is that if "change" is called and there is a running schedule, a new schedule is created and the base-time (let's call it
X) of this new schedule is used so at instant X, it becomes the "current" schedule. So, in short, "change" doesn't change the current schedule, it creates a new one and sets it up to it becomes the current one at some point.

In IEEE 802.1Q terms, it means that we have support for the "Oper" (current and read-only) and "Admin" (future and mutable) schedules.

Example of creating the first schedule, then adding a new one:

(1)
tc qdisc add dev IFACE parent root handle 100 taprio \

      	      num_tc 1 \
	      map 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \
	      queues 1@0 \
	      sched-entry S 0x1 1000000 \
	      sched-entry S 0x0 2000000 \
	      sched-entry S 0x1 3000000 \
	      sched-entry S 0x0 4000000 \
	      base-time 100000000 \
	      clockid CLOCK_TAI

(2)
tc qdisc change dev IFACE parent root handle 100 taprio \

	      base-time 7500000000000 \
	      sched-entry S 0x0 5000000 \
              sched-entry S 0x1 5000000 \

It was necessary to fix a bug, so the clockid doesn't need to be specified when changing the schedule.

Most of the changes are related to make it easier to reuse the same function for printing the "admin" and "oper" schedules.

---
 tc/q_taprio.c | 42 +++++++++++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 9 deletions(-)
tc/q_taprio.c +33 -9
index 8f6b263a..336bb245 100644
@@ -268,14 +268,15 @@ static int taprio_parse_opt(struct qdisc_util *qu, int argc,
 	tail = NLMSG_TAIL(n);
 	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 
+	if (clockid != CLOCKID_INVALID)
+		addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_CLOCKID, &clockid, sizeof(clockid));
+
 	if (opt.num_tc > 0)
 		addattr_l(n, 1024, TCA_TAPRIO_ATTR_PRIOMAP, &opt, sizeof(opt));
 
 	if (base_time)
 		addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_BASE_TIME, &base_time, sizeof(base_time));
 
-	addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_CLOCKID, &clockid, sizeof(clockid));
-
 	if (!list_empty(&sched_entries)) {
 		struct rtattr *entry_list;
 		entry_list = addattr_nest(n, 1024, TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST | NLA_F_NESTED);
@@ -306,6 +307,8 @@ static int print_sched_list(FILE *f, struct rtattr *list)
 
 	open_json_array(PRINT_JSON, "schedule");
 
+	print_string(PRINT_FP, NULL, "%s", _SL_);
+
 	for (item = RTA_DATA(list); RTA_OK(item, rem); item = RTA_NEXT(item, rem)) {
 		struct rtattr *tb[TCA_TAPRIO_SCHED_ENTRY_MAX + 1];
 		__u32 index = 0, gatemask = 0, interval = 0;
@@ -340,12 +343,25 @@ static int print_sched_list(FILE *f, struct rtattr *list)
 	return 0;
 }
 
+static int print_schedule(FILE *f, struct rtattr **tb)
+{
+	int64_t base_time = 0;
+
+	if (tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME])
+		base_time = rta_getattr_s64(tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME]);
+
+	print_lluint(PRINT_ANY, "base_time", "\tbase-time %lld", base_time);
+
+	print_sched_list(f, tb[TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST]);
+
+	return 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;
 	__s32 clockid = CLOCKID_INVALID;
-	__s64 base_time = 0;
 	int i;
 
 	if (opt == NULL)
@@ -378,19 +394,27 @@ static int taprio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 
 	print_string(PRINT_FP, NULL, "%s", _SL_);
 
-	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_SCHED_CLOCKID])
 		clockid = rta_getattr_s32(tb[TCA_TAPRIO_ATTR_SCHED_CLOCKID]);
 
 	print_string(PRINT_ANY, "clockid", "clockid %s", get_clock_name(clockid));
 
-	print_lluint(PRINT_ANY, "base_time", " base-time %lld", base_time);
+	print_schedule(f, tb);
 
-	print_string(PRINT_FP, NULL, "%s", _SL_);
+	if (tb[TCA_TAPRIO_ATTR_ADMIN_SCHED]) {
+		struct rtattr *t[TCA_TAPRIO_ATTR_MAX + 1];
+
+		parse_rtattr_nested(t, TCA_TAPRIO_ATTR_MAX,
+				    tb[TCA_TAPRIO_ATTR_ADMIN_SCHED]);
 
-	return print_sched_list(f, tb[TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST]);
+		open_json_object(NULL);
+
+		print_schedule(f, t);
+
+		close_json_object();
+	}
+
+	return 0;
 }
 
 struct qdisc_util taprio_qdisc_util = {
Signature · 1 line
2.21.0
Applied
#2 lore raw

Re: [PATCH iproute2 net-next v1 2/3] taprio: Add support for changing schedules

Quoted 15 lines · Vinicius Costa Gomes

This allows for a new schedule to be specified during runtime, without removing the current one.

For that, the semantics of the 'tc qdisc change' operation in the context of taprio is that if "change" is called and there is a running schedule, a new schedule is created and the base-time (let's call it
X) of this new schedule is used so at instant X, it becomes the "current" schedule. So, in short, "change" doesn't change the current schedule, it creates a new one and sets it up to it becomes the current one at some point.

In IEEE 802.1Q terms, it means that we have support for the "Oper" (current and read-only) and "Admin" (future and mutable) schedules.

...

Quoted 3 lines

It was necessary to fix a bug, so the clockid doesn't need to be specified when changing the schedule.

Does that bug fix need to be applied to master?

Quoted 9 lines

Most of the changes are related to make it easier to reuse the same function for printing the "admin" and "oper" schedules.

---
 tc/q_taprio.c | 42 +++++++++++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 9 deletions(-)

applied to iproute2-next.

#3 lore raw

PATCH 3/3 taprio: Add support for cycle_time and cycle_time_extension

In reply to Vinicius Costa Gomes

This allows a cycle-time and a cycle-time-extension to be specified.

Specifying a cycle-time will truncate that cycle, so when that instant is reached, the cycle will start from its beginning.

A cycle-time-extension may cause the last entry of a cycle, just before the start of a new schedule (the base-time of the "admin" schedule) to be extended by at maximum "cycle-time-extension" nanoseconds. The idea of this feauture, as described by the IEEE 802.1Q, is too avoid too narrow gate states.

Example:

tc qdisc change dev IFACE parent root handle 100 taprio \

	      sched-entry S 0x1 1000000 \
	      sched-entry S 0x0 2000000 \
	      sched-entry S 0x1 3000000 \
	      sched-entry S 0x0 4000000 \
	      cycle-time-extension 100000 \
	      cycle-time 9000000 \
	      base-time 12345678900000000
---
 tc/q_taprio.c | 64 ++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 53 insertions(+), 11 deletions(-)
tc/q_taprio.c +53 -11
index 336bb245..aad055d8 100644
@@ -155,8 +155,10 @@ static int taprio_parse_opt(struct qdisc_util *qu, int argc,
 {
 	__s32 clockid = CLOCKID_INVALID;
 	struct tc_mqprio_qopt opt = { };
+	__s64 cycle_time_extension = 0;
 	struct list_head sched_entries;
-	struct rtattr *tail;
+	struct rtattr *tail, *l;
+	__s64 cycle_time = 0;
 	__s64 base_time = 0;
 	int err, idx;
 
@@ -245,6 +247,29 @@ static int taprio_parse_opt(struct qdisc_util *qu, int argc,
 				PREV_ARG();
 				break;
 			}
+		} else if (strcmp(*argv, "cycle-time") == 0) {
+			NEXT_ARG();
+			if (cycle_time) {
+				fprintf(stderr, "taprio: duplicate \"cycle-time\" specification\n");
+				return -1;
+			}
+
+			if (get_s64(&cycle_time, *argv, 10)) {
+				PREV_ARG();
+				break;
+			}
+
+		} else if (strcmp(*argv, "cycle-time-extension") == 0) {
+			NEXT_ARG();
+			if (cycle_time_extension) {
+				fprintf(stderr, "taprio: duplicate \"cycle-time-extension\" specification\n");
+				return -1;
+			}
+
+			if (get_s64(&cycle_time_extension, *argv, 10)) {
+				PREV_ARG();
+				break;
+			}
 		} else if (strcmp(*argv, "clockid") == 0) {
 			NEXT_ARG();
 			if (clockid != CLOCKID_INVALID) {
@@ -277,19 +302,24 @@ static int taprio_parse_opt(struct qdisc_util *qu, int argc,
 	if (base_time)
 		addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_BASE_TIME, &base_time, sizeof(base_time));
 
-	if (!list_empty(&sched_entries)) {
-		struct rtattr *entry_list;
-		entry_list = addattr_nest(n, 1024, TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST | NLA_F_NESTED);
+	if (cycle_time)
+		addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME,
+			  &cycle_time, sizeof(cycle_time));
 
-		err = add_sched_list(&sched_entries, n);
-		if (err < 0) {
-			fprintf(stderr, "Could not add schedule to netlink message\n");
-			return -1;
-		}
+	if (cycle_time_extension)
+		addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION,
+			  &cycle_time_extension, sizeof(cycle_time_extension));
+
+	l = addattr_nest(n, 1024, TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST | NLA_F_NESTED);
 
-		addattr_nest_end(n, entry_list);
+	err = add_sched_list(&sched_entries, n);
+	if (err < 0) {
+		fprintf(stderr, "Could not add schedule to netlink message\n");
+		return -1;
 	}
 
+	addattr_nest_end(n, l);
+
 	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 
 	return 0;
@@ -345,13 +375,25 @@ static int print_sched_list(FILE *f, struct rtattr *list)
 
 static int print_schedule(FILE *f, struct rtattr **tb)
 {
-	int64_t base_time = 0;
+	int64_t base_time = 0, cycle_time = 0, cycle_time_extension = 0;
 
 	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_SCHED_CYCLE_TIME])
+		cycle_time = rta_getattr_s64(tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME]);
+
+	if (tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION])
+		cycle_time_extension = rta_getattr_s64(
+			tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION]);
+
 	print_lluint(PRINT_ANY, "base_time", "\tbase-time %lld", base_time);
 
+	print_lluint(PRINT_ANY, "cycle_time", " cycle-time %lld", cycle_time);
+
+	print_lluint(PRINT_ANY, "cycle_time_extension",
+		     " cycle-time-extension %lld", cycle_time_extension);
+
 	print_sched_list(f, tb[TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST]);
 
 	return 0;
Signature · 1 line
2.21.0