[PATCH] selftests: cpufreq: stop CPU hotplug loop after cpufreq update test

From: xiong yining

Date: Sat Oct 10 2026 - 06:04:10 EST


Original test uses a fixed 5000 iteration loop to trigger CPU hotplug
for verifying cpufreq synchronization between CPU hotplug and sysfs
writes.

Two issues exist:
1. Background hotplug task keeps running after test completes, causing
redundant CPU on/offline operations.
2. When cpufreq frequency setup is slow, the hotplug loop may exit
before frequency updates finish, which breaks test purpose.

Introduce a file-based stop flag to control the infinite hotplug loop.
After all cpufreq updates complete, create the stop flag file and
wait for the hotplug task to exit.

This makes hotplug run only during cpufreq sysfs write test,
align with test objective.

Signed-off-by: xiong yining <xiongyining1480@xxxxxxxxxxxxxx>
---
tools/testing/selftests/cpufreq/special-tests.sh | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/cpufreq/special-tests.sh b/tools/testing/selftests/cpufreq/special-tests.sh
index e87ed7c8e5e5..14530c1b8d25 100755
--- a/tools/testing/selftests/cpufreq/special-tests.sh
+++ b/tools/testing/selftests/cpufreq/special-tests.sh
@@ -97,14 +97,20 @@ governor_race()
hotplug_with_updates_cpu()
{
local filepath="$CPUROOT/$1/cpufreq"
+ local stop_flag="/tmp/stop_hotplug_$1"
+ rm -f "$stop_flag"

# switch to ondemand
__switch_governor_for_cpu $1 "ondemand"

- for i in `seq 1 5000`
+ while true
do
+ if [ -f "$stop_flag" ]; then
+ break
+ fi
reboot_cpu $1
done &
+ local hotplug_pid=$!

local freqs=$(cat $filepath/scaling_available_frequencies)
local oldfreq=$(cat $filepath/scaling_min_freq)
@@ -117,6 +123,10 @@ hotplug_with_updates_cpu()
done
done

+ touch "$stop_flag"
+ wait $hotplug_pid
+ rm -f "$stop_flag"
+
# restore old freq
echo $oldfreq > $filepath/scaling_min_freq
}

base-commit: 28924df2a08f440c73991b83028032c901de2ae4
--
2.34.1