|
@@ -3,12 +3,17 @@
|
|
|
Each lane uses an independent work root and receipt. A failed lane does not
|
|
Each lane uses an independent work root and receipt. A failed lane does not
|
|
|
cancel unrelated lanes. Missing toolchains produce `blocked` or `not_run`, never
|
|
cancel unrelated lanes. Missing toolchains produce `blocked` or `not_run`, never
|
|
|
a fabricated pass. Long tasks use tools/run_visible.py for live heartbeat.
|
|
a fabricated pass. Long tasks use tools/run_visible.py for live heartbeat.
|
|
|
|
|
+
|
|
|
|
|
+Resource classes (light / medium / heavy / exclusive) are derived from host
|
|
|
|
|
+nproc, MemAvailable, and free disk. Formal concurrency is memory-capped. TD is
|
|
|
|
|
+always exclusive (serialized after open-source lanes, with a lock file).
|
|
|
"""
|
|
"""
|
|
|
from __future__ import annotations
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import argparse
|
|
import argparse
|
|
|
import json
|
|
import json
|
|
|
import os
|
|
import os
|
|
|
|
|
+import shutil
|
|
|
import sys
|
|
import sys
|
|
|
import time
|
|
import time
|
|
|
import uuid
|
|
import uuid
|
|
@@ -33,10 +38,26 @@ DEFAULT_LANES = [
|
|
|
"formal",
|
|
"formal",
|
|
|
"td",
|
|
"td",
|
|
|
]
|
|
]
|
|
|
-# TD is exclusive; keep open-source concurrency modest on ~3 GiB hosts.
|
|
|
|
|
-DEFAULT_MAX_WORKERS = 2
|
|
|
|
|
TD_EXCLUSIVE = frozenset({"td"})
|
|
TD_EXCLUSIVE = frozenset({"td"})
|
|
|
|
|
|
|
|
|
|
+# Approximate resident budgets used only for concurrency planning (not fake %).
|
|
|
|
|
+_CLASS_MEM_KB = {
|
|
|
|
|
+ "light": 256 * 1024,
|
|
|
|
|
+ "medium": 512 * 1024,
|
|
|
|
|
+ "heavy": 1536 * 1024,
|
|
|
|
|
+ "exclusive": 2048 * 1024,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+LANE_RESOURCE_CLASS: dict[str, str] = {
|
|
|
|
|
+ "python": "light",
|
|
|
|
|
+ "board_viewer": "light",
|
|
|
|
|
+ "icarus": "medium",
|
|
|
|
|
+ "cocotb": "medium",
|
|
|
|
|
+ "verilator": "heavy",
|
|
|
|
|
+ "formal": "heavy",
|
|
|
|
|
+ "td": "exclusive",
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
|
|
|
def _utc_now() -> str:
|
|
def _utc_now() -> str:
|
|
|
return datetime.now(timezone.utc).isoformat()
|
|
return datetime.now(timezone.utc).isoformat()
|
|
@@ -51,6 +72,100 @@ def _write_json(path: Path, payload: dict[str, Any]) -> None:
|
|
|
path.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
path.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _prefer_oss_cad_on_path() -> None:
|
|
|
|
|
+ cache = Path(os.environ.get("XDG_CACHE_HOME", str(Path.home() / ".cache"))) / "prod2u"
|
|
|
|
|
+ root = Path(os.environ.get("OSS_CAD_SUITE_ROOT", str(cache / "oss-cad-suite" / "latest")))
|
|
|
|
|
+ oss_bin = root / "bin"
|
|
|
|
|
+ if not oss_bin.is_dir():
|
|
|
|
|
+ return
|
|
|
|
|
+ prefix = str(oss_bin)
|
|
|
|
|
+ current = os.environ.get("PATH", "")
|
|
|
|
|
+ parts = current.split(os.pathsep) if current else []
|
|
|
|
|
+ if prefix not in parts:
|
|
|
|
|
+ os.environ["PATH"] = prefix + (os.pathsep + current if current else "")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def host_resources() -> dict[str, Any]:
|
|
|
|
|
+ nproc = os.cpu_count() or 1
|
|
|
|
|
+ mem_available_kb: int | None = None
|
|
|
|
|
+ try:
|
|
|
|
|
+ with open("/proc/meminfo", encoding="utf-8") as handle:
|
|
|
|
|
+ for line in handle:
|
|
|
|
|
+ if line.startswith("MemAvailable:"):
|
|
|
|
|
+ mem_available_kb = int(line.split()[1])
|
|
|
|
|
+ break
|
|
|
|
|
+ except OSError:
|
|
|
|
|
+ mem_available_kb = None
|
|
|
|
|
+ try:
|
|
|
|
|
+ disk_free_bytes = shutil.disk_usage("/").free
|
|
|
|
|
+ except OSError:
|
|
|
|
|
+ disk_free_bytes = None
|
|
|
|
|
+ return {
|
|
|
|
|
+ "nproc": nproc,
|
|
|
|
|
+ "mem_available_kb": mem_available_kb,
|
|
|
|
|
+ "disk_free_bytes": disk_free_bytes,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def plan_concurrency(selected: list[str], *, max_workers_cap: int | None = None) -> dict[str, Any]:
|
|
|
|
|
+ """Derive open-source worker count from host resources and lane classes.
|
|
|
|
|
+
|
|
|
|
|
+ - TD (exclusive) never shares the pool; callers run it alone after OSS lanes.
|
|
|
|
|
+ - Formal is heavy and memory-capped: at most one formal job when MemAvailable
|
|
|
|
|
+ is under ~3.5 GiB, and never more than one formal concurrent with another
|
|
|
|
|
+ heavy lane on small hosts.
|
|
|
|
|
+ """
|
|
|
|
|
+ host = host_resources()
|
|
|
|
|
+ nproc = int(host["nproc"] or 1)
|
|
|
|
|
+ mem_kb = host["mem_available_kb"]
|
|
|
|
|
+ disk_free = host["disk_free_bytes"]
|
|
|
|
|
+
|
|
|
|
|
+ open_lanes = [lane for lane in selected if lane not in TD_EXCLUSIVE]
|
|
|
|
|
+ classes = {lane: LANE_RESOURCE_CLASS.get(lane, "medium") for lane in open_lanes}
|
|
|
|
|
+ has_formal = "formal" in open_lanes
|
|
|
|
|
+ has_heavy = any(classes[lane] == "heavy" for lane in open_lanes)
|
|
|
|
|
+
|
|
|
|
|
+ # Disk gate: refuse to oversubscribe if free disk is critically low.
|
|
|
|
|
+ disk_ok = disk_free is None or disk_free >= 2 * 1024**3
|
|
|
|
|
+
|
|
|
|
|
+ if mem_kb is None:
|
|
|
|
|
+ # Unknown memory: stay conservative.
|
|
|
|
|
+ workers = 1 if has_heavy else min(2, nproc)
|
|
|
|
|
+ formal_slots = 1
|
|
|
|
|
+ else:
|
|
|
|
|
+ # Leave ~512 MiB headroom for the matrix process / OS.
|
|
|
|
|
+ usable = max(0, mem_kb - 512 * 1024)
|
|
|
|
|
+ if has_formal and mem_kb < 3500 * 1024:
|
|
|
|
|
+ formal_slots = 1
|
|
|
|
|
+ # On low-memory hosts, do not overlap formal with another heavy lane.
|
|
|
|
|
+ workers = 1 if has_heavy else min(2, nproc)
|
|
|
|
|
+ else:
|
|
|
|
|
+ formal_slots = 1 # formal is always single-flight within this matrix
|
|
|
|
|
+ # Pack light/medium/heavy budgets into usable RAM, capped by nproc.
|
|
|
|
|
+ budget_workers = max(1, usable // _CLASS_MEM_KB["medium"])
|
|
|
|
|
+ workers = max(1, min(nproc, budget_workers, 4))
|
|
|
|
|
+ if has_heavy and mem_kb < 2500 * 1024:
|
|
|
|
|
+ workers = 1
|
|
|
|
|
+
|
|
|
|
|
+ if not disk_ok:
|
|
|
|
|
+ workers = 1
|
|
|
|
|
+
|
|
|
|
|
+ if max_workers_cap is not None:
|
|
|
|
|
+ workers = max(1, min(workers, max_workers_cap))
|
|
|
|
|
+
|
|
|
|
|
+ workers = max(1, min(workers, max(1, len(open_lanes))))
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ "host": host,
|
|
|
|
|
+ "open_lanes": open_lanes,
|
|
|
|
|
+ "lane_classes": classes,
|
|
|
|
|
+ "max_workers": workers,
|
|
|
|
|
+ "formal_slots": formal_slots if has_formal else 0,
|
|
|
|
|
+ "td_exclusive": bool(any(lane in TD_EXCLUSIVE for lane in selected)),
|
|
|
|
|
+ "disk_ok": disk_ok,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def _run_visible_cmd(
|
|
def _run_visible_cmd(
|
|
|
cmd: list[str],
|
|
cmd: list[str],
|
|
|
*,
|
|
*,
|
|
@@ -63,7 +178,8 @@ def _run_visible_cmd(
|
|
|
) -> int:
|
|
) -> int:
|
|
|
# Strip Anlogic libs for non-TD lanes so apt/python stay healthy.
|
|
# Strip Anlogic libs for non-TD lanes so apt/python stay healthy.
|
|
|
clean = os.environ.copy()
|
|
clean = os.environ.copy()
|
|
|
- if name != "td":
|
|
|
|
|
|
|
+ keep_td = name == "td"
|
|
|
|
|
+ if not keep_td:
|
|
|
for key in ("LD_LIBRARY_PATH", "LD_PRELOAD", "QT_PLUGIN_PATH"):
|
|
for key in ("LD_LIBRARY_PATH", "LD_PRELOAD", "QT_PLUGIN_PATH"):
|
|
|
clean.pop(key, None)
|
|
clean.pop(key, None)
|
|
|
if env:
|
|
if env:
|
|
@@ -76,6 +192,8 @@ def _run_visible_cmd(
|
|
|
status_path=status_path,
|
|
status_path=status_path,
|
|
|
name=name,
|
|
name=name,
|
|
|
timeout_s=timeout_s,
|
|
timeout_s=timeout_s,
|
|
|
|
|
+ heartbeat_s=5.0,
|
|
|
|
|
+ keep_td_libs=keep_td,
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -119,6 +237,7 @@ def run_python_unit(repo: Path, work_root: Path, run_id: str) -> dict[str, Any]:
|
|
|
"log_path": str(log_path),
|
|
"log_path": str(log_path),
|
|
|
"status_path": str(status_path),
|
|
"status_path": str(status_path),
|
|
|
"report_path": str(receipt_path),
|
|
"report_path": str(receipt_path),
|
|
|
|
|
+ "resource_class": LANE_RESOURCE_CLASS["python"],
|
|
|
}
|
|
}
|
|
|
_write_json(receipt_path, receipt)
|
|
_write_json(receipt_path, receipt)
|
|
|
return receipt
|
|
return receipt
|
|
@@ -156,6 +275,7 @@ def run_board_viewer(repo: Path, work_root: Path, run_id: str) -> dict[str, Any]
|
|
|
"returncode": code,
|
|
"returncode": code,
|
|
|
"log_path": str(log_path),
|
|
"log_path": str(log_path),
|
|
|
"report_path": str(receipt_path),
|
|
"report_path": str(receipt_path),
|
|
|
|
|
+ "resource_class": LANE_RESOURCE_CLASS["board_viewer"],
|
|
|
}
|
|
}
|
|
|
_write_json(receipt_path, receipt)
|
|
_write_json(receipt_path, receipt)
|
|
|
return receipt
|
|
return receipt
|
|
@@ -211,6 +331,7 @@ def _run_harness_lane(
|
|
|
receipt.setdefault("log_path", str(log_path))
|
|
receipt.setdefault("log_path", str(log_path))
|
|
|
receipt.setdefault("report_path", str(receipt_path))
|
|
receipt.setdefault("report_path", str(receipt_path))
|
|
|
receipt.setdefault("status_path", str(status_path))
|
|
receipt.setdefault("status_path", str(status_path))
|
|
|
|
|
+ receipt.setdefault("resource_class", LANE_RESOURCE_CLASS.get(lane, "medium"))
|
|
|
return receipt
|
|
return receipt
|
|
|
|
|
|
|
|
|
|
|
|
@@ -246,9 +367,10 @@ def run_td(repo: Path, work_root: Path, run_id: str) -> dict[str, Any]:
|
|
|
"verification_run_id": run_id,
|
|
"verification_run_id": run_id,
|
|
|
"failures": [f"td_lock_held:{lock_path}"],
|
|
"failures": [f"td_lock_held:{lock_path}"],
|
|
|
"report_path": str(work_root / "td-receipt.json"),
|
|
"report_path": str(work_root / "td-receipt.json"),
|
|
|
|
|
+ "resource_class": "exclusive",
|
|
|
}
|
|
}
|
|
|
try:
|
|
try:
|
|
|
- return _run_harness_lane(
|
|
|
|
|
|
|
+ receipt = _run_harness_lane(
|
|
|
repo,
|
|
repo,
|
|
|
work_root,
|
|
work_root,
|
|
|
run_id,
|
|
run_id,
|
|
@@ -256,6 +378,8 @@ def run_td(repo: Path, work_root: Path, run_id: str) -> dict[str, Any]:
|
|
|
"td-build",
|
|
"td-build",
|
|
|
timeout_s=3600,
|
|
timeout_s=3600,
|
|
|
)
|
|
)
|
|
|
|
|
+ receipt["resource_class"] = "exclusive"
|
|
|
|
|
+ return receipt
|
|
|
finally:
|
|
finally:
|
|
|
try:
|
|
try:
|
|
|
lock_path.unlink(missing_ok=True)
|
|
lock_path.unlink(missing_ok=True)
|
|
@@ -285,6 +409,31 @@ def _overall_status(results: dict[str, dict[str, Any]], selected: list[str]) ->
|
|
|
return "fail"
|
|
return "fail"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _schedule_open_lanes(open_lanes: list[str], plan: dict[str, Any]) -> list[list[str]]:
|
|
|
|
|
+ """Partition open-source lanes into waves respecting memory / formal caps.
|
|
|
|
|
+
|
|
|
|
|
+ When formal_slots==1 and memory is tight (max_workers==1 with heavy), run
|
|
|
|
|
+ heavy lanes (formal, verilator) sequentially. Otherwise run the pool wave
|
|
|
|
|
+ first, then any remaining exclusive-within-OSS serialization is handled by
|
|
|
|
|
+ max_workers alone.
|
|
|
|
|
+ """
|
|
|
|
|
+ if not open_lanes:
|
|
|
|
|
+ return []
|
|
|
|
|
+ workers = int(plan["max_workers"])
|
|
|
|
|
+ mem_kb = (plan.get("host") or {}).get("mem_available_kb")
|
|
|
|
|
+ # On low-memory hosts: serialize heavy lanes, allow light/medium to share.
|
|
|
|
|
+ if workers <= 1 or (mem_kb is not None and mem_kb < 2500 * 1024):
|
|
|
|
|
+ light_medium = [lane for lane in open_lanes if LANE_RESOURCE_CLASS.get(lane) in ("light", "medium")]
|
|
|
|
|
+ heavy = [lane for lane in open_lanes if LANE_RESOURCE_CLASS.get(lane) == "heavy"]
|
|
|
|
|
+ waves: list[list[str]] = []
|
|
|
|
|
+ if light_medium:
|
|
|
|
|
+ waves.append(light_medium)
|
|
|
|
|
+ for lane in heavy:
|
|
|
|
|
+ waves.append([lane])
|
|
|
|
|
+ return waves or [open_lanes]
|
|
|
|
|
+ return [open_lanes]
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def main() -> int:
|
|
def main() -> int:
|
|
|
parser = argparse.ArgumentParser(description="Run the verification matrix")
|
|
parser = argparse.ArgumentParser(description="Run the verification matrix")
|
|
|
parser.add_argument("--work-root-prefix", required=True)
|
|
parser.add_argument("--work-root-prefix", required=True)
|
|
@@ -292,9 +441,18 @@ def main() -> int:
|
|
|
parser.add_argument("--report-file", required=True)
|
|
parser.add_argument("--report-file", required=True)
|
|
|
parser.add_argument("--lanes", default=",".join(DEFAULT_LANES))
|
|
parser.add_argument("--lanes", default=",".join(DEFAULT_LANES))
|
|
|
parser.add_argument("--only-lane", help="rerun a single lane")
|
|
parser.add_argument("--only-lane", help="rerun a single lane")
|
|
|
- parser.add_argument("--max-workers", type=int, default=DEFAULT_MAX_WORKERS)
|
|
|
|
|
|
|
+ parser.add_argument(
|
|
|
|
|
+ "--max-workers",
|
|
|
|
|
+ type=int,
|
|
|
|
|
+ default=None,
|
|
|
|
|
+ help="Cap open-source concurrency (default: host-resource plan).",
|
|
|
|
|
+ )
|
|
|
args = parser.parse_args()
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
+ for key in ("LD_LIBRARY_PATH", "LD_PRELOAD", "QT_PLUGIN_PATH"):
|
|
|
|
|
+ os.environ.pop(key, None)
|
|
|
|
|
+ _prefer_oss_cad_on_path()
|
|
|
|
|
+
|
|
|
repo = _repo_root
|
|
repo = _repo_root
|
|
|
run_id = (args.verification_run_id or uuid.uuid4().hex).strip().lower()
|
|
run_id = (args.verification_run_id or uuid.uuid4().hex).strip().lower()
|
|
|
if len(run_id) != 32 or any(c not in "0123456789abcdef" for c in run_id):
|
|
if len(run_id) != 32 or any(c not in "0123456789abcdef" for c in run_id):
|
|
@@ -309,12 +467,25 @@ def main() -> int:
|
|
|
print(f"unknown lanes: {unknown}", file=sys.stderr)
|
|
print(f"unknown lanes: {unknown}", file=sys.stderr)
|
|
|
return 1
|
|
return 1
|
|
|
|
|
|
|
|
|
|
+ plan = plan_concurrency(selected, max_workers_cap=args.max_workers)
|
|
|
|
|
+ print(
|
|
|
|
|
+ f"[matrix] resource_plan workers={plan['max_workers']} "
|
|
|
|
|
+ f"formal_slots={plan['formal_slots']} td_exclusive={plan['td_exclusive']} "
|
|
|
|
|
+ f"nproc={plan['host']['nproc']} mem_available_kb={plan['host']['mem_available_kb']} "
|
|
|
|
|
+ f"classes={plan['lane_classes']}",
|
|
|
|
|
+ flush=True,
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
results: dict[str, dict[str, Any]] = {}
|
|
results: dict[str, dict[str, Any]] = {}
|
|
|
|
|
|
|
|
def _run_lane(lane: str) -> tuple[str, dict[str, Any]]:
|
|
def _run_lane(lane: str) -> tuple[str, dict[str, Any]]:
|
|
|
work_root = Path(f"{args.work_root_prefix}-{lane}-{run_id[:8]}")
|
|
work_root = Path(f"{args.work_root_prefix}-{lane}-{run_id[:8]}")
|
|
|
runner = LANE_RUNNERS[lane]
|
|
runner = LANE_RUNNERS[lane]
|
|
|
- print(f"[matrix] starting lane={lane} work_root={work_root}", flush=True)
|
|
|
|
|
|
|
+ print(
|
|
|
|
|
+ f"[matrix] starting lane={lane} class={LANE_RESOURCE_CLASS.get(lane)} "
|
|
|
|
|
+ f"work_root={work_root}",
|
|
|
|
|
+ flush=True,
|
|
|
|
|
+ )
|
|
|
if lane in ("icarus", "verilator", "cocotb"):
|
|
if lane in ("icarus", "verilator", "cocotb"):
|
|
|
receipt = runner(repo, work_root, run_id, lane)
|
|
receipt = runner(repo, work_root, run_id, lane)
|
|
|
else:
|
|
else:
|
|
@@ -323,16 +494,18 @@ def main() -> int:
|
|
|
return lane, receipt
|
|
return lane, receipt
|
|
|
|
|
|
|
|
start = time.time()
|
|
start = time.time()
|
|
|
- # Run TD alone after open-source lanes to avoid license/memory contention.
|
|
|
|
|
- open_lanes = [l for l in selected if l not in TD_EXCLUSIVE]
|
|
|
|
|
- td_lanes = [l for l in selected if l in TD_EXCLUSIVE]
|
|
|
|
|
-
|
|
|
|
|
- with ThreadPoolExecutor(max_workers=min(args.max_workers, max(1, len(open_lanes)))) as pool:
|
|
|
|
|
- futures = [pool.submit(_run_lane, lane) for lane in open_lanes]
|
|
|
|
|
- for fut in as_completed(futures):
|
|
|
|
|
- lane, receipt = fut.result()
|
|
|
|
|
- results[lane] = receipt
|
|
|
|
|
-
|
|
|
|
|
|
|
+ open_lanes = [lane for lane in selected if lane not in TD_EXCLUSIVE]
|
|
|
|
|
+ td_lanes = [lane for lane in selected if lane in TD_EXCLUSIVE]
|
|
|
|
|
+
|
|
|
|
|
+ for wave in _schedule_open_lanes(open_lanes, plan):
|
|
|
|
|
+ workers = min(plan["max_workers"], max(1, len(wave)))
|
|
|
|
|
+ with ThreadPoolExecutor(max_workers=workers) as pool:
|
|
|
|
|
+ futures = [pool.submit(_run_lane, lane) for lane in wave]
|
|
|
|
|
+ for fut in as_completed(futures):
|
|
|
|
|
+ lane, receipt = fut.result()
|
|
|
|
|
+ results[lane] = receipt
|
|
|
|
|
+
|
|
|
|
|
+ # TD exclusive: never overlap with OSS lanes or another TD.
|
|
|
for lane in td_lanes:
|
|
for lane in td_lanes:
|
|
|
lane_name, receipt = _run_lane(lane)
|
|
lane_name, receipt = _run_lane(lane)
|
|
|
results[lane_name] = receipt
|
|
results[lane_name] = receipt
|
|
@@ -355,6 +528,7 @@ def main() -> int:
|
|
|
"failures": [f"{lane}:{r['status']}" for lane, r in results.items() if r.get("status") != "pass"],
|
|
"failures": [f"{lane}:{r['status']}" for lane, r in results.items() if r.get("status") != "pass"],
|
|
|
"environment": "linux",
|
|
"environment": "linux",
|
|
|
"td_command": "td2026",
|
|
"td_command": "td2026",
|
|
|
|
|
+ "resource_plan": plan,
|
|
|
}
|
|
}
|
|
|
report_path = Path(args.report_file)
|
|
report_path = Path(args.report_file)
|
|
|
report_path.parent.mkdir(parents=True, exist_ok=True)
|
|
report_path.parent.mkdir(parents=True, exist_ok=True)
|