Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 516F5CA1012 for ; Thu, 4 Sep 2025 06:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1756968116; h=to : date : message-id : mime-version : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : content-type : content-transfer-encoding : sender : from; bh=/TBmcLyRdhr7XBlUeMibVrdojtGnJUDPL/l9srKDdlo=; b=lM5K+ZYSrr1njsGzifNo1nL8zGav1qeEnZJ9XNaRjcTNjuCRrnKYDGAk+Imbhck8OEqjm Vo2Gl9Ga8PhIXQkP3bLFAAW3DHeaUN1qk4flRx5W7iD2mg/Frz2lOzVLhfZZf0UmVMc237B WXV9bKDaDEcuM8t8sZmu9v2XomjgHk0= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 9CDF43CD14A for ; Thu, 4 Sep 2025 08:41:56 +0200 (CEST) Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 4591E3CB5B0 for ; Thu, 4 Sep 2025 08:41:36 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 65CDF1A002DB for ; Thu, 4 Sep 2025 08:41:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756968093; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xAAzf454nmJTCk+or6eCJakKQnZ2sK2TQ4l7UD7fC/U=; b=EaZ2aWK5MAZyWH8PgjAcmUB/br3ixsXf16CtYJ/Lca/zGZ03LkrjyMwwii9nvQKjUjQ20O rNs/NYKktADNlpQ8gSIFUsZJANr45T6cuOXvmghnIQ0/VvIk45ugNzTtoAsF/Ye9fH0Dyy 0wZY7mmeZU6NOM2IVCVctCdICW7xqSo= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-304-i2n2XbLUMBSmL_V-HJp3sg-1; Thu, 04 Sep 2025 02:41:31 -0400 X-MC-Unique: i2n2XbLUMBSmL_V-HJp3sg-1 X-Mimecast-MFC-AGG-ID: i2n2XbLUMBSmL_V-HJp3sg_1756968090 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9C1D7195608B; Thu, 4 Sep 2025 06:41:30 +0000 (UTC) Received: from fedora-laptop-x1.redhat.com (unknown [10.72.112.183]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9EDEF180044F; Thu, 4 Sep 2025 06:41:27 +0000 (UTC) To: ltp@lists.linux.it Date: Thu, 4 Sep 2025 14:41:26 +0800 Message-ID: <20250904064126.125661-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: bo67Z5gb2b-T9ZY_wTjX2tyQlfeWZ8ngXJFQaOiNULM_1756968090 X-Mimecast-Originator: redhat.com X-Virus-Scanned: clamav-milter 1.0.7 at in-3.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH] sched_football: synchronize with kickoff flag to reduce skew X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Li Wang via ltp Reply-To: Li Wang Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ltp-bounces+ltp=archiver.kernel.org@lists.linux.it Sender: "ltp" Previously, thread synchronization in sched_football only relied on a thread_barrier. This ensured that all threads were created before the referee started the game, but did not fully prevent offense threads from getting a scheduling opportunity before defense threads were migrated, leading to occasional non-zero final ball positions on kvm or debug kernels. This patch introduces an explicit `kickoff_flag`: * All player threads (offense, defense, fans) wait at the barrier and then spin until the referee sets `kickoff_flag`. This reduces kernel scheduling skew, as threads only proceed once the referee explicitly signals the kickoff. * The referee now: - Waits at the barrier. - Clears the ball position. - Sets `kickoff_flag` to start the ball. * Game termination is also slightly reordered (by Cyril): - Final ball position is read before `game_over` is set, avoiding a race where the ball could still move right after defense threads stop. * Only test on RT-kernels. This makes startup sequencing more deterministic while still allowing some nondeterminism, which is intentional for testing scheduler behavior under load. Signed-off-by: Li Wang Signed-off-by: Cyril Hrubis Cc: Andrea Cervesato --- .../func/sched_football/sched_football.c | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/testcases/realtime/func/sched_football/sched_football.c b/testcases/realtime/func/sched_football/sched_football.c index 0617bdb87..97ac9d413 100644 --- a/testcases/realtime/func/sched_football/sched_football.c +++ b/testcases/realtime/func/sched_football/sched_football.c @@ -44,6 +44,7 @@ static tst_atomic_t the_ball; static int players_per_team = 0; static int game_length = DEF_GAME_LENGTH; +static tst_atomic_t kickoff_flag; static tst_atomic_t game_over; static char *str_game_length; @@ -55,6 +56,9 @@ void *thread_fan(void *arg LTP_ATTRIBUTE_UNUSED) { prctl(PR_SET_NAME, "crazy_fan", 0, 0, 0); pthread_barrier_wait(&start_barrier); + while (!tst_atomic_load(&kickoff_flag)) + ; + /*occasionally wake up and run across the field */ while (!tst_atomic_load(&game_over)) { struct timespec start, stop; @@ -80,6 +84,9 @@ void *thread_defense(void *arg LTP_ATTRIBUTE_UNUSED) { prctl(PR_SET_NAME, "defense", 0, 0, 0); pthread_barrier_wait(&start_barrier); + while (!tst_atomic_load(&kickoff_flag)) + ; + /*keep the ball from being moved */ while (!tst_atomic_load(&game_over)) { } @@ -92,6 +99,9 @@ void *thread_offense(void *arg LTP_ATTRIBUTE_UNUSED) { prctl(PR_SET_NAME, "offense", 0, 0, 0); pthread_barrier_wait(&start_barrier); + while (!tst_atomic_load(&kickoff_flag)) + ; + while (!tst_atomic_load(&game_over)) { tst_atomic_add_return(1, &the_ball); /* move the ball ahead one yard */ } @@ -115,9 +125,10 @@ void referee(int game_length) now = start; /* Start the game! */ - tst_atomic_store(0, &the_ball); - pthread_barrier_wait(&start_barrier); atrace_marker_write("sched_football", "Game_started!"); + pthread_barrier_wait(&start_barrier); + tst_atomic_store(0, &the_ball); + tst_atomic_store(1, &kickoff_flag); /* Watch the game */ while ((now.tv_sec - start.tv_sec) < game_length) { @@ -125,14 +136,14 @@ void referee(int game_length) gettimeofday(&now, NULL); } - /* Stop the game! */ - tst_atomic_store(1, &game_over); - atrace_marker_write("sched_football", "Game_Over!"); - /* Blow the whistle */ final_ball = tst_atomic_load(&the_ball); tst_res(TINFO, "Final ball position: %d", final_ball); + /* Stop the game! */ + tst_atomic_store(1, &game_over); + atrace_marker_write("sched_football", "Game_Over!"); + TST_EXP_EXPR(final_ball == 0); } @@ -154,6 +165,7 @@ static void do_test(void) /* We're the ref, so set our priority right */ param.sched_priority = sched_get_priority_min(SCHED_FIFO) + 80; sched_setscheduler(0, SCHED_FIFO, ¶m); + tst_atomic_store(0, &kickoff_flag); /* * Start the offense @@ -186,6 +198,9 @@ static void do_test(void) static void do_setup(void) { + if (!tst_check_preempt_rt()) + tst_brk(TCONF, "Test requires real-time kernel"); + if (tst_parse_int(str_game_length, &game_length, 1, INT_MAX)) tst_brk(TBROK, "Invalid game length '%s'", str_game_length); -- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp