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 bool gp_exp; /* Use expedited GP wait primitives. */
69 static bool gp_normal; /* Use normal GP wait primitives. */
70 static int n_barrier_cbs; /* Number of callbacks to test RCU barriers. */
71 static int object_debug; /* Test object-debug double call_rcu()?. */
72 static int onoff_interval; /* Wait time between CPU hotplugs, 0=disable. */
73 static int onoff_holdoff; /* Seconds after boot before CPU hotplugs. */
74 static int shutdown_secs; /* Shutdown time (s). <=0 for no shutdown. */
75 static int stall_cpu; /* CPU-stall duration (s). 0 for no stall. */
76 static int stall_cpu_holdoff = 10; /* Time to wait until stall (s). */
77 static int test_boost = 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */
78 static int test_boost_interval = 7; /* Interval between boost tests, seconds. */
79 static int test_boost_duration = 4; /* Duration of each boost test, seconds. */
80 static char *torture_type = "rcu"; /* What RCU implementation to torture. */
82 module_param(nreaders, int, 0444);
83 MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
84 module_param(nfakewriters, int, 0444);
85 MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
86 module_param(stat_interval, int, 0644);
87 MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
88 module_param(verbose, bool, 0444);
89 MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
90 module_param(test_no_idle_hz, bool, 0444);
91 MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
92 module_param(shuffle_interval, int, 0444);
93 MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
94 module_param(stutter, int, 0444);
95 MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
96 module_param(irqreader, int, 0444);
97 MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
98 module_param(fqs_duration, int, 0444);
99 MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us)");
100 module_param(fqs_holdoff, int, 0444);
101 MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)");
102 module_param(fqs_stutter, int, 0444);
103 MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)");
104 module_param(gp_normal, bool, 0444);
105 MODULE_PARM_DESC(gp_normal, "Use normal (non-expedited) GP wait primitives");
106 module_param(gp_exp, bool, 0444);
107 MODULE_PARM_DESC(gp_exp, "Use expedited GP wait primitives");
108 module_param(n_barrier_cbs, int, 0444);
109 MODULE_PARM_DESC(n_barrier_cbs, "# of callbacks/kthreads for barrier testing");
110 module_param(object_debug, int, 0444);
111 MODULE_PARM_DESC(object_debug, "Enable debug-object double call_rcu() testing");
112 module_param(onoff_interval, int, 0444);
113 MODULE_PARM_DESC(onoff_interval, "Time between CPU hotplugs (s), 0=disable");
114 module_param(onoff_holdoff, int, 0444);
115 MODULE_PARM_DESC(onoff_holdoff, "Time after boot before CPU hotplugs (s)");
116 module_param(shutdown_secs, int, 0444);
117 MODULE_PARM_DESC(shutdown_secs, "Shutdown time (s), zero to disable.");
118 module_param(stall_cpu, int, 0444);
119 MODULE_PARM_DESC(stall_cpu, "Stall duration (s), zero to disable.");
120 module_param(stall_cpu_holdoff, int, 0444);
121 MODULE_PARM_DESC(stall_cpu_holdoff, "Time to wait before starting stall (s).");
122 module_param(test_boost, int, 0444);
123 MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
124 module_param(test_boost_interval, int, 0444);
125 MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds.");
126 module_param(test_boost_duration, int, 0444);
127 MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds.");
128 module_param(torture_type, charp, 0444);
129 MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
131 #define TORTURE_FLAG "-torture:"
132 #define PRINTK_STRING(s) \
133 do { pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
134 #define VERBOSE_PRINTK_STRING(s) \
135 do { if (verbose) pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
136 #define VERBOSE_PRINTK_ERRSTRING(s) \
137 do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
139 static char printk_buf[4096];
141 static int nrealreaders;
142 static struct task_struct *writer_task;
143 static struct task_struct **fakewriter_tasks;
144 static struct task_struct **reader_tasks;
145 static struct task_struct *stats_task;
146 static struct task_struct *shuffler_task;
147 static struct task_struct *stutter_task;
148 static struct task_struct *fqs_task;
149 static struct task_struct *boost_tasks[NR_CPUS];
150 static struct task_struct *shutdown_task;
151 #ifdef CONFIG_HOTPLUG_CPU
152 static struct task_struct *onoff_task;
153 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
154 static struct task_struct *stall_task;
155 static struct task_struct **barrier_cbs_tasks;
156 static struct task_struct *barrier_task;
158 #define RCU_TORTURE_PIPE_LEN 10
161 struct rcu_head rtort_rcu;
162 int rtort_pipe_count;
163 struct list_head rtort_free;
167 static LIST_HEAD(rcu_torture_freelist);
168 static struct rcu_torture __rcu *rcu_torture_current;
169 static unsigned long rcu_torture_current_version;
170 static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
171 static DEFINE_SPINLOCK(rcu_torture_lock);
172 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
174 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
176 static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
177 static atomic_t n_rcu_torture_alloc;
178 static atomic_t n_rcu_torture_alloc_fail;
179 static atomic_t n_rcu_torture_free;
180 static atomic_t n_rcu_torture_mberror;
181 static atomic_t n_rcu_torture_error;
182 static long n_rcu_torture_barrier_error;
183 static long n_rcu_torture_boost_ktrerror;
184 static long n_rcu_torture_boost_rterror;
185 static long n_rcu_torture_boost_failure;
186 static long n_rcu_torture_boosts;
187 static long n_rcu_torture_timers;
188 static long n_offline_attempts;
189 static long n_offline_successes;
190 static unsigned long sum_offline;
191 static int min_offline = -1;
192 static int max_offline;
193 static long n_online_attempts;
194 static long n_online_successes;
195 static unsigned long sum_online;
196 static int min_online = -1;
197 static int max_online;
198 static long n_barrier_attempts;
199 static long n_barrier_successes;
200 static struct list_head rcu_torture_removed;
201 static cpumask_var_t shuffle_tmp_mask;
203 static int stutter_pause_test;
205 #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
206 #define RCUTORTURE_RUNNABLE_INIT 1
208 #define RCUTORTURE_RUNNABLE_INIT 0
210 int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
211 module_param(rcutorture_runnable, int, 0444);
212 MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot");
214 #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
215 #define rcu_can_boost() 1
216 #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
217 #define rcu_can_boost() 0
218 #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
220 #ifdef CONFIG_RCU_TRACE
221 static u64 notrace rcu_trace_clock_local(void)
223 u64 ts = trace_clock_local();
224 unsigned long __maybe_unused ts_rem = do_div(ts, NSEC_PER_USEC);
227 #else /* #ifdef CONFIG_RCU_TRACE */
228 static u64 notrace rcu_trace_clock_local(void)
232 #endif /* #else #ifdef CONFIG_RCU_TRACE */
234 static unsigned long shutdown_time; /* jiffies to system shutdown. */
235 static unsigned long boost_starttime; /* jiffies of next boost test start. */
236 DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
237 /* and boost task create/destroy. */
238 static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */
239 static bool barrier_phase; /* Test phase. */
240 static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */
241 static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */
242 static DECLARE_WAIT_QUEUE_HEAD(barrier_wq);
244 /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
246 #define FULLSTOP_DONTSTOP 0 /* Normal operation. */
247 #define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
248 #define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
249 static int fullstop = FULLSTOP_RMMOD;
251 * Protect fullstop transitions and spawning of kthreads.
253 static DEFINE_MUTEX(fullstop_mutex);
255 /* Forward reference. */
256 static void rcu_torture_cleanup(void);
259 * Detect and respond to a system shutdown.
262 rcutorture_shutdown_notify(struct notifier_block *unused1,
263 unsigned long unused2, void *unused3)
265 mutex_lock(&fullstop_mutex);
266 if (fullstop == FULLSTOP_DONTSTOP)
267 fullstop = FULLSTOP_SHUTDOWN;
269 pr_warn(/* but going down anyway, so... */
270 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
271 mutex_unlock(&fullstop_mutex);
276 * Absorb kthreads into a kernel function that won't return, so that
277 * they won't ever access module text or data again.
279 static void rcutorture_shutdown_absorb(const char *title)
281 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
283 "rcutorture thread %s parking due to system shutdown\n",
285 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
290 * Allocate an element from the rcu_tortures pool.
292 static struct rcu_torture *
293 rcu_torture_alloc(void)
297 spin_lock_bh(&rcu_torture_lock);
298 if (list_empty(&rcu_torture_freelist)) {
299 atomic_inc(&n_rcu_torture_alloc_fail);
300 spin_unlock_bh(&rcu_torture_lock);
303 atomic_inc(&n_rcu_torture_alloc);
304 p = rcu_torture_freelist.next;
306 spin_unlock_bh(&rcu_torture_lock);
307 return container_of(p, struct rcu_torture, rtort_free);
311 * Free an element to the rcu_tortures pool.
314 rcu_torture_free(struct rcu_torture *p)
316 atomic_inc(&n_rcu_torture_free);
317 spin_lock_bh(&rcu_torture_lock);
318 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
319 spin_unlock_bh(&rcu_torture_lock);
322 struct rcu_random_state {
323 unsigned long rrs_state;
327 #define RCU_RANDOM_MULT 39916801 /* prime */
328 #define RCU_RANDOM_ADD 479001701 /* prime */
329 #define RCU_RANDOM_REFRESH 10000
331 #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
334 * Crude but fast random-number generator. Uses a linear congruential
335 * generator, with occasional help from cpu_clock().
338 rcu_random(struct rcu_random_state *rrsp)
340 if (--rrsp->rrs_count < 0) {
341 rrsp->rrs_state += (unsigned long)local_clock();
342 rrsp->rrs_count = RCU_RANDOM_REFRESH;
344 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
345 return swahw32(rrsp->rrs_state);
349 rcu_stutter_wait(const char *title)
351 while (stutter_pause_test || !rcutorture_runnable) {
352 if (rcutorture_runnable)
353 schedule_timeout_interruptible(1);
355 schedule_timeout_interruptible(round_jiffies_relative(HZ));
356 rcutorture_shutdown_absorb(title);
361 * Operations vector for selecting different types of tests.
364 struct rcu_torture_ops {
366 int (*readlock)(void);
367 void (*read_delay)(struct rcu_random_state *rrsp);
368 void (*readunlock)(int idx);
369 int (*completed)(void);
370 void (*deferred_free)(struct rcu_torture *p);
372 void (*exp_sync)(void);
373 void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu));
374 void (*cb_barrier)(void);
376 int (*stats)(char *page);
382 static struct rcu_torture_ops *cur_ops;
385 * Definitions for rcu torture testing.
388 static int rcu_torture_read_lock(void) __acquires(RCU)
394 static void rcu_read_delay(struct rcu_random_state *rrsp)
396 const unsigned long shortdelay_us = 200;
397 const unsigned long longdelay_ms = 50;
399 /* We want a short delay sometimes to make a reader delay the grace
400 * period, and we want a long delay occasionally to trigger
401 * force_quiescent_state. */
403 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
404 mdelay(longdelay_ms);
405 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
406 udelay(shortdelay_us);
407 #ifdef CONFIG_PREEMPT
408 if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000)))
409 preempt_schedule(); /* No QS if preempt_disable() in effect */
413 static void rcu_torture_read_unlock(int idx) __releases(RCU)
418 static int rcu_torture_completed(void)
420 return rcu_batches_completed();
424 rcu_torture_cb(struct rcu_head *p)
427 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
429 if (fullstop != FULLSTOP_DONTSTOP) {
430 /* Test is ending, just drop callbacks on the floor. */
431 /* The next initialization will pick up the pieces. */
434 i = rp->rtort_pipe_count;
435 if (i > RCU_TORTURE_PIPE_LEN)
436 i = RCU_TORTURE_PIPE_LEN;
437 atomic_inc(&rcu_torture_wcount[i]);
438 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
439 rp->rtort_mbtest = 0;
440 rcu_torture_free(rp);
442 cur_ops->deferred_free(rp);
446 static int rcu_no_completed(void)
451 static void rcu_torture_deferred_free(struct rcu_torture *p)
453 call_rcu(&p->rtort_rcu, rcu_torture_cb);
456 static void rcu_sync_torture_init(void)
458 INIT_LIST_HEAD(&rcu_torture_removed);
461 static struct rcu_torture_ops rcu_ops = {
462 .init = rcu_sync_torture_init,
463 .readlock = rcu_torture_read_lock,
464 .read_delay = rcu_read_delay,
465 .readunlock = rcu_torture_read_unlock,
466 .completed = rcu_torture_completed,
467 .deferred_free = rcu_torture_deferred_free,
468 .sync = synchronize_rcu,
469 .exp_sync = synchronize_rcu_expedited,
471 .cb_barrier = rcu_barrier,
472 .fqs = rcu_force_quiescent_state,
475 .can_boost = rcu_can_boost(),
480 * Definitions for rcu_bh torture testing.
483 static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
489 static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
491 rcu_read_unlock_bh();
494 static int rcu_bh_torture_completed(void)
496 return rcu_batches_completed_bh();
499 static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
501 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
504 static struct rcu_torture_ops rcu_bh_ops = {
505 .init = rcu_sync_torture_init,
506 .readlock = rcu_bh_torture_read_lock,
507 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
508 .readunlock = rcu_bh_torture_read_unlock,
509 .completed = rcu_bh_torture_completed,
510 .deferred_free = rcu_bh_torture_deferred_free,
511 .sync = synchronize_rcu_bh,
512 .exp_sync = synchronize_rcu_bh_expedited,
514 .cb_barrier = rcu_barrier_bh,
515 .fqs = rcu_bh_force_quiescent_state,
522 * Definitions for srcu torture testing.
525 DEFINE_STATIC_SRCU(srcu_ctl);
527 static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
529 return srcu_read_lock(&srcu_ctl);
532 static void srcu_read_delay(struct rcu_random_state *rrsp)
535 const long uspertick = 1000000 / HZ;
536 const long longdelay = 10;
538 /* We want there to be long-running readers, but not all the time. */
540 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
542 schedule_timeout_interruptible(longdelay);
544 rcu_read_delay(rrsp);
547 static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
549 srcu_read_unlock(&srcu_ctl, idx);
552 static int srcu_torture_completed(void)
554 return srcu_batches_completed(&srcu_ctl);
557 static void srcu_torture_deferred_free(struct rcu_torture *rp)
559 call_srcu(&srcu_ctl, &rp->rtort_rcu, rcu_torture_cb);
562 static void srcu_torture_synchronize(void)
564 synchronize_srcu(&srcu_ctl);
567 static void srcu_torture_call(struct rcu_head *head,
568 void (*func)(struct rcu_head *head))
570 call_srcu(&srcu_ctl, head, func);
573 static void srcu_torture_barrier(void)
575 srcu_barrier(&srcu_ctl);
578 static int srcu_torture_stats(char *page)
582 int idx = srcu_ctl.completed & 0x1;
584 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
585 torture_type, TORTURE_FLAG, idx);
586 for_each_possible_cpu(cpu) {
587 cnt += sprintf(&page[cnt], " %d(%lu,%lu)", cpu,
588 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
589 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
591 cnt += sprintf(&page[cnt], "\n");
595 static void srcu_torture_synchronize_expedited(void)
597 synchronize_srcu_expedited(&srcu_ctl);
600 static struct rcu_torture_ops srcu_ops = {
601 .init = rcu_sync_torture_init,
602 .readlock = srcu_torture_read_lock,
603 .read_delay = srcu_read_delay,
604 .readunlock = srcu_torture_read_unlock,
605 .completed = srcu_torture_completed,
606 .deferred_free = srcu_torture_deferred_free,
607 .sync = srcu_torture_synchronize,
608 .exp_sync = srcu_torture_synchronize_expedited,
609 .call = srcu_torture_call,
610 .cb_barrier = srcu_torture_barrier,
611 .stats = srcu_torture_stats,
616 * Definitions for sched torture testing.
619 static int sched_torture_read_lock(void)
625 static void sched_torture_read_unlock(int idx)
630 static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
632 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
635 static struct rcu_torture_ops sched_ops = {
636 .init = rcu_sync_torture_init,
637 .readlock = sched_torture_read_lock,
638 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
639 .readunlock = sched_torture_read_unlock,
640 .completed = rcu_no_completed,
641 .deferred_free = rcu_sched_torture_deferred_free,
642 .sync = synchronize_sched,
643 .exp_sync = synchronize_sched_expedited,
644 .call = call_rcu_sched,
645 .cb_barrier = rcu_barrier_sched,
646 .fqs = rcu_sched_force_quiescent_state,
653 * RCU torture priority-boost testing. Runs one real-time thread per
654 * CPU for moderate bursts, repeatedly registering RCU callbacks and
655 * spinning waiting for them to be invoked. If a given callback takes
656 * too long to be invoked, we assume that priority inversion has occurred.
659 struct rcu_boost_inflight {
664 static void rcu_torture_boost_cb(struct rcu_head *head)
666 struct rcu_boost_inflight *rbip =
667 container_of(head, struct rcu_boost_inflight, rcu);
669 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
673 static int rcu_torture_boost(void *arg)
675 unsigned long call_rcu_time;
676 unsigned long endtime;
677 unsigned long oldstarttime;
678 struct rcu_boost_inflight rbi = { .inflight = 0 };
679 struct sched_param sp;
681 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
683 /* Set real-time priority. */
684 sp.sched_priority = 1;
685 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
686 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
687 n_rcu_torture_boost_rterror++;
690 init_rcu_head_on_stack(&rbi.rcu);
691 /* Each pass through the following loop does one boost-test cycle. */
693 /* Wait for the next test interval. */
694 oldstarttime = boost_starttime;
695 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
696 schedule_timeout_interruptible(oldstarttime - jiffies);
697 rcu_stutter_wait("rcu_torture_boost");
698 if (kthread_should_stop() ||
699 fullstop != FULLSTOP_DONTSTOP)
703 /* Do one boost-test interval. */
704 endtime = oldstarttime + test_boost_duration * HZ;
705 call_rcu_time = jiffies;
706 while (ULONG_CMP_LT(jiffies, endtime)) {
707 /* If we don't have a callback in flight, post one. */
709 smp_mb(); /* RCU core before ->inflight = 1. */
711 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
712 if (jiffies - call_rcu_time >
713 test_boost_duration * HZ - HZ / 2) {
714 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
715 n_rcu_torture_boost_failure++;
717 call_rcu_time = jiffies;
720 rcu_stutter_wait("rcu_torture_boost");
721 if (kthread_should_stop() ||
722 fullstop != FULLSTOP_DONTSTOP)
727 * Set the start time of the next test interval.
728 * Yes, this is vulnerable to long delays, but such
729 * delays simply cause a false negative for the next
730 * interval. Besides, we are running at RT priority,
731 * so delays should be relatively rare.
733 while (oldstarttime == boost_starttime &&
734 !kthread_should_stop()) {
735 if (mutex_trylock(&boost_mutex)) {
736 boost_starttime = jiffies +
737 test_boost_interval * HZ;
738 n_rcu_torture_boosts++;
739 mutex_unlock(&boost_mutex);
742 schedule_timeout_uninterruptible(1);
745 /* Go do the stutter. */
746 checkwait: rcu_stutter_wait("rcu_torture_boost");
747 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
749 /* Clean up and exit. */
750 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
751 rcutorture_shutdown_absorb("rcu_torture_boost");
752 while (!kthread_should_stop() || rbi.inflight)
753 schedule_timeout_uninterruptible(1);
754 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
755 destroy_rcu_head_on_stack(&rbi.rcu);
760 * RCU torture force-quiescent-state kthread. Repeatedly induces
761 * bursts of calls to force_quiescent_state(), increasing the probability
762 * of occurrence of some important types of race conditions.
765 rcu_torture_fqs(void *arg)
767 unsigned long fqs_resume_time;
768 int fqs_burst_remaining;
770 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
772 fqs_resume_time = jiffies + fqs_stutter * HZ;
773 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
774 !kthread_should_stop()) {
775 schedule_timeout_interruptible(1);
777 fqs_burst_remaining = fqs_duration;
778 while (fqs_burst_remaining > 0 &&
779 !kthread_should_stop()) {
782 fqs_burst_remaining -= fqs_holdoff;
784 rcu_stutter_wait("rcu_torture_fqs");
785 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
786 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
787 rcutorture_shutdown_absorb("rcu_torture_fqs");
788 while (!kthread_should_stop())
789 schedule_timeout_uninterruptible(1);
794 * RCU torture writer kthread. Repeatedly substitutes a new structure
795 * for that pointed to by rcu_torture_current, freeing the old structure
796 * after a series of grace periods (the "pipeline").
799 rcu_torture_writer(void *arg)
803 long oldbatch = rcu_batches_completed();
804 struct rcu_torture *rp;
805 struct rcu_torture *rp1;
806 struct rcu_torture *old_rp;
807 static DEFINE_RCU_RANDOM(rand);
809 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
810 set_user_nice(current, 19);
813 schedule_timeout_uninterruptible(1);
814 rp = rcu_torture_alloc();
817 rp->rtort_pipe_count = 0;
818 udelay(rcu_random(&rand) & 0x3ff);
819 old_rp = rcu_dereference_check(rcu_torture_current,
820 current == writer_task);
821 rp->rtort_mbtest = 1;
822 rcu_assign_pointer(rcu_torture_current, rp);
823 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
825 i = old_rp->rtort_pipe_count;
826 if (i > RCU_TORTURE_PIPE_LEN)
827 i = RCU_TORTURE_PIPE_LEN;
828 atomic_inc(&rcu_torture_wcount[i]);
829 old_rp->rtort_pipe_count++;
830 if (gp_normal == gp_exp)
831 exp = !!(rcu_random(&rand) & 0x80);
835 cur_ops->deferred_free(old_rp);
838 list_add(&old_rp->rtort_free,
839 &rcu_torture_removed);
840 list_for_each_entry_safe(rp, rp1,
841 &rcu_torture_removed,
843 i = rp->rtort_pipe_count;
844 if (i > RCU_TORTURE_PIPE_LEN)
845 i = RCU_TORTURE_PIPE_LEN;
846 atomic_inc(&rcu_torture_wcount[i]);
847 if (++rp->rtort_pipe_count >=
848 RCU_TORTURE_PIPE_LEN) {
849 rp->rtort_mbtest = 0;
850 list_del(&rp->rtort_free);
851 rcu_torture_free(rp);
856 rcutorture_record_progress(++rcu_torture_current_version);
857 oldbatch = cur_ops->completed();
858 rcu_stutter_wait("rcu_torture_writer");
859 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
860 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
861 rcutorture_shutdown_absorb("rcu_torture_writer");
862 while (!kthread_should_stop())
863 schedule_timeout_uninterruptible(1);
868 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
869 * delay between calls.
872 rcu_torture_fakewriter(void *arg)
874 DEFINE_RCU_RANDOM(rand);
876 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
877 set_user_nice(current, 19);
880 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
881 udelay(rcu_random(&rand) & 0x3ff);
882 if (cur_ops->cb_barrier != NULL &&
883 rcu_random(&rand) % (nfakewriters * 8) == 0) {
884 cur_ops->cb_barrier();
885 } else if (gp_normal == gp_exp) {
886 if (rcu_random(&rand) & 0x80)
890 } else if (gp_normal) {
895 rcu_stutter_wait("rcu_torture_fakewriter");
896 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
898 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
899 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
900 while (!kthread_should_stop())
901 schedule_timeout_uninterruptible(1);
905 void rcutorture_trace_dump(void)
907 static atomic_t beenhere = ATOMIC_INIT(0);
909 if (atomic_read(&beenhere))
911 if (atomic_xchg(&beenhere, 1) != 0)
913 ftrace_dump(DUMP_ALL);
917 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
918 * incrementing the corresponding element of the pipeline array. The
919 * counter in the element should never be greater than 1, otherwise, the
920 * RCU implementation is broken.
922 static void rcu_torture_timer(unsigned long unused)
927 static DEFINE_RCU_RANDOM(rand);
928 static DEFINE_SPINLOCK(rand_lock);
929 struct rcu_torture *p;
931 unsigned long long ts;
933 idx = cur_ops->readlock();
934 completed = cur_ops->completed();
935 ts = rcu_trace_clock_local();
936 p = rcu_dereference_check(rcu_torture_current,
937 rcu_read_lock_bh_held() ||
938 rcu_read_lock_sched_held() ||
939 srcu_read_lock_held(&srcu_ctl));
941 /* Leave because rcu_torture_writer is not yet underway */
942 cur_ops->readunlock(idx);
945 if (p->rtort_mbtest == 0)
946 atomic_inc(&n_rcu_torture_mberror);
947 spin_lock(&rand_lock);
948 cur_ops->read_delay(&rand);
949 n_rcu_torture_timers++;
950 spin_unlock(&rand_lock);
952 pipe_count = p->rtort_pipe_count;
953 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
954 /* Should not happen, but... */
955 pipe_count = RCU_TORTURE_PIPE_LEN;
957 completed_end = cur_ops->completed();
958 if (pipe_count > 1) {
959 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, ts,
960 completed, completed_end);
961 rcutorture_trace_dump();
963 __this_cpu_inc(rcu_torture_count[pipe_count]);
964 completed = completed_end - completed;
965 if (completed > RCU_TORTURE_PIPE_LEN) {
966 /* Should not happen, but... */
967 completed = RCU_TORTURE_PIPE_LEN;
969 __this_cpu_inc(rcu_torture_batch[completed]);
971 cur_ops->readunlock(idx);
975 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
976 * incrementing the corresponding element of the pipeline array. The
977 * counter in the element should never be greater than 1, otherwise, the
978 * RCU implementation is broken.
981 rcu_torture_reader(void *arg)
986 DEFINE_RCU_RANDOM(rand);
987 struct rcu_torture *p;
990 unsigned long long ts;
992 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
993 set_user_nice(current, 19);
994 if (irqreader && cur_ops->irq_capable)
995 setup_timer_on_stack(&t, rcu_torture_timer, 0);
998 if (irqreader && cur_ops->irq_capable) {
999 if (!timer_pending(&t))
1000 mod_timer(&t, jiffies + 1);
1002 idx = cur_ops->readlock();
1003 completed = cur_ops->completed();
1004 ts = rcu_trace_clock_local();
1005 p = rcu_dereference_check(rcu_torture_current,
1006 rcu_read_lock_bh_held() ||
1007 rcu_read_lock_sched_held() ||
1008 srcu_read_lock_held(&srcu_ctl));
1010 /* Wait for rcu_torture_writer to get underway */
1011 cur_ops->readunlock(idx);
1012 schedule_timeout_interruptible(HZ);
1015 if (p->rtort_mbtest == 0)
1016 atomic_inc(&n_rcu_torture_mberror);
1017 cur_ops->read_delay(&rand);
1019 pipe_count = p->rtort_pipe_count;
1020 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1021 /* Should not happen, but... */
1022 pipe_count = RCU_TORTURE_PIPE_LEN;
1024 completed_end = cur_ops->completed();
1025 if (pipe_count > 1) {
1026 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu,
1027 ts, completed, completed_end);
1028 rcutorture_trace_dump();
1030 __this_cpu_inc(rcu_torture_count[pipe_count]);
1031 completed = completed_end - 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 rcu_torture_current,
1077 rcu_torture_current_version,
1078 list_empty(&rcu_torture_freelist),
1079 atomic_read(&n_rcu_torture_alloc),
1080 atomic_read(&n_rcu_torture_alloc_fail),
1081 atomic_read(&n_rcu_torture_free));
1082 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
1083 atomic_read(&n_rcu_torture_mberror),
1084 n_rcu_torture_boost_ktrerror,
1085 n_rcu_torture_boost_rterror);
1086 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
1087 n_rcu_torture_boost_failure,
1088 n_rcu_torture_boosts,
1089 n_rcu_torture_timers);
1090 cnt += sprintf(&page[cnt],
1091 "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ",
1092 n_online_successes, n_online_attempts,
1093 n_offline_successes, n_offline_attempts,
1094 min_online, max_online,
1095 min_offline, max_offline,
1096 sum_online, sum_offline, HZ);
1097 cnt += sprintf(&page[cnt], "barrier: %ld/%ld:%ld",
1098 n_barrier_successes,
1100 n_rcu_torture_barrier_error);
1101 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
1102 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
1103 n_rcu_torture_barrier_error != 0 ||
1104 n_rcu_torture_boost_ktrerror != 0 ||
1105 n_rcu_torture_boost_rterror != 0 ||
1106 n_rcu_torture_boost_failure != 0 ||
1108 cnt += sprintf(&page[cnt], "!!! ");
1109 atomic_inc(&n_rcu_torture_error);
1112 cnt += sprintf(&page[cnt], "Reader Pipe: ");
1113 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1114 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
1115 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
1116 cnt += sprintf(&page[cnt], "Reader Batch: ");
1117 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1118 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
1119 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
1120 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
1121 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1122 cnt += sprintf(&page[cnt], " %d",
1123 atomic_read(&rcu_torture_wcount[i]));
1125 cnt += sprintf(&page[cnt], "\n");
1127 cnt += cur_ops->stats(&page[cnt]);
1132 * Print torture statistics. Caller must ensure that there is only
1133 * one call to this function at a given time!!! This is normally
1134 * accomplished by relying on the module system to only have one copy
1135 * of the module loaded, and then by giving the rcu_torture_stats
1136 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1137 * thread is not running).
1140 rcu_torture_stats_print(void)
1144 cnt = rcu_torture_printk(printk_buf);
1145 pr_alert("%s", printk_buf);
1149 * Periodically prints torture statistics, if periodic statistics printing
1150 * was specified via the stat_interval module parameter.
1152 * No need to worry about fullstop here, since this one doesn't reference
1153 * volatile state or register callbacks.
1156 rcu_torture_stats(void *arg)
1158 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1160 schedule_timeout_interruptible(stat_interval * HZ);
1161 rcu_torture_stats_print();
1162 rcutorture_shutdown_absorb("rcu_torture_stats");
1163 } while (!kthread_should_stop());
1164 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1168 static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
1170 /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1171 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1173 static void rcu_torture_shuffle_tasks(void)
1177 cpumask_setall(shuffle_tmp_mask);
1180 /* No point in shuffling if there is only one online CPU (ex: UP) */
1181 if (num_online_cpus() == 1) {
1186 if (rcu_idle_cpu != -1)
1187 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
1189 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
1192 for (i = 0; i < nrealreaders; i++)
1193 if (reader_tasks[i])
1194 set_cpus_allowed_ptr(reader_tasks[i],
1197 if (fakewriter_tasks) {
1198 for (i = 0; i < nfakewriters; i++)
1199 if (fakewriter_tasks[i])
1200 set_cpus_allowed_ptr(fakewriter_tasks[i],
1204 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
1206 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
1208 set_cpus_allowed_ptr(stutter_task, shuffle_tmp_mask);
1210 set_cpus_allowed_ptr(fqs_task, shuffle_tmp_mask);
1212 set_cpus_allowed_ptr(shutdown_task, shuffle_tmp_mask);
1213 #ifdef CONFIG_HOTPLUG_CPU
1215 set_cpus_allowed_ptr(onoff_task, shuffle_tmp_mask);
1216 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
1218 set_cpus_allowed_ptr(stall_task, shuffle_tmp_mask);
1219 if (barrier_cbs_tasks)
1220 for (i = 0; i < n_barrier_cbs; i++)
1221 if (barrier_cbs_tasks[i])
1222 set_cpus_allowed_ptr(barrier_cbs_tasks[i],
1225 set_cpus_allowed_ptr(barrier_task, shuffle_tmp_mask);
1227 if (rcu_idle_cpu == -1)
1228 rcu_idle_cpu = num_online_cpus() - 1;
1235 /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1236 * system to become idle at a time and cut off its timer ticks. This is meant
1237 * to test the support for such tickless idle CPU in RCU.
1240 rcu_torture_shuffle(void *arg)
1242 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1244 schedule_timeout_interruptible(shuffle_interval * HZ);
1245 rcu_torture_shuffle_tasks();
1246 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1247 } while (!kthread_should_stop());
1248 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1252 /* Cause the rcutorture test to "stutter", starting and stopping all
1253 * threads periodically.
1256 rcu_torture_stutter(void *arg)
1258 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1260 schedule_timeout_interruptible(stutter * HZ);
1261 stutter_pause_test = 1;
1262 if (!kthread_should_stop())
1263 schedule_timeout_interruptible(stutter * HZ);
1264 stutter_pause_test = 0;
1265 rcutorture_shutdown_absorb("rcu_torture_stutter");
1266 } while (!kthread_should_stop());
1267 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1272 rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag)
1274 pr_alert("%s" TORTURE_FLAG
1275 "--- %s: nreaders=%d nfakewriters=%d "
1276 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1277 "shuffle_interval=%d stutter=%d irqreader=%d "
1278 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1279 "test_boost=%d/%d test_boost_interval=%d "
1280 "test_boost_duration=%d shutdown_secs=%d "
1281 "stall_cpu=%d stall_cpu_holdoff=%d "
1283 "onoff_interval=%d onoff_holdoff=%d\n",
1284 torture_type, tag, nrealreaders, nfakewriters,
1285 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
1286 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1287 test_boost, cur_ops->can_boost,
1288 test_boost_interval, test_boost_duration, shutdown_secs,
1289 stall_cpu, stall_cpu_holdoff,
1291 onoff_interval, onoff_holdoff);
1294 static struct notifier_block rcutorture_shutdown_nb = {
1295 .notifier_call = rcutorture_shutdown_notify,
1298 static void rcutorture_booster_cleanup(int cpu)
1300 struct task_struct *t;
1302 if (boost_tasks[cpu] == NULL)
1304 mutex_lock(&boost_mutex);
1305 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1306 t = boost_tasks[cpu];
1307 boost_tasks[cpu] = NULL;
1308 mutex_unlock(&boost_mutex);
1310 /* This must be outside of the mutex, otherwise deadlock! */
1312 boost_tasks[cpu] = NULL;
1315 static int rcutorture_booster_init(int cpu)
1319 if (boost_tasks[cpu] != NULL)
1320 return 0; /* Already created, nothing more to do. */
1322 /* Don't allow time recalculation while creating a new task. */
1323 mutex_lock(&boost_mutex);
1324 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
1325 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1327 "rcu_torture_boost");
1328 if (IS_ERR(boost_tasks[cpu])) {
1329 retval = PTR_ERR(boost_tasks[cpu]);
1330 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1331 n_rcu_torture_boost_ktrerror++;
1332 boost_tasks[cpu] = NULL;
1333 mutex_unlock(&boost_mutex);
1336 kthread_bind(boost_tasks[cpu], cpu);
1337 wake_up_process(boost_tasks[cpu]);
1338 mutex_unlock(&boost_mutex);
1343 * Cause the rcutorture test to shutdown the system after the test has
1344 * run for the time specified by the shutdown_secs module parameter.
1347 rcu_torture_shutdown(void *arg)
1350 unsigned long jiffies_snap;
1352 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1353 jiffies_snap = ACCESS_ONCE(jiffies);
1354 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
1355 !kthread_should_stop()) {
1356 delta = shutdown_time - jiffies_snap;
1358 pr_alert("%s" TORTURE_FLAG
1359 "rcu_torture_shutdown task: %lu jiffies remaining\n",
1360 torture_type, delta);
1361 schedule_timeout_interruptible(delta);
1362 jiffies_snap = ACCESS_ONCE(jiffies);
1364 if (kthread_should_stop()) {
1365 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1369 /* OK, shut down the system. */
1371 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1372 shutdown_task = NULL; /* Avoid self-kill deadlock. */
1373 rcu_torture_cleanup(); /* Get the success/failure message. */
1374 kernel_power_off(); /* Shut down the system. */
1378 #ifdef CONFIG_HOTPLUG_CPU
1381 * Execute random CPU-hotplug operations at the interval specified
1382 * by the onoff_interval.
1385 rcu_torture_onoff(void *arg)
1388 unsigned long delta;
1390 DEFINE_RCU_RANDOM(rand);
1392 unsigned long starttime;
1394 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1395 for_each_online_cpu(cpu)
1397 WARN_ON(maxcpu < 0);
1398 if (onoff_holdoff > 0) {
1399 VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff");
1400 schedule_timeout_interruptible(onoff_holdoff * HZ);
1401 VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff");
1403 while (!kthread_should_stop()) {
1404 cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
1405 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) {
1407 pr_alert("%s" TORTURE_FLAG
1408 "rcu_torture_onoff task: offlining %d\n",
1410 starttime = jiffies;
1411 n_offline_attempts++;
1412 ret = cpu_down(cpu);
1415 pr_alert("%s" TORTURE_FLAG
1416 "rcu_torture_onoff task: offline %d failed: errno %d\n",
1417 torture_type, cpu, ret);
1420 pr_alert("%s" TORTURE_FLAG
1421 "rcu_torture_onoff task: offlined %d\n",
1423 n_offline_successes++;
1424 delta = jiffies - starttime;
1425 sum_offline += delta;
1426 if (min_offline < 0) {
1427 min_offline = delta;
1428 max_offline = delta;
1430 if (min_offline > delta)
1431 min_offline = delta;
1432 if (max_offline < delta)
1433 max_offline = delta;
1435 } else if (cpu_is_hotpluggable(cpu)) {
1437 pr_alert("%s" TORTURE_FLAG
1438 "rcu_torture_onoff task: onlining %d\n",
1440 starttime = jiffies;
1441 n_online_attempts++;
1442 if (cpu_up(cpu) == 0) {
1444 pr_alert("%s" TORTURE_FLAG
1445 "rcu_torture_onoff task: onlined %d\n",
1447 n_online_successes++;
1448 delta = jiffies - starttime;
1449 sum_online += delta;
1450 if (min_online < 0) {
1454 if (min_online > delta)
1456 if (max_online < delta)
1460 schedule_timeout_interruptible(onoff_interval * HZ);
1462 VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1467 rcu_torture_onoff_init(void)
1471 if (onoff_interval <= 0)
1473 onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff");
1474 if (IS_ERR(onoff_task)) {
1475 ret = PTR_ERR(onoff_task);
1482 static void rcu_torture_onoff_cleanup(void)
1484 if (onoff_task == NULL)
1486 VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1487 kthread_stop(onoff_task);
1491 #else /* #ifdef CONFIG_HOTPLUG_CPU */
1494 rcu_torture_onoff_init(void)
1499 static void rcu_torture_onoff_cleanup(void)
1503 #endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1506 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1507 * induces a CPU stall for the time specified by stall_cpu.
1509 static int rcu_torture_stall(void *args)
1511 unsigned long stop_at;
1513 VERBOSE_PRINTK_STRING("rcu_torture_stall task started");
1514 if (stall_cpu_holdoff > 0) {
1515 VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff");
1516 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
1517 VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff");
1519 if (!kthread_should_stop()) {
1520 stop_at = get_seconds() + stall_cpu;
1521 /* RCU CPU stall is expected behavior in following code. */
1522 pr_alert("rcu_torture_stall start.\n");
1525 while (ULONG_CMP_LT(get_seconds(), stop_at))
1526 continue; /* Induce RCU CPU stall warning. */
1529 pr_alert("rcu_torture_stall end.\n");
1531 rcutorture_shutdown_absorb("rcu_torture_stall");
1532 while (!kthread_should_stop())
1533 schedule_timeout_interruptible(10 * HZ);
1537 /* Spawn CPU-stall kthread, if stall_cpu specified. */
1538 static int __init rcu_torture_stall_init(void)
1544 stall_task = kthread_run(rcu_torture_stall, NULL, "rcu_torture_stall");
1545 if (IS_ERR(stall_task)) {
1546 ret = PTR_ERR(stall_task);
1553 /* Clean up after the CPU-stall kthread, if one was spawned. */
1554 static void rcu_torture_stall_cleanup(void)
1556 if (stall_task == NULL)
1558 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task.");
1559 kthread_stop(stall_task);
1563 /* Callback function for RCU barrier testing. */
1564 void rcu_torture_barrier_cbf(struct rcu_head *rcu)
1566 atomic_inc(&barrier_cbs_invoked);
1569 /* kthread function to register callbacks used to test RCU barriers. */
1570 static int rcu_torture_barrier_cbs(void *arg)
1572 long myid = (long)arg;
1574 struct rcu_head rcu;
1576 init_rcu_head_on_stack(&rcu);
1577 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
1578 set_user_nice(current, 19);
1580 wait_event(barrier_cbs_wq[myid],
1581 barrier_phase != lastphase ||
1582 kthread_should_stop() ||
1583 fullstop != FULLSTOP_DONTSTOP);
1584 lastphase = barrier_phase;
1585 smp_mb(); /* ensure barrier_phase load before ->call(). */
1586 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1588 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1589 if (atomic_dec_and_test(&barrier_cbs_count))
1590 wake_up(&barrier_wq);
1591 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1592 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task stopping");
1593 rcutorture_shutdown_absorb("rcu_torture_barrier_cbs");
1594 while (!kthread_should_stop())
1595 schedule_timeout_interruptible(1);
1596 cur_ops->cb_barrier();
1597 destroy_rcu_head_on_stack(&rcu);
1601 /* kthread function to drive and coordinate RCU barrier testing. */
1602 static int rcu_torture_barrier(void *arg)
1606 VERBOSE_PRINTK_STRING("rcu_torture_barrier task starting");
1608 atomic_set(&barrier_cbs_invoked, 0);
1609 atomic_set(&barrier_cbs_count, n_barrier_cbs);
1610 smp_mb(); /* Ensure barrier_phase after prior assignments. */
1611 barrier_phase = !barrier_phase;
1612 for (i = 0; i < n_barrier_cbs; i++)
1613 wake_up(&barrier_cbs_wq[i]);
1614 wait_event(barrier_wq,
1615 atomic_read(&barrier_cbs_count) == 0 ||
1616 kthread_should_stop() ||
1617 fullstop != FULLSTOP_DONTSTOP);
1618 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1620 n_barrier_attempts++;
1621 cur_ops->cb_barrier();
1622 if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
1623 n_rcu_torture_barrier_error++;
1626 n_barrier_successes++;
1627 schedule_timeout_interruptible(HZ / 10);
1628 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1629 VERBOSE_PRINTK_STRING("rcu_torture_barrier task stopping");
1630 rcutorture_shutdown_absorb("rcu_torture_barrier");
1631 while (!kthread_should_stop())
1632 schedule_timeout_interruptible(1);
1636 /* Initialize RCU barrier testing. */
1637 static int rcu_torture_barrier_init(void)
1642 if (n_barrier_cbs == 0)
1644 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
1645 pr_alert("%s" TORTURE_FLAG
1646 " Call or barrier ops missing for %s,\n",
1647 torture_type, cur_ops->name);
1648 pr_alert("%s" TORTURE_FLAG
1649 " RCU barrier testing omitted from run.\n",
1653 atomic_set(&barrier_cbs_count, 0);
1654 atomic_set(&barrier_cbs_invoked, 0);
1656 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
1659 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
1661 if (barrier_cbs_tasks == NULL || !barrier_cbs_wq)
1663 for (i = 0; i < n_barrier_cbs; i++) {
1664 init_waitqueue_head(&barrier_cbs_wq[i]);
1665 barrier_cbs_tasks[i] = kthread_run(rcu_torture_barrier_cbs,
1667 "rcu_torture_barrier_cbs");
1668 if (IS_ERR(barrier_cbs_tasks[i])) {
1669 ret = PTR_ERR(barrier_cbs_tasks[i]);
1670 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier_cbs");
1671 barrier_cbs_tasks[i] = NULL;
1675 barrier_task = kthread_run(rcu_torture_barrier, NULL,
1676 "rcu_torture_barrier");
1677 if (IS_ERR(barrier_task)) {
1678 ret = PTR_ERR(barrier_task);
1679 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier");
1680 barrier_task = NULL;
1685 /* Clean up after RCU barrier testing. */
1686 static void rcu_torture_barrier_cleanup(void)
1690 if (barrier_task != NULL) {
1691 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier task");
1692 kthread_stop(barrier_task);
1693 barrier_task = NULL;
1695 if (barrier_cbs_tasks != NULL) {
1696 for (i = 0; i < n_barrier_cbs; i++) {
1697 if (barrier_cbs_tasks[i] != NULL) {
1698 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier_cbs task");
1699 kthread_stop(barrier_cbs_tasks[i]);
1700 barrier_cbs_tasks[i] = NULL;
1703 kfree(barrier_cbs_tasks);
1704 barrier_cbs_tasks = NULL;
1706 if (barrier_cbs_wq != NULL) {
1707 kfree(barrier_cbs_wq);
1708 barrier_cbs_wq = NULL;
1712 static int rcutorture_cpu_notify(struct notifier_block *self,
1713 unsigned long action, void *hcpu)
1715 long cpu = (long)hcpu;
1719 case CPU_DOWN_FAILED:
1720 (void)rcutorture_booster_init(cpu);
1722 case CPU_DOWN_PREPARE:
1723 rcutorture_booster_cleanup(cpu);
1731 static struct notifier_block rcutorture_cpu_nb = {
1732 .notifier_call = rcutorture_cpu_notify,
1736 rcu_torture_cleanup(void)
1740 mutex_lock(&fullstop_mutex);
1741 rcutorture_record_test_transition();
1742 if (fullstop == FULLSTOP_SHUTDOWN) {
1743 pr_warn(/* but going down anyway, so... */
1744 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
1745 mutex_unlock(&fullstop_mutex);
1746 schedule_timeout_uninterruptible(10);
1747 if (cur_ops->cb_barrier != NULL)
1748 cur_ops->cb_barrier();
1751 fullstop = FULLSTOP_RMMOD;
1752 mutex_unlock(&fullstop_mutex);
1753 unregister_reboot_notifier(&rcutorture_shutdown_nb);
1754 rcu_torture_barrier_cleanup();
1755 rcu_torture_stall_cleanup();
1757 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1758 kthread_stop(stutter_task);
1760 stutter_task = NULL;
1761 if (shuffler_task) {
1762 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1763 kthread_stop(shuffler_task);
1764 free_cpumask_var(shuffle_tmp_mask);
1766 shuffler_task = NULL;
1769 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1770 kthread_stop(writer_task);
1775 for (i = 0; i < nrealreaders; i++) {
1776 if (reader_tasks[i]) {
1777 VERBOSE_PRINTK_STRING(
1778 "Stopping rcu_torture_reader task");
1779 kthread_stop(reader_tasks[i]);
1781 reader_tasks[i] = NULL;
1783 kfree(reader_tasks);
1784 reader_tasks = NULL;
1786 rcu_torture_current = NULL;
1788 if (fakewriter_tasks) {
1789 for (i = 0; i < nfakewriters; i++) {
1790 if (fakewriter_tasks[i]) {
1791 VERBOSE_PRINTK_STRING(
1792 "Stopping rcu_torture_fakewriter task");
1793 kthread_stop(fakewriter_tasks[i]);
1795 fakewriter_tasks[i] = NULL;
1797 kfree(fakewriter_tasks);
1798 fakewriter_tasks = NULL;
1802 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1803 kthread_stop(stats_task);
1808 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1809 kthread_stop(fqs_task);
1812 if ((test_boost == 1 && cur_ops->can_boost) ||
1814 unregister_cpu_notifier(&rcutorture_cpu_nb);
1815 for_each_possible_cpu(i)
1816 rcutorture_booster_cleanup(i);
1818 if (shutdown_task != NULL) {
1819 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1820 kthread_stop(shutdown_task);
1822 shutdown_task = NULL;
1823 rcu_torture_onoff_cleanup();
1825 /* Wait for all RCU callbacks to fire. */
1827 if (cur_ops->cb_barrier != NULL)
1828 cur_ops->cb_barrier();
1830 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
1832 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
1833 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
1834 else if (n_online_successes != n_online_attempts ||
1835 n_offline_successes != n_offline_attempts)
1836 rcu_torture_print_module_parms(cur_ops,
1837 "End of test: RCU_HOTPLUG");
1839 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
1842 #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1843 static void rcu_torture_leak_cb(struct rcu_head *rhp)
1847 static void rcu_torture_err_cb(struct rcu_head *rhp)
1850 * This -might- happen due to race conditions, but is unlikely.
1851 * The scenario that leads to this happening is that the
1852 * first of the pair of duplicate callbacks is queued,
1853 * someone else starts a grace period that includes that
1854 * callback, then the second of the pair must wait for the
1855 * next grace period. Unlikely, but can happen. If it
1856 * does happen, the debug-objects subsystem won't have splatted.
1858 pr_alert("rcutorture: duplicated callback was invoked.\n");
1860 #endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1863 * Verify that double-free causes debug-objects to complain, but only
1864 * if CONFIG_DEBUG_OBJECTS_RCU_HEAD=y. Otherwise, say that the test
1865 * cannot be carried out.
1867 static void rcu_test_debug_objects(void)
1869 #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1870 struct rcu_head rh1;
1871 struct rcu_head rh2;
1873 init_rcu_head_on_stack(&rh1);
1874 init_rcu_head_on_stack(&rh2);
1875 pr_alert("rcutorture: WARN: Duplicate call_rcu() test starting.\n");
1877 /* Try to queue the rh2 pair of callbacks for the same grace period. */
1878 preempt_disable(); /* Prevent preemption from interrupting test. */
1879 rcu_read_lock(); /* Make it impossible to finish a grace period. */
1880 call_rcu(&rh1, rcu_torture_leak_cb); /* Start grace period. */
1881 local_irq_disable(); /* Make it harder to start a new grace period. */
1882 call_rcu(&rh2, rcu_torture_leak_cb);
1883 call_rcu(&rh2, rcu_torture_err_cb); /* Duplicate callback. */
1888 /* Wait for them all to get done so we can safely return. */
1890 pr_alert("rcutorture: WARN: Duplicate call_rcu() test complete.\n");
1891 destroy_rcu_head_on_stack(&rh1);
1892 destroy_rcu_head_on_stack(&rh2);
1893 #else /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1894 pr_alert("rcutorture: !CONFIG_DEBUG_OBJECTS_RCU_HEAD, not testing duplicate call_rcu()\n");
1895 #endif /* #else #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1899 rcu_torture_init(void)
1905 static struct rcu_torture_ops *torture_ops[] = {
1906 &rcu_ops, &rcu_bh_ops, &srcu_ops, &sched_ops,
1909 mutex_lock(&fullstop_mutex);
1911 /* Process args and tell the world that the torturer is on the job. */
1912 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
1913 cur_ops = torture_ops[i];
1914 if (strcmp(torture_type, cur_ops->name) == 0)
1917 if (i == ARRAY_SIZE(torture_ops)) {
1918 pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
1920 pr_alert("rcu-torture types:");
1921 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
1922 pr_alert(" %s", torture_ops[i]->name);
1924 mutex_unlock(&fullstop_mutex);
1927 if (cur_ops->fqs == NULL && fqs_duration != 0) {
1928 pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
1932 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1935 nrealreaders = nreaders;
1937 nrealreaders = 2 * num_online_cpus();
1938 rcu_torture_print_module_parms(cur_ops, "Start of test");
1939 fullstop = FULLSTOP_DONTSTOP;
1941 /* Set up the freelist. */
1943 INIT_LIST_HEAD(&rcu_torture_freelist);
1944 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
1945 rcu_tortures[i].rtort_mbtest = 0;
1946 list_add_tail(&rcu_tortures[i].rtort_free,
1947 &rcu_torture_freelist);
1950 /* Initialize the statistics so that each run gets its own numbers. */
1952 rcu_torture_current = NULL;
1953 rcu_torture_current_version = 0;
1954 atomic_set(&n_rcu_torture_alloc, 0);
1955 atomic_set(&n_rcu_torture_alloc_fail, 0);
1956 atomic_set(&n_rcu_torture_free, 0);
1957 atomic_set(&n_rcu_torture_mberror, 0);
1958 atomic_set(&n_rcu_torture_error, 0);
1959 n_rcu_torture_barrier_error = 0;
1960 n_rcu_torture_boost_ktrerror = 0;
1961 n_rcu_torture_boost_rterror = 0;
1962 n_rcu_torture_boost_failure = 0;
1963 n_rcu_torture_boosts = 0;
1964 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1965 atomic_set(&rcu_torture_wcount[i], 0);
1966 for_each_possible_cpu(cpu) {
1967 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1968 per_cpu(rcu_torture_count, cpu)[i] = 0;
1969 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1973 /* Start up the kthreads. */
1975 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1976 writer_task = kthread_create(rcu_torture_writer, NULL,
1977 "rcu_torture_writer");
1978 if (IS_ERR(writer_task)) {
1979 firsterr = PTR_ERR(writer_task);
1980 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1984 wake_up_process(writer_task);
1985 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
1987 if (fakewriter_tasks == NULL) {
1988 VERBOSE_PRINTK_ERRSTRING("out of memory");
1992 for (i = 0; i < nfakewriters; i++) {
1993 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
1994 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
1995 "rcu_torture_fakewriter");
1996 if (IS_ERR(fakewriter_tasks[i])) {
1997 firsterr = PTR_ERR(fakewriter_tasks[i]);
1998 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
1999 fakewriter_tasks[i] = NULL;
2003 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
2005 if (reader_tasks == NULL) {
2006 VERBOSE_PRINTK_ERRSTRING("out of memory");
2010 for (i = 0; i < nrealreaders; i++) {
2011 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
2012 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
2013 "rcu_torture_reader");
2014 if (IS_ERR(reader_tasks[i])) {
2015 firsterr = PTR_ERR(reader_tasks[i]);
2016 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
2017 reader_tasks[i] = NULL;
2021 if (stat_interval > 0) {
2022 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
2023 stats_task = kthread_run(rcu_torture_stats, NULL,
2024 "rcu_torture_stats");
2025 if (IS_ERR(stats_task)) {
2026 firsterr = PTR_ERR(stats_task);
2027 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
2032 if (test_no_idle_hz) {
2033 rcu_idle_cpu = num_online_cpus() - 1;
2035 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
2037 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
2041 /* Create the shuffler thread */
2042 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
2043 "rcu_torture_shuffle");
2044 if (IS_ERR(shuffler_task)) {
2045 free_cpumask_var(shuffle_tmp_mask);
2046 firsterr = PTR_ERR(shuffler_task);
2047 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
2048 shuffler_task = NULL;
2055 /* Create the stutter thread */
2056 stutter_task = kthread_run(rcu_torture_stutter, NULL,
2057 "rcu_torture_stutter");
2058 if (IS_ERR(stutter_task)) {
2059 firsterr = PTR_ERR(stutter_task);
2060 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
2061 stutter_task = NULL;
2065 if (fqs_duration < 0)
2068 /* Create the stutter thread */
2069 fqs_task = kthread_run(rcu_torture_fqs, NULL,
2071 if (IS_ERR(fqs_task)) {
2072 firsterr = PTR_ERR(fqs_task);
2073 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
2078 if (test_boost_interval < 1)
2079 test_boost_interval = 1;
2080 if (test_boost_duration < 2)
2081 test_boost_duration = 2;
2082 if ((test_boost == 1 && cur_ops->can_boost) ||
2085 boost_starttime = jiffies + test_boost_interval * HZ;
2086 register_cpu_notifier(&rcutorture_cpu_nb);
2087 for_each_possible_cpu(i) {
2088 if (cpu_is_offline(i))
2089 continue; /* Heuristic: CPU can go offline. */
2090 retval = rcutorture_booster_init(i);
2097 if (shutdown_secs > 0) {
2098 shutdown_time = jiffies + shutdown_secs * HZ;
2099 shutdown_task = kthread_create(rcu_torture_shutdown, NULL,
2100 "rcu_torture_shutdown");
2101 if (IS_ERR(shutdown_task)) {
2102 firsterr = PTR_ERR(shutdown_task);
2103 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
2104 shutdown_task = NULL;
2107 wake_up_process(shutdown_task);
2109 i = rcu_torture_onoff_init();
2114 register_reboot_notifier(&rcutorture_shutdown_nb);
2115 i = rcu_torture_stall_init();
2120 retval = rcu_torture_barrier_init();
2126 rcu_test_debug_objects();
2127 rcutorture_record_test_transition();
2128 mutex_unlock(&fullstop_mutex);
2132 mutex_unlock(&fullstop_mutex);
2133 rcu_torture_cleanup();
2137 module_init(rcu_torture_init);
2138 module_exit(rcu_torture_cleanup);