diff mbox series

[1/2] torture: Add a kthread-creation callback to _torture_create_kthread()

Message ID 20230728032232.816584-1-paulmck@kernel.org (mailing list archive)
State Accepted
Commit 67d5404d274376890d6d095a10e6565854918f8e
Headers show
Series [1/2] torture: Add a kthread-creation callback to _torture_create_kthread() | expand

Commit Message

Paul E. McKenney July 28, 2023, 3:22 a.m. UTC
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(-)

Comments

Joel Fernandes Aug. 5, 2023, 10:44 p.m. UTC | #1
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
>
John Stultz Aug. 8, 2023, 3:26 a.m. UTC | #2
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>
diff mbox series

Patch

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;