All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	willemdebruijn.kernel@gmail.com, ecree.xilinx@gmail.com,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 2/4] selftests: drv-net: add helper to wait for HW stats to sync
Date: Thu, 20 Jun 2024 16:28:59 -0700	[thread overview]
Message-ID: <20240620232902.1343834-3-kuba@kernel.org> (raw)
In-Reply-To: <20240620232902.1343834-1-kuba@kernel.org>

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
+        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


  parent reply	other threads:[~2024-06-20 23:29 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-20 23:28 [PATCH net-next 0/4] selftests: drv-net: rss_ctx: add tests for RSS contexts Jakub Kicinski
2024-06-20 23:28 ` [PATCH net-next 1/4] selftests: drv-net: try to check if port is in use Jakub Kicinski
2024-06-21  1:52   ` David Wei
2024-06-23  7:34   ` Willem de Bruijn
2024-06-24 13:59   ` Przemek Kitszel
2024-06-20 23:28 ` Jakub Kicinski [this message]
2024-06-23  7:37   ` [PATCH net-next 2/4] selftests: drv-net: add helper to wait for HW stats to sync Willem de Bruijn
2024-06-24 14:43     ` Jakub Kicinski
2024-06-20 23:29 ` [PATCH net-next 3/4] selftests: drv-net: add ability to wait for at least N packets to load gen Jakub Kicinski
2024-06-21  1:14   ` David Wei
2024-06-20 23:29 ` [PATCH net-next 4/4] selftests: drv-net: rss_ctx: add tests for RSS configuration and contexts Jakub Kicinski
2024-06-21  1:52   ` David Wei
2024-06-21  2:26     ` Jakub Kicinski
2024-06-23  8:03   ` Willem de Bruijn
2024-06-24 14:50     ` Jakub Kicinski
2024-06-24 16:02       ` Jakub Kicinski
2024-06-24 12:55   ` Edward Cree
2024-06-24 14:54     ` Jakub Kicinski

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=20240620232902.1343834-3-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=ecree.xilinx@gmail.com \
    --cc=edumazet@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemdebruijn.kernel@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.