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 <linux/trace_clock.h>
50 #include <asm/byteorder.h>
52 MODULE_LICENSE("GPL");
53 MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and 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 = 60; /* Interval between stats, in seconds. */
58 /* Zero means "only at end of test". */
59 static bool verbose; /* Print more debug info. */
60 static bool test_no_idle_hz = true;
61 /* Test RCU support for tickless idle CPUs. */
62 static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/
63 static int stutter = 5; /* Start/stop testing interval (in sec) */
64 static int irqreader = 1; /* RCU readers from irq (timers). */
65 static int fqs_duration; /* Duration of bursts (us), 0 to disable. */
66 static int fqs_holdoff; /* Hold time within burst (us). */
67 static int fqs_stutter = 3; /* Wait time between bursts (s). */
68 static int n_barrier_cbs; /* Number of callbacks to test RCU barriers. */
69 static int onoff_interval; /* Wait time between CPU hotplugs, 0=disable. */
70 static int onoff_holdoff; /* Seconds after boot before CPU hotplugs. */
71 static int shutdown_secs; /* Shutdown time (s). <=0 for no shutdown. */
72 static int stall_cpu; /* CPU-stall duration (s). 0 for no stall. */
73 static int stall_cpu_holdoff = 10; /* Time to wait until stall (s). */
74 static int test_boost = 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */
75 static int test_boost_interval = 7; /* Interval between boost tests, seconds. */
76 static int test_boost_duration = 4; /* Duration of each boost test, seconds. */
77 static char *torture_type = "rcu"; /* What RCU implementation to torture. */
79 module_param(nreaders, int, 0444);
80 MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
81 module_param(nfakewriters, int, 0444);
82 MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
83 module_param(stat_interval, int, 0644);
84 MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
85 module_param(verbose, bool, 0444);
86 MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
87 module_param(test_no_idle_hz, bool, 0444);
88 MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
89 module_param(shuffle_interval, int, 0444);
90 MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
91 module_param(stutter, int, 0444);
92 MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
93 module_param(irqreader, int, 0444);
94 MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
95 module_param(fqs_duration, int, 0444);
96 MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us)");
97 module_param(fqs_holdoff, int, 0444);
98 MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)");
99 module_param(fqs_stutter, int, 0444);
100 MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)");
101 module_param(n_barrier_cbs, int, 0444);
102 MODULE_PARM_DESC(n_barrier_cbs, "# of callbacks/kthreads for barrier testing");
103 module_param(onoff_interval, int, 0444);
104 MODULE_PARM_DESC(onoff_interval, "Time between CPU hotplugs (s), 0=disable");
105 module_param(onoff_holdoff, int, 0444);
106 MODULE_PARM_DESC(onoff_holdoff, "Time after boot before CPU hotplugs (s)");
107 module_param(shutdown_secs, int, 0444);
108 MODULE_PARM_DESC(shutdown_secs, "Shutdown time (s), zero to disable.");
109 module_param(stall_cpu, int, 0444);
110 MODULE_PARM_DESC(stall_cpu, "Stall duration (s), zero to disable.");
111 module_param(stall_cpu_holdoff, int, 0444);
112 MODULE_PARM_DESC(stall_cpu_holdoff, "Time to wait before starting stall (s).");
113 module_param(test_boost, int, 0444);
114 MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
115 module_param(test_boost_interval, int, 0444);
116 MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds.");
117 module_param(test_boost_duration, int, 0444);
118 MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds.");
119 module_param(torture_type, charp, 0444);
120 MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
122 #define TORTURE_FLAG "-torture:"
123 #define PRINTK_STRING(s) \
124 do { pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
125 #define VERBOSE_PRINTK_STRING(s) \
126 do { if (verbose) pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
127 #define VERBOSE_PRINTK_ERRSTRING(s) \
128 do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
130 static char printk_buf[4096];
132 static int nrealreaders;
133 static struct task_struct *writer_task;
134 static struct task_struct **fakewriter_tasks;
135 static struct task_struct **reader_tasks;
136 static struct task_struct *stats_task;
137 static struct task_struct *shuffler_task;
138 static struct task_struct *stutter_task;
139 static struct task_struct *fqs_task;
140 static struct task_struct *boost_tasks[NR_CPUS];
141 static struct task_struct *shutdown_task;
142 #ifdef CONFIG_HOTPLUG_CPU
143 static struct task_struct *onoff_task;
144 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
145 static struct task_struct *stall_task;
146 static struct task_struct **barrier_cbs_tasks;
147 static struct task_struct *barrier_task;
149 #define RCU_TORTURE_PIPE_LEN 10
152 struct rcu_head rtort_rcu;
153 int rtort_pipe_count;
154 struct list_head rtort_free;
158 static LIST_HEAD(rcu_torture_freelist);
159 static struct rcu_torture __rcu *rcu_torture_current;
160 static unsigned long rcu_torture_current_version;
161 static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
162 static DEFINE_SPINLOCK(rcu_torture_lock);
163 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
165 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
167 static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
168 static atomic_t n_rcu_torture_alloc;
169 static atomic_t n_rcu_torture_alloc_fail;
170 static atomic_t n_rcu_torture_free;
171 static atomic_t n_rcu_torture_mberror;
172 static atomic_t n_rcu_torture_error;
173 static long n_rcu_torture_barrier_error;
174 static long n_rcu_torture_boost_ktrerror;
175 static long n_rcu_torture_boost_rterror;
176 static long n_rcu_torture_boost_failure;
177 static long n_rcu_torture_boosts;
178 static long n_rcu_torture_timers;
179 static long n_offline_attempts;
180 static long n_offline_successes;
181 static unsigned long sum_offline;
182 static int min_offline = -1;
183 static int max_offline;
184 static long n_online_attempts;
185 static long n_online_successes;
186 static unsigned long sum_online;
187 static int min_online = -1;
188 static int max_online;
189 static long n_barrier_attempts;
190 static long n_barrier_successes;
191 static struct list_head rcu_torture_removed;
192 static cpumask_var_t shuffle_tmp_mask;
194 static int stutter_pause_test;
196 #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
197 #define RCUTORTURE_RUNNABLE_INIT 1
199 #define RCUTORTURE_RUNNABLE_INIT 0
201 int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
202 module_param(rcutorture_runnable, int, 0444);
203 MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot");
205 #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
206 #define rcu_can_boost() 1
207 #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
208 #define rcu_can_boost() 0
209 #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
211 static unsigned long shutdown_time; /* jiffies to system shutdown. */
212 static unsigned long boost_starttime; /* jiffies of next boost test start. */
213 DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
214 /* and boost task create/destroy. */
215 static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */
216 static bool barrier_phase; /* Test phase. */
217 static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */
218 static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */
219 static DECLARE_WAIT_QUEUE_HEAD(barrier_wq);
221 /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
223 #define FULLSTOP_DONTSTOP 0 /* Normal operation. */
224 #define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
225 #define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
226 static int fullstop = FULLSTOP_RMMOD;
228 * Protect fullstop transitions and spawning of kthreads.
230 static DEFINE_MUTEX(fullstop_mutex);
232 /* Forward reference. */
233 static void rcu_torture_cleanup(void);
236 * Detect and respond to a system shutdown.
239 rcutorture_shutdown_notify(struct notifier_block *unused1,
240 unsigned long unused2, void *unused3)
242 mutex_lock(&fullstop_mutex);
243 if (fullstop == FULLSTOP_DONTSTOP)
244 fullstop = FULLSTOP_SHUTDOWN;
246 pr_warn(/* but going down anyway, so... */
247 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
248 mutex_unlock(&fullstop_mutex);
253 * Absorb kthreads into a kernel function that won't return, so that
254 * they won't ever access module text or data again.
256 static void rcutorture_shutdown_absorb(char *title)
258 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
260 "rcutorture thread %s parking due to system shutdown\n",
262 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
267 * Allocate an element from the rcu_tortures pool.
269 static struct rcu_torture *
270 rcu_torture_alloc(void)
274 spin_lock_bh(&rcu_torture_lock);
275 if (list_empty(&rcu_torture_freelist)) {
276 atomic_inc(&n_rcu_torture_alloc_fail);
277 spin_unlock_bh(&rcu_torture_lock);
280 atomic_inc(&n_rcu_torture_alloc);
281 p = rcu_torture_freelist.next;
283 spin_unlock_bh(&rcu_torture_lock);
284 return container_of(p, struct rcu_torture, rtort_free);
288 * Free an element to the rcu_tortures pool.
291 rcu_torture_free(struct rcu_torture *p)
293 atomic_inc(&n_rcu_torture_free);
294 spin_lock_bh(&rcu_torture_lock);
295 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
296 spin_unlock_bh(&rcu_torture_lock);
299 struct rcu_random_state {
300 unsigned long rrs_state;
304 #define RCU_RANDOM_MULT 39916801 /* prime */
305 #define RCU_RANDOM_ADD 479001701 /* prime */
306 #define RCU_RANDOM_REFRESH 10000
308 #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
311 * Crude but fast random-number generator. Uses a linear congruential
312 * generator, with occasional help from cpu_clock().
315 rcu_random(struct rcu_random_state *rrsp)
317 if (--rrsp->rrs_count < 0) {
318 rrsp->rrs_state += (unsigned long)local_clock();
319 rrsp->rrs_count = RCU_RANDOM_REFRESH;
321 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
322 return swahw32(rrsp->rrs_state);
326 rcu_stutter_wait(char *title)
328 while (stutter_pause_test || !rcutorture_runnable) {
329 if (rcutorture_runnable)
330 schedule_timeout_interruptible(1);
332 schedule_timeout_interruptible(round_jiffies_relative(HZ));
333 rcutorture_shutdown_absorb(title);
338 * Operations vector for selecting different types of tests.
341 struct rcu_torture_ops {
343 int (*readlock)(void);
344 void (*read_delay)(struct rcu_random_state *rrsp);
345 void (*readunlock)(int idx);
346 int (*completed)(void);
347 void (*deferred_free)(struct rcu_torture *p);
349 void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu));
350 void (*cb_barrier)(void);
352 int (*stats)(char *page);
358 static struct rcu_torture_ops *cur_ops;
361 * Definitions for rcu torture testing.
364 static int rcu_torture_read_lock(void) __acquires(RCU)
370 static void rcu_read_delay(struct rcu_random_state *rrsp)
372 const unsigned long shortdelay_us = 200;
373 const unsigned long longdelay_ms = 50;
375 /* We want a short delay sometimes to make a reader delay the grace
376 * period, and we want a long delay occasionally to trigger
377 * force_quiescent_state. */
379 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
380 mdelay(longdelay_ms);
381 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
382 udelay(shortdelay_us);
383 #ifdef CONFIG_PREEMPT
384 if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000)))
385 preempt_schedule(); /* No QS if preempt_disable() in effect */
389 static void rcu_torture_read_unlock(int idx) __releases(RCU)
394 static int rcu_torture_completed(void)
396 return rcu_batches_completed();
400 rcu_torture_cb(struct rcu_head *p)
403 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
405 if (fullstop != FULLSTOP_DONTSTOP) {
406 /* Test is ending, just drop callbacks on the floor. */
407 /* The next initialization will pick up the pieces. */
410 i = rp->rtort_pipe_count;
411 if (i > RCU_TORTURE_PIPE_LEN)
412 i = RCU_TORTURE_PIPE_LEN;
413 atomic_inc(&rcu_torture_wcount[i]);
414 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
415 rp->rtort_mbtest = 0;
416 rcu_torture_free(rp);
418 cur_ops->deferred_free(rp);
422 static int rcu_no_completed(void)
427 static void rcu_torture_deferred_free(struct rcu_torture *p)
429 call_rcu(&p->rtort_rcu, rcu_torture_cb);
432 static struct rcu_torture_ops rcu_ops = {
434 .readlock = rcu_torture_read_lock,
435 .read_delay = rcu_read_delay,
436 .readunlock = rcu_torture_read_unlock,
437 .completed = rcu_torture_completed,
438 .deferred_free = rcu_torture_deferred_free,
439 .sync = synchronize_rcu,
441 .cb_barrier = rcu_barrier,
442 .fqs = rcu_force_quiescent_state,
445 .can_boost = rcu_can_boost(),
449 static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
452 struct rcu_torture *rp;
453 struct rcu_torture *rp1;
456 list_add(&p->rtort_free, &rcu_torture_removed);
457 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
458 i = rp->rtort_pipe_count;
459 if (i > RCU_TORTURE_PIPE_LEN)
460 i = RCU_TORTURE_PIPE_LEN;
461 atomic_inc(&rcu_torture_wcount[i]);
462 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
463 rp->rtort_mbtest = 0;
464 list_del(&rp->rtort_free);
465 rcu_torture_free(rp);
470 static void rcu_sync_torture_init(void)
472 INIT_LIST_HEAD(&rcu_torture_removed);
475 static struct rcu_torture_ops rcu_sync_ops = {
476 .init = rcu_sync_torture_init,
477 .readlock = rcu_torture_read_lock,
478 .read_delay = rcu_read_delay,
479 .readunlock = rcu_torture_read_unlock,
480 .completed = rcu_torture_completed,
481 .deferred_free = rcu_sync_torture_deferred_free,
482 .sync = synchronize_rcu,
485 .fqs = rcu_force_quiescent_state,
488 .can_boost = rcu_can_boost(),
492 static struct rcu_torture_ops rcu_expedited_ops = {
493 .init = rcu_sync_torture_init,
494 .readlock = rcu_torture_read_lock,
495 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
496 .readunlock = rcu_torture_read_unlock,
497 .completed = rcu_no_completed,
498 .deferred_free = rcu_sync_torture_deferred_free,
499 .sync = synchronize_rcu_expedited,
502 .fqs = rcu_force_quiescent_state,
505 .can_boost = rcu_can_boost(),
506 .name = "rcu_expedited"
510 * Definitions for rcu_bh torture testing.
513 static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
519 static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
521 rcu_read_unlock_bh();
524 static int rcu_bh_torture_completed(void)
526 return rcu_batches_completed_bh();
529 static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
531 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
534 static struct rcu_torture_ops rcu_bh_ops = {
536 .readlock = rcu_bh_torture_read_lock,
537 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
538 .readunlock = rcu_bh_torture_read_unlock,
539 .completed = rcu_bh_torture_completed,
540 .deferred_free = rcu_bh_torture_deferred_free,
541 .sync = synchronize_rcu_bh,
543 .cb_barrier = rcu_barrier_bh,
544 .fqs = rcu_bh_force_quiescent_state,
550 static struct rcu_torture_ops rcu_bh_sync_ops = {
551 .init = rcu_sync_torture_init,
552 .readlock = rcu_bh_torture_read_lock,
553 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
554 .readunlock = rcu_bh_torture_read_unlock,
555 .completed = rcu_bh_torture_completed,
556 .deferred_free = rcu_sync_torture_deferred_free,
557 .sync = synchronize_rcu_bh,
560 .fqs = rcu_bh_force_quiescent_state,
563 .name = "rcu_bh_sync"
566 static struct rcu_torture_ops rcu_bh_expedited_ops = {
567 .init = rcu_sync_torture_init,
568 .readlock = rcu_bh_torture_read_lock,
569 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
570 .readunlock = rcu_bh_torture_read_unlock,
571 .completed = rcu_bh_torture_completed,
572 .deferred_free = rcu_sync_torture_deferred_free,
573 .sync = synchronize_rcu_bh_expedited,
576 .fqs = rcu_bh_force_quiescent_state,
579 .name = "rcu_bh_expedited"
583 * Definitions for srcu torture testing.
586 DEFINE_STATIC_SRCU(srcu_ctl);
588 static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
590 return srcu_read_lock(&srcu_ctl);
593 static void srcu_read_delay(struct rcu_random_state *rrsp)
596 const long uspertick = 1000000 / HZ;
597 const long longdelay = 10;
599 /* We want there to be long-running readers, but not all the time. */
601 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
603 schedule_timeout_interruptible(longdelay);
605 rcu_read_delay(rrsp);
608 static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
610 srcu_read_unlock(&srcu_ctl, idx);
613 static int srcu_torture_completed(void)
615 return srcu_batches_completed(&srcu_ctl);
618 static void srcu_torture_deferred_free(struct rcu_torture *rp)
620 call_srcu(&srcu_ctl, &rp->rtort_rcu, rcu_torture_cb);
623 static void srcu_torture_synchronize(void)
625 synchronize_srcu(&srcu_ctl);
628 static void srcu_torture_call(struct rcu_head *head,
629 void (*func)(struct rcu_head *head))
631 call_srcu(&srcu_ctl, head, func);
634 static void srcu_torture_barrier(void)
636 srcu_barrier(&srcu_ctl);
639 static int srcu_torture_stats(char *page)
643 int idx = srcu_ctl.completed & 0x1;
645 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
646 torture_type, TORTURE_FLAG, idx);
647 for_each_possible_cpu(cpu) {
648 cnt += sprintf(&page[cnt], " %d(%lu,%lu)", cpu,
649 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
650 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
652 cnt += sprintf(&page[cnt], "\n");
656 static struct rcu_torture_ops srcu_ops = {
657 .init = rcu_sync_torture_init,
658 .readlock = srcu_torture_read_lock,
659 .read_delay = srcu_read_delay,
660 .readunlock = srcu_torture_read_unlock,
661 .completed = srcu_torture_completed,
662 .deferred_free = srcu_torture_deferred_free,
663 .sync = srcu_torture_synchronize,
664 .call = srcu_torture_call,
665 .cb_barrier = srcu_torture_barrier,
666 .stats = srcu_torture_stats,
670 static struct rcu_torture_ops srcu_sync_ops = {
671 .init = rcu_sync_torture_init,
672 .readlock = srcu_torture_read_lock,
673 .read_delay = srcu_read_delay,
674 .readunlock = srcu_torture_read_unlock,
675 .completed = srcu_torture_completed,
676 .deferred_free = rcu_sync_torture_deferred_free,
677 .sync = srcu_torture_synchronize,
680 .stats = srcu_torture_stats,
684 static int srcu_torture_read_lock_raw(void) __acquires(&srcu_ctl)
686 return srcu_read_lock_raw(&srcu_ctl);
689 static void srcu_torture_read_unlock_raw(int idx) __releases(&srcu_ctl)
691 srcu_read_unlock_raw(&srcu_ctl, idx);
694 static struct rcu_torture_ops srcu_raw_ops = {
695 .init = rcu_sync_torture_init,
696 .readlock = srcu_torture_read_lock_raw,
697 .read_delay = srcu_read_delay,
698 .readunlock = srcu_torture_read_unlock_raw,
699 .completed = srcu_torture_completed,
700 .deferred_free = srcu_torture_deferred_free,
701 .sync = srcu_torture_synchronize,
704 .stats = srcu_torture_stats,
708 static struct rcu_torture_ops srcu_raw_sync_ops = {
709 .init = rcu_sync_torture_init,
710 .readlock = srcu_torture_read_lock_raw,
711 .read_delay = srcu_read_delay,
712 .readunlock = srcu_torture_read_unlock_raw,
713 .completed = srcu_torture_completed,
714 .deferred_free = rcu_sync_torture_deferred_free,
715 .sync = srcu_torture_synchronize,
718 .stats = srcu_torture_stats,
719 .name = "srcu_raw_sync"
722 static void srcu_torture_synchronize_expedited(void)
724 synchronize_srcu_expedited(&srcu_ctl);
727 static struct rcu_torture_ops srcu_expedited_ops = {
728 .init = rcu_sync_torture_init,
729 .readlock = srcu_torture_read_lock,
730 .read_delay = srcu_read_delay,
731 .readunlock = srcu_torture_read_unlock,
732 .completed = srcu_torture_completed,
733 .deferred_free = rcu_sync_torture_deferred_free,
734 .sync = srcu_torture_synchronize_expedited,
737 .stats = srcu_torture_stats,
738 .name = "srcu_expedited"
742 * Definitions for sched torture testing.
745 static int sched_torture_read_lock(void)
751 static void sched_torture_read_unlock(int idx)
756 static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
758 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
761 static struct rcu_torture_ops sched_ops = {
762 .init = rcu_sync_torture_init,
763 .readlock = sched_torture_read_lock,
764 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
765 .readunlock = sched_torture_read_unlock,
766 .completed = rcu_no_completed,
767 .deferred_free = rcu_sched_torture_deferred_free,
768 .sync = synchronize_sched,
769 .cb_barrier = rcu_barrier_sched,
770 .fqs = rcu_sched_force_quiescent_state,
776 static struct rcu_torture_ops sched_sync_ops = {
777 .init = rcu_sync_torture_init,
778 .readlock = sched_torture_read_lock,
779 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
780 .readunlock = sched_torture_read_unlock,
781 .completed = rcu_no_completed,
782 .deferred_free = rcu_sync_torture_deferred_free,
783 .sync = synchronize_sched,
785 .fqs = rcu_sched_force_quiescent_state,
790 static struct rcu_torture_ops sched_expedited_ops = {
791 .init = rcu_sync_torture_init,
792 .readlock = sched_torture_read_lock,
793 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
794 .readunlock = sched_torture_read_unlock,
795 .completed = rcu_no_completed,
796 .deferred_free = rcu_sync_torture_deferred_free,
797 .sync = synchronize_sched_expedited,
799 .fqs = rcu_sched_force_quiescent_state,
802 .name = "sched_expedited"
806 * RCU torture priority-boost testing. Runs one real-time thread per
807 * CPU for moderate bursts, repeatedly registering RCU callbacks and
808 * spinning waiting for them to be invoked. If a given callback takes
809 * too long to be invoked, we assume that priority inversion has occurred.
812 struct rcu_boost_inflight {
817 static void rcu_torture_boost_cb(struct rcu_head *head)
819 struct rcu_boost_inflight *rbip =
820 container_of(head, struct rcu_boost_inflight, rcu);
822 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
826 static int rcu_torture_boost(void *arg)
828 unsigned long call_rcu_time;
829 unsigned long endtime;
830 unsigned long oldstarttime;
831 struct rcu_boost_inflight rbi = { .inflight = 0 };
832 struct sched_param sp;
834 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
836 /* Set real-time priority. */
837 sp.sched_priority = 1;
838 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
839 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
840 n_rcu_torture_boost_rterror++;
843 init_rcu_head_on_stack(&rbi.rcu);
844 /* Each pass through the following loop does one boost-test cycle. */
846 /* Wait for the next test interval. */
847 oldstarttime = boost_starttime;
848 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
849 schedule_timeout_uninterruptible(1);
850 rcu_stutter_wait("rcu_torture_boost");
851 if (kthread_should_stop() ||
852 fullstop != FULLSTOP_DONTSTOP)
856 /* Do one boost-test interval. */
857 endtime = oldstarttime + test_boost_duration * HZ;
858 call_rcu_time = jiffies;
859 while (ULONG_CMP_LT(jiffies, endtime)) {
860 /* If we don't have a callback in flight, post one. */
862 smp_mb(); /* RCU core before ->inflight = 1. */
864 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
865 if (jiffies - call_rcu_time >
866 test_boost_duration * HZ - HZ / 2) {
867 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
868 n_rcu_torture_boost_failure++;
870 call_rcu_time = jiffies;
873 rcu_stutter_wait("rcu_torture_boost");
874 if (kthread_should_stop() ||
875 fullstop != FULLSTOP_DONTSTOP)
880 * Set the start time of the next test interval.
881 * Yes, this is vulnerable to long delays, but such
882 * delays simply cause a false negative for the next
883 * interval. Besides, we are running at RT priority,
884 * so delays should be relatively rare.
886 while (oldstarttime == boost_starttime &&
887 !kthread_should_stop()) {
888 if (mutex_trylock(&boost_mutex)) {
889 boost_starttime = jiffies +
890 test_boost_interval * HZ;
891 n_rcu_torture_boosts++;
892 mutex_unlock(&boost_mutex);
895 schedule_timeout_uninterruptible(1);
898 /* Go do the stutter. */
899 checkwait: rcu_stutter_wait("rcu_torture_boost");
900 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
902 /* Clean up and exit. */
903 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
904 rcutorture_shutdown_absorb("rcu_torture_boost");
905 while (!kthread_should_stop() || rbi.inflight)
906 schedule_timeout_uninterruptible(1);
907 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
908 destroy_rcu_head_on_stack(&rbi.rcu);
913 * RCU torture force-quiescent-state kthread. Repeatedly induces
914 * bursts of calls to force_quiescent_state(), increasing the probability
915 * of occurrence of some important types of race conditions.
918 rcu_torture_fqs(void *arg)
920 unsigned long fqs_resume_time;
921 int fqs_burst_remaining;
923 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
925 fqs_resume_time = jiffies + fqs_stutter * HZ;
926 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
927 !kthread_should_stop()) {
928 schedule_timeout_interruptible(1);
930 fqs_burst_remaining = fqs_duration;
931 while (fqs_burst_remaining > 0 &&
932 !kthread_should_stop()) {
935 fqs_burst_remaining -= fqs_holdoff;
937 rcu_stutter_wait("rcu_torture_fqs");
938 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
939 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
940 rcutorture_shutdown_absorb("rcu_torture_fqs");
941 while (!kthread_should_stop())
942 schedule_timeout_uninterruptible(1);
947 * RCU torture writer kthread. Repeatedly substitutes a new structure
948 * for that pointed to by rcu_torture_current, freeing the old structure
949 * after a series of grace periods (the "pipeline").
952 rcu_torture_writer(void *arg)
955 long oldbatch = rcu_batches_completed();
956 struct rcu_torture *rp;
957 struct rcu_torture *old_rp;
958 static DEFINE_RCU_RANDOM(rand);
960 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
961 set_user_nice(current, 19);
964 schedule_timeout_uninterruptible(1);
965 rp = rcu_torture_alloc();
968 rp->rtort_pipe_count = 0;
969 udelay(rcu_random(&rand) & 0x3ff);
970 old_rp = rcu_dereference_check(rcu_torture_current,
971 current == writer_task);
972 rp->rtort_mbtest = 1;
973 rcu_assign_pointer(rcu_torture_current, rp);
974 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
976 i = old_rp->rtort_pipe_count;
977 if (i > RCU_TORTURE_PIPE_LEN)
978 i = RCU_TORTURE_PIPE_LEN;
979 atomic_inc(&rcu_torture_wcount[i]);
980 old_rp->rtort_pipe_count++;
981 cur_ops->deferred_free(old_rp);
983 rcutorture_record_progress(++rcu_torture_current_version);
984 oldbatch = cur_ops->completed();
985 rcu_stutter_wait("rcu_torture_writer");
986 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
987 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
988 rcutorture_shutdown_absorb("rcu_torture_writer");
989 while (!kthread_should_stop())
990 schedule_timeout_uninterruptible(1);
995 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
996 * delay between calls.
999 rcu_torture_fakewriter(void *arg)
1001 DEFINE_RCU_RANDOM(rand);
1003 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
1004 set_user_nice(current, 19);
1007 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
1008 udelay(rcu_random(&rand) & 0x3ff);
1009 if (cur_ops->cb_barrier != NULL &&
1010 rcu_random(&rand) % (nfakewriters * 8) == 0)
1011 cur_ops->cb_barrier();
1014 rcu_stutter_wait("rcu_torture_fakewriter");
1015 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1017 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
1018 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
1019 while (!kthread_should_stop())
1020 schedule_timeout_uninterruptible(1);
1024 void rcutorture_trace_dump(void)
1026 static atomic_t beenhere = ATOMIC_INIT(0);
1028 if (atomic_read(&beenhere))
1030 if (atomic_xchg(&beenhere, 1) != 0)
1032 ftrace_dump(DUMP_ALL);
1036 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
1037 * incrementing the corresponding element of the pipeline array. The
1038 * counter in the element should never be greater than 1, otherwise, the
1039 * RCU implementation is broken.
1041 static void rcu_torture_timer(unsigned long unused)
1046 static DEFINE_RCU_RANDOM(rand);
1047 static DEFINE_SPINLOCK(rand_lock);
1048 struct rcu_torture *p;
1050 unsigned long long ts;
1052 idx = cur_ops->readlock();
1053 completed = cur_ops->completed();
1054 ts = trace_clock_local();
1055 p = rcu_dereference_check(rcu_torture_current,
1056 rcu_read_lock_bh_held() ||
1057 rcu_read_lock_sched_held() ||
1058 srcu_read_lock_held(&srcu_ctl));
1060 /* Leave because rcu_torture_writer is not yet underway */
1061 cur_ops->readunlock(idx);
1064 if (p->rtort_mbtest == 0)
1065 atomic_inc(&n_rcu_torture_mberror);
1066 spin_lock(&rand_lock);
1067 cur_ops->read_delay(&rand);
1068 n_rcu_torture_timers++;
1069 spin_unlock(&rand_lock);
1071 pipe_count = p->rtort_pipe_count;
1072 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1073 /* Should not happen, but... */
1074 pipe_count = RCU_TORTURE_PIPE_LEN;
1076 completed_end = cur_ops->completed();
1077 if (pipe_count > 1) {
1078 unsigned long __maybe_unused ts_rem = do_div(ts, NSEC_PER_USEC);
1080 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, ts,
1081 completed, completed_end);
1082 rcutorture_trace_dump();
1084 __this_cpu_inc(rcu_torture_count[pipe_count]);
1085 completed = completed_end - completed;
1086 if (completed > RCU_TORTURE_PIPE_LEN) {
1087 /* Should not happen, but... */
1088 completed = RCU_TORTURE_PIPE_LEN;
1090 __this_cpu_inc(rcu_torture_batch[completed]);
1092 cur_ops->readunlock(idx);
1096 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
1097 * incrementing the corresponding element of the pipeline array. The
1098 * counter in the element should never be greater than 1, otherwise, the
1099 * RCU implementation is broken.
1102 rcu_torture_reader(void *arg)
1107 DEFINE_RCU_RANDOM(rand);
1108 struct rcu_torture *p;
1110 struct timer_list t;
1111 unsigned long long ts;
1113 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
1114 set_user_nice(current, 19);
1115 if (irqreader && cur_ops->irq_capable)
1116 setup_timer_on_stack(&t, rcu_torture_timer, 0);
1119 if (irqreader && cur_ops->irq_capable) {
1120 if (!timer_pending(&t))
1121 mod_timer(&t, jiffies + 1);
1123 idx = cur_ops->readlock();
1124 completed = cur_ops->completed();
1125 ts = trace_clock_local();
1126 p = rcu_dereference_check(rcu_torture_current,
1127 rcu_read_lock_bh_held() ||
1128 rcu_read_lock_sched_held() ||
1129 srcu_read_lock_held(&srcu_ctl));
1131 /* Wait for rcu_torture_writer to get underway */
1132 cur_ops->readunlock(idx);
1133 schedule_timeout_interruptible(HZ);
1136 if (p->rtort_mbtest == 0)
1137 atomic_inc(&n_rcu_torture_mberror);
1138 cur_ops->read_delay(&rand);
1140 pipe_count = p->rtort_pipe_count;
1141 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1142 /* Should not happen, but... */
1143 pipe_count = RCU_TORTURE_PIPE_LEN;
1145 completed_end = cur_ops->completed();
1146 if (pipe_count > 1) {
1147 unsigned long __maybe_unused ts_rem =
1148 do_div(ts, NSEC_PER_USEC);
1150 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu,
1151 ts, completed, completed_end);
1152 rcutorture_trace_dump();
1154 __this_cpu_inc(rcu_torture_count[pipe_count]);
1155 completed = completed_end - completed;
1156 if (completed > RCU_TORTURE_PIPE_LEN) {
1157 /* Should not happen, but... */
1158 completed = RCU_TORTURE_PIPE_LEN;
1160 __this_cpu_inc(rcu_torture_batch[completed]);
1162 cur_ops->readunlock(idx);
1164 rcu_stutter_wait("rcu_torture_reader");
1165 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1166 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
1167 rcutorture_shutdown_absorb("rcu_torture_reader");
1168 if (irqreader && cur_ops->irq_capable)
1170 while (!kthread_should_stop())
1171 schedule_timeout_uninterruptible(1);
1176 * Create an RCU-torture statistics message in the specified buffer.
1179 rcu_torture_printk(char *page)
1184 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1185 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1187 for_each_possible_cpu(cpu) {
1188 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1189 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1190 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1193 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1194 if (pipesummary[i] != 0)
1197 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
1198 cnt += sprintf(&page[cnt],
1199 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
1200 rcu_torture_current,
1201 rcu_torture_current_version,
1202 list_empty(&rcu_torture_freelist),
1203 atomic_read(&n_rcu_torture_alloc),
1204 atomic_read(&n_rcu_torture_alloc_fail),
1205 atomic_read(&n_rcu_torture_free));
1206 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
1207 atomic_read(&n_rcu_torture_mberror),
1208 n_rcu_torture_boost_ktrerror,
1209 n_rcu_torture_boost_rterror);
1210 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
1211 n_rcu_torture_boost_failure,
1212 n_rcu_torture_boosts,
1213 n_rcu_torture_timers);
1214 cnt += sprintf(&page[cnt],
1215 "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ",
1216 n_online_successes, n_online_attempts,
1217 n_offline_successes, n_offline_attempts,
1218 min_online, max_online,
1219 min_offline, max_offline,
1220 sum_online, sum_offline, HZ);
1221 cnt += sprintf(&page[cnt], "barrier: %ld/%ld:%ld",
1222 n_barrier_successes,
1224 n_rcu_torture_barrier_error);
1225 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
1226 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
1227 n_rcu_torture_barrier_error != 0 ||
1228 n_rcu_torture_boost_ktrerror != 0 ||
1229 n_rcu_torture_boost_rterror != 0 ||
1230 n_rcu_torture_boost_failure != 0 ||
1232 cnt += sprintf(&page[cnt], "!!! ");
1233 atomic_inc(&n_rcu_torture_error);
1236 cnt += sprintf(&page[cnt], "Reader Pipe: ");
1237 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1238 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
1239 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
1240 cnt += sprintf(&page[cnt], "Reader Batch: ");
1241 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1242 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
1243 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
1244 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
1245 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1246 cnt += sprintf(&page[cnt], " %d",
1247 atomic_read(&rcu_torture_wcount[i]));
1249 cnt += sprintf(&page[cnt], "\n");
1251 cnt += cur_ops->stats(&page[cnt]);
1256 * Print torture statistics. Caller must ensure that there is only
1257 * one call to this function at a given time!!! This is normally
1258 * accomplished by relying on the module system to only have one copy
1259 * of the module loaded, and then by giving the rcu_torture_stats
1260 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1261 * thread is not running).
1264 rcu_torture_stats_print(void)
1268 cnt = rcu_torture_printk(printk_buf);
1269 pr_alert("%s", printk_buf);
1273 * Periodically prints torture statistics, if periodic statistics printing
1274 * was specified via the stat_interval module parameter.
1276 * No need to worry about fullstop here, since this one doesn't reference
1277 * volatile state or register callbacks.
1280 rcu_torture_stats(void *arg)
1282 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1284 schedule_timeout_interruptible(stat_interval * HZ);
1285 rcu_torture_stats_print();
1286 rcutorture_shutdown_absorb("rcu_torture_stats");
1287 } while (!kthread_should_stop());
1288 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1292 static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
1294 /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1295 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1297 static void rcu_torture_shuffle_tasks(void)
1301 cpumask_setall(shuffle_tmp_mask);
1304 /* No point in shuffling if there is only one online CPU (ex: UP) */
1305 if (num_online_cpus() == 1) {
1310 if (rcu_idle_cpu != -1)
1311 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
1313 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
1316 for (i = 0; i < nrealreaders; i++)
1317 if (reader_tasks[i])
1318 set_cpus_allowed_ptr(reader_tasks[i],
1322 if (fakewriter_tasks) {
1323 for (i = 0; i < nfakewriters; i++)
1324 if (fakewriter_tasks[i])
1325 set_cpus_allowed_ptr(fakewriter_tasks[i],
1330 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
1333 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
1335 if (rcu_idle_cpu == -1)
1336 rcu_idle_cpu = num_online_cpus() - 1;
1343 /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1344 * system to become idle at a time and cut off its timer ticks. This is meant
1345 * to test the support for such tickless idle CPU in RCU.
1348 rcu_torture_shuffle(void *arg)
1350 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1352 schedule_timeout_interruptible(shuffle_interval * HZ);
1353 rcu_torture_shuffle_tasks();
1354 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1355 } while (!kthread_should_stop());
1356 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1360 /* Cause the rcutorture test to "stutter", starting and stopping all
1361 * threads periodically.
1364 rcu_torture_stutter(void *arg)
1366 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1368 schedule_timeout_interruptible(stutter * HZ);
1369 stutter_pause_test = 1;
1370 if (!kthread_should_stop())
1371 schedule_timeout_interruptible(stutter * HZ);
1372 stutter_pause_test = 0;
1373 rcutorture_shutdown_absorb("rcu_torture_stutter");
1374 } while (!kthread_should_stop());
1375 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1380 rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
1382 pr_alert("%s" TORTURE_FLAG
1383 "--- %s: nreaders=%d nfakewriters=%d "
1384 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1385 "shuffle_interval=%d stutter=%d irqreader=%d "
1386 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1387 "test_boost=%d/%d test_boost_interval=%d "
1388 "test_boost_duration=%d shutdown_secs=%d "
1389 "stall_cpu=%d stall_cpu_holdoff=%d "
1391 "onoff_interval=%d onoff_holdoff=%d\n",
1392 torture_type, tag, nrealreaders, nfakewriters,
1393 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
1394 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1395 test_boost, cur_ops->can_boost,
1396 test_boost_interval, test_boost_duration, shutdown_secs,
1397 stall_cpu, stall_cpu_holdoff,
1399 onoff_interval, onoff_holdoff);
1402 static struct notifier_block rcutorture_shutdown_nb = {
1403 .notifier_call = rcutorture_shutdown_notify,
1406 static void rcutorture_booster_cleanup(int cpu)
1408 struct task_struct *t;
1410 if (boost_tasks[cpu] == NULL)
1412 mutex_lock(&boost_mutex);
1413 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1414 t = boost_tasks[cpu];
1415 boost_tasks[cpu] = NULL;
1416 mutex_unlock(&boost_mutex);
1418 /* This must be outside of the mutex, otherwise deadlock! */
1420 boost_tasks[cpu] = NULL;
1423 static int rcutorture_booster_init(int cpu)
1427 if (boost_tasks[cpu] != NULL)
1428 return 0; /* Already created, nothing more to do. */
1430 /* Don't allow time recalculation while creating a new task. */
1431 mutex_lock(&boost_mutex);
1432 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
1433 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1435 "rcu_torture_boost");
1436 if (IS_ERR(boost_tasks[cpu])) {
1437 retval = PTR_ERR(boost_tasks[cpu]);
1438 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1439 n_rcu_torture_boost_ktrerror++;
1440 boost_tasks[cpu] = NULL;
1441 mutex_unlock(&boost_mutex);
1444 kthread_bind(boost_tasks[cpu], cpu);
1445 wake_up_process(boost_tasks[cpu]);
1446 mutex_unlock(&boost_mutex);
1451 * Cause the rcutorture test to shutdown the system after the test has
1452 * run for the time specified by the shutdown_secs module parameter.
1455 rcu_torture_shutdown(void *arg)
1458 unsigned long jiffies_snap;
1460 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1461 jiffies_snap = ACCESS_ONCE(jiffies);
1462 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
1463 !kthread_should_stop()) {
1464 delta = shutdown_time - jiffies_snap;
1466 pr_alert("%s" TORTURE_FLAG
1467 "rcu_torture_shutdown task: %lu jiffies remaining\n",
1468 torture_type, delta);
1469 schedule_timeout_interruptible(delta);
1470 jiffies_snap = ACCESS_ONCE(jiffies);
1472 if (kthread_should_stop()) {
1473 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1477 /* OK, shut down the system. */
1479 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1480 shutdown_task = NULL; /* Avoid self-kill deadlock. */
1481 rcu_torture_cleanup(); /* Get the success/failure message. */
1482 kernel_power_off(); /* Shut down the system. */
1486 #ifdef CONFIG_HOTPLUG_CPU
1489 * Execute random CPU-hotplug operations at the interval specified
1490 * by the onoff_interval.
1492 static int __cpuinit
1493 rcu_torture_onoff(void *arg)
1496 unsigned long delta;
1498 DEFINE_RCU_RANDOM(rand);
1500 unsigned long starttime;
1502 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1503 for_each_online_cpu(cpu)
1505 WARN_ON(maxcpu < 0);
1506 if (onoff_holdoff > 0) {
1507 VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff");
1508 schedule_timeout_interruptible(onoff_holdoff * HZ);
1509 VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff");
1511 while (!kthread_should_stop()) {
1512 cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
1513 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) {
1515 pr_alert("%s" TORTURE_FLAG
1516 "rcu_torture_onoff task: offlining %d\n",
1518 starttime = jiffies;
1519 n_offline_attempts++;
1520 ret = cpu_down(cpu);
1523 pr_alert("%s" TORTURE_FLAG
1524 "rcu_torture_onoff task: offline %d failed: errno %d\n",
1525 torture_type, cpu, ret);
1528 pr_alert("%s" TORTURE_FLAG
1529 "rcu_torture_onoff task: offlined %d\n",
1531 n_offline_successes++;
1532 delta = jiffies - starttime;
1533 sum_offline += delta;
1534 if (min_offline < 0) {
1535 min_offline = delta;
1536 max_offline = delta;
1538 if (min_offline > delta)
1539 min_offline = delta;
1540 if (max_offline < delta)
1541 max_offline = delta;
1543 } else if (cpu_is_hotpluggable(cpu)) {
1545 pr_alert("%s" TORTURE_FLAG
1546 "rcu_torture_onoff task: onlining %d\n",
1548 starttime = jiffies;
1549 n_online_attempts++;
1550 if (cpu_up(cpu) == 0) {
1552 pr_alert("%s" TORTURE_FLAG
1553 "rcu_torture_onoff task: onlined %d\n",
1555 n_online_successes++;
1556 delta = jiffies - starttime;
1557 sum_online += delta;
1558 if (min_online < 0) {
1562 if (min_online > delta)
1564 if (max_online < delta)
1568 schedule_timeout_interruptible(onoff_interval * HZ);
1570 VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1574 static int __cpuinit
1575 rcu_torture_onoff_init(void)
1579 if (onoff_interval <= 0)
1581 onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff");
1582 if (IS_ERR(onoff_task)) {
1583 ret = PTR_ERR(onoff_task);
1590 static void rcu_torture_onoff_cleanup(void)
1592 if (onoff_task == NULL)
1594 VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1595 kthread_stop(onoff_task);
1599 #else /* #ifdef CONFIG_HOTPLUG_CPU */
1602 rcu_torture_onoff_init(void)
1607 static void rcu_torture_onoff_cleanup(void)
1611 #endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1614 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1615 * induces a CPU stall for the time specified by stall_cpu.
1617 static int __cpuinit rcu_torture_stall(void *args)
1619 unsigned long stop_at;
1621 VERBOSE_PRINTK_STRING("rcu_torture_stall task started");
1622 if (stall_cpu_holdoff > 0) {
1623 VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff");
1624 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
1625 VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff");
1627 if (!kthread_should_stop()) {
1628 stop_at = get_seconds() + stall_cpu;
1629 /* RCU CPU stall is expected behavior in following code. */
1630 pr_alert("rcu_torture_stall start.\n");
1633 while (ULONG_CMP_LT(get_seconds(), stop_at))
1634 continue; /* Induce RCU CPU stall warning. */
1637 pr_alert("rcu_torture_stall end.\n");
1639 rcutorture_shutdown_absorb("rcu_torture_stall");
1640 while (!kthread_should_stop())
1641 schedule_timeout_interruptible(10 * HZ);
1645 /* Spawn CPU-stall kthread, if stall_cpu specified. */
1646 static int __init rcu_torture_stall_init(void)
1652 stall_task = kthread_run(rcu_torture_stall, NULL, "rcu_torture_stall");
1653 if (IS_ERR(stall_task)) {
1654 ret = PTR_ERR(stall_task);
1661 /* Clean up after the CPU-stall kthread, if one was spawned. */
1662 static void rcu_torture_stall_cleanup(void)
1664 if (stall_task == NULL)
1666 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task.");
1667 kthread_stop(stall_task);
1671 /* Callback function for RCU barrier testing. */
1672 void rcu_torture_barrier_cbf(struct rcu_head *rcu)
1674 atomic_inc(&barrier_cbs_invoked);
1677 /* kthread function to register callbacks used to test RCU barriers. */
1678 static int rcu_torture_barrier_cbs(void *arg)
1680 long myid = (long)arg;
1682 struct rcu_head rcu;
1684 init_rcu_head_on_stack(&rcu);
1685 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
1686 set_user_nice(current, 19);
1688 wait_event(barrier_cbs_wq[myid],
1689 barrier_phase != lastphase ||
1690 kthread_should_stop() ||
1691 fullstop != FULLSTOP_DONTSTOP);
1692 lastphase = barrier_phase;
1693 smp_mb(); /* ensure barrier_phase load before ->call(). */
1694 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1696 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1697 if (atomic_dec_and_test(&barrier_cbs_count))
1698 wake_up(&barrier_wq);
1699 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1700 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task stopping");
1701 rcutorture_shutdown_absorb("rcu_torture_barrier_cbs");
1702 while (!kthread_should_stop())
1703 schedule_timeout_interruptible(1);
1704 cur_ops->cb_barrier();
1705 destroy_rcu_head_on_stack(&rcu);
1709 /* kthread function to drive and coordinate RCU barrier testing. */
1710 static int rcu_torture_barrier(void *arg)
1714 VERBOSE_PRINTK_STRING("rcu_torture_barrier task starting");
1716 atomic_set(&barrier_cbs_invoked, 0);
1717 atomic_set(&barrier_cbs_count, n_barrier_cbs);
1718 smp_mb(); /* Ensure barrier_phase after prior assignments. */
1719 barrier_phase = !barrier_phase;
1720 for (i = 0; i < n_barrier_cbs; i++)
1721 wake_up(&barrier_cbs_wq[i]);
1722 wait_event(barrier_wq,
1723 atomic_read(&barrier_cbs_count) == 0 ||
1724 kthread_should_stop() ||
1725 fullstop != FULLSTOP_DONTSTOP);
1726 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1728 n_barrier_attempts++;
1729 cur_ops->cb_barrier();
1730 if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
1731 n_rcu_torture_barrier_error++;
1734 n_barrier_successes++;
1735 schedule_timeout_interruptible(HZ / 10);
1736 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1737 VERBOSE_PRINTK_STRING("rcu_torture_barrier task stopping");
1738 rcutorture_shutdown_absorb("rcu_torture_barrier");
1739 while (!kthread_should_stop())
1740 schedule_timeout_interruptible(1);
1744 /* Initialize RCU barrier testing. */
1745 static int rcu_torture_barrier_init(void)
1750 if (n_barrier_cbs == 0)
1752 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
1753 pr_alert("%s" TORTURE_FLAG
1754 " Call or barrier ops missing for %s,\n",
1755 torture_type, cur_ops->name);
1756 pr_alert("%s" TORTURE_FLAG
1757 " RCU barrier testing omitted from run.\n",
1761 atomic_set(&barrier_cbs_count, 0);
1762 atomic_set(&barrier_cbs_invoked, 0);
1764 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
1767 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
1769 if (barrier_cbs_tasks == NULL || barrier_cbs_wq == 0)
1771 for (i = 0; i < n_barrier_cbs; i++) {
1772 init_waitqueue_head(&barrier_cbs_wq[i]);
1773 barrier_cbs_tasks[i] = kthread_run(rcu_torture_barrier_cbs,
1775 "rcu_torture_barrier_cbs");
1776 if (IS_ERR(barrier_cbs_tasks[i])) {
1777 ret = PTR_ERR(barrier_cbs_tasks[i]);
1778 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier_cbs");
1779 barrier_cbs_tasks[i] = NULL;
1783 barrier_task = kthread_run(rcu_torture_barrier, NULL,
1784 "rcu_torture_barrier");
1785 if (IS_ERR(barrier_task)) {
1786 ret = PTR_ERR(barrier_task);
1787 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier");
1788 barrier_task = NULL;
1793 /* Clean up after RCU barrier testing. */
1794 static void rcu_torture_barrier_cleanup(void)
1798 if (barrier_task != NULL) {
1799 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier task");
1800 kthread_stop(barrier_task);
1801 barrier_task = NULL;
1803 if (barrier_cbs_tasks != NULL) {
1804 for (i = 0; i < n_barrier_cbs; i++) {
1805 if (barrier_cbs_tasks[i] != NULL) {
1806 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier_cbs task");
1807 kthread_stop(barrier_cbs_tasks[i]);
1808 barrier_cbs_tasks[i] = NULL;
1811 kfree(barrier_cbs_tasks);
1812 barrier_cbs_tasks = NULL;
1814 if (barrier_cbs_wq != NULL) {
1815 kfree(barrier_cbs_wq);
1816 barrier_cbs_wq = NULL;
1820 static int rcutorture_cpu_notify(struct notifier_block *self,
1821 unsigned long action, void *hcpu)
1823 long cpu = (long)hcpu;
1827 case CPU_DOWN_FAILED:
1828 (void)rcutorture_booster_init(cpu);
1830 case CPU_DOWN_PREPARE:
1831 rcutorture_booster_cleanup(cpu);
1839 static struct notifier_block rcutorture_cpu_nb = {
1840 .notifier_call = rcutorture_cpu_notify,
1844 rcu_torture_cleanup(void)
1848 mutex_lock(&fullstop_mutex);
1849 rcutorture_record_test_transition();
1850 if (fullstop == FULLSTOP_SHUTDOWN) {
1851 pr_warn(/* but going down anyway, so... */
1852 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
1853 mutex_unlock(&fullstop_mutex);
1854 schedule_timeout_uninterruptible(10);
1855 if (cur_ops->cb_barrier != NULL)
1856 cur_ops->cb_barrier();
1859 fullstop = FULLSTOP_RMMOD;
1860 mutex_unlock(&fullstop_mutex);
1861 unregister_reboot_notifier(&rcutorture_shutdown_nb);
1862 rcu_torture_barrier_cleanup();
1863 rcu_torture_stall_cleanup();
1865 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1866 kthread_stop(stutter_task);
1868 stutter_task = NULL;
1869 if (shuffler_task) {
1870 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1871 kthread_stop(shuffler_task);
1872 free_cpumask_var(shuffle_tmp_mask);
1874 shuffler_task = NULL;
1877 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1878 kthread_stop(writer_task);
1883 for (i = 0; i < nrealreaders; i++) {
1884 if (reader_tasks[i]) {
1885 VERBOSE_PRINTK_STRING(
1886 "Stopping rcu_torture_reader task");
1887 kthread_stop(reader_tasks[i]);
1889 reader_tasks[i] = NULL;
1891 kfree(reader_tasks);
1892 reader_tasks = NULL;
1894 rcu_torture_current = NULL;
1896 if (fakewriter_tasks) {
1897 for (i = 0; i < nfakewriters; i++) {
1898 if (fakewriter_tasks[i]) {
1899 VERBOSE_PRINTK_STRING(
1900 "Stopping rcu_torture_fakewriter task");
1901 kthread_stop(fakewriter_tasks[i]);
1903 fakewriter_tasks[i] = NULL;
1905 kfree(fakewriter_tasks);
1906 fakewriter_tasks = NULL;
1910 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1911 kthread_stop(stats_task);
1916 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1917 kthread_stop(fqs_task);
1920 if ((test_boost == 1 && cur_ops->can_boost) ||
1922 unregister_cpu_notifier(&rcutorture_cpu_nb);
1923 for_each_possible_cpu(i)
1924 rcutorture_booster_cleanup(i);
1926 if (shutdown_task != NULL) {
1927 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1928 kthread_stop(shutdown_task);
1930 shutdown_task = NULL;
1931 rcu_torture_onoff_cleanup();
1933 /* Wait for all RCU callbacks to fire. */
1935 if (cur_ops->cb_barrier != NULL)
1936 cur_ops->cb_barrier();
1938 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
1940 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
1941 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
1942 else if (n_online_successes != n_online_attempts ||
1943 n_offline_successes != n_offline_attempts)
1944 rcu_torture_print_module_parms(cur_ops,
1945 "End of test: RCU_HOTPLUG");
1947 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
1951 rcu_torture_init(void)
1957 static struct rcu_torture_ops *torture_ops[] =
1958 { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
1959 &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops,
1960 &srcu_ops, &srcu_sync_ops, &srcu_expedited_ops,
1961 &srcu_raw_ops, &srcu_raw_sync_ops,
1962 &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
1964 mutex_lock(&fullstop_mutex);
1966 /* Process args and tell the world that the torturer is on the job. */
1967 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
1968 cur_ops = torture_ops[i];
1969 if (strcmp(torture_type, cur_ops->name) == 0)
1972 if (i == ARRAY_SIZE(torture_ops)) {
1973 pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
1975 pr_alert("rcu-torture types:");
1976 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
1977 pr_alert(" %s", torture_ops[i]->name);
1979 mutex_unlock(&fullstop_mutex);
1982 if (cur_ops->fqs == NULL && fqs_duration != 0) {
1983 pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
1987 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1990 nrealreaders = nreaders;
1992 nrealreaders = 2 * num_online_cpus();
1993 rcu_torture_print_module_parms(cur_ops, "Start of test");
1994 fullstop = FULLSTOP_DONTSTOP;
1996 /* Set up the freelist. */
1998 INIT_LIST_HEAD(&rcu_torture_freelist);
1999 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
2000 rcu_tortures[i].rtort_mbtest = 0;
2001 list_add_tail(&rcu_tortures[i].rtort_free,
2002 &rcu_torture_freelist);
2005 /* Initialize the statistics so that each run gets its own numbers. */
2007 rcu_torture_current = NULL;
2008 rcu_torture_current_version = 0;
2009 atomic_set(&n_rcu_torture_alloc, 0);
2010 atomic_set(&n_rcu_torture_alloc_fail, 0);
2011 atomic_set(&n_rcu_torture_free, 0);
2012 atomic_set(&n_rcu_torture_mberror, 0);
2013 atomic_set(&n_rcu_torture_error, 0);
2014 n_rcu_torture_barrier_error = 0;
2015 n_rcu_torture_boost_ktrerror = 0;
2016 n_rcu_torture_boost_rterror = 0;
2017 n_rcu_torture_boost_failure = 0;
2018 n_rcu_torture_boosts = 0;
2019 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
2020 atomic_set(&rcu_torture_wcount[i], 0);
2021 for_each_possible_cpu(cpu) {
2022 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
2023 per_cpu(rcu_torture_count, cpu)[i] = 0;
2024 per_cpu(rcu_torture_batch, cpu)[i] = 0;
2028 /* Start up the kthreads. */
2030 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
2031 writer_task = kthread_create(rcu_torture_writer, NULL,
2032 "rcu_torture_writer");
2033 if (IS_ERR(writer_task)) {
2034 firsterr = PTR_ERR(writer_task);
2035 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
2039 wake_up_process(writer_task);
2040 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
2042 if (fakewriter_tasks == NULL) {
2043 VERBOSE_PRINTK_ERRSTRING("out of memory");
2047 for (i = 0; i < nfakewriters; i++) {
2048 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
2049 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
2050 "rcu_torture_fakewriter");
2051 if (IS_ERR(fakewriter_tasks[i])) {
2052 firsterr = PTR_ERR(fakewriter_tasks[i]);
2053 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
2054 fakewriter_tasks[i] = NULL;
2058 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
2060 if (reader_tasks == NULL) {
2061 VERBOSE_PRINTK_ERRSTRING("out of memory");
2065 for (i = 0; i < nrealreaders; i++) {
2066 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
2067 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
2068 "rcu_torture_reader");
2069 if (IS_ERR(reader_tasks[i])) {
2070 firsterr = PTR_ERR(reader_tasks[i]);
2071 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
2072 reader_tasks[i] = NULL;
2076 if (stat_interval > 0) {
2077 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
2078 stats_task = kthread_run(rcu_torture_stats, NULL,
2079 "rcu_torture_stats");
2080 if (IS_ERR(stats_task)) {
2081 firsterr = PTR_ERR(stats_task);
2082 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
2087 if (test_no_idle_hz) {
2088 rcu_idle_cpu = num_online_cpus() - 1;
2090 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
2092 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
2096 /* Create the shuffler thread */
2097 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
2098 "rcu_torture_shuffle");
2099 if (IS_ERR(shuffler_task)) {
2100 free_cpumask_var(shuffle_tmp_mask);
2101 firsterr = PTR_ERR(shuffler_task);
2102 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
2103 shuffler_task = NULL;
2110 /* Create the stutter thread */
2111 stutter_task = kthread_run(rcu_torture_stutter, NULL,
2112 "rcu_torture_stutter");
2113 if (IS_ERR(stutter_task)) {
2114 firsterr = PTR_ERR(stutter_task);
2115 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
2116 stutter_task = NULL;
2120 if (fqs_duration < 0)
2123 /* Create the stutter thread */
2124 fqs_task = kthread_run(rcu_torture_fqs, NULL,
2126 if (IS_ERR(fqs_task)) {
2127 firsterr = PTR_ERR(fqs_task);
2128 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
2133 if (test_boost_interval < 1)
2134 test_boost_interval = 1;
2135 if (test_boost_duration < 2)
2136 test_boost_duration = 2;
2137 if ((test_boost == 1 && cur_ops->can_boost) ||
2140 boost_starttime = jiffies + test_boost_interval * HZ;
2141 register_cpu_notifier(&rcutorture_cpu_nb);
2142 for_each_possible_cpu(i) {
2143 if (cpu_is_offline(i))
2144 continue; /* Heuristic: CPU can go offline. */
2145 retval = rcutorture_booster_init(i);
2152 if (shutdown_secs > 0) {
2153 shutdown_time = jiffies + shutdown_secs * HZ;
2154 shutdown_task = kthread_create(rcu_torture_shutdown, NULL,
2155 "rcu_torture_shutdown");
2156 if (IS_ERR(shutdown_task)) {
2157 firsterr = PTR_ERR(shutdown_task);
2158 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
2159 shutdown_task = NULL;
2162 wake_up_process(shutdown_task);
2164 i = rcu_torture_onoff_init();
2169 register_reboot_notifier(&rcutorture_shutdown_nb);
2170 i = rcu_torture_stall_init();
2175 retval = rcu_torture_barrier_init();
2180 rcutorture_record_test_transition();
2181 mutex_unlock(&fullstop_mutex);
2185 mutex_unlock(&fullstop_mutex);
2186 rcu_torture_cleanup();
2190 module_init(rcu_torture_init);
2191 module_exit(rcu_torture_cleanup);