2 * Read-Copy Update module-based torture test facility
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * Copyright (C) IBM Corporation, 2005, 2006
20 * Authors: Paul E. McKenney <paulmck@us.ibm.com>
21 * Josh Triplett <josh@freedesktop.org>
23 * See also: Documentation/RCU/torture.txt
25 #include <linux/types.h>
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/module.h>
29 #include <linux/kthread.h>
30 #include <linux/err.h>
31 #include <linux/spinlock.h>
32 #include <linux/smp.h>
33 #include <linux/rcupdate.h>
34 #include <linux/interrupt.h>
35 #include <linux/sched.h>
36 #include <linux/atomic.h>
37 #include <linux/bitops.h>
38 #include <linux/completion.h>
39 #include <linux/moduleparam.h>
40 #include <linux/percpu.h>
41 #include <linux/notifier.h>
42 #include <linux/reboot.h>
43 #include <linux/freezer.h>
44 #include <linux/cpu.h>
45 #include <linux/delay.h>
46 #include <linux/stat.h>
47 #include <linux/srcu.h>
48 #include <linux/slab.h>
49 #include <asm/byteorder.h>
51 MODULE_LICENSE("GPL");
52 MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and "
53 "Josh Triplett <josh@freedesktop.org>");
55 static int nreaders = -1; /* # reader threads, defaults to 2*ncpus */
56 static int nfakewriters = 4; /* # fake writer threads */
57 static int stat_interval; /* Interval between stats, in seconds. */
58 /* Defaults to "only at end of test". */
59 static int verbose; /* Print more debug info. */
60 static int test_no_idle_hz; /* Test RCU's support for tickless idle CPUs. */
61 static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/
62 static int stutter = 5; /* Start/stop testing interval (in sec) */
63 static int irqreader = 1; /* RCU readers from irq (timers). */
64 static int fqs_duration = 0; /* Duration of bursts (us), 0 to disable. */
65 static int fqs_holdoff = 0; /* Hold time within burst (us). */
66 static int fqs_stutter = 3; /* Wait time between bursts (s). */
67 static int test_boost = 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */
68 static int test_boost_interval = 7; /* Interval between boost tests, seconds. */
69 static int test_boost_duration = 4; /* Duration of each boost test, seconds. */
70 static char *torture_type = "rcu"; /* What RCU implementation to torture. */
72 module_param(nreaders, int, 0444);
73 MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
74 module_param(nfakewriters, int, 0444);
75 MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
76 module_param(stat_interval, int, 0644);
77 MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
78 module_param(verbose, bool, 0444);
79 MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
80 module_param(test_no_idle_hz, bool, 0444);
81 MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
82 module_param(shuffle_interval, int, 0444);
83 MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
84 module_param(stutter, int, 0444);
85 MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
86 module_param(irqreader, int, 0444);
87 MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
88 module_param(fqs_duration, int, 0444);
89 MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us)");
90 module_param(fqs_holdoff, int, 0444);
91 MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)");
92 module_param(fqs_stutter, int, 0444);
93 MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)");
94 module_param(test_boost, int, 0444);
95 MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
96 module_param(test_boost_interval, int, 0444);
97 MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds.");
98 module_param(test_boost_duration, int, 0444);
99 MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds.");
100 module_param(torture_type, charp, 0444);
101 MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
103 #define TORTURE_FLAG "-torture:"
104 #define PRINTK_STRING(s) \
105 do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
106 #define VERBOSE_PRINTK_STRING(s) \
107 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
108 #define VERBOSE_PRINTK_ERRSTRING(s) \
109 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
111 static char printk_buf[4096];
113 static int nrealreaders;
114 static struct task_struct *writer_task;
115 static struct task_struct **fakewriter_tasks;
116 static struct task_struct **reader_tasks;
117 static struct task_struct *stats_task;
118 static struct task_struct *shuffler_task;
119 static struct task_struct *stutter_task;
120 static struct task_struct *fqs_task;
121 static struct task_struct *boost_tasks[NR_CPUS];
123 #define RCU_TORTURE_PIPE_LEN 10
126 struct rcu_head rtort_rcu;
127 int rtort_pipe_count;
128 struct list_head rtort_free;
132 static LIST_HEAD(rcu_torture_freelist);
133 static struct rcu_torture __rcu *rcu_torture_current;
134 static unsigned long rcu_torture_current_version;
135 static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
136 static DEFINE_SPINLOCK(rcu_torture_lock);
137 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
139 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
141 static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
142 static atomic_t n_rcu_torture_alloc;
143 static atomic_t n_rcu_torture_alloc_fail;
144 static atomic_t n_rcu_torture_free;
145 static atomic_t n_rcu_torture_mberror;
146 static atomic_t n_rcu_torture_error;
147 static long n_rcu_torture_boost_ktrerror;
148 static long n_rcu_torture_boost_rterror;
149 static long n_rcu_torture_boost_failure;
150 static long n_rcu_torture_boosts;
151 static long n_rcu_torture_timers;
152 static struct list_head rcu_torture_removed;
153 static cpumask_var_t shuffle_tmp_mask;
155 static int stutter_pause_test;
157 #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
158 #define RCUTORTURE_RUNNABLE_INIT 1
160 #define RCUTORTURE_RUNNABLE_INIT 0
162 int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
164 #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
165 #define rcu_can_boost() 1
166 #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
167 #define rcu_can_boost() 0
168 #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
170 static unsigned long boost_starttime; /* jiffies of next boost test start. */
171 DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
172 /* and boost task create/destroy. */
174 /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
176 #define FULLSTOP_DONTSTOP 0 /* Normal operation. */
177 #define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
178 #define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
179 static int fullstop = FULLSTOP_RMMOD;
181 * Protect fullstop transitions and spawning of kthreads.
183 static DEFINE_MUTEX(fullstop_mutex);
186 * Detect and respond to a system shutdown.
189 rcutorture_shutdown_notify(struct notifier_block *unused1,
190 unsigned long unused2, void *unused3)
192 mutex_lock(&fullstop_mutex);
193 if (fullstop == FULLSTOP_DONTSTOP)
194 fullstop = FULLSTOP_SHUTDOWN;
196 printk(KERN_WARNING /* but going down anyway, so... */
197 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
198 mutex_unlock(&fullstop_mutex);
203 * Absorb kthreads into a kernel function that won't return, so that
204 * they won't ever access module text or data again.
206 static void rcutorture_shutdown_absorb(char *title)
208 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
210 "rcutorture thread %s parking due to system shutdown\n",
212 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
217 * Allocate an element from the rcu_tortures pool.
219 static struct rcu_torture *
220 rcu_torture_alloc(void)
224 spin_lock_bh(&rcu_torture_lock);
225 if (list_empty(&rcu_torture_freelist)) {
226 atomic_inc(&n_rcu_torture_alloc_fail);
227 spin_unlock_bh(&rcu_torture_lock);
230 atomic_inc(&n_rcu_torture_alloc);
231 p = rcu_torture_freelist.next;
233 spin_unlock_bh(&rcu_torture_lock);
234 return container_of(p, struct rcu_torture, rtort_free);
238 * Free an element to the rcu_tortures pool.
241 rcu_torture_free(struct rcu_torture *p)
243 atomic_inc(&n_rcu_torture_free);
244 spin_lock_bh(&rcu_torture_lock);
245 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
246 spin_unlock_bh(&rcu_torture_lock);
249 struct rcu_random_state {
250 unsigned long rrs_state;
254 #define RCU_RANDOM_MULT 39916801 /* prime */
255 #define RCU_RANDOM_ADD 479001701 /* prime */
256 #define RCU_RANDOM_REFRESH 10000
258 #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
261 * Crude but fast random-number generator. Uses a linear congruential
262 * generator, with occasional help from cpu_clock().
265 rcu_random(struct rcu_random_state *rrsp)
267 if (--rrsp->rrs_count < 0) {
268 rrsp->rrs_state += (unsigned long)local_clock();
269 rrsp->rrs_count = RCU_RANDOM_REFRESH;
271 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
272 return swahw32(rrsp->rrs_state);
276 rcu_stutter_wait(char *title)
278 while (stutter_pause_test || !rcutorture_runnable) {
279 if (rcutorture_runnable)
280 schedule_timeout_interruptible(1);
282 schedule_timeout_interruptible(round_jiffies_relative(HZ));
283 rcutorture_shutdown_absorb(title);
288 * Operations vector for selecting different types of tests.
291 struct rcu_torture_ops {
293 void (*cleanup)(void);
294 int (*readlock)(void);
295 void (*read_delay)(struct rcu_random_state *rrsp);
296 void (*readunlock)(int idx);
297 int (*completed)(void);
298 void (*deferred_free)(struct rcu_torture *p);
300 void (*cb_barrier)(void);
302 int (*stats)(char *page);
308 static struct rcu_torture_ops *cur_ops;
311 * Definitions for rcu torture testing.
314 static int rcu_torture_read_lock(void) __acquires(RCU)
320 static void rcu_read_delay(struct rcu_random_state *rrsp)
322 const unsigned long shortdelay_us = 200;
323 const unsigned long longdelay_ms = 50;
325 /* We want a short delay sometimes to make a reader delay the grace
326 * period, and we want a long delay occasionally to trigger
327 * force_quiescent_state. */
329 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
330 mdelay(longdelay_ms);
331 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
332 udelay(shortdelay_us);
333 #ifdef CONFIG_PREEMPT
334 if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000)))
335 preempt_schedule(); /* No QS if preempt_disable() in effect */
339 static void rcu_torture_read_unlock(int idx) __releases(RCU)
344 static int rcu_torture_completed(void)
346 return rcu_batches_completed();
350 rcu_torture_cb(struct rcu_head *p)
353 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
355 if (fullstop != FULLSTOP_DONTSTOP) {
356 /* Test is ending, just drop callbacks on the floor. */
357 /* The next initialization will pick up the pieces. */
360 i = rp->rtort_pipe_count;
361 if (i > RCU_TORTURE_PIPE_LEN)
362 i = RCU_TORTURE_PIPE_LEN;
363 atomic_inc(&rcu_torture_wcount[i]);
364 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
365 rp->rtort_mbtest = 0;
366 rcu_torture_free(rp);
368 cur_ops->deferred_free(rp);
371 static int rcu_no_completed(void)
376 static void rcu_torture_deferred_free(struct rcu_torture *p)
378 call_rcu(&p->rtort_rcu, rcu_torture_cb);
381 static struct rcu_torture_ops rcu_ops = {
384 .readlock = rcu_torture_read_lock,
385 .read_delay = rcu_read_delay,
386 .readunlock = rcu_torture_read_unlock,
387 .completed = rcu_torture_completed,
388 .deferred_free = rcu_torture_deferred_free,
389 .sync = synchronize_rcu,
390 .cb_barrier = rcu_barrier,
391 .fqs = rcu_force_quiescent_state,
394 .can_boost = rcu_can_boost(),
398 static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
401 struct rcu_torture *rp;
402 struct rcu_torture *rp1;
405 list_add(&p->rtort_free, &rcu_torture_removed);
406 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
407 i = rp->rtort_pipe_count;
408 if (i > RCU_TORTURE_PIPE_LEN)
409 i = RCU_TORTURE_PIPE_LEN;
410 atomic_inc(&rcu_torture_wcount[i]);
411 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
412 rp->rtort_mbtest = 0;
413 list_del(&rp->rtort_free);
414 rcu_torture_free(rp);
419 static void rcu_sync_torture_init(void)
421 INIT_LIST_HEAD(&rcu_torture_removed);
424 static struct rcu_torture_ops rcu_sync_ops = {
425 .init = rcu_sync_torture_init,
427 .readlock = rcu_torture_read_lock,
428 .read_delay = rcu_read_delay,
429 .readunlock = rcu_torture_read_unlock,
430 .completed = rcu_torture_completed,
431 .deferred_free = rcu_sync_torture_deferred_free,
432 .sync = synchronize_rcu,
434 .fqs = rcu_force_quiescent_state,
437 .can_boost = rcu_can_boost(),
441 static struct rcu_torture_ops rcu_expedited_ops = {
442 .init = rcu_sync_torture_init,
444 .readlock = rcu_torture_read_lock,
445 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
446 .readunlock = rcu_torture_read_unlock,
447 .completed = rcu_no_completed,
448 .deferred_free = rcu_sync_torture_deferred_free,
449 .sync = synchronize_rcu_expedited,
451 .fqs = rcu_force_quiescent_state,
454 .can_boost = rcu_can_boost(),
455 .name = "rcu_expedited"
459 * Definitions for rcu_bh torture testing.
462 static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
468 static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
470 rcu_read_unlock_bh();
473 static int rcu_bh_torture_completed(void)
475 return rcu_batches_completed_bh();
478 static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
480 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
483 static struct rcu_torture_ops rcu_bh_ops = {
486 .readlock = rcu_bh_torture_read_lock,
487 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
488 .readunlock = rcu_bh_torture_read_unlock,
489 .completed = rcu_bh_torture_completed,
490 .deferred_free = rcu_bh_torture_deferred_free,
491 .sync = synchronize_rcu_bh,
492 .cb_barrier = rcu_barrier_bh,
493 .fqs = rcu_bh_force_quiescent_state,
499 static struct rcu_torture_ops rcu_bh_sync_ops = {
500 .init = rcu_sync_torture_init,
502 .readlock = rcu_bh_torture_read_lock,
503 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
504 .readunlock = rcu_bh_torture_read_unlock,
505 .completed = rcu_bh_torture_completed,
506 .deferred_free = rcu_sync_torture_deferred_free,
507 .sync = synchronize_rcu_bh,
509 .fqs = rcu_bh_force_quiescent_state,
512 .name = "rcu_bh_sync"
515 static struct rcu_torture_ops rcu_bh_expedited_ops = {
516 .init = rcu_sync_torture_init,
518 .readlock = rcu_bh_torture_read_lock,
519 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
520 .readunlock = rcu_bh_torture_read_unlock,
521 .completed = rcu_bh_torture_completed,
522 .deferred_free = rcu_sync_torture_deferred_free,
523 .sync = synchronize_rcu_bh_expedited,
525 .fqs = rcu_bh_force_quiescent_state,
528 .name = "rcu_bh_expedited"
532 * Definitions for srcu torture testing.
535 static struct srcu_struct srcu_ctl;
537 static void srcu_torture_init(void)
539 init_srcu_struct(&srcu_ctl);
540 rcu_sync_torture_init();
543 static void srcu_torture_cleanup(void)
545 synchronize_srcu(&srcu_ctl);
546 cleanup_srcu_struct(&srcu_ctl);
549 static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
551 return srcu_read_lock(&srcu_ctl);
554 static void srcu_read_delay(struct rcu_random_state *rrsp)
557 const long uspertick = 1000000 / HZ;
558 const long longdelay = 10;
560 /* We want there to be long-running readers, but not all the time. */
562 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
564 schedule_timeout_interruptible(longdelay);
566 rcu_read_delay(rrsp);
569 static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
571 srcu_read_unlock(&srcu_ctl, idx);
574 static int srcu_torture_completed(void)
576 return srcu_batches_completed(&srcu_ctl);
579 static void srcu_torture_synchronize(void)
581 synchronize_srcu(&srcu_ctl);
584 static int srcu_torture_stats(char *page)
588 int idx = srcu_ctl.completed & 0x1;
590 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
591 torture_type, TORTURE_FLAG, idx);
592 for_each_possible_cpu(cpu) {
593 cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu,
594 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
595 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
597 cnt += sprintf(&page[cnt], "\n");
601 static struct rcu_torture_ops srcu_ops = {
602 .init = srcu_torture_init,
603 .cleanup = srcu_torture_cleanup,
604 .readlock = srcu_torture_read_lock,
605 .read_delay = srcu_read_delay,
606 .readunlock = srcu_torture_read_unlock,
607 .completed = srcu_torture_completed,
608 .deferred_free = rcu_sync_torture_deferred_free,
609 .sync = srcu_torture_synchronize,
611 .stats = srcu_torture_stats,
615 static void srcu_torture_synchronize_expedited(void)
617 synchronize_srcu_expedited(&srcu_ctl);
620 static struct rcu_torture_ops srcu_expedited_ops = {
621 .init = srcu_torture_init,
622 .cleanup = srcu_torture_cleanup,
623 .readlock = srcu_torture_read_lock,
624 .read_delay = srcu_read_delay,
625 .readunlock = srcu_torture_read_unlock,
626 .completed = srcu_torture_completed,
627 .deferred_free = rcu_sync_torture_deferred_free,
628 .sync = srcu_torture_synchronize_expedited,
630 .stats = srcu_torture_stats,
631 .name = "srcu_expedited"
635 * Definitions for sched torture testing.
638 static int sched_torture_read_lock(void)
644 static void sched_torture_read_unlock(int idx)
649 static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
651 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
654 static struct rcu_torture_ops sched_ops = {
655 .init = rcu_sync_torture_init,
657 .readlock = sched_torture_read_lock,
658 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
659 .readunlock = sched_torture_read_unlock,
660 .completed = rcu_no_completed,
661 .deferred_free = rcu_sched_torture_deferred_free,
662 .sync = synchronize_sched,
663 .cb_barrier = rcu_barrier_sched,
664 .fqs = rcu_sched_force_quiescent_state,
670 static struct rcu_torture_ops sched_sync_ops = {
671 .init = rcu_sync_torture_init,
673 .readlock = sched_torture_read_lock,
674 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
675 .readunlock = sched_torture_read_unlock,
676 .completed = rcu_no_completed,
677 .deferred_free = rcu_sync_torture_deferred_free,
678 .sync = synchronize_sched,
680 .fqs = rcu_sched_force_quiescent_state,
685 static struct rcu_torture_ops sched_expedited_ops = {
686 .init = rcu_sync_torture_init,
688 .readlock = sched_torture_read_lock,
689 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
690 .readunlock = sched_torture_read_unlock,
691 .completed = rcu_no_completed,
692 .deferred_free = rcu_sync_torture_deferred_free,
693 .sync = synchronize_sched_expedited,
695 .fqs = rcu_sched_force_quiescent_state,
698 .name = "sched_expedited"
702 * RCU torture priority-boost testing. Runs one real-time thread per
703 * CPU for moderate bursts, repeatedly registering RCU callbacks and
704 * spinning waiting for them to be invoked. If a given callback takes
705 * too long to be invoked, we assume that priority inversion has occurred.
708 struct rcu_boost_inflight {
713 static void rcu_torture_boost_cb(struct rcu_head *head)
715 struct rcu_boost_inflight *rbip =
716 container_of(head, struct rcu_boost_inflight, rcu);
718 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
722 static int rcu_torture_boost(void *arg)
724 unsigned long call_rcu_time;
725 unsigned long endtime;
726 unsigned long oldstarttime;
727 struct rcu_boost_inflight rbi = { .inflight = 0 };
728 struct sched_param sp;
730 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
732 /* Set real-time priority. */
733 sp.sched_priority = 1;
734 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
735 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
736 n_rcu_torture_boost_rterror++;
739 init_rcu_head_on_stack(&rbi.rcu);
740 /* Each pass through the following loop does one boost-test cycle. */
742 /* Wait for the next test interval. */
743 oldstarttime = boost_starttime;
744 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
745 schedule_timeout_uninterruptible(1);
746 rcu_stutter_wait("rcu_torture_boost");
747 if (kthread_should_stop() ||
748 fullstop != FULLSTOP_DONTSTOP)
752 /* Do one boost-test interval. */
753 endtime = oldstarttime + test_boost_duration * HZ;
754 call_rcu_time = jiffies;
755 while (ULONG_CMP_LT(jiffies, endtime)) {
756 /* If we don't have a callback in flight, post one. */
758 smp_mb(); /* RCU core before ->inflight = 1. */
760 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
761 if (jiffies - call_rcu_time >
762 test_boost_duration * HZ - HZ / 2) {
763 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
764 n_rcu_torture_boost_failure++;
766 call_rcu_time = jiffies;
769 rcu_stutter_wait("rcu_torture_boost");
770 if (kthread_should_stop() ||
771 fullstop != FULLSTOP_DONTSTOP)
776 * Set the start time of the next test interval.
777 * Yes, this is vulnerable to long delays, but such
778 * delays simply cause a false negative for the next
779 * interval. Besides, we are running at RT priority,
780 * so delays should be relatively rare.
782 while (oldstarttime == boost_starttime &&
783 !kthread_should_stop()) {
784 if (mutex_trylock(&boost_mutex)) {
785 boost_starttime = jiffies +
786 test_boost_interval * HZ;
787 n_rcu_torture_boosts++;
788 mutex_unlock(&boost_mutex);
791 schedule_timeout_uninterruptible(1);
794 /* Go do the stutter. */
795 checkwait: rcu_stutter_wait("rcu_torture_boost");
796 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
798 /* Clean up and exit. */
799 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
800 rcutorture_shutdown_absorb("rcu_torture_boost");
801 while (!kthread_should_stop() || rbi.inflight)
802 schedule_timeout_uninterruptible(1);
803 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
804 destroy_rcu_head_on_stack(&rbi.rcu);
809 * RCU torture force-quiescent-state kthread. Repeatedly induces
810 * bursts of calls to force_quiescent_state(), increasing the probability
811 * of occurrence of some important types of race conditions.
814 rcu_torture_fqs(void *arg)
816 unsigned long fqs_resume_time;
817 int fqs_burst_remaining;
819 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
821 fqs_resume_time = jiffies + fqs_stutter * HZ;
822 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
823 !kthread_should_stop()) {
824 schedule_timeout_interruptible(1);
826 fqs_burst_remaining = fqs_duration;
827 while (fqs_burst_remaining > 0 &&
828 !kthread_should_stop()) {
831 fqs_burst_remaining -= fqs_holdoff;
833 rcu_stutter_wait("rcu_torture_fqs");
834 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
835 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
836 rcutorture_shutdown_absorb("rcu_torture_fqs");
837 while (!kthread_should_stop())
838 schedule_timeout_uninterruptible(1);
843 * RCU torture writer kthread. Repeatedly substitutes a new structure
844 * for that pointed to by rcu_torture_current, freeing the old structure
845 * after a series of grace periods (the "pipeline").
848 rcu_torture_writer(void *arg)
851 long oldbatch = rcu_batches_completed();
852 struct rcu_torture *rp;
853 struct rcu_torture *old_rp;
854 static DEFINE_RCU_RANDOM(rand);
856 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
857 set_user_nice(current, 19);
860 schedule_timeout_uninterruptible(1);
861 rp = rcu_torture_alloc();
864 rp->rtort_pipe_count = 0;
865 udelay(rcu_random(&rand) & 0x3ff);
866 old_rp = rcu_dereference_check(rcu_torture_current,
867 current == writer_task);
868 rp->rtort_mbtest = 1;
869 rcu_assign_pointer(rcu_torture_current, rp);
870 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
872 i = old_rp->rtort_pipe_count;
873 if (i > RCU_TORTURE_PIPE_LEN)
874 i = RCU_TORTURE_PIPE_LEN;
875 atomic_inc(&rcu_torture_wcount[i]);
876 old_rp->rtort_pipe_count++;
877 cur_ops->deferred_free(old_rp);
879 rcutorture_record_progress(++rcu_torture_current_version);
880 oldbatch = cur_ops->completed();
881 rcu_stutter_wait("rcu_torture_writer");
882 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
883 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
884 rcutorture_shutdown_absorb("rcu_torture_writer");
885 while (!kthread_should_stop())
886 schedule_timeout_uninterruptible(1);
891 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
892 * delay between calls.
895 rcu_torture_fakewriter(void *arg)
897 DEFINE_RCU_RANDOM(rand);
899 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
900 set_user_nice(current, 19);
903 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
904 udelay(rcu_random(&rand) & 0x3ff);
906 rcu_stutter_wait("rcu_torture_fakewriter");
907 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
909 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
910 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
911 while (!kthread_should_stop())
912 schedule_timeout_uninterruptible(1);
916 void rcutorture_trace_dump(void)
918 static atomic_t beenhere = ATOMIC_INIT(0);
920 if (atomic_read(&beenhere))
922 if (atomic_xchg(&beenhere, 1) != 0)
924 do_trace_rcu_torture_read(cur_ops->name, (struct rcu_head *)~0UL);
925 ftrace_dump(DUMP_ALL);
929 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
930 * incrementing the corresponding element of the pipeline array. The
931 * counter in the element should never be greater than 1, otherwise, the
932 * RCU implementation is broken.
934 static void rcu_torture_timer(unsigned long unused)
938 static DEFINE_RCU_RANDOM(rand);
939 static DEFINE_SPINLOCK(rand_lock);
940 struct rcu_torture *p;
943 idx = cur_ops->readlock();
944 completed = cur_ops->completed();
945 p = rcu_dereference_check(rcu_torture_current,
946 rcu_read_lock_bh_held() ||
947 rcu_read_lock_sched_held() ||
948 srcu_read_lock_held(&srcu_ctl));
949 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
951 /* Leave because rcu_torture_writer is not yet underway */
952 cur_ops->readunlock(idx);
955 if (p->rtort_mbtest == 0)
956 atomic_inc(&n_rcu_torture_mberror);
957 spin_lock(&rand_lock);
958 cur_ops->read_delay(&rand);
959 n_rcu_torture_timers++;
960 spin_unlock(&rand_lock);
962 pipe_count = p->rtort_pipe_count;
963 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
964 /* Should not happen, but... */
965 pipe_count = RCU_TORTURE_PIPE_LEN;
968 rcutorture_trace_dump();
969 __this_cpu_inc(rcu_torture_count[pipe_count]);
970 completed = cur_ops->completed() - completed;
971 if (completed > RCU_TORTURE_PIPE_LEN) {
972 /* Should not happen, but... */
973 completed = RCU_TORTURE_PIPE_LEN;
975 __this_cpu_inc(rcu_torture_batch[completed]);
977 cur_ops->readunlock(idx);
981 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
982 * incrementing the corresponding element of the pipeline array. The
983 * counter in the element should never be greater than 1, otherwise, the
984 * RCU implementation is broken.
987 rcu_torture_reader(void *arg)
991 DEFINE_RCU_RANDOM(rand);
992 struct rcu_torture *p;
996 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
997 set_user_nice(current, 19);
998 if (irqreader && cur_ops->irq_capable)
999 setup_timer_on_stack(&t, rcu_torture_timer, 0);
1002 if (irqreader && cur_ops->irq_capable) {
1003 if (!timer_pending(&t))
1004 mod_timer(&t, jiffies + 1);
1006 idx = cur_ops->readlock();
1007 completed = cur_ops->completed();
1008 p = rcu_dereference_check(rcu_torture_current,
1009 rcu_read_lock_bh_held() ||
1010 rcu_read_lock_sched_held() ||
1011 srcu_read_lock_held(&srcu_ctl));
1012 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
1014 /* Wait for rcu_torture_writer to get underway */
1015 cur_ops->readunlock(idx);
1016 schedule_timeout_interruptible(HZ);
1019 if (p->rtort_mbtest == 0)
1020 atomic_inc(&n_rcu_torture_mberror);
1021 cur_ops->read_delay(&rand);
1023 pipe_count = p->rtort_pipe_count;
1024 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1025 /* Should not happen, but... */
1026 pipe_count = RCU_TORTURE_PIPE_LEN;
1029 rcutorture_trace_dump();
1030 __this_cpu_inc(rcu_torture_count[pipe_count]);
1031 completed = cur_ops->completed() - completed;
1032 if (completed > RCU_TORTURE_PIPE_LEN) {
1033 /* Should not happen, but... */
1034 completed = RCU_TORTURE_PIPE_LEN;
1036 __this_cpu_inc(rcu_torture_batch[completed]);
1038 cur_ops->readunlock(idx);
1040 rcu_stutter_wait("rcu_torture_reader");
1041 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1042 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
1043 rcutorture_shutdown_absorb("rcu_torture_reader");
1044 if (irqreader && cur_ops->irq_capable)
1046 while (!kthread_should_stop())
1047 schedule_timeout_uninterruptible(1);
1052 * Create an RCU-torture statistics message in the specified buffer.
1055 rcu_torture_printk(char *page)
1060 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1061 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1063 for_each_possible_cpu(cpu) {
1064 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1065 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1066 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1069 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1070 if (pipesummary[i] != 0)
1073 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
1074 cnt += sprintf(&page[cnt],
1075 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d "
1076 "rtmbe: %d rtbke: %ld rtbre: %ld "
1077 "rtbf: %ld rtb: %ld nt: %ld",
1078 rcu_torture_current,
1079 rcu_torture_current_version,
1080 list_empty(&rcu_torture_freelist),
1081 atomic_read(&n_rcu_torture_alloc),
1082 atomic_read(&n_rcu_torture_alloc_fail),
1083 atomic_read(&n_rcu_torture_free),
1084 atomic_read(&n_rcu_torture_mberror),
1085 n_rcu_torture_boost_ktrerror,
1086 n_rcu_torture_boost_rterror,
1087 n_rcu_torture_boost_failure,
1088 n_rcu_torture_boosts,
1089 n_rcu_torture_timers);
1090 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
1091 n_rcu_torture_boost_ktrerror != 0 ||
1092 n_rcu_torture_boost_rterror != 0 ||
1093 n_rcu_torture_boost_failure != 0)
1094 cnt += sprintf(&page[cnt], " !!!");
1095 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
1097 cnt += sprintf(&page[cnt], "!!! ");
1098 atomic_inc(&n_rcu_torture_error);
1101 cnt += sprintf(&page[cnt], "Reader Pipe: ");
1102 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1103 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
1104 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
1105 cnt += sprintf(&page[cnt], "Reader Batch: ");
1106 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1107 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
1108 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
1109 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
1110 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1111 cnt += sprintf(&page[cnt], " %d",
1112 atomic_read(&rcu_torture_wcount[i]));
1114 cnt += sprintf(&page[cnt], "\n");
1116 cnt += cur_ops->stats(&page[cnt]);
1121 * Print torture statistics. Caller must ensure that there is only
1122 * one call to this function at a given time!!! This is normally
1123 * accomplished by relying on the module system to only have one copy
1124 * of the module loaded, and then by giving the rcu_torture_stats
1125 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1126 * thread is not running).
1129 rcu_torture_stats_print(void)
1133 cnt = rcu_torture_printk(printk_buf);
1134 printk(KERN_ALERT "%s", printk_buf);
1138 * Periodically prints torture statistics, if periodic statistics printing
1139 * was specified via the stat_interval module parameter.
1141 * No need to worry about fullstop here, since this one doesn't reference
1142 * volatile state or register callbacks.
1145 rcu_torture_stats(void *arg)
1147 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1149 schedule_timeout_interruptible(stat_interval * HZ);
1150 rcu_torture_stats_print();
1151 rcutorture_shutdown_absorb("rcu_torture_stats");
1152 } while (!kthread_should_stop());
1153 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1157 static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
1159 /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1160 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1162 static void rcu_torture_shuffle_tasks(void)
1166 cpumask_setall(shuffle_tmp_mask);
1169 /* No point in shuffling if there is only one online CPU (ex: UP) */
1170 if (num_online_cpus() == 1) {
1175 if (rcu_idle_cpu != -1)
1176 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
1178 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
1181 for (i = 0; i < nrealreaders; i++)
1182 if (reader_tasks[i])
1183 set_cpus_allowed_ptr(reader_tasks[i],
1187 if (fakewriter_tasks) {
1188 for (i = 0; i < nfakewriters; i++)
1189 if (fakewriter_tasks[i])
1190 set_cpus_allowed_ptr(fakewriter_tasks[i],
1195 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
1198 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
1200 if (rcu_idle_cpu == -1)
1201 rcu_idle_cpu = num_online_cpus() - 1;
1208 /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1209 * system to become idle at a time and cut off its timer ticks. This is meant
1210 * to test the support for such tickless idle CPU in RCU.
1213 rcu_torture_shuffle(void *arg)
1215 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1217 schedule_timeout_interruptible(shuffle_interval * HZ);
1218 rcu_torture_shuffle_tasks();
1219 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1220 } while (!kthread_should_stop());
1221 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1225 /* Cause the rcutorture test to "stutter", starting and stopping all
1226 * threads periodically.
1229 rcu_torture_stutter(void *arg)
1231 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1233 schedule_timeout_interruptible(stutter * HZ);
1234 stutter_pause_test = 1;
1235 if (!kthread_should_stop())
1236 schedule_timeout_interruptible(stutter * HZ);
1237 stutter_pause_test = 0;
1238 rcutorture_shutdown_absorb("rcu_torture_stutter");
1239 } while (!kthread_should_stop());
1240 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1245 rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
1247 printk(KERN_ALERT "%s" TORTURE_FLAG
1248 "--- %s: nreaders=%d nfakewriters=%d "
1249 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1250 "shuffle_interval=%d stutter=%d irqreader=%d "
1251 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1252 "test_boost=%d/%d test_boost_interval=%d "
1253 "test_boost_duration=%d\n",
1254 torture_type, tag, nrealreaders, nfakewriters,
1255 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
1256 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1257 test_boost, cur_ops->can_boost,
1258 test_boost_interval, test_boost_duration);
1261 static struct notifier_block rcutorture_shutdown_nb = {
1262 .notifier_call = rcutorture_shutdown_notify,
1265 static void rcutorture_booster_cleanup(int cpu)
1267 struct task_struct *t;
1269 if (boost_tasks[cpu] == NULL)
1271 mutex_lock(&boost_mutex);
1272 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1273 t = boost_tasks[cpu];
1274 boost_tasks[cpu] = NULL;
1275 mutex_unlock(&boost_mutex);
1277 /* This must be outside of the mutex, otherwise deadlock! */
1281 static int rcutorture_booster_init(int cpu)
1285 if (boost_tasks[cpu] != NULL)
1286 return 0; /* Already created, nothing more to do. */
1288 /* Don't allow time recalculation while creating a new task. */
1289 mutex_lock(&boost_mutex);
1290 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
1291 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1293 "rcu_torture_boost");
1294 if (IS_ERR(boost_tasks[cpu])) {
1295 retval = PTR_ERR(boost_tasks[cpu]);
1296 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1297 n_rcu_torture_boost_ktrerror++;
1298 boost_tasks[cpu] = NULL;
1299 mutex_unlock(&boost_mutex);
1302 kthread_bind(boost_tasks[cpu], cpu);
1303 wake_up_process(boost_tasks[cpu]);
1304 mutex_unlock(&boost_mutex);
1308 static int rcutorture_cpu_notify(struct notifier_block *self,
1309 unsigned long action, void *hcpu)
1311 long cpu = (long)hcpu;
1315 case CPU_DOWN_FAILED:
1316 (void)rcutorture_booster_init(cpu);
1318 case CPU_DOWN_PREPARE:
1319 rcutorture_booster_cleanup(cpu);
1327 static struct notifier_block rcutorture_cpu_nb = {
1328 .notifier_call = rcutorture_cpu_notify,
1332 rcu_torture_cleanup(void)
1336 mutex_lock(&fullstop_mutex);
1337 rcutorture_record_test_transition();
1338 if (fullstop == FULLSTOP_SHUTDOWN) {
1339 printk(KERN_WARNING /* but going down anyway, so... */
1340 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
1341 mutex_unlock(&fullstop_mutex);
1342 schedule_timeout_uninterruptible(10);
1343 if (cur_ops->cb_barrier != NULL)
1344 cur_ops->cb_barrier();
1347 fullstop = FULLSTOP_RMMOD;
1348 mutex_unlock(&fullstop_mutex);
1349 unregister_reboot_notifier(&rcutorture_shutdown_nb);
1351 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1352 kthread_stop(stutter_task);
1354 stutter_task = NULL;
1355 if (shuffler_task) {
1356 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1357 kthread_stop(shuffler_task);
1358 free_cpumask_var(shuffle_tmp_mask);
1360 shuffler_task = NULL;
1363 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1364 kthread_stop(writer_task);
1369 for (i = 0; i < nrealreaders; i++) {
1370 if (reader_tasks[i]) {
1371 VERBOSE_PRINTK_STRING(
1372 "Stopping rcu_torture_reader task");
1373 kthread_stop(reader_tasks[i]);
1375 reader_tasks[i] = NULL;
1377 kfree(reader_tasks);
1378 reader_tasks = NULL;
1380 rcu_torture_current = NULL;
1382 if (fakewriter_tasks) {
1383 for (i = 0; i < nfakewriters; i++) {
1384 if (fakewriter_tasks[i]) {
1385 VERBOSE_PRINTK_STRING(
1386 "Stopping rcu_torture_fakewriter task");
1387 kthread_stop(fakewriter_tasks[i]);
1389 fakewriter_tasks[i] = NULL;
1391 kfree(fakewriter_tasks);
1392 fakewriter_tasks = NULL;
1396 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1397 kthread_stop(stats_task);
1402 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1403 kthread_stop(fqs_task);
1406 if ((test_boost == 1 && cur_ops->can_boost) ||
1408 unregister_cpu_notifier(&rcutorture_cpu_nb);
1409 for_each_possible_cpu(i)
1410 rcutorture_booster_cleanup(i);
1413 /* Wait for all RCU callbacks to fire. */
1415 if (cur_ops->cb_barrier != NULL)
1416 cur_ops->cb_barrier();
1418 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
1420 if (cur_ops->cleanup)
1422 if (atomic_read(&n_rcu_torture_error))
1423 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
1425 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
1429 rcu_torture_init(void)
1434 static struct rcu_torture_ops *torture_ops[] =
1435 { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
1436 &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops,
1437 &srcu_ops, &srcu_expedited_ops,
1438 &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
1440 mutex_lock(&fullstop_mutex);
1442 /* Process args and tell the world that the torturer is on the job. */
1443 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
1444 cur_ops = torture_ops[i];
1445 if (strcmp(torture_type, cur_ops->name) == 0)
1448 if (i == ARRAY_SIZE(torture_ops)) {
1449 printk(KERN_ALERT "rcu-torture: invalid torture type: \"%s\"\n",
1451 printk(KERN_ALERT "rcu-torture types:");
1452 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
1453 printk(KERN_ALERT " %s", torture_ops[i]->name);
1454 printk(KERN_ALERT "\n");
1455 mutex_unlock(&fullstop_mutex);
1458 if (cur_ops->fqs == NULL && fqs_duration != 0) {
1459 printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero "
1460 "fqs_duration, fqs disabled.\n");
1464 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1467 nrealreaders = nreaders;
1469 nrealreaders = 2 * num_online_cpus();
1470 rcu_torture_print_module_parms(cur_ops, "Start of test");
1471 fullstop = FULLSTOP_DONTSTOP;
1473 /* Set up the freelist. */
1475 INIT_LIST_HEAD(&rcu_torture_freelist);
1476 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
1477 rcu_tortures[i].rtort_mbtest = 0;
1478 list_add_tail(&rcu_tortures[i].rtort_free,
1479 &rcu_torture_freelist);
1482 /* Initialize the statistics so that each run gets its own numbers. */
1484 rcu_torture_current = NULL;
1485 rcu_torture_current_version = 0;
1486 atomic_set(&n_rcu_torture_alloc, 0);
1487 atomic_set(&n_rcu_torture_alloc_fail, 0);
1488 atomic_set(&n_rcu_torture_free, 0);
1489 atomic_set(&n_rcu_torture_mberror, 0);
1490 atomic_set(&n_rcu_torture_error, 0);
1491 n_rcu_torture_boost_ktrerror = 0;
1492 n_rcu_torture_boost_rterror = 0;
1493 n_rcu_torture_boost_failure = 0;
1494 n_rcu_torture_boosts = 0;
1495 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1496 atomic_set(&rcu_torture_wcount[i], 0);
1497 for_each_possible_cpu(cpu) {
1498 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1499 per_cpu(rcu_torture_count, cpu)[i] = 0;
1500 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1504 /* Start up the kthreads. */
1506 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1507 writer_task = kthread_run(rcu_torture_writer, NULL,
1508 "rcu_torture_writer");
1509 if (IS_ERR(writer_task)) {
1510 firsterr = PTR_ERR(writer_task);
1511 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1515 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
1517 if (fakewriter_tasks == NULL) {
1518 VERBOSE_PRINTK_ERRSTRING("out of memory");
1522 for (i = 0; i < nfakewriters; i++) {
1523 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
1524 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
1525 "rcu_torture_fakewriter");
1526 if (IS_ERR(fakewriter_tasks[i])) {
1527 firsterr = PTR_ERR(fakewriter_tasks[i]);
1528 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
1529 fakewriter_tasks[i] = NULL;
1533 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
1535 if (reader_tasks == NULL) {
1536 VERBOSE_PRINTK_ERRSTRING("out of memory");
1540 for (i = 0; i < nrealreaders; i++) {
1541 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
1542 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
1543 "rcu_torture_reader");
1544 if (IS_ERR(reader_tasks[i])) {
1545 firsterr = PTR_ERR(reader_tasks[i]);
1546 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
1547 reader_tasks[i] = NULL;
1551 if (stat_interval > 0) {
1552 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
1553 stats_task = kthread_run(rcu_torture_stats, NULL,
1554 "rcu_torture_stats");
1555 if (IS_ERR(stats_task)) {
1556 firsterr = PTR_ERR(stats_task);
1557 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
1562 if (test_no_idle_hz) {
1563 rcu_idle_cpu = num_online_cpus() - 1;
1565 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
1567 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
1571 /* Create the shuffler thread */
1572 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
1573 "rcu_torture_shuffle");
1574 if (IS_ERR(shuffler_task)) {
1575 free_cpumask_var(shuffle_tmp_mask);
1576 firsterr = PTR_ERR(shuffler_task);
1577 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
1578 shuffler_task = NULL;
1585 /* Create the stutter thread */
1586 stutter_task = kthread_run(rcu_torture_stutter, NULL,
1587 "rcu_torture_stutter");
1588 if (IS_ERR(stutter_task)) {
1589 firsterr = PTR_ERR(stutter_task);
1590 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
1591 stutter_task = NULL;
1595 if (fqs_duration < 0)
1598 /* Create the stutter thread */
1599 fqs_task = kthread_run(rcu_torture_fqs, NULL,
1601 if (IS_ERR(fqs_task)) {
1602 firsterr = PTR_ERR(fqs_task);
1603 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
1608 if (test_boost_interval < 1)
1609 test_boost_interval = 1;
1610 if (test_boost_duration < 2)
1611 test_boost_duration = 2;
1612 if ((test_boost == 1 && cur_ops->can_boost) ||
1616 boost_starttime = jiffies + test_boost_interval * HZ;
1617 register_cpu_notifier(&rcutorture_cpu_nb);
1618 for_each_possible_cpu(i) {
1619 if (cpu_is_offline(i))
1620 continue; /* Heuristic: CPU can go offline. */
1621 retval = rcutorture_booster_init(i);
1628 register_reboot_notifier(&rcutorture_shutdown_nb);
1629 rcutorture_record_test_transition();
1630 mutex_unlock(&fullstop_mutex);
1634 mutex_unlock(&fullstop_mutex);
1635 rcu_torture_cleanup();
1639 module_init(rcu_torture_init);
1640 module_exit(rcu_torture_cleanup);