rcutorture: Add test of RCU CPU stall notifiers
authorPaul E. McKenney <paulmck@kernel.org>
Tue, 15 Aug 2023 22:53:32 +0000 (15:53 -0700)
committerFrederic Weisbecker <frederic@kernel.org>
Mon, 11 Sep 2023 20:36:40 +0000 (22:36 +0200)
This commit registers an RCU CPU stall notifier when testing RCU CPU
stalls.  The notifier logs a message similar to the following:

rcu_torture_stall_nf: v=1, duration=21001.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
kernel/rcu/rcutorture.c

index ade42d6a9d9b64860b8f51b33625703fc2ea598c..1830cacac01d755a7e9e1229995e23bd79211663 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/spinlock.h>
 #include <linux/smp.h>
 #include <linux/rcupdate_wait.h>
+#include <linux/rcu_notifier.h>
 #include <linux/interrupt.h>
 #include <linux/sched/signal.h>
 #include <uapi/linux/sched/types.h>
@@ -2428,6 +2429,16 @@ static int rcutorture_booster_init(unsigned int cpu)
        return 0;
 }
 
+static int rcu_torture_stall_nf(struct notifier_block *nb, unsigned long v, void *ptr)
+{
+       pr_info("%s: v=%lu, duration=%lu.\n", __func__, v, (unsigned long)ptr);
+       return NOTIFY_OK;
+}
+
+static struct notifier_block rcu_torture_stall_block = {
+       .notifier_call = rcu_torture_stall_nf,
+};
+
 /*
  * CPU-stall kthread.  It waits as specified by stall_cpu_holdoff, then
  * induces a CPU stall for the time specified by stall_cpu.
@@ -2435,9 +2446,14 @@ static int rcutorture_booster_init(unsigned int cpu)
 static int rcu_torture_stall(void *args)
 {
        int idx;
+       int ret;
        unsigned long stop_at;
 
        VERBOSE_TOROUT_STRING("rcu_torture_stall task started");
+       ret = rcu_stall_chain_notifier_register(&rcu_torture_stall_block);
+       if (ret)
+               pr_info("%s: rcu_stall_chain_notifier_register() returned %d, %sexpected.\n",
+                       __func__, ret, !IS_ENABLED(CONFIG_RCU_STALL_COMMON) ? "un" : "");
        if (stall_cpu_holdoff > 0) {
                VERBOSE_TOROUT_STRING("rcu_torture_stall begin holdoff");
                schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
@@ -2481,6 +2497,11 @@ static int rcu_torture_stall(void *args)
                cur_ops->readunlock(idx);
        }
        pr_alert("%s end.\n", __func__);
+       if (!ret) {
+               ret = rcu_stall_chain_notifier_unregister(&rcu_torture_stall_block);
+               if (ret)
+                       pr_info("%s: rcu_stall_chain_notifier_unregister() returned %d.\n", __func__, ret);
+       }
        torture_shutdown_absorb("rcu_torture_stall");
        while (!kthread_should_stop())
                schedule_timeout_interruptible(10 * HZ);