tools/testing/selftests/drivers/net/napi_threaded.py
Source file repositories/reference/linux-study-clean/tools/testing/selftests/drivers/net/napi_threaded.py
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/drivers/net/napi_threaded.py- Extension
.py- Size
- 4109 bytes
- Lines
- 144
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
"""
Test napi threaded states.
"""
from lib.py import ksft_run, ksft_exit
from lib.py import ksft_eq, ksft_ne, ksft_ge
from lib.py import NetDrvEnv, NetdevFamily
from lib.py import cmd, defer, ethtool
def _assert_napi_threaded_enabled(nl, napi_id) -> None:
napi = nl.napi_get({'id': napi_id})
ksft_eq(napi['threaded'], 'enabled')
ksft_ne(napi.get('pid'), None)
def _assert_napi_threaded_disabled(nl, napi_id) -> None:
napi = nl.napi_get({'id': napi_id})
ksft_eq(napi['threaded'], 'disabled')
ksft_eq(napi.get('pid'), None)
def _set_threaded_state(cfg, threaded) -> None:
with open(f"/sys/class/net/{cfg.ifname}/threaded", "wb") as fp:
fp.write(str(threaded).encode('utf-8'))
def _setup_deferred_cleanup(cfg) -> None:
combined = ethtool(f"-l {cfg.ifname}", json=True)[0].get("combined", 0)
ksft_ge(combined, 2)
defer(ethtool, f"-L {cfg.ifname} combined {combined}")
threaded = cmd(f"cat /sys/class/net/{cfg.ifname}/threaded").stdout
defer(_set_threaded_state, cfg, threaded)
return combined
def napi_init(cfg, nl) -> None:
"""
Test that threaded state (in the persistent NAPI config) gets updated
even when NAPI with given ID is not allocated at the time.
"""
qcnt = _setup_deferred_cleanup(cfg)
_set_threaded_state(cfg, 1)
cmd(f"ethtool -L {cfg.ifname} combined 1")
_set_threaded_state(cfg, 0)
cmd(f"ethtool -L {cfg.ifname} combined {qcnt}")
napis = nl.napi_get({'ifindex': cfg.ifindex}, dump=True)
for napi in napis:
ksft_eq(napi['threaded'], 'disabled')
ksft_eq(napi.get('pid'), None)
cmd(f"ethtool -L {cfg.ifname} combined 1")
_set_threaded_state(cfg, 1)
cmd(f"ethtool -L {cfg.ifname} combined {qcnt}")
napis = nl.napi_get({'ifindex': cfg.ifindex}, dump=True)
for napi in napis:
ksft_eq(napi['threaded'], 'enabled')
ksft_ne(napi.get('pid'), None)
def enable_dev_threaded_disable_napi_threaded(cfg, nl) -> None:
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.