From: Cyril Hrubis <chrubis@suse.cz>
To: John Stultz <jstultz@google.com>
Cc: kernel-team@android.com,
Darren Hart <darren@os.amperecomputing.com>,
ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 3/6] sched_football: Re-add the crazy fans to interrupt everyone
Date: Mon, 29 Apr 2024 11:10:47 +0200 [thread overview]
Message-ID: <Zi9kFxXw3mUEVcnf@yuki> (raw)
In-Reply-To: <20240423225821.4003538-4-jstultz@google.com>
Hi!
> * This is a scheduler test that uses a football analogy.
> * The premise is that we want to make sure that lower priority threads
> - * (defensive team). The offense is trying to increment the balls position,
> - * while the defense is trying to block that from happening.
> + * don't run while we have runnable higher priority threads.
> + * The offense is trying to increment the balls position, while the
> + * defense is trying to block that from happening.
> * And the ref (highest priority thread) will blow the wistle if the
> * ball moves. Finally, we have crazy fans (higer prority) that try to
> * distract the defense by occasionally running onto the field.
> *
> * Steps:
> - * - Create a fixed number of offense threads (lower priority)
> + * - Create NR_CPU offense threads (lower priority)
> + * - Create NR_CPU defense threads (mid priority)
> + * - Create 2*NR_CPU fan threads (high priority)
> * - Create a referee thread (highest priority)
> - * - Once everyone is on the field, the offense thread increments the
> - * value of 'the_ball'. The defense thread tries to block
> - * the ball by never letting the offense players get the CPU (it just
> - * spins).
> + * - Once everyone is on the field, the offense thread spins incrementing
> + * the value of 'the_ball'. The defense thread tries to block the ball
> + * by never letting the offense players get the CPU (it just spins).
> + * The crazy fans sleep a bit, then jump the rail and run across the
> + * field, disrupting the players on the field.
> * - The refree threads wakes up regularly to check if the game is over :)
> * - In the end, if the value of 'the_ball' is >0, the test is considered
> * to have failed.
> @@ -52,7 +56,7 @@
> * bugfixes and cleanups. -- Josh Triplett
> * 2009-06-23 Simplified atomic startup mechanism, avoiding thundering herd
> * scheduling at the beginning of the game. -- Darren Hart
> - *
> + * 2024-04-23 Re-add crazy fans! Along with minor cleanups -- John Stultz
We use git now, so it's kind of pointless to add more changelog lines
into the file itself.
> *****************************************************************************/
>
> #include <stdio.h>
> @@ -107,6 +111,38 @@ int parse_args(int c, char *v)
> return handled;
> }
>
> +#define NSEC_PER_SEC 1000000000ULL
> +unsigned long long ts_delta(struct timespec *start, struct timespec *stop)
> +{
> + unsigned long long a, b;
> +
> + a = start->tv_sec * NSEC_PER_SEC + start->tv_nsec;
> + b = stop->tv_sec * NSEC_PER_SEC + stop->tv_nsec;
> + return b - a;
> +}
This is tst_timespec_diff() from include/tst_timer.h
> +#define SPIN_TIME_NS 200000000
> +#define SLEEP_TIME_NS 50000000
> +/* These are fans running across the field. They're trying to interrupt/distract everyone */
> +void *thread_fan(void *arg)
> +{
> + atomic_inc(&players_ready);
> + /*occasionally wake up and run across the field */
> + while (1) {
> + int i;
> + struct timespec start, stop;
> +
> + start.tv_sec = 0;
> + start.tv_nsec = SLEEP_TIME_NS;
> + clock_nanosleep(CLOCK_MONOTONIC, 0, &start, NULL);
> + clock_gettime(CLOCK_MONOTONIC, &start);
> + clock_gettime(CLOCK_MONOTONIC, &stop);
> + while (ts_delta(&start, &stop) < SPIN_TIME_NS)
> + clock_gettime(CLOCK_MONOTONIC, &stop);
> + }
> + return NULL;
> +}
> +
> /* This is the defensive team. They're trying to block the offense */
> void *thread_defense(void *arg)
> {
> @@ -199,6 +235,17 @@ int main(int argc, char *argv[])
> while (atomic_get(&players_ready) < players_per_team * 2)
> usleep(100);
>
> + /* Start the crazy fans*/
> + priority = 50;
> + printf("Starting %d fan threads at priority %d\n",
> + players_per_team, priority);
> + for (i = 0; i < players_per_team*2; i++)
> + create_fifo_thread(thread_fan, NULL, priority);
> +
> + /* Wait for the crazy fan threads to start */
> + while (atomic_get(&players_ready) < players_per_team * 4)
> + usleep(100);
> +
> /* Ok, everyone is on the field, bring out the ref */
> printf("Starting referee thread\n");
> result = referee(game_length);
> --
> 2.44.0.769.g3c40516874-goog
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-04-29 9:12 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 ` [LTP] [PATCH 2/6] sched_football: Use atomic for ball John Stultz via ltp
2024-04-29 9:06 ` 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 [this message]
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=Zi9kFxXw3mUEVcnf@yuki \
--to=chrubis@suse.cz \
--cc=darren@os.amperecomputing.com \
--cc=jstultz@google.com \
--cc=kernel-team@android.com \
--cc=ltp@lists.linux.it \
/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