summaryrefslogtreecommitdiff
path: root/tc
diff options
context:
space:
mode:
authorVladimir Oltean <vladimir.oltean@nxp.com>2022-10-28 14:50:53 +0300
committerDavid Ahern <dsahern@kernel.org>2022-10-31 07:11:28 -0600
commitb10a6509c1959d1109692d667f32b815ddcaa4fc (patch)
tree62e5667e1a2a85495c67fe4219fece90546896ce /tc
parent9313ba541f793dd1600ea4bb7c4f739accac3e84 (diff)
downloadiproute2-b10a6509c1959d1109692d667f32b815ddcaa4fc.tar.gz
taprio: support dumping and setting per-tc max SDU
The 802.1Q queueMaxSDU table is technically implemented in Linux as the TCA_TAPRIO_TC_ENTRY_MAX_SDU attribute of the TCA_TAPRIO_ATTR_TC_ENTRY nest. Multiple TCA_TAPRIO_ATTR_TC_ENTRY nests may appear in the netlink message, one per traffic class. Other configuration items that are per traffic class are also supposed to go there. This is done for future extensibility of the netlink interface (I have the feeling that the struct tc_mqprio_qopt passed through TCA_TAPRIO_ATTR_PRIOMAP is not exactly extensible, which kind of defeats the purpose of using netlink). But otherwise, the max-sdu is parsed from the user, and printed, just like any other fixed-size 16 element array. I've modified the example for a fully offloaded configuration (flags 2) to also show a max-sdu use case. The gate intervals were 0x80 (for TC 7), 0xa0 (for TCs 7 and 5) and 0xdf (for TCs 7, 6, 4, 3, 2, 1, 0). I modified the last gate to exclude TC 7 (df -> 5f), so that TC 7 now only interferes with TC 5. Output after running the full offload command from the man page example (the new attribute is "max-sdu"): $ tc qdisc show dev swp0 root qdisc taprio 8002: root tc 8 map 0 1 2 3 4 5 6 7 0 0 0 0 0 0 0 0 queues offset 0 count 1 offset 1 count 1 offset 2 count 1 offset 3 count 1 offset 4 count 1 offset 5 count 1 offset 6 count 1 offset 7 count 1 flags 0x2 base-time 200 cycle-time 100000 cycle-time-extension 0 index 0 cmd S gatemask 0x80 interval 20000 index 1 cmd S gatemask 0xa0 interval 20000 index 2 cmd S gatemask 0x5f interval 60000 max-sdu 0 0 0 0 0 200 0 0 0 0 0 0 0 0 0 0 $ tc -j -p qdisc show dev eno0 root [ { "kind": "taprio", "handle": "8002:", "root": true, "options": { "tc": 8, "map": [ 0,1,2,3,4,5,6,7,0,0,0,0,0,0,0,0 ], "queues": [ { "offset": 0, "count": 1 },{ "offset": 1, "count": 1 },{ "offset": 2, "count": 1 },{ "offset": 3, "count": 1 },{ "offset": 4, "count": 1 },{ "offset": 5, "count": 1 },{ "offset": 6, "count": 1 },{ "offset": 7, "count": 1 } ], "flags": "0x2", "base_time": 200, "cycle_time": 100000, "cycle_time_extension": 0, "schedule": [ { "index": 0, "cmd": "S", "gatemask": "0x80", "interval": 20000 },{ "index": 1, "cmd": "S", "gatemask": "0xa0", "interval": 20000 },{ "index": 2, "cmd": "S", "gatemask": "0x5f", "interval": 60000 } ], "max-sdu": [ 0,0,0,0,0,200,0,0,0,0,0,0,0,0,0,0 ] } } ] Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: David Ahern <dsahern@kernel.org>
Diffstat (limited to 'tc')
-rw-r--r--tc/q_taprio.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/tc/q_taprio.c b/tc/q_taprio.c
index e3af3f3f..ded385ca 100644
--- a/tc/q_taprio.c
+++ b/tc/q_taprio.c
@@ -151,13 +151,33 @@ static struct sched_entry *create_entry(uint32_t gatemask, uint32_t interval, ui
return e;
}
+static void add_tc_entries(struct nlmsghdr *n, __u32 max_sdu[TC_QOPT_MAX_QUEUE],
+ int num_max_sdu_entries)
+{
+ struct rtattr *l;
+ __u32 tc;
+
+ for (tc = 0; tc <= num_max_sdu_entries; tc++) {
+ l = addattr_nest(n, 1024, TCA_TAPRIO_ATTR_TC_ENTRY | NLA_F_NESTED);
+
+ addattr_l(n, 1024, TCA_TAPRIO_TC_ENTRY_INDEX, &tc, sizeof(tc));
+ addattr_l(n, 1024, TCA_TAPRIO_TC_ENTRY_MAX_SDU,
+ &max_sdu[tc], sizeof(max_sdu[tc]));
+
+ addattr_nest_end(n, l);
+ }
+}
+
static int taprio_parse_opt(struct qdisc_util *qu, int argc,
char **argv, struct nlmsghdr *n, const char *dev)
{
+ __u32 max_sdu[TC_QOPT_MAX_QUEUE] = { };
__s32 clockid = CLOCKID_INVALID;
struct tc_mqprio_qopt opt = { };
__s64 cycle_time_extension = 0;
struct list_head sched_entries;
+ bool have_tc_entries = false;
+ int num_max_sdu_entries = 0;
struct rtattr *tail, *l;
__u32 taprio_flags = 0;
__u32 txtime_delay = 0;
@@ -211,6 +231,17 @@ static int taprio_parse_opt(struct qdisc_util *qu, int argc,
free(tmp);
idx++;
}
+ } else if (strcmp(*argv, "max-sdu") == 0) {
+ while (idx < TC_QOPT_MAX_QUEUE && NEXT_ARG_OK()) {
+ NEXT_ARG();
+ if (get_u32(&max_sdu[idx], *argv, 10)) {
+ PREV_ARG();
+ break;
+ }
+ num_max_sdu_entries++;
+ idx++;
+ }
+ have_tc_entries = true;
} else if (strcmp(*argv, "sched-entry") == 0) {
uint32_t mask, interval;
struct sched_entry *e;
@@ -341,6 +372,9 @@ static int taprio_parse_opt(struct qdisc_util *qu, int argc,
addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION,
&cycle_time_extension, sizeof(cycle_time_extension));
+ if (have_tc_entries)
+ add_tc_entries(n, max_sdu, num_max_sdu_entries);
+
l = addattr_nest(n, 1024, TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST | NLA_F_NESTED);
err = add_sched_list(&sched_entries, n);
@@ -430,6 +464,65 @@ static int print_schedule(FILE *f, struct rtattr **tb)
return 0;
}
+static void dump_tc_entry(__u32 max_sdu[TC_QOPT_MAX_QUEUE],
+ struct rtattr *item, bool *have_tc_entries,
+ int *max_tc_index)
+{
+ struct rtattr *tb[TCA_TAPRIO_TC_ENTRY_MAX + 1];
+ __u32 tc, val = 0;
+
+ parse_rtattr_nested(tb, TCA_TAPRIO_TC_ENTRY_MAX, item);
+
+ if (!tb[TCA_TAPRIO_TC_ENTRY_INDEX]) {
+ fprintf(stderr, "Missing tc entry index\n");
+ return;
+ }
+
+ tc = rta_getattr_u32(tb[TCA_TAPRIO_TC_ENTRY_INDEX]);
+ /* Prevent array out of bounds access */
+ if (tc >= TC_QOPT_MAX_QUEUE) {
+ fprintf(stderr, "Unexpected tc entry index %d\n", tc);
+ return;
+ }
+
+ if (*max_tc_index < tc)
+ *max_tc_index = tc;
+
+ if (tb[TCA_TAPRIO_TC_ENTRY_MAX_SDU])
+ val = rta_getattr_u32(tb[TCA_TAPRIO_TC_ENTRY_MAX_SDU]);
+
+ max_sdu[tc] = val;
+
+ *have_tc_entries = true;
+}
+
+static void dump_tc_entries(FILE *f, struct rtattr *opt)
+{
+ __u32 max_sdu[TC_QOPT_MAX_QUEUE] = {};
+ int tc, rem, max_tc_index = 0;
+ bool have_tc_entries = false;
+ struct rtattr *i;
+
+ rem = RTA_PAYLOAD(opt);
+
+ for (i = RTA_DATA(opt); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
+ if (i->rta_type != (TCA_TAPRIO_ATTR_TC_ENTRY | NLA_F_NESTED))
+ continue;
+
+ dump_tc_entry(max_sdu, i, &have_tc_entries, &max_tc_index);
+ }
+
+ if (!have_tc_entries)
+ return;
+
+ open_json_array(PRINT_ANY, "max-sdu");
+ for (tc = 0; tc <= max_tc_index; tc++)
+ print_uint(PRINT_ANY, NULL, " %u", max_sdu[tc]);
+ close_json_array(PRINT_ANY, "");
+
+ print_nl();
+}
+
static int taprio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
struct rtattr *tb[TCA_TAPRIO_ATTR_MAX + 1];
@@ -503,6 +596,8 @@ static int taprio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
close_json_object();
}
+ dump_tc_entries(f, opt);
+
return 0;
}