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)
42 "Usage: ... etf delta NANOS clockid CLOCKID [offload] [deadline_mode]\n"
43 "CLOCKID must be a valid SYS-V id (i.e. CLOCK_TAI)\n");
46 static void explain1(const char *arg
, const char *val
)
48 fprintf(stderr
, "etf: illegal value for \"%s\": \"%s\"\n", arg
, val
);
51 static void explain_clockid(const char *val
)
54 "etf: illegal value for \"clockid\": \"%s\".\n"
55 "It must be a valid SYS-V id (i.e. CLOCK_TAI)\n",
59 static int get_clockid(__s32
*val
, const char *arg
)
61 const struct static_clockid
*c
;
63 /* Drop the CLOCK_ prefix if that is being used. */
64 if (strcasestr(arg
, "CLOCK_") != NULL
)
65 arg
+= sizeof("CLOCK_") - 1;
67 for (c
= clockids_sysv
; c
->name
; c
++) {
68 if (strcasecmp(c
->name
, arg
) == 0) {
78 static const char* get_clock_name(clockid_t clockid
)
80 const struct static_clockid
*c
;
82 for (c
= clockids_sysv
; c
->name
; c
++) {
83 if (clockid
== c
->clockid
)
90 static int etf_parse_opt(struct qdisc_util
*qu
, int argc
,
91 char **argv
, struct nlmsghdr
*n
, const char *dev
)
93 struct tc_etf_qopt opt
= {
94 .clockid
= CLOCKID_INVALID
,
99 if (matches(*argv
, "offload") == 0) {
100 if (opt
.flags
& TC_ETF_OFFLOAD_ON
) {
101 fprintf(stderr
, "etf: duplicate \"offload\" specification\n");
105 opt
.flags
|= TC_ETF_OFFLOAD_ON
;
106 } else if (matches(*argv
, "deadline_mode") == 0) {
107 if (opt
.flags
& TC_ETF_DEADLINE_MODE_ON
) {
108 fprintf(stderr
, "etf: duplicate \"deadline_mode\" specification\n");
112 opt
.flags
|= TC_ETF_DEADLINE_MODE_ON
;
113 } else if (matches(*argv
, "delta") == 0) {
116 fprintf(stderr
, "etf: duplicate \"delta\" specification\n");
119 if (get_s32(&opt
.delta
, *argv
, 0)) {
120 explain1("delta", *argv
);
123 } else if (matches(*argv
, "clockid") == 0) {
125 if (opt
.clockid
!= CLOCKID_INVALID
) {
126 fprintf(stderr
, "etf: duplicate \"clockid\" specification\n");
129 if (get_clockid(&opt
.clockid
, *argv
)) {
130 explain_clockid(*argv
);
133 } else if (strcmp(*argv
, "skip_sock_check") == 0) {
134 if (opt
.flags
& TC_ETF_SKIP_SOCK_CHECK
) {
135 fprintf(stderr
, "etf: duplicate \"skip_sock_check\" specification\n");
139 opt
.flags
|= TC_ETF_SKIP_SOCK_CHECK
;
140 } else if (strcmp(*argv
, "help") == 0) {
144 fprintf(stderr
, "etf: unknown parameter \"%s\"\n", *argv
);
151 tail
= NLMSG_TAIL(n
);
152 addattr_l(n
, 1024, TCA_OPTIONS
, NULL
, 0);
153 addattr_l(n
, 2024, TCA_ETF_PARMS
, &opt
, sizeof(opt
));
154 tail
->rta_len
= (void *) NLMSG_TAIL(n
) - (void *) tail
;
158 static int etf_print_opt(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*opt
)
160 struct rtattr
*tb
[TCA_ETF_MAX
+1];
161 struct tc_etf_qopt
*qopt
;
166 parse_rtattr_nested(tb
, TCA_ETF_MAX
, opt
);
168 if (tb
[TCA_ETF_PARMS
] == NULL
)
171 qopt
= RTA_DATA(tb
[TCA_ETF_PARMS
]);
172 if (RTA_PAYLOAD(tb
[TCA_ETF_PARMS
]) < sizeof(*qopt
))
175 print_string(PRINT_ANY
, "clockid", "clockid %s ",
176 get_clock_name(qopt
->clockid
));
178 print_uint(PRINT_ANY
, "delta", "delta %d ", qopt
->delta
);
179 print_string(PRINT_ANY
, "offload", "offload %s ",
180 (qopt
->flags
& TC_ETF_OFFLOAD_ON
) ? "on" : "off");
181 print_string(PRINT_ANY
, "deadline_mode", "deadline_mode %s ",
182 (qopt
->flags
& TC_ETF_DEADLINE_MODE_ON
) ? "on" : "off");
183 print_string(PRINT_ANY
, "skip_sock_check", "skip_sock_check %s",
184 (qopt
->flags
& TC_ETF_SKIP_SOCK_CHECK
) ? "on" : "off");
189 struct qdisc_util etf_qdisc_util
= {
191 .parse_qopt
= etf_parse_opt
,
192 .print_qopt
= etf_print_opt
,