Netdev List
 help / color / mirror / Atom feed
* [PATCH iproute2-next] tc/netem: display per-impairment xstats counters
@ 2026-05-20 17:34 Stephen Hemminger
  0 siblings, 0 replies; only message in thread
From: Stephen Hemminger @ 2026-05-20 17:34 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Stephen Hemminger

The kernel now reports struct tc_netem_xstats via TCA_STATS_APP with
per-impairment counters: delayed, loss, corrupted, duplicated,
reordered, and ecn_marked.

Add netem_print_xstats() following the same pattern as
fq_print_xstats()

Example output of `tc -s qdisc show dev eth0`:
  qdisc netem 8001: root refcnt 2 limit 1000 delay 100ms loss 5%
   Sent 1234567 bytes 15483 pkt (dropped 774, overlimits 0 requeues 0)
   delayed 14709 dropped 774 corrupted 154 duplicated 309 reordered 61 ecn_marked 0

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 tc/q_netem.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/tc/q_netem.c b/tc/q_netem.c
index c48fde11..98e28909 100644
--- a/tc/q_netem.c
+++ b/tc/q_netem.c
@@ -870,8 +870,34 @@ static int netem_print_opt(const struct qdisc_util *qu, FILE *f, struct rtattr *
 	return 0;
 }
 
+static int netem_print_xstats(const struct qdisc_util *qu, FILE *f,
+			      struct rtattr *xstats)
+{
+	struct tc_netem_xstats *st, _st;
+
+	if (xstats == NULL)
+		return 0;
+
+	/* future proof for addition of more stats */
+	memset(&_st, 0, sizeof(_st));
+	memcpy(&_st, RTA_DATA(xstats), min(RTA_PAYLOAD(xstats), sizeof(*st)));
+	st = &_st;
+
+	print_u64(PRINT_ANY, "delayed",    "  delayed %llu",   st->delayed);
+	print_u64(PRINT_ANY, "dropped",    " dropped %llu",    st->dropped);
+	print_u64(PRINT_ANY, "corrupted",  " corrupted %llu",  st->corrupted);
+	print_u64(PRINT_ANY, "duplicated", " duplicated %llu", st->duplicated);
+	print_u64(PRINT_ANY, "reordered",  " reordered %llu",  st->reordered);
+	print_u64(PRINT_ANY, "ecn_marked", " ecn_marked %llu", st->ecn_marked);
+	if (st->allocation_errors)
+		print_u64(PRINT_ANY, "alloc_errors", " alloc_errors %llu", st->allocation_errors);
+
+	return 0;
+}
+
 struct qdisc_util netem_qdisc_util = {
 	.id		= "netem",
 	.parse_qopt	= netem_parse_opt,
 	.print_qopt	= netem_print_opt,
+	.print_xstats	= netem_print_xstats,
 };
-- 
2.53.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-05-20 17:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-20 17:34 [PATCH iproute2-next] tc/netem: display per-impairment xstats counters Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox