Phase 4-Step1: Add PGO workflow automation (+6.25% performance)
Implemented automated Profile-Guided Optimization workflow using Box pattern: Performance Improvement: - Baseline: 57.0 M ops/s - PGO-optimized: 60.6 M ops/s - Gain: +6.25% (within expected +5-10% range) Implementation: 1. scripts/box/pgo_tiny_profile_config.sh - 5 representative workloads 2. scripts/box/pgo_tiny_profile_box.sh - Automated profile collection 3. Makefile PGO targets: - pgo-tiny-profile: Build instrumented binaries - pgo-tiny-collect: Collect .gcda profile data - pgo-tiny-build: Build optimized binaries - pgo-tiny-full: Complete workflow (profile → collect → build → test) 4. Makefile help target: Added PGO instructions for discoverability Design: - Box化: Single responsibility, clear contracts - Deterministic: Fixed seeds (42) for reproducibility - Safe: Validation, error detection, timeout protection (30s/workload) - Observable: Progress reporting, .gcda verification (33 files generated) Workload Coverage: - Random mixed: 3 working set sizes (128/256/512 slots) - Tiny hot: 2 size classes (16B/64B) - Total: 5 workloads covering hot/cold paths Documentation: - PHASE4_STEP1_COMPLETE.md - Completion report - CURRENT_TASK.md - Phase 4 roadmap (Step 1 complete ✓) - docs/design/PHASE4_TINY_FRONT_BOX_DESIGN.md - Complete Phase 4 design Next: Phase 4-Step2 (Hot/Cold Path Box, target +10-15%) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
101
scripts/box/pgo_tiny_profile_box.sh
Executable file
101
scripts/box/pgo_tiny_profile_box.sh
Executable file
@ -0,0 +1,101 @@
|
||||
#!/bin/bash
|
||||
# Box: PGO Profile Collection (Tiny Front)
|
||||
# Contract: Execute representative Tiny workloads for PGO
|
||||
# Usage: ./scripts/box/pgo_tiny_profile_box.sh
|
||||
#
|
||||
# Input: Built binaries with -fprofile-generate -flto
|
||||
# Output: .gcda profile data files
|
||||
# Guarantees: Deterministic execution, error detection, summary report
|
||||
|
||||
set -e # Fail fast on errors
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "${SCRIPT_DIR}/pgo_tiny_profile_config.sh"
|
||||
|
||||
echo "========================================="
|
||||
echo "Box: PGO Profile Collection (Tiny Front)"
|
||||
echo "========================================="
|
||||
echo "Date: $(date)"
|
||||
echo "Workloads: $PGO_WORKLOAD_COUNT"
|
||||
echo "Binaries: $PGO_BINARY_COUNT"
|
||||
echo ""
|
||||
|
||||
# Validate binaries exist and are executable
|
||||
echo "[PGO_BOX] Validating binaries..."
|
||||
for bin in "${PGO_BINARIES[@]}"; do
|
||||
if [[ ! -f "$bin" ]]; then
|
||||
echo "ERROR: Binary not found: $bin"
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -x "$bin" ]]; then
|
||||
echo "ERROR: Binary not executable: $bin"
|
||||
chmod +x "$bin" || exit 1
|
||||
echo " Fixed: Made $bin executable"
|
||||
fi
|
||||
echo " ✓ $bin"
|
||||
done
|
||||
echo ""
|
||||
|
||||
# Clean old profile data
|
||||
echo "[PGO_BOX] Cleaning old .gcda files..."
|
||||
GCDA_OLD_COUNT=$(find . -name "*.gcda" 2>/dev/null | wc -l)
|
||||
if [[ $GCDA_OLD_COUNT -gt 0 ]]; then
|
||||
find . -name "*.gcda" -delete
|
||||
echo " Removed $GCDA_OLD_COUNT old .gcda files"
|
||||
else
|
||||
echo " No old .gcda files found"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Execute workloads
|
||||
echo "[PGO_BOX] Executing representative workloads..."
|
||||
echo "==========================================="
|
||||
WORKLOAD_NUM=0
|
||||
for workload in "${PGO_WORKLOADS[@]}"; do
|
||||
WORKLOAD_NUM=$((WORKLOAD_NUM + 1))
|
||||
echo ""
|
||||
echo "[$WORKLOAD_NUM/$PGO_WORKLOAD_COUNT] Running: $workload"
|
||||
echo "-------------------------------------------"
|
||||
|
||||
# Execute with timeout (30s per workload)
|
||||
if timeout 30 $workload; then
|
||||
echo " ✓ Success"
|
||||
else
|
||||
EXIT_CODE=$?
|
||||
if [[ $EXIT_CODE -eq 124 ]]; then
|
||||
echo " ✗ TIMEOUT (30s exceeded)"
|
||||
else
|
||||
echo " ✗ FAILED (exit code: $EXIT_CODE)"
|
||||
fi
|
||||
echo "ERROR: Workload failed: $workload"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
echo ""
|
||||
echo "==========================================="
|
||||
|
||||
# Verify profile data generated
|
||||
echo "[PGO_BOX] Verifying profile data..."
|
||||
GCDA_COUNT=$(find . -name "*.gcda" 2>/dev/null | wc -l)
|
||||
if [[ $GCDA_COUNT -eq 0 ]]; then
|
||||
echo "ERROR: No .gcda files generated!"
|
||||
echo " This usually means binaries were not built with -fprofile-generate"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo " ✓ Generated $GCDA_COUNT .gcda files"
|
||||
echo ""
|
||||
|
||||
# Summary
|
||||
echo "========================================="
|
||||
echo "PGO Profile Collection: SUCCESS"
|
||||
echo "========================================="
|
||||
echo "Profile files: $GCDA_COUNT .gcda files"
|
||||
echo "Next step: make pgo-tiny-build"
|
||||
echo ""
|
||||
echo "Profile locations:"
|
||||
find . -name "*.gcda" | head -5
|
||||
if [[ $GCDA_COUNT -gt 5 ]]; then
|
||||
echo " ... and $((GCDA_COUNT - 5)) more"
|
||||
fi
|
||||
echo "========================================="
|
||||
43
scripts/box/pgo_tiny_profile_config.sh
Executable file
43
scripts/box/pgo_tiny_profile_config.sh
Executable file
@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
# Box: PGO Profile Configuration
|
||||
# Purpose: Define representative workloads for Tiny Front
|
||||
# Contract: Provides workload definitions for PGO profile collection
|
||||
|
||||
# Binaries to profile
|
||||
PGO_BINARIES=(
|
||||
"./bench_random_mixed_hakmem"
|
||||
"./bench_tiny_hot_hakmem"
|
||||
)
|
||||
|
||||
# Representative workloads (deterministic seeds for reproducibility)
|
||||
# Design: Cover diverse allocation patterns for optimal PGO data
|
||||
PGO_WORKLOADS=(
|
||||
# Random mixed: Common case (medium working set)
|
||||
# - Most representative of general allocation patterns
|
||||
# - 256 slots = moderate cache pressure
|
||||
"./bench_random_mixed_hakmem 5000000 256 42"
|
||||
|
||||
# Random mixed: Smaller working set (higher cache hit)
|
||||
# - Exercises hot TLS SLL path heavily
|
||||
# - 128 slots = higher hit rate
|
||||
"./bench_random_mixed_hakmem 5000000 128 42"
|
||||
|
||||
# Random mixed: Larger working set (more diverse)
|
||||
# - Exercises refill and cold paths more
|
||||
# - 512 slots = more SuperSlab allocations
|
||||
"./bench_random_mixed_hakmem 5000000 512 42"
|
||||
|
||||
# Tiny hot path: 16B allocations
|
||||
# - Class 0 (smallest) intensive
|
||||
# - High allocation frequency
|
||||
"./bench_tiny_hot_hakmem 16 100 60000"
|
||||
|
||||
# Tiny hot path: 64B allocations
|
||||
# - Class 3 (common size) intensive
|
||||
# - Typical small object pattern
|
||||
"./bench_tiny_hot_hakmem 64 100 60000"
|
||||
)
|
||||
|
||||
# Configuration summary
|
||||
PGO_WORKLOAD_COUNT=${#PGO_WORKLOADS[@]}
|
||||
PGO_BINARY_COUNT=${#PGO_BINARIES[@]}
|
||||
Reference in New Issue
Block a user