analyse-pcap: count UDP, because ROM streaming is UDP/FSP not TCP

The 850 KB/s dump measurement does not bound ROM streaming, and the tool could
not have measured streaming at all: it only counted TCP payload, so a
streaming capture would have reported ~zero throughput.

Swiss's ROM streaming runs in the game via the patch driver's own stack
(cube/patches/bba/tcpip.c), which contains no TCP whatsoever -- UDP + FSP,
plus ICMP and ARP.  Reads are sized to the path MTU rather than 1024:

  _fsp.data_length = MIN(length, env->pmtu - (fsp->data - eth->data));

so ~1446 B of payload per datagram at a 1500 MTU, with QUEUE_SIZE 2
outstanding and udp->checksum = 0x0000 (no payload checksum).  None of the
menu path's TCP window, lwIP overhead or 1024-byte writes apply.

The analyser now counts UDP payload and picks the bulk direction by which way
the payload actually flows -- streaming is PC -> GC, the opposite of a disc
dump -- with --bulk to_gc to steer the gap analysis.  Self-test H replays the
streaming shape (1446 B datagrams, 2 per request) and checks the bulk
direction is identified and the payload counted.

Recorded in the TODO that "can it stream?" is still OPEN, but open on the GC's
side: the dump established the adapter has headroom (zero retransmissions,
~17% W5100 bus utilisation, 26% of the EXI ceiling).  The hard ceiling is
3375 KB/s and the GC's disc delivers ~2000-3100 KB/s, so full disc rate has no
margin -- but games read in bursts, not continuously at peak.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 15:32:45 +02:00
parent d8ddea13ba
commit 4e7a2ef429
3 changed files with 103 additions and 4 deletions
+36 -4
View File
@@ -61,11 +61,20 @@ def main():
ap.add_argument("pcap")
ap.add_argument("--gc-ip", default="10.0.0.64")
ap.add_argument("--top-gaps", type=int, default=5)
ap.add_argument("--bulk", choices=("auto", "from_gc", "to_gc"),
default="auto",
help="which direction carries the payload; 'auto' guesses "
"GC->PC (a disc dump). ROM streaming is to_gc.")
a = ap.parse_args()
gc = socket.inet_aton(a.gc_ip)
stats = {d: dict(pkts=0, wire=0, payload=0, retx=0, sizes=[], zerowin=0)
for d in ("from_gc", "to_gc")}
# Which direction carries the bulk is not knowable until the end, so the
# gap analysis needs a hint up front. Two passes would be cleaner; one
# pass with a hint is enough, and the hint only affects which direction's
# inter-frame gaps get recorded.
bulk_hint = a.bulk if a.bulk != "auto" else "from_gc"
seen = {d: set() for d in ("from_gc", "to_gc")}
t0 = t1 = None
wins, gaps, last_ts = [], [], None
@@ -95,6 +104,22 @@ def main():
s["pkts"] += 1
s["wire"] += orig
s["sizes"].append(orig)
if ip[9] == socket.IPPROTO_UDP:
# ROM streaming (Swiss's in-game patch driver) is UDP + FSP, with
# no TCP anywhere -- so without this the tool reports a streaming
# capture as zero throughput.
udp = ip[ihl:]
if len(udp) >= 8:
ulen = struct.unpack("!H", udp[4:6])[0]
s["payload"] += max(ulen - 8, 0)
s["udp"] = s.get("udp", 0) + 1
if d == "from_gc" or d == "to_gc":
pass
if d == bulk_hint:
if last_ts is not None:
gaps.append((ts - last_ts, ts))
last_ts = ts
continue
if ip[9] != socket.IPPROTO_TCP:
continue
tcp = ip[ihl:]
@@ -164,13 +189,20 @@ def main():
# window / RTT no matter how fast the wire or the adapter is. Derive the
# round trip from the capture itself -- one ACK is one round trip -- so
# this needs no ping and no assumptions.
data_pkts = stats["from_gc"]["pkts"]
acks = stats["to_gc"]["pkts"]
payload = stats["from_gc"]["payload"]
# Bulk = whichever direction actually moved the payload.
bulk = max(("from_gc", "to_gc"), key=lambda d: stats[d]["payload"])
back = "to_gc" if bulk == "from_gc" else "from_gc"
data_pkts = stats[bulk]["pkts"]
acks = stats[back]["pkts"]
payload = stats[bulk]["payload"]
if payload:
print(f"\nbulk direction: {'GC -> PC' if bulk == 'from_gc' else 'PC -> GC'}"
f" ({stats[bulk].get('udp', 0)} UDP, "
f"{data_pkts - stats[bulk].get('udp', 0)} TCP frames)")
if acks and payload:
per_rt = payload / acks
rtt = dur / acks
print(f"\nround-trip analysis (bulk direction GC -> PC)")
print(f"round-trip analysis")
print(f" {data_pkts/acks:.1f} data frames per ACK, "
f"{per_rt:.0f} B per round trip, "
f"implied RTT {rtt*1000:.2f} ms")
+33
View File
@@ -158,6 +158,39 @@ else:
print("G 1024B segments + 2920B window -> window x RTT bound,")
print(" full-MSS suggested, coalescing warned against")
def udp_frame(src, dst, smac, dmac, payload):
udp = struct.pack("!HHHH", 7717, 7717, 8 + len(payload), 0) + payload
ip = struct.pack("!BBHHHBBH4s4s", 0x45, 0, 20 + len(udp), 0, 0, 64,
socket.IPPROTO_UDP, 0, src, dst)
return dmac + smac + b"\x08\x00" + ip + udp
# Scenario H: ROM streaming shape -- UDP/FSP, bulk flowing PC -> GC, with
# small requests going the other way. Before UDP was counted this reported
# zero throughput, because Swiss's in-game stack has no TCP at all.
pkts, t = [], 7000.0
for i in range(300):
pkts.append((t, udp_frame(GC, PC, MAC_GC, MAC_PC, b"\0" * 20))) # request
t += 0.0001
for _ in range(2): # 2 queued
pkts.append((t, udp_frame(PC, GC, MAC_PC, MAC_GC, b"\0" * 1446)))
t += 0.0002
t += 0.0008
pH = os.path.join(tmp, "h.pcap")
write_pcap(pH, pkts)
out = run(pH, "--bulk", "to_gc")
if "bulk direction: PC -> GC" not in out:
fails.append(f"H: bulk direction not detected as PC->GC\n{out}")
elif "UDP" not in out:
fails.append(f"H: UDP frames not counted\n{out}")
else:
# 600 x 1446 B over ~0.39 s should be well above 1 MB/s
kbs = float(out.split("throughput")[2].split("KB/s")[0].strip())
if kbs < 500:
fails.append(f"H: UDP payload undercounted, {kbs} KB/s")
else:
print(f"H UDP/FSP streaming shape -> bulk PC->GC, {kbs:.0f} KB/s")
print("\nFAILURES:\n " + "\n ".join(fails) if fails else
"\nAll analyse-pcap self-tests passed.")
sys.exit(1 if fails else 0)