2 * q_etf.c Earliest TxTime First (ETF).
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Vinicius Costa Gomes <vinicius.gomes@intel.com>
10 * Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
18 #include <sys/ioctl.h>
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
27 #define CLOCKID_INVALID (-1)
28 static const struct static_clockid
{
32 { "REALTIME", CLOCK_REALTIME
},
34 { "BOOTTIME", CLOCK_BOOTTIME
},
35 { "MONOTONIC", CLOCK_MONOTONIC
},
39 static void explain(void)
41 fprintf(stderr
, "Usage: ... etf delta NANOS clockid CLOCKID [offload] [deadline_mode]\n");
42 fprintf(stderr
, "CLOCKID must be a valid SYS-V id (i.e. CLOCK_TAI)\n");
45 static void explain1(const char *arg
, const char *val
)
47 fprintf(stderr
, "etf: illegal value for \"%s\": \"%s\"\n", arg
, val
);
50 static void explain_clockid(const char *val
)
52 fprintf(stderr
, "etf: illegal value for \"clockid\": \"%s\".\n", val
);
53 fprintf(stderr
, "It must be a valid SYS-V id (i.e. CLOCK_TAI)\n");
56 static int get_clockid(__s32
*val
, const char *arg
)
58 const struct static_clockid
*c
;
60 /* Drop the CLOCK_ prefix if that is being used. */
61 if (strcasestr(arg
, "CLOCK_") != NULL
)
62 arg
+= sizeof("CLOCK_") - 1;
64 for (c
= clockids_sysv
; c
->name
; c
++) {
65 if (strcasecmp(c
->name
, arg
) == 0) {
75 static const char* get_clock_name(clockid_t clockid
)
77 const struct static_clockid
*c
;
79 for (c
= clockids_sysv
; c
->name
; c
++) {
80 if (clockid
== c
->clockid
)
87 static int etf_parse_opt(struct qdisc_util
*qu
, int argc
,
88 char **argv
, struct nlmsghdr
*n
, const char *dev
)
90 struct tc_etf_qopt opt
= {
91 .clockid
= CLOCKID_INVALID
,
96 if (matches(*argv
, "offload") == 0) {
97 if (opt
.flags
& TC_ETF_OFFLOAD_ON
) {
98 fprintf(stderr
, "etf: duplicate \"offload\" specification\n");
102 opt
.flags
|= TC_ETF_OFFLOAD_ON
;
103 } else if (matches(*argv
, "deadline_mode") == 0) {
104 if (opt
.flags
& TC_ETF_DEADLINE_MODE_ON
) {
105 fprintf(stderr
, "etf: duplicate \"deadline_mode\" specification\n");
109 opt
.flags
|= TC_ETF_DEADLINE_MODE_ON
;
110 } else if (matches(*argv
, "delta") == 0) {
113 fprintf(stderr
, "etf: duplicate \"delta\" specification\n");
116 if (get_s32(&opt
.delta
, *argv
, 0)) {
117 explain1("delta", *argv
);
120 } else if (matches(*argv
, "clockid") == 0) {
122 if (opt
.clockid
!= CLOCKID_INVALID
) {
123 fprintf(stderr
, "etf: duplicate \"clockid\" specification\n");
126 if (get_clockid(&opt
.clockid
, *argv
)) {
127 explain_clockid(*argv
);
130 } else if (strcmp(*argv
, "help") == 0) {
134 fprintf(stderr
, "etf: unknown parameter \"%s\"\n", *argv
);
141 tail
= NLMSG_TAIL(n
);
142 addattr_l(n
, 1024, TCA_OPTIONS
, NULL
, 0);
143 addattr_l(n
, 2024, TCA_ETF_PARMS
, &opt
, sizeof(opt
));
144 tail
->rta_len
= (void *) NLMSG_TAIL(n
) - (void *) tail
;
148 static int etf_print_opt(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*opt
)
150 struct rtattr
*tb
[TCA_ETF_MAX
+1];
151 struct tc_etf_qopt
*qopt
;
156 parse_rtattr_nested(tb
, TCA_ETF_MAX
, opt
);
158 if (tb
[TCA_ETF_PARMS
] == NULL
)
161 qopt
= RTA_DATA(tb
[TCA_ETF_PARMS
]);
162 if (RTA_PAYLOAD(tb
[TCA_ETF_PARMS
]) < sizeof(*qopt
))
165 print_string(PRINT_ANY
, "clockid", "clockid %s ",
166 get_clock_name(qopt
->clockid
));
168 print_uint(PRINT_ANY
, "delta", "delta %d ", qopt
->delta
);
169 print_string(PRINT_ANY
, "offload", "offload %s ",
170 (qopt
->flags
& TC_ETF_OFFLOAD_ON
) ? "on" : "off");
171 print_string(PRINT_ANY
, "deadline_mode", "deadline_mode %s",
172 (qopt
->flags
& TC_ETF_DEADLINE_MODE_ON
) ? "on" : "off");
177 struct qdisc_util etf_qdisc_util
= {
179 .parse_qopt
= etf_parse_opt
,
180 .print_qopt
= etf_print_opt
,