public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: John Stultz via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: kernel-team@android.com, John Stultz <jstultz@google.com>,
	Darren Hart <darren@os.amperecomputing.com>
Subject: [LTP] [PATCH 2/6] sched_football: Use atomic for ball
Date: Tue, 23 Apr 2024 15:57:59 -0700	[thread overview]
Message-ID: <20240423225821.4003538-3-jstultz@google.com> (raw)
In-Reply-To: <20240423225821.4003538-1-jstultz@google.com>

Use atomic type for the ball value, as we don't have any locking
going on.

Cc: kernel-team@android.com
Cc: Darren Hart <darren@os.amperecomputing.com>
Signed-off-by: John Stultz <jstultz@google.com>
---
 testcases/realtime/func/sched_football/sched_football.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/testcases/realtime/func/sched_football/sched_football.c b/testcases/realtime/func/sched_football/sched_football.c
index 1e205219d..359c96703 100644
--- a/testcases/realtime/func/sched_football/sched_football.c
+++ b/testcases/realtime/func/sched_football/sched_football.c
@@ -71,7 +71,7 @@
 #define DEF_GAME_LENGTH 5
 
 /* Here's the position of the ball */
-volatile int the_ball;
+static atomic_t the_ball;
 
 static int players_per_team = 0;
 static int game_length = DEF_GAME_LENGTH;
@@ -122,7 +122,7 @@ void *thread_offense(void *arg)
 {
 	atomic_inc(&players_ready);
 	while (1) {
-		the_ball++;	/* move the ball ahead one yard */
+		atomic_inc(&the_ball);	/* move the ball ahead one yard */
 	}
 	return NULL;
 }
@@ -138,16 +138,16 @@ int referee(int game_length)
 	now = start;
 
 	/* Start the game! */
-	the_ball = 0;
+	atomic_set(0, &the_ball);
 
 	/* Watch the game */
 	while ((now.tv_sec - start.tv_sec) < game_length) {
 		sleep(1);
 		gettimeofday(&now, NULL);
 	}
+	final_ball = atomic_get(&the_ball);
 	/* Blow the whistle */
 	printf("Game Over!\n");
-	final_ball = the_ball;
 	printf("Final ball position: %d\n", final_ball);
 	return final_ball != 0;
 }
-- 
2.44.0.769.g3c40516874-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2024-04-24 12:23 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-23 22:57 [LTP] [PATCH 0/6] sched_football: Re-add crazy fans and other cleanups John Stultz via ltp
2024-04-23 22:57 ` [LTP] [PATCH 1/6] sched_football: Drop use of sched_yeild() John Stultz via ltp
2024-04-23 22:57 ` John Stultz via ltp [this message]
2024-04-29  9:06   ` [LTP] [PATCH 2/6] sched_football: Use atomic for ball Cyril Hrubis
2024-04-29 22:56     ` John Stultz via ltp
2024-05-07  9:35       ` Cyril Hrubis
2024-06-24 10:45         ` Cyril Hrubis
2024-06-25  0:05           ` John Stultz via ltp
2024-06-25  3:15             ` Li Wang
2024-06-25 20:20               ` John Stultz via ltp
2024-06-26  2:26                 ` Li Wang
2024-06-26 17:01                   ` John Stultz via ltp
2024-06-27  3:32                     ` Li Wang
2024-06-27 11:09                       ` Cyril Hrubis
2024-06-27 18:01                       ` John Stultz via ltp
2024-06-27 18:03                         ` John Stultz via ltp
2024-06-28  8:12                         ` Cyril Hrubis
2024-06-28 18:37                           ` John Stultz via ltp
2024-04-23 22:58 ` [LTP] [PATCH 3/6] sched_football: Re-add the crazy fans to interrupt everyone John Stultz via ltp
2024-04-29  9:10   ` Cyril Hrubis
2024-04-29 23:06     ` John Stultz via ltp
2024-06-27 13:25     ` Martin Doucha
2024-06-27 13:34       ` Cyril Hrubis
2024-04-23 22:58 ` [LTP] [PATCH 4/6] sched_football: Add a sleep before the game begins to get into steady state John Stultz via ltp
2024-04-23 22:58 ` [LTP] [PATCH 5/6] sched_football: Add prctrl calls to set thread comms John Stultz via ltp
2024-04-23 22:58 ` [LTP] [PATCH 6/6] sched_football: Add trace_marker messages if we're tracing John Stultz via ltp
2024-04-29  9:17   ` Cyril Hrubis
2024-04-29 23:14     ` John Stultz via ltp

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=20240423225821.4003538-3-jstultz@google.com \
    --to=ltp@lists.linux.it \
    --cc=darren@os.amperecomputing.com \
    --cc=jstultz@google.com \
    --cc=kernel-team@android.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox