[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240626012456.2326192-3-kuba@kernel.org>
Date: Tue, 25 Jun 2024 18:24:54 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: davem@...emloft.net
Cc: netdev@...r.kernel.org,
edumazet@...gle.com,
pabeni@...hat.com,
willemdebruijn.kernel@...il.com,
ecree.xilinx@...il.com,
dw@...idwei.uk,
przemyslaw.kitszel@...el.com,
michael.chan@...adcom.com,
andrew.gospodarek@...adcom.com,
leitao@...ian.org,
petrm@...dia.com,
Jakub Kicinski <kuba@...nel.org>
Subject: [PATCH net-next v3 2/4] selftests: drv-net: add helper to wait for HW stats to sync
Some devices DMA stats to the host periodically. Add a helper
which can wait for that to happen, based on frequency reported
by the driver in ethtool.
Signed-off-by: Jakub Kicinski <kuba@...nel.org>
---
v3:
- use get() for stats-block-usecs (Petr)
- fix double space (Petr)
v2:
- sleep for 25ms on top of the driver DMA period
(and remove confusing comment)
---
.../selftests/drivers/net/lib/py/env.py | 19 ++++++++++++++++++-
tools/testing/selftests/net/lib/py/utils.py | 4 ++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
index edcedd7bffab..a5e800b8f103 100644
--- a/tools/testing/selftests/drivers/net/lib/py/env.py
+++ b/tools/testing/selftests/drivers/net/lib/py/env.py
@@ -1,9 +1,10 @@
# SPDX-License-Identifier: GPL-2.0
import os
+import time
from pathlib import Path
from lib.py import KsftSkipEx, KsftXfailEx
-from lib.py import cmd, ip
+from lib.py import cmd, ethtool, ip
from lib.py import NetNS, NetdevSimDev
from .remote import Remote
@@ -82,6 +83,8 @@ from .remote import Remote
self.env = _load_env_file(src_path)
+ self._stats_settle_time = None
+
# Things we try to destroy
self.remote = None
# These are for local testing state
@@ -222,3 +225,17 @@ from .remote import Remote
if remote:
if not self._require_cmd(comm, "remote"):
raise KsftSkipEx("Test requires (remote) command: " + comm)
+
+ def wait_hw_stats_settle(self):
+ """
+ Wait for HW stats to become consistent, some devices DMA HW stats
+ periodically so events won't be reflected until next sync.
+ Good drivers will tell us via ethtool what their sync period is.
+ """
+ if self._stats_settle_time is None:
+ data = ethtool("-c " + self.ifname, json=True)[0]
+
+ self._stats_settle_time = 0.025 + \
+ data.get('stats-block-usecs', 0) / 1000 / 1000
+
+ time.sleep(self._stats_settle_time)
diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
index dd9d2b9f2b20..a6c87bfe532f 100644
--- a/tools/testing/selftests/net/lib/py/utils.py
+++ b/tools/testing/selftests/net/lib/py/utils.py
@@ -79,6 +79,10 @@ import time
return tool('ip', args, json=json, host=host)
+def ethtool(args, json=None, ns=None, host=None):
+ return tool('ethtool', args, json=json, ns=ns, host=host)
+
+
def rand_port():
"""
Get a random unprivileged port, try to make sure it's not already used.
--
2.45.2
Powered by blists - more mailing lists