Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions tools/test_e1000e_qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,27 @@ def tcp_client(client, key):
continue
if not data:
break
client.sendall(data)
with counter_lock:
counts[key] += len(data)
except OSError:
# A saturated guest may temporarily close its TCP window.
# Preserve the exact unsent suffix across timeout/short writes;
# the short socket timeout exists to observe shutdown, not to
# abort an otherwise healthy stream under backpressure.
pending = memoryview(data)
while pending and not stop.is_set():
try:
sent = client.send(pending)
except socket.timeout:
continue
if not sent:
raise ConnectionError("TCP echo peer stopped accepting data")
pending = pending[sent:]
with counter_lock:
counts[key] += sent
except OSError as error:
if not stop.is_set():
with counter_lock:
counts.setdefault("client_errors", 0)
counts["client_errors"] += 1
counts["client_last_error"] = repr(error)
finally:
client.close()

Expand Down
89 changes: 89 additions & 0 deletions tools/test_vmxnet3_performance_qemu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
"""Measure verified TCP echo, guest CPU accounting and UDP latency in QEMU."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import re
import subprocess

from test_e1000e_qemu import echo_peers
from test_multi_nic_qemu import prepare

ROOT = Path(__file__).resolve().parents[1]


def main():
parser = argparse.ArgumentParser(description=__doc__)
for name in ("install", "busybox", "probe", "output"):
parser.add_argument("--" + name, type=Path, required=True)
parser.add_argument("--modular", action="store_true")
parser.add_argument("--expect-msix", action="store_true")
parser.add_argument("--bytes", type=int, default=8 * 1024 * 1024)
parser.add_argument("--rounds", type=int, default=2)
args = parser.parse_args()
for name in ("install", "busybox", "probe", "output"):
setattr(args, name, getattr(args, name).resolve())
if args.output.exists() or not args.output.is_relative_to(ROOT / "out"):
parser.error("output must be a new directory within this checkout's out")
if not 1 <= args.rounds <= 5 or not 1 <= args.bytes <= 1024 ** 3:
parser.error("rounds/bytes exceed the bounded probe limits")
args.output.mkdir(parents=True)
result = {"passed": False, "platform": "QEMU/KVM", "vmware_verified": False}
with echo_peers() as (port, counts):
def script(port, modular):
load = "modprobe vmxnet3\n" if modular else ""
return f'''#!/bin/sh
export PATH=/bin
exec </dev/console >/dev/ttyS0 2>&1
finish() {{
status=$?
echo VMXNET3_PERF_DONE:status=$status
poweroff -f
}}
trap finish EXIT
set -eu
{load}udhcpc -f -n -q -i eth0 -s /dhcp-script -t 4 -T 1
for round in $(seq 1 {args.rounds}); do
/probe eth0 10.0.2.2 {port} {args.bytes}
done
cat /proc/net/dev /proc/interrupts
'''
iso, manifest = prepare(args, port, script_factory=script)
serial = args.output / "serial.log"
command = ["qemu-system-x86_64", "-machine", "q35", "-accel", "kvm", "-cpu", "host",
"-m", "1024", "-smp", "2", "-vga", "std", "-display", "none",
"-serial", "file:" + str(serial), "-cdrom", str(iso), "-boot", "d",
"-netdev", "user,id=net0", "-device", "vmxnet3,netdev=net0", "-no-reboot"]
result.update(command=command, release=manifest["release"],
kernel_sha256=manifest["files"]["kernel.sys"]["sha256"],
probe_sha256=hashlib.sha256(args.probe.read_bytes()).hexdigest())
try:
with (args.output / "qemu.log").open("w") as log:
completed = subprocess.run(command, stdout=log, stderr=log,
env={**os.environ, "TMPDIR": str(ROOT / "out/tmp")}, timeout=300)
text = serial.read_text(errors="replace")
samples = [json.loads(row) for row in re.findall(r"VMXNET3_PERF (\{[^\r\n]+\})", text)]
if completed.returncode or "VMXNET3_PERF_DONE:status=0" not in text or len(samples) != args.rounds:
raise AssertionError("guest benchmark did not complete")
if args.expect_msix and "irq=msix" not in text:
raise AssertionError("MSI-X was not selected")
if counts["tcp4"] != args.bytes * args.rounds or counts["udp4"] != 128 * args.rounds:
raise AssertionError(f"echo counters differ: {counts}")
for sample in samples:
sample["echo_payload_mib_s"] = round(sample["bytes"] * 1e9 / sample["elapsed_ns"] / 1024 ** 2, 3)
sample["guest_cpu_busy_pct"] = round(100 * sample["cpu_busy_ticks"] / max(1, sample["cpu_total_ticks"]), 2)
result.update(passed=True, samples=samples, echoes=dict(counts))
except Exception as error:
result["error"] = repr(error)
raise
finally:
result["echoes"] = dict(counts)
(args.output / "result.json").write_text(json.dumps(result, indent=2) + "\n")
print(json.dumps(result, indent=2))


if __name__ == "__main__":
main()
11 changes: 9 additions & 2 deletions tools/test_vmxnet3_qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import hashlib
import json
import os
import re
from pathlib import Path
import subprocess
import time
Expand Down Expand Up @@ -82,7 +83,7 @@ def guest_script(port, modular):
wait "$third"
echo VMXNET3_CONCURRENT_PASS
{lifecycle}
cat /proc/net/dev
cat /proc/net/dev /proc/interrupts
ip addr show
echo VMXNET3_QEMU_PASS
'''
Expand Down Expand Up @@ -144,12 +145,18 @@ def main():
raise AssertionError("missing guest result " + marker)
if "MULTINIC_FAIL" in text or "Kernel Panic" in text or process.returncode:
raise AssertionError("guest failed")
if text.count("irq=msix") < 2:
raise AssertionError("both VMXNET3 controllers must negotiate MSI-X")
messages = re.findall(r"(?m)^8[01]:\s+(\d+)\s+(\d+)\s+.*PCI-MSI", text)
if len(messages) < 2 or any(sum(map(int, row)) == 0 for row in messages):
raise AssertionError("missing real MSI-X interrupts for both VMXNET3 controllers")
expected_counts = ({"tcp4": 266240, "tcp6": 73728, "udp4": 24, "udp6": 24}
if args.modular else
{"tcp4": 36864, "tcp6": 36864, "udp4": 12, "udp6": 12})
if any(counts[key] != value for key, value in expected_counts.items()):
raise AssertionError(f"host echo counts differ: {counts}")
result.update(passed=True, returncode=process.returncode, echoes=dict(counts))
result.update(passed=True, returncode=process.returncode, echoes=dict(counts),
msix_messages=[sum(map(int, row)) for row in messages])
except Exception as error:
result["error"] = repr(error)
raise
Expand Down
Loading