From patchwork Thu Jun 20 23:28:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13706558 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5257130ADA for ; Thu, 20 Jun 2024 23:29:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718926153; cv=none; b=Fu1nQzha7ZT9EiuYxQ0pFFpAD/m8+IQ+VmpfvvLuJCOxDjWxwF2WfENoggQru/HX/+S7ExZlQbSqFIqqUjnrOr6wWsCyRInK2oSeM6rip2Mlm1uq/SW8uMLVXN5arBRkWHjkd8wnmjPHwrtHx1x015INoQPTHORqZ1P98Khh9NA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718926153; c=relaxed/simple; bh=ntpxYppCIoJn8lPT5mNgVV6d3Hw983mb6VVLWtN7yxA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RUWSTfSAly4kHL566OAmAIyC5+heckPZi0WatMZryswsKgGZ4/HU9BZnNg00iyYPrrMfCz8HJck+Th2ID/z7NTjZnlzYy8oKUBWwbpfpnngsfymfIAaY/UrLarUamqc566coH53PzrcEPOZjiZjlXuAHESgyyl+L2N834fAD/J8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XsUnK8CW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XsUnK8CW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A99EC32781; Thu, 20 Jun 2024 23:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718926153; bh=ntpxYppCIoJn8lPT5mNgVV6d3Hw983mb6VVLWtN7yxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XsUnK8CWkwxc8kZ/pydG/5CNGoyuokMWlIXhtnfZ7iJ4liZu5TGtsR6wnH8Y968Ix gw7X0b6W0heRzfZ2xJaM/rcW1tbUPsj86NIsqubm58Zq40s6VMmqMay3TDZXQtLigi Dua4x6c7n8LnOiPm45P8ue0BarQixLBVK3f+EGRpAEk75CiHlEwXllcxI1NykIpvSK Deo7qkEvgP0VMwJDFKjW0safYtOo6Ydit0yGLih1zL373627JL0kUI0aoZcBComW4m ZubGsKGVUjdIt05I1+76YJdZpTvqbdauSh9WhbLsLX60/wfT9f2vV9Toc0P5dMV4is V7CkkaykSdMNQ== From: Jakub Kicinski 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 Subject: [PATCH net-next 1/4] selftests: drv-net: try to check if port is in use Date: Thu, 20 Jun 2024 16:28:58 -0700 Message-ID: <20240620232902.1343834-2-kuba@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620232902.1343834-1-kuba@kernel.org> References: <20240620232902.1343834-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org We use random ports for communication. As Willem predicted this leads to occasional failures. Try to check if port is already in use by opening a socket and binding to that port. Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/lib/py/utils.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py index 0540ea24921d..9fa9ec720c89 100644 --- a/tools/testing/selftests/net/lib/py/utils.py +++ b/tools/testing/selftests/net/lib/py/utils.py @@ -3,6 +3,7 @@ import json as _json import random import re +import socket import subprocess import time @@ -81,7 +82,17 @@ import time """ Get unprivileged port, for now just random, one day we may decide to check if used. """ - return random.randint(10000, 65535) + while True: + port = random.randint(10000, 65535) + try: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.bind(("", port)) + with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s: + s.bind(("", port)) + return port + except OSError as e: + if e.errno != 98: # already in use + raise def wait_port_listen(port, proto="tcp", ns=None, host=None, sleep=0.005, deadline=5): From patchwork Thu Jun 20 23:28:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13706559 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B79E145B0C for ; Thu, 20 Jun 2024 23:29:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718926154; cv=none; b=cFrGdOddgfj92oahhICc0EOh7rRZd5aQVDT9rBVWgfsx5Ac03CSt3t02AriJOijH6/yJMBOX5JRFwfCQ9Amzn3shwKQnhFnvSjbf29zGTlpt2RFbln9LCo4mVda1liSBVJ3jkSrcg6+qpBJbpCZSgo6p1WeljUXi/2vgOlVWUSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718926154; c=relaxed/simple; bh=Nrnikk/qobBM6D4ec6hhxHhazQqRTKohQLMN4Ee5kEw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uAx2YDnAoO1//Gwqqo1kzzVOrZ3F4K8Xmb/v1+U0vjJ2ugUJ0q88gAN0/OvM0UqcB7I8FwdEJigrcxk7UmJkBFGNiVB47IH9PeZTmiJFQfabMODyOs8YYxTfypNEFk4nkM/ByBUt9PMPzmkrfNyxoehDn1ZMbYV6jg6PKNcUaFg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Yeelds3a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Yeelds3a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E0A2C4AF0A; Thu, 20 Jun 2024 23:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718926153; bh=Nrnikk/qobBM6D4ec6hhxHhazQqRTKohQLMN4Ee5kEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yeelds3aHhLspcmYwWBTREpoQIV517F1gp5XurzbzEfQ0wQIpHJ6wvouVkOEevrdm ZAMuzizwmksONPMKtRR4inJiIau7ZCfH4l8OG22JFvuVtsysSKdlmVK/f8DxZ6qL3W Y7YtdU792LkYCz/01urhoMYUU32jP7NUwO4M7guX+pfAiNmwm2gb393ZqyvLR9MnD1 yrHCn+qbp+QsWsWJodjMOwuyb3jBxrIdF4atmoPXPgLDzbWzr29goCiRd83qx7QVbA TsGZ/tlmTDJtGpkp2P4BO/WgF1hY7CQqXleW5jD+15zOncKG8Y3xBrtNDMJRcrr5uw z14MZqjDoNclA== From: Jakub Kicinski 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 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 Message-ID: <20240620232902.1343834-3-kuba@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620232902.1343834-1-kuba@kernel.org> References: <20240620232902.1343834-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: 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 --- .../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. From patchwork Thu Jun 20 23:29:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13706560 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B00814A615 for ; Thu, 20 Jun 2024 23:29:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718926154; cv=none; b=Rfkb2P5P1YqTjoqh8LW1FuAoGBSZ8o3qOuV4FJMwbcEEJ5FCy49nYramc8MG8CxHLMs5kdzQDsEeg17goVN6ifXVkYka3TyJB1YsqAG6EYHvgWMw8Vx108sNZgx7jx0sipIVe4LSZMHZM0i5ZvSnCINMkioeWtFkJ9IusLUXkIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718926154; c=relaxed/simple; bh=9JErtGL3/Z1VDYeNIUkrIb3x6eLeoWnQLPq3nfQNJeo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=inMzSy2Jv1/kF9LzzGtIt2UkLNskICB90vI3ZlLpw6s+jrzDZh1pHlkykaofbOWzTOAH3CNfBOobtY91Uwe+oCWEcouqbiMyYTIXBfU3URQsI3qymAszf/adkwISW9ISvy7ja8BfIMpIdxKfDUPsfycxFZz2nxgZW2f7tTd2zyw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Zq1cek3C; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Zq1cek3C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F21F0C4AF0B; Thu, 20 Jun 2024 23:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718926154; bh=9JErtGL3/Z1VDYeNIUkrIb3x6eLeoWnQLPq3nfQNJeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zq1cek3CMmhukyVBFD7OzvdJE6Us174XzQ13axF6x6FxCGaUkd8xlm79xm/qwVklh YAjff7LybnTZPjyR8151KGoOvS6YLUdZKhnTaHlc6JaadzadAoYBeNUcntUGPCuEz2 OGKlHj9PHWq0Ia8lomkt0UqhQDHMWhZF+w/81T3dqF0QNkWieUdb/W5bKogqo8sY2o pG2RpaaCXk9zN8akbvemwQdXzD/4GvvydU78oJcXh3AiMlsCGyIYVVUUdeT9Xed9v6 lZFovRGYkHb9/R0fbWQEcE4Yhn+ldxvS+UxQYVQ5sex/kbZXZP/PqHpPNUaOg5r6aH th2W08wb9LPmw== From: Jakub Kicinski 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 Subject: [PATCH net-next 3/4] selftests: drv-net: add ability to wait for at least N packets to load gen Date: Thu, 20 Jun 2024 16:29:00 -0700 Message-ID: <20240620232902.1343834-4-kuba@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620232902.1343834-1-kuba@kernel.org> References: <20240620232902.1343834-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Teach the load generator how to wait for at least given number of packets to be received. This will be useful for filtering where we'll want to send a non-trivial number of packets and make sure they landed in right queues. Signed-off-by: Jakub Kicinski --- .../selftests/drivers/net/lib/py/load.py | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/drivers/net/lib/py/load.py b/tools/testing/selftests/drivers/net/lib/py/load.py index abdb677bdb1c..ae60c438f6c2 100644 --- a/tools/testing/selftests/drivers/net/lib/py/load.py +++ b/tools/testing/selftests/drivers/net/lib/py/load.py @@ -18,15 +18,27 @@ from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen background=True, host=env.remote) # Wait for traffic to ramp up - pkt = ip("-s link show dev " + env.ifname, json=True)[0]["stats64"]["rx"]["packets"] + if not self._wait_pkts(pps=1000): + self.stop(verbose=True) + raise Exception("iperf3 traffic did not ramp up") + + def _wait_pkts(self, pkt_cnt=None, pps=None): + pkt = ip("-s link show dev " + self.env.ifname, json=True)[0]["stats64"]["rx"]["packets"] for _ in range(50): time.sleep(0.1) - now = ip("-s link show dev " + env.ifname, json=True)[0]["stats64"]["rx"]["packets"] - if now - pkt > 1000: - return - pkt = now - self.stop(verbose=True) - raise Exception("iperf3 traffic did not ramp up") + now = ip("-s link show dev " + self.env.ifname, json=True)[0]["stats64"]["rx"]["packets"] + if pps: + if now - pkt > pps / 10: + return True + pkt = now + elif pkt_cnt: + if now - pkt > pkt_cnt: + return True + return False + + def wait_pkts_and_stop(self, pkt_cnt): + failed = not self._wait_pkts(pkt_cnt=pkt_cnt) + self.stop(verbose=failed) def stop(self, verbose=None): self._iperf_client.process(terminate=True) From patchwork Thu Jun 20 23:29:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13706561 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A02714E2FB for ; Thu, 20 Jun 2024 23:29:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718926155; cv=none; b=BrdxI19MIDZQ+1rFChUCxN00NfHmTgSDukH5z1yT5Zf2Ar0m0PTlIn9RI/L1bZE5EDwk0H/2Zb5jkHW+2QZ1cQ+O9kAY3Jp4kQWHMR3jAxX10s0vmDF/LY/EkRIB0cc+1KVs2qvSbXrE0s1VcNa0kPoE9P0u+Da/xC8LTEdonJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718926155; c=relaxed/simple; bh=Qz+ECKR6tQQLmspO9tbFySS3E9KJ8NO3q8P9l0ZpPOs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TWTTYwIbaJ+Oi+w66unS2/t+FhhWvu4j9W3cpoltI0ZdNqR3npMcDezzid9+Gzh5e+pItSo1N14Psbil48u7GltS9Y5Y/gdw8akINpqH1hBWX8aQ0z/GPkMgDTIV9/nHZuSoF1/0QD/8n5MUInSM1mgvyjVtFQBxIe/awVcqRMA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LFpic0tA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LFpic0tA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 721C6C2BD10; Thu, 20 Jun 2024 23:29:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718926154; bh=Qz+ECKR6tQQLmspO9tbFySS3E9KJ8NO3q8P9l0ZpPOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LFpic0tAYvl/ikePaCfIwJ3NnXVO0i0f/ZX7DYKvPBMBxw1D7RorSryuwIXdzwSy7 R50M72lx27Jx/sFFjnLUrmMszkMB5tRUgBPyqIlfvlbp1vsWiRjL+JS243+VrgfCI/ TEw/nH7VvPoqIJGyy9AptiLropdpblvubgu1WCuI7X1np0LWwL9rY2r3c82tSeFPc9 5mzbwC8zQdYRdyE3u9FNSw3xNfwLaTUlEOsqfPrRPaJloKMnfzQ7dlItCoveFPFUkL OgFca838yTH5X8xzZYNp6dFm+irhLZiDINV9SpS7ycppyU6OvFhU/scpOKGZJLZ+Lk eG2JlbEoTIVqA== From: Jakub Kicinski 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 Subject: [PATCH net-next 4/4] selftests: drv-net: rss_ctx: add tests for RSS configuration and contexts Date: Thu, 20 Jun 2024 16:29:01 -0700 Message-ID: <20240620232902.1343834-5-kuba@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620232902.1343834-1-kuba@kernel.org> References: <20240620232902.1343834-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add tests focusing on indirection table configuration and creating extra RSS contexts in drivers which support it. $ ./drivers/net/hw/rss_ctx.py KTAP version 1 1..6 ok 1 rss_ctx.test_rss_key_indir ok 2 rss_ctx.test_rss_context ok 3 rss_ctx.test_rss_context4 # Increasing queue count 44 -> 66 # Failed to create context 32, trying to test what we got ok 4 rss_ctx.test_rss_context32 # SKIP Tested only 31 contexts, wanted 32 ok 5 rss_ctx.test_rss_context_overlap ok 6 rss_ctx.test_rss_context_overlap2 # Totals: pass:5 fail:0 xfail:0 xpass:0 skip:1 error:0 Signed-off-by: Jakub Kicinski --- .../testing/selftests/drivers/net/hw/Makefile | 1 + .../selftests/drivers/net/hw/rss_ctx.py | 243 ++++++++++++++++++ .../selftests/drivers/net/lib/py/load.py | 7 +- tools/testing/selftests/net/lib/py/ksft.py | 5 + tools/testing/selftests/net/lib/py/utils.py | 8 +- 5 files changed, 259 insertions(+), 5 deletions(-) create mode 100755 tools/testing/selftests/drivers/net/hw/rss_ctx.py diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile index 4933d045ab66..c9f2f48fc30f 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -11,6 +11,7 @@ TEST_PROGS = \ hw_stats_l3_gre.sh \ loopback.sh \ pp_alloc_fail.py \ + rss_ctx.py \ # TEST_FILES := \ diff --git a/tools/testing/selftests/drivers/net/hw/rss_ctx.py b/tools/testing/selftests/drivers/net/hw/rss_ctx.py new file mode 100755 index 000000000000..74d2ca62083f --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/rss_ctx.py @@ -0,0 +1,243 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import datetime +import random +from lib.py import ksft_run, ksft_pr, ksft_exit, ksft_eq, ksft_ge, ksft_lt +from lib.py import NetDrvEpEnv +from lib.py import NetdevFamily +from lib.py import KsftSkipEx +from lib.py import rand_port +from lib.py import ethtool, ip, GenerateTraffic, CmdExitFailure + + +def _rss_key_str(key): + return ":".join(["{:02x}".format(x) for x in key]) + + +def _rss_key_rand(length): + return [random.randint(0, 255) for _ in range(length)] + + +def get_rss(cfg): + return ethtool(f"-x {cfg.ifname}", json=True)[0] + + +def ethtool_create(cfg, act, opts): + output = ethtool(f"{act} {cfg.ifname} {opts}").stdout + # Output will be something like: "New RSS context is 1" or + # "Added rule with ID 7", we want the integer from the end + return int(output.split()[-1]) + + +# Get Rx packet counts for all queues, as a simple list of integers +# if @prev is specified the prev counts will be subtracted +def _get_rx_cnts(cfg, prev=None): + cfg.wait_hw_stats_settle() + data = cfg.netdevnl.qstats_get({"ifindex": cfg.ifindex, "scope": ["queue"]}, dump=True) + data = [x for x in data if x['queue-type'] == "rx"] + max_q = max([x["queue-id"] for x in data]) + queue_stats = [0] * (max_q + 1) + for q in data: + queue_stats[q["queue-id"]] = q["rx-packets"] + if prev and q["queue-id"] < len(prev): + queue_stats[q["queue-id"]] -= prev[q["queue-id"]] + return queue_stats + + +def test_rss_key_indir(cfg): + """ + Test basics like updating the main RSS key and indirection table. + """ + data = get_rss(cfg) + want_keys = ['rss-hash-key', 'rss-hash-function', 'rss-indirection-table'] + for k in want_keys: + if k not in data: + raise KsftFailEx("ethtool results missing key: " + k) + if not data[k]: + raise KsftFailEx(f"ethtool results empty for '{k}': {data[k]}") + + key_len = len(data['rss-hash-key']) + + # Set the key + key = _rss_key_rand(key_len) + ethtool(f"-X {cfg.ifname} hkey " + _rss_key_str(key)) + + data = get_rss(cfg) + ksft_eq(key, data['rss-hash-key']) + + # Set the indirection table + ethtool(f"-X {cfg.ifname} equal 2") + data = get_rss(cfg) + ksft_eq(0, min(data['rss-indirection-table'])) + ksft_eq(1, max(data['rss-indirection-table'])) + + # Check we only get traffic on the first 2 queues + cnts = _get_rx_cnts(cfg) + GenerateTraffic(cfg).wait_pkts_and_stop(20000) + cnts = _get_rx_cnts(cfg, prev=cnts) + # 2 queues, 20k packets, must be at least 5k per queue + ksft_ge(cnts[0], 5000, "traffic on main context (1/2): " + str(cnts)) + ksft_ge(cnts[1], 5000, "traffic on main context (2/2): " + str(cnts)) + # The other queues should be unused + ksft_eq(sum(cnts[2:]), 0, "traffic on unused queues: " + str(cnts)) + + # Restore, and check traffic gets spread again + ethtool(f"-X {cfg.ifname} default") + + cnts = _get_rx_cnts(cfg) + GenerateTraffic(cfg).wait_pkts_and_stop(20000) + cnts = _get_rx_cnts(cfg, prev=cnts) + # First two queues get less traffic than all the rest + ksft_ge(sum(cnts[2:]), sum(cnts[:2]), "traffic distributed: " + str(cnts)) + + +def test_rss_context(cfg, ctx_cnt=1): + """ + Test separating traffic into RSS contexts. + The queues will be allocated 2 for each context: + ctx0 ctx1 ctx2 ctx3 + [0 1] [2 3] [4 5] [6 7] ... + """ + + requested_ctx_cnt = ctx_cnt + + # Try to allocate more queues when necessary + qcnt = len(_get_rx_cnts(cfg)) + if qcnt >= 2 + 2 * ctx_cnt: + qcnt = None + else: + try: + ksft_pr(f"Increasing queue count {qcnt} -> {2 + 2 * ctx_cnt}") + ethtool(f"-L {cfg.ifname} combined {2 + 2 * ctx_cnt}") + except: + raise KsftSkipEx("Not enough queues for the test") + + ntuple = [] + ctx_id = [] + ports = [] + try: + # Use queues 0 and 1 for normal traffic + ethtool(f"-X {cfg.ifname} equal 2") + + for i in range(ctx_cnt): + try: + ctx_id.append(ethtool_create(cfg, "-X", "context new")) + except CmdExitFailure: + # try to carry on and skip at the end + if i == 0: + raise + ksft_pr(f"Failed to create context {i + 1}, trying to test what we got") + ctx_cnt = i + break + + ethtool(f"-X {cfg.ifname} context {ctx_id[i]} start {2 + i * 2} equal 2") + + ports.append(rand_port()) + flow = f"flow-type tcp{cfg.addr_ipver} dst-port {ports[i]} context {ctx_id[i]}" + ntuple.append(ethtool_create(cfg, "-N", flow)) + + for i in range(ctx_cnt): + cnts = _get_rx_cnts(cfg) + GenerateTraffic(cfg, port=ports[i]).wait_pkts_and_stop(20000) + cnts = _get_rx_cnts(cfg, prev=cnts) + + ksft_lt(sum(cnts[ :2]), 10000, "traffic on main context:" + str(cnts)) + ksft_ge(sum(cnts[2+i*2:4+i*2]), 20000, f"traffic on context {i}: " + str(cnts)) + ksft_eq(sum(cnts[2:2+i*2] + cnts[4+i*2:]), 0, "traffic on other contexts: " + str(cnts)) + finally: + for nid in ntuple: + ethtool(f"-N {cfg.ifname} delete {nid}") + for cid in ctx_id: + ethtool(f"-X {cfg.ifname} context {cid} delete") + ethtool(f"-X {cfg.ifname} default") + if qcnt: + ethtool(f"-L {cfg.ifname} combined {qcnt}") + + if requested_ctx_cnt != ctx_cnt: + raise KsftSkipEx(f"Tested only {ctx_cnt} contexts, wanted {requested_ctx_cnt}") + + +def test_rss_context4(cfg): + test_rss_context(cfg, 4) + + +def test_rss_context32(cfg): + test_rss_context(cfg, 32) + + +def test_rss_context_overlap(cfg, other_ctx=0): + """ + Test contexts overlapping with each other. + Use 4 queues for the main context, but only queues 2 and 3 for context 1. + """ + ctx_id = None + ntuple = None + if other_ctx == 0: + ethtool(f"-X {cfg.ifname} equal 4") + else: + other_ctx = ethtool_create(cfg, "-X", "context new") + ethtool(f"-X {cfg.ifname} context {other_ctx} equal 4") + + try: + ctx_id = ethtool_create(cfg, "-X", "context new") + ethtool(f"-X {cfg.ifname} context {ctx_id} start 2 equal 2") + + port = rand_port() + if other_ctx: + flow = f"flow-type tcp{cfg.addr_ipver} dst-port {port} context {other_ctx}" + ntuple = ethtool_create(cfg, "-N", flow) + + # Test the main context + cnts = _get_rx_cnts(cfg) + GenerateTraffic(cfg, port=port).wait_pkts_and_stop(20000) + cnts = _get_rx_cnts(cfg, prev=cnts) + + ksft_ge(sum(cnts[ :4]), 20000, "traffic on main context: " + str(cnts)) + ksft_ge(sum(cnts[ :2]), 7000, "traffic on main context (1/2): " + str(cnts)) + ksft_ge(sum(cnts[2:4]), 7000, "traffic on main context (2/2): " + str(cnts)) + if other_ctx == 0: + ksft_eq(sum(cnts[4: ]), 0, "traffic on other queues: " + str(cnts)) + + # Now create a rule for context 1 and make sure traffic goes to a subset + if other_ctx: + ethtool(f"-N {cfg.ifname} delete {ntuple}") + flow = f"flow-type tcp{cfg.addr_ipver} dst-port {port} context {ctx_id}" + ntuple = ethtool_create(cfg, "-N", flow) + + cnts = _get_rx_cnts(cfg) + GenerateTraffic(cfg, port=port).wait_pkts_and_stop(20000) + cnts = _get_rx_cnts(cfg, prev=cnts) + + ksft_lt(sum(cnts[ :2]), 7000, "traffic on main context: " + str(cnts)) + ksft_ge(sum(cnts[2:4]), 20000, "traffic on extra context: " + str(cnts)) + if other_ctx == 0: + ksft_eq(sum(cnts[4: ]), 0, "traffic on other queues: " + str(cnts)) + finally: + if ntuple: + ethtool(f"-N {cfg.ifname} delete {ntuple}") + if ctx_id: + ethtool(f"-X {cfg.ifname} context {ctx_id} delete") + if other_ctx == 0: + ethtool(f"-X {cfg.ifname} default") + else: + ethtool(f"-X {cfg.ifname} context {other_ctx} delete") + + +def test_rss_context_overlap2(cfg): + test_rss_context_overlap(cfg, True) + + +def main() -> None: + with NetDrvEpEnv(__file__, nsim_test=False) as cfg: + cfg.netdevnl = NetdevFamily() + + ksft_run([test_rss_key_indir, test_rss_context, test_rss_context4, + test_rss_context32, test_rss_context_overlap, + test_rss_context_overlap2], + args=(cfg, )) + ksft_exit() + + +if __name__ == "__main__": + main() diff --git a/tools/testing/selftests/drivers/net/lib/py/load.py b/tools/testing/selftests/drivers/net/lib/py/load.py index ae60c438f6c2..1de62977433b 100644 --- a/tools/testing/selftests/drivers/net/lib/py/load.py +++ b/tools/testing/selftests/drivers/net/lib/py/load.py @@ -5,13 +5,14 @@ import time from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen class GenerateTraffic: - def __init__(self, env): + def __init__(self, env, port=None): env.require_cmd("iperf3", remote=True) self.env = env - port = rand_port() - self._iperf_server = cmd(f"iperf3 -s -p {port}", background=True) + if port is None: + port = rand_port() + self._iperf_server = cmd(f"iperf3 -s -1 -p {port}", background=True) wait_port_listen(port) time.sleep(0.1) self._iperf_client = cmd(f"iperf3 -c {env.addr} -P 16 -p {port} -t 86400", diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py index 4769b4eb1ea1..91648c5baf40 100644 --- a/tools/testing/selftests/net/lib/py/ksft.py +++ b/tools/testing/selftests/net/lib/py/ksft.py @@ -57,6 +57,11 @@ KSFT_RESULT_ALL = True _fail("Check failed", a, "<", b, comment) +def ksft_lt(a, b, comment=""): + if a > b: + _fail("Check failed", a, ">", b, comment) + + class ksft_raises: def __init__(self, expected_type): self.exception = None diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py index bf8b5e4d9bac..b3ee57a650ae 100644 --- a/tools/testing/selftests/net/lib/py/utils.py +++ b/tools/testing/selftests/net/lib/py/utils.py @@ -8,6 +8,10 @@ import subprocess import time +class CmdExitFailure(Exception): + pass + + class cmd: def __init__(self, comm, shell=True, fail=True, ns=None, background=False, host=None, timeout=5): if ns: @@ -42,8 +46,8 @@ import time if self.proc.returncode != 0 and fail: if len(stderr) > 0 and stderr[-1] == "\n": stderr = stderr[:-1] - raise Exception("Command failed: %s\nSTDOUT: %s\nSTDERR: %s" % - (self.proc.args, stdout, stderr)) + raise CmdExitFailure("Command failed: %s\nSTDOUT: %s\nSTDERR: %s" % + (self.proc.args, stdout, stderr)) class bkg(cmd):