Files
hakmem/scripts/phase75_c5_inline_test.sh

143 lines
5.1 KiB
Bash
Raw Normal View History

#!/bin/bash
# Phase 75-2: C5 Inline Slots A/B Test (C5-only, with C6=ON baseline)
#
# Strategy: Isolate C5 individual contribution
# Baseline: C5=OFF, C6=ON (from Phase 75-1, now the new baseline)
# Treatment: C5=ON, C6=ON (adds C5 on top)
#
# Decision Gate:
# GO: +1.0% or higher
# NEUTRAL: -1.0% to +1.0%
# NO-GO: -1.0% or lower
set -e
echo "==========================================="
echo "Phase 75-2: C5 Inline Slots A/B Test"
echo "==========================================="
echo "(Baseline: C5=OFF, C6=ON; Treatment: C5=ON, C6=ON)"
echo ""
# Build baseline (C6=ON, C5=OFF)
echo "Building baseline (C6=ON, C5=OFF)..."
HAKMEM_TINY_C6_INLINE_SLOTS=1 make clean > /dev/null 2>&1
HAKMEM_TINY_C6_INLINE_SLOTS=1 make -j bench_random_mixed_hakmem > /tmp/c5_inline_build_baseline.log 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: Baseline build failed!"
tail -20 /tmp/c5_inline_build_baseline.log
exit 1
fi
echo "Baseline build: OK"
# Run baseline 10x
echo ""
echo "Running baseline 10x (WS=400, ITERS=20000000)..."
echo "Config: C5=OFF, C6=ON"
for i in {1..10}; do
echo " Run $i/10 (C5=OFF, C6=ON)"
HAKMEM_WARM_POOL_SIZE=16 HAKMEM_TINY_C6_INLINE_SLOTS=1 HAKMEM_TINY_C5_INLINE_SLOTS=0 \
./bench_random_mixed_hakmem 20000000 400 1 2>&1
done > /tmp/c5_inline_baseline.log 2>&1
# Build treatment (C6=ON, C5=ON)
echo ""
echo "Building treatment (C6=ON, C5=ON)..."
HAKMEM_TINY_C6_INLINE_SLOTS=1 HAKMEM_TINY_C5_INLINE_SLOTS=1 make clean > /dev/null 2>&1
HAKMEM_TINY_C6_INLINE_SLOTS=1 HAKMEM_TINY_C5_INLINE_SLOTS=1 make -j bench_random_mixed_hakmem > /tmp/c5_inline_build_treatment.log 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: Treatment build failed!"
tail -20 /tmp/c5_inline_build_treatment.log
exit 1
fi
echo "Treatment build: OK"
# Run treatment 10x with perf stat
echo ""
echo "Running treatment 10x with perf stat (C5=ON, C6=ON)..."
echo "Config: C5=ON, C6=ON"
for i in {1..10}; do
echo " Run $i/10 (C5=ON, C6=ON)"
HAKMEM_WARM_POOL_SIZE=16 HAKMEM_TINY_C6_INLINE_SLOTS=1 HAKMEM_TINY_C5_INLINE_SLOTS=1 \
perf stat -e cycles,instructions,branches,branch-misses,cache-misses,dTLB-load-misses \
./bench_random_mixed_hakmem 20000000 400 1 2>&1
done > /tmp/c5_inline_treatment.log 2>&1
# Analysis
echo ""
echo "==========================================="
echo "ANALYSIS: Throughput Comparison"
echo "==========================================="
BASELINE_AVG=$(grep "Throughput" /tmp/c5_inline_baseline.log | awk '{print $3}' | sed 's/ops\/s//' | awk '{s+=$1; n++} END {printf "%.2f", s/n/1000000}')
TREATMENT_AVG=$(grep "Throughput" /tmp/c5_inline_treatment.log | awk '{print $3}' | sed 's/ops\/s//' | awk '{s+=$1; n++} END {printf "%.2f", s/n/1000000}')
echo "Baseline (C5=OFF, C6=ON): $BASELINE_AVG M ops/s"
echo "Treatment (C5=ON, C6=ON): $TREATMENT_AVG M ops/s"
DELTA=$(awk "BEGIN {printf \"%.2f\", $TREATMENT_AVG - $BASELINE_AVG}")
DELTA_PCT=$(awk "BEGIN {printf \"%.2f\", (($TREATMENT_AVG - $BASELINE_AVG) / $BASELINE_AVG) * 100}")
echo "Delta: +$DELTA M ops/s (+$DELTA_PCT%)"
echo ""
echo "==========================================="
echo "PERF STAT ANALYSIS (Treatment)"
echo "==========================================="
# Extract perf stat averages from treatment
INSTRUCTIONS=$(grep "instructions" /tmp/c5_inline_treatment.log | awk '{sum+=$1; count++} END {printf "%.0f", sum/count}')
BRANCHES=$(grep -w "branches" /tmp/c5_inline_treatment.log | awk '{sum+=$1; count++} END {printf "%.0f", sum/count}')
CACHE_MISSES=$(grep "cache-misses" /tmp/c5_inline_treatment.log | awk '{sum+=$1; count++} END {printf "%.0f", sum/count}')
DTLB_MISSES=$(grep "dTLB-load-misses" /tmp/c5_inline_treatment.log | awk '{sum+=$1; count++} END {printf "%.0f", sum/count}')
echo "Instructions: $INSTRUCTIONS"
echo "Branches: $BRANCHES"
echo "Cache-misses: $CACHE_MISSES"
echo "dTLB-load-misses: $DTLB_MISSES"
echo ""
echo "==========================================="
echo "DECISION GATE (+1.0% GO threshold)"
echo "==========================================="
# Decision logic
GO_THRESHOLD=1.0
NOGO_THRESHOLD=-1.0
if (( $(echo "$DELTA_PCT >= $GO_THRESHOLD" | bc -l) )); then
echo "Result: GO (+$DELTA_PCT%)"
echo "Recommendation: Proceed to Phase 75-3 (C5+C6 interaction test)"
DECISION="GO"
elif (( $(echo "$DELTA_PCT <= $NOGO_THRESHOLD" | bc -l) )); then
echo "Result: NO-GO ($DELTA_PCT%)"
echo "Recommendation: REVERT immediately, keep C6-only from Phase 75-1"
DECISION="NO-GO"
else
echo "Result: NEUTRAL ($DELTA_PCT%)"
echo "Recommendation: Freeze, evaluate in Phase 76"
DECISION="NEUTRAL"
fi
echo ""
echo "==========================================="
echo "LOGS & DATA"
echo "==========================================="
echo "Build logs:"
echo " - Baseline: /tmp/c5_inline_build_baseline.log"
echo " - Treatment: /tmp/c5_inline_build_treatment.log"
echo ""
echo "Benchmark logs:"
echo " - Baseline: /tmp/c5_inline_baseline.log"
echo " - Treatment: /tmp/c5_inline_treatment.log"
echo ""
echo "==========================================="
# Exit with status based on decision
if [ "$DECISION" = "GO" ]; then
exit 0
elif [ "$DECISION" = "NO-GO" ]; then
exit 1
else
exit 2 # NEUTRAL
fi