tools/testing/selftests/drivers/net/hw/tso.py
Source file repositories/reference/linux-study-clean/tools/testing/selftests/drivers/net/hw/tso.py
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/drivers/net/hw/tso.py- Extension
.py- Size
- 10784 bytes
- Lines
- 268
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
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
"""Run the tools/testing/selftests/net/csum testsuite."""
import fcntl
import socket
import struct
import termios
import time
from lib.py import ksft_pr, ksft_run, ksft_exit, KsftSkipEx, KsftXfailEx
from lib.py import ksft_eq, ksft_ge, ksft_lt
from lib.py import EthtoolFamily, NetdevFamily, NetDrvEpEnv
from lib.py import bkg, cmd, defer, ethtool, ip, rand_port, wait_port_listen
def sock_wait_drain(sock, max_wait=1000):
"""Wait for all pending write data on the socket to get ACKed."""
for _ in range(max_wait):
one = b'\0' * 4
outq = fcntl.ioctl(sock.fileno(), termios.TIOCOUTQ, one)
outq = struct.unpack("I", outq)[0]
if outq == 0:
break
time.sleep(0.01)
ksft_eq(outq, 0)
def tcp_sock_get_retrans(sock):
"""Get the number of retransmissions for the TCP socket."""
info = sock.getsockopt(socket.SOL_TCP, socket.TCP_INFO, 512)
return struct.unpack("I", info[100:104])[0]
def run_one_stream(cfg, ipver, remote_v4, remote_v6, should_lso):
cfg.require_cmd("socat", local=False, remote=True)
# Set recv window clamp to avoid overwhelming receiver on debug kernels
# the 200k clamp should still let use reach > 15Gbps on real HW
port = rand_port()
listen_opts = f"{port},reuseport,tcp-window-clamp=200000"
listen_cmd = f"socat -{ipver} -t 2 -u TCP-LISTEN:{listen_opts} /dev/null,ignoreeof"
with bkg(listen_cmd, host=cfg.remote, exit_wait=True) as nc:
wait_port_listen(port, host=cfg.remote)
if ipver == "4":
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((remote_v4, port))
else:
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
sock.connect((remote_v6, port))
# Small send to make sure the connection is working.
sock.send("ping".encode())
sock_wait_drain(sock)
# Send 4MB of data, record the LSO packet count.
qstat_old = cfg.netnl.qstats_get({"ifindex": cfg.ifindex}, dump=True)[0]
buf = b"0" * 1024 * 1024 * 4
sock.send(buf)
sock_wait_drain(sock)
qstat_new = cfg.netnl.qstats_get({"ifindex": cfg.ifindex}, dump=True)[0]
# Check that at least 90% of the data was sent as LSO packets.
# System noise may cause false negatives. Also header overheads
# will add up to 5% of extra packes... The check is best effort.
total_lso_wire = len(buf) * 0.90 // cfg.dev["mtu"]
total_lso_super = len(buf) * 0.90 // cfg.dev["tso_max_size"]
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.