#!/bin/sh
# DF-4890 race amplifier — REAL HARDWARE ONLY (needs CST C2/C3, see
# precond_probe.sh). Must run as root. Run together with an instrumented
# kernel to observe AcpiOsAcquireLock(HardwareLock) branch overlap, or on a
# stock kernel to look for ACPI malfunction symptoms (dmesg errors, missed
# wakeups, S3 anomalies) under load.
#
# Strategy: force all CPUs into the deepest C-state so their idle threads
# run the C3 BM/ARB bit-register writes (acpi_cpu_cstate.c:935,958,977),
# while continuously generating normal-thread AcpiWriteBitRegister traffic
# (CST re-evaluation notify + cx_lowest churn -> acpi_cpu_cstate.c:668,810,
# hwxface.c:411 RMW under the same lock via the lockmgr branch).
set -e
sysctl hw.acpi.cpu0.cx_supported
sysctl -w hw.acpi.cpu.cx_lowest=C3
# churn: push CST re-evaluation + state changes while CPUs idle
i=0
while [ $i -lt 600 ]; do
    sysctl -w hw.acpi.cpu.cx_lowest=C1 >/dev/null 2>&1 || true
    sysctl -w hw.acpi.cpu.cx_lowest=C3 >/dev/null 2>&1 || true
    i=$((i+1))
done
dmesg | tail -50
