From a06e9dbc444162b3d95cab43dda8c56aeab123a7 Mon Sep 17 00:00:00 2001 From: Vittorio Distefano Date: Tue, 10 Nov 2026 22:31:39 +0100 Subject: [PATCH] fix(bench): rotate the timed gate trials through the code layouts The gate built five -C metadata layouts per side but timed only layout 0, so wall time and the hardware counters read one code placement. On merged main the same instructions read ruin wall +10.2% (its byte-identical hot function moved 32 bytes and its fill loop crossed a cache line) and nearby_swap branch misses +9.9% (identical function at the same address, predictor aliasing with moved code), while the medians over five layouts moved +1.2% and +1.0%. Trial t now runs layout t mod SIM_LAYOUTS on both sides, and warmups rotate the same way, so every timed median pools all layouts. Trials, budget, graded metrics, pass rule and run time are unchanged. A 15-trial run of ruin and nearby_swap on main vs v0.26.0 passes (wall -1.8% and -1.5%). Closes #245 --- scripts/bench-zero-regression.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/bench-zero-regression.sh b/scripts/bench-zero-regression.sh index 4831f724..617e96d3 100755 --- a/scripts/bench-zero-regression.sh +++ b/scripts/bench-zero-regression.sh @@ -47,6 +47,12 @@ BENCH_ISOLATE=${BENCH_ISOLATE:-1} # indirect mispredictions into 859k with equal instruction counts. Branch # behaviour is graded on the hardware branch-misses counter instead, whose # baseline interquartile range on the isolated CPU stays at 0.04-2.2%. +# The timed trials rotate through the same layouts: trial t runs layout +# t mod SIM_LAYOUTS on both sides, so every timed metric (wall time, hardware +# instructions and branch misses) is a median over all layouts rather than +# the reading of one placement. Measured on one layout, identical code moved +# by 32 bytes read +10% wall time (ruin) and +9.9% hardware branch misses +# (nearby_swap), while the medians over five layouts moved +1.2% and +1.0%. SIM_LAYOUTS=${SIM_LAYOUTS:-5} SIM_JOBS=${SIM_JOBS:-8} # Each trial's hardware counters are the mean of PERF_REPEATS process runs. @@ -381,12 +387,11 @@ cat >"$RESULTS/environment.json" </dev/null - taskset -c "$BENCH_CPU" "$CANDIDATE_BIN" "$case_name" "$case_iterations" >/dev/null + layout=$((warmup % SIM_LAYOUTS)) + taskset -c "$BENCH_CPU" "$(case_binary baseline "$case_name" "$layout")" "$case_name" "$case_iterations" >/dev/null + taskset -c "$BENCH_CPU" "$(case_binary candidate "$case_name" "$layout")" "$case_name" "$case_iterations" >/dev/null done done @@ -417,9 +422,10 @@ run_trial() { } for case_name in "${CASES[@]}"; do - BASELINE_BIN=$(case_binary baseline "$case_name") - CANDIDATE_BIN=$(case_binary candidate "$case_name") for ((trial = 0; trial < TRIALS; trial++)); do + layout=$((trial % SIM_LAYOUTS)) + BASELINE_BIN=$(case_binary baseline "$case_name" "$layout") + CANDIDATE_BIN=$(case_binary candidate "$case_name" "$layout") if ((trial % 2 == 0)); then run_trial baseline "$BASELINE_BIN" "$case_name" "$trial" run_trial candidate "$CANDIDATE_BIN" "$case_name" "$trial"