kab time: monotonic ns + TSC slices with a dependent-add clock calibration before and after each slice (tq_cpu_parity --bench method; slices whose clock moved >5 percent are dropped, threshold from tq_cpu_parity.cpp:303), RESIDENT and STREAMED regimes, pinned single-thread pool, 4096-aligned buffers, manifest and case input hashes, effective environment. aa.sh: seeded schedule, N rounds of two fresh processes, per-round ratios only. time_smoke.sh runs the acceptance commands. Only tools/kernel-ab/ is touched. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
64 lines
4.0 KiB
Bash
Executable File
64 lines
4.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# tools/kernel-ab/time_smoke.sh - STRA-317 acceptance in one command: `kab time`, verify_manifest.py, aa.sh. Last line `TIME SMOKE OK`.
|
|
#
|
|
# E2E_ROOT run root (default $HOME/work/leleka-e2e; on rnr5090 the root file system is full: E2E_ROOT=/data/leleka-e2e)
|
|
# KAB the built driver (default $E2E_ROOT/build/kernel-ab/kab; build with smoke.sh or make -C tools/kernel-ab/cpp BUILD=...)
|
|
# KAB_RUN a KAB1 run directory written by `kab gen` (default $E2E_ROOT/runs/kernel-ab/final); it is only read
|
|
# TS_CASE (18-20-r1) TS_PIN (cpu number, default 9) TS_SLICES (50) TS_ROUNDS (A/A rounds, default 30) TS_SEED (default 20261028)
|
|
# TS_RUN_ID output directory name under $E2E_ROOT/runs/kernel-ab-time/ (default time-<utc timestamp>)
|
|
# CPU only. Timing numbers from a shared host are noisy and are not evidence by themselves.
|
|
set -euo pipefail
|
|
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
repo="$(cd "${here}/../.." && pwd)"
|
|
root="${E2E_ROOT:-${HOME}/work/leleka-e2e}"
|
|
kab="${KAB:-${root}/build/kernel-ab/kab}"
|
|
d="${KAB_RUN:-${root}/runs/kernel-ab/final}"
|
|
cas="${TS_CASE:-18-20-r1}"; pin="${TS_PIN:-9}"; slices="${TS_SLICES:-50}"; rounds="${TS_ROUNDS:-30}"; seed="${TS_SEED:-20261028}"
|
|
py="${PYTHON:-python3}"
|
|
out="${root}/runs/kernel-ab-time/${TS_RUN_ID:-time-$(date -u +%Y%m%dT%H%M%SZ)}"
|
|
case "${out}/" in "${repo}/"*) echo "time_smoke: output ${out} is inside the repository" >&2; exit 1;; esac
|
|
mkdir -p "${out}"
|
|
export PYTHONDONTWRITEBYTECODE=1
|
|
step() { printf '\n==== %s ====\n' "$*"; }
|
|
|
|
step "AC1 kab time: resident + streamed, ${slices} slices, pin ${pin}"
|
|
"${kab}" time --run-dir "${d}" --case "${cas}" --slices "${slices}" --pin "${pin}" --out "${out}/t.json"
|
|
"${py}" -I - "${out}/t.json" "${slices}" "${pin}" <<'PY'
|
|
import json, sys
|
|
d = json.load(open(sys.argv[1])); n = int(sys.argv[2]); pin = int(sys.argv[3])
|
|
assert d["format"] == "KAB1-time" and d["mode"] == "time" and d["writer"] == "cpp"
|
|
assert len(d["manifest_sha256"]) == 64 and len(d["case"]["input_sha256"]) == 64 and d["case"]["input_sha256_matches_manifest"]
|
|
assert d["tree"] in ("avx512", "avx2") and isinstance(d["effective_env"], dict)
|
|
assert d["pin"]["cpu"] == pin and "thread_siblings_list" in d["pin"] and d["pool"]["workers"] == 1
|
|
cal = d["clock_calibration"]; rule = cal["drop_rule"]
|
|
assert rule["source_file"].endswith("tq_cpu_parity.cpp") and rule["source_line"] == 303 and rule["fraction"] == 0.05
|
|
assert d["selfcheck_bitwise_equal_compose_expert"] and d["final_output_unchanged"]
|
|
names = [r["regime"] for r in d["regimes"]]
|
|
assert names == ["RESIDENT", "STREAMED"], names
|
|
for r in d["regimes"]:
|
|
assert r["slices_requested"] == n and r["slices_kept"] + r["dropped_count"] == n
|
|
assert len(r["slices"]) == r["slices_kept"] and len(r["dropped"]) == r["dropped_count"] and r["slices_kept"] > 0
|
|
for s in r["slices"] + r["dropped"]:
|
|
for k in ("ns_per_call", "tsc_per_call", "ghz_before", "ghz_after"):
|
|
assert s[k] > 0, (r["regime"], s)
|
|
print("%-8s K=%-3d kept=%d dropped=%d working_set=%d llc=%d median_ns=%.0f" % (r["regime"], r["copies_k"], r["slices_kept"], r["dropped_count"],
|
|
r["working_set_bytes"], r["llc_bytes"], r["median_ns_per_call"]))
|
|
st = d["regimes"][1]; assert st["working_set_bytes"] > st["llc_bytes"] and d["regimes"][0]["copies_k"] == 1
|
|
print("t.json shape OK")
|
|
PY
|
|
|
|
step "AC2 verify_manifest.py after the run (the dump is untouched)"
|
|
"${py}" "${here}/verify_manifest.py" "${d}"
|
|
|
|
step "AC3 the cited drop threshold exists"
|
|
sed -n '303p' "${repo}/engine/strata/src/kernels/cpu/tq_cpu_parity.cpp"
|
|
sed -n '303p' "${repo}/engine/strata/src/kernels/cpu/tq_cpu_parity.cpp" | grep -q 'std::fabs(g1 - g0) > 0.05 \* g0'
|
|
|
|
step "AC3 aa.sh ${d} ${cas} ${rounds} ${seed} ${pin}"
|
|
AA_OUT="${out}/aa" E2E_ROOT="${root}" KAB="${kab}" bash "${here}/aa.sh" "${d}" "${cas}" "${rounds}" "${seed}" "${pin}"
|
|
n="$(grep -vc '^#' "${out}/aa/ratios.tsv" || true)"
|
|
echo "ratios.tsv data lines: ${n}"
|
|
[ "${n}" = "${rounds}" ]
|
|
"${py}" "${here}/verify_manifest.py" "${d}"
|
|
echo "TIME SMOKE OK"
|