trace: stop all recording to ring buffer on ftrace_dump
[safe/jmp/linux-2.6] / kernel / rcutorture.c
index 5e954ed..7c4142a 100644 (file)
 #include <linux/moduleparam.h>
 #include <linux/percpu.h>
 #include <linux/notifier.h>
+#include <linux/reboot.h>
 #include <linux/freezer.h>
 #include <linux/cpu.h>
 #include <linux/delay.h>
-#include <linux/byteorder/swabb.h>
 #include <linux/stat.h>
 #include <linux/srcu.h>
 #include <linux/slab.h>
+#include <asm/byteorder.h>
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and "
@@ -59,6 +60,7 @@ static int verbose;           /* Print more debug info. */
 static int test_no_idle_hz;    /* Test RCU's support for tickless idle CPUs. */
 static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/
 static int stutter = 5;                /* Start/stop testing interval (in sec) */
+static int irqreader = 1;      /* RCU readers from irq (timers). */
 static char *torture_type = "rcu"; /* What RCU implementation to torture. */
 
 module_param(nreaders, int, 0444);
@@ -75,6 +77,8 @@ module_param(shuffle_interval, int, 0444);
 MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
 module_param(stutter, int, 0444);
 MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
+module_param(irqreader, int, 0444);
+MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
 module_param(torture_type, charp, 0444);
 MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
 
@@ -105,7 +109,6 @@ struct rcu_torture {
        int rtort_mbtest;
 };
 
-static int fullstop = 0;       /* stop generating callbacks at test end. */
 static LIST_HEAD(rcu_torture_freelist);
 static struct rcu_torture *rcu_torture_current = NULL;
 static long rcu_torture_current_version = 0;
@@ -121,6 +124,7 @@ static atomic_t n_rcu_torture_alloc_fail;
 static atomic_t n_rcu_torture_free;
 static atomic_t n_rcu_torture_mberror;
 static atomic_t n_rcu_torture_error;
+static long n_rcu_torture_timers = 0;
 static struct list_head rcu_torture_removed;
 
 static int stutter_pause_test = 0;
@@ -132,6 +136,46 @@ static int stutter_pause_test = 0;
 #endif
 int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
 
+/* Mediate rmmod and system shutdown.  Concurrent rmmod & shutdown illegal! */
+
+#define FULLSTOP_DONTSTOP 0    /* Normal operation. */
+#define FULLSTOP_SHUTDOWN 1    /* System shutdown with rcutorture running. */
+#define FULLSTOP_RMMOD    2    /* Normal rmmod of rcutorture. */
+static int fullstop = FULLSTOP_RMMOD;
+DEFINE_MUTEX(fullstop_mutex);  /* Protect fullstop transitions and spawning */
+                               /*  of kthreads. */
+
+/*
+ * Detect and respond to a system shutdown.
+ */
+static int
+rcutorture_shutdown_notify(struct notifier_block *unused1,
+                          unsigned long unused2, void *unused3)
+{
+       mutex_lock(&fullstop_mutex);
+       if (fullstop == FULLSTOP_DONTSTOP)
+               fullstop = FULLSTOP_SHUTDOWN;
+       else
+               printk(KERN_WARNING /* but going down anyway, so... */
+                      "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
+       mutex_unlock(&fullstop_mutex);
+       return NOTIFY_DONE;
+}
+
+/*
+ * Absorb kthreads into a kernel function that won't return, so that
+ * they won't ever access module text or data again.
+ */
+static void rcutorture_shutdown_absorb(char *title)
+{
+       if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
+               printk(KERN_NOTICE
+                      "rcutorture thread %s parking due to system shutdown\n",
+                      title);
+               schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
+       }
+}
+
 /*
  * Allocate an element from the rcu_tortures pool.
  */
@@ -193,13 +237,15 @@ rcu_random(struct rcu_random_state *rrsp)
 }
 
 static void
-rcu_stutter_wait(void)
+rcu_stutter_wait(char *title)
 {
-       while (stutter_pause_test || !rcutorture_runnable)
+       while (stutter_pause_test || !rcutorture_runnable) {
                if (rcutorture_runnable)
                        schedule_timeout_interruptible(1);
                else
                        schedule_timeout_interruptible(round_jiffies_relative(HZ));
+               rcutorture_shutdown_absorb(title);
+       }
 }
 
 /*
@@ -217,6 +263,7 @@ struct rcu_torture_ops {
        void (*sync)(void);
        void (*cb_barrier)(void);
        int (*stats)(char *page);
+       int irqcapable;
        char *name;
 };
 static struct rcu_torture_ops *cur_ops = NULL;
@@ -259,7 +306,7 @@ rcu_torture_cb(struct rcu_head *p)
        int i;
        struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
 
-       if (fullstop) {
+       if (fullstop != FULLSTOP_DONTSTOP) {
                /* Test is ending, just drop callbacks on the floor. */
                /* The next initialization will pick up the pieces. */
                return;
@@ -291,6 +338,7 @@ static struct rcu_torture_ops rcu_ops = {
        .sync = synchronize_rcu,
        .cb_barrier = rcu_barrier,
        .stats = NULL,
+       .irqcapable = 1,
        .name = "rcu"
 };
 
@@ -331,6 +379,7 @@ static struct rcu_torture_ops rcu_sync_ops = {
        .sync = synchronize_rcu,
        .cb_barrier = NULL,
        .stats = NULL,
+       .irqcapable = 1,
        .name = "rcu_sync"
 };
 
@@ -392,6 +441,7 @@ static struct rcu_torture_ops rcu_bh_ops = {
        .sync = rcu_bh_torture_synchronize,
        .cb_barrier = rcu_barrier_bh,
        .stats = NULL,
+       .irqcapable = 1,
        .name = "rcu_bh"
 };
 
@@ -406,6 +456,7 @@ static struct rcu_torture_ops rcu_bh_sync_ops = {
        .sync = rcu_bh_torture_synchronize,
        .cb_barrier = NULL,
        .stats = NULL,
+       .irqcapable = 1,
        .name = "rcu_bh_sync"
 };
 
@@ -532,6 +583,7 @@ static struct rcu_torture_ops sched_ops = {
        .sync = sched_torture_synchronize,
        .cb_barrier = rcu_barrier_sched,
        .stats = NULL,
+       .irqcapable = 1,
        .name = "sched"
 };
 
@@ -586,9 +638,10 @@ rcu_torture_writer(void *arg)
                }
                rcu_torture_current_version++;
                oldbatch = cur_ops->completed();
-               rcu_stutter_wait();
-       } while (!kthread_should_stop() && !fullstop);
+               rcu_stutter_wait("rcu_torture_writer");
+       } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
        VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
+       rcutorture_shutdown_absorb("rcu_torture_writer");
        while (!kthread_should_stop())
                schedule_timeout_uninterruptible(1);
        return 0;
@@ -610,16 +663,63 @@ rcu_torture_fakewriter(void *arg)
                schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
                udelay(rcu_random(&rand) & 0x3ff);
                cur_ops->sync();
-               rcu_stutter_wait();
-       } while (!kthread_should_stop() && !fullstop);
+               rcu_stutter_wait("rcu_torture_fakewriter");
+       } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
 
        VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
+       rcutorture_shutdown_absorb("rcu_torture_fakewriter");
        while (!kthread_should_stop())
                schedule_timeout_uninterruptible(1);
        return 0;
 }
 
 /*
+ * RCU torture reader from timer handler.  Dereferences rcu_torture_current,
+ * incrementing the corresponding element of the pipeline array.  The
+ * counter in the element should never be greater than 1, otherwise, the
+ * RCU implementation is broken.
+ */
+static void rcu_torture_timer(unsigned long unused)
+{
+       int idx;
+       int completed;
+       static DEFINE_RCU_RANDOM(rand);
+       static DEFINE_SPINLOCK(rand_lock);
+       struct rcu_torture *p;
+       int pipe_count;
+
+       idx = cur_ops->readlock();
+       completed = cur_ops->completed();
+       p = rcu_dereference(rcu_torture_current);
+       if (p == NULL) {
+               /* Leave because rcu_torture_writer is not yet underway */
+               cur_ops->readunlock(idx);
+               return;
+       }
+       if (p->rtort_mbtest == 0)
+               atomic_inc(&n_rcu_torture_mberror);
+       spin_lock(&rand_lock);
+       cur_ops->readdelay(&rand);
+       n_rcu_torture_timers++;
+       spin_unlock(&rand_lock);
+       preempt_disable();
+       pipe_count = p->rtort_pipe_count;
+       if (pipe_count > RCU_TORTURE_PIPE_LEN) {
+               /* Should not happen, but... */
+               pipe_count = RCU_TORTURE_PIPE_LEN;
+       }
+       ++__get_cpu_var(rcu_torture_count)[pipe_count];
+       completed = cur_ops->completed() - completed;
+       if (completed > RCU_TORTURE_PIPE_LEN) {
+               /* Should not happen, but... */
+               completed = RCU_TORTURE_PIPE_LEN;
+       }
+       ++__get_cpu_var(rcu_torture_batch)[completed];
+       preempt_enable();
+       cur_ops->readunlock(idx);
+}
+
+/*
  * RCU torture reader kthread.  Repeatedly dereferences rcu_torture_current,
  * incrementing the corresponding element of the pipeline array.  The
  * counter in the element should never be greater than 1, otherwise, the
@@ -633,11 +733,18 @@ rcu_torture_reader(void *arg)
        DEFINE_RCU_RANDOM(rand);
        struct rcu_torture *p;
        int pipe_count;
+       struct timer_list t;
 
        VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
        set_user_nice(current, 19);
+       if (irqreader && cur_ops->irqcapable)
+               setup_timer_on_stack(&t, rcu_torture_timer, 0);
 
        do {
+               if (irqreader && cur_ops->irqcapable) {
+                       if (!timer_pending(&t))
+                               mod_timer(&t, 1);
+               }
                idx = cur_ops->readlock();
                completed = cur_ops->completed();
                p = rcu_dereference(rcu_torture_current);
@@ -666,9 +773,12 @@ rcu_torture_reader(void *arg)
                preempt_enable();
                cur_ops->readunlock(idx);
                schedule();
-               rcu_stutter_wait();
-       } while (!kthread_should_stop() && !fullstop);
+               rcu_stutter_wait("rcu_torture_reader");
+       } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
        VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
+       rcutorture_shutdown_absorb("rcu_torture_reader");
+       if (irqreader && cur_ops->irqcapable)
+               del_timer_sync(&t);
        while (!kthread_should_stop())
                schedule_timeout_uninterruptible(1);
        return 0;
@@ -699,14 +809,15 @@ rcu_torture_printk(char *page)
        cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
        cnt += sprintf(&page[cnt],
                       "rtc: %p ver: %ld tfle: %d rta: %d rtaf: %d rtf: %d "
-                      "rtmbe: %d",
+                      "rtmbe: %d nt: %ld",
                       rcu_torture_current,
                       rcu_torture_current_version,
                       list_empty(&rcu_torture_freelist),
                       atomic_read(&n_rcu_torture_alloc),
                       atomic_read(&n_rcu_torture_alloc_fail),
                       atomic_read(&n_rcu_torture_free),
-                      atomic_read(&n_rcu_torture_mberror));
+                      atomic_read(&n_rcu_torture_mberror),
+                      n_rcu_torture_timers);
        if (atomic_read(&n_rcu_torture_mberror) != 0)
                cnt += sprintf(&page[cnt], " !!!");
        cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
@@ -765,6 +876,7 @@ rcu_torture_stats(void *arg)
        do {
                schedule_timeout_interruptible(stat_interval * HZ);
                rcu_torture_stats_print();
+               rcutorture_shutdown_absorb("rcu_torture_stats");
        } while (!kthread_should_stop());
        VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
        return 0;
@@ -833,6 +945,7 @@ rcu_torture_shuffle(void *arg)
        do {
                schedule_timeout_interruptible(shuffle_interval * HZ);
                rcu_torture_shuffle_tasks();
+               rcutorture_shutdown_absorb("rcu_torture_shuffle");
        } while (!kthread_should_stop());
        VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
        return 0;
@@ -851,6 +964,7 @@ rcu_torture_stutter(void *arg)
                if (!kthread_should_stop())
                        schedule_timeout_interruptible(stutter * HZ);
                stutter_pause_test = 0;
+               rcutorture_shutdown_absorb("rcu_torture_stutter");
        } while (!kthread_should_stop());
        VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
        return 0;
@@ -862,18 +976,34 @@ rcu_torture_print_module_parms(char *tag)
        printk(KERN_ALERT "%s" TORTURE_FLAG
                "--- %s: nreaders=%d nfakewriters=%d "
                "stat_interval=%d verbose=%d test_no_idle_hz=%d "
-               "shuffle_interval=%d stutter=%d\n",
+               "shuffle_interval=%d stutter=%d irqreader=%d\n",
                torture_type, tag, nrealreaders, nfakewriters,
                stat_interval, verbose, test_no_idle_hz, shuffle_interval,
-               stutter);
+               stutter, irqreader);
 }
 
+static struct notifier_block rcutorture_nb = {
+       .notifier_call = rcutorture_shutdown_notify,
+};
+
 static void
 rcu_torture_cleanup(void)
 {
        int i;
 
-       fullstop = 1;
+       mutex_lock(&fullstop_mutex);
+       if (fullstop == FULLSTOP_SHUTDOWN) {
+               printk(KERN_WARNING /* but going down anyway, so... */
+                      "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
+               mutex_unlock(&fullstop_mutex);
+               schedule_timeout_uninterruptible(10);
+               if (cur_ops->cb_barrier != NULL)
+                       cur_ops->cb_barrier();
+               return;
+       }
+       fullstop = FULLSTOP_RMMOD;
+       mutex_unlock(&fullstop_mutex);
+       unregister_reboot_notifier(&rcutorture_nb);
        if (stutter_task) {
                VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
                kthread_stop(stutter_task);
@@ -949,6 +1079,8 @@ rcu_torture_init(void)
                { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops,
                  &srcu_ops, &sched_ops, &sched_ops_sync, };
 
+       mutex_lock(&fullstop_mutex);
+
        /* Process args and tell the world that the torturer is on the job. */
        for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
                cur_ops = torture_ops[i];
@@ -958,6 +1090,7 @@ rcu_torture_init(void)
        if (i == ARRAY_SIZE(torture_ops)) {
                printk(KERN_ALERT "rcutorture: invalid torture type: \"%s\"\n",
                       torture_type);
+               mutex_unlock(&fullstop_mutex);
                return (-EINVAL);
        }
        if (cur_ops->init)
@@ -968,7 +1101,7 @@ rcu_torture_init(void)
        else
                nrealreaders = 2 * num_online_cpus();
        rcu_torture_print_module_parms("Start of test");
-       fullstop = 0;
+       fullstop = FULLSTOP_DONTSTOP;
 
        /* Set up the freelist. */
 
@@ -1080,9 +1213,12 @@ rcu_torture_init(void)
                        goto unwind;
                }
        }
+       register_reboot_notifier(&rcutorture_nb);
+       mutex_unlock(&fullstop_mutex);
        return 0;
 
 unwind:
+       mutex_unlock(&fullstop_mutex);
        rcu_torture_cleanup();
        return firsterr;
 }