From: Carolina Jubran <cjubran@nvidia.com>
To: Shuah Khan <shuah@kernel.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: Gal Pressman <gal@nvidia.com>, Tariq Toukan <tariqt@nvidia.com>,
"Cosmin Ratiu" <cratiu@nvidia.com>,
Nimrod Oren <noren@nvidia.com>, Mark Bloch <mbloch@nvidia.com>,
<linux-kernel@vger.kernel.org>, <linux-kselftest@vger.kernel.org>,
<netdev@vger.kernel.org>
Subject: [PATCH net-next 6/6] selftests: drv-net: Fix tolerance calculation in devlink_rate_tc_bw.py
Date: Thu, 20 Nov 2025 11:58:59 +0200 [thread overview]
Message-ID: <20251120095859.2951339-7-cjubran@nvidia.com> (raw)
In-Reply-To: <20251120095859.2951339-1-cjubran@nvidia.com>
Currently, tolerance is computed against the TC’s expected percentage,
making TC3 (20%) validation overly strict and TC4 (80%) overly loose.
Update BandwidthValidator to take a dict of shares and compute bounds
relative to the overall total, so that all shares are validated
consistently.
Signed-off-by: Carolina Jubran <cjubran@nvidia.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Nimrod Oren <noren@nvidia.com>
---
.../drivers/net/hw/devlink_rate_tc_bw.py | 74 ++++++++-----------
1 file changed, 30 insertions(+), 44 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/hw/devlink_rate_tc_bw.py b/tools/testing/selftests/drivers/net/hw/devlink_rate_tc_bw.py
index db24bfc51da4..4e4faa9275bb 100755
--- a/tools/testing/selftests/drivers/net/hw/devlink_rate_tc_bw.py
+++ b/tools/testing/selftests/drivers/net/hw/devlink_rate_tc_bw.py
@@ -69,39 +69,35 @@ from lib.py import Iperf3Runner
class BandwidthValidator:
"""
- Validates bandwidth totals and per-TC shares against expected values
- with a tolerance.
+ Validates total bandwidth and individual shares with tolerance
+ relative to the overall total.
"""
- def __init__(self):
+ def __init__(self, shares):
self.tolerance_percent = 12
- self.expected_total_gbps = 1.0
- self.total_min_expected = self.min_expected(self.expected_total_gbps)
- self.total_max_expected = self.max_expected(self.expected_total_gbps)
- self.tc_expected_percent = {
- 3: 20.0,
- 4: 80.0,
- }
+ self.expected_total = sum(shares.values())
+ self.bounds = {}
+
+ for name, exp in shares.items():
+ self.bounds[name] = (self.min_expected(exp), self.max_expected(exp))
def min_expected(self, value):
"""Calculates the minimum acceptable value based on tolerance."""
- return value - (value * self.tolerance_percent / 100)
+ return value - (self.expected_total * self.tolerance_percent / 100)
def max_expected(self, value):
"""Calculates the maximum acceptable value based on tolerance."""
- return value + (value * self.tolerance_percent / 100)
-
- def bound(self, expected, value):
- """Returns True if value is within expected tolerance."""
- return self.min_expected(expected) <= value <= self.max_expected(expected)
+ return value + (self.expected_total * self.tolerance_percent / 100)
- def tc_bandwidth_bound(self, value, tc_ix):
+ def bound(self, values):
"""
- Returns True if the given bandwidth value is within tolerance
- for the TC's expected bandwidth.
+ Return True if all given values fall within tolerance.
"""
- expected = self.tc_expected_percent[tc_ix]
- return self.bound(expected, value)
+ for name, value in values.items():
+ low, high = self.bounds[name]
+ if not low <= value <= high:
+ return False
+ return True
def setup_vf(cfg, set_tc_mapping=True):
@@ -353,38 +349,26 @@ def verify_total_bandwidth(bw_data, validator):
"""
total = bw_data['total_bw']
- if validator.bound(validator.expected_total_gbps, total):
+ if validator.bound({"total": total}):
return
- if total < validator.total_min_expected:
+ low, high = validator.bounds["total"]
+
+ if total < low:
raise KsftSkipEx(
f"Total bandwidth {total:.2f} Gbps < minimum "
- f"{validator.total_min_expected:.2f} Gbps; "
- f"parent tx_max ({validator.expected_total_gbps:.1f} G) "
+ f"{low:.2f} Gbps; "
+ f"parent tx_max ({validator.expected_total:.1f} G) "
f"not reached, cannot validate share"
)
raise KsftFailEx(
f"Total bandwidth {total:.2f} Gbps exceeds allowed ceiling "
- f"{validator.total_max_expected:.2f} Gbps "
- f"(VF tx_max set to {validator.expected_total_gbps:.1f} G)"
+ f"{high:.2f} Gbps "
+ f"(VF tx_max set to {validator.expected_total:.1f} G)"
)
-def check_bandwidth_distribution(bw_data, validator):
- """
- Checks whether the measured TC3 and TC4 bandwidth percentages
- fall within their expected tolerance ranges.
-
- Returns:
- bool: True if both TC3 and TC4 percentages are within bounds.
- """
- tc3_valid = validator.tc_bandwidth_bound(bw_data['tc3_percentage'], 3)
- tc4_valid = validator.tc_bandwidth_bound(bw_data['tc4_percentage'], 4)
-
- return tc3_valid and tc4_valid
-
-
def run_bandwidth_distribution_test(cfg, set_tc_mapping):
"""
Runs parallel bandwidth measurements for both TCs and collects results.
@@ -395,9 +379,10 @@ def run_bandwidth_distribution_test(cfg, set_tc_mapping):
test_name = "with TC mapping" if set_tc_mapping else "without TC mapping"
print_bandwidth_results(bw_data, test_name)
- verify_total_bandwidth(bw_data, cfg.bw_validator)
+ verify_total_bandwidth(bw_data, cfg.traffic_bw_validator)
- return check_bandwidth_distribution(bw_data, cfg.bw_validator)
+ return cfg.tc_bw_validator.bound({"tc3": bw_data['tc3_percentage'],
+ "tc4": bw_data['tc4_percentage']})
def test_no_tc_mapping_bandwidth(cfg):
@@ -441,7 +426,8 @@ def main() -> None:
if not cfg.pci:
raise KsftSkipEx("Could not get PCI address of the interface")
- cfg.bw_validator = BandwidthValidator()
+ cfg.traffic_bw_validator = BandwidthValidator({"total": 1})
+ cfg.tc_bw_validator = BandwidthValidator({"tc3": 20, "tc4": 80})
cases = [test_no_tc_mapping_bandwidth, test_tc_mapping_bandwidth]
--
2.38.1
prev parent reply other threads:[~2025-11-20 10:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-20 9:58 [PATCH net-next 0/6] selftests: drv-net: Fix issues in devlink_rate_tc_bw.py Carolina Jubran
2025-11-20 9:58 ` [PATCH net-next 1/6] selftests: drv-net: Add devlink_rate_tc_bw.py to TEST_PROGS Carolina Jubran
2025-11-21 3:03 ` Jakub Kicinski
2025-11-20 9:58 ` [PATCH net-next 2/6] selftests: drv-net: introduce Iperf3Runner for measurement use cases Carolina Jubran
2025-11-20 9:58 ` [PATCH net-next 3/6] selftests: drv-net: Use Iperf3Runner in devlink_rate_tc_bw.py Carolina Jubran
2025-11-20 9:58 ` [PATCH net-next 4/6] selftests: drv-net: Set shell=True for sysfs writes " Carolina Jubran
2025-11-20 9:58 ` [PATCH net-next 5/6] selftests: drv-net: Fix and clarify TC bandwidth split " Carolina Jubran
2025-11-20 9:58 ` Carolina Jubran [this message]
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=20251120095859.2951339-7-cjubran@nvidia.com \
--to=cjubran@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=cratiu@nvidia.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=noren@nvidia.com \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=tariqt@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).