Path: blob/master/tools/testing/selftests/drivers/net/napi_threaded.py
26288 views
#!/usr/bin/env python31# SPDX-License-Identifier: GPL-2.023"""4Test napi threaded states.5"""67from lib.py import ksft_run, ksft_exit8from lib.py import ksft_eq, ksft_ne, ksft_ge9from lib.py import NetDrvEnv, NetdevFamily10from lib.py import cmd, defer, ethtool111213def _assert_napi_threaded_enabled(nl, napi_id) -> None:14napi = nl.napi_get({'id': napi_id})15ksft_eq(napi['threaded'], 'enabled')16ksft_ne(napi.get('pid'), None)171819def _assert_napi_threaded_disabled(nl, napi_id) -> None:20napi = nl.napi_get({'id': napi_id})21ksft_eq(napi['threaded'], 'disabled')22ksft_eq(napi.get('pid'), None)232425def _set_threaded_state(cfg, threaded) -> None:26cmd(f"echo {threaded} > /sys/class/net/{cfg.ifname}/threaded")272829def _setup_deferred_cleanup(cfg) -> None:30combined = ethtool(f"-l {cfg.ifname}", json=True)[0].get("combined", 0)31ksft_ge(combined, 2)32defer(ethtool, f"-L {cfg.ifname} combined {combined}")3334threaded = cmd(f"cat /sys/class/net/{cfg.ifname}/threaded").stdout35defer(_set_threaded_state, cfg, threaded)3637return combined383940def enable_dev_threaded_disable_napi_threaded(cfg, nl) -> None:41"""42Test that when napi threaded is enabled at device level and43then disabled at napi level for one napi, the threaded state44of all napis is preserved after a change in number of queues.45"""4647napis = nl.napi_get({'ifindex': cfg.ifindex}, dump=True)48ksft_ge(len(napis), 2)4950napi0_id = napis[0]['id']51napi1_id = napis[1]['id']5253qcnt = _setup_deferred_cleanup(cfg)5455# set threaded56_set_threaded_state(cfg, 1)5758# check napi threaded is set for both napis59_assert_napi_threaded_enabled(nl, napi0_id)60_assert_napi_threaded_enabled(nl, napi1_id)6162# disable threaded for napi163nl.napi_set({'id': napi1_id, 'threaded': 'disabled'})6465cmd(f"ethtool -L {cfg.ifname} combined 1")66cmd(f"ethtool -L {cfg.ifname} combined {qcnt}")67_assert_napi_threaded_enabled(nl, napi0_id)68_assert_napi_threaded_disabled(nl, napi1_id)697071def change_num_queues(cfg, nl) -> None:72"""73Test that when napi threaded is enabled at device level,74the napi threaded state is preserved after a change in75number of queues.76"""7778napis = nl.napi_get({'ifindex': cfg.ifindex}, dump=True)79ksft_ge(len(napis), 2)8081napi0_id = napis[0]['id']82napi1_id = napis[1]['id']8384qcnt = _setup_deferred_cleanup(cfg)8586# set threaded87_set_threaded_state(cfg, 1)8889# check napi threaded is set for both napis90_assert_napi_threaded_enabled(nl, napi0_id)91_assert_napi_threaded_enabled(nl, napi1_id)9293cmd(f"ethtool -L {cfg.ifname} combined 1")94cmd(f"ethtool -L {cfg.ifname} combined {qcnt}")9596# check napi threaded is set for both napis97_assert_napi_threaded_enabled(nl, napi0_id)98_assert_napi_threaded_enabled(nl, napi1_id)99100101def main() -> None:102""" Ksft boiler plate main """103104with NetDrvEnv(__file__, queue_count=2) as cfg:105ksft_run([change_num_queues,106enable_dev_threaded_disable_napi_threaded],107args=(cfg, NetdevFamily()))108ksft_exit()109110111if __name__ == "__main__":112main()113114115