diff mbox series

[net-next,2/4] selftests: drv-net: add helper to wait for HW stats to sync

Message ID 20240620232902.1343834-3-kuba@kernel.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series selftests: drv-net: rss_ctx: add tests for RSS contexts | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 2 maintainers not CCed: shuah@kernel.org linux-kselftest@vger.kernel.org
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 48 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jakub Kicinski June 20, 2024, 11:28 p.m. UTC
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@kernel.org>
---
 .../selftests/drivers/net/lib/py/env.py       | 21 ++++++++++++++++++-
 tools/testing/selftests/net/lib/py/utils.py   |  4 ++++
 2 files changed, 24 insertions(+), 1 deletion(-)

Comments

Willem de Bruijn June 23, 2024, 7:37 a.m. UTC | #1
Jakub Kicinski wrote:
> 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@kernel.org>
> ---
>  .../selftests/drivers/net/lib/py/env.py       | 21 ++++++++++++++++++-
>  tools/testing/selftests/net/lib/py/utils.py   |  4 ++++
>  2 files changed, 24 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..34f62002b741 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,19 @@ 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]
> +            if 'stats-block-usecs' in data:
> +                self._stats_settle_time = data['stats-block-usecs'] / 1000 / 1000
> +            else:
> +                # Assume sync not required, we may use a small (50ms?) sleep
> +                # regardless if we see flakiness
> +                self._stats_settle_time = 0

Intended to set _stats_settle_time to 0.05 here? Else I don't follow
the comment

> +        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 9fa9ec720c89..bf8b5e4d9bac 100644
> --- a/tools/testing/selftests/net/lib/py/utils.py
> +++ b/tools/testing/selftests/net/lib/py/utils.py
> @@ -78,6 +78,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 unprivileged port, for now just random, one day we may decide to check if used.
> -- 
> 2.45.2
>
Jakub Kicinski June 24, 2024, 2:43 p.m. UTC | #2
On Sun, 23 Jun 2024 03:37:19 -0400 Willem de Bruijn wrote:
> > +            else:
> > +                # Assume sync not required, we may use a small (50ms?) sleep
> > +                # regardless if we see flakiness
> > +                self._stats_settle_time = 0  
> 
> Intended to set _stats_settle_time to 0.05 here? Else I don't follow
> the comment

My intuition was that we will need a sleep, but I didn't see failures
in practice, so I removed it and added the comment. I'll just bring
back the sleep.
diff mbox series

Patch

diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
index edcedd7bffab..34f62002b741 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,19 @@  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]
+            if 'stats-block-usecs' in data:
+                self._stats_settle_time = data['stats-block-usecs'] / 1000 / 1000
+            else:
+                # Assume sync not required, we may use a small (50ms?) sleep
+                # regardless if we see flakiness
+                self._stats_settle_time = 0
+        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 9fa9ec720c89..bf8b5e4d9bac 100644
--- a/tools/testing/selftests/net/lib/py/utils.py
+++ b/tools/testing/selftests/net/lib/py/utils.py
@@ -78,6 +78,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 unprivileged port, for now just random, one day we may decide to check if used.