[PATCH rcu 3/9] torture: Add lock_torture_writer_fifo module param

Paul E. McKenney posted 9 patches 2 years, 6 months ago
[PATCH rcu 3/9] torture: Add lock_torture_writer_fifo module param
Posted by Paul E. McKenney 2 years, 6 months ago
From: Dietmar Eggemann <dietmar.eggemann@arm.com>

Modifies locktorture writer to run as RT task.

To use it:
insmod /lib/modules/torture.ko random_shuffle=1 lock_torture_writer_fifo=1
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^
insmod /lib/modules/locktorture.ko torture_type=mutex_lock rt_boost=1 rt_boost_factor=50 nested_locks=3

This patch has been helpful to uncover issues with the proxy-execution
series.

Cc: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Joel Fernandes <joel@joelfernandes.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: kernel-team@android.com
Signed-off-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
[jstultz: Include header change to build, reword commit message]
Signed-off-by: John Stultz <jstultz@google.com>
Acked-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
 kernel/locking/locktorture.c |  3 ++-
 kernel/torture.c             | 11 ++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index 949d3deae506..aac48d323254 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -809,7 +809,8 @@ static int lock_torture_writer(void *arg)
 	bool skip_main_lock;
 
 	VERBOSE_TOROUT_STRING("lock_torture_writer task started");
-	set_user_nice(current, MAX_NICE);
+	if (!rt_task(current))
+		set_user_nice(current, MAX_NICE);
 
 	do {
 		if ((torture_random(&rand) & 0xfffff) == 0)
diff --git a/kernel/torture.c b/kernel/torture.c
index 8be83fdc6be1..db79197e257a 100644
--- a/kernel/torture.c
+++ b/kernel/torture.c
@@ -37,6 +37,7 @@
 #include <linux/ktime.h>
 #include <asm/byteorder.h>
 #include <linux/torture.h>
+#include <linux/sched/rt.h>
 #include "rcu/rcu.h"
 
 MODULE_LICENSE("GPL");
@@ -57,6 +58,9 @@ module_param(verbose_sleep_duration, int, 0444);
 static int random_shuffle;
 module_param(random_shuffle, int, 0444);
 
+static int lock_torture_writer_fifo;
+module_param(lock_torture_writer_fifo, int, 0444);
+
 static char *torture_type;
 static int verbose;
 
@@ -734,7 +738,7 @@ bool stutter_wait(const char *title)
 	cond_resched_tasks_rcu_qs();
 	spt = READ_ONCE(stutter_pause_test);
 	for (; spt; spt = READ_ONCE(stutter_pause_test)) {
-		if (!ret) {
+		if (!ret && !rt_task(current)) {
 			sched_set_normal(current, MAX_NICE);
 			ret = true;
 		}
@@ -944,6 +948,11 @@ int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
 		*tp = NULL;
 		return ret;
 	}
+
+	if (lock_torture_writer_fifo &&
+	    !strncmp(s, "lock_torture_writer", strlen(s)))
+		sched_set_fifo(*tp);
+
 	wake_up_process(*tp);  // Process is sleeping, so ordering provided.
 	torture_shuffle_task_register(*tp);
 	return ret;
-- 
2.40.1
Re: [PATCH rcu 3/9] torture: Add lock_torture_writer_fifo module param
Posted by Paul E. McKenney 2 years, 6 months ago
On Mon, Jul 17, 2023 at 11:20:36AM -0700, Paul E. McKenney wrote:
> From: Dietmar Eggemann <dietmar.eggemann@arm.com>
> 
> Modifies locktorture writer to run as RT task.
> 
> To use it:
> insmod /lib/modules/torture.ko random_shuffle=1 lock_torture_writer_fifo=1
>                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
> insmod /lib/modules/locktorture.ko torture_type=mutex_lock rt_boost=1 rt_boost_factor=50 nested_locks=3
> 
> This patch has been helpful to uncover issues with the proxy-execution
> series.
> 
> Cc: "Paul E. McKenney" <paulmck@kernel.org>
> Cc: Josh Triplett <josh@joshtriplett.org>
> Cc: Joel Fernandes <joel@joelfernandes.org>
> Cc: Juri Lelli <juri.lelli@redhat.com>
> Cc: Valentin Schneider <vschneid@redhat.com>
> Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
> Cc: kernel-team@android.com
> Signed-off-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
> [jstultz: Include header change to build, reword commit message]
> Signed-off-by: John Stultz <jstultz@google.com>
> Acked-by: Davidlohr Bueso <dave@stgolabs.net>
> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> ---
>  kernel/locking/locktorture.c |  3 ++-
>  kernel/torture.c             | 11 ++++++++++-
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
> index 949d3deae506..aac48d323254 100644
> --- a/kernel/locking/locktorture.c
> +++ b/kernel/locking/locktorture.c
> @@ -809,7 +809,8 @@ static int lock_torture_writer(void *arg)
>  	bool skip_main_lock;
>  
>  	VERBOSE_TOROUT_STRING("lock_torture_writer task started");
> -	set_user_nice(current, MAX_NICE);
> +	if (!rt_task(current))
> +		set_user_nice(current, MAX_NICE);
>  
>  	do {
>  		if ((torture_random(&rand) & 0xfffff) == 0)
> diff --git a/kernel/torture.c b/kernel/torture.c
> index 8be83fdc6be1..db79197e257a 100644
> --- a/kernel/torture.c
> +++ b/kernel/torture.c
> @@ -37,6 +37,7 @@
>  #include <linux/ktime.h>
>  #include <asm/byteorder.h>
>  #include <linux/torture.h>
> +#include <linux/sched/rt.h>
>  #include "rcu/rcu.h"
>  
>  MODULE_LICENSE("GPL");
> @@ -57,6 +58,9 @@ module_param(verbose_sleep_duration, int, 0444);
>  static int random_shuffle;
>  module_param(random_shuffle, int, 0444);
>  
> +static int lock_torture_writer_fifo;
> +module_param(lock_torture_writer_fifo, int, 0444);
> +
>  static char *torture_type;
>  static int verbose;
>  
> @@ -734,7 +738,7 @@ bool stutter_wait(const char *title)
>  	cond_resched_tasks_rcu_qs();
>  	spt = READ_ONCE(stutter_pause_test);
>  	for (; spt; spt = READ_ONCE(stutter_pause_test)) {
> -		if (!ret) {
> +		if (!ret && !rt_task(current)) {
>  			sched_set_normal(current, MAX_NICE);
>  			ret = true;
>  		}
> @@ -944,6 +948,11 @@ int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
>  		*tp = NULL;
>  		return ret;
>  	}
> +
> +	if (lock_torture_writer_fifo &&
> +	    !strncmp(s, "lock_torture_writer", strlen(s)))
> +		sched_set_fifo(*tp);

I replaced this with a callback function in order to confine
locktorture-specific code to kernel/locking/locktorture.c.

I will reply with the following two patches.

1.	Add a kthread-creation callback to _torture_create_kthread().

2.	Add lock_torture writer_fifo module parameter, courtesy of
	Dietmar Eggemann.

Please let me know if you have objections to this change.

						Thanx, Paul

------------------------------------------------------------------------

 b/Documentation/admin-guide/kernel-parameters.txt |    4 ++++
 b/include/linux/torture.h                         |    7 +++++--
 b/kernel/locking/locktorture.c                    |   12 +++++++-----
 b/kernel/torture.c                                |    6 +++++-
 kernel/torture.c                                  |    3 ++-
 5 files changed, 23 insertions(+), 9 deletions(-)
[PATCH rcu 1/2] torture: Add a kthread-creation callback to _torture_create_kthread()
Posted by Paul E. McKenney 2 years, 6 months ago
This commit adds a kthread-creation callback to the
_torture_create_kthread() function, which allows callers of a new
torture_create_kthread_cb() macro to specify a function to be invoked
after the kthread is created but before it is awakened for the first time.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: John Stultz <jstultz@google.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Joel Fernandes <joel@joelfernandes.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: kernel-team@android.com
---
 include/linux/torture.h | 7 +++++--
 kernel/torture.c        | 6 +++++-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/include/linux/torture.h b/include/linux/torture.h
index 7038104463e4..bb466eec01e4 100644
--- a/include/linux/torture.h
+++ b/include/linux/torture.h
@@ -108,12 +108,15 @@ bool torture_must_stop(void);
 bool torture_must_stop_irq(void);
 void torture_kthread_stopping(char *title);
 int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
-			     char *f, struct task_struct **tp);
+			     char *f, struct task_struct **tp, void (*cbf)(struct task_struct *tp));
 void _torture_stop_kthread(char *m, struct task_struct **tp);
 
 #define torture_create_kthread(n, arg, tp) \
 	_torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
-				"Failed to create " #n, &(tp))
+				"Failed to create " #n, &(tp), NULL)
+#define torture_create_kthread_cb(n, arg, tp, cbf) \
+	_torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
+				"Failed to create " #n, &(tp), cbf)
 #define torture_stop_kthread(n, tp) \
 	_torture_stop_kthread("Stopping " #n " task", &(tp))
 
diff --git a/kernel/torture.c b/kernel/torture.c
index 8be83fdc6be1..b88a1a86d9da 100644
--- a/kernel/torture.c
+++ b/kernel/torture.c
@@ -932,7 +932,7 @@ EXPORT_SYMBOL_GPL(torture_kthread_stopping);
  * it starts, you will need to open-code your own.
  */
 int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
-			    char *f, struct task_struct **tp)
+			    char *f, struct task_struct **tp, void (*cbf)(struct task_struct *tp))
 {
 	int ret = 0;
 
@@ -944,6 +944,10 @@ int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
 		*tp = NULL;
 		return ret;
 	}
+
+	if (cbf)
+		cbf(*tp);
+
 	wake_up_process(*tp);  // Process is sleeping, so ordering provided.
 	torture_shuffle_task_register(*tp);
 	return ret;
-- 
2.40.1
Re: [PATCH rcu 1/2] torture: Add a kthread-creation callback to _torture_create_kthread()
Posted by John Stultz 2 years, 6 months ago
On Thu, Jul 27, 2023 at 8:22 PM Paul E. McKenney <paulmck@kernel.org> wrote:
>
> This commit adds a kthread-creation callback to the
> _torture_create_kthread() function, which allows callers of a new
> torture_create_kthread_cb() macro to specify a function to be invoked
> after the kthread is created but before it is awakened for the first time.
>
> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
> Cc: John Stultz <jstultz@google.com>
> Cc: Josh Triplett <josh@joshtriplett.org>
> Cc: Joel Fernandes <joel@joelfernandes.org>
> Cc: Juri Lelli <juri.lelli@redhat.com>
> Cc: Valentin Schneider <vschneid@redhat.com>
> Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
> Cc: kernel-team@android.com

Thanks for improving the patch this way!

Acked-by: John Stultz <jstultz@google.com>
Re: [PATCH rcu 1/2] torture: Add a kthread-creation callback to _torture_create_kthread()
Posted by Joel Fernandes 2 years, 6 months ago
On Thu, Jul 27, 2023 at 11:22 PM Paul E. McKenney <paulmck@kernel.org> wrote:
>
> This commit adds a kthread-creation callback to the
> _torture_create_kthread() function, which allows callers of a new
> torture_create_kthread_cb() macro to specify a function to be invoked
> after the kthread is created but before it is awakened for the first time.
>
> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
> Cc: John Stultz <jstultz@google.com>
> Cc: Josh Triplett <josh@joshtriplett.org>
> Cc: Joel Fernandes <joel@joelfernandes.org>

Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>

thanks,

 - Joel


> Cc: Juri Lelli <juri.lelli@redhat.com>
> Cc: Valentin Schneider <vschneid@redhat.com>
> Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
> Cc: kernel-team@android.com
> ---
>  include/linux/torture.h | 7 +++++--
>  kernel/torture.c        | 6 +++++-
>  2 files changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/torture.h b/include/linux/torture.h
> index 7038104463e4..bb466eec01e4 100644
> --- a/include/linux/torture.h
> +++ b/include/linux/torture.h
> @@ -108,12 +108,15 @@ bool torture_must_stop(void);
>  bool torture_must_stop_irq(void);
>  void torture_kthread_stopping(char *title);
>  int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
> -                            char *f, struct task_struct **tp);
> +                            char *f, struct task_struct **tp, void (*cbf)(struct task_struct *tp));
>  void _torture_stop_kthread(char *m, struct task_struct **tp);
>
>  #define torture_create_kthread(n, arg, tp) \
>         _torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
> -                               "Failed to create " #n, &(tp))
> +                               "Failed to create " #n, &(tp), NULL)
> +#define torture_create_kthread_cb(n, arg, tp, cbf) \
> +       _torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
> +                               "Failed to create " #n, &(tp), cbf)
>  #define torture_stop_kthread(n, tp) \
>         _torture_stop_kthread("Stopping " #n " task", &(tp))
>
> diff --git a/kernel/torture.c b/kernel/torture.c
> index 8be83fdc6be1..b88a1a86d9da 100644
> --- a/kernel/torture.c
> +++ b/kernel/torture.c
> @@ -932,7 +932,7 @@ EXPORT_SYMBOL_GPL(torture_kthread_stopping);
>   * it starts, you will need to open-code your own.
>   */
>  int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
> -                           char *f, struct task_struct **tp)
> +                           char *f, struct task_struct **tp, void (*cbf)(struct task_struct *tp))
>  {
>         int ret = 0;
>
> @@ -944,6 +944,10 @@ int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
>                 *tp = NULL;
>                 return ret;
>         }
> +
> +       if (cbf)
> +               cbf(*tp);
> +
>         wake_up_process(*tp);  // Process is sleeping, so ordering provided.
>         torture_shuffle_task_register(*tp);
>         return ret;
> --
> 2.40.1
>
[PATCH rcu 2/2] torture: Add lock_torture writer_fifo module parameter
Posted by Paul E. McKenney 2 years, 6 months ago
From: Dietmar Eggemann <dietmar.eggemann@arm.com>

This commit adds a module parameter that causes the locktorture writer
to run at real-time priority.

To use it:
insmod /lib/modules/torture.ko random_shuffle=1
insmod /lib/modules/locktorture.ko torture_type=mutex_lock rt_boost=1 rt_boost_factor=50 nested_locks=3 writer_fifo=1
													^^^^^^^^^^^^^

A predecessor to this patch has been helpful to uncover issues with the
proxy-execution series.

[ paulmck: Remove locktorture-specific code from kernel/torture.c. ]

Cc: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Joel Fernandes <joel@joelfernandes.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: kernel-team@android.com
Signed-off-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
[jstultz: Include header change to build, reword commit message]
Signed-off-by: John Stultz <jstultz@google.com>
Acked-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
 Documentation/admin-guide/kernel-parameters.txt |  4 ++++
 kernel/locking/locktorture.c                    | 12 +++++++-----
 kernel/torture.c                                |  3 ++-
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index a1457995fd41..7b94455e9ae2 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2918,6 +2918,10 @@
 	locktorture.torture_type= [KNL]
 			Specify the locking implementation to test.
 
+	locktorture.writer_fifo= [KNL]
+			Run the write-side locktorture kthreads at
+			sched_set_fifo() real-time priority.
+
 	locktorture.verbose= [KNL]
 			Enable additional printk() statements.
 
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index 949d3deae506..270c7f80ce84 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -45,6 +45,7 @@ torture_param(int, stutter, 5, "Number of jiffies to run/halt test, 0=disable");
 torture_param(int, rt_boost, 2,
 		   "Do periodic rt-boost. 0=Disable, 1=Only for rt_mutex, 2=For all lock types.");
 torture_param(int, rt_boost_factor, 50, "A factor determining how often rt-boost happens.");
+torture_param(int, writer_fifo, 0, "Run writers at sched_set_fifo() priority");
 torture_param(int, verbose, 1, "Enable verbose debugging printk()s");
 torture_param(int, nested_locks, 0, "Number of nested locks (max = 8)");
 /* Going much higher trips "BUG: MAX_LOCKDEP_CHAIN_HLOCKS too low!" errors */
@@ -809,7 +810,8 @@ static int lock_torture_writer(void *arg)
 	bool skip_main_lock;
 
 	VERBOSE_TOROUT_STRING("lock_torture_writer task started");
-	set_user_nice(current, MAX_NICE);
+	if (!rt_task(current))
+		set_user_nice(current, MAX_NICE);
 
 	do {
 		if ((torture_random(&rand) & 0xfffff) == 0)
@@ -1015,8 +1017,7 @@ static void lock_torture_cleanup(void)
 
 	if (writer_tasks) {
 		for (i = 0; i < cxt.nrealwriters_stress; i++)
-			torture_stop_kthread(lock_torture_writer,
-					     writer_tasks[i]);
+			torture_stop_kthread(lock_torture_writer, writer_tasks[i]);
 		kfree(writer_tasks);
 		writer_tasks = NULL;
 	}
@@ -1244,8 +1245,9 @@ static int __init lock_torture_init(void)
 			goto create_reader;
 
 		/* Create writer. */
-		firsterr = torture_create_kthread(lock_torture_writer, &cxt.lwsa[i],
-						  writer_tasks[i]);
+		firsterr = torture_create_kthread_cb(lock_torture_writer, &cxt.lwsa[i],
+						     writer_tasks[i],
+						     writer_fifo ? sched_set_fifo : NULL);
 		if (torture_init_error(firsterr))
 			goto unwind;
 
diff --git a/kernel/torture.c b/kernel/torture.c
index b88a1a86d9da..a1ac493488e2 100644
--- a/kernel/torture.c
+++ b/kernel/torture.c
@@ -37,6 +37,7 @@
 #include <linux/ktime.h>
 #include <asm/byteorder.h>
 #include <linux/torture.h>
+#include <linux/sched/rt.h>
 #include "rcu/rcu.h"
 
 MODULE_LICENSE("GPL");
@@ -734,7 +735,7 @@ bool stutter_wait(const char *title)
 	cond_resched_tasks_rcu_qs();
 	spt = READ_ONCE(stutter_pause_test);
 	for (; spt; spt = READ_ONCE(stutter_pause_test)) {
-		if (!ret) {
+		if (!ret && !rt_task(current)) {
 			sched_set_normal(current, MAX_NICE);
 			ret = true;
 		}
-- 
2.40.1
Re: [PATCH rcu 2/2] torture: Add lock_torture writer_fifo module parameter
Posted by John Stultz 2 years, 6 months ago
On Thu, Jul 27, 2023 at 8:22 PM Paul E. McKenney <paulmck@kernel.org> wrote:
>
> From: Dietmar Eggemann <dietmar.eggemann@arm.com>
>
> This commit adds a module parameter that causes the locktorture writer
> to run at real-time priority.
>
> To use it:
> insmod /lib/modules/torture.ko random_shuffle=1
> insmod /lib/modules/locktorture.ko torture_type=mutex_lock rt_boost=1 rt_boost_factor=50 nested_locks=3 writer_fifo=1
>                                                                                                         ^^^^^^^^^^^^^
>
> A predecessor to this patch has been helpful to uncover issues with the
> proxy-execution series.
>
> [ paulmck: Remove locktorture-specific code from kernel/torture.c. ]

Thanks again for improving this!  I've switched over to your version
here in my test tree.

Acked-by: John Stultz <jstultz@google.com>

thanks
-john
Re: [PATCH rcu 2/2] torture: Add lock_torture writer_fifo module parameter
Posted by Paul E. McKenney 2 years, 6 months ago
On Mon, Aug 07, 2023 at 08:27:29PM -0700, John Stultz wrote:
> On Thu, Jul 27, 2023 at 8:22 PM Paul E. McKenney <paulmck@kernel.org> wrote:
> >
> > From: Dietmar Eggemann <dietmar.eggemann@arm.com>
> >
> > This commit adds a module parameter that causes the locktorture writer
> > to run at real-time priority.
> >
> > To use it:
> > insmod /lib/modules/torture.ko random_shuffle=1
> > insmod /lib/modules/locktorture.ko torture_type=mutex_lock rt_boost=1 rt_boost_factor=50 nested_locks=3 writer_fifo=1
> >                                                                                                         ^^^^^^^^^^^^^
> >
> > A predecessor to this patch has been helpful to uncover issues with the
> > proxy-execution series.
> >
> > [ paulmck: Remove locktorture-specific code from kernel/torture.c. ]
> 
> Thanks again for improving this!  I've switched over to your version
> here in my test tree.
> 
> Acked-by: John Stultz <jstultz@google.com>

Thank you both!  I will apply on my next rebase.

							Thanx, Paul