Commit bafd3133 by PLN (Algolia)

feat(perf): RAPL package-power caps — watts are the thermal lever, not percent

Discovery 2026-07-19: the Dell BIOS ships PL1=PL2=135W on this 45W-TDP
i7-10875H. With no sustained-power brake, the only thing that ever slows
the CPU is the 100C thermal limiter — which is how a set peaked at 91C and
had to be aborted. Percent clock caps (--cool's max_perf_pct) don't bound
multi-core power; watt caps do.

All three modes now set package power limits via RAPL, saved/restored by
--stop:
- --optimize / --extreme: PL1 45W (chip spec) / PL2 90W — full nominal
  performance, bursts stay snappy, sustained runaway impossible.
- --cool: PL1 28W / PL2 50W by default (~2.5GHz all-core), tunable with
  COOL_PL1_W / COOL_PL2_W.
- --diagnose now prints the current PL1/PL2 against spec.
parent 2f6b0b7a
......@@ -11,6 +11,15 @@ SAVED_MAX_PCT="/tmp/saved_cpu_max_pct.txt"
# the editor's bursty UI work to clear quickly. Tune with COOL_MAX_PCT=NN
# (lower = cooler but laggier UI; higher = snappier but warmer).
COOL_MAX_PCT="${COOL_MAX_PCT:-85}"
# Package power caps in watts (PL1 = sustained, PL2 = burst). The Dell BIOS
# ships PL1=PL2=135W on this 45W-TDP i7-10875H, so nothing but the 100°C
# thermal limiter ever brakes the CPU (measured 91°C mid-set 2026-07-18).
# Watts bound heat directly; percent clock caps don't on multi-core load.
COOL_PL1_W="${COOL_PL1_W:-28}"
COOL_PL2_W="${COOL_PL2_W:-50}"
SAVED_PL1="/tmp/saved_rapl_pl1.txt"
SAVED_PL2="/tmp/saved_rapl_pl2.txt"
RAPL_DIR="/sys/class/powercap/intel-rapl:0"
# Display help
show_help() {
......@@ -91,6 +100,11 @@ run_diagnostics() {
echo "Min performance percentage:"
cat /sys/devices/system/cpu/intel_pstate/min_perf_pct 2>/dev/null
fi
if [ -d "$RAPL_DIR" ]; then
echo "Package power limits (spec for i7-10875H: PL1 45W):"
echo "PL1 $(( $(cat $RAPL_DIR/constraint_0_power_limit_uw) / 1000000 ))W sustained / PL2 $(( $(cat $RAPL_DIR/constraint_1_power_limit_uw) / 1000000 ))W burst"
fi
# Check for excessive disk I/O
echo -e "\n=== DISK I/O STATUS ==="
......@@ -171,6 +185,17 @@ run_diagnostics() {
echo "4. Run 'sudo $0 --extreme' before performance to apply maximum optimizations"
}
# Cap package power via RAPL (PL1 sustained / PL2 burst, in watts). Saves the
# current values once so --stop can restore them.
set_power_caps() {
[ -d "$RAPL_DIR" ] || return 0
[ -f "$SAVED_PL1" ] || cat $RAPL_DIR/constraint_0_power_limit_uw > $SAVED_PL1 2>/dev/null
[ -f "$SAVED_PL2" ] || cat $RAPL_DIR/constraint_1_power_limit_uw > $SAVED_PL2 2>/dev/null
echo $(($1 * 1000000)) > $RAPL_DIR/constraint_0_power_limit_uw 2>/dev/null
echo $(($2 * 1000000)) > $RAPL_DIR/constraint_1_power_limit_uw 2>/dev/null
echo "✓ Package power capped: PL1 ${1}W sustained / PL2 ${2}W burst"
}
# Function to apply standard performance optimizations
optimize_standard() {
check_root "--optimize"
......@@ -204,24 +229,28 @@ optimize_standard() {
echo "✓ CPU Turbo enabled"
fi
# Even at full performance, sustained power must stay at the 45W spec —
# the BIOS's 135W setting is what produced the 91°C thermal runaway.
set_power_caps 45 90
# Apply IRQ thread priorities
echo "Setting IRQ thread priorities..."
for irq in $(find /proc/irq/*/smp_affinity -type f 2>/dev/null | grep -v self); do
irq_num=$(echo $irq | cut -d '/' -f 4)
name=$(cat /proc/irq/$irq_num/name 2>/dev/null)
# Check if this is an audio-related IRQ
if [[ "$name" == *"snd"* ]] || [[ "$name" == *"audio"* ]] || [[ "$name" == *"hda"* ]]; then
echo "Setting audio IRQ $irq_num ($name) affinity"
echo 1 > /proc/irq/$irq_num/smp_affinity 2>/dev/null
fi
done
# Reduce kernel printk level to minimize logging impact
echo "Reducing kernel logging level..."
echo 1 > /proc/sys/kernel/printk
echo "✓ Kernel logging reduced"
# Set process priorities with standard mode
set_priorities standard
......@@ -283,7 +312,12 @@ optimize_extreme() {
echo 100 > /sys/devices/system/cpu/intel_pstate/min_perf_pct 2>/dev/null
echo "✓ Intel CPU min/max performance pinned to 100% (no downclocking, turbo reachable)"
fi
# Extreme pins clocks but must still bound sustained power at the 45W spec:
# with the BIOS's 135W limit the only brake left is the 100°C thermal
# limiter (measured 91°C mid-set 2026-07-18). PL2 90W keeps bursts snappy.
set_power_caps 45 90
# Disable NMI watchdog (can cause stutters)
echo "Disabling NMI watchdog..."
echo 0 > /proc/sys/kernel/nmi_watchdog
......@@ -378,6 +412,10 @@ optimize_cool() {
echo "✓ Peak clock capped to ${COOL_MAX_PCT}% (turbo bounded, idle stays low)"
fi
# The real heat lever: bound sustained package power in watts. Tune with
# COOL_PL1_W=NN (lower = cooler; 28W ≈ all-core ~2.5GHz on this chip).
set_power_caps "$COOL_PL1_W" "$COOL_PL2_W"
# Light VM tuning: avoid swap-driven stalls during a set without forcing anything.
echo 10 > /proc/sys/vm/swappiness 2>/dev/null
echo "✓ Swappiness lowered to 10"
......@@ -638,6 +676,13 @@ reset_system() {
rm -f "$SAVED_EPP"
echo "✓ EPP restored"
fi
# Restore RAPL package power limits if any mode capped them
if [ -d "$RAPL_DIR" ]; then
[ -f "$SAVED_PL1" ] && cat "$SAVED_PL1" > $RAPL_DIR/constraint_0_power_limit_uw 2>/dev/null && rm -f "$SAVED_PL1"
[ -f "$SAVED_PL2" ] && cat "$SAVED_PL2" > $RAPL_DIR/constraint_1_power_limit_uw 2>/dev/null && rm -f "$SAVED_PL2"
echo "✓ RAPL power limits restored"
fi
# Restore NMI watchdog
echo 1 > /proc/sys/kernel/nmi_watchdog
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment