From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
andrew+netdev@lunn.ch, horms@kernel.org,
Jakub Kicinski <kuba@kernel.org>,
andrew@lunn.ch, shuah@kernel.org, dsahern@kernel.org,
idosch@nvidia.com, ioana.ciornei@nxp.com, petrm@nvidia.com,
linux-kselftest@vger.kernel.org
Subject: [PATCH net-next 2/2] selftests: drv-net: let ethtool stats settle before reading
Date: Sat, 8 Aug 2026 09:36:53 -0700 [thread overview]
Message-ID: <20260808163653.2460381-2-kuba@kernel.org> (raw)
In-Reply-To: <20260808163653.2460381-1-kuba@kernel.org>
Some devices refresh the statistics exposed via ethtool only
periodically, every stats-block-usecs (as reported by ethtool -c).
ethtool_std_stats and ethtool_rmon sample the counters immediately
after generating traffic, so on such devices they can read stale
values and fail with a delta short of the packets just sent.
Add a hw_stats_settle() helper which sleeps for 1.25x the configured
stats-block-usecs (defaulting to 20ms when the device reports no, or
a zero, period). Use it for ethtool std stats and RMON.
The 1.25x/20msec heuristic matches what the Python tests do.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: andrew@lunn.ch
CC: shuah@kernel.org
CC: dsahern@kernel.org
CC: idosch@nvidia.com
CC: ioana.ciornei@nxp.com
CC: petrm@nvidia.com
CC: linux-kselftest@vger.kernel.org
---
.../selftests/drivers/net/hw/ethtool_rmon.sh | 2 ++
.../selftests/drivers/net/hw/ethtool_std_stats.sh | 2 ++
tools/testing/selftests/net/forwarding/lib.sh | 15 +++++++++++++++
3 files changed, 19 insertions(+)
diff --git a/tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh b/tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh
index 2ec19edddfaa..a074834cbe59 100755
--- a/tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh
+++ b/tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh
@@ -65,6 +65,8 @@ bucket_test()
run_on "$iface" \
"$MZ" "$iface" -q -c "$num_tx" -p "$len" -a own -b bcast -d 10us
+ hw_stats_settle "$iface"
+
after=$(run_on "$iface" ethtool --json -S "$iface" --groups rmon | \
jq -r ".[0].rmon[\"${set}-pktsNtoM\"][$bucket].val")
diff --git a/tools/testing/selftests/drivers/net/hw/ethtool_std_stats.sh b/tools/testing/selftests/drivers/net/hw/ethtool_std_stats.sh
index 1b329b3f60c2..09f8128c51f3 100755
--- a/tools/testing/selftests/drivers/net/hw/ethtool_std_stats.sh
+++ b/tools/testing/selftests/drivers/net/hw/ethtool_std_stats.sh
@@ -48,6 +48,8 @@ traffic_test()
# shellcheck disable=SC2086 # needs split options
run_on "$neigh" "$MZ" "$neigh" -q -d 10usec -c "$num_rx" $pkt_format
+ hw_stats_settle "$int"
+
for i in "${!counters[@]}"; do
read -r int grp cnt target exact_check xfail_message \
<<< "${counters[$i]}"
diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
index ac8358bcb22c..05acd4011456 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -406,6 +406,21 @@ get_ifname_by_ip()
__run_on "$target" ip -j addr show to "$ip_addr" | jq -r '.[].ifname'
}
+# Wait for the device to refresh its HW statistics. Devices latch the stats
+# reported via ethtool only every stats-block-usecs, so sample after that.
+hw_stats_settle()
+{
+ local iface=$1; shift
+ local usecs
+
+ # Match only a non-zero integer; 0 or "n/a" use default (20msec)
+ usecs=$(run_on "$iface" ethtool -c "$iface" 2>/dev/null | \
+ sed -n 's/^stats-block-usecs:[[:space:]]*\([1-9][0-9]*\)$/\1/p')
+ usecs=${usecs:-20000}
+
+ sleep "$(echo "$usecs * 1.25 / 1000 / 1000" | bc -l)"
+}
+
# Whether the test is conforming to the requirements and usage described in
# drivers/net/README.rst.
: "${DRIVER_TEST_CONFORMANT:=no}"
--
2.55.0
next prev parent reply other threads:[~2026-08-08 16:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-08 16:36 [PATCH net-next 1/2] selftests: drv-net: pace ethtool_std_stats packet generation Jakub Kicinski
2026-08-08 16:36 ` Jakub Kicinski [this message]
2026-08-08 16:52 ` [PATCH net-next 2/2] selftests: drv-net: let ethtool stats settle before reading Andrew Lunn
2026-08-11 0:00 ` [PATCH net-next 1/2] selftests: drv-net: pace ethtool_std_stats packet generation patchwork-bot+netdevbpf
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=20260808163653.2460381-2-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=ioana.ciornei@nxp.com \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.com \
--cc=shuah@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