* [RFC iproute2-next v1 0/5] net/sched: Introduce the taprio scheduler
@ 2018-07-14 0:06 Vinicius Costa Gomes
2018-07-14 0:06 ` [RFC iproute2-next v1 1/5] utils: Implement get_s64() Vinicius Costa Gomes
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2018-07-14 0:06 UTC (permalink / raw)
To: netdev
Cc: Vinicius Costa Gomes, jhs, xiyou.wangcong, jiri,
jesus.sanchez-palencia
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,
^ permalink raw reply [flat|nested] 9+ messages in thread
* [RFC iproute2-next v1 1/5] utils: Implement get_s64()
2018-07-14 0:06 [RFC iproute2-next v1 0/5] net/sched: Introduce the taprio scheduler Vinicius Costa Gomes
@ 2018-07-14 0:06 ` Vinicius Costa Gomes
2018-07-14 0:06 ` [RFC iproute2-next v1 2/5] include: Add helper to retrieve a __s64 from a netlink msg Vinicius Costa Gomes
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2018-07-14 0:06 UTC (permalink / raw)
To: netdev
Cc: Vinicius Costa Gomes, jhs, xiyou.wangcong, jiri,
jesus.sanchez-palencia
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(+)
diff --git a/include/utils.h b/include/utils.h
index 8cb4349e..58574a05 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -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);
diff --git a/lib/utils.c b/lib/utils.c
index 02ce6772..02836d6e 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -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;
--
2.18.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC iproute2-next v1 2/5] include: Add helper to retrieve a __s64 from a netlink msg
2018-07-14 0:06 [RFC iproute2-next v1 0/5] net/sched: Introduce the taprio scheduler Vinicius Costa Gomes
2018-07-14 0:06 ` [RFC iproute2-next v1 1/5] utils: Implement get_s64() Vinicius Costa Gomes
@ 2018-07-14 0:06 ` Vinicius Costa Gomes
2018-07-14 0:06 ` [RFC iproute2-next v1 3/5] libnetlink: Add helper for getting a __s32 from netlink msgs Vinicius Costa Gomes
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2018-07-14 0:06 UTC (permalink / raw)
To: netdev
Cc: Vinicius Costa Gomes, jhs, xiyou.wangcong, jiri,
jesus.sanchez-palencia
This allows signed 64-bit integers to be retrieved from a netlink
message.
---
include/libnetlink.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/include/libnetlink.h b/include/libnetlink.h
index 9d9249e6..88164975 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -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);
--
2.18.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC iproute2-next v1 3/5] libnetlink: Add helper for getting a __s32 from netlink msgs
2018-07-14 0:06 [RFC iproute2-next v1 0/5] net/sched: Introduce the taprio scheduler Vinicius Costa Gomes
2018-07-14 0:06 ` [RFC iproute2-next v1 1/5] utils: Implement get_s64() Vinicius Costa Gomes
2018-07-14 0:06 ` [RFC iproute2-next v1 2/5] include: Add helper to retrieve a __s64 from a netlink msg Vinicius Costa Gomes
@ 2018-07-14 0:06 ` Vinicius Costa Gomes
2018-07-14 0:06 ` [RFC iproute2-next v1 4/5] include: add definitions for taprio [DO NOT COMMIT] Vinicius Costa Gomes
2018-07-14 0:06 ` [RFC iproute2-next v1 5/5] tc: Add support for configuring the taprio scheduler Vinicius Costa Gomes
4 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2018-07-14 0:06 UTC (permalink / raw)
To: netdev; +Cc: Jesus Sanchez-Palencia, jhs, xiyou.wangcong, jiri
From: Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
This function retrieves a signed 32-bit integer from a netlink message
and returns it.
Signed-off-by: Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
---
include/libnetlink.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/include/libnetlink.h b/include/libnetlink.h
index 88164975..114a816e 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -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;
--
2.18.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC iproute2-next v1 4/5] include: add definitions for taprio [DO NOT COMMIT]
2018-07-14 0:06 [RFC iproute2-next v1 0/5] net/sched: Introduce the taprio scheduler Vinicius Costa Gomes
` (2 preceding siblings ...)
2018-07-14 0:06 ` [RFC iproute2-next v1 3/5] libnetlink: Add helper for getting a __s32 from netlink msgs Vinicius Costa Gomes
@ 2018-07-14 0:06 ` Vinicius Costa Gomes
2018-07-14 0:06 ` [RFC iproute2-next v1 5/5] tc: Add support for configuring the taprio scheduler Vinicius Costa Gomes
4 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2018-07-14 0:06 UTC (permalink / raw)
To: netdev
Cc: Vinicius Costa Gomes, jhs, xiyou.wangcong, jiri,
jesus.sanchez-palencia
DO NOT COMMIT
This patch exists only to ease the testing, until this header is
updated with the definitions from the kernel.
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
include/uapi/linux/pkt_sched.h | 48 ++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h
index 37b5096a..8ca988cb 100644
--- a/include/uapi/linux/pkt_sched.h
+++ b/include/uapi/linux/pkt_sched.h
@@ -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
--
2.18.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC iproute2-next v1 5/5] tc: Add support for configuring the taprio scheduler
2018-07-14 0:06 [RFC iproute2-next v1 0/5] net/sched: Introduce the taprio scheduler Vinicius Costa Gomes
` (3 preceding siblings ...)
2018-07-14 0:06 ` [RFC iproute2-next v1 4/5] include: add definitions for taprio [DO NOT COMMIT] Vinicius Costa Gomes
@ 2018-07-14 0:06 ` Vinicius Costa Gomes
2018-07-14 19:19 ` Stephen Hemminger
4 siblings, 1 reply; 9+ messages in thread
From: Vinicius Costa Gomes @ 2018-07-14 0:06 UTC (permalink / raw)
To: netdev
Cc: Vinicius Costa Gomes, jhs, xiyou.wangcong, jiri,
jesus.sanchez-palencia
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.
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Signed-off-by: Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
---
tc/Makefile | 1 +
tc/q_taprio.c | 450 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 451 insertions(+)
create mode 100644 tc/q_taprio.c
diff --git a/tc/Makefile b/tc/Makefile
index dfd00267..6534d69b 100644
--- a/tc/Makefile
+++ b/tc/Makefile
@@ -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)
diff --git a/tc/q_taprio.c b/tc/q_taprio.c
new file mode 100644
index 00000000..ef8baa4b
--- /dev/null
+++ b/tc/q_taprio.c
@@ -0,0 +1,450 @@
+/*
+ * q_taprio.c Time Aware Priority Scheduler
+ *
+ * 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: Vinicius Costa Gomes <vinicius.gomes@intel.com>
+ * Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <syslog.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <string.h>
+
+#include "utils.h"
+#include "tc_util.h"
+
+#define CLOCKID_INVALID (-1)
+static const struct static_clockid {
+ const char *name;
+ clockid_t clockid;
+} clockids_sysv[] = {
+ { "REALTIME", CLOCK_REALTIME },
+ { "TAI", CLOCK_TAI },
+ { "BOOTTIME", CLOCK_BOOTTIME },
+ { "MONOTONIC", CLOCK_MONOTONIC },
+ { NULL }
+};
+
+static void explain(void)
+{
+ fprintf(stderr, "Usage: ... taprio clockid CLOCKID\n");
+ fprintf(stderr, " [num_tc NUMBER] [map P0 P1 ...] ");
+ fprintf(stderr, " [queues TC0 TC1 TC2 ...] ");
+ fprintf(stderr, " [ [sched-file file] | [sched-row index cmd gate-mask interval] ] ");
+ fprintf(stderr, " [base-time time] [extension-time time] [cycle-time time] ");
+ fprintf(stderr, " [preemption TC0 TC1 TC2 ... ] ");
+ fprintf(stderr, "\nCLOCKID must be a valid SYS-V id (i.e. CLOCK_TAI)");
+ fprintf(stderr, "\n");
+}
+
+static void explain_clockid(const char *val)
+{
+ fprintf(stderr, "taprio: illegal value for \"clockid\": \"%s\".\n", val);
+ fprintf(stderr, "It must be a valid SYS-V id (i.e. CLOCK_TAI)\n");
+}
+
+static int get_clockid(__s32 *val, const char *arg)
+{
+ const struct static_clockid *c;
+
+ /* Drop the CLOCK_ prefix if that is being used. */
+ if (strcasestr(arg, "CLOCK_") != NULL)
+ arg += sizeof("CLOCK_") - 1;
+
+ for (c = clockids_sysv; c->name; c++) {
+ if (strcasecmp(c->name, arg) == 0) {
+ *val = c->clockid;
+
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+static const char* get_clock_name(clockid_t clockid)
+{
+ const struct static_clockid *c;
+
+ for (c = clockids_sysv; c->name; c++) {
+ if (clockid == c->clockid)
+ return c->name;
+ }
+
+ return "invalid";
+}
+
+static int str_to_entry_cmd(const char *str)
+{
+ if (strcmp(str, "S") == 0)
+ return TC_TAPRIO_CMD_SET_GATES;
+
+ if (strcmp(str, "H") == 0)
+ return TC_TAPRIO_CMD_SET_AND_HOLD;
+
+ if (strcmp(str, "R") == 0)
+ return TC_TAPRIO_CMD_SET_AND_RELEASE;
+
+ return -1;
+}
+
+static int add_sched_list(FILE *f, struct nlmsghdr *n)
+{
+ __u32 interval, gatemask, index = 0;
+ char *cmd_str;
+ __u8 cmd;
+ int err;
+
+ 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));
+ addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_INTERVAL, &interval, sizeof(interval));
+
+ addattr_nest_end(n, entry);
+ }
+
+ return 0;
+}
+
+static void explain_sched_row(void)
+{
+ fprintf(stderr, "Usage: ... taprio ... sched-row <index> <cmd> <gate mask> <interval>\n");
+}
+
+static int taprio_parse_opt(struct qdisc_util *qu, int argc,
+ char **argv, struct nlmsghdr *n, const char *dev)
+{
+ __u32 entry_interval = 0, entry_gatemask = 0, entry_index = 0;
+ __s64 base_time = 0, extension_time = 0, cycle_time = 0;
+ __s32 clockid = CLOCKID_INVALID;
+ struct tc_mqprio_qopt opt = { };
+ unsigned int preemption = 0;
+ FILE *sched_file = NULL;
+ struct rtattr *tail;
+ __u8 entry_cmd = 0;
+ int err, idx;
+
+ while (argc > 0) {
+ idx = 0;
+ if (strcmp(*argv, "num_tc") == 0) {
+ NEXT_ARG();
+ if (get_u8(&opt.num_tc, *argv, 10)) {
+ fprintf(stderr, "Illegal \"num_tc\"\n");
+ return -1;
+ }
+ } else if (strcmp(*argv, "map") == 0) {
+ while (idx < TC_QOPT_MAX_QUEUE && NEXT_ARG_OK()) {
+ NEXT_ARG();
+ if (get_u8(&opt.prio_tc_map[idx], *argv, 10)) {
+ PREV_ARG();
+ break;
+ }
+ idx++;
+ }
+ for ( ; idx < TC_QOPT_MAX_QUEUE; idx++)
+ opt.prio_tc_map[idx] = 0;
+ } else if (strcmp(*argv, "queues") == 0) {
+ char *tmp, *tok;
+
+ while (idx < TC_QOPT_MAX_QUEUE && NEXT_ARG_OK()) {
+ NEXT_ARG();
+
+ tmp = strdup(*argv);
+ if (!tmp)
+ break;
+
+ tok = strtok(tmp, "@");
+ if (get_u16(&opt.count[idx], tok, 10)) {
+ free(tmp);
+ PREV_ARG();
+ break;
+ }
+ tok = strtok(NULL, "@");
+ if (get_u16(&opt.offset[idx], tok, 10)) {
+ free(tmp);
+ PREV_ARG();
+ break;
+ }
+ free(tmp);
+ idx++;
+ }
+ } else if (strcmp(*argv, "sched-file") == 0) {
+ if (entry_index || entry_cmd || entry_gatemask || entry_interval) {
+ fprintf(stderr,
+ "taprio: specifying both \"sched-file\" and \"sched-row\" is not allowed\n");
+ return -1;
+ }
+ NEXT_ARG();
+
+ sched_file = fopen(*argv, "r");
+ if (!sched_file) {
+ break;
+ }
+ } else if (strcmp(*argv, "sched-row") == 0) {
+ if (sched_file) {
+ fprintf(stderr, "taprio: specifying both \"sched-file\" and \"sched-row\" is not allowed\n");
+ return -1;
+ }
+
+ NEXT_ARG();
+
+ if (get_u32(&entry_index, *argv, 10)) {
+ explain_sched_row();
+ return -1;
+ }
+
+ NEXT_ARG();
+ err = str_to_entry_cmd(*argv);
+ if (err < 0) {
+ explain_sched_row();
+ return -1;
+ }
+ entry_cmd = err;
+
+ NEXT_ARG();
+ if (get_u32(&entry_gatemask, *argv, 0)) {
+ explain_sched_row();
+ return -1;
+ }
+
+ NEXT_ARG();
+ if (get_u32(&entry_interval, *argv, 0)) {
+ explain_sched_row();
+ return -1;
+ }
+ } else if (strcmp(*argv, "base-time") == 0) {
+ NEXT_ARG();
+ if (get_s64(&base_time, *argv, 10)) {
+ PREV_ARG();
+ break;
+ }
+ } else if (strcmp(*argv, "cycle-time") == 0) {
+ NEXT_ARG();
+ if (get_s64(&cycle_time, *argv, 10)) {
+ PREV_ARG();
+ break;
+ }
+ } else if (strcmp(*argv, "extension-time") == 0) {
+ NEXT_ARG();
+ if (get_s64(&extension_time, *argv, 10)) {
+ PREV_ARG();
+ break;
+ }
+ } else if (strcmp(*argv, "preemption") == 0) {
+ __u8 enable;
+ int i;
+
+ for (i = 0; i < opt.num_tc; i++) {
+ NEXT_ARG();
+
+ if (get_u8(&enable, *argv, 0)) {
+ PREV_ARG();
+ break;
+ }
+
+ preemption |= enable ? BIT(i) : 0;
+ }
+ } else if (strcmp(*argv, "clockid") == 0) {
+ NEXT_ARG();
+ if (clockid != CLOCKID_INVALID) {
+ fprintf(stderr, "taprio: duplicate \"clockid\" specification\n");
+ return -1;
+ }
+ if (get_clockid(&clockid, *argv)) {
+ explain_clockid(*argv);
+ return -1;
+ }
+ } else if (strcmp(*argv, "help") == 0) {
+ explain();
+ return -1;
+ } else {
+ fprintf(stderr, "Unknown argument\n");
+ return -1;
+ }
+ argc--; argv++;
+ }
+
+ tail = NLMSG_TAIL(n);
+ addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
+
+ if (opt.num_tc > 0)
+ addattr_l(n, 1024, TCA_TAPRIO_ATTR_PRIOMAP, &opt, sizeof(opt));
+
+ if (preemption)
+ addattr_l(n, 1024, TCA_TAPRIO_ATTR_PREEMPT_MASK, &preemption, sizeof(preemption));
+
+ if (base_time)
+ addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_BASE_TIME, &base_time, sizeof(base_time));
+
+ if (cycle_time)
+ addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME, &cycle_time, sizeof(cycle_time));
+
+ if (extension_time)
+ addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_EXTENSION_TIME, &extension_time, sizeof(extension_time));
+
+ addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_CLOCKID, &clockid, sizeof(clockid));
+
+ if (sched_file) {
+ struct rtattr *entry_list;
+ entry_list = addattr_nest(n, 1024, TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST | NLA_F_NESTED);
+
+ err = add_sched_list(sched_file, n);
+ if (err < 0) {
+ fprintf(stderr, "Could not read sched list from file\n");
+ return -1;
+ }
+
+ addattr_nest_end(n, entry_list);
+ }
+
+ if (entry_index || entry_cmd || entry_gatemask || entry_interval) {
+ struct rtattr *entry, *entry_list;
+
+ entry_list = addattr_nest(n, 1024, TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY | NLA_F_NESTED);
+ entry = addattr_nest(n, 1024, TCA_TAPRIO_SCHED_ENTRY);
+
+ addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_INDEX, &entry_index, sizeof(entry_index));
+ addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_CMD, &entry_cmd, sizeof(entry_cmd));
+ addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_GATE_MASK, &entry_gatemask, sizeof(entry_gatemask));
+ addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_INTERVAL, &entry_interval, sizeof(entry_interval));
+
+ addattr_nest_end(n, entry);
+ addattr_nest_end(n, entry_list);
+ }
+
+ tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
+
+ return 0;
+}
+
+static const char *command_to_str(__u8 cmd)
+{
+ switch (cmd) {
+ case TC_TAPRIO_CMD_SET_GATES:
+ return "S";
+ case TC_TAPRIO_CMD_SET_AND_HOLD:
+ return "H";
+ case TC_TAPRIO_CMD_SET_AND_RELEASE:
+ return "R";
+ default:
+ return "Invalid";
+ }
+}
+
+static int print_sched_list(FILE *f, struct rtattr *list)
+{
+ struct rtattr *item;
+ int rem;
+
+ if (list == NULL)
+ return 0;
+
+ rem = RTA_PAYLOAD(list);
+
+ 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;
+ __u8 command = 0;
+
+ parse_rtattr_nested(tb, TCA_TAPRIO_SCHED_ENTRY_MAX, item);
+
+ if (tb[TCA_TAPRIO_SCHED_ENTRY_INDEX])
+ index = rta_getattr_u32(tb[TCA_TAPRIO_SCHED_ENTRY_INDEX]);
+
+ if (tb[TCA_TAPRIO_SCHED_ENTRY_CMD])
+ command = rta_getattr_u8(tb[TCA_TAPRIO_SCHED_ENTRY_CMD]);
+
+ if (tb[TCA_TAPRIO_SCHED_ENTRY_GATE_MASK])
+ gatemask = rta_getattr_u32(tb[TCA_TAPRIO_SCHED_ENTRY_GATE_MASK]);
+
+ if (tb[TCA_TAPRIO_SCHED_ENTRY_INTERVAL])
+ interval = rta_getattr_u32(tb[TCA_TAPRIO_SCHED_ENTRY_INTERVAL]);
+
+ fprintf(f, "\n index %u cmd %s gate-mask 0x%x interval %u", index,
+ command_to_str(command), gatemask, interval);
+ }
+
+ 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;
+ __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 ",
+ 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]);
+}
+
+struct qdisc_util taprio_qdisc_util = {
+ .id = "taprio",
+ .parse_qopt = taprio_parse_opt,
+ .print_qopt = taprio_print_opt,
+};
--
2.18.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [RFC iproute2-next v1 5/5] tc: Add support for configuring the taprio scheduler
2018-07-14 0:06 ` [RFC iproute2-next v1 5/5] tc: Add support for configuring the taprio scheduler Vinicius Costa Gomes
@ 2018-07-14 19:19 ` Stephen Hemminger
2018-07-17 16:44 ` Vinicius Costa Gomes
0 siblings, 1 reply; 9+ messages in thread
From: Stephen Hemminger @ 2018-07-14 19:19 UTC (permalink / raw)
To: Vinicius Costa Gomes
Cc: netdev, jhs, xiyou.wangcong, jiri, jesus.sanchez-palencia
On Fri, 13 Jul 2018 17:06:11 -0700
Vinicius Costa Gomes <vinicius.gomes@intel.com> wrote:
> + 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));
> + 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.
> +
> +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 ",
> + 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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC iproute2-next v1 5/5] tc: Add support for configuring the taprio scheduler
2018-07-14 19:19 ` Stephen Hemminger
@ 2018-07-17 16:44 ` Vinicius Costa Gomes
2018-07-24 23:20 ` Vinicius Costa Gomes
0 siblings, 1 reply; 9+ messages in thread
From: Vinicius Costa Gomes @ 2018-07-17 16:44 UTC (permalink / raw)
To: Stephen Hemminger
Cc: netdev, jhs, xiyou.wangcong, jiri, jesus.sanchez-palencia
Hi,
Stephen Hemminger <stephen@networkplumber.org> writes:
> On Fri, 13 Jul 2018 17:06:11 -0700
> Vinicius Costa Gomes <vinicius.gomes@intel.com> wrote:
>
>> + 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));
>> + 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.
>
>> +
>> +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 ",
>> + 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,
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC iproute2-next v1 5/5] tc: Add support for configuring the taprio scheduler
2018-07-17 16:44 ` Vinicius Costa Gomes
@ 2018-07-24 23:20 ` Vinicius Costa Gomes
0 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2018-07-24 23:20 UTC (permalink / raw)
To: Stephen Hemminger
Cc: netdev, jhs, xiyou.wangcong, jiri, jesus.sanchez-palencia
Hi,
Vinicius Costa Gomes <vinicius.gomes@intel.com> writes:
> Hi,
>
> Stephen Hemminger <stephen@networkplumber.org> writes:
>
[...]
>>
>> 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,
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-07-25 0:29 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-14 0:06 [RFC iproute2-next v1 0/5] net/sched: Introduce the taprio scheduler Vinicius Costa Gomes
2018-07-14 0:06 ` [RFC iproute2-next v1 1/5] utils: Implement get_s64() Vinicius Costa Gomes
2018-07-14 0:06 ` [RFC iproute2-next v1 2/5] include: Add helper to retrieve a __s64 from a netlink msg Vinicius Costa Gomes
2018-07-14 0:06 ` [RFC iproute2-next v1 3/5] libnetlink: Add helper for getting a __s32 from netlink msgs Vinicius Costa Gomes
2018-07-14 0:06 ` [RFC iproute2-next v1 4/5] include: add definitions for taprio [DO NOT COMMIT] Vinicius Costa Gomes
2018-07-14 0:06 ` [RFC iproute2-next v1 5/5] tc: Add support for configuring the taprio scheduler Vinicius Costa Gomes
2018-07-14 19:19 ` Stephen Hemminger
2018-07-17 16:44 ` Vinicius Costa Gomes
2018-07-24 23:20 ` Vinicius Costa Gomes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).