[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <338faf05-e545-4b17-b941-32a4a02adbd4@infradead.org>
Date: Tue, 19 Dec 2023 16:59:08 -0800
From: Randy Dunlap <rdunlap@...radead.org>
To: John Stultz <jstultz@...gle.com>, LKML <linux-kernel@...r.kernel.org>
Cc: Joel Fernandes <joelaf@...gle.com>, Qais Yousef <qyousef@...gle.com>,
Ingo Molnar <mingo@...hat.com>, Peter Zijlstra <peterz@...radead.org>,
Juri Lelli <juri.lelli@...hat.com>,
Vincent Guittot <vincent.guittot@...aro.org>,
Dietmar Eggemann <dietmar.eggemann@....com>,
Valentin Schneider <vschneid@...hat.com>,
Steven Rostedt <rostedt@...dmis.org>, Ben Segall <bsegall@...gle.com>,
Zimuzo Ezeozue <zezeozue@...gle.com>, Youssef Esmat
<youssefesmat@...gle.com>, Mel Gorman <mgorman@...e.de>,
Daniel Bristot de Oliveira <bristot@...hat.com>,
Will Deacon <will@...nel.org>, Waiman Long <longman@...hat.com>,
Boqun Feng <boqun.feng@...il.com>, "Paul E. McKenney" <paulmck@...nel.org>,
Metin Kaya <Metin.Kaya@....com>, Xuewen Yan <xuewen.yan94@...il.com>,
K Prateek Nayak <kprateek.nayak@....com>,
Thomas Gleixner <tglx@...utronix.de>, kernel-team@...roid.com
Subject: Re: [PATCH v7 17/23] sched: Initial sched_football test
implementation
Hi John,
On 12/19/23 16:18, John Stultz wrote:
> Reimplementation of the sched_football test from LTP:
> https://github.com/linux-test-project/ltp/blob/master/testcases/realtime/func/sched_football/sched_football.c
>
> But reworked to run in the kernel and utilize mutexes
> to illustrate proper boosting of low priority mutex
> holders.
>
> TODO:
> * Need a rt_mutex version so it can work w/o proxy-execution
> * Need a better place to put it
>
> Cc: kernel-team@...roid.com
> Signed-off-by: John Stultz <jstultz@...gle.com>
> ---
> kernel/sched/Makefile | 1 +
> kernel/sched/test_sched_football.c | 242 +++++++++++++++++++++++++++++
> lib/Kconfig.debug | 14 ++
> 3 files changed, 257 insertions(+)
> create mode 100644 kernel/sched/test_sched_football.c
>
> diff --git a/kernel/sched/test_sched_football.c b/kernel/sched/test_sched_football.c
> new file mode 100644
> index 000000000000..9742c45c0fe0
> --- /dev/null
> +++ b/kernel/sched/test_sched_football.c
> @@ -0,0 +1,242 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Module-based test case for RT scheduling invariant
> + *
> + * A reimplementation of my old sched_football test
> + * found in LTP:
> + * https://github.com/linux-test-project/ltp/blob/master/testcases/realtime/func/sched_football/sched_football.c
> + *
> + * Similar to that test, this tries to validate the RT
> + * scheduling invariant, that the across N available cpus, the
> + * top N priority tasks always running.
> + *
> + * This is done via having N offsensive players that are
> + * medium priority, which constantly are trying to increment the
> + * ball_pos counter.
> + *
> + * Blocking this, are N defensive players that are higher
no comma ^
> + * priority which just spin on the cpu, preventing the medium
> + * priroity tasks from running.
> + *
> + * To complicate this, there are also N defensive low priority
> + * tasks. These start first and each aquire one of N mutexes.
acquire
> + * The high priority defense tasks will later try to grab the
> + * mutexes and block, opening a window for the offsensive tasks
offensive
> + * to run and increment the ball. If priority inheritance or
> + * proxy execution is used, the low priority defense players
> + * should be boosted to the high priority levels, and will
> + * prevent the mid priority offensive tasks from running.
> + *
> + * Copyright © International Business Machines Corp., 2007, 2008
> + * Copyright (C) Google, 2023
> + *
> + * Authors: John Stultz <jstultz@...gle.com>
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/kthread.h>
> +#include <linux/delay.h>
> +#include <linux/sched/rt.h>
> +#include <linux/spinlock.h>
> +#include <linux/mutex.h>
> +#include <linux/rwsem.h>
> +#include <linux/smp.h>
> +#include <linux/slab.h>
> +#include <linux/interrupt.h>
> +#include <linux/sched.h>
> +#include <uapi/linux/sched/types.h>
> +#include <linux/rtmutex.h>
> +
> +atomic_t players_ready;
> +atomic_t ball_pos;
> +int players_per_team;
> +bool game_over;
> +
> +struct mutex *mutex_low_list;
> +struct mutex *mutex_mid_list;
> +
[]
Is this the referee?
> +int ref_thread(void *arg)
> +{
> + struct task_struct *kth;
> + long game_time = (long)arg;
> + unsigned long final_pos;
> + long i;
> +
> + pr_info("%s: started ref, game_time: %ld secs !\n", __func__,
> + game_time);
> +
> + /* Create low priority defensive team */
> + for (i = 0; i < players_per_team; i++)
> + kth = create_fifo_thread(defense_low_thread, (void *)i,
> + "defese-low-thread", 2);
defense
> + /* Wait for the defense threads to start */
> + while (atomic_read(&players_ready) < players_per_team)
> + msleep(1);
> +
> + for (i = 0; i < players_per_team; i++)
> + kth = create_fifo_thread(defense_mid_thread,
> + (void *)(players_per_team - i - 1),
> + "defese-mid-thread", 3);
ditto
> + /* Wait for the defense threads to start */
> + while (atomic_read(&players_ready) < players_per_team * 2)
> + msleep(1);
> +
> + /* Create mid priority offensive team */
> + for (i = 0; i < players_per_team; i++)
> + kth = create_fifo_thread(offense_thread, NULL,
> + "offense-thread", 5);
> + /* Wait for the offense threads to start */
> + while (atomic_read(&players_ready) < players_per_team * 3)
> + msleep(1);
> +
> + /* Create high priority defensive team */
> + for (i = 0; i < players_per_team; i++)
> + kth = create_fifo_thread(defense_hi_thread, (void *)i,
> + "defese-hi-thread", 10);
ditto
> + /* Wait for the defense threads to start */
> + while (atomic_read(&players_ready) < players_per_team * 4)
> + msleep(1);
> +
> + /* Create high priority defensive team */
> + for (i = 0; i < players_per_team; i++)
> + kth = create_fifo_thread(crazy_fan_thread, NULL,
> + "crazy-fan-thread", 15);
> + /* Wait for the defense threads to start */
> + while (atomic_read(&players_ready) < players_per_team * 5)
> + msleep(1);
> +
> + pr_info("%s: all players checked in! Starting game.\n", __func__);
> + atomic_set(&ball_pos, 0);
> + msleep(game_time * 1000);
> + final_pos = atomic_read(&ball_pos);
> + pr_info("%s: final ball_pos: %ld\n", __func__, final_pos);
> + WARN_ON(final_pos != 0);
> + game_over = true;
> + return 0;
> +}
> +
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index 4405f81248fb..1d90059d190f 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -1238,6 +1238,20 @@ config SCHED_DEBUG
> that can help debug the scheduler. The runtime overhead of this
> option is minimal.
>
> +config SCHED_RT_INVARIENT_TEST
INVARIANT
> + tristate "RT invarient scheduling tester"
invariant
> + depends on DEBUG_KERNEL
> + help
> + This option provides a kernel module that runs tests to make
> + sure the RT invarient holds (top N priority tasks run on N
invariant
> + available cpus).
> +
> + Say Y here if you want kernel rt scheduling tests
RT
> + to be built into the kernel.
> + Say M if you want this test to build as a module.
> + Say N if you are unsure.
> +
> +
> config SCHED_INFO
> bool
> default n
--
#Randy
https://people.kernel.org/tglx/notes-about-netiquette
https://subspace.kernel.org/etiquette.html
Powered by blists - more mailing lists