[PATCH 09/11] tests: start stalld before starvation_gen in all tests
From: Wander Lairson Costa <hidden>
Date: 2026-07-10 13:39:17
Subsystem:
the rest · Maintainer:
Linus Torvalds
The test sections previously started starvation_gen before stalld,
based on a belief that stalld's idle detection could miss tasks
appearing after it began scanning. Source analysis showed this
concern was unfounded -- stalld re-scans continuously and will detect
starvation regardless of when the starved tasks appear. Meanwhile,
the old ordering introduced intermittent failures: starvation_gen
could finish and exit before stalld had a chance to scan, causing
timeouts in assert_starvation_detected and wait_for_boost_detected.
Reorder all 15 test sections across test_fifo_boosting.sh,
test_fifo_priority_starvation.sh, test_starvation_detection.sh,
test_starvation_threshold.sh, and test_log_only.sh so that
start_stalld_with_log runs before start_starvation_gen. Remove stale
comments about the old ordering rationale ("Create starvation FIRST",
"avoid idle detection race").
Signed-off-by: Wander Lairson Costa <redacted>
---
tests/functional/test_fifo_boosting.sh | 22 +++++------
.../test_fifo_priority_starvation.sh | 38 ++++++++-----------
tests/functional/test_log_only.sh | 10 ++---
tests/functional/test_starvation_detection.sh | 18 ++++-----
tests/functional/test_starvation_threshold.sh | 23 +++++------
5 files changed, 45 insertions(+), 66 deletions(-)
diff --git a/tests/functional/test_fifo_boosting.sh b/tests/functional/test_fifo_boosting.sh
index e489950..4d2841d 100755
--- a/tests/functional/test_fifo_boosting.sh
+++ b/tests/functional/test_fifo_boosting.sh@@ -22,16 +22,14 @@ init_functional_test "SCHED_FIFO Boosting Mechanism" "test_fifo_boost" test_section "Test 1: FIFO Boost with -F Flag" threshold=5 -# Create starvation FIRST (before stalld starts) starvation_duration=$((threshold + 5)) -log "Creating starvation on CPU ${TEST_CPU} for ${starvation_duration}s" -start_starvation_gen -c ${TEST_CPU} -p 80 -n 2 -d ${starvation_duration} log "Starting stalld with -F flag to force SCHED_FIFO boosting" -# Note: -F requires non-single-threaded mode (aggressive mode) -# Use -g 1 for 1-second granularity to ensure timely detection start_stalld_with_log "${STALLD_LOG}" -f -v -g 1 -N -F -A -t $threshold -c ${TEST_CPU} -a ${STALLD_CPU} +log "Creating starvation on CPU ${TEST_CPU} for ${starvation_duration}s" +start_starvation_gen -c ${TEST_CPU} -p 80 -n 2 -d ${starvation_duration} + # Wait for boosting log "Waiting for boost detection..." assert_boost_detected "${STALLD_LOG}" "Boosting occurred with -F flag"
@@ -48,14 +46,13 @@ test_section "Test 2: FIFO Priority Verification" threshold=5 rm -f "${STALLD_LOG}" -# Create starvation FIRST +log "Starting stalld with -F flag (FIFO boosting)" +start_stalld_with_log "${STALLD_LOG}" -f -v -g 1 -N -F -A -t $threshold -c ${TEST_CPU} -a ${STALLD_CPU} + log "Creating starvation on CPU ${TEST_CPU}" start_starvation_gen -c ${TEST_CPU} -p 80 -n 1 -d 10 tracked_pid=$(find_starved_child "${STARVE_PID}") -log "Starting stalld with -F flag (FIFO boosting)" -start_stalld_with_log "${STALLD_LOG}" -f -v -g 1 -N -F -A -t $threshold -c ${TEST_CPU} -a ${STALLD_CPU} - # Wait for boosting log "Waiting for boost detection..." wait_for_boost_detected "${STALLD_LOG}"
@@ -101,13 +98,12 @@ log " Expected cycles: ~5" rm -f "${STALLD_LOG}" -# Create starvation FIRST -log "Creating starvation on CPU ${TEST_CPU}" -start_starvation_gen -c ${TEST_CPU} -p 80 -n 1 -d 12 - start_stalld_with_log "${STALLD_LOG}" -f -v -g 1 -N -F -A -t $threshold -c ${TEST_CPU} -a ${STALLD_CPU} \ -d ${boost_duration} -p ${boost_period} -r ${boost_runtime} +log "Creating starvation on CPU ${TEST_CPU}" +start_starvation_gen -c ${TEST_CPU} -p 80 -n 1 -d 12 + # Wait for boosting to start log "Waiting for boost detection..." wait_for_boost_detected "${STALLD_LOG}"
diff --git a/tests/functional/test_fifo_priority_starvation.sh b/tests/functional/test_fifo_priority_starvation.sh
index 028b825..86c6517 100755
--- a/tests/functional/test_fifo_priority_starvation.sh
+++ b/tests/functional/test_fifo_priority_starvation.sh@@ -27,17 +27,16 @@ test_section "Test 1: Basic FIFO-on-FIFO Starvation Detection" log "Testing: FIFO:10 blocker starves FIFO:5 blockee" threshold=5 - -# Create starvation BEFORE starting stalld to avoid idle detection race starvation_duration=$((threshold + 5)) + +log "Starting stalld with ${threshold}s threshold (log-only mode)" +start_stalld_with_log "${STALLD_LOG}" -f -v -l -t $threshold -c ${TEST_CPU} -a ${STALLD_CPU} + log "Creating FIFO-on-FIFO starvation on CPU ${TEST_CPU} for ${starvation_duration}s" log " Blocker: SCHED_FIFO priority 10" log " Blockee: SCHED_FIFO priority 5" start_starvation_gen -c ${TEST_CPU} -p 10 -b 5 -n 2 -d ${starvation_duration} -log "Starting stalld with ${threshold}s threshold (log-only mode)" -start_stalld_with_log "${STALLD_LOG}" -f -v -l -t $threshold -c ${TEST_CPU} -a ${STALLD_CPU} - # Wait for starvation detection log "Waiting for starvation detection..." assert_starvation_detected "${STALLD_LOG}" "FIFO-on-FIFO starvation detected"
@@ -57,6 +56,9 @@ rm -f "${STALLD_LOG}" threshold=5 boost_duration=3 +log "Starting stalld with boosting enabled" +start_stalld_with_log "${STALLD_LOG}" -f -v -N -t $threshold -c ${TEST_CPU} -a ${STALLD_CPU} -d ${boost_duration} + log "Creating FIFO-on-FIFO starvation on CPU ${TEST_CPU}" start_starvation_gen -c ${TEST_CPU} -p 10 -b 5 -n 1 -d 12
@@ -69,9 +71,6 @@ if [ -n "${blockee_pid}" ]; then log "Blockee task PID ${blockee_pid}, context switches before boost: ${ctxt_before}" fi -log "Starting stalld with boosting enabled" -start_stalld_with_log "${STALLD_LOG}" -f -v -N -t $threshold -c ${TEST_CPU} -a ${STALLD_CPU} -d ${boost_duration} - # Wait for detection and boosting wait_for_boost_detected "${STALLD_LOG}" sleep ${boost_duration}
@@ -103,16 +102,15 @@ log "Verify duration accumulates correctly (task merging)" rm -f "${STALLD_LOG}" threshold=3 - -# Create long starvation to trigger multiple detection cycles starvation_duration=12 -log "Creating long FIFO-on-FIFO starvation for ${starvation_duration}s" -start_starvation_gen -c ${TEST_CPU} -p 10 -b 5 -n 2 -d ${starvation_duration} log "Starting stalld with ${threshold}s threshold (log-only mode)" log "Will monitor for multiple detection cycles to verify timestamp preservation" start_stalld_with_log "${STALLD_LOG}" -f -v -l -t $threshold -c ${TEST_CPU} -a ${STALLD_CPU} +log "Creating long FIFO-on-FIFO starvation for ${starvation_duration}s" +start_starvation_gen -c ${TEST_CPU} -p 10 -b 5 -n 2 -d ${starvation_duration} + # Wait for multiple detection cycles log "Waiting for first detection cycle..." wait_for_starvation_detected "${STALLD_LOG}"
@@ -147,15 +145,14 @@ log "Testing edge case with only 1 priority difference" rm -f "${STALLD_LOG}" threshold=5 -# Test with very close priorities +log "Starting stalld with ${threshold}s threshold" +start_stalld_with_log "${STALLD_LOG}" -f -v -l -t $threshold -c ${TEST_CPU} -a ${STALLD_CPU} + log "Creating FIFO-on-FIFO starvation with close priorities" log " Blocker: SCHED_FIFO priority 6" log " Blockee: SCHED_FIFO priority 5" start_starvation_gen -c ${TEST_CPU} -p 6 -b 5 -n 1 -d $((threshold + 5)) -log "Starting stalld with ${threshold}s threshold" -start_stalld_with_log "${STALLD_LOG}" -f -v -l -t $threshold -c ${TEST_CPU} -a ${STALLD_CPU} - # Wait for starvation detection log "Waiting for starvation detection..." if wait_for_starvation_detected "${STALLD_LOG}"; then
@@ -180,16 +177,13 @@ log "Ensure stalld boosts the blockee (FIFO:5), not the blocker (FIFO:10)" rm -f "${STALLD_LOG}" threshold=5 +log "Starting stalld with boosting enabled" +start_stalld_with_log "${STALLD_LOG}" -f -v -N -t $threshold -c ${TEST_CPU} -a ${STALLD_CPU} + log "Creating FIFO-on-FIFO starvation" start_starvation_gen -c ${TEST_CPU} -p 10 -b 5 -n 2 -d 12 -v - -# Extract blocker and blockee PIDs from starvation_gen output -# The output shows "Blocker TID: <pid>" and "Blockee N TID: <pid>" log "Starvation generator PID: ${STARVE_PID}" -log "Starting stalld with boosting enabled" -start_stalld_with_log "${STALLD_LOG}" -f -v -N -t $threshold -c ${TEST_CPU} -a ${STALLD_CPU} - # Wait for boosting log "Waiting for boost detection..." if wait_for_boost_detected "${STALLD_LOG}"; then
diff --git a/tests/functional/test_log_only.sh b/tests/functional/test_log_only.sh
index b38db70..cba7596 100755
--- a/tests/functional/test_log_only.sh
+++ b/tests/functional/test_log_only.sh@@ -44,16 +44,12 @@ echo "Stalld will run on CPU ${STALLD_CPU}" LOG_FILE="/tmp/stalld_test_log_only_$$.log" CLEANUP_FILES+=("${LOG_FILE}") -echo "Creating starvation on CPU ${TEST_CPU} (will run for 10 seconds)" - -# Start starvation generator BEFORE stalld to ensure CPU is busy from the start -start_starvation_gen -c ${TEST_CPU} -p 10 -n 1 -d 10 -STARVGEN_PID=${STARVE_PID} - -# Start stalld in log-only mode with verbose output to capture logs echo "Starting stalld in log-only mode with 5 second threshold" start_stalld_with_log "${LOG_FILE}" -f -v -l -t 5 -c ${TEST_CPU} -a ${STALLD_CPU} +echo "Creating starvation on CPU ${TEST_CPU} (will run for 10 seconds)" +start_starvation_gen -c ${TEST_CPU} -p 10 -n 1 -d 10 +STARVGEN_PID=${STARVE_PID} echo "Starvation generator started (PID ${STARVGEN_PID})" echo "Waiting for starvation detection..."
diff --git a/tests/functional/test_starvation_detection.sh b/tests/functional/test_starvation_detection.sh
index 52031c5..9702f99 100755
--- a/tests/functional/test_starvation_detection.sh
+++ b/tests/functional/test_starvation_detection.sh@@ -24,15 +24,14 @@ NUM_CPUS=$(get_num_cpus) test_section "Test 1: Basic Starvation Detection" threshold=5 - -# Create starvation BEFORE starting stalld to avoid idle detection race starvation_duration=$((threshold + 5)) -log "Creating starvation on CPU ${TEST_CPU} for ${starvation_duration}s" -start_starvation_gen -c ${TEST_CPU} -p 80 -n 2 -d ${starvation_duration} log "Starting stalld with ${threshold}s threshold (log-only mode)" start_stalld_with_log "${STALLD_LOG}" -f -v -N -l -t $threshold -c ${TEST_CPU} -a ${STALLD_CPU} +log "Creating starvation on CPU ${TEST_CPU} for ${starvation_duration}s" +start_starvation_gen -c ${TEST_CPU} -p 80 -n 2 -d ${starvation_duration} + # Wait for starvation detection log "Waiting for starvation detection..." assert_starvation_detected "${STALLD_LOG}" "Starvation detected"
@@ -50,13 +49,12 @@ test_section "Test 2: Context Switch Count Tracking" rm -f "${STALLD_LOG}" threshold=5 -# Create starvation -log "Creating starvation on CPU ${TEST_CPU}" -start_starvation_gen -c ${TEST_CPU} -p 80 -n 1 -d 10 - log "Starting stalld with ${threshold}s threshold (log-only mode)" start_stalld_with_log "${STALLD_LOG}" -f -v -N -l -t $threshold -c ${TEST_CPU} -a ${STALLD_CPU} +log "Creating starvation on CPU ${TEST_CPU}" +start_starvation_gen -c ${TEST_CPU} -p 80 -n 1 -d 10 + # Wait for starvation detection log "Waiting for starvation detection..." wait_for_starvation_detected "${STALLD_LOG}"
@@ -116,6 +114,8 @@ else rm -f "${STALLD_LOG}" threshold=5 + start_stalld_with_log "${STALLD_LOG}" -f -v -N -l -t $threshold -c ${CPU0},${CPU1} -a ${STALLD_CPU_MULTI} + # Create starvation on CPU0 log "Creating starvation on CPU ${CPU0}" start_starvation_gen -c ${CPU0} -p 80 -n 1 -d 12
@@ -126,8 +126,6 @@ else start_starvation_gen -c ${CPU1} -p 80 -n 1 -d 12 STARVE_PID1=${STARVE_PID} - start_stalld_with_log "${STALLD_LOG}" -f -v -N -l -t $threshold -c ${CPU0},${CPU1} -a ${STALLD_CPU_MULTI} - # Wait for starvation detection on both CPUs log "Waiting for starvation detection on CPU ${CPU0}..." assert_starvation_detected "${STALLD_LOG}" "Starvation detected on CPU ${CPU0}" "30" "${CPU0}"
diff --git a/tests/functional/test_starvation_threshold.sh b/tests/functional/test_starvation_threshold.sh
index b372a87..bb4a862 100755
--- a/tests/functional/test_starvation_threshold.sh
+++ b/tests/functional/test_starvation_threshold.sh@@ -25,16 +25,14 @@ init_functional_test "Starvation Threshold Option (-t)" "test_threshold" test_section "Test 1: Custom threshold of 5 seconds" threshold=5 - -# Create starvation BEFORE starting stalld (avoid detecting kworker tasks) starvation_duration=10 -log "Creating starvation on CPU ${TEST_CPU} for ${starvation_duration}s" -start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${starvation_duration} log "Starting stalld with ${threshold}s threshold" -# Use -i to ignore kernel workers that may starve before our test tasks start_stalld_with_log "${STALLD_LOG}" -f -v -N -M -g 1 -i "ksoftirqd,kworker" -c "${TEST_CPU}" -a "${STALLD_CPU}" -t ${threshold} +log "Creating starvation on CPU ${TEST_CPU} for ${starvation_duration}s" +start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${starvation_duration} + # Wait for starvation detection log "Waiting for detection (threshold: ${threshold}s)"
@@ -51,15 +49,14 @@ test_section "Test 2: No detection before threshold" threshold=10 rm -f "${STALLD_LOG}" -# Create starvation BEFORE starting stalld (avoid detecting kworker tasks) -# Create starvation that will last 6 seconds (less than threshold) starvation_duration=6 -log "Creating short starvation (${starvation_duration}s) with threshold of ${threshold}s" -start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${starvation_duration} log "Starting stalld with ${threshold}s threshold" start_stalld_with_log "${STALLD_LOG}" -f -v -N -M -g 1 -c "${TEST_CPU}" -a "${STALLD_CPU}" -t ${threshold} +log "Creating short starvation (${starvation_duration}s) with threshold of ${threshold}s" +start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${starvation_duration} + # Wait for starvation generator to fully complete wait "${STARVE_PID}" 2>/dev/null || true
@@ -82,16 +79,14 @@ test_section "Test 3: Shorter threshold (3 seconds)" threshold=3 rm -f "${STALLD_LOG}" -# Create starvation BEFORE starting stalld (avoid detecting kworker tasks) -# Create starvation for 8 seconds starvation_duration=8 -log "Creating starvation for ${starvation_duration}s with threshold of ${threshold}s" -start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${starvation_duration} log "Starting stalld with ${threshold}s threshold" -# Use -i to ignore kernel workers that may starve before our test tasks start_stalld_with_log "${STALLD_LOG}" -f -v -N -M -g 1 -i "ksoftirqd,kworker" -c "${TEST_CPU}" -a "${STALLD_CPU}" -t ${threshold} +log "Creating starvation for ${starvation_duration}s with threshold of ${threshold}s" +start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${starvation_duration} + # Wait for starvation detection log "Waiting for detection (threshold: ${threshold}s)"
--
2.55.0