Skip to contentSkip to conversation

cpuhotplug03.sh: Poll for CPU migration instead of sleeping

PATCH Applied Benjamin Wheeler via ltp 3 participants 5 messages Jul 14 – Jul 17

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpuhotplug03.sh: Poll for CPU migration instead of sleeping

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).

---
 .../cpu_hotplug/functional/cpuhotplug03.sh    | 43 ++++++++++++-------
 1 file changed, 27 insertions(+), 16 deletions(-)
testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug03.sh +27 -16
index 3a461e30c..1577f3e6e 100755
@@ -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

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Benjamin,

Quoted 1 line · Benjamin Wheeler

cpuhotplug03.sh: Poll for CPU migration instead of sleeping

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp