All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wander Lairson Costa <wander@redhat.com>
To: williams@redhat.com, jkacur@redhat.com, linux-rt-users@vger.kernel.org
Cc: juri.lelli@redhat.com, luffyluo@tencent.com,
	davidlt@rivosinc.com, Wander Lairson Costa <wander@redhat.com>
Subject: [PATCH 09/11] tests: start stalld before starvation_gen in all tests
Date: Fri, 10 Jul 2026 10:38:08 -0300	[thread overview]
Message-ID: <20260710133810.72398-10-wander@redhat.com> (raw)
In-Reply-To: <20260710133810.72398-1-wander@redhat.com>

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 <wander@redhat.com>
---
 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


  parent reply	other threads:[~2026-07-10 13:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10 13:37 [PATCH 00/11] tests: harden functional test suite against flakiness Wander Lairson Costa
2026-07-10 13:38 ` [PATCH 01/11] stalld: add readiness log marker for tests Wander Lairson Costa
2026-07-10 13:38 ` [PATCH 02/11] tests: use fail() for error paths in helpers Wander Lairson Costa
2026-07-10 13:38 ` [PATCH 03/11] tests: add --verbose flag for bash trace output Wander Lairson Costa
2026-07-10 13:38 ` [PATCH 04/11] tests: drop journal logging from test framework Wander Lairson Costa
2026-07-10 13:38 ` [PATCH 05/11] tests: fix intermittent starvation_gen readiness failure Wander Lairson Costa
2026-07-10 13:38 ` [PATCH 06/11] tests: add --fail-fast flag to stop on first failure Wander Lairson Costa
2026-07-10 13:38 ` [PATCH 07/11] tests: dump log contents on assert_log_contains failure Wander Lairson Costa
2026-07-10 13:38 ` [PATCH 08/11] tests: dump log on start_stalld_with_log failure Wander Lairson Costa
2026-07-10 13:38 ` Wander Lairson Costa [this message]
2026-07-10 13:38 ` [PATCH 10/11] tests: add startup timing to stalld launch helpers Wander Lairson Costa
2026-07-10 13:38 ` [PATCH 11/11] tests: increase stalld initialization timeout to 240s Wander Lairson Costa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260710133810.72398-10-wander@redhat.com \
    --to=wander@redhat.com \
    --cc=davidlt@rivosinc.com \
    --cc=jkacur@redhat.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=luffyluo@tencent.com \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.