Path: blob/master/tools/testing/selftests/drivers/net/hw/rss_drv.py
121896 views
#!/usr/bin/env python31# SPDX-License-Identifier: GPL-2.023"""4Driver-related behavior tests for RSS.5"""67from lib.py import ksft_run, ksft_exit, ksft_ge8from lib.py import ksft_variants, KsftNamedVariant, KsftSkipEx9from lib.py import defer, ethtool10from lib.py import EthtoolFamily, NlError11from lib.py import NetDrvEnv121314def _is_power_of_two(n):15return n > 0 and (n & (n - 1)) == 0161718def _get_rss(cfg, context=0):19return ethtool(f"-x {cfg.ifname} context {context}", json=True)[0]202122def _test_rss_indir_size(cfg, qcnt, context=0):23"""Test that indirection table size is at least 4x queue count."""24ethtool(f"-L {cfg.ifname} combined {qcnt}")2526rss = _get_rss(cfg, context=context)27indir = rss['rss-indirection-table']28ksft_ge(len(indir), 4 * qcnt, "Table smaller than 4x")29return len(indir)303132def _maybe_create_context(cfg, create_context):33""" Either create a context and return its ID or return 0 for main ctx """34if not create_context:35return 036try:37ctx = cfg.ethnl.rss_create_act({'header': {'dev-index': cfg.ifindex}})38ctx_id = ctx['context']39defer(cfg.ethnl.rss_delete_act,40{'header': {'dev-index': cfg.ifindex}, 'context': ctx_id})41except NlError:42raise KsftSkipEx("Device does not support additional RSS contexts")4344return ctx_id454647@ksft_variants([48KsftNamedVariant("main", False),49KsftNamedVariant("ctx", True),50])51def indir_size_4x(cfg, create_context):52"""53Test that the indirection table has at least 4 entries per queue.54Empirically network-heavy workloads like memcache suffer with the 33%55imbalance of a 2x indirection table size.564x table translates to a 16% imbalance.57"""58channels = cfg.ethnl.channels_get({'header': {'dev-index': cfg.ifindex}})59ch_max = channels.get('combined-max', 0)60qcnt = channels['combined-count']6162if ch_max < 3:63raise KsftSkipEx(f"Not enough queues for the test: max={ch_max}")6465defer(ethtool, f"-L {cfg.ifname} combined {qcnt}")66ethtool(f"-L {cfg.ifname} combined 3")6768ctx_id = _maybe_create_context(cfg, create_context)6970indir_sz = _test_rss_indir_size(cfg, 3, context=ctx_id)7172# Test with max queue count (max - 1 if max is a power of two)73test_max = ch_max - 1 if _is_power_of_two(ch_max) else ch_max74if test_max > 3 and indir_sz < test_max * 4:75_test_rss_indir_size(cfg, test_max, context=ctx_id)767778def main() -> None:79""" Ksft boiler plate main """80with NetDrvEnv(__file__) as cfg:81cfg.ethnl = EthtoolFamily()82ksft_run([indir_size_4x], args=(cfg, ))83ksft_exit()848586if __name__ == "__main__":87main()888990