* [LTP] [PATCH v1 1/1] cpuhotplug03.sh: Poll for CPU migration instead of sleeping
@ 2026-07-14 16:28 Benjamin Wheeler via ltp
2026-07-14 18:07 ` [LTP] " linuxtestproject.agent
2026-07-16 15:40 ` [LTP] [PATCH v1 1/1] " Cyril Hrubis
0 siblings, 2 replies; 3+ messages in thread
From: Benjamin Wheeler via ltp @ 2026-07-14 16:28 UTC (permalink / raw)
To: ltp
The test onlined the target CPU, slept a fixed one second and then
checked once whether the scheduler had migrated a cpuhotplug_do_spin_loop
process onto it. A blind sleep is both racy (the migration may not have
happened yet on a busy or slow system) and wasteful (it always waits the
full second even when the migration is immediate).
Replace the sleep and single check with tst_retry(), which retries the
check a few times until a process is seen on the onlined CPU. The
migration check is factored out into a check_cpu_migrated() helper.
tst_retry() is the retry helper available in the legacy shell test API
(test.sh) that this test uses; TST_RETRY_FUNC() only exists in the new
API (tst_test.sh), so it is not usable here without converting the whole
test, which is out of scope for this change.
The TBROK vs TFAIL distinction is preserved: if no spin loop processes
are running at all it is reported as a broken test (TBROK), whereas
processes running but none migrating to the onlined CPU remains a
genuine failure (TFAIL).
Signed-off-by: Benjamin Wheeler <benjamin.wheeler@canonical.com>
---
.../cpu_hotplug/functional/cpuhotplug03.sh | 43 ++++++++++++-------
1 file changed, 27 insertions(+), 16 deletions(-)
diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug03.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug03.sh
index 3a461e30c..1577f3e6e 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug03.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug03.sh
@@ -50,6 +50,20 @@ do_clean()
set_all_cpu_states "$cpu_states"
}
+# check_cpu_migrated()
+#
+# Returns 0 if at least one cpuhotplug_do_spin_loop process is running
+# on CPU_TO_TEST, non-zero otherwise.
+# Since procps v3.3.15, we need to accurately select command name by -C
+# option, because procps cannot truncate normal command name to 15
+# characters by default.
+check_cpu_migrated()
+{
+ ps -o psr -o command --no-headers -C cpuhotplug_do_s \
+ | sed -e "s/^ *//" | cut -d' ' -f 1 \
+ | grep -q "^${CPU_TO_TEST}$"
+}
+
while getopts c:l: OPTION; do
case $OPTION in
c)
@@ -120,21 +134,18 @@ until [ $LOOP_COUNT -gt $HOTPLUG03_LOOPS ]; do
tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
fi
- sleep 1
-
- # Verify at least one process has migrated to the new CPU
- # Since procps v3.3.15, we need to accurately select command name
- # by -C option, because procps cannot trucate normal command name
- # to 15 characters by default).
- ps -o psr -o command --no-headers -C cpuhotplug_do_s
- if [ $? -ne 0 ]; then
- tst_brkm TBROK "No cpuhotplug_do_spin_loop processes \
- found on any processor"
- fi
- NUM=`ps -o psr -o command --no-headers -C cpuhotplug_do_s \
- | sed -e "s/^ *//" | cut -d' ' -f 1 | grep "^${CPU_TO_TEST}$" \
- | wc -l`
- if [ $NUM -lt 1 ]; then
+ # Verify at least one process has migrated to the new CPU.
+ # Retry the check in a loop instead of blindly sleeping, since the
+ # scheduler may take a while to migrate a task to the freshly
+ # onlined CPU.
+ if ! tst_retry "check_cpu_migrated"; then
+ # Distinguish a broken workload (no spin loop processes running
+ # at all) from a genuine failure (processes running, but none
+ # migrated to the onlined CPU).
+ if ! ps --no-headers -C cpuhotplug_do_s >/dev/null; then
+ tst_brkm TBROK "No cpuhotplug_do_spin_loop processes \
+ found on any processor"
+ fi
tst_resm TFAIL "No cpuhotplug_do_spin_loop processes found on \
CPU${CPU_TO_TEST}"
tst_exit
@@ -145,7 +156,7 @@ until [ $LOOP_COUNT -gt $HOTPLUG03_LOOPS ]; do
LOOP_COUNT=$((LOOP_COUNT+1))
done
-tst_resm TPASS "$NUM cpuhotplug_do_spin_loop processes found on \
+tst_resm TPASS "cpuhotplug_do_spin_loop process(es) migrated to \
CPU${CPU_TO_TEST}"
tst_exit
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-16 15:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-14 16:28 [LTP] [PATCH v1 1/1] cpuhotplug03.sh: Poll for CPU migration instead of sleeping Benjamin Wheeler via ltp
2026-07-14 18:07 ` [LTP] " linuxtestproject.agent
2026-07-16 15:40 ` [LTP] [PATCH v1 1/1] " Cyril Hrubis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.