Files
nvdriver/tools/check_original_live_timer_init.py
morebrackets a5cde383de Address Greptile review findings on #301
- tools/check_original_live_timer_init.py (4777572276): record incomplete
  default (_nv059507rm) and config (_nv059487rm) register samples in rejected
  so missing registers cannot pass all_28_samples_parsed.
- tools/gpu_engine_dispatch_sites.py (4777572295): verify nvidia.ko .modinfo
  version (580.178.04) and relative symbol offsets match the kallsyms capture
  snapshot before generating breakpoint sites.
- tools/gpu_label_live_engines.py (4777572314): verify open-gpu-kernel-modules
  release metadata (version.mk / nvUnixVersion.h == 580.178.04) before
  accepting a generated/ directory from OPEN_GPU_ROOT/NV_RS_OPEN_GPU_SRC or
  --generated-dir, and replace hardcoded /home/geodd default with Path.home().
- tests/offline/test_build_product_and_live_timer_tools.py: add unit tests
  covering all three guards.
2026-12-02 16:52:59 -08:00

134 lines
7.3 KiB
Python

#!/usr/bin/env python3
"""Validate the finite closed-driver timeout/Timer StateLoad capture.
Function entries establish attempted calls and argument values, not returns.
This checker makes no replacement-driver or other-hardware parity claim.
"""
import argparse
from collections import Counter
import hashlib
import json
from pathlib import Path
import re
def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("report_directory", type=Path)
args = parser.parse_args(argv)
root = args.report_directory
required = ("before.json", "after.json", "rea-capture.json", "perf-script.txt", "perf-dump.txt", "perf.data")
for rel in required:
if not (root / rel).is_file():
raise SystemExit(f"missing required capture file: {root / rel}")
before = json.loads((root / "before.json").read_text(encoding="utf-8"))
after = json.loads((root / "after.json").read_text(encoding="utf-8"))
raw = json.loads((root / "rea-capture.json").read_text(encoding="utf-8"))
evidence = raw.get("structuredContent")
if evidence is None:
text_chunk = next((c["text"] for c in raw.get("content", ()) if c.get("type") == "text"), None)
if text_chunk is None:
raise SystemExit(f"no text content entry in {root / 'rea-capture.json'}")
evidence = json.loads(text_chunk)
capture = evidence["normalized_result"]
pattern = re.compile(
r"^\s*(\S+)\s+(\d+)/(\d+)\s+(\d+)\.(\d{9}):\s+"
r"mem:(0x[0-9a-f]+):x:\s+([0-9a-f]+)\s+(_nv\d+rm)\s+ABI:2(.*)$"
)
events, rejected = [], []
for line in (root / "perf-script.txt").read_text(encoding="utf-8").splitlines():
if not line.strip():
continue
match = pattern.fullmatch(line)
if match is None:
rejected.append(line)
continue
comm, pid, tid, sec, ns, address, ip, name, registers = match.groups()
events.append({
"comm": comm, "pid": int(pid), "tid": int(tid),
"perf_time_ns": int(sec) * 1_000_000_000 + int(ns),
"address": address, "ip": "0x" + ip, "symbol": name,
"registers": dict(re.findall(r"\b(AX|CX|DX|SI|DI):(0x[0-9a-f]+)", registers)),
})
defaults = []
for e in events:
if e["symbol"] != "_nv059507rm":
continue
if "DI" not in e["registers"] or "SI" not in e["registers"]:
rejected.append(f"incomplete registers on default sample at {e['perf_time_ns']}")
continue
defaults.append(e)
configs = []
for e in events:
if e["symbol"] != "_nv059487rm":
continue
if "DI" not in e["registers"] or "SI" not in e["registers"] or "DX" not in e["registers"]:
rejected.append(f"incomplete registers on config sample at {e['perf_time_ns']}")
continue
configs.append(e)
loads = [e for e in events if e["symbol"] == "_nv059665rm"]
groups = []
for load in loads:
regs = load["registers"]
gpu = regs.get("DI")
timer = regs.get("SI")
dx = regs.get("DX")
if gpu is None or timer is None or dx is None:
rejected.append(f"incomplete registers on load sample at {load['perf_time_ns']}")
continue
ds = [e for e in defaults if e["registers"]["SI"] == gpu]
cs = [e for e in configs if e["registers"]["DI"] == gpu]
groups.append({
"gpu_owner": gpu, "timer_owner": timer,
"load_flags": int(dx, 16),
"default_data_offsets": [int(e["registers"]["DI"], 16) - int(gpu, 16) for e in ds],
"timeout_us": [int(e["registers"]["SI"], 16) for e in cs],
"timeout_flags": [int(e["registers"]["DX"], 16) for e in cs],
"initial_order": bool(ds and cs and ds[0]["perf_time_ns"] < cs[0]["perf_time_ns"] < load["perf_time_ns"]),
})
dump = (root / "perf-dump.txt").read_text(encoding="utf-8")
losses = {name: dump.count(name) for name in (
"PERF_RECORD_LOST", "PERF_RECORD_THROTTLE", "PERF_RECORD_UNTHROTTLE")}
output = "".join(frame["data"] for frame in capture["frames"])
checks = {
"original_cuda_passed_64_words_and_destroyed_context": capture["exit"]["code"] == 0
and all(s in output for s in ('"passed":true', '"verified_words":64', '"context_destroyed":true')),
"all_28_samples_parsed": len(events) == 28 and not rejected,
"function_addresses_match_snapshot": all(
e["address"] == e["ip"] == before["symbols"].get(e["symbol"]) for e in events
),
"ordered_perf_timestamps": all(a["perf_time_ns"] <= b["perf_time_ns"] for a, b in zip(events, events[1:])),
"no_reported_loss_or_throttle": not any(losses.values()),
"eight_distinct_gpu_and_timer_owners": len(groups) == len({g["gpu_owner"] for g in groups}) == len({g["timer_owner"] for g in groups}) == 8,
"per_owner_default_then_thread_config_then_timer_load": bool(groups) and all(g["initial_order"] for g in groups),
"all_observed_data_to_gpu_argument_offsets_match_1e08": bool(groups) and all(g["default_data_offsets"] and all(v == 0x1e08 for v in g["default_data_offsets"]) for g in groups),
"all_initial_configs_4s_os_timer_and_load_flags_zero": bool(groups) and all(
bool(g["timeout_us"]) and g["timeout_us"][0] == 4_000_000 and all(f == 8 for f in g["timeout_flags"]) and g["load_flags"] == 0
for g in groups
),
"one_owner_4s_30s_4s_seven_owners_4s": Counter(tuple(g["timeout_us"]) for g in groups) == Counter({(4_000_000,): 7, (4_000_000, 30_000_000, 4_000_000): 1}),
"retained_input_hashes_match": before["sha256"] == after["sha256"],
"eight_original_gpu_bindings_unchanged": len(before["bindings"]) == 8 and before["bindings"] == after["bindings"] and set(after["bindings"].values()) == {"nvidia"},
"runtime_addresses_unchanged": before["symbols"] == after["symbols"],
"recorded_perf_file_matches": after["perf_sha256"] == hashlib.sha256((root / "perf.data").read_bytes()).hexdigest(),
}
report = {
"passed": all(checks.values()), "checks": checks,
"rea_capture_evidence": evidence["evidence_id"],
"counts": dict(Counter(e["symbol"] for e in events)),
"record_loss_diagnostics": losses, "gpu_groups": groups,
"events": events, "rejected": rejected,
"scope": "One finite original580 V100 per-open/context lifecycle; entry attempts only. No mapping of object pointers to BDFs, function return proof, boot/probe capture, deferred-worker coverage, other-hardware support, performance baseline or Rust readiness.",
"unobserved_path": "No059564 OS-relative entry was sampled on these workload threads. This does not establish path absence or an empty OS-event list.",
"interpretation": "The 4s/30s/4s transition agrees with separately instruction-proven compute-reference policy; computeRefCount itself was not sampled.",
"related_static_proof": "reports/timer-timeout-provenance.json",
"rea_process_sampling_limits": evidence["limitations"],
}
(root / "validation.json").write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8")
print(json.dumps({"passed": report["passed"], "checks": checks, "counts": report["counts"]}, indent=2))
return 0 if report["passed"] else 1
if __name__ == "__main__":
raise SystemExit(main())