2 * Read-Copy Update module-based torture test facility
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * Copyright (C) IBM Corporation, 2005, 2006
20 * Authors: Paul E. McKenney <paulmck@us.ibm.com>
21 * Josh Triplett <josh@freedesktop.org>
23 * See also: Documentation/RCU/torture.txt
25 #include <linux/types.h>
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/module.h>
29 #include <linux/kthread.h>
30 #include <linux/err.h>
31 #include <linux/spinlock.h>
32 #include <linux/smp.h>
33 #include <linux/rcupdate.h>
34 #include <linux/interrupt.h>
35 #include <linux/sched.h>
36 #include <linux/atomic.h>
37 #include <linux/bitops.h>
38 #include <linux/completion.h>
39 #include <linux/moduleparam.h>
40 #include <linux/percpu.h>
41 #include <linux/notifier.h>
42 #include <linux/reboot.h>
43 #include <linux/freezer.h>
44 #include <linux/cpu.h>
45 #include <linux/delay.h>
46 #include <linux/stat.h>
47 #include <linux/srcu.h>
48 #include <linux/slab.h>
49 #include <asm/byteorder.h>
51 MODULE_LICENSE("GPL");
52 MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@freedesktop.org>");
54 static int nreaders = -1; /* # reader threads, defaults to 2*ncpus */
55 static int nfakewriters = 4; /* # fake writer threads */
56 static int stat_interval = 60; /* Interval between stats, in seconds. */
57 /* Zero means "only at end of test". */
58 static bool verbose; /* Print more debug info. */
59 static bool test_no_idle_hz = true;
60 /* Test RCU support for tickless idle CPUs. */
61 static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/
62 static int stutter = 5; /* Start/stop testing interval (in sec) */
63 static int irqreader = 1; /* RCU readers from irq (timers). */
64 static int fqs_duration; /* Duration of bursts (us), 0 to disable. */
65 static int fqs_holdoff; /* Hold time within burst (us). */
66 static int fqs_stutter = 3; /* Wait time between bursts (s). */
67 static int n_barrier_cbs; /* Number of callbacks to test RCU barriers. */
68 static int onoff_interval; /* Wait time between CPU hotplugs, 0=disable. */
69 static int onoff_holdoff; /* Seconds after boot before CPU hotplugs. */
70 static int shutdown_secs; /* Shutdown time (s). <=0 for no shutdown. */
71 static int stall_cpu; /* CPU-stall duration (s). 0 for no stall. */
72 static int stall_cpu_holdoff = 10; /* Time to wait until stall (s). */
73 static int test_boost = 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */
74 static int test_boost_interval = 7; /* Interval between boost tests, seconds. */
75 static int test_boost_duration = 4; /* Duration of each boost test, seconds. */
76 static char *torture_type = "rcu"; /* What RCU implementation to torture. */
78 module_param(nreaders, int, 0444);
79 MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
80 module_param(nfakewriters, int, 0444);
81 MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
82 module_param(stat_interval, int, 0644);
83 MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
84 module_param(verbose, bool, 0444);
85 MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
86 module_param(test_no_idle_hz, bool, 0444);
87 MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
88 module_param(shuffle_interval, int, 0444);
89 MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
90 module_param(stutter, int, 0444);
91 MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
92 module_param(irqreader, int, 0444);
93 MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
94 module_param(fqs_duration, int, 0444);
95 MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us)");
96 module_param(fqs_holdoff, int, 0444);
97 MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)");
98 module_param(fqs_stutter, int, 0444);
99 MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)");
100 module_param(n_barrier_cbs, int, 0444);
101 MODULE_PARM_DESC(n_barrier_cbs, "# of callbacks/kthreads for barrier testing");
102 module_param(onoff_interval, int, 0444);
103 MODULE_PARM_DESC(onoff_interval, "Time between CPU hotplugs (s), 0=disable");
104 module_param(onoff_holdoff, int, 0444);
105 MODULE_PARM_DESC(onoff_holdoff, "Time after boot before CPU hotplugs (s)");
106 module_param(shutdown_secs, int, 0444);
107 MODULE_PARM_DESC(shutdown_secs, "Shutdown time (s), zero to disable.");
108 module_param(stall_cpu, int, 0444);
109 MODULE_PARM_DESC(stall_cpu, "Stall duration (s), zero to disable.");
110 module_param(stall_cpu_holdoff, int, 0444);
111 MODULE_PARM_DESC(stall_cpu_holdoff, "Time to wait before starting stall (s).");
112 module_param(test_boost, int, 0444);
113 MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
114 module_param(test_boost_interval, int, 0444);
115 MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds.");
116 module_param(test_boost_duration, int, 0444);
117 MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds.");
118 module_param(torture_type, charp, 0444);
119 MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
121 #define TORTURE_FLAG "-torture:"
122 #define PRINTK_STRING(s) \
123 do { pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
124 #define VERBOSE_PRINTK_STRING(s) \
125 do { if (verbose) pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
126 #define VERBOSE_PRINTK_ERRSTRING(s) \
127 do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
129 static char printk_buf[4096];
131 static int nrealreaders;
132 static struct task_struct *writer_task;
133 static struct task_struct **fakewriter_tasks;
134 static struct task_struct **reader_tasks;
135 static struct task_struct *stats_task;
136 static struct task_struct *shuffler_task;
137 static struct task_struct *stutter_task;
138 static struct task_struct *fqs_task;
139 static struct task_struct *boost_tasks[NR_CPUS];
140 static struct task_struct *shutdown_task;
141 #ifdef CONFIG_HOTPLUG_CPU
142 static struct task_struct *onoff_task;
143 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
144 static struct task_struct *stall_task;
145 static struct task_struct **barrier_cbs_tasks;
146 static struct task_struct *barrier_task;
148 #define RCU_TORTURE_PIPE_LEN 10
151 struct rcu_head rtort_rcu;
152 int rtort_pipe_count;
153 struct list_head rtort_free;
157 static LIST_HEAD(rcu_torture_freelist);
158 static struct rcu_torture __rcu *rcu_torture_current;
159 static unsigned long rcu_torture_current_version;
160 static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
161 static DEFINE_SPINLOCK(rcu_torture_lock);
162 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
164 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
166 static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
167 static atomic_t n_rcu_torture_alloc;
168 static atomic_t n_rcu_torture_alloc_fail;
169 static atomic_t n_rcu_torture_free;
170 static atomic_t n_rcu_torture_mberror;
171 static atomic_t n_rcu_torture_error;
172 static long n_rcu_torture_barrier_error;
173 static long n_rcu_torture_boost_ktrerror;
174 static long n_rcu_torture_boost_rterror;
175 static long n_rcu_torture_boost_failure;
176 static long n_rcu_torture_boosts;
177 static long n_rcu_torture_timers;
178 static long n_offline_attempts;
179 static long n_offline_successes;
180 static unsigned long sum_offline;
181 static int min_offline = -1;
182 static int max_offline;
183 static long n_online_attempts;
184 static long n_online_successes;
185 static unsigned long sum_online;
186 static int min_online = -1;
187 static int max_online;
188 static long n_barrier_attempts;
189 static long n_barrier_successes;
190 static struct list_head rcu_torture_removed;
191 static cpumask_var_t shuffle_tmp_mask;
193 static int stutter_pause_test;
195 #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
196 #define RCUTORTURE_RUNNABLE_INIT 1
198 #define RCUTORTURE_RUNNABLE_INIT 0
200 int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
201 module_param(rcutorture_runnable, int, 0444);
202 MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot");
204 #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
205 #define rcu_can_boost() 1
206 #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
207 #define rcu_can_boost() 0
208 #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
210 static unsigned long shutdown_time; /* jiffies to system shutdown. */
211 static unsigned long boost_starttime; /* jiffies of next boost test start. */
212 DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
213 /* and boost task create/destroy. */
214 static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */
215 static bool barrier_phase; /* Test phase. */
216 static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */
217 static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */
218 static DECLARE_WAIT_QUEUE_HEAD(barrier_wq);
220 /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
222 #define FULLSTOP_DONTSTOP 0 /* Normal operation. */
223 #define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
224 #define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
225 static int fullstop = FULLSTOP_RMMOD;
227 * Protect fullstop transitions and spawning of kthreads.
229 static DEFINE_MUTEX(fullstop_mutex);
231 /* Forward reference. */
232 static void rcu_torture_cleanup(void);
235 * Detect and respond to a system shutdown.
238 rcutorture_shutdown_notify(struct notifier_block *unused1,
239 unsigned long unused2, void *unused3)
241 mutex_lock(&fullstop_mutex);
242 if (fullstop == FULLSTOP_DONTSTOP)
243 fullstop = FULLSTOP_SHUTDOWN;
245 pr_warn(/* but going down anyway, so... */
246 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
247 mutex_unlock(&fullstop_mutex);
252 * Absorb kthreads into a kernel function that won't return, so that
253 * they won't ever access module text or data again.
255 static void rcutorture_shutdown_absorb(char *title)
257 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
259 "rcutorture thread %s parking due to system shutdown\n",
261 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
266 * Allocate an element from the rcu_tortures pool.
268 static struct rcu_torture *
269 rcu_torture_alloc(void)
273 spin_lock_bh(&rcu_torture_lock);
274 if (list_empty(&rcu_torture_freelist)) {
275 atomic_inc(&n_rcu_torture_alloc_fail);
276 spin_unlock_bh(&rcu_torture_lock);
279 atomic_inc(&n_rcu_torture_alloc);
280 p = rcu_torture_freelist.next;
282 spin_unlock_bh(&rcu_torture_lock);
283 return container_of(p, struct rcu_torture, rtort_free);
287 * Free an element to the rcu_tortures pool.
290 rcu_torture_free(struct rcu_torture *p)
292 atomic_inc(&n_rcu_torture_free);
293 spin_lock_bh(&rcu_torture_lock);
294 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
295 spin_unlock_bh(&rcu_torture_lock);
298 struct rcu_random_state {
299 unsigned long rrs_state;
303 #define RCU_RANDOM_MULT 39916801 /* prime */
304 #define RCU_RANDOM_ADD 479001701 /* prime */
305 #define RCU_RANDOM_REFRESH 10000
307 #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
310 * Crude but fast random-number generator. Uses a linear congruential
311 * generator, with occasional help from cpu_clock().
314 rcu_random(struct rcu_random_state *rrsp)
316 if (--rrsp->rrs_count < 0) {
317 rrsp->rrs_state += (unsigned long)local_clock();
318 rrsp->rrs_count = RCU_RANDOM_REFRESH;
320 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
321 return swahw32(rrsp->rrs_state);
325 rcu_stutter_wait(char *title)
327 while (stutter_pause_test || !rcutorture_runnable) {
328 if (rcutorture_runnable)
329 schedule_timeout_interruptible(1);
331 schedule_timeout_interruptible(round_jiffies_relative(HZ));
332 rcutorture_shutdown_absorb(title);
337 * Operations vector for selecting different types of tests.
340 struct rcu_torture_ops {
342 void (*cleanup)(void);
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 = {
435 .readlock = rcu_torture_read_lock,
436 .read_delay = rcu_read_delay,
437 .readunlock = rcu_torture_read_unlock,
438 .completed = rcu_torture_completed,
439 .deferred_free = rcu_torture_deferred_free,
440 .sync = synchronize_rcu,
442 .cb_barrier = rcu_barrier,
443 .fqs = rcu_force_quiescent_state,
446 .can_boost = rcu_can_boost(),
450 static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
453 struct rcu_torture *rp;
454 struct rcu_torture *rp1;
457 list_add(&p->rtort_free, &rcu_torture_removed);
458 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
459 i = rp->rtort_pipe_count;
460 if (i > RCU_TORTURE_PIPE_LEN)
461 i = RCU_TORTURE_PIPE_LEN;
462 atomic_inc(&rcu_torture_wcount[i]);
463 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
464 rp->rtort_mbtest = 0;
465 list_del(&rp->rtort_free);
466 rcu_torture_free(rp);
471 static void rcu_sync_torture_init(void)
473 INIT_LIST_HEAD(&rcu_torture_removed);
476 static struct rcu_torture_ops rcu_sync_ops = {
477 .init = rcu_sync_torture_init,
479 .readlock = rcu_torture_read_lock,
480 .read_delay = rcu_read_delay,
481 .readunlock = rcu_torture_read_unlock,
482 .completed = rcu_torture_completed,
483 .deferred_free = rcu_sync_torture_deferred_free,
484 .sync = synchronize_rcu,
487 .fqs = rcu_force_quiescent_state,
490 .can_boost = rcu_can_boost(),
494 static struct rcu_torture_ops rcu_expedited_ops = {
495 .init = rcu_sync_torture_init,
497 .readlock = rcu_torture_read_lock,
498 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
499 .readunlock = rcu_torture_read_unlock,
500 .completed = rcu_no_completed,
501 .deferred_free = rcu_sync_torture_deferred_free,
502 .sync = synchronize_rcu_expedited,
505 .fqs = rcu_force_quiescent_state,
508 .can_boost = rcu_can_boost(),
509 .name = "rcu_expedited"
513 * Definitions for rcu_bh torture testing.
516 static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
522 static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
524 rcu_read_unlock_bh();
527 static int rcu_bh_torture_completed(void)
529 return rcu_batches_completed_bh();
532 static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
534 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
537 static struct rcu_torture_ops rcu_bh_ops = {
540 .readlock = rcu_bh_torture_read_lock,
541 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
542 .readunlock = rcu_bh_torture_read_unlock,
543 .completed = rcu_bh_torture_completed,
544 .deferred_free = rcu_bh_torture_deferred_free,
545 .sync = synchronize_rcu_bh,
547 .cb_barrier = rcu_barrier_bh,
548 .fqs = rcu_bh_force_quiescent_state,
554 static struct rcu_torture_ops rcu_bh_sync_ops = {
555 .init = rcu_sync_torture_init,
557 .readlock = rcu_bh_torture_read_lock,
558 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
559 .readunlock = rcu_bh_torture_read_unlock,
560 .completed = rcu_bh_torture_completed,
561 .deferred_free = rcu_sync_torture_deferred_free,
562 .sync = synchronize_rcu_bh,
565 .fqs = rcu_bh_force_quiescent_state,
568 .name = "rcu_bh_sync"
571 static struct rcu_torture_ops rcu_bh_expedited_ops = {
572 .init = rcu_sync_torture_init,
574 .readlock = rcu_bh_torture_read_lock,
575 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
576 .readunlock = rcu_bh_torture_read_unlock,
577 .completed = rcu_bh_torture_completed,
578 .deferred_free = rcu_sync_torture_deferred_free,
579 .sync = synchronize_rcu_bh_expedited,
582 .fqs = rcu_bh_force_quiescent_state,
585 .name = "rcu_bh_expedited"
589 * Definitions for srcu torture testing.
592 static struct srcu_struct srcu_ctl;
594 static void srcu_torture_init(void)
596 init_srcu_struct(&srcu_ctl);
597 rcu_sync_torture_init();
600 static void srcu_torture_cleanup(void)
602 synchronize_srcu(&srcu_ctl);
603 cleanup_srcu_struct(&srcu_ctl);
606 static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
608 return srcu_read_lock(&srcu_ctl);
611 static void srcu_read_delay(struct rcu_random_state *rrsp)
614 const long uspertick = 1000000 / HZ;
615 const long longdelay = 10;
617 /* We want there to be long-running readers, but not all the time. */
619 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
621 schedule_timeout_interruptible(longdelay);
623 rcu_read_delay(rrsp);
626 static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
628 srcu_read_unlock(&srcu_ctl, idx);
631 static int srcu_torture_completed(void)
633 return srcu_batches_completed(&srcu_ctl);
636 static void srcu_torture_deferred_free(struct rcu_torture *rp)
638 call_srcu(&srcu_ctl, &rp->rtort_rcu, rcu_torture_cb);
641 static void srcu_torture_synchronize(void)
643 synchronize_srcu(&srcu_ctl);
646 static void srcu_torture_call(struct rcu_head *head,
647 void (*func)(struct rcu_head *head))
649 call_srcu(&srcu_ctl, head, func);
652 static void srcu_torture_barrier(void)
654 srcu_barrier(&srcu_ctl);
657 static int srcu_torture_stats(char *page)
661 int idx = srcu_ctl.completed & 0x1;
663 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
664 torture_type, TORTURE_FLAG, idx);
665 for_each_possible_cpu(cpu) {
666 cnt += sprintf(&page[cnt], " %d(%lu,%lu)", cpu,
667 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
668 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
670 cnt += sprintf(&page[cnt], "\n");
674 static struct rcu_torture_ops srcu_ops = {
675 .init = srcu_torture_init,
676 .cleanup = srcu_torture_cleanup,
677 .readlock = srcu_torture_read_lock,
678 .read_delay = srcu_read_delay,
679 .readunlock = srcu_torture_read_unlock,
680 .completed = srcu_torture_completed,
681 .deferred_free = srcu_torture_deferred_free,
682 .sync = srcu_torture_synchronize,
683 .call = srcu_torture_call,
684 .cb_barrier = srcu_torture_barrier,
685 .stats = srcu_torture_stats,
689 static struct rcu_torture_ops srcu_sync_ops = {
690 .init = srcu_torture_init,
691 .cleanup = srcu_torture_cleanup,
692 .readlock = srcu_torture_read_lock,
693 .read_delay = srcu_read_delay,
694 .readunlock = srcu_torture_read_unlock,
695 .completed = srcu_torture_completed,
696 .deferred_free = rcu_sync_torture_deferred_free,
697 .sync = srcu_torture_synchronize,
700 .stats = srcu_torture_stats,
704 static int srcu_torture_read_lock_raw(void) __acquires(&srcu_ctl)
706 return srcu_read_lock_raw(&srcu_ctl);
709 static void srcu_torture_read_unlock_raw(int idx) __releases(&srcu_ctl)
711 srcu_read_unlock_raw(&srcu_ctl, idx);
714 static struct rcu_torture_ops srcu_raw_ops = {
715 .init = srcu_torture_init,
716 .cleanup = srcu_torture_cleanup,
717 .readlock = srcu_torture_read_lock_raw,
718 .read_delay = srcu_read_delay,
719 .readunlock = srcu_torture_read_unlock_raw,
720 .completed = srcu_torture_completed,
721 .deferred_free = srcu_torture_deferred_free,
722 .sync = srcu_torture_synchronize,
725 .stats = srcu_torture_stats,
729 static struct rcu_torture_ops srcu_raw_sync_ops = {
730 .init = srcu_torture_init,
731 .cleanup = srcu_torture_cleanup,
732 .readlock = srcu_torture_read_lock_raw,
733 .read_delay = srcu_read_delay,
734 .readunlock = srcu_torture_read_unlock_raw,
735 .completed = srcu_torture_completed,
736 .deferred_free = rcu_sync_torture_deferred_free,
737 .sync = srcu_torture_synchronize,
740 .stats = srcu_torture_stats,
741 .name = "srcu_raw_sync"
744 static void srcu_torture_synchronize_expedited(void)
746 synchronize_srcu_expedited(&srcu_ctl);
749 static struct rcu_torture_ops srcu_expedited_ops = {
750 .init = srcu_torture_init,
751 .cleanup = srcu_torture_cleanup,
752 .readlock = srcu_torture_read_lock,
753 .read_delay = srcu_read_delay,
754 .readunlock = srcu_torture_read_unlock,
755 .completed = srcu_torture_completed,
756 .deferred_free = rcu_sync_torture_deferred_free,
757 .sync = srcu_torture_synchronize_expedited,
760 .stats = srcu_torture_stats,
761 .name = "srcu_expedited"
765 * Definitions for sched torture testing.
768 static int sched_torture_read_lock(void)
774 static void sched_torture_read_unlock(int idx)
779 static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
781 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
784 static struct rcu_torture_ops sched_ops = {
785 .init = rcu_sync_torture_init,
787 .readlock = sched_torture_read_lock,
788 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
789 .readunlock = sched_torture_read_unlock,
790 .completed = rcu_no_completed,
791 .deferred_free = rcu_sched_torture_deferred_free,
792 .sync = synchronize_sched,
793 .cb_barrier = rcu_barrier_sched,
794 .fqs = rcu_sched_force_quiescent_state,
800 static struct rcu_torture_ops sched_sync_ops = {
801 .init = rcu_sync_torture_init,
803 .readlock = sched_torture_read_lock,
804 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
805 .readunlock = sched_torture_read_unlock,
806 .completed = rcu_no_completed,
807 .deferred_free = rcu_sync_torture_deferred_free,
808 .sync = synchronize_sched,
810 .fqs = rcu_sched_force_quiescent_state,
815 static struct rcu_torture_ops sched_expedited_ops = {
816 .init = rcu_sync_torture_init,
818 .readlock = sched_torture_read_lock,
819 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
820 .readunlock = sched_torture_read_unlock,
821 .completed = rcu_no_completed,
822 .deferred_free = rcu_sync_torture_deferred_free,
823 .sync = synchronize_sched_expedited,
825 .fqs = rcu_sched_force_quiescent_state,
828 .name = "sched_expedited"
832 * RCU torture priority-boost testing. Runs one real-time thread per
833 * CPU for moderate bursts, repeatedly registering RCU callbacks and
834 * spinning waiting for them to be invoked. If a given callback takes
835 * too long to be invoked, we assume that priority inversion has occurred.
838 struct rcu_boost_inflight {
843 static void rcu_torture_boost_cb(struct rcu_head *head)
845 struct rcu_boost_inflight *rbip =
846 container_of(head, struct rcu_boost_inflight, rcu);
848 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
852 static int rcu_torture_boost(void *arg)
854 unsigned long call_rcu_time;
855 unsigned long endtime;
856 unsigned long oldstarttime;
857 struct rcu_boost_inflight rbi = { .inflight = 0 };
858 struct sched_param sp;
860 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
862 /* Set real-time priority. */
863 sp.sched_priority = 1;
864 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
865 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
866 n_rcu_torture_boost_rterror++;
869 init_rcu_head_on_stack(&rbi.rcu);
870 /* Each pass through the following loop does one boost-test cycle. */
872 /* Wait for the next test interval. */
873 oldstarttime = boost_starttime;
874 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
875 schedule_timeout_uninterruptible(1);
876 rcu_stutter_wait("rcu_torture_boost");
877 if (kthread_should_stop() ||
878 fullstop != FULLSTOP_DONTSTOP)
882 /* Do one boost-test interval. */
883 endtime = oldstarttime + test_boost_duration * HZ;
884 call_rcu_time = jiffies;
885 while (ULONG_CMP_LT(jiffies, endtime)) {
886 /* If we don't have a callback in flight, post one. */
888 smp_mb(); /* RCU core before ->inflight = 1. */
890 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
891 if (jiffies - call_rcu_time >
892 test_boost_duration * HZ - HZ / 2) {
893 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
894 n_rcu_torture_boost_failure++;
896 call_rcu_time = jiffies;
899 rcu_stutter_wait("rcu_torture_boost");
900 if (kthread_should_stop() ||
901 fullstop != FULLSTOP_DONTSTOP)
906 * Set the start time of the next test interval.
907 * Yes, this is vulnerable to long delays, but such
908 * delays simply cause a false negative for the next
909 * interval. Besides, we are running at RT priority,
910 * so delays should be relatively rare.
912 while (oldstarttime == boost_starttime &&
913 !kthread_should_stop()) {
914 if (mutex_trylock(&boost_mutex)) {
915 boost_starttime = jiffies +
916 test_boost_interval * HZ;
917 n_rcu_torture_boosts++;
918 mutex_unlock(&boost_mutex);
921 schedule_timeout_uninterruptible(1);
924 /* Go do the stutter. */
925 checkwait: rcu_stutter_wait("rcu_torture_boost");
926 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
928 /* Clean up and exit. */
929 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
930 rcutorture_shutdown_absorb("rcu_torture_boost");
931 while (!kthread_should_stop() || rbi.inflight)
932 schedule_timeout_uninterruptible(1);
933 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
934 destroy_rcu_head_on_stack(&rbi.rcu);
939 * RCU torture force-quiescent-state kthread. Repeatedly induces
940 * bursts of calls to force_quiescent_state(), increasing the probability
941 * of occurrence of some important types of race conditions.
944 rcu_torture_fqs(void *arg)
946 unsigned long fqs_resume_time;
947 int fqs_burst_remaining;
949 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
951 fqs_resume_time = jiffies + fqs_stutter * HZ;
952 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
953 !kthread_should_stop()) {
954 schedule_timeout_interruptible(1);
956 fqs_burst_remaining = fqs_duration;
957 while (fqs_burst_remaining > 0 &&
958 !kthread_should_stop()) {
961 fqs_burst_remaining -= fqs_holdoff;
963 rcu_stutter_wait("rcu_torture_fqs");
964 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
965 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
966 rcutorture_shutdown_absorb("rcu_torture_fqs");
967 while (!kthread_should_stop())
968 schedule_timeout_uninterruptible(1);
973 * RCU torture writer kthread. Repeatedly substitutes a new structure
974 * for that pointed to by rcu_torture_current, freeing the old structure
975 * after a series of grace periods (the "pipeline").
978 rcu_torture_writer(void *arg)
981 long oldbatch = rcu_batches_completed();
982 struct rcu_torture *rp;
983 struct rcu_torture *old_rp;
984 static DEFINE_RCU_RANDOM(rand);
986 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
987 set_user_nice(current, 19);
990 schedule_timeout_uninterruptible(1);
991 rp = rcu_torture_alloc();
994 rp->rtort_pipe_count = 0;
995 udelay(rcu_random(&rand) & 0x3ff);
996 old_rp = rcu_dereference_check(rcu_torture_current,
997 current == writer_task);
998 rp->rtort_mbtest = 1;
999 rcu_assign_pointer(rcu_torture_current, rp);
1000 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
1002 i = old_rp->rtort_pipe_count;
1003 if (i > RCU_TORTURE_PIPE_LEN)
1004 i = RCU_TORTURE_PIPE_LEN;
1005 atomic_inc(&rcu_torture_wcount[i]);
1006 old_rp->rtort_pipe_count++;
1007 cur_ops->deferred_free(old_rp);
1009 rcutorture_record_progress(++rcu_torture_current_version);
1010 oldbatch = cur_ops->completed();
1011 rcu_stutter_wait("rcu_torture_writer");
1012 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1013 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
1014 rcutorture_shutdown_absorb("rcu_torture_writer");
1015 while (!kthread_should_stop())
1016 schedule_timeout_uninterruptible(1);
1021 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
1022 * delay between calls.
1025 rcu_torture_fakewriter(void *arg)
1027 DEFINE_RCU_RANDOM(rand);
1029 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
1030 set_user_nice(current, 19);
1033 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
1034 udelay(rcu_random(&rand) & 0x3ff);
1035 if (cur_ops->cb_barrier != NULL &&
1036 rcu_random(&rand) % (nfakewriters * 8) == 0)
1037 cur_ops->cb_barrier();
1040 rcu_stutter_wait("rcu_torture_fakewriter");
1041 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1043 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
1044 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
1045 while (!kthread_should_stop())
1046 schedule_timeout_uninterruptible(1);
1050 void rcutorture_trace_dump(void)
1052 static atomic_t beenhere = ATOMIC_INIT(0);
1054 if (atomic_read(&beenhere))
1056 if (atomic_xchg(&beenhere, 1) != 0)
1058 do_trace_rcu_torture_read(cur_ops->name, (struct rcu_head *)~0UL);
1059 ftrace_dump(DUMP_ALL);
1063 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
1064 * incrementing the corresponding element of the pipeline array. The
1065 * counter in the element should never be greater than 1, otherwise, the
1066 * RCU implementation is broken.
1068 static void rcu_torture_timer(unsigned long unused)
1072 static DEFINE_RCU_RANDOM(rand);
1073 static DEFINE_SPINLOCK(rand_lock);
1074 struct rcu_torture *p;
1077 idx = cur_ops->readlock();
1078 completed = cur_ops->completed();
1079 p = rcu_dereference_check(rcu_torture_current,
1080 rcu_read_lock_bh_held() ||
1081 rcu_read_lock_sched_held() ||
1082 srcu_read_lock_held(&srcu_ctl));
1084 /* Leave because rcu_torture_writer is not yet underway */
1085 cur_ops->readunlock(idx);
1088 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
1089 if (p->rtort_mbtest == 0)
1090 atomic_inc(&n_rcu_torture_mberror);
1091 spin_lock(&rand_lock);
1092 cur_ops->read_delay(&rand);
1093 n_rcu_torture_timers++;
1094 spin_unlock(&rand_lock);
1096 pipe_count = p->rtort_pipe_count;
1097 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1098 /* Should not happen, but... */
1099 pipe_count = RCU_TORTURE_PIPE_LEN;
1102 rcutorture_trace_dump();
1103 __this_cpu_inc(rcu_torture_count[pipe_count]);
1104 completed = cur_ops->completed() - completed;
1105 if (completed > RCU_TORTURE_PIPE_LEN) {
1106 /* Should not happen, but... */
1107 completed = RCU_TORTURE_PIPE_LEN;
1109 __this_cpu_inc(rcu_torture_batch[completed]);
1111 cur_ops->readunlock(idx);
1115 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
1116 * incrementing the corresponding element of the pipeline array. The
1117 * counter in the element should never be greater than 1, otherwise, the
1118 * RCU implementation is broken.
1121 rcu_torture_reader(void *arg)
1125 DEFINE_RCU_RANDOM(rand);
1126 struct rcu_torture *p;
1128 struct timer_list t;
1130 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
1131 set_user_nice(current, 19);
1132 if (irqreader && cur_ops->irq_capable)
1133 setup_timer_on_stack(&t, rcu_torture_timer, 0);
1136 if (irqreader && cur_ops->irq_capable) {
1137 if (!timer_pending(&t))
1138 mod_timer(&t, jiffies + 1);
1140 idx = cur_ops->readlock();
1141 completed = cur_ops->completed();
1142 p = rcu_dereference_check(rcu_torture_current,
1143 rcu_read_lock_bh_held() ||
1144 rcu_read_lock_sched_held() ||
1145 srcu_read_lock_held(&srcu_ctl));
1147 /* Wait for rcu_torture_writer to get underway */
1148 cur_ops->readunlock(idx);
1149 schedule_timeout_interruptible(HZ);
1152 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
1153 if (p->rtort_mbtest == 0)
1154 atomic_inc(&n_rcu_torture_mberror);
1155 cur_ops->read_delay(&rand);
1157 pipe_count = p->rtort_pipe_count;
1158 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1159 /* Should not happen, but... */
1160 pipe_count = RCU_TORTURE_PIPE_LEN;
1163 rcutorture_trace_dump();
1164 __this_cpu_inc(rcu_torture_count[pipe_count]);
1165 completed = cur_ops->completed() - completed;
1166 if (completed > RCU_TORTURE_PIPE_LEN) {
1167 /* Should not happen, but... */
1168 completed = RCU_TORTURE_PIPE_LEN;
1170 __this_cpu_inc(rcu_torture_batch[completed]);
1172 cur_ops->readunlock(idx);
1174 rcu_stutter_wait("rcu_torture_reader");
1175 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1176 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
1177 rcutorture_shutdown_absorb("rcu_torture_reader");
1178 if (irqreader && cur_ops->irq_capable)
1180 while (!kthread_should_stop())
1181 schedule_timeout_uninterruptible(1);
1186 * Create an RCU-torture statistics message in the specified buffer.
1189 rcu_torture_printk(char *page)
1194 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1195 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1197 for_each_possible_cpu(cpu) {
1198 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1199 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1200 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1203 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1204 if (pipesummary[i] != 0)
1207 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
1208 cnt += sprintf(&page[cnt],
1209 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
1210 rcu_torture_current,
1211 rcu_torture_current_version,
1212 list_empty(&rcu_torture_freelist),
1213 atomic_read(&n_rcu_torture_alloc),
1214 atomic_read(&n_rcu_torture_alloc_fail),
1215 atomic_read(&n_rcu_torture_free));
1216 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
1217 atomic_read(&n_rcu_torture_mberror),
1218 n_rcu_torture_boost_ktrerror,
1219 n_rcu_torture_boost_rterror);
1220 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
1221 n_rcu_torture_boost_failure,
1222 n_rcu_torture_boosts,
1223 n_rcu_torture_timers);
1224 cnt += sprintf(&page[cnt],
1225 "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ",
1226 n_online_successes, n_online_attempts,
1227 n_offline_successes, n_offline_attempts,
1228 min_online, max_online,
1229 min_offline, max_offline,
1230 sum_online, sum_offline, HZ);
1231 cnt += sprintf(&page[cnt], "barrier: %ld/%ld:%ld",
1232 n_barrier_successes,
1234 n_rcu_torture_barrier_error);
1235 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
1236 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
1237 n_rcu_torture_barrier_error != 0 ||
1238 n_rcu_torture_boost_ktrerror != 0 ||
1239 n_rcu_torture_boost_rterror != 0 ||
1240 n_rcu_torture_boost_failure != 0 ||
1242 cnt += sprintf(&page[cnt], "!!! ");
1243 atomic_inc(&n_rcu_torture_error);
1246 cnt += sprintf(&page[cnt], "Reader Pipe: ");
1247 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1248 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
1249 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
1250 cnt += sprintf(&page[cnt], "Reader Batch: ");
1251 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1252 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
1253 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
1254 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
1255 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1256 cnt += sprintf(&page[cnt], " %d",
1257 atomic_read(&rcu_torture_wcount[i]));
1259 cnt += sprintf(&page[cnt], "\n");
1261 cnt += cur_ops->stats(&page[cnt]);
1266 * Print torture statistics. Caller must ensure that there is only
1267 * one call to this function at a given time!!! This is normally
1268 * accomplished by relying on the module system to only have one copy
1269 * of the module loaded, and then by giving the rcu_torture_stats
1270 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1271 * thread is not running).
1274 rcu_torture_stats_print(void)
1278 cnt = rcu_torture_printk(printk_buf);
1279 pr_alert("%s", printk_buf);
1283 * Periodically prints torture statistics, if periodic statistics printing
1284 * was specified via the stat_interval module parameter.
1286 * No need to worry about fullstop here, since this one doesn't reference
1287 * volatile state or register callbacks.
1290 rcu_torture_stats(void *arg)
1292 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1294 schedule_timeout_interruptible(stat_interval * HZ);
1295 rcu_torture_stats_print();
1296 rcutorture_shutdown_absorb("rcu_torture_stats");
1297 } while (!kthread_should_stop());
1298 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1302 static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
1304 /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1305 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1307 static void rcu_torture_shuffle_tasks(void)
1311 cpumask_setall(shuffle_tmp_mask);
1314 /* No point in shuffling if there is only one online CPU (ex: UP) */
1315 if (num_online_cpus() == 1) {
1320 if (rcu_idle_cpu != -1)
1321 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
1323 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
1326 for (i = 0; i < nrealreaders; i++)
1327 if (reader_tasks[i])
1328 set_cpus_allowed_ptr(reader_tasks[i],
1332 if (fakewriter_tasks) {
1333 for (i = 0; i < nfakewriters; i++)
1334 if (fakewriter_tasks[i])
1335 set_cpus_allowed_ptr(fakewriter_tasks[i],
1340 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
1343 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
1345 if (rcu_idle_cpu == -1)
1346 rcu_idle_cpu = num_online_cpus() - 1;
1353 /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1354 * system to become idle at a time and cut off its timer ticks. This is meant
1355 * to test the support for such tickless idle CPU in RCU.
1358 rcu_torture_shuffle(void *arg)
1360 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1362 schedule_timeout_interruptible(shuffle_interval * HZ);
1363 rcu_torture_shuffle_tasks();
1364 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1365 } while (!kthread_should_stop());
1366 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1370 /* Cause the rcutorture test to "stutter", starting and stopping all
1371 * threads periodically.
1374 rcu_torture_stutter(void *arg)
1376 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1378 schedule_timeout_interruptible(stutter * HZ);
1379 stutter_pause_test = 1;
1380 if (!kthread_should_stop())
1381 schedule_timeout_interruptible(stutter * HZ);
1382 stutter_pause_test = 0;
1383 rcutorture_shutdown_absorb("rcu_torture_stutter");
1384 } while (!kthread_should_stop());
1385 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1390 rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
1392 pr_alert("%s" TORTURE_FLAG
1393 "--- %s: nreaders=%d nfakewriters=%d "
1394 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1395 "shuffle_interval=%d stutter=%d irqreader=%d "
1396 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1397 "test_boost=%d/%d test_boost_interval=%d "
1398 "test_boost_duration=%d shutdown_secs=%d "
1399 "onoff_interval=%d onoff_holdoff=%d\n",
1400 torture_type, tag, nrealreaders, nfakewriters,
1401 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
1402 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1403 test_boost, cur_ops->can_boost,
1404 test_boost_interval, test_boost_duration, shutdown_secs,
1405 onoff_interval, onoff_holdoff);
1408 static struct notifier_block rcutorture_shutdown_nb = {
1409 .notifier_call = rcutorture_shutdown_notify,
1412 static void rcutorture_booster_cleanup(int cpu)
1414 struct task_struct *t;
1416 if (boost_tasks[cpu] == NULL)
1418 mutex_lock(&boost_mutex);
1419 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1420 t = boost_tasks[cpu];
1421 boost_tasks[cpu] = NULL;
1422 mutex_unlock(&boost_mutex);
1424 /* This must be outside of the mutex, otherwise deadlock! */
1426 boost_tasks[cpu] = NULL;
1429 static int rcutorture_booster_init(int cpu)
1433 if (boost_tasks[cpu] != NULL)
1434 return 0; /* Already created, nothing more to do. */
1436 /* Don't allow time recalculation while creating a new task. */
1437 mutex_lock(&boost_mutex);
1438 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
1439 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1441 "rcu_torture_boost");
1442 if (IS_ERR(boost_tasks[cpu])) {
1443 retval = PTR_ERR(boost_tasks[cpu]);
1444 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1445 n_rcu_torture_boost_ktrerror++;
1446 boost_tasks[cpu] = NULL;
1447 mutex_unlock(&boost_mutex);
1450 kthread_bind(boost_tasks[cpu], cpu);
1451 wake_up_process(boost_tasks[cpu]);
1452 mutex_unlock(&boost_mutex);
1457 * Cause the rcutorture test to shutdown the system after the test has
1458 * run for the time specified by the shutdown_secs module parameter.
1461 rcu_torture_shutdown(void *arg)
1464 unsigned long jiffies_snap;
1466 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1467 jiffies_snap = ACCESS_ONCE(jiffies);
1468 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
1469 !kthread_should_stop()) {
1470 delta = shutdown_time - jiffies_snap;
1472 pr_alert("%s" TORTURE_FLAG
1473 "rcu_torture_shutdown task: %lu jiffies remaining\n",
1474 torture_type, delta);
1475 schedule_timeout_interruptible(delta);
1476 jiffies_snap = ACCESS_ONCE(jiffies);
1478 if (kthread_should_stop()) {
1479 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1483 /* OK, shut down the system. */
1485 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1486 shutdown_task = NULL; /* Avoid self-kill deadlock. */
1487 rcu_torture_cleanup(); /* Get the success/failure message. */
1488 kernel_power_off(); /* Shut down the system. */
1492 #ifdef CONFIG_HOTPLUG_CPU
1495 * Execute random CPU-hotplug operations at the interval specified
1496 * by the onoff_interval.
1498 static int __cpuinit
1499 rcu_torture_onoff(void *arg)
1502 unsigned long delta;
1504 DEFINE_RCU_RANDOM(rand);
1506 unsigned long starttime;
1508 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1509 for_each_online_cpu(cpu)
1511 WARN_ON(maxcpu < 0);
1512 if (onoff_holdoff > 0) {
1513 VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff");
1514 schedule_timeout_interruptible(onoff_holdoff * HZ);
1515 VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff");
1517 while (!kthread_should_stop()) {
1518 cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
1519 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) {
1521 pr_alert("%s" TORTURE_FLAG
1522 "rcu_torture_onoff task: offlining %d\n",
1524 starttime = jiffies;
1525 n_offline_attempts++;
1526 ret = cpu_down(cpu);
1529 pr_alert("%s" TORTURE_FLAG
1530 "rcu_torture_onoff task: offline %d failed: errno %d\n",
1531 torture_type, cpu, ret);
1534 pr_alert("%s" TORTURE_FLAG
1535 "rcu_torture_onoff task: offlined %d\n",
1537 n_offline_successes++;
1538 delta = jiffies - starttime;
1539 sum_offline += delta;
1540 if (min_offline < 0) {
1541 min_offline = delta;
1542 max_offline = delta;
1544 if (min_offline > delta)
1545 min_offline = delta;
1546 if (max_offline < delta)
1547 max_offline = delta;
1549 } else if (cpu_is_hotpluggable(cpu)) {
1551 pr_alert("%s" TORTURE_FLAG
1552 "rcu_torture_onoff task: onlining %d\n",
1554 starttime = jiffies;
1555 n_online_attempts++;
1556 if (cpu_up(cpu) == 0) {
1558 pr_alert("%s" TORTURE_FLAG
1559 "rcu_torture_onoff task: onlined %d\n",
1561 n_online_successes++;
1562 delta = jiffies - starttime;
1563 sum_online += delta;
1564 if (min_online < 0) {
1568 if (min_online > delta)
1570 if (max_online < delta)
1574 schedule_timeout_interruptible(onoff_interval * HZ);
1576 VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1580 static int __cpuinit
1581 rcu_torture_onoff_init(void)
1585 if (onoff_interval <= 0)
1587 onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff");
1588 if (IS_ERR(onoff_task)) {
1589 ret = PTR_ERR(onoff_task);
1596 static void rcu_torture_onoff_cleanup(void)
1598 if (onoff_task == NULL)
1600 VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1601 kthread_stop(onoff_task);
1605 #else /* #ifdef CONFIG_HOTPLUG_CPU */
1608 rcu_torture_onoff_init(void)
1613 static void rcu_torture_onoff_cleanup(void)
1617 #endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1620 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1621 * induces a CPU stall for the time specified by stall_cpu.
1623 static int __cpuinit rcu_torture_stall(void *args)
1625 unsigned long stop_at;
1627 VERBOSE_PRINTK_STRING("rcu_torture_stall task started");
1628 if (stall_cpu_holdoff > 0) {
1629 VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff");
1630 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
1631 VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff");
1633 if (!kthread_should_stop()) {
1634 stop_at = get_seconds() + stall_cpu;
1635 /* RCU CPU stall is expected behavior in following code. */
1636 pr_alert("rcu_torture_stall start.\n");
1639 while (ULONG_CMP_LT(get_seconds(), stop_at))
1640 continue; /* Induce RCU CPU stall warning. */
1643 pr_alert("rcu_torture_stall end.\n");
1645 rcutorture_shutdown_absorb("rcu_torture_stall");
1646 while (!kthread_should_stop())
1647 schedule_timeout_interruptible(10 * HZ);
1651 /* Spawn CPU-stall kthread, if stall_cpu specified. */
1652 static int __init rcu_torture_stall_init(void)
1658 stall_task = kthread_run(rcu_torture_stall, NULL, "rcu_torture_stall");
1659 if (IS_ERR(stall_task)) {
1660 ret = PTR_ERR(stall_task);
1667 /* Clean up after the CPU-stall kthread, if one was spawned. */
1668 static void rcu_torture_stall_cleanup(void)
1670 if (stall_task == NULL)
1672 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task.");
1673 kthread_stop(stall_task);
1677 /* Callback function for RCU barrier testing. */
1678 void rcu_torture_barrier_cbf(struct rcu_head *rcu)
1680 atomic_inc(&barrier_cbs_invoked);
1683 /* kthread function to register callbacks used to test RCU barriers. */
1684 static int rcu_torture_barrier_cbs(void *arg)
1686 long myid = (long)arg;
1688 struct rcu_head rcu;
1690 init_rcu_head_on_stack(&rcu);
1691 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
1692 set_user_nice(current, 19);
1694 wait_event(barrier_cbs_wq[myid],
1695 barrier_phase != lastphase ||
1696 kthread_should_stop() ||
1697 fullstop != FULLSTOP_DONTSTOP);
1698 lastphase = barrier_phase;
1699 smp_mb(); /* ensure barrier_phase load before ->call(). */
1700 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1702 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1703 if (atomic_dec_and_test(&barrier_cbs_count))
1704 wake_up(&barrier_wq);
1705 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1706 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task stopping");
1707 rcutorture_shutdown_absorb("rcu_torture_barrier_cbs");
1708 while (!kthread_should_stop())
1709 schedule_timeout_interruptible(1);
1710 cur_ops->cb_barrier();
1711 destroy_rcu_head_on_stack(&rcu);
1715 /* kthread function to drive and coordinate RCU barrier testing. */
1716 static int rcu_torture_barrier(void *arg)
1720 VERBOSE_PRINTK_STRING("rcu_torture_barrier task starting");
1722 atomic_set(&barrier_cbs_invoked, 0);
1723 atomic_set(&barrier_cbs_count, n_barrier_cbs);
1724 smp_mb(); /* Ensure barrier_phase after prior assignments. */
1725 barrier_phase = !barrier_phase;
1726 for (i = 0; i < n_barrier_cbs; i++)
1727 wake_up(&barrier_cbs_wq[i]);
1728 wait_event(barrier_wq,
1729 atomic_read(&barrier_cbs_count) == 0 ||
1730 kthread_should_stop() ||
1731 fullstop != FULLSTOP_DONTSTOP);
1732 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1734 n_barrier_attempts++;
1735 cur_ops->cb_barrier();
1736 if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
1737 n_rcu_torture_barrier_error++;
1740 n_barrier_successes++;
1741 schedule_timeout_interruptible(HZ / 10);
1742 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1743 VERBOSE_PRINTK_STRING("rcu_torture_barrier task stopping");
1744 rcutorture_shutdown_absorb("rcu_torture_barrier");
1745 while (!kthread_should_stop())
1746 schedule_timeout_interruptible(1);
1750 /* Initialize RCU barrier testing. */
1751 static int rcu_torture_barrier_init(void)
1756 if (n_barrier_cbs == 0)
1758 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
1759 pr_alert("%s" TORTURE_FLAG
1760 " Call or barrier ops missing for %s,\n",
1761 torture_type, cur_ops->name);
1762 pr_alert("%s" TORTURE_FLAG
1763 " RCU barrier testing omitted from run.\n",
1767 atomic_set(&barrier_cbs_count, 0);
1768 atomic_set(&barrier_cbs_invoked, 0);
1770 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
1773 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
1775 if (barrier_cbs_tasks == NULL || barrier_cbs_wq == 0)
1777 for (i = 0; i < n_barrier_cbs; i++) {
1778 init_waitqueue_head(&barrier_cbs_wq[i]);
1779 barrier_cbs_tasks[i] = kthread_run(rcu_torture_barrier_cbs,
1781 "rcu_torture_barrier_cbs");
1782 if (IS_ERR(barrier_cbs_tasks[i])) {
1783 ret = PTR_ERR(barrier_cbs_tasks[i]);
1784 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier_cbs");
1785 barrier_cbs_tasks[i] = NULL;
1789 barrier_task = kthread_run(rcu_torture_barrier, NULL,
1790 "rcu_torture_barrier");
1791 if (IS_ERR(barrier_task)) {
1792 ret = PTR_ERR(barrier_task);
1793 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier");
1794 barrier_task = NULL;
1799 /* Clean up after RCU barrier testing. */
1800 static void rcu_torture_barrier_cleanup(void)
1804 if (barrier_task != NULL) {
1805 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier task");
1806 kthread_stop(barrier_task);
1807 barrier_task = NULL;
1809 if (barrier_cbs_tasks != NULL) {
1810 for (i = 0; i < n_barrier_cbs; i++) {
1811 if (barrier_cbs_tasks[i] != NULL) {
1812 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier_cbs task");
1813 kthread_stop(barrier_cbs_tasks[i]);
1814 barrier_cbs_tasks[i] = NULL;
1817 kfree(barrier_cbs_tasks);
1818 barrier_cbs_tasks = NULL;
1820 if (barrier_cbs_wq != NULL) {
1821 kfree(barrier_cbs_wq);
1822 barrier_cbs_wq = NULL;
1826 static int rcutorture_cpu_notify(struct notifier_block *self,
1827 unsigned long action, void *hcpu)
1829 long cpu = (long)hcpu;
1833 case CPU_DOWN_FAILED:
1834 (void)rcutorture_booster_init(cpu);
1836 case CPU_DOWN_PREPARE:
1837 rcutorture_booster_cleanup(cpu);
1845 static struct notifier_block rcutorture_cpu_nb = {
1846 .notifier_call = rcutorture_cpu_notify,
1850 rcu_torture_cleanup(void)
1854 mutex_lock(&fullstop_mutex);
1855 rcutorture_record_test_transition();
1856 if (fullstop == FULLSTOP_SHUTDOWN) {
1857 pr_warn(/* but going down anyway, so... */
1858 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
1859 mutex_unlock(&fullstop_mutex);
1860 schedule_timeout_uninterruptible(10);
1861 if (cur_ops->cb_barrier != NULL)
1862 cur_ops->cb_barrier();
1865 fullstop = FULLSTOP_RMMOD;
1866 mutex_unlock(&fullstop_mutex);
1867 unregister_reboot_notifier(&rcutorture_shutdown_nb);
1868 rcu_torture_barrier_cleanup();
1869 rcu_torture_stall_cleanup();
1871 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1872 kthread_stop(stutter_task);
1874 stutter_task = NULL;
1875 if (shuffler_task) {
1876 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1877 kthread_stop(shuffler_task);
1878 free_cpumask_var(shuffle_tmp_mask);
1880 shuffler_task = NULL;
1883 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1884 kthread_stop(writer_task);
1889 for (i = 0; i < nrealreaders; i++) {
1890 if (reader_tasks[i]) {
1891 VERBOSE_PRINTK_STRING(
1892 "Stopping rcu_torture_reader task");
1893 kthread_stop(reader_tasks[i]);
1895 reader_tasks[i] = NULL;
1897 kfree(reader_tasks);
1898 reader_tasks = NULL;
1900 rcu_torture_current = NULL;
1902 if (fakewriter_tasks) {
1903 for (i = 0; i < nfakewriters; i++) {
1904 if (fakewriter_tasks[i]) {
1905 VERBOSE_PRINTK_STRING(
1906 "Stopping rcu_torture_fakewriter task");
1907 kthread_stop(fakewriter_tasks[i]);
1909 fakewriter_tasks[i] = NULL;
1911 kfree(fakewriter_tasks);
1912 fakewriter_tasks = NULL;
1916 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1917 kthread_stop(stats_task);
1922 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1923 kthread_stop(fqs_task);
1926 if ((test_boost == 1 && cur_ops->can_boost) ||
1928 unregister_cpu_notifier(&rcutorture_cpu_nb);
1929 for_each_possible_cpu(i)
1930 rcutorture_booster_cleanup(i);
1932 if (shutdown_task != NULL) {
1933 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1934 kthread_stop(shutdown_task);
1936 shutdown_task = NULL;
1937 rcu_torture_onoff_cleanup();
1939 /* Wait for all RCU callbacks to fire. */
1941 if (cur_ops->cb_barrier != NULL)
1942 cur_ops->cb_barrier();
1944 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
1946 if (cur_ops->cleanup)
1948 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
1949 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
1950 else if (n_online_successes != n_online_attempts ||
1951 n_offline_successes != n_offline_attempts)
1952 rcu_torture_print_module_parms(cur_ops,
1953 "End of test: RCU_HOTPLUG");
1955 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
1959 rcu_torture_init(void)
1965 static struct rcu_torture_ops *torture_ops[] =
1966 { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
1967 &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops,
1968 &srcu_ops, &srcu_sync_ops, &srcu_expedited_ops,
1969 &srcu_raw_ops, &srcu_raw_sync_ops,
1970 &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
1972 mutex_lock(&fullstop_mutex);
1974 /* Process args and tell the world that the torturer is on the job. */
1975 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
1976 cur_ops = torture_ops[i];
1977 if (strcmp(torture_type, cur_ops->name) == 0)
1980 if (i == ARRAY_SIZE(torture_ops)) {
1981 pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
1983 pr_alert("rcu-torture types:");
1984 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
1985 pr_alert(" %s", torture_ops[i]->name);
1987 mutex_unlock(&fullstop_mutex);
1990 if (cur_ops->fqs == NULL && fqs_duration != 0) {
1991 pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
1995 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1998 nrealreaders = nreaders;
2000 nrealreaders = 2 * num_online_cpus();
2001 rcu_torture_print_module_parms(cur_ops, "Start of test");
2002 fullstop = FULLSTOP_DONTSTOP;
2004 /* Set up the freelist. */
2006 INIT_LIST_HEAD(&rcu_torture_freelist);
2007 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
2008 rcu_tortures[i].rtort_mbtest = 0;
2009 list_add_tail(&rcu_tortures[i].rtort_free,
2010 &rcu_torture_freelist);
2013 /* Initialize the statistics so that each run gets its own numbers. */
2015 rcu_torture_current = NULL;
2016 rcu_torture_current_version = 0;
2017 atomic_set(&n_rcu_torture_alloc, 0);
2018 atomic_set(&n_rcu_torture_alloc_fail, 0);
2019 atomic_set(&n_rcu_torture_free, 0);
2020 atomic_set(&n_rcu_torture_mberror, 0);
2021 atomic_set(&n_rcu_torture_error, 0);
2022 n_rcu_torture_barrier_error = 0;
2023 n_rcu_torture_boost_ktrerror = 0;
2024 n_rcu_torture_boost_rterror = 0;
2025 n_rcu_torture_boost_failure = 0;
2026 n_rcu_torture_boosts = 0;
2027 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
2028 atomic_set(&rcu_torture_wcount[i], 0);
2029 for_each_possible_cpu(cpu) {
2030 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
2031 per_cpu(rcu_torture_count, cpu)[i] = 0;
2032 per_cpu(rcu_torture_batch, cpu)[i] = 0;
2036 /* Start up the kthreads. */
2038 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
2039 writer_task = kthread_create(rcu_torture_writer, NULL,
2040 "rcu_torture_writer");
2041 if (IS_ERR(writer_task)) {
2042 firsterr = PTR_ERR(writer_task);
2043 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
2047 wake_up_process(writer_task);
2048 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
2050 if (fakewriter_tasks == NULL) {
2051 VERBOSE_PRINTK_ERRSTRING("out of memory");
2055 for (i = 0; i < nfakewriters; i++) {
2056 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
2057 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
2058 "rcu_torture_fakewriter");
2059 if (IS_ERR(fakewriter_tasks[i])) {
2060 firsterr = PTR_ERR(fakewriter_tasks[i]);
2061 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
2062 fakewriter_tasks[i] = NULL;
2066 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
2068 if (reader_tasks == NULL) {
2069 VERBOSE_PRINTK_ERRSTRING("out of memory");
2073 for (i = 0; i < nrealreaders; i++) {
2074 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
2075 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
2076 "rcu_torture_reader");
2077 if (IS_ERR(reader_tasks[i])) {
2078 firsterr = PTR_ERR(reader_tasks[i]);
2079 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
2080 reader_tasks[i] = NULL;
2084 if (stat_interval > 0) {
2085 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
2086 stats_task = kthread_run(rcu_torture_stats, NULL,
2087 "rcu_torture_stats");
2088 if (IS_ERR(stats_task)) {
2089 firsterr = PTR_ERR(stats_task);
2090 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
2095 if (test_no_idle_hz) {
2096 rcu_idle_cpu = num_online_cpus() - 1;
2098 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
2100 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
2104 /* Create the shuffler thread */
2105 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
2106 "rcu_torture_shuffle");
2107 if (IS_ERR(shuffler_task)) {
2108 free_cpumask_var(shuffle_tmp_mask);
2109 firsterr = PTR_ERR(shuffler_task);
2110 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
2111 shuffler_task = NULL;
2118 /* Create the stutter thread */
2119 stutter_task = kthread_run(rcu_torture_stutter, NULL,
2120 "rcu_torture_stutter");
2121 if (IS_ERR(stutter_task)) {
2122 firsterr = PTR_ERR(stutter_task);
2123 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
2124 stutter_task = NULL;
2128 if (fqs_duration < 0)
2131 /* Create the stutter thread */
2132 fqs_task = kthread_run(rcu_torture_fqs, NULL,
2134 if (IS_ERR(fqs_task)) {
2135 firsterr = PTR_ERR(fqs_task);
2136 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
2141 if (test_boost_interval < 1)
2142 test_boost_interval = 1;
2143 if (test_boost_duration < 2)
2144 test_boost_duration = 2;
2145 if ((test_boost == 1 && cur_ops->can_boost) ||
2148 boost_starttime = jiffies + test_boost_interval * HZ;
2149 register_cpu_notifier(&rcutorture_cpu_nb);
2150 for_each_possible_cpu(i) {
2151 if (cpu_is_offline(i))
2152 continue; /* Heuristic: CPU can go offline. */
2153 retval = rcutorture_booster_init(i);
2160 if (shutdown_secs > 0) {
2161 shutdown_time = jiffies + shutdown_secs * HZ;
2162 shutdown_task = kthread_create(rcu_torture_shutdown, NULL,
2163 "rcu_torture_shutdown");
2164 if (IS_ERR(shutdown_task)) {
2165 firsterr = PTR_ERR(shutdown_task);
2166 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
2167 shutdown_task = NULL;
2170 wake_up_process(shutdown_task);
2172 i = rcu_torture_onoff_init();
2177 register_reboot_notifier(&rcutorture_shutdown_nb);
2178 i = rcu_torture_stall_init();
2183 retval = rcu_torture_barrier_init();
2188 rcutorture_record_test_transition();
2189 mutex_unlock(&fullstop_mutex);
2193 mutex_unlock(&fullstop_mutex);
2194 rcu_torture_cleanup();
2198 module_init(rcu_torture_init);
2199 module_exit(rcu_torture_cleanup);