From: Jan Polensky <japo@linux.ibm.com>
To: chrubis@suse.cz, pvorel@suse.cz, jstultz@google.com
Cc: Linux Test Project <ltp@lists.linux.it>
Subject: [LTP] [PATCH v1 1/1] sched_football: harden kickoff synchronization on high-CPU systems
Date: Tue, 24 Feb 2026 11:45:44 +0100 [thread overview]
Message-ID: <20260224104544.101292-1-japo@linux.ibm.com> (raw)
The sched_football test has been intermittently failing, most noticeably
on systems with many CPUs and/or under load, due to a startup ordering
hole around kickoff.
At game start the referee can transition into kickoff while not all
defense threads have reliably reached their blocking path yet. This
creates a window where offense threads may run and increment the_ball.
Fix the startup protocol:
- Introduce a dedicated defense_ready_barrier to rendezvous all defense
threads with the referee before kickoff.
- Increase the pre-kickoff settle time (RT: 100 ms, non-RT: 2.5 s) to
account for large CPU counts and loaded systems.
- Add a compiler barrier in the defense busy-loop to prevent it from
being optimized away.
- Add an additional barrier step after the initial start phase so all
threads are positioned deterministically before the game begins.
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
---
| 23 ++++++++++++++-----
1 file changed, 17 insertions(+), 6 deletions(-)
--git a/testcases/realtime/func/sched_football/sched_football.c b/testcases/realtime/func/sched_football/sched_football.c
index 2cb85322d782..08cdc2fd8b4e 100644
--- a/testcases/realtime/func/sched_football/sched_football.c
+++ b/testcases/realtime/func/sched_football/sched_football.c
@@ -50,6 +50,7 @@ static tst_atomic_t game_over;
static char *str_game_length;
static char *str_players_per_team;
static pthread_barrier_t start_barrier;
+static pthread_barrier_t defense_ready_barrier;
/* These are fans running across the field. They're trying to interrupt/distract everyone */
void *thread_fan(void *arg LTP_ATTRIBUTE_UNUSED)
@@ -81,11 +82,13 @@ void *thread_defense(void *arg LTP_ATTRIBUTE_UNUSED)
{
prctl(PR_SET_NAME, "defense", 0, 0, 0);
pthread_barrier_wait(&start_barrier);
+ pthread_barrier_wait(&defense_ready_barrier);
while (!tst_atomic_load(&kickoff_flag))
;
- /*keep the ball from being moved */
+ /* Keep the ball from being moved using a compiler barrier */
while (!tst_atomic_load(&game_over)) {
+ __asm__ __volatile__("" ::: "memory");
}
return NULL;
@@ -124,14 +127,18 @@ void referee(int game_length)
/* Start the game! */
atrace_marker_write("sched_football", "Game_started!");
pthread_barrier_wait(&start_barrier);
- usleep(200000);
+
+ /* Wait for defense to be ready before starting the game */
+ pthread_barrier_wait(&defense_ready_barrier);
+
+ /* Give defense threads time to establish */
+ if (tst_check_preempt_rt())
+ usleep(100000);
+ else
+ usleep(2500000);
tst_atomic_store(0, &the_ball);
tst_atomic_store(1, &kickoff_flag);
- if (tst_check_preempt_rt())
- usleep(20000);
- else
- usleep(2000000);
/* Watch the game */
while ((now.tv_sec - start.tv_sec) < game_length) {
@@ -170,6 +177,9 @@ static void do_test(void)
sched_setscheduler(0, SCHED_FIFO, ¶m);
tst_atomic_store(0, &kickoff_flag);
+ /* Defense ready barrier: defense threads + referee */
+ pthread_barrier_init(&defense_ready_barrier, NULL, players_per_team + 1);
+
/*
* Start the offense
* They are lower priority than defense, so they must be started first.
@@ -197,6 +207,7 @@ static void do_test(void)
referee(game_length);
pthread_barrier_destroy(&start_barrier);
+ pthread_barrier_destroy(&defense_ready_barrier);
}
static void do_setup(void)
--
2.53.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2026-02-24 10:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-24 10:45 Jan Polensky [this message]
2026-02-24 12:44 ` [LTP] [PATCH v1 1/1] sched_football: harden kickoff synchronization on high-CPU systems Andrea Cervesato via ltp
2026-02-24 21:03 ` John Stultz via ltp
2026-02-25 9:23 ` Andrea Cervesato via ltp
2026-02-25 19:11 ` John Stultz via ltp
2026-02-26 9:43 ` Andrea Cervesato via ltp
2026-03-02 8:56 ` Jan Polensky
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=20260224104544.101292-1-japo@linux.ibm.com \
--to=japo@linux.ibm.com \
--cc=chrubis@suse.cz \
--cc=jstultz@google.com \
--cc=ltp@lists.linux.it \
--cc=pvorel@suse.cz \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox