From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: David Ahern <dsahern@kernel.org>,
Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2-next] tc/netem: display per-impairment xstats counters
Date: Wed, 20 May 2026 10:34:46 -0700 [thread overview]
Message-ID: <20260520173512.807908-1-stephen@networkplumber.org> (raw)
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
reply other threads:[~2026-05-20 17:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260520173512.807908-1-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dsahern@kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox