torture: Add a kthread-creation callback to _torture_create_kthread()
authorPaul E. McKenney <paulmck@kernel.org>
Wed, 19 Jul 2023 22:50:07 +0000 (15:50 -0700)
committerPaul E. McKenney <paulmck@kernel.org>
Mon, 14 Aug 2023 22:00:37 +0000 (15:00 -0700)
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: Josh Triplett <josh@joshtriplett.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
Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Acked-by: John Stultz <jstultz@google.com>
include/linux/torture.h
kernel/torture.c

index 7038104463e481486424da66e909bcaf0604be2e..bb466eec01e4264984b45c1f3030981984a2e335 100644 (file)
@@ -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))
 
index 8be83fdc6be1aedda6d8a4645c161bd1d8fec143..b88a1a86d9dafaa062fed5ff1db6ac7df36a7f95 100644 (file)
@@ -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;