Message ID | 1563231104-19912-2-git-send-email-vedang.patel@intel.com |
---|---|
State | Changes Requested |
Delegated to: | David Ahern |
Headers | show |
Series | [iproute2,net-next,v3,1/5] etf: Add skip_sock_check | expand |
On Mon, 15 Jul 2019 15:51:41 -0700 Vedang Patel <vedang.patel@intel.com> wrote: > @@ -405,6 +420,7 @@ 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; > + __u32 taprio_flags = 0; > int i; > > if (opt == NULL) > @@ -442,6 +458,11 @@ static int taprio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) > > print_string(PRINT_ANY, "clockid", "clockid %s", get_clock_name(clockid)); > > + if (tb[TCA_TAPRIO_ATTR_FLAGS]) { > + taprio_flags = rta_getattr_u32(tb[TCA_TAPRIO_ATTR_FLAGS]); > + print_uint(PRINT_ANY, "flags", " flags %x", taprio_flags); > + } > + Overall this looks fine, but three small comments: 1. It is better not to do unnecessary variable initialization 2. It is better to move variables into the basic block where they are used. 3. Use the print_0xhex() instead of print_uint() for hex values. The difference is that in the JSON output, print_uint would be decimal but the print_0xhex is always hex. And use "flags %#x" so that it is clear you are printing flags in hex.
On Mon, 15 Jul 2019 16:37:43 -0700, Stephen Hemminger wrote: > On Mon, 15 Jul 2019 15:51:41 -0700 > Vedang Patel <vedang.patel@intel.com> wrote: > > @@ -442,6 +458,11 @@ static int taprio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) > > > > print_string(PRINT_ANY, "clockid", "clockid %s", get_clock_name(clockid)); > > > > + if (tb[TCA_TAPRIO_ATTR_FLAGS]) { > > + taprio_flags = rta_getattr_u32(tb[TCA_TAPRIO_ATTR_FLAGS]); > > + print_uint(PRINT_ANY, "flags", " flags %x", taprio_flags); > > + } >[...] > 3. Use the print_0xhex() instead of print_uint() for hex values. The difference > is that in the JSON output, print_uint would be decimal but the print_0xhex > is always hex. And use "flags %#x" so that it is clear you are printing flags in hex. In my humble personal experience scripting tests using iproute2 and bpftool with Python I found printing the "hex string" instead of just outputing the integer value counter productive :( Even tho it looks better to the eye, JSON is primarily for machine processing and hex strings have to be manually converted.
On Mon, 15 Jul 2019 17:15:15 -0700 Jakub Kicinski <jakub.kicinski@netronome.com> wrote: > On Mon, 15 Jul 2019 16:37:43 -0700, Stephen Hemminger wrote: > > On Mon, 15 Jul 2019 15:51:41 -0700 > > Vedang Patel <vedang.patel@intel.com> wrote: > > > @@ -442,6 +458,11 @@ static int taprio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) > > > > > > print_string(PRINT_ANY, "clockid", "clockid %s", get_clock_name(clockid)); > > > > > > + if (tb[TCA_TAPRIO_ATTR_FLAGS]) { > > > + taprio_flags = rta_getattr_u32(tb[TCA_TAPRIO_ATTR_FLAGS]); > > > + print_uint(PRINT_ANY, "flags", " flags %x", taprio_flags); > > > + } > >[...] > > 3. Use the print_0xhex() instead of print_uint() for hex values. The difference > > is that in the JSON output, print_uint would be decimal but the print_0xhex > > is always hex. And use "flags %#x" so that it is clear you are printing flags in hex. > > In my humble personal experience scripting tests using iproute2 and > bpftool with Python I found printing the "hex string" instead of just > outputing the integer value counter productive :( Even tho it looks > better to the eye, JSON is primarily for machine processing and hex > strings have to be manually converted. If it is hex on normal output, it should be hex on JSON output. And what ever the normal output format is has to be accepted on command line as input.
On Mon, 15 Jul 2019 17:24:22 -0700, Stephen Hemminger wrote: > On Mon, 15 Jul 2019 17:15:15 -0700 > Jakub Kicinski <jakub.kicinski@netronome.com> wrote: > > On Mon, 15 Jul 2019 16:37:43 -0700, Stephen Hemminger wrote: > > > On Mon, 15 Jul 2019 15:51:41 -0700 > > > Vedang Patel <vedang.patel@intel.com> wrote: > > > > @@ -442,6 +458,11 @@ static int taprio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) > > > > > > > > print_string(PRINT_ANY, "clockid", "clockid %s", get_clock_name(clockid)); > > > > > > > > + if (tb[TCA_TAPRIO_ATTR_FLAGS]) { > > > > + taprio_flags = rta_getattr_u32(tb[TCA_TAPRIO_ATTR_FLAGS]); > > > > + print_uint(PRINT_ANY, "flags", " flags %x", taprio_flags); > > > > + } > > >[...] > > > 3. Use the print_0xhex() instead of print_uint() for hex values. The difference > > > is that in the JSON output, print_uint would be decimal but the print_0xhex > > > is always hex. And use "flags %#x" so that it is clear you are printing flags in hex. > > > > In my humble personal experience scripting tests using iproute2 and > > bpftool with Python I found printing the "hex string" instead of just > > outputing the integer value counter productive :( Even tho it looks > > better to the eye, JSON is primarily for machine processing and hex > > strings have to be manually converted. > > If it is hex on normal output, it should be hex on JSON output. > And what ever the normal output format is has to be accepted on command line as input. Ah, I forgot the output == input principle in iproute2! In any case if there was ever a vote whether to limit this principle to non-JSON output, and make machines' life easier, I'd vote 'yes' :)
Hi Stephen, > On Jul 15, 2019, at 4:37 PM, Stephen Hemminger <stephen@networkplumber.org> wrote: > > On Mon, 15 Jul 2019 15:51:41 -0700 > Vedang Patel <vedang.patel@intel.com> wrote: > >> @@ -405,6 +420,7 @@ 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; >> + __u32 taprio_flags = 0; >> int i; >> >> if (opt == NULL) >> @@ -442,6 +458,11 @@ static int taprio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) >> >> print_string(PRINT_ANY, "clockid", "clockid %s", get_clock_name(clockid)); >> >> + if (tb[TCA_TAPRIO_ATTR_FLAGS]) { >> + taprio_flags = rta_getattr_u32(tb[TCA_TAPRIO_ATTR_FLAGS]); >> + print_uint(PRINT_ANY, "flags", " flags %x", taprio_flags); >> + } >> + > > Overall this looks fine, but three small comments: > 1. It is better not to do unnecessary variable initialization > 2. It is better to move variables into the basic block where they are used. > 3. Use the print_0xhex() instead of print_uint() for hex values. The difference > is that in the JSON output, print_uint would be decimal but the print_0xhex > is always hex. And use "flags %#x" so that it is clear you are printing flags in hex. Thanks for they inputs. I will incorporate your comments and send the updated series in a couple of days. -Vedang > >
diff --git a/tc/q_taprio.c b/tc/q_taprio.c index 62c8c591da99..930ecb9d1eef 100644 --- a/tc/q_taprio.c +++ b/tc/q_taprio.c @@ -154,6 +154,7 @@ static struct sched_entry *create_entry(uint32_t gatemask, uint32_t interval, ui static int taprio_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev) { + __u32 taprio_flags = UINT32_MAX; __s32 clockid = CLOCKID_INVALID; struct tc_mqprio_qopt opt = { }; __s64 cycle_time_extension = 0; @@ -281,6 +282,17 @@ static int taprio_parse_opt(struct qdisc_util *qu, int argc, explain_clockid(*argv); return -1; } + } else if (strcmp(*argv, "flags") == 0) { + NEXT_ARG(); + if (taprio_flags != UINT32_MAX) { + fprintf(stderr, "taprio: duplicate \"flags\" specification\n"); + return -1; + } + if (get_u32(&taprio_flags, *argv, 0)) { + PREV_ARG(); + return -1; + } + } else if (strcmp(*argv, "help") == 0) { explain(); return -1; @@ -297,6 +309,9 @@ static int taprio_parse_opt(struct qdisc_util *qu, int argc, if (clockid != CLOCKID_INVALID) addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_CLOCKID, &clockid, sizeof(clockid)); + if (taprio_flags != UINT32_MAX) + addattr_l(n, 1024, TCA_TAPRIO_ATTR_FLAGS, &taprio_flags, sizeof(taprio_flags)); + if (opt.num_tc > 0) addattr_l(n, 1024, TCA_TAPRIO_ATTR_PRIOMAP, &opt, sizeof(opt)); @@ -405,6 +420,7 @@ 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; + __u32 taprio_flags = 0; int i; if (opt == NULL) @@ -442,6 +458,11 @@ static int taprio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) print_string(PRINT_ANY, "clockid", "clockid %s", get_clock_name(clockid)); + if (tb[TCA_TAPRIO_ATTR_FLAGS]) { + taprio_flags = rta_getattr_u32(tb[TCA_TAPRIO_ATTR_FLAGS]); + print_uint(PRINT_ANY, "flags", " flags %x", taprio_flags); + } + print_schedule(f, tb); if (tb[TCA_TAPRIO_ATTR_ADMIN_SCHED]) {