rcutorture: Add early boot self tests
authorPranith Kumar <bobby.prani@gmail.com>
Fri, 19 Sep 2014 15:32:29 +0000 (11:32 -0400)
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Tue, 4 Nov 2014 03:26:37 +0000 (19:26 -0800)
Add early boot self tests for RCU under CONFIG_PROVE_RCU.

Currently the only test is adding a dummy callback which increments a counter
which we then later verify after calling rcu_barrier*().

Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
kernel/rcu/rcu.h
kernel/rcu/tiny.c
kernel/rcu/tree.c
kernel/rcu/update.c

index ff1a6de62f1789813260cbe719fd11ba448b946e..07bb02eda844bf16eee540ba01a99beb7c52ac60 100644 (file)
@@ -135,4 +135,6 @@ int rcu_jiffies_till_stall_check(void);
  */
 #define TPS(x)  tracepoint_string(x)
 
+void rcu_early_boot_tests(void);
+
 #endif /* __LINUX_RCU_H */
index c0623fc471256abb404a5d49e8d4d805b7fb4ba7..d3d44c58912210fde488cf77c976e946901208f5 100644 (file)
@@ -380,7 +380,9 @@ void call_rcu_bh(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
 }
 EXPORT_SYMBOL_GPL(call_rcu_bh);
 
-void rcu_init(void)
+void __init rcu_init(void)
 {
        open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
+
+       rcu_early_boot_tests();
 }
index 9815447d22e0354d5304b0ef8394577f09414602..77b48f03c077e7015ca45efae49f3a7a4e6507d7 100644 (file)
@@ -3766,6 +3766,8 @@ void __init rcu_init(void)
        pm_notifier(rcu_pm_notify, 0);
        for_each_online_cpu(cpu)
                rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
+
+       rcu_early_boot_tests();
 }
 
 #include "tree_plugin.h"
index 3ef8ba58694e95190e326986a252a276c9d721ed..99d47e6a280fb5a84fe4594f94a8b2cc6e438a38 100644 (file)
@@ -690,3 +690,87 @@ static void rcu_spawn_tasks_kthread(void)
 }
 
 #endif /* #ifdef CONFIG_TASKS_RCU */
+
+#ifdef CONFIG_PROVE_RCU
+
+/*
+ * Early boot self test parameters, one for each flavor
+ */
+static bool rcu_self_test;
+static bool rcu_self_test_bh;
+static bool rcu_self_test_sched;
+
+module_param(rcu_self_test, bool, 0444);
+module_param(rcu_self_test_bh, bool, 0444);
+module_param(rcu_self_test_sched, bool, 0444);
+
+static int rcu_self_test_counter;
+
+static void test_callback(struct rcu_head *r)
+{
+       rcu_self_test_counter++;
+       pr_info("RCU test callback executed %d\n", rcu_self_test_counter);
+}
+
+static void early_boot_test_call_rcu(void)
+{
+       static struct rcu_head head;
+
+       call_rcu(&head, test_callback);
+}
+
+static void early_boot_test_call_rcu_bh(void)
+{
+       static struct rcu_head head;
+
+       call_rcu_bh(&head, test_callback);
+}
+
+static void early_boot_test_call_rcu_sched(void)
+{
+       static struct rcu_head head;
+
+       call_rcu_sched(&head, test_callback);
+}
+
+void rcu_early_boot_tests(void)
+{
+       pr_info("Running RCU self tests\n");
+
+       if (rcu_self_test)
+               early_boot_test_call_rcu();
+       if (rcu_self_test_bh)
+               early_boot_test_call_rcu_bh();
+       if (rcu_self_test_sched)
+               early_boot_test_call_rcu_sched();
+}
+
+static int rcu_verify_early_boot_tests(void)
+{
+       int ret = 0;
+       int early_boot_test_counter = 0;
+
+       if (rcu_self_test) {
+               early_boot_test_counter++;
+               rcu_barrier();
+       }
+       if (rcu_self_test_bh) {
+               early_boot_test_counter++;
+               rcu_barrier_bh();
+       }
+       if (rcu_self_test_sched) {
+               early_boot_test_counter++;
+               rcu_barrier_sched();
+       }
+
+       if (rcu_self_test_counter != early_boot_test_counter) {
+               WARN_ON(1);
+               ret = -1;
+       }
+
+       return ret;
+}
+late_initcall(rcu_verify_early_boot_tests);
+#else
+void rcu_early_boot_tests(void) {}
+#endif /* CONFIG_PROVE_RCU */