Merge tag 'mac80211-next-for-john-2014-11-04' of git://git.kernel.org/pub/scm/linux...
[cascardo/linux.git] / kernel / rcu / rcutorture.c
index ff4f0c7..240fa90 100644 (file)
 #include <linux/trace_clock.h>
 #include <asm/byteorder.h>
 #include <linux/torture.h>
+#include <linux/vmalloc.h>
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@joshtriplett.org>");
 
 
+torture_param(int, cbflood_inter_holdoff, HZ,
+             "Holdoff between floods (jiffies)");
+torture_param(int, cbflood_intra_holdoff, 1,
+             "Holdoff between bursts (jiffies)");
+torture_param(int, cbflood_n_burst, 3, "# bursts in flood, zero to disable");
+torture_param(int, cbflood_n_per_burst, 20000,
+             "# callbacks per burst in flood");
 torture_param(int, fqs_duration, 0,
              "Duration of fqs bursts (us), 0 to disable");
 torture_param(int, fqs_holdoff, 0, "Holdoff time within fqs bursts (us)");
@@ -96,10 +104,12 @@ module_param(torture_type, charp, 0444);
 MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)");
 
 static int nrealreaders;
+static int ncbflooders;
 static struct task_struct *writer_task;
 static struct task_struct **fakewriter_tasks;
 static struct task_struct **reader_tasks;
 static struct task_struct *stats_task;
+static struct task_struct **cbflood_task;
 static struct task_struct *fqs_task;
 static struct task_struct *boost_tasks[NR_CPUS];
 static struct task_struct *stall_task;
@@ -138,6 +148,7 @@ static long n_rcu_torture_boosts;
 static long n_rcu_torture_timers;
 static long n_barrier_attempts;
 static long n_barrier_successes;
+static atomic_long_t n_cbfloods;
 static struct list_head rcu_torture_removed;
 
 static int rcu_torture_writer_state;
@@ -157,9 +168,9 @@ static int rcu_torture_writer_state;
 #else
 #define RCUTORTURE_RUNNABLE_INIT 0
 #endif
-int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
-module_param(rcutorture_runnable, int, 0444);
-MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot");
+static int torture_runnable = RCUTORTURE_RUNNABLE_INIT;
+module_param(torture_runnable, int, 0444);
+MODULE_PARM_DESC(torture_runnable, "Start rcutorture at boot");
 
 #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
 #define rcu_can_boost() 1
@@ -601,6 +612,52 @@ static struct rcu_torture_ops sched_ops = {
        .name           = "sched"
 };
 
+#ifdef CONFIG_TASKS_RCU
+
+/*
+ * Definitions for RCU-tasks torture testing.
+ */
+
+static int tasks_torture_read_lock(void)
+{
+       return 0;
+}
+
+static void tasks_torture_read_unlock(int idx)
+{
+}
+
+static void rcu_tasks_torture_deferred_free(struct rcu_torture *p)
+{
+       call_rcu_tasks(&p->rtort_rcu, rcu_torture_cb);
+}
+
+static struct rcu_torture_ops tasks_ops = {
+       .ttype          = RCU_TASKS_FLAVOR,
+       .init           = rcu_sync_torture_init,
+       .readlock       = tasks_torture_read_lock,
+       .read_delay     = rcu_read_delay,  /* just reuse rcu's version. */
+       .readunlock     = tasks_torture_read_unlock,
+       .completed      = rcu_no_completed,
+       .deferred_free  = rcu_tasks_torture_deferred_free,
+       .sync           = synchronize_rcu_tasks,
+       .exp_sync       = synchronize_rcu_tasks,
+       .call           = call_rcu_tasks,
+       .cb_barrier     = rcu_barrier_tasks,
+       .fqs            = NULL,
+       .stats          = NULL,
+       .irq_capable    = 1,
+       .name           = "tasks"
+};
+
+#define RCUTORTURE_TASKS_OPS &tasks_ops,
+
+#else /* #ifdef CONFIG_TASKS_RCU */
+
+#define RCUTORTURE_TASKS_OPS
+
+#endif /* #else #ifdef CONFIG_TASKS_RCU */
+
 /*
  * RCU torture priority-boost testing.  Runs one real-time thread per
  * CPU for moderate bursts, repeatedly registering RCU callbacks and
@@ -667,7 +724,7 @@ static int rcu_torture_boost(void *arg)
                                }
                                call_rcu_time = jiffies;
                        }
-                       cond_resched();
+                       cond_resched_rcu_qs();
                        stutter_wait("rcu_torture_boost");
                        if (torture_must_stop())
                                goto checkwait;
@@ -707,6 +764,58 @@ checkwait: stutter_wait("rcu_torture_boost");
        return 0;
 }
 
+static void rcu_torture_cbflood_cb(struct rcu_head *rhp)
+{
+}
+
+/*
+ * RCU torture callback-flood kthread.  Repeatedly induces bursts of calls
+ * to call_rcu() or analogous, increasing the probability of occurrence
+ * of callback-overflow corner cases.
+ */
+static int
+rcu_torture_cbflood(void *arg)
+{
+       int err = 1;
+       int i;
+       int j;
+       struct rcu_head *rhp;
+
+       if (cbflood_n_per_burst > 0 &&
+           cbflood_inter_holdoff > 0 &&
+           cbflood_intra_holdoff > 0 &&
+           cur_ops->call &&
+           cur_ops->cb_barrier) {
+               rhp = vmalloc(sizeof(*rhp) *
+                             cbflood_n_burst * cbflood_n_per_burst);
+               err = !rhp;
+       }
+       if (err) {
+               VERBOSE_TOROUT_STRING("rcu_torture_cbflood disabled: Bad args or OOM");
+               while (!torture_must_stop())
+                       schedule_timeout_interruptible(HZ);
+               return 0;
+       }
+       VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started");
+       do {
+               schedule_timeout_interruptible(cbflood_inter_holdoff);
+               atomic_long_inc(&n_cbfloods);
+               WARN_ON(signal_pending(current));
+               for (i = 0; i < cbflood_n_burst; i++) {
+                       for (j = 0; j < cbflood_n_per_burst; j++) {
+                               cur_ops->call(&rhp[i * cbflood_n_per_burst + j],
+                                             rcu_torture_cbflood_cb);
+                       }
+                       schedule_timeout_interruptible(cbflood_intra_holdoff);
+                       WARN_ON(signal_pending(current));
+               }
+               cur_ops->cb_barrier();
+               stutter_wait("rcu_torture_cbflood");
+       } while (!torture_must_stop());
+       torture_kthread_stopping("rcu_torture_cbflood");
+       return 0;
+}
+
 /*
  * RCU torture force-quiescent-state kthread.  Repeatedly induces
  * bursts of calls to force_quiescent_state(), increasing the probability
@@ -1019,7 +1128,7 @@ rcu_torture_reader(void *arg)
                __this_cpu_inc(rcu_torture_batch[completed]);
                preempt_enable();
                cur_ops->readunlock(idx);
-               cond_resched();
+               cond_resched_rcu_qs();
                stutter_wait("rcu_torture_reader");
        } while (!torture_must_stop());
        if (irqreader && cur_ops->irq_capable) {
@@ -1075,10 +1184,11 @@ rcu_torture_stats_print(void)
                n_rcu_torture_boosts,
                n_rcu_torture_timers);
        torture_onoff_stats();
-       pr_cont("barrier: %ld/%ld:%ld\n",
+       pr_cont("barrier: %ld/%ld:%ld ",
                n_barrier_successes,
                n_barrier_attempts,
                n_rcu_torture_barrier_error);
+       pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods));
 
        pr_alert("%s%s ", torture_type, TORTURE_FLAG);
        if (atomic_read(&n_rcu_torture_mberror) != 0 ||
@@ -1280,7 +1390,8 @@ static int rcu_torture_barrier_cbs(void *arg)
                if (atomic_dec_and_test(&barrier_cbs_count))
                        wake_up(&barrier_wq);
        } while (!torture_must_stop());
-       cur_ops->cb_barrier();
+       if (cur_ops->cb_barrier != NULL)
+               cur_ops->cb_barrier();
        destroy_rcu_head_on_stack(&rcu);
        torture_kthread_stopping("rcu_torture_barrier_cbs");
        return 0;
@@ -1403,7 +1514,7 @@ rcu_torture_cleanup(void)
        int i;
 
        rcutorture_record_test_transition();
-       if (torture_cleanup()) {
+       if (torture_cleanup_begin()) {
                if (cur_ops->cb_barrier != NULL)
                        cur_ops->cb_barrier();
                return;
@@ -1432,6 +1543,8 @@ rcu_torture_cleanup(void)
 
        torture_stop_kthread(rcu_torture_stats, stats_task);
        torture_stop_kthread(rcu_torture_fqs, fqs_task);
+       for (i = 0; i < ncbflooders; i++)
+               torture_stop_kthread(rcu_torture_cbflood, cbflood_task[i]);
        if ((test_boost == 1 && cur_ops->can_boost) ||
            test_boost == 2) {
                unregister_cpu_notifier(&rcutorture_cpu_nb);
@@ -1453,6 +1566,7 @@ rcu_torture_cleanup(void)
                                               "End of test: RCU_HOTPLUG");
        else
                rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
+       torture_cleanup_end();
 }
 
 #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
@@ -1519,9 +1633,10 @@ rcu_torture_init(void)
        int firsterr = 0;
        static struct rcu_torture_ops *torture_ops[] = {
                &rcu_ops, &rcu_bh_ops, &rcu_busted_ops, &srcu_ops, &sched_ops,
+               RCUTORTURE_TASKS_OPS
        };
 
-       if (!torture_init_begin(torture_type, verbose, &rcutorture_runnable))
+       if (!torture_init_begin(torture_type, verbose, &torture_runnable))
                return -EBUSY;
 
        /* Process args and tell the world that the torturer is on the job. */
@@ -1678,6 +1793,24 @@ rcu_torture_init(void)
                goto unwind;
        if (object_debug)
                rcu_test_debug_objects();
+       if (cbflood_n_burst > 0) {
+               /* Create the cbflood threads */
+               ncbflooders = (num_online_cpus() + 3) / 4;
+               cbflood_task = kcalloc(ncbflooders, sizeof(*cbflood_task),
+                                      GFP_KERNEL);
+               if (!cbflood_task) {
+                       VERBOSE_TOROUT_ERRSTRING("out of memory");
+                       firsterr = -ENOMEM;
+                       goto unwind;
+               }
+               for (i = 0; i < ncbflooders; i++) {
+                       firsterr = torture_create_kthread(rcu_torture_cbflood,
+                                                         NULL,
+                                                         cbflood_task[i]);
+                       if (firsterr)
+                               goto unwind;
+               }
+       }
        rcutorture_record_test_transition();
        torture_init_end();
        return 0;