Skip to contentSkip to conversation

tc: add support for JSON output in some qdiscs

PATCH Applied Leslie Monis 2 participants 14 messages Dec 25, 2019 – Dec 29, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover tc: add support for JSON output in some qdiscs

Several qdiscs do not yet support the JSON output format. This patch series adds the missing compatibility to 9 classless qdiscs. Some of the patches also improve the oneline output of the qdiscs. The last patch in the series fixes a missing statistic in the JSON output of fq_codel.

Leslie Monis (10):
tc: cbs: add support for JSON output
tc: choke: add support for JSON output
tc: codel: add support for JSON output
tc: fq: add support for JSON output
tc: hhf: add support for JSON output
tc: pie: add support for JSON output
tc: sfb: add support for JSON output
tc: sfq: add support for JSON output
tc: tbf: add support for JSON output
tc: fq_codel: fix missing statistic in JSON output

 man/man8/tc-fq.8  |  14 +++---
 man/man8/tc-pie.8 |  16 +++----
 tc/q_cbs.c        |  10 ++---
 tc/q_choke.c      |  26 +++++++----
 tc/q_codel.c      |  45 +++++++++++++------
 tc/q_fq.c         | 108 ++++++++++++++++++++++++++++++++--------------
 tc/q_fq_codel.c   |   4 +-
 tc/q_hhf.c        |  33 +++++++++-----
 tc/q_pie.c        |  47 ++++++++++++--------
 tc/q_sfb.c        |  67 ++++++++++++++++++----------
 tc/q_sfq.c        |  66 +++++++++++++++++-----------
 tc/q_tbf.c        |  68 ++++++++++++++++++++---------
 12 files changed, 335 insertions(+), 169 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/10 tc: cbs: add support for JSON output

Enable proper JSON output for the CBS Qdisc.

---
 tc/q_cbs.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tc/q_cbs.c +5 -5
index 9515a1f7..13bb08e9 100644
@@ -125,11 +125,11 @@ static int cbs_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 	if (RTA_PAYLOAD(tb[TCA_CBS_PARMS])  < sizeof(*qopt))
 		return -1;
 
-	fprintf(f, "hicredit %d ", qopt->hicredit);
-	fprintf(f, "locredit %d ", qopt->locredit);
-	fprintf(f, "sendslope %d ", qopt->sendslope);
-	fprintf(f, "idleslope %d ", qopt->idleslope);
-	fprintf(f, "offload %d ", qopt->offload);
+	print_int(PRINT_ANY, "hicredit", "hicredit %d ", qopt->hicredit);
+	print_int(PRINT_ANY, "locredit", "locredit %d ", qopt->locredit);
+	print_int(PRINT_ANY, "sendslope", "sendslope %d ", qopt->sendslope);
+	print_int(PRINT_ANY, "idleslope", "idleslope %d ", qopt->idleslope);
+	print_int(PRINT_ANY, "offload", "offload %d ", qopt->offload);
 
 	return 0;
 }
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/10 tc: choke: add support for JSON output

In reply to Leslie Monis

Enable proper JSON output for the choke Qdisc.
Also, use the long double format specifier to print the value of "probability".

---
 tc/q_choke.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
tc/q_choke.c +18 -8
index 648d9ad7..570c3599 100644
@@ -186,18 +186,23 @@ static int choke_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 	    RTA_PAYLOAD(tb[TCA_CHOKE_MAX_P]) >= sizeof(__u32))
 		max_P = rta_getattr_u32(tb[TCA_CHOKE_MAX_P]);
 
-	fprintf(f, "limit %up min %up max %up ",
-		qopt->limit, qopt->qth_min, qopt->qth_max);
+	print_uint(PRINT_ANY, "limit", "limit %up ", qopt->limit);
+	print_uint(PRINT_ANY, "min", "min %up ", qopt->qth_min);
+	print_uint(PRINT_ANY, "max", "max %up ", qopt->qth_max);
 
 	tc_red_print_flags(qopt->flags);
 
 	if (show_details) {
-		fprintf(f, "ewma %u ", qopt->Wlog);
+		print_uint(PRINT_ANY, "ewma", "ewma %u ", qopt->Wlog);
+
 		if (max_P)
-			fprintf(f, "probability %g ", max_P / pow(2, 32));
+			print_float(PRINT_ANY, "probability",
+				    "probability %lg ", max_P / pow(2, 32));
 		else
-			fprintf(f, "Plog %u ", qopt->Plog);
-		fprintf(f, "Scell_log %u", qopt->Scell_log);
+			print_uint(PRINT_ANY, "Plog", "Plog %u ", qopt->Plog);
+
+		print_uint(PRINT_ANY, "Scell_log", "Scell_log %u",
+			   qopt->Scell_log);
 	}
 	return 0;
 }
@@ -214,8 +219,13 @@ static int choke_print_xstats(struct qdisc_util *qu, FILE *f,
 		return -1;
 
 	st = RTA_DATA(xstats);
-	fprintf(f, "  marked %u early %u pdrop %u other %u matched %u",
-		st->marked, st->early, st->pdrop, st->other, st->matched);
+
+	print_uint(PRINT_ANY, "marked", "  marked %u", st->marked);
+	print_uint(PRINT_ANY, "early", " early %u", st->early);
+	print_uint(PRINT_ANY, "pdrop", " pdrop %u", st->pdrop);
+	print_uint(PRINT_ANY, "other", " other %u", st->other);
+	print_uint(PRINT_ANY, "matched", " matched %u", st->matched);
+
 	return 0;
 
 }
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/10 tc: codel: add support for JSON output

In reply to Leslie Monis

Enable proper JSON output for the CoDel Qdisc.

---
 tc/q_codel.c | 45 ++++++++++++++++++++++++++++++++-------------
 1 file changed, 32 insertions(+), 13 deletions(-)
tc/q_codel.c +32 -13
index 849cc040..c72a5779 100644
@@ -144,28 +144,34 @@ static int codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 	if (tb[TCA_CODEL_LIMIT] &&
 	    RTA_PAYLOAD(tb[TCA_CODEL_LIMIT]) >= sizeof(__u32)) {
 		limit = rta_getattr_u32(tb[TCA_CODEL_LIMIT]);
-		fprintf(f, "limit %up ", limit);
+		print_uint(PRINT_ANY, "limit", "limit %up ", limit);
 	}
 	if (tb[TCA_CODEL_TARGET] &&
 	    RTA_PAYLOAD(tb[TCA_CODEL_TARGET]) >= sizeof(__u32)) {
 		target = rta_getattr_u32(tb[TCA_CODEL_TARGET]);
-		fprintf(f, "target %s ", sprint_time(target, b1));
+		print_uint(PRINT_JSON, "target", NULL, target);
+		print_string(PRINT_FP, NULL, "target %s ",
+			     sprint_time(target, b1));
 	}
 	if (tb[TCA_CODEL_CE_THRESHOLD] &&
 	    RTA_PAYLOAD(tb[TCA_CODEL_CE_THRESHOLD]) >= sizeof(__u32)) {
 		ce_threshold = rta_getattr_u32(tb[TCA_CODEL_CE_THRESHOLD]);
-		fprintf(f, "ce_threshold %s ", sprint_time(ce_threshold, b1));
+		print_uint(PRINT_JSON, "ce_threshold", NULL, ce_threshold);
+		print_string(PRINT_FP, NULL, "ce_threshold %s ",
+			     sprint_time(ce_threshold, b1));
 	}
 	if (tb[TCA_CODEL_INTERVAL] &&
 	    RTA_PAYLOAD(tb[TCA_CODEL_INTERVAL]) >= sizeof(__u32)) {
 		interval = rta_getattr_u32(tb[TCA_CODEL_INTERVAL]);
-		fprintf(f, "interval %s ", sprint_time(interval, b1));
+		print_uint(PRINT_JSON, "interval", NULL, interval);
+		print_string(PRINT_FP, NULL, "interval %s ",
+			     sprint_time(interval, b1));
 	}
 	if (tb[TCA_CODEL_ECN] &&
 	    RTA_PAYLOAD(tb[TCA_CODEL_ECN]) >= sizeof(__u32)) {
 		ecn = rta_getattr_u32(tb[TCA_CODEL_ECN]);
 		if (ecn)
-			fprintf(f, "ecn ");
+			print_bool(PRINT_ANY, "ecn", "ecn ", true);
 	}
 
 	return 0;
@@ -187,18 +193,31 @@ static int codel_print_xstats(struct qdisc_util *qu, FILE *f,
 		st = &_st;
 	}
 
-	fprintf(f, "  count %u lastcount %u ldelay %s",
-		st->count, st->lastcount, sprint_time(st->ldelay, b1));
+	print_uint(PRINT_ANY, "count", "  count %u", st->count);
+	print_uint(PRINT_ANY, "lastcount", " lastcount %u", st->lastcount);
+	print_uint(PRINT_JSON, "ldelay", NULL, st->ldelay);
+	print_string(PRINT_FP, NULL, " ldelay %s", sprint_time(st->ldelay, b1));
+
 	if (st->dropping)
-		fprintf(f, " dropping");
+		print_bool(PRINT_ANY, "dropping", " dropping", true);
+
+	print_int(PRINT_JSON, "drop_next", NULL, st->drop_next);
 	if (st->drop_next < 0)
-		fprintf(f, " drop_next -%s", sprint_time(-st->drop_next, b1));
+		print_string(PRINT_FP, NULL, " drop_next -%s",
+			     sprint_time(-st->drop_next, b1));
 	else
-		fprintf(f, " drop_next %s", sprint_time(st->drop_next, b1));
-	fprintf(f, "\n  maxpacket %u ecn_mark %u drop_overlimit %u",
-		st->maxpacket, st->ecn_mark, st->drop_overlimit);
+		print_string(PRINT_FP, NULL, " drop_next %s",
+			     sprint_time(st->drop_next, b1));
+
+	print_nl();
+	print_uint(PRINT_ANY, "maxpacket", "  maxpacket %u", st->maxpacket);
+	print_uint(PRINT_ANY, "ecn_mark", " ecn_mark %u", st->ecn_mark);
+	print_uint(PRINT_ANY, "drop_overlimit", " drop_overlimit %u",
+		   st->drop_overlimit);
+
 	if (st->ce_mark)
-		fprintf(f, " ce_mark %u", st->ce_mark);
+		print_uint(PRINT_ANY, "ce_mark", " ce_mark %u", st->ce_mark);
+
 	return 0;
 
 }
Signature · 1 line
2.17.1
#4 lore raw

PATCH 4/10 tc: fq: add support for JSON output

In reply to Leslie Monis

Enable proper JSON output for the FQ Qdisc.
Use the "KEY VALUE" format for oneline output of statistics instead of "VALUE KEY", and remove unnecessary commas from the output. Use sprint_size() to print size values in fq_print_opt(). Use sprint_time64() to print time values in fq_print_xstats(). Also, update the man page to reflect the changes in the output format.

---
 man/man8/tc-fq.8 |  14 +++---
 tc/q_fq.c        | 108 +++++++++++++++++++++++++++++++++--------------
 2 files changed, 83 insertions(+), 39 deletions(-)
man/man8/tc-fq.8 +7 -7
index 1febe62b..27385aae 100644
@@ -90,15 +90,15 @@ Experienced. This is useful for DCTCP-style congestion control algorithms that
 require marking at very shallow queueing thresholds.
 
 .SH EXAMPLES
-#tc qdisc add dev eth0 root est 1sec 4sec fq ce_threshold 4ms
+#tc qdisc add dev eth0 root fq ce_threshold 4ms
 .br
-#tc -s -d qdisc sh dev eth0
+#tc -s -d qdisc show dev eth0
 .br
-qdisc fq 800e: root refcnt 9 limit 10000p flow_limit 1000p buckets 1024 orphan_mask 1023 quantum 3028 initial_quantum 15140 low_rate_threshold 550Kbit refill_delay 40.0ms ce_threshold 4.0ms
- Sent 533368436185 bytes 352296695 pkt (dropped 0, overlimits 0 requeues 1339864)
- rate 39220Mbit 3238202pps backlog 12417828b 358p requeues 1339864
-  1052 flows (852 inactive, 0 throttled)
-  112 gc, 0 highprio, 212 throttled, 21501 ns latency, 470241 ce_mark
+qdisc fq 8001: dev eth0 root refcnt 2 limit 10000p flow_limit 100p buckets 1024 orphan_mask 1023 quantum 3028b initial_quantum 15140b low_rate_threshold 550Kbit refill_delay 40.0ms ce_threshold 4.0ms
+ Sent 72149092 bytes 48062 pkt (dropped 2176, overlimits 0 requeues 0)
+ backlog 1937920b 1280p requeues 0
+  flows 34 (inactive 17 throttled 0)
+  gc 0 highprio 0 throttled 0 ce_mark 47622 flows_plimit 2176
 .br
 .SH SEE ALSO
 .BR tc (8),
tc/q_fq.c +76 -32

185 lines not on this page · raw message

Signature · 1 line
2.17.1
#5 lore raw

PATCH 5/10 tc: hhf: add support for JSON output

In reply to Leslie Monis

Enable proper JSON output for the HHF Qdisc.
Also, use sprint_size() to print size values.

---
 tc/q_hhf.c | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)
tc/q_hhf.c +23 -10
index 5ee6642f..f8888011 100644
@@ -138,37 +138,46 @@ static int hhf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 	if (tb[TCA_HHF_BACKLOG_LIMIT] &&
 	    RTA_PAYLOAD(tb[TCA_HHF_BACKLOG_LIMIT]) >= sizeof(__u32)) {
 		limit = rta_getattr_u32(tb[TCA_HHF_BACKLOG_LIMIT]);
-		fprintf(f, "limit %up ", limit);
+		print_uint(PRINT_ANY, "limit", "limit %up ", limit);
 	}
 	if (tb[TCA_HHF_QUANTUM] &&
 	    RTA_PAYLOAD(tb[TCA_HHF_QUANTUM]) >= sizeof(__u32)) {
 		quantum = rta_getattr_u32(tb[TCA_HHF_QUANTUM]);
-		fprintf(f, "quantum %u ", quantum);
+		print_uint(PRINT_JSON, "quantum", NULL, quantum);
+		print_string(PRINT_FP, NULL, "quantum %s ",
+			     sprint_size(quantum, b1));
 	}
 	if (tb[TCA_HHF_HH_FLOWS_LIMIT] &&
 	    RTA_PAYLOAD(tb[TCA_HHF_HH_FLOWS_LIMIT]) >= sizeof(__u32)) {
 		hh_limit = rta_getattr_u32(tb[TCA_HHF_HH_FLOWS_LIMIT]);
-		fprintf(f, "hh_limit %u ", hh_limit);
+		print_uint(PRINT_ANY, "hh_limit", "hh_limit %u ", hh_limit);
 	}
 	if (tb[TCA_HHF_RESET_TIMEOUT] &&
 	    RTA_PAYLOAD(tb[TCA_HHF_RESET_TIMEOUT]) >= sizeof(__u32)) {
 		reset_timeout = rta_getattr_u32(tb[TCA_HHF_RESET_TIMEOUT]);
-		fprintf(f, "reset_timeout %s ", sprint_time(reset_timeout, b1));
+		print_uint(PRINT_JSON, "reset_timeout", NULL, reset_timeout);
+		print_string(PRINT_FP, NULL, "reset_timeout %s ",
+			     sprint_time(reset_timeout, b1));
 	}
 	if (tb[TCA_HHF_ADMIT_BYTES] &&
 	    RTA_PAYLOAD(tb[TCA_HHF_ADMIT_BYTES]) >= sizeof(__u32)) {
 		admit_bytes = rta_getattr_u32(tb[TCA_HHF_ADMIT_BYTES]);
-		fprintf(f, "admit_bytes %u ", admit_bytes);
+		print_uint(PRINT_JSON, "admit_bytes", NULL, admit_bytes);
+		print_string(PRINT_FP, NULL, "admit_bytes %s ",
+			     sprint_size(admit_bytes, b1));
 	}
 	if (tb[TCA_HHF_EVICT_TIMEOUT] &&
 	    RTA_PAYLOAD(tb[TCA_HHF_EVICT_TIMEOUT]) >= sizeof(__u32)) {
 		evict_timeout = rta_getattr_u32(tb[TCA_HHF_EVICT_TIMEOUT]);
-		fprintf(f, "evict_timeout %s ", sprint_time(evict_timeout, b1));
+		print_uint(PRINT_JSON, "evict_timeout", NULL, evict_timeout);
+		print_string(PRINT_FP, NULL, "evict_timeout %s ",
+			     sprint_time(evict_timeout, b1));
 	}
 	if (tb[TCA_HHF_NON_HH_WEIGHT] &&
 	    RTA_PAYLOAD(tb[TCA_HHF_NON_HH_WEIGHT]) >= sizeof(__u32)) {
 		non_hh_weight = rta_getattr_u32(tb[TCA_HHF_NON_HH_WEIGHT]);
-		fprintf(f, "non_hh_weight %u ", non_hh_weight);
+		print_uint(PRINT_ANY, "non_hh_weight", "non_hh_weight %u ",
+			   non_hh_weight);
 	}
 	return 0;
 }
@@ -186,9 +195,13 @@ static int hhf_print_xstats(struct qdisc_util *qu, FILE *f,
 
 	st = RTA_DATA(xstats);
 
-	fprintf(f, "  drop_overlimit %u hh_overlimit %u tot_hh %u cur_hh %u",
-		st->drop_overlimit, st->hh_overlimit,
-		st->hh_tot_count, st->hh_cur_count);
+	print_uint(PRINT_ANY, "drop_overlimit", "  drop_overlimit %u",
+		   st->drop_overlimit);
+	print_uint(PRINT_ANY, "hh_overlimit", " hh_overlimit %u",
+		   st->hh_overlimit);
+	print_uint(PRINT_ANY, "tot_hh", " tot_hh %u", st->hh_tot_count);
+	print_uint(PRINT_ANY, "cur_hh", " cur_hh %u", st->hh_cur_count);
+
 	return 0;
 }
 
Signature · 1 line
2.17.1
#6 lore raw

PATCH 6/10 tc: pie: add support for JSON output

In reply to Leslie Monis

Enable proper JSON output for the PIE Qdisc.
Use sprint_time() to print the value of tc_pie_xstats->delay. Use the long double format specifier to print tc_pie_xstats->prob. Also, fix the indentation in the oneline output of statistics and update the man page to reflect this change.

---
 man/man8/tc-pie.8 | 16 ++++++++--------
 tc/q_pie.c        | 47 ++++++++++++++++++++++++++++++-----------------
 2 files changed, 38 insertions(+), 25 deletions(-)
man/man8/tc-pie.8 +8 -8
index bdcfba51..0db97d13 100644
@@ -107,32 +107,32 @@ is turned off.
    qdisc pie 8036: dev eth0 root refcnt 2 limit 1000p target 15.0ms tupdate 16.0ms alpha 2 beta 20
     Sent 31216108 bytes 20800 pkt (dropped 80, overlimits 0 requeues 0)
     backlog 16654b 11p requeues 0
-   prob 0.006161 delay 15666us
-   pkts_in 20811 overlimit 0 dropped 80 maxq 50 ecn_mark 0
+     prob 0.006161 delay 15666us
+     pkts_in 20811 overlimit 0 dropped 80 maxq 50 ecn_mark 0
 
  # tc qdisc add dev eth0 root pie dq_rate_estimator
  # tc -s qdisc show
    qdisc pie 8036: dev eth0 root refcnt 2 limit 1000p target 15.0ms tupdate 16.0ms alpha 2 beta 20
     Sent 63947420 bytes 42414 pkt (dropped 41, overlimits 0 requeues 0)
     backlog 271006b 179p requeues 0
-   prob 0.000092 delay 22200us avg_dq_rate 12145996
-   pkts_in 41 overlimit 343 dropped 0 maxq 50 ecn_mark 0
+     prob 0.000092 delay 22200us avg_dq_rate 12145996
+     pkts_in 41 overlimit 343 dropped 0 maxq 50 ecn_mark 0
 
  # tc qdisc add dev eth0 root pie limit 100 target 20ms tupdate 30ms ecn
  # tc -s qdisc show
    qdisc pie 8036: dev eth0 root refcnt 2 limit 100p target 20.0ms tupdate 32.0ms alpha 2 beta 20 ecn
     Sent 6591724 bytes 4442 pkt (dropped 27, overlimits 0 requeues 0)
     backlog 18168b 12p requeues 0
-   prob 0.008845 delay 11348us
-   pkts_in 4454 overlimit 0 dropped 27 maxq 65 ecn_mark 0
+     prob 0.008845 delay 11348us
+     pkts_in 4454 overlimit 0 dropped 27 maxq 65 ecn_mark 0
 
  # tc qdisc add dev eth0 root pie limit 100 target 50ms tupdate 30ms bytemode
  # tc -s qdisc show
    qdisc pie 8036: dev eth0 root refcnt 2 limit 100p target 50.0ms tupdate 32.0ms alpha 2 beta 20 bytemode
     Sent 1616274 bytes 1137 pkt (dropped 0, overlimits 0 requeues 0)
     backlog 13626b 9p requeues 0
-   prob 0.000000 delay 0us
-   pkts_in 1146 overlimit 0 dropped 0 maxq 23 ecn_mark 0
+     prob 0.000000 delay 0us
+     pkts_in 1146 overlimit 0 dropped 0 maxq 23 ecn_mark 0
 
 .SH SEE ALSO
 .BR tc (8),
tc/q_pie.c +30 -17

101 lines not on this page · raw message

Signature · 1 line
2.17.1
#7 lore raw

PATCH 7/10 tc: sfb: add support for JSON output

In reply to Leslie Monis

Enable proper JSON output for the SFB Qdisc.
Make the output for options "rehash" and "db" explicit. Use the long double format specifier to print probability values. Use sprint_time() to print time values.
Also, fix the indentation in sfb_print_opt().

---
 tc/q_sfb.c | 67 ++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 45 insertions(+), 22 deletions(-)
tc/q_sfb.c +45 -22
index 7f48c6e0..8af55d98 100644
@@ -143,6 +143,8 @@ static int sfb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 	struct rtattr *tb[__TCA_SFB_MAX];
 	struct tc_sfb_qopt *qopt;
 
+	SPRINT_BUF(b1);
+
 	if (opt == NULL)
 		return 0;
 
@@ -153,14 +155,27 @@ static int sfb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 	if (RTA_PAYLOAD(tb[TCA_SFB_PARMS]) < sizeof(*qopt))
 		return -1;
 
-	fprintf(f,
-		"limit %d max %d target %d\n"
-		"  increment %.5f decrement %.5f penalty rate %d burst %d (%ums %ums)",
-		qopt->limit, qopt->max, qopt->bin_size,
-		(double)qopt->increment / SFB_MAX_PROB,
-		(double)qopt->decrement / SFB_MAX_PROB,
-		qopt->penalty_rate, qopt->penalty_burst,
-		qopt->rehash_interval, qopt->warmup_time);
+	print_uint(PRINT_JSON, "rehash", NULL, qopt->rehash_interval * 1000);
+	print_string(PRINT_FP, NULL, "rehash %s ",
+		     sprint_time(qopt->rehash_interval * 1000, b1));
+
+	print_uint(PRINT_JSON, "db", NULL, qopt->warmup_time * 1000);
+	print_string(PRINT_FP, NULL, "db %s ",
+		     sprint_time(qopt->warmup_time * 1000, b1));
+
+	print_uint(PRINT_ANY, "limit", "limit %up ", qopt->limit);
+	print_uint(PRINT_ANY, "max", "max %up ", qopt->max);
+	print_uint(PRINT_ANY, "target", "target %up ", qopt->bin_size);
+
+	print_float(PRINT_ANY, "increment", "increment %lg ",
+		    (double)qopt->increment / SFB_MAX_PROB);
+	print_float(PRINT_ANY, "decrement", "decrement %lg ",
+		    (double)qopt->decrement / SFB_MAX_PROB);
+
+	print_uint(PRINT_ANY, "penalty_rate", "penalty_rate %upps ",
+		   qopt->penalty_rate);
+	print_uint(PRINT_ANY, "penalty_burst", "penalty_burst %up ",
+		   qopt->penalty_burst);
 
 	return 0;
 }
@@ -168,24 +183,32 @@ static int sfb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 static int sfb_print_xstats(struct qdisc_util *qu, FILE *f,
 			    struct rtattr *xstats)
 {
-    struct tc_sfb_xstats *st;
+	struct tc_sfb_xstats *st;
 
-    if (xstats == NULL)
-	    return 0;
+	if (xstats == NULL)
+		return 0;
+
+	if (RTA_PAYLOAD(xstats) < sizeof(*st))
+		return -1;
 
-    if (RTA_PAYLOAD(xstats) < sizeof(*st))
-	    return -1;
+	st = RTA_DATA(xstats);
 
-    st = RTA_DATA(xstats);
-    fprintf(f,
-	    "  earlydrop %u penaltydrop %u bucketdrop %u queuedrop %u childdrop %u marked %u\n"
-	    "  maxqlen %u maxprob %.5f avgprob %.5f ",
-	    st->earlydrop, st->penaltydrop, st->bucketdrop, st->queuedrop, st->childdrop,
-	    st->marked,
-	    st->maxqlen, (double)st->maxprob / SFB_MAX_PROB,
-		(double)st->avgprob / SFB_MAX_PROB);
+	print_uint(PRINT_ANY, "earlydrop", "  earlydrop %u", st->earlydrop);
+	print_uint(PRINT_ANY, "penaltydrop", " penaltydrop %u",
+		   st->penaltydrop);
+	print_uint(PRINT_ANY, "bucketdrop", " bucketdrop %u", st->bucketdrop);
+	print_uint(PRINT_ANY, "queuedrop", " queuedrop %u", st->queuedrop);
+	print_uint(PRINT_ANY, "childdrop", " childdrop %u", st->childdrop);
+	print_uint(PRINT_ANY, "marked", " marked %u", st->marked);
+	print_nl();
+	print_uint(PRINT_ANY, "maxqlen", "  maxqlen %u", st->maxqlen);
 
-    return 0;
+	print_float(PRINT_ANY, "maxprob", " maxprob %lg",
+		    (double)st->maxprob / SFB_MAX_PROB);
+	print_float(PRINT_ANY, "avgprob", " avgprob %lg",
+		    (double)st->avgprob / SFB_MAX_PROB);
+
+	return 0;
 }
 
 struct qdisc_util sfb_qdisc_util = {
Signature · 1 line
2.17.1
#8 lore raw

PATCH 8/10 tc: sfq: add support for JSON output

In reply to Leslie Monis

Enable proper JSON output for the SFQ Qdisc.
Use the long double format specifier to print the value of "probability".
Also, fix the indentation in the online output of the contents in the tc_sfqred_stats structure.

---
 tc/q_sfq.c | 66 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 42 insertions(+), 24 deletions(-)
tc/q_sfq.c +42 -24
index 4998921d..2b9bbcd2 100644
@@ -217,35 +217,53 @@ static int sfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 	if (RTA_PAYLOAD(opt) >= sizeof(*qopt_ext))
 		qopt_ext = RTA_DATA(opt);
 	qopt = RTA_DATA(opt);
-	fprintf(f, "limit %up ", qopt->limit);
-	fprintf(f, "quantum %s ", sprint_size(qopt->quantum, b1));
+
+	print_uint(PRINT_ANY, "limit", "limit %up ", qopt->limit);
+	print_uint(PRINT_JSON, "quantum", NULL, qopt->quantum);
+	print_string(PRINT_FP, NULL, "quantum %s ",
+		     sprint_size(qopt->quantum, b1));
+
 	if (qopt_ext && qopt_ext->depth)
-		fprintf(f, "depth %u ", qopt_ext->depth);
+		print_uint(PRINT_ANY, "depth", "depth %u ", qopt_ext->depth);
 	if (qopt_ext && qopt_ext->headdrop)
-		fprintf(f, "headdrop ");
+		print_bool(PRINT_ANY, "headdrop", "headdrop ", true);
+	if (show_details)
+		print_uint(PRINT_ANY, "flows", "flows %u ", qopt->flows);
+
+	print_uint(PRINT_ANY, "divisor", "divisor %u ", qopt->divisor);
 
-	if (show_details) {
-		fprintf(f, "flows %u/%u ", qopt->flows, qopt->divisor);
-	}
-	fprintf(f, "divisor %u ", qopt->divisor);
 	if (qopt->perturb_period)
-		fprintf(f, "perturb %dsec ", qopt->perturb_period);
+		print_int(PRINT_ANY, "perturb", "perturb %dsec ",
+			   qopt->perturb_period);
 	if (qopt_ext && qopt_ext->qth_min) {
-		fprintf(f, "\n ewma %u ", qopt_ext->Wlog);
-		fprintf(f, "min %s max %s probability %g ",
-			sprint_size(qopt_ext->qth_min, b2),
-			sprint_size(qopt_ext->qth_max, b3),
-			qopt_ext->max_P / pow(2, 32));
+		print_uint(PRINT_ANY, "ewma", "ewma %u ", qopt_ext->Wlog);
+		print_uint(PRINT_JSON, "min", NULL, qopt_ext->qth_min);
+		print_string(PRINT_FP, NULL, "min %s ",
+			     sprint_size(qopt_ext->qth_min, b2));
+		print_uint(PRINT_JSON, "max", NULL, qopt_ext->qth_max);
+		print_string(PRINT_FP, NULL, "max %s ",
+			     sprint_size(qopt_ext->qth_max, b3));
+		print_float(PRINT_ANY, "probability", "probability %lg ",
+			    qopt_ext->max_P / pow(2, 32));
 		tc_red_print_flags(qopt_ext->flags);
 		if (show_stats) {
-			fprintf(f, "\n prob_mark %u prob_mark_head %u prob_drop %u",
-				qopt_ext->stats.prob_mark,
-				qopt_ext->stats.prob_mark_head,
-				qopt_ext->stats.prob_drop);
-			fprintf(f, "\n forced_mark %u forced_mark_head %u forced_drop %u",
-				qopt_ext->stats.forced_mark,
-				qopt_ext->stats.forced_mark_head,
-				qopt_ext->stats.forced_drop);
+			print_nl();
+			print_uint(PRINT_ANY, "prob_mark", "  prob_mark %u",
+				   qopt_ext->stats.prob_mark);
+			print_uint(PRINT_ANY, "prob_mark_head",
+				   " prob_mark_head %u",
+				   qopt_ext->stats.prob_mark_head);
+			print_uint(PRINT_ANY, "prob_drop", " prob_drop %u",
+				   qopt_ext->stats.prob_drop);
+			print_nl();
+			print_uint(PRINT_ANY, "forced_mark",
+				   "  forced_mark %u",
+				   qopt_ext->stats.forced_mark);
+			print_uint(PRINT_ANY, "forced_mark_head",
+				   " forced_mark_head %u",
+				   qopt_ext->stats.forced_mark_head);
+			print_uint(PRINT_ANY, "forced_drop", " forced_drop %u",
+				   qopt_ext->stats.forced_drop);
 		}
 	}
 	return 0;
@@ -262,8 +280,8 @@ static int sfq_print_xstats(struct qdisc_util *qu, FILE *f,
 		return -1;
 	st = RTA_DATA(xstats);
 
-	fprintf(f, " allot %d ", st->allot);
-	fprintf(f, "\n");
+	print_int(PRINT_ANY, "allot", "  allot %d", st->allot);
+
 	return 0;
 }
 
Signature · 1 line
2.17.1
#9 lore raw

PATCH 9/10 tc: tbf: add support for JSON output

In reply to Leslie Monis

Enable proper JSON output for the TBF Qdisc.
Also, fix the style of the statement that's calculating "latency" in tbf_print_opt().

---
 tc/q_tbf.c | 68 +++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 47 insertions(+), 21 deletions(-)
tc/q_tbf.c +47 -21
index 57a9736c..5135b1d6 100644
@@ -264,7 +264,7 @@ static int tbf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 	struct tc_tbf_qopt *qopt;
 	unsigned int linklayer;
 	double buffer, mtu;
-	double latency;
+	double latency, lat2;
 	__u64 rate64 = 0, prate64 = 0;
 
 	SPRINT_BUF(b1);
@@ -286,53 +286,79 @@ static int tbf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 	if (tb[TCA_TBF_RATE64] &&
 	    RTA_PAYLOAD(tb[TCA_TBF_RATE64]) >= sizeof(rate64))
 		rate64 = rta_getattr_u64(tb[TCA_TBF_RATE64]);
-	fprintf(f, "rate %s ", sprint_rate(rate64, b1));
+	print_u64(PRINT_JSON, "rate", NULL, rate64);
+	print_string(PRINT_FP, NULL, "rate %s ", sprint_rate(rate64, b1));
 	buffer = tc_calc_xmitsize(rate64, qopt->buffer);
 	if (show_details) {
-		fprintf(f, "burst %s/%u mpu %s ", sprint_size(buffer, b1),
-			1<<qopt->rate.cell_log, sprint_size(qopt->rate.mpu, b2));
+		sprintf(b1, "%s/%u",  sprint_size(buffer, b2),
+			1 << qopt->rate.cell_log);
+		print_string(PRINT_ANY, "burst", "burst %s ", b1);
+		print_uint(PRINT_JSON, "mpu", NULL, qopt->rate.mpu);
+		print_string(PRINT_FP, NULL, "mpu %s ",
+			     sprint_size(qopt->rate.mpu, b1));
 	} else {
-		fprintf(f, "burst %s ", sprint_size(buffer, b1));
+		print_u64(PRINT_JSON, "burst", NULL, buffer);
+		print_string(PRINT_FP, NULL, "burst %s ",
+			     sprint_size(buffer, b1));
 	}
 	if (show_raw)
-		fprintf(f, "[%08x] ", qopt->buffer);
+		print_hex(PRINT_ANY, "burst_raw", "[%08x] ", qopt->buffer);
 	prate64 = qopt->peakrate.rate;
 	if (tb[TCA_TBF_PRATE64] &&
 	    RTA_PAYLOAD(tb[TCA_TBF_PRATE64]) >= sizeof(prate64))
 		prate64 = rta_getattr_u64(tb[TCA_TBF_PRATE64]);
 	if (prate64) {
-		fprintf(f, "peakrate %s ", sprint_rate(prate64, b1));
+		print_u64(PRINT_JSON, "peakrate", NULL, prate64);
+		print_string(PRINT_FP, NULL, "peakrate %s ",
+			     sprint_rate(prate64, b1));
 		if (qopt->mtu || qopt->peakrate.mpu) {
 			mtu = tc_calc_xmitsize(prate64, qopt->mtu);
 			if (show_details) {
-				fprintf(f, "mtu %s/%u mpu %s ", sprint_size(mtu, b1),
-					1<<qopt->peakrate.cell_log, sprint_size(qopt->peakrate.mpu, b2));
+				sprintf(b1, "%s/%u",  sprint_size(mtu, b2),
+					1 << qopt->peakrate.cell_log);
+				print_string(PRINT_ANY, "mtu", "mtu %s ", b1);
+				print_uint(PRINT_JSON, "mpu", NULL,
+					   qopt->peakrate.mpu);
+				print_string(PRINT_FP, NULL, "mpu %s ",
+					     sprint_size(qopt->peakrate.mpu,
+							 b1));
 			} else {
-				fprintf(f, "minburst %s ", sprint_size(mtu, b1));
+				print_u64(PRINT_JSON, "minburst", NULL, mtu);
+				print_string(PRINT_FP, NULL, "minburst %s ",
+					     sprint_size(mtu, b1));
 			}
 			if (show_raw)
-				fprintf(f, "[%08x] ", qopt->mtu);
+				print_hex(PRINT_ANY, "mtu_raw", "[%08x] ",
+					    qopt->mtu);
 		}
 	}
 
-	latency = TIME_UNITS_PER_SEC*(qopt->limit/(double)rate64) - tc_core_tick2time(qopt->buffer);
+	latency = TIME_UNITS_PER_SEC * (qopt->limit / (double)rate64) -
+		  tc_core_tick2time(qopt->buffer);
 	if (prate64) {
-		double lat2 = TIME_UNITS_PER_SEC*(qopt->limit/(double)prate64) - tc_core_tick2time(qopt->mtu);
+		lat2 = TIME_UNITS_PER_SEC * (qopt->limit / (double)prate64) -
+		       tc_core_tick2time(qopt->mtu);
 
 		if (lat2 > latency)
 			latency = lat2;
 	}
-	if (latency >= 0.0)
-		fprintf(f, "lat %s ", sprint_time(latency, b1));
-	if (show_raw || latency < 0.0)
-		fprintf(f, "limit %s ", sprint_size(qopt->limit, b1));
-
-	if (qopt->rate.overhead) {
-		fprintf(f, "overhead %d", qopt->rate.overhead);
+	if (latency >= 0.0) {
+		print_u64(PRINT_JSON, "lat", NULL, latency);
+		print_string(PRINT_FP, NULL, "lat %s ",
+			     sprint_time(latency, b1));
+	}
+	if (show_raw || latency < 0.0) {
+		print_uint(PRINT_JSON, "limit", NULL, qopt->limit);
+		print_string(PRINT_FP, NULL, "limit %s ",
+			     sprint_size(qopt->limit, b1));
 	}
+	if (qopt->rate.overhead)
+		print_int(PRINT_ANY, "overhead", "overhead %d ",
+			  qopt->rate.overhead);
 	linklayer = (qopt->rate.linklayer & TC_LINKLAYER_MASK);
 	if (linklayer > TC_LINKLAYER_ETHERNET || show_details)
-		fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b3));
+		print_string(PRINT_ANY, "linklayer", "linklayer %s ",
+			     sprint_linklayer(linklayer, b3));
 
 	return 0;
 }
Signature · 1 line
2.17.1
#10 lore raw

PATCH 10/10 tc: fq_codel: fix missing statistic in JSON output

In reply to Leslie Monis

Print JSON object even if tc_fq_codel_xstats->class_stats.drop_next is negative.

Cc Toke Høiland-Jørgensen <[email protected]>
Fixes 997f2dc19378 ("tc: Add JSON output of fq_codel stats")
---
 tc/q_fq_codel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tc/q_fq_codel.c +2 -2
index 12ce3fbf..efed4d28 100644
@@ -276,12 +276,12 @@ static int fq_codel_print_xstats(struct qdisc_util *qu, FILE *f,
 			sprint_time(st->class_stats.ldelay, b1));
 		if (st->class_stats.dropping) {
 			print_bool(PRINT_ANY, "dropping", " dropping", true);
+			print_int(PRINT_JSON, "drop_next", NULL,
+				  st->class_stats.drop_next);
 			if (st->class_stats.drop_next < 0)
 				print_string(PRINT_FP, NULL, " drop_next -%s",
 					sprint_time(-st->class_stats.drop_next, b1));
 			else {
-				print_uint(PRINT_JSON, "drop_next", NULL,
-					st->class_stats.drop_next);
 				print_string(PRINT_FP, NULL, " drop_next %s",
 					sprint_time(st->class_stats.drop_next, b1));
 			}
Signature · 1 line
2.17.1
#11 lore raw
In reply to Leslie Monis
Quoted 17 lines · On Thu, 26 Dec 2019 00:34:08 +0530 Leslie Monis <[email protected]> wrote:

Several qdiscs do not yet support the JSON output format. This patch series adds the missing compatibility to 9 classless qdiscs. Some of the patches also improve the oneline output of the qdiscs. The last patch in the series fixes a missing statistic in the JSON output of fq_codel.

Leslie Monis (10):
tc: cbs: add support for JSON output
tc: choke: add support for JSON output
tc: codel: add support for JSON output
tc: fq: add support for JSON output
tc: hhf: add support for JSON output
tc: pie: add support for JSON output
tc: sfb: add support for JSON output
tc: sfq: add support for JSON output
tc: tbf: add support for JSON output
tc: fq_codel: fix missing statistic in JSON output

Quoted 14 lines
 man/man8/tc-fq.8  |  14 +++---
 man/man8/tc-pie.8 |  16 +++----
 tc/q_cbs.c        |  10 ++---
 tc/q_choke.c      |  26 +++++++----
 tc/q_codel.c      |  45 +++++++++++++------
 tc/q_fq.c         | 108 ++++++++++++++++++++++++++++++++--------------
 tc/q_fq_codel.c   |   4 +-
 tc/q_hhf.c        |  33 +++++++++-----
 tc/q_pie.c        |  47 ++++++++++++--------
 tc/q_sfb.c        |  67 ++++++++++++++++++----------
 tc/q_sfq.c        |  66 +++++++++++++++++-----------
 tc/q_tbf.c        |  68 ++++++++++++++++++++---------
 12 files changed, 335 insertions(+), 169 deletions(-)

After I test these, looks like they could go into iproute2 directly and skip next. There is no kernel version dependency

#12 lore raw
Quoted 36 lines · Stephen Hemminger
Quoted 17 lines · On Thu, 26 Dec 2019 00:34:08 +0530 Leslie Monis <[email protected]> wrote:

Several qdiscs do not yet support the JSON output format. This patch series adds the missing compatibility to 9 classless qdiscs. Some of the patches also improve the oneline output of the qdiscs. The last patch in the series fixes a missing statistic in the JSON output of fq_codel.

Leslie Monis (10):
tc: cbs: add support for JSON output
tc: choke: add support for JSON output
tc: codel: add support for JSON output
tc: fq: add support for JSON output
tc: hhf: add support for JSON output
tc: pie: add support for JSON output
tc: sfb: add support for JSON output
tc: sfq: add support for JSON output
tc: tbf: add support for JSON output
tc: fq_codel: fix missing statistic in JSON output

Quoted 14 lines
 man/man8/tc-fq.8  |  14 +++---
 man/man8/tc-pie.8 |  16 +++----
 tc/q_cbs.c        |  10 ++---
 tc/q_choke.c      |  26 +++++++----
 tc/q_codel.c      |  45 +++++++++++++------
 tc/q_fq.c         | 108 ++++++++++++++++++++++++++++++++--------------
 tc/q_fq_codel.c   |   4 +-
 tc/q_hhf.c        |  33 +++++++++-----
 tc/q_pie.c        |  47 ++++++++++++--------
 tc/q_sfb.c        |  67 ++++++++++++++++++----------
 tc/q_sfq.c        |  66 +++++++++++++++++-----------
 tc/q_tbf.c        |  68 ++++++++++++++++++++---------
 12 files changed, 335 insertions(+), 169 deletions(-)
Quoted 2 lines

After I test these, looks like they could go into iproute2 directly and skip next. There is no kernel version dependency

Sure, that's fine with me.
Thanks

#13 lore raw
In reply to Leslie Monis
Quoted 17 lines · On Thu, 26 Dec 2019 00:34:08 +0530 Leslie Monis <[email protected]> wrote:

Several qdiscs do not yet support the JSON output format. This patch series adds the missing compatibility to 9 classless qdiscs. Some of the patches also improve the oneline output of the qdiscs. The last patch in the series fixes a missing statistic in the JSON output of fq_codel.

Leslie Monis (10):
tc: cbs: add support for JSON output
tc: choke: add support for JSON output
tc: codel: add support for JSON output
tc: fq: add support for JSON output
tc: hhf: add support for JSON output
tc: pie: add support for JSON output
tc: sfb: add support for JSON output
tc: sfq: add support for JSON output
tc: tbf: add support for JSON output
tc: fq_codel: fix missing statistic in JSON output

Quoted 14 lines
 man/man8/tc-fq.8  |  14 +++---
 man/man8/tc-pie.8 |  16 +++----
 tc/q_cbs.c        |  10 ++---
 tc/q_choke.c      |  26 +++++++----
 tc/q_codel.c      |  45 +++++++++++++------
 tc/q_fq.c         | 108 ++++++++++++++++++++++++++++++++--------------
 tc/q_fq_codel.c   |   4 +-
 tc/q_hhf.c        |  33 +++++++++-----
 tc/q_pie.c        |  47 ++++++++++++--------
 tc/q_sfb.c        |  67 ++++++++++++++++++----------
 tc/q_sfq.c        |  66 +++++++++++++++++-----------
 tc/q_tbf.c        |  68 ++++++++++++++++++++---------
 12 files changed, 335 insertions(+), 169 deletions(-)

Applied, thanks for doing this.