Commit af8e5164 authored by Jakub Kicinski's avatar Jakub Kicinski

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.
Reviewed-by: default avatarPetr Machata <petrm@nvidia.com>
Reviewed-by: default avatarWillem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20240626012456.2326192-3-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 8b8fe280
# 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 @@ class NetDrvEpEnv:
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 @@ class NetDrvEpEnv:
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)
......@@ -79,6 +79,10 @@ def ip(args, json=None, ns=None, host=None):
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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment