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>
51 #include <linux/torture.h>
53 MODULE_LICENSE("GPL");
54 MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@freedesktop.org>");
56 MODULE_ALIAS("rcutorture");
57 #ifdef MODULE_PARAM_PREFIX
58 #undef MODULE_PARAM_PREFIX
60 #define MODULE_PARAM_PREFIX "rcutorture."
62 static int fqs_duration
;
63 module_param(fqs_duration
, int, 0444);
64 MODULE_PARM_DESC(fqs_duration
, "Duration of fqs bursts (us), 0 to disable");
65 static int fqs_holdoff
;
66 module_param(fqs_holdoff
, int, 0444);
67 MODULE_PARM_DESC(fqs_holdoff
, "Holdoff time within fqs bursts (us)");
68 static int fqs_stutter
= 3;
69 module_param(fqs_stutter
, int, 0444);
70 MODULE_PARM_DESC(fqs_stutter
, "Wait time between fqs bursts (s)");
72 module_param(gp_exp
, bool, 0444);
73 MODULE_PARM_DESC(gp_exp
, "Use expedited GP wait primitives");
74 static bool gp_normal
;
75 module_param(gp_normal
, bool, 0444);
76 MODULE_PARM_DESC(gp_normal
, "Use normal (non-expedited) GP wait primitives");
77 static int irqreader
= 1;
78 module_param(irqreader
, int, 0444);
79 MODULE_PARM_DESC(irqreader
, "Allow RCU readers from irq handlers");
80 static int n_barrier_cbs
;
81 module_param(n_barrier_cbs
, int, 0444);
82 MODULE_PARM_DESC(n_barrier_cbs
, "# of callbacks/kthreads for barrier testing");
83 static int nfakewriters
= 4;
84 module_param(nfakewriters
, int, 0444);
85 MODULE_PARM_DESC(nfakewriters
, "Number of RCU fake writer threads");
86 static int nreaders
= -1;
87 module_param(nreaders
, int, 0444);
88 MODULE_PARM_DESC(nreaders
, "Number of RCU reader threads");
89 static int object_debug
;
90 module_param(object_debug
, int, 0444);
91 MODULE_PARM_DESC(object_debug
, "Enable debug-object double call_rcu() testing");
92 static int onoff_holdoff
;
93 module_param(onoff_holdoff
, int, 0444);
94 MODULE_PARM_DESC(onoff_holdoff
, "Time after boot before CPU hotplugs (s)");
95 static int onoff_interval
;
96 module_param(onoff_interval
, int, 0444);
97 MODULE_PARM_DESC(onoff_interval
, "Time between CPU hotplugs (s), 0=disable");
98 static int shuffle_interval
= 3;
99 module_param(shuffle_interval
, int, 0444);
100 MODULE_PARM_DESC(shuffle_interval
, "Number of seconds between shuffles");
101 static int shutdown_secs
;
102 module_param(shutdown_secs
, int, 0444);
103 MODULE_PARM_DESC(shutdown_secs
, "Shutdown time (s), <= zero to disable.");
104 static int stall_cpu
;
105 module_param(stall_cpu
, int, 0444);
106 MODULE_PARM_DESC(stall_cpu
, "Stall duration (s), zero to disable.");
107 static int stall_cpu_holdoff
= 10;
108 module_param(stall_cpu_holdoff
, int, 0444);
109 MODULE_PARM_DESC(stall_cpu_holdoff
, "Time to wait before starting stall (s).");
110 static int stat_interval
= 60;
111 module_param(stat_interval
, int, 0644);
112 MODULE_PARM_DESC(stat_interval
, "Number of seconds between stats printk()s");
113 static int stutter
= 5;
114 module_param(stutter
, int, 0444);
115 MODULE_PARM_DESC(stutter
, "Number of seconds to run/halt test");
116 static int test_boost
= 1;
117 module_param(test_boost
, int, 0444);
118 MODULE_PARM_DESC(test_boost
, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
119 static int test_boost_duration
= 4;
120 module_param(test_boost_duration
, int, 0444);
121 MODULE_PARM_DESC(test_boost_duration
, "Duration of each boost test, seconds.");
122 static int test_boost_interval
= 7;
123 module_param(test_boost_interval
, int, 0444);
124 MODULE_PARM_DESC(test_boost_interval
, "Interval between boost tests, seconds.");
125 static bool test_no_idle_hz
= true;
126 module_param(test_no_idle_hz
, bool, 0444);
127 MODULE_PARM_DESC(test_no_idle_hz
, "Test support for tickless idle CPUs");
128 static char *torture_type
= "rcu";
129 module_param(torture_type
, charp
, 0444);
130 MODULE_PARM_DESC(torture_type
, "Type of RCU to torture (rcu, rcu_bh, ...)");
132 module_param(verbose
, bool, 0444);
133 MODULE_PARM_DESC(verbose
, "Enable verbose debugging printk()s");
135 #define TORTURE_FLAG "-torture:"
136 #define PRINTK_STRING(s) \
137 do { pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
138 #define VERBOSE_PRINTK_STRING(s) \
139 do { if (verbose) pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
140 #define VERBOSE_PRINTK_ERRSTRING(s) \
141 do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
143 static int nrealreaders
;
144 static struct task_struct
*writer_task
;
145 static struct task_struct
**fakewriter_tasks
;
146 static struct task_struct
**reader_tasks
;
147 static struct task_struct
*stats_task
;
148 static struct task_struct
*shuffler_task
;
149 static struct task_struct
*stutter_task
;
150 static struct task_struct
*fqs_task
;
151 static struct task_struct
*boost_tasks
[NR_CPUS
];
152 static struct task_struct
*shutdown_task
;
153 #ifdef CONFIG_HOTPLUG_CPU
154 static struct task_struct
*onoff_task
;
155 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
156 static struct task_struct
*stall_task
;
157 static struct task_struct
**barrier_cbs_tasks
;
158 static struct task_struct
*barrier_task
;
160 #define RCU_TORTURE_PIPE_LEN 10
163 struct rcu_head rtort_rcu
;
164 int rtort_pipe_count
;
165 struct list_head rtort_free
;
169 static LIST_HEAD(rcu_torture_freelist
);
170 static struct rcu_torture __rcu
*rcu_torture_current
;
171 static unsigned long rcu_torture_current_version
;
172 static struct rcu_torture rcu_tortures
[10 * RCU_TORTURE_PIPE_LEN
];
173 static DEFINE_SPINLOCK(rcu_torture_lock
);
174 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN
+ 1],
175 rcu_torture_count
) = { 0 };
176 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN
+ 1],
177 rcu_torture_batch
) = { 0 };
178 static atomic_t rcu_torture_wcount
[RCU_TORTURE_PIPE_LEN
+ 1];
179 static atomic_t n_rcu_torture_alloc
;
180 static atomic_t n_rcu_torture_alloc_fail
;
181 static atomic_t n_rcu_torture_free
;
182 static atomic_t n_rcu_torture_mberror
;
183 static atomic_t n_rcu_torture_error
;
184 static long n_rcu_torture_barrier_error
;
185 static long n_rcu_torture_boost_ktrerror
;
186 static long n_rcu_torture_boost_rterror
;
187 static long n_rcu_torture_boost_failure
;
188 static long n_rcu_torture_boosts
;
189 static long n_rcu_torture_timers
;
190 static long n_offline_attempts
;
191 static long n_offline_successes
;
192 static unsigned long sum_offline
;
193 static int min_offline
= -1;
194 static int max_offline
;
195 static long n_online_attempts
;
196 static long n_online_successes
;
197 static unsigned long sum_online
;
198 static int min_online
= -1;
199 static int max_online
;
200 static long n_barrier_attempts
;
201 static long n_barrier_successes
;
202 static struct list_head rcu_torture_removed
;
203 static cpumask_var_t shuffle_tmp_mask
;
205 static int stutter_pause_test
;
207 #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
208 #define RCUTORTURE_RUNNABLE_INIT 1
210 #define RCUTORTURE_RUNNABLE_INIT 0
212 int rcutorture_runnable
= RCUTORTURE_RUNNABLE_INIT
;
213 module_param(rcutorture_runnable
, int, 0444);
214 MODULE_PARM_DESC(rcutorture_runnable
, "Start rcutorture at boot");
216 #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
217 #define rcu_can_boost() 1
218 #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
219 #define rcu_can_boost() 0
220 #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
222 #ifdef CONFIG_RCU_TRACE
223 static u64 notrace
rcu_trace_clock_local(void)
225 u64 ts
= trace_clock_local();
226 unsigned long __maybe_unused ts_rem
= do_div(ts
, NSEC_PER_USEC
);
229 #else /* #ifdef CONFIG_RCU_TRACE */
230 static u64 notrace
rcu_trace_clock_local(void)
234 #endif /* #else #ifdef CONFIG_RCU_TRACE */
236 static unsigned long shutdown_time
; /* jiffies to system shutdown. */
237 static unsigned long boost_starttime
; /* jiffies of next boost test start. */
238 DEFINE_MUTEX(boost_mutex
); /* protect setting boost_starttime */
239 /* and boost task create/destroy. */
240 static atomic_t barrier_cbs_count
; /* Barrier callbacks registered. */
241 static bool barrier_phase
; /* Test phase. */
242 static atomic_t barrier_cbs_invoked
; /* Barrier callbacks invoked. */
243 static wait_queue_head_t
*barrier_cbs_wq
; /* Coordinate barrier testing. */
244 static DECLARE_WAIT_QUEUE_HEAD(barrier_wq
);
246 /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
248 #define FULLSTOP_DONTSTOP 0 /* Normal operation. */
249 #define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
250 #define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
251 static int fullstop
= FULLSTOP_RMMOD
;
253 * Protect fullstop transitions and spawning of kthreads.
255 static DEFINE_MUTEX(fullstop_mutex
);
257 /* Forward reference. */
258 static void rcu_torture_cleanup(void);
261 * Detect and respond to a system shutdown.
264 rcutorture_shutdown_notify(struct notifier_block
*unused1
,
265 unsigned long unused2
, void *unused3
)
267 mutex_lock(&fullstop_mutex
);
268 if (fullstop
== FULLSTOP_DONTSTOP
)
269 fullstop
= FULLSTOP_SHUTDOWN
;
271 pr_warn(/* but going down anyway, so... */
272 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
273 mutex_unlock(&fullstop_mutex
);
278 * Absorb kthreads into a kernel function that won't return, so that
279 * they won't ever access module text or data again.
281 static void rcutorture_shutdown_absorb(const char *title
)
283 if (ACCESS_ONCE(fullstop
) == FULLSTOP_SHUTDOWN
) {
285 "rcutorture thread %s parking due to system shutdown\n",
287 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT
);
292 * Allocate an element from the rcu_tortures pool.
294 static struct rcu_torture
*
295 rcu_torture_alloc(void)
299 spin_lock_bh(&rcu_torture_lock
);
300 if (list_empty(&rcu_torture_freelist
)) {
301 atomic_inc(&n_rcu_torture_alloc_fail
);
302 spin_unlock_bh(&rcu_torture_lock
);
305 atomic_inc(&n_rcu_torture_alloc
);
306 p
= rcu_torture_freelist
.next
;
308 spin_unlock_bh(&rcu_torture_lock
);
309 return container_of(p
, struct rcu_torture
, rtort_free
);
313 * Free an element to the rcu_tortures pool.
316 rcu_torture_free(struct rcu_torture
*p
)
318 atomic_inc(&n_rcu_torture_free
);
319 spin_lock_bh(&rcu_torture_lock
);
320 list_add_tail(&p
->rtort_free
, &rcu_torture_freelist
);
321 spin_unlock_bh(&rcu_torture_lock
);
325 rcu_stutter_wait(const 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 int (*readlock
)(void);
343 void (*read_delay
)(struct torture_random_state
*rrsp
);
344 void (*readunlock
)(int idx
);
345 int (*completed
)(void);
346 void (*deferred_free
)(struct rcu_torture
*p
);
348 void (*exp_sync
)(void);
349 void (*call
)(struct rcu_head
*head
, void (*func
)(struct rcu_head
*rcu
));
350 void (*cb_barrier
)(void);
352 void (*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 torture_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 (!(torture_random(rrsp
) % (nrealreaders
* 2000 * longdelay_ms
)))
380 mdelay(longdelay_ms
);
381 if (!(torture_random(rrsp
) % (nrealreaders
* 2 * shortdelay_us
)))
382 udelay(shortdelay_us
);
383 #ifdef CONFIG_PREEMPT
384 if (!preempt_count() &&
385 !(torture_random(rrsp
) % (nrealreaders
* 20000)))
386 preempt_schedule(); /* No QS if preempt_disable() in effect */
390 static void rcu_torture_read_unlock(int idx
) __releases(RCU
)
395 static int rcu_torture_completed(void)
397 return rcu_batches_completed();
401 rcu_torture_cb(struct rcu_head
*p
)
404 struct rcu_torture
*rp
= container_of(p
, struct rcu_torture
, rtort_rcu
);
406 if (fullstop
!= FULLSTOP_DONTSTOP
) {
407 /* Test is ending, just drop callbacks on the floor. */
408 /* The next initialization will pick up the pieces. */
411 i
= rp
->rtort_pipe_count
;
412 if (i
> RCU_TORTURE_PIPE_LEN
)
413 i
= RCU_TORTURE_PIPE_LEN
;
414 atomic_inc(&rcu_torture_wcount
[i
]);
415 if (++rp
->rtort_pipe_count
>= RCU_TORTURE_PIPE_LEN
) {
416 rp
->rtort_mbtest
= 0;
417 rcu_torture_free(rp
);
419 cur_ops
->deferred_free(rp
);
423 static int rcu_no_completed(void)
428 static void rcu_torture_deferred_free(struct rcu_torture
*p
)
430 call_rcu(&p
->rtort_rcu
, rcu_torture_cb
);
433 static void rcu_sync_torture_init(void)
435 INIT_LIST_HEAD(&rcu_torture_removed
);
438 static struct rcu_torture_ops rcu_ops
= {
439 .init
= rcu_sync_torture_init
,
440 .readlock
= rcu_torture_read_lock
,
441 .read_delay
= rcu_read_delay
,
442 .readunlock
= rcu_torture_read_unlock
,
443 .completed
= rcu_torture_completed
,
444 .deferred_free
= rcu_torture_deferred_free
,
445 .sync
= synchronize_rcu
,
446 .exp_sync
= synchronize_rcu_expedited
,
448 .cb_barrier
= rcu_barrier
,
449 .fqs
= rcu_force_quiescent_state
,
452 .can_boost
= rcu_can_boost(),
457 * Definitions for rcu_bh torture testing.
460 static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH
)
466 static void rcu_bh_torture_read_unlock(int idx
) __releases(RCU_BH
)
468 rcu_read_unlock_bh();
471 static int rcu_bh_torture_completed(void)
473 return rcu_batches_completed_bh();
476 static void rcu_bh_torture_deferred_free(struct rcu_torture
*p
)
478 call_rcu_bh(&p
->rtort_rcu
, rcu_torture_cb
);
481 static struct rcu_torture_ops rcu_bh_ops
= {
482 .init
= rcu_sync_torture_init
,
483 .readlock
= rcu_bh_torture_read_lock
,
484 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
485 .readunlock
= rcu_bh_torture_read_unlock
,
486 .completed
= rcu_bh_torture_completed
,
487 .deferred_free
= rcu_bh_torture_deferred_free
,
488 .sync
= synchronize_rcu_bh
,
489 .exp_sync
= synchronize_rcu_bh_expedited
,
491 .cb_barrier
= rcu_barrier_bh
,
492 .fqs
= rcu_bh_force_quiescent_state
,
499 * Definitions for srcu torture testing.
502 DEFINE_STATIC_SRCU(srcu_ctl
);
504 static int srcu_torture_read_lock(void) __acquires(&srcu_ctl
)
506 return srcu_read_lock(&srcu_ctl
);
509 static void srcu_read_delay(struct torture_random_state
*rrsp
)
512 const long uspertick
= 1000000 / HZ
;
513 const long longdelay
= 10;
515 /* We want there to be long-running readers, but not all the time. */
517 delay
= torture_random(rrsp
) %
518 (nrealreaders
* 2 * longdelay
* uspertick
);
520 schedule_timeout_interruptible(longdelay
);
522 rcu_read_delay(rrsp
);
525 static void srcu_torture_read_unlock(int idx
) __releases(&srcu_ctl
)
527 srcu_read_unlock(&srcu_ctl
, idx
);
530 static int srcu_torture_completed(void)
532 return srcu_batches_completed(&srcu_ctl
);
535 static void srcu_torture_deferred_free(struct rcu_torture
*rp
)
537 call_srcu(&srcu_ctl
, &rp
->rtort_rcu
, rcu_torture_cb
);
540 static void srcu_torture_synchronize(void)
542 synchronize_srcu(&srcu_ctl
);
545 static void srcu_torture_call(struct rcu_head
*head
,
546 void (*func
)(struct rcu_head
*head
))
548 call_srcu(&srcu_ctl
, head
, func
);
551 static void srcu_torture_barrier(void)
553 srcu_barrier(&srcu_ctl
);
556 static void srcu_torture_stats(char *page
)
559 int idx
= srcu_ctl
.completed
& 0x1;
561 page
+= sprintf(page
, "%s%s per-CPU(idx=%d):",
562 torture_type
, TORTURE_FLAG
, idx
);
563 for_each_possible_cpu(cpu
) {
564 page
+= sprintf(page
, " %d(%lu,%lu)", cpu
,
565 per_cpu_ptr(srcu_ctl
.per_cpu_ref
, cpu
)->c
[!idx
],
566 per_cpu_ptr(srcu_ctl
.per_cpu_ref
, cpu
)->c
[idx
]);
571 static void srcu_torture_synchronize_expedited(void)
573 synchronize_srcu_expedited(&srcu_ctl
);
576 static struct rcu_torture_ops srcu_ops
= {
577 .init
= rcu_sync_torture_init
,
578 .readlock
= srcu_torture_read_lock
,
579 .read_delay
= srcu_read_delay
,
580 .readunlock
= srcu_torture_read_unlock
,
581 .completed
= srcu_torture_completed
,
582 .deferred_free
= srcu_torture_deferred_free
,
583 .sync
= srcu_torture_synchronize
,
584 .exp_sync
= srcu_torture_synchronize_expedited
,
585 .call
= srcu_torture_call
,
586 .cb_barrier
= srcu_torture_barrier
,
587 .stats
= srcu_torture_stats
,
592 * Definitions for sched torture testing.
595 static int sched_torture_read_lock(void)
601 static void sched_torture_read_unlock(int idx
)
606 static void rcu_sched_torture_deferred_free(struct rcu_torture
*p
)
608 call_rcu_sched(&p
->rtort_rcu
, rcu_torture_cb
);
611 static struct rcu_torture_ops sched_ops
= {
612 .init
= rcu_sync_torture_init
,
613 .readlock
= sched_torture_read_lock
,
614 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
615 .readunlock
= sched_torture_read_unlock
,
616 .completed
= rcu_no_completed
,
617 .deferred_free
= rcu_sched_torture_deferred_free
,
618 .sync
= synchronize_sched
,
619 .exp_sync
= synchronize_sched_expedited
,
620 .call
= call_rcu_sched
,
621 .cb_barrier
= rcu_barrier_sched
,
622 .fqs
= rcu_sched_force_quiescent_state
,
629 * RCU torture priority-boost testing. Runs one real-time thread per
630 * CPU for moderate bursts, repeatedly registering RCU callbacks and
631 * spinning waiting for them to be invoked. If a given callback takes
632 * too long to be invoked, we assume that priority inversion has occurred.
635 struct rcu_boost_inflight
{
640 static void rcu_torture_boost_cb(struct rcu_head
*head
)
642 struct rcu_boost_inflight
*rbip
=
643 container_of(head
, struct rcu_boost_inflight
, rcu
);
645 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
649 static int rcu_torture_boost(void *arg
)
651 unsigned long call_rcu_time
;
652 unsigned long endtime
;
653 unsigned long oldstarttime
;
654 struct rcu_boost_inflight rbi
= { .inflight
= 0 };
655 struct sched_param sp
;
657 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
659 /* Set real-time priority. */
660 sp
.sched_priority
= 1;
661 if (sched_setscheduler(current
, SCHED_FIFO
, &sp
) < 0) {
662 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
663 n_rcu_torture_boost_rterror
++;
666 init_rcu_head_on_stack(&rbi
.rcu
);
667 /* Each pass through the following loop does one boost-test cycle. */
669 /* Wait for the next test interval. */
670 oldstarttime
= boost_starttime
;
671 while (ULONG_CMP_LT(jiffies
, oldstarttime
)) {
672 schedule_timeout_interruptible(oldstarttime
- jiffies
);
673 rcu_stutter_wait("rcu_torture_boost");
674 if (kthread_should_stop() ||
675 fullstop
!= FULLSTOP_DONTSTOP
)
679 /* Do one boost-test interval. */
680 endtime
= oldstarttime
+ test_boost_duration
* HZ
;
681 call_rcu_time
= jiffies
;
682 while (ULONG_CMP_LT(jiffies
, endtime
)) {
683 /* If we don't have a callback in flight, post one. */
685 smp_mb(); /* RCU core before ->inflight = 1. */
687 call_rcu(&rbi
.rcu
, rcu_torture_boost_cb
);
688 if (jiffies
- call_rcu_time
>
689 test_boost_duration
* HZ
- HZ
/ 2) {
690 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
691 n_rcu_torture_boost_failure
++;
693 call_rcu_time
= jiffies
;
696 rcu_stutter_wait("rcu_torture_boost");
697 if (kthread_should_stop() ||
698 fullstop
!= FULLSTOP_DONTSTOP
)
703 * Set the start time of the next test interval.
704 * Yes, this is vulnerable to long delays, but such
705 * delays simply cause a false negative for the next
706 * interval. Besides, we are running at RT priority,
707 * so delays should be relatively rare.
709 while (oldstarttime
== boost_starttime
&&
710 !kthread_should_stop()) {
711 if (mutex_trylock(&boost_mutex
)) {
712 boost_starttime
= jiffies
+
713 test_boost_interval
* HZ
;
714 n_rcu_torture_boosts
++;
715 mutex_unlock(&boost_mutex
);
718 schedule_timeout_uninterruptible(1);
721 /* Go do the stutter. */
722 checkwait
: rcu_stutter_wait("rcu_torture_boost");
723 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
725 /* Clean up and exit. */
726 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
727 rcutorture_shutdown_absorb("rcu_torture_boost");
728 while (!kthread_should_stop() || rbi
.inflight
)
729 schedule_timeout_uninterruptible(1);
730 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
731 destroy_rcu_head_on_stack(&rbi
.rcu
);
736 * RCU torture force-quiescent-state kthread. Repeatedly induces
737 * bursts of calls to force_quiescent_state(), increasing the probability
738 * of occurrence of some important types of race conditions.
741 rcu_torture_fqs(void *arg
)
743 unsigned long fqs_resume_time
;
744 int fqs_burst_remaining
;
746 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
748 fqs_resume_time
= jiffies
+ fqs_stutter
* HZ
;
749 while (ULONG_CMP_LT(jiffies
, fqs_resume_time
) &&
750 !kthread_should_stop()) {
751 schedule_timeout_interruptible(1);
753 fqs_burst_remaining
= fqs_duration
;
754 while (fqs_burst_remaining
> 0 &&
755 !kthread_should_stop()) {
758 fqs_burst_remaining
-= fqs_holdoff
;
760 rcu_stutter_wait("rcu_torture_fqs");
761 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
762 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
763 rcutorture_shutdown_absorb("rcu_torture_fqs");
764 while (!kthread_should_stop())
765 schedule_timeout_uninterruptible(1);
770 * RCU torture writer kthread. Repeatedly substitutes a new structure
771 * for that pointed to by rcu_torture_current, freeing the old structure
772 * after a series of grace periods (the "pipeline").
775 rcu_torture_writer(void *arg
)
779 struct rcu_torture
*rp
;
780 struct rcu_torture
*rp1
;
781 struct rcu_torture
*old_rp
;
782 static DEFINE_TORTURE_RANDOM(rand
);
784 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
785 set_user_nice(current
, 19);
788 schedule_timeout_uninterruptible(1);
789 rp
= rcu_torture_alloc();
792 rp
->rtort_pipe_count
= 0;
793 udelay(torture_random(&rand
) & 0x3ff);
794 old_rp
= rcu_dereference_check(rcu_torture_current
,
795 current
== writer_task
);
796 rp
->rtort_mbtest
= 1;
797 rcu_assign_pointer(rcu_torture_current
, rp
);
798 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
800 i
= old_rp
->rtort_pipe_count
;
801 if (i
> RCU_TORTURE_PIPE_LEN
)
802 i
= RCU_TORTURE_PIPE_LEN
;
803 atomic_inc(&rcu_torture_wcount
[i
]);
804 old_rp
->rtort_pipe_count
++;
805 if (gp_normal
== gp_exp
)
806 exp
= !!(torture_random(&rand
) & 0x80);
810 cur_ops
->deferred_free(old_rp
);
813 list_add(&old_rp
->rtort_free
,
814 &rcu_torture_removed
);
815 list_for_each_entry_safe(rp
, rp1
,
816 &rcu_torture_removed
,
818 i
= rp
->rtort_pipe_count
;
819 if (i
> RCU_TORTURE_PIPE_LEN
)
820 i
= RCU_TORTURE_PIPE_LEN
;
821 atomic_inc(&rcu_torture_wcount
[i
]);
822 if (++rp
->rtort_pipe_count
>=
823 RCU_TORTURE_PIPE_LEN
) {
824 rp
->rtort_mbtest
= 0;
825 list_del(&rp
->rtort_free
);
826 rcu_torture_free(rp
);
831 rcutorture_record_progress(++rcu_torture_current_version
);
832 rcu_stutter_wait("rcu_torture_writer");
833 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
834 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
835 rcutorture_shutdown_absorb("rcu_torture_writer");
836 while (!kthread_should_stop())
837 schedule_timeout_uninterruptible(1);
842 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
843 * delay between calls.
846 rcu_torture_fakewriter(void *arg
)
848 DEFINE_TORTURE_RANDOM(rand
);
850 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
851 set_user_nice(current
, 19);
854 schedule_timeout_uninterruptible(1 + torture_random(&rand
)%10);
855 udelay(torture_random(&rand
) & 0x3ff);
856 if (cur_ops
->cb_barrier
!= NULL
&&
857 torture_random(&rand
) % (nfakewriters
* 8) == 0) {
858 cur_ops
->cb_barrier();
859 } else if (gp_normal
== gp_exp
) {
860 if (torture_random(&rand
) & 0x80)
864 } else if (gp_normal
) {
869 rcu_stutter_wait("rcu_torture_fakewriter");
870 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
872 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
873 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
874 while (!kthread_should_stop())
875 schedule_timeout_uninterruptible(1);
879 void rcutorture_trace_dump(void)
881 static atomic_t beenhere
= ATOMIC_INIT(0);
883 if (atomic_read(&beenhere
))
885 if (atomic_xchg(&beenhere
, 1) != 0)
887 ftrace_dump(DUMP_ALL
);
891 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
892 * incrementing the corresponding element of the pipeline array. The
893 * counter in the element should never be greater than 1, otherwise, the
894 * RCU implementation is broken.
896 static void rcu_torture_timer(unsigned long unused
)
901 static DEFINE_TORTURE_RANDOM(rand
);
902 static DEFINE_SPINLOCK(rand_lock
);
903 struct rcu_torture
*p
;
905 unsigned long long ts
;
907 idx
= cur_ops
->readlock();
908 completed
= cur_ops
->completed();
909 ts
= rcu_trace_clock_local();
910 p
= rcu_dereference_check(rcu_torture_current
,
911 rcu_read_lock_bh_held() ||
912 rcu_read_lock_sched_held() ||
913 srcu_read_lock_held(&srcu_ctl
));
915 /* Leave because rcu_torture_writer is not yet underway */
916 cur_ops
->readunlock(idx
);
919 if (p
->rtort_mbtest
== 0)
920 atomic_inc(&n_rcu_torture_mberror
);
921 spin_lock(&rand_lock
);
922 cur_ops
->read_delay(&rand
);
923 n_rcu_torture_timers
++;
924 spin_unlock(&rand_lock
);
926 pipe_count
= p
->rtort_pipe_count
;
927 if (pipe_count
> RCU_TORTURE_PIPE_LEN
) {
928 /* Should not happen, but... */
929 pipe_count
= RCU_TORTURE_PIPE_LEN
;
931 completed_end
= cur_ops
->completed();
932 if (pipe_count
> 1) {
933 do_trace_rcu_torture_read(cur_ops
->name
, &p
->rtort_rcu
, ts
,
934 completed
, completed_end
);
935 rcutorture_trace_dump();
937 __this_cpu_inc(rcu_torture_count
[pipe_count
]);
938 completed
= completed_end
- completed
;
939 if (completed
> RCU_TORTURE_PIPE_LEN
) {
940 /* Should not happen, but... */
941 completed
= RCU_TORTURE_PIPE_LEN
;
943 __this_cpu_inc(rcu_torture_batch
[completed
]);
945 cur_ops
->readunlock(idx
);
949 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
950 * incrementing the corresponding element of the pipeline array. The
951 * counter in the element should never be greater than 1, otherwise, the
952 * RCU implementation is broken.
955 rcu_torture_reader(void *arg
)
960 DEFINE_TORTURE_RANDOM(rand
);
961 struct rcu_torture
*p
;
964 unsigned long long ts
;
966 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
967 set_user_nice(current
, 19);
968 if (irqreader
&& cur_ops
->irq_capable
)
969 setup_timer_on_stack(&t
, rcu_torture_timer
, 0);
972 if (irqreader
&& cur_ops
->irq_capable
) {
973 if (!timer_pending(&t
))
974 mod_timer(&t
, jiffies
+ 1);
976 idx
= cur_ops
->readlock();
977 completed
= cur_ops
->completed();
978 ts
= rcu_trace_clock_local();
979 p
= rcu_dereference_check(rcu_torture_current
,
980 rcu_read_lock_bh_held() ||
981 rcu_read_lock_sched_held() ||
982 srcu_read_lock_held(&srcu_ctl
));
984 /* Wait for rcu_torture_writer to get underway */
985 cur_ops
->readunlock(idx
);
986 schedule_timeout_interruptible(HZ
);
989 if (p
->rtort_mbtest
== 0)
990 atomic_inc(&n_rcu_torture_mberror
);
991 cur_ops
->read_delay(&rand
);
993 pipe_count
= p
->rtort_pipe_count
;
994 if (pipe_count
> RCU_TORTURE_PIPE_LEN
) {
995 /* Should not happen, but... */
996 pipe_count
= RCU_TORTURE_PIPE_LEN
;
998 completed_end
= cur_ops
->completed();
999 if (pipe_count
> 1) {
1000 do_trace_rcu_torture_read(cur_ops
->name
, &p
->rtort_rcu
,
1001 ts
, completed
, completed_end
);
1002 rcutorture_trace_dump();
1004 __this_cpu_inc(rcu_torture_count
[pipe_count
]);
1005 completed
= completed_end
- completed
;
1006 if (completed
> RCU_TORTURE_PIPE_LEN
) {
1007 /* Should not happen, but... */
1008 completed
= RCU_TORTURE_PIPE_LEN
;
1010 __this_cpu_inc(rcu_torture_batch
[completed
]);
1012 cur_ops
->readunlock(idx
);
1014 rcu_stutter_wait("rcu_torture_reader");
1015 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
1016 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
1017 rcutorture_shutdown_absorb("rcu_torture_reader");
1018 if (irqreader
&& cur_ops
->irq_capable
)
1020 while (!kthread_should_stop())
1021 schedule_timeout_uninterruptible(1);
1026 * Create an RCU-torture statistics message in the specified buffer.
1029 rcu_torture_printk(char *page
)
1033 long pipesummary
[RCU_TORTURE_PIPE_LEN
+ 1] = { 0 };
1034 long batchsummary
[RCU_TORTURE_PIPE_LEN
+ 1] = { 0 };
1036 for_each_possible_cpu(cpu
) {
1037 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
1038 pipesummary
[i
] += per_cpu(rcu_torture_count
, cpu
)[i
];
1039 batchsummary
[i
] += per_cpu(rcu_torture_batch
, cpu
)[i
];
1042 for (i
= RCU_TORTURE_PIPE_LEN
- 1; i
>= 0; i
--) {
1043 if (pipesummary
[i
] != 0)
1046 page
+= sprintf(page
, "%s%s ", torture_type
, TORTURE_FLAG
);
1047 page
+= sprintf(page
,
1048 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
1049 rcu_torture_current
,
1050 rcu_torture_current_version
,
1051 list_empty(&rcu_torture_freelist
),
1052 atomic_read(&n_rcu_torture_alloc
),
1053 atomic_read(&n_rcu_torture_alloc_fail
),
1054 atomic_read(&n_rcu_torture_free
));
1055 page
+= sprintf(page
, "rtmbe: %d rtbke: %ld rtbre: %ld ",
1056 atomic_read(&n_rcu_torture_mberror
),
1057 n_rcu_torture_boost_ktrerror
,
1058 n_rcu_torture_boost_rterror
);
1059 page
+= sprintf(page
, "rtbf: %ld rtb: %ld nt: %ld ",
1060 n_rcu_torture_boost_failure
,
1061 n_rcu_torture_boosts
,
1062 n_rcu_torture_timers
);
1063 page
+= sprintf(page
,
1064 "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ",
1065 n_online_successes
, n_online_attempts
,
1066 n_offline_successes
, n_offline_attempts
,
1067 min_online
, max_online
,
1068 min_offline
, max_offline
,
1069 sum_online
, sum_offline
, HZ
);
1070 page
+= sprintf(page
, "barrier: %ld/%ld:%ld",
1071 n_barrier_successes
,
1073 n_rcu_torture_barrier_error
);
1074 page
+= sprintf(page
, "\n%s%s ", torture_type
, TORTURE_FLAG
);
1075 if (atomic_read(&n_rcu_torture_mberror
) != 0 ||
1076 n_rcu_torture_barrier_error
!= 0 ||
1077 n_rcu_torture_boost_ktrerror
!= 0 ||
1078 n_rcu_torture_boost_rterror
!= 0 ||
1079 n_rcu_torture_boost_failure
!= 0 ||
1081 page
+= sprintf(page
, "!!! ");
1082 atomic_inc(&n_rcu_torture_error
);
1085 page
+= sprintf(page
, "Reader Pipe: ");
1086 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
1087 page
+= sprintf(page
, " %ld", pipesummary
[i
]);
1088 page
+= sprintf(page
, "\n%s%s ", torture_type
, TORTURE_FLAG
);
1089 page
+= sprintf(page
, "Reader Batch: ");
1090 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
1091 page
+= sprintf(page
, " %ld", batchsummary
[i
]);
1092 page
+= sprintf(page
, "\n%s%s ", torture_type
, TORTURE_FLAG
);
1093 page
+= sprintf(page
, "Free-Block Circulation: ");
1094 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
1095 page
+= sprintf(page
, " %d",
1096 atomic_read(&rcu_torture_wcount
[i
]));
1098 page
+= sprintf(page
, "\n");
1100 cur_ops
->stats(page
);
1104 * Print torture statistics. Caller must ensure that there is only
1105 * one call to this function at a given time!!! This is normally
1106 * accomplished by relying on the module system to only have one copy
1107 * of the module loaded, and then by giving the rcu_torture_stats
1108 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1109 * thread is not running).
1112 rcu_torture_stats_print(void)
1114 int size
= nr_cpu_ids
* 200 + 8192;
1117 buf
= kmalloc(size
, GFP_KERNEL
);
1119 pr_err("rcu-torture: Out of memory, need: %d", size
);
1122 rcu_torture_printk(buf
);
1123 pr_alert("%s", buf
);
1128 * Periodically prints torture statistics, if periodic statistics printing
1129 * was specified via the stat_interval module parameter.
1131 * No need to worry about fullstop here, since this one doesn't reference
1132 * volatile state or register callbacks.
1135 rcu_torture_stats(void *arg
)
1137 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1139 schedule_timeout_interruptible(stat_interval
* HZ
);
1140 rcu_torture_stats_print();
1141 rcutorture_shutdown_absorb("rcu_torture_stats");
1142 } while (!kthread_should_stop());
1143 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1147 static int rcu_idle_cpu
; /* Force all torture tasks off this CPU */
1149 /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1150 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1152 static void rcu_torture_shuffle_tasks(void)
1156 cpumask_setall(shuffle_tmp_mask
);
1159 /* No point in shuffling if there is only one online CPU (ex: UP) */
1160 if (num_online_cpus() == 1) {
1165 if (rcu_idle_cpu
!= -1)
1166 cpumask_clear_cpu(rcu_idle_cpu
, shuffle_tmp_mask
);
1168 set_cpus_allowed_ptr(current
, shuffle_tmp_mask
);
1171 for (i
= 0; i
< nrealreaders
; i
++)
1172 if (reader_tasks
[i
])
1173 set_cpus_allowed_ptr(reader_tasks
[i
],
1176 if (fakewriter_tasks
) {
1177 for (i
= 0; i
< nfakewriters
; i
++)
1178 if (fakewriter_tasks
[i
])
1179 set_cpus_allowed_ptr(fakewriter_tasks
[i
],
1183 set_cpus_allowed_ptr(writer_task
, shuffle_tmp_mask
);
1185 set_cpus_allowed_ptr(stats_task
, shuffle_tmp_mask
);
1187 set_cpus_allowed_ptr(stutter_task
, shuffle_tmp_mask
);
1189 set_cpus_allowed_ptr(fqs_task
, shuffle_tmp_mask
);
1191 set_cpus_allowed_ptr(shutdown_task
, shuffle_tmp_mask
);
1192 #ifdef CONFIG_HOTPLUG_CPU
1194 set_cpus_allowed_ptr(onoff_task
, shuffle_tmp_mask
);
1195 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
1197 set_cpus_allowed_ptr(stall_task
, shuffle_tmp_mask
);
1198 if (barrier_cbs_tasks
)
1199 for (i
= 0; i
< n_barrier_cbs
; i
++)
1200 if (barrier_cbs_tasks
[i
])
1201 set_cpus_allowed_ptr(barrier_cbs_tasks
[i
],
1204 set_cpus_allowed_ptr(barrier_task
, shuffle_tmp_mask
);
1206 if (rcu_idle_cpu
== -1)
1207 rcu_idle_cpu
= num_online_cpus() - 1;
1214 /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1215 * system to become idle at a time and cut off its timer ticks. This is meant
1216 * to test the support for such tickless idle CPU in RCU.
1219 rcu_torture_shuffle(void *arg
)
1221 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1223 schedule_timeout_interruptible(shuffle_interval
* HZ
);
1224 rcu_torture_shuffle_tasks();
1225 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1226 } while (!kthread_should_stop());
1227 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1231 /* Cause the rcutorture test to "stutter", starting and stopping all
1232 * threads periodically.
1235 rcu_torture_stutter(void *arg
)
1237 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1239 schedule_timeout_interruptible(stutter
* HZ
);
1240 stutter_pause_test
= 1;
1241 if (!kthread_should_stop())
1242 schedule_timeout_interruptible(stutter
* HZ
);
1243 stutter_pause_test
= 0;
1244 rcutorture_shutdown_absorb("rcu_torture_stutter");
1245 } while (!kthread_should_stop());
1246 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1251 rcu_torture_print_module_parms(struct rcu_torture_ops
*cur_ops
, const char *tag
)
1253 pr_alert("%s" TORTURE_FLAG
1254 "--- %s: nreaders=%d nfakewriters=%d "
1255 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1256 "shuffle_interval=%d stutter=%d irqreader=%d "
1257 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1258 "test_boost=%d/%d test_boost_interval=%d "
1259 "test_boost_duration=%d shutdown_secs=%d "
1260 "stall_cpu=%d stall_cpu_holdoff=%d "
1262 "onoff_interval=%d onoff_holdoff=%d\n",
1263 torture_type
, tag
, nrealreaders
, nfakewriters
,
1264 stat_interval
, verbose
, test_no_idle_hz
, shuffle_interval
,
1265 stutter
, irqreader
, fqs_duration
, fqs_holdoff
, fqs_stutter
,
1266 test_boost
, cur_ops
->can_boost
,
1267 test_boost_interval
, test_boost_duration
, shutdown_secs
,
1268 stall_cpu
, stall_cpu_holdoff
,
1270 onoff_interval
, onoff_holdoff
);
1273 static struct notifier_block rcutorture_shutdown_nb
= {
1274 .notifier_call
= rcutorture_shutdown_notify
,
1277 static void rcutorture_booster_cleanup(int cpu
)
1279 struct task_struct
*t
;
1281 if (boost_tasks
[cpu
] == NULL
)
1283 mutex_lock(&boost_mutex
);
1284 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1285 t
= boost_tasks
[cpu
];
1286 boost_tasks
[cpu
] = NULL
;
1287 mutex_unlock(&boost_mutex
);
1289 /* This must be outside of the mutex, otherwise deadlock! */
1291 boost_tasks
[cpu
] = NULL
;
1294 static int rcutorture_booster_init(int cpu
)
1298 if (boost_tasks
[cpu
] != NULL
)
1299 return 0; /* Already created, nothing more to do. */
1301 /* Don't allow time recalculation while creating a new task. */
1302 mutex_lock(&boost_mutex
);
1303 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
1304 boost_tasks
[cpu
] = kthread_create_on_node(rcu_torture_boost
, NULL
,
1306 "rcu_torture_boost");
1307 if (IS_ERR(boost_tasks
[cpu
])) {
1308 retval
= PTR_ERR(boost_tasks
[cpu
]);
1309 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1310 n_rcu_torture_boost_ktrerror
++;
1311 boost_tasks
[cpu
] = NULL
;
1312 mutex_unlock(&boost_mutex
);
1315 kthread_bind(boost_tasks
[cpu
], cpu
);
1316 wake_up_process(boost_tasks
[cpu
]);
1317 mutex_unlock(&boost_mutex
);
1322 * Cause the rcutorture test to shutdown the system after the test has
1323 * run for the time specified by the shutdown_secs module parameter.
1326 rcu_torture_shutdown(void *arg
)
1329 unsigned long jiffies_snap
;
1331 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1332 jiffies_snap
= ACCESS_ONCE(jiffies
);
1333 while (ULONG_CMP_LT(jiffies_snap
, shutdown_time
) &&
1334 !kthread_should_stop()) {
1335 delta
= shutdown_time
- jiffies_snap
;
1337 pr_alert("%s" TORTURE_FLAG
1338 "rcu_torture_shutdown task: %lu jiffies remaining\n",
1339 torture_type
, delta
);
1340 schedule_timeout_interruptible(delta
);
1341 jiffies_snap
= ACCESS_ONCE(jiffies
);
1343 if (kthread_should_stop()) {
1344 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1348 /* OK, shut down the system. */
1350 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1351 shutdown_task
= NULL
; /* Avoid self-kill deadlock. */
1352 rcu_torture_cleanup(); /* Get the success/failure message. */
1353 kernel_power_off(); /* Shut down the system. */
1357 #ifdef CONFIG_HOTPLUG_CPU
1360 * Execute random CPU-hotplug operations at the interval specified
1361 * by the onoff_interval.
1364 rcu_torture_onoff(void *arg
)
1367 unsigned long delta
;
1369 DEFINE_TORTURE_RANDOM(rand
);
1371 unsigned long starttime
;
1373 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1374 for_each_online_cpu(cpu
)
1376 WARN_ON(maxcpu
< 0);
1377 if (onoff_holdoff
> 0) {
1378 VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff");
1379 schedule_timeout_interruptible(onoff_holdoff
* HZ
);
1380 VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff");
1382 while (!kthread_should_stop()) {
1383 cpu
= (torture_random(&rand
) >> 4) % (maxcpu
+ 1);
1384 if (cpu_online(cpu
) && cpu_is_hotpluggable(cpu
)) {
1386 pr_alert("%s" TORTURE_FLAG
1387 "rcu_torture_onoff task: offlining %d\n",
1389 starttime
= jiffies
;
1390 n_offline_attempts
++;
1391 ret
= cpu_down(cpu
);
1394 pr_alert("%s" TORTURE_FLAG
1395 "rcu_torture_onoff task: offline %d failed: errno %d\n",
1396 torture_type
, cpu
, ret
);
1399 pr_alert("%s" TORTURE_FLAG
1400 "rcu_torture_onoff task: offlined %d\n",
1402 n_offline_successes
++;
1403 delta
= jiffies
- starttime
;
1404 sum_offline
+= delta
;
1405 if (min_offline
< 0) {
1406 min_offline
= delta
;
1407 max_offline
= delta
;
1409 if (min_offline
> delta
)
1410 min_offline
= delta
;
1411 if (max_offline
< delta
)
1412 max_offline
= delta
;
1414 } else if (cpu_is_hotpluggable(cpu
)) {
1416 pr_alert("%s" TORTURE_FLAG
1417 "rcu_torture_onoff task: onlining %d\n",
1419 starttime
= jiffies
;
1420 n_online_attempts
++;
1424 pr_alert("%s" TORTURE_FLAG
1425 "rcu_torture_onoff task: online %d failed: errno %d\n",
1426 torture_type
, cpu
, ret
);
1429 pr_alert("%s" TORTURE_FLAG
1430 "rcu_torture_onoff task: onlined %d\n",
1432 n_online_successes
++;
1433 delta
= jiffies
- starttime
;
1434 sum_online
+= delta
;
1435 if (min_online
< 0) {
1439 if (min_online
> delta
)
1441 if (max_online
< delta
)
1445 schedule_timeout_interruptible(onoff_interval
* HZ
);
1447 VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1452 rcu_torture_onoff_init(void)
1456 if (onoff_interval
<= 0)
1458 onoff_task
= kthread_run(rcu_torture_onoff
, NULL
, "rcu_torture_onoff");
1459 if (IS_ERR(onoff_task
)) {
1460 ret
= PTR_ERR(onoff_task
);
1467 static void rcu_torture_onoff_cleanup(void)
1469 if (onoff_task
== NULL
)
1471 VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1472 kthread_stop(onoff_task
);
1476 #else /* #ifdef CONFIG_HOTPLUG_CPU */
1479 rcu_torture_onoff_init(void)
1484 static void rcu_torture_onoff_cleanup(void)
1488 #endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1491 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1492 * induces a CPU stall for the time specified by stall_cpu.
1494 static int rcu_torture_stall(void *args
)
1496 unsigned long stop_at
;
1498 VERBOSE_PRINTK_STRING("rcu_torture_stall task started");
1499 if (stall_cpu_holdoff
> 0) {
1500 VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff");
1501 schedule_timeout_interruptible(stall_cpu_holdoff
* HZ
);
1502 VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff");
1504 if (!kthread_should_stop()) {
1505 stop_at
= get_seconds() + stall_cpu
;
1506 /* RCU CPU stall is expected behavior in following code. */
1507 pr_alert("rcu_torture_stall start.\n");
1510 while (ULONG_CMP_LT(get_seconds(), stop_at
))
1511 continue; /* Induce RCU CPU stall warning. */
1514 pr_alert("rcu_torture_stall end.\n");
1516 rcutorture_shutdown_absorb("rcu_torture_stall");
1517 while (!kthread_should_stop())
1518 schedule_timeout_interruptible(10 * HZ
);
1522 /* Spawn CPU-stall kthread, if stall_cpu specified. */
1523 static int __init
rcu_torture_stall_init(void)
1529 stall_task
= kthread_run(rcu_torture_stall
, NULL
, "rcu_torture_stall");
1530 if (IS_ERR(stall_task
)) {
1531 ret
= PTR_ERR(stall_task
);
1538 /* Clean up after the CPU-stall kthread, if one was spawned. */
1539 static void rcu_torture_stall_cleanup(void)
1541 if (stall_task
== NULL
)
1543 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task.");
1544 kthread_stop(stall_task
);
1548 /* Callback function for RCU barrier testing. */
1549 void rcu_torture_barrier_cbf(struct rcu_head
*rcu
)
1551 atomic_inc(&barrier_cbs_invoked
);
1554 /* kthread function to register callbacks used to test RCU barriers. */
1555 static int rcu_torture_barrier_cbs(void *arg
)
1557 long myid
= (long)arg
;
1560 struct rcu_head rcu
;
1562 init_rcu_head_on_stack(&rcu
);
1563 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
1564 set_user_nice(current
, 19);
1566 wait_event(barrier_cbs_wq
[myid
],
1568 ACCESS_ONCE(barrier_phase
)) != lastphase
||
1569 kthread_should_stop() ||
1570 fullstop
!= FULLSTOP_DONTSTOP
);
1571 lastphase
= newphase
;
1572 smp_mb(); /* ensure barrier_phase load before ->call(). */
1573 if (kthread_should_stop() || fullstop
!= FULLSTOP_DONTSTOP
)
1575 cur_ops
->call(&rcu
, rcu_torture_barrier_cbf
);
1576 if (atomic_dec_and_test(&barrier_cbs_count
))
1577 wake_up(&barrier_wq
);
1578 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
1579 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task stopping");
1580 rcutorture_shutdown_absorb("rcu_torture_barrier_cbs");
1581 while (!kthread_should_stop())
1582 schedule_timeout_interruptible(1);
1583 cur_ops
->cb_barrier();
1584 destroy_rcu_head_on_stack(&rcu
);
1588 /* kthread function to drive and coordinate RCU barrier testing. */
1589 static int rcu_torture_barrier(void *arg
)
1593 VERBOSE_PRINTK_STRING("rcu_torture_barrier task starting");
1595 atomic_set(&barrier_cbs_invoked
, 0);
1596 atomic_set(&barrier_cbs_count
, n_barrier_cbs
);
1597 smp_mb(); /* Ensure barrier_phase after prior assignments. */
1598 barrier_phase
= !barrier_phase
;
1599 for (i
= 0; i
< n_barrier_cbs
; i
++)
1600 wake_up(&barrier_cbs_wq
[i
]);
1601 wait_event(barrier_wq
,
1602 atomic_read(&barrier_cbs_count
) == 0 ||
1603 kthread_should_stop() ||
1604 fullstop
!= FULLSTOP_DONTSTOP
);
1605 if (kthread_should_stop() || fullstop
!= FULLSTOP_DONTSTOP
)
1607 n_barrier_attempts
++;
1608 cur_ops
->cb_barrier(); /* Implies smp_mb() for wait_event(). */
1609 if (atomic_read(&barrier_cbs_invoked
) != n_barrier_cbs
) {
1610 n_rcu_torture_barrier_error
++;
1613 n_barrier_successes
++;
1614 schedule_timeout_interruptible(HZ
/ 10);
1615 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
1616 VERBOSE_PRINTK_STRING("rcu_torture_barrier task stopping");
1617 rcutorture_shutdown_absorb("rcu_torture_barrier");
1618 while (!kthread_should_stop())
1619 schedule_timeout_interruptible(1);
1623 /* Initialize RCU barrier testing. */
1624 static int rcu_torture_barrier_init(void)
1629 if (n_barrier_cbs
== 0)
1631 if (cur_ops
->call
== NULL
|| cur_ops
->cb_barrier
== NULL
) {
1632 pr_alert("%s" TORTURE_FLAG
1633 " Call or barrier ops missing for %s,\n",
1634 torture_type
, cur_ops
->name
);
1635 pr_alert("%s" TORTURE_FLAG
1636 " RCU barrier testing omitted from run.\n",
1640 atomic_set(&barrier_cbs_count
, 0);
1641 atomic_set(&barrier_cbs_invoked
, 0);
1643 kzalloc(n_barrier_cbs
* sizeof(barrier_cbs_tasks
[0]),
1646 kzalloc(n_barrier_cbs
* sizeof(barrier_cbs_wq
[0]),
1648 if (barrier_cbs_tasks
== NULL
|| !barrier_cbs_wq
)
1650 for (i
= 0; i
< n_barrier_cbs
; i
++) {
1651 init_waitqueue_head(&barrier_cbs_wq
[i
]);
1652 barrier_cbs_tasks
[i
] = kthread_run(rcu_torture_barrier_cbs
,
1654 "rcu_torture_barrier_cbs");
1655 if (IS_ERR(barrier_cbs_tasks
[i
])) {
1656 ret
= PTR_ERR(barrier_cbs_tasks
[i
]);
1657 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier_cbs");
1658 barrier_cbs_tasks
[i
] = NULL
;
1662 barrier_task
= kthread_run(rcu_torture_barrier
, NULL
,
1663 "rcu_torture_barrier");
1664 if (IS_ERR(barrier_task
)) {
1665 ret
= PTR_ERR(barrier_task
);
1666 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier");
1667 barrier_task
= NULL
;
1672 /* Clean up after RCU barrier testing. */
1673 static void rcu_torture_barrier_cleanup(void)
1677 if (barrier_task
!= NULL
) {
1678 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier task");
1679 kthread_stop(barrier_task
);
1680 barrier_task
= NULL
;
1682 if (barrier_cbs_tasks
!= NULL
) {
1683 for (i
= 0; i
< n_barrier_cbs
; i
++) {
1684 if (barrier_cbs_tasks
[i
] != NULL
) {
1685 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier_cbs task");
1686 kthread_stop(barrier_cbs_tasks
[i
]);
1687 barrier_cbs_tasks
[i
] = NULL
;
1690 kfree(barrier_cbs_tasks
);
1691 barrier_cbs_tasks
= NULL
;
1693 if (barrier_cbs_wq
!= NULL
) {
1694 kfree(barrier_cbs_wq
);
1695 barrier_cbs_wq
= NULL
;
1699 static int rcutorture_cpu_notify(struct notifier_block
*self
,
1700 unsigned long action
, void *hcpu
)
1702 long cpu
= (long)hcpu
;
1706 case CPU_DOWN_FAILED
:
1707 (void)rcutorture_booster_init(cpu
);
1709 case CPU_DOWN_PREPARE
:
1710 rcutorture_booster_cleanup(cpu
);
1718 static struct notifier_block rcutorture_cpu_nb
= {
1719 .notifier_call
= rcutorture_cpu_notify
,
1723 rcu_torture_cleanup(void)
1727 mutex_lock(&fullstop_mutex
);
1728 rcutorture_record_test_transition();
1729 if (fullstop
== FULLSTOP_SHUTDOWN
) {
1730 pr_warn(/* but going down anyway, so... */
1731 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
1732 mutex_unlock(&fullstop_mutex
);
1733 schedule_timeout_uninterruptible(10);
1734 if (cur_ops
->cb_barrier
!= NULL
)
1735 cur_ops
->cb_barrier();
1738 fullstop
= FULLSTOP_RMMOD
;
1739 mutex_unlock(&fullstop_mutex
);
1740 unregister_reboot_notifier(&rcutorture_shutdown_nb
);
1741 rcu_torture_barrier_cleanup();
1742 rcu_torture_stall_cleanup();
1744 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1745 kthread_stop(stutter_task
);
1747 stutter_task
= NULL
;
1748 if (shuffler_task
) {
1749 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1750 kthread_stop(shuffler_task
);
1751 free_cpumask_var(shuffle_tmp_mask
);
1753 shuffler_task
= NULL
;
1756 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1757 kthread_stop(writer_task
);
1762 for (i
= 0; i
< nrealreaders
; i
++) {
1763 if (reader_tasks
[i
]) {
1764 VERBOSE_PRINTK_STRING(
1765 "Stopping rcu_torture_reader task");
1766 kthread_stop(reader_tasks
[i
]);
1768 reader_tasks
[i
] = NULL
;
1770 kfree(reader_tasks
);
1771 reader_tasks
= NULL
;
1773 rcu_torture_current
= NULL
;
1775 if (fakewriter_tasks
) {
1776 for (i
= 0; i
< nfakewriters
; i
++) {
1777 if (fakewriter_tasks
[i
]) {
1778 VERBOSE_PRINTK_STRING(
1779 "Stopping rcu_torture_fakewriter task");
1780 kthread_stop(fakewriter_tasks
[i
]);
1782 fakewriter_tasks
[i
] = NULL
;
1784 kfree(fakewriter_tasks
);
1785 fakewriter_tasks
= NULL
;
1789 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1790 kthread_stop(stats_task
);
1795 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1796 kthread_stop(fqs_task
);
1799 if ((test_boost
== 1 && cur_ops
->can_boost
) ||
1801 unregister_cpu_notifier(&rcutorture_cpu_nb
);
1802 for_each_possible_cpu(i
)
1803 rcutorture_booster_cleanup(i
);
1805 if (shutdown_task
!= NULL
) {
1806 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1807 kthread_stop(shutdown_task
);
1809 shutdown_task
= NULL
;
1810 rcu_torture_onoff_cleanup();
1812 /* Wait for all RCU callbacks to fire. */
1814 if (cur_ops
->cb_barrier
!= NULL
)
1815 cur_ops
->cb_barrier();
1817 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
1819 if (atomic_read(&n_rcu_torture_error
) || n_rcu_torture_barrier_error
)
1820 rcu_torture_print_module_parms(cur_ops
, "End of test: FAILURE");
1821 else if (n_online_successes
!= n_online_attempts
||
1822 n_offline_successes
!= n_offline_attempts
)
1823 rcu_torture_print_module_parms(cur_ops
,
1824 "End of test: RCU_HOTPLUG");
1826 rcu_torture_print_module_parms(cur_ops
, "End of test: SUCCESS");
1829 #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1830 static void rcu_torture_leak_cb(struct rcu_head
*rhp
)
1834 static void rcu_torture_err_cb(struct rcu_head
*rhp
)
1837 * This -might- happen due to race conditions, but is unlikely.
1838 * The scenario that leads to this happening is that the
1839 * first of the pair of duplicate callbacks is queued,
1840 * someone else starts a grace period that includes that
1841 * callback, then the second of the pair must wait for the
1842 * next grace period. Unlikely, but can happen. If it
1843 * does happen, the debug-objects subsystem won't have splatted.
1845 pr_alert("rcutorture: duplicated callback was invoked.\n");
1847 #endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1850 * Verify that double-free causes debug-objects to complain, but only
1851 * if CONFIG_DEBUG_OBJECTS_RCU_HEAD=y. Otherwise, say that the test
1852 * cannot be carried out.
1854 static void rcu_test_debug_objects(void)
1856 #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1857 struct rcu_head rh1
;
1858 struct rcu_head rh2
;
1860 init_rcu_head_on_stack(&rh1
);
1861 init_rcu_head_on_stack(&rh2
);
1862 pr_alert("rcutorture: WARN: Duplicate call_rcu() test starting.\n");
1864 /* Try to queue the rh2 pair of callbacks for the same grace period. */
1865 preempt_disable(); /* Prevent preemption from interrupting test. */
1866 rcu_read_lock(); /* Make it impossible to finish a grace period. */
1867 call_rcu(&rh1
, rcu_torture_leak_cb
); /* Start grace period. */
1868 local_irq_disable(); /* Make it harder to start a new grace period. */
1869 call_rcu(&rh2
, rcu_torture_leak_cb
);
1870 call_rcu(&rh2
, rcu_torture_err_cb
); /* Duplicate callback. */
1875 /* Wait for them all to get done so we can safely return. */
1877 pr_alert("rcutorture: WARN: Duplicate call_rcu() test complete.\n");
1878 destroy_rcu_head_on_stack(&rh1
);
1879 destroy_rcu_head_on_stack(&rh2
);
1880 #else /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1881 pr_alert("rcutorture: !CONFIG_DEBUG_OBJECTS_RCU_HEAD, not testing duplicate call_rcu()\n");
1882 #endif /* #else #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1886 rcu_torture_init(void)
1892 static struct rcu_torture_ops
*torture_ops
[] = {
1893 &rcu_ops
, &rcu_bh_ops
, &srcu_ops
, &sched_ops
,
1896 mutex_lock(&fullstop_mutex
);
1898 /* Process args and tell the world that the torturer is on the job. */
1899 for (i
= 0; i
< ARRAY_SIZE(torture_ops
); i
++) {
1900 cur_ops
= torture_ops
[i
];
1901 if (strcmp(torture_type
, cur_ops
->name
) == 0)
1904 if (i
== ARRAY_SIZE(torture_ops
)) {
1905 pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
1907 pr_alert("rcu-torture types:");
1908 for (i
= 0; i
< ARRAY_SIZE(torture_ops
); i
++)
1909 pr_alert(" %s", torture_ops
[i
]->name
);
1911 mutex_unlock(&fullstop_mutex
);
1914 if (cur_ops
->fqs
== NULL
&& fqs_duration
!= 0) {
1915 pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
1919 cur_ops
->init(); /* no "goto unwind" prior to this point!!! */
1922 nrealreaders
= nreaders
;
1924 nrealreaders
= 2 * num_online_cpus();
1925 rcu_torture_print_module_parms(cur_ops
, "Start of test");
1926 fullstop
= FULLSTOP_DONTSTOP
;
1928 /* Set up the freelist. */
1930 INIT_LIST_HEAD(&rcu_torture_freelist
);
1931 for (i
= 0; i
< ARRAY_SIZE(rcu_tortures
); i
++) {
1932 rcu_tortures
[i
].rtort_mbtest
= 0;
1933 list_add_tail(&rcu_tortures
[i
].rtort_free
,
1934 &rcu_torture_freelist
);
1937 /* Initialize the statistics so that each run gets its own numbers. */
1939 rcu_torture_current
= NULL
;
1940 rcu_torture_current_version
= 0;
1941 atomic_set(&n_rcu_torture_alloc
, 0);
1942 atomic_set(&n_rcu_torture_alloc_fail
, 0);
1943 atomic_set(&n_rcu_torture_free
, 0);
1944 atomic_set(&n_rcu_torture_mberror
, 0);
1945 atomic_set(&n_rcu_torture_error
, 0);
1946 n_rcu_torture_barrier_error
= 0;
1947 n_rcu_torture_boost_ktrerror
= 0;
1948 n_rcu_torture_boost_rterror
= 0;
1949 n_rcu_torture_boost_failure
= 0;
1950 n_rcu_torture_boosts
= 0;
1951 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
1952 atomic_set(&rcu_torture_wcount
[i
], 0);
1953 for_each_possible_cpu(cpu
) {
1954 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
1955 per_cpu(rcu_torture_count
, cpu
)[i
] = 0;
1956 per_cpu(rcu_torture_batch
, cpu
)[i
] = 0;
1960 /* Start up the kthreads. */
1962 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1963 writer_task
= kthread_create(rcu_torture_writer
, NULL
,
1964 "rcu_torture_writer");
1965 if (IS_ERR(writer_task
)) {
1966 firsterr
= PTR_ERR(writer_task
);
1967 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1971 wake_up_process(writer_task
);
1972 fakewriter_tasks
= kzalloc(nfakewriters
* sizeof(fakewriter_tasks
[0]),
1974 if (fakewriter_tasks
== NULL
) {
1975 VERBOSE_PRINTK_ERRSTRING("out of memory");
1979 for (i
= 0; i
< nfakewriters
; i
++) {
1980 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
1981 fakewriter_tasks
[i
] = kthread_run(rcu_torture_fakewriter
, NULL
,
1982 "rcu_torture_fakewriter");
1983 if (IS_ERR(fakewriter_tasks
[i
])) {
1984 firsterr
= PTR_ERR(fakewriter_tasks
[i
]);
1985 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
1986 fakewriter_tasks
[i
] = NULL
;
1990 reader_tasks
= kzalloc(nrealreaders
* sizeof(reader_tasks
[0]),
1992 if (reader_tasks
== NULL
) {
1993 VERBOSE_PRINTK_ERRSTRING("out of memory");
1997 for (i
= 0; i
< nrealreaders
; i
++) {
1998 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
1999 reader_tasks
[i
] = kthread_run(rcu_torture_reader
, NULL
,
2000 "rcu_torture_reader");
2001 if (IS_ERR(reader_tasks
[i
])) {
2002 firsterr
= PTR_ERR(reader_tasks
[i
]);
2003 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
2004 reader_tasks
[i
] = NULL
;
2008 if (stat_interval
> 0) {
2009 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
2010 stats_task
= kthread_run(rcu_torture_stats
, NULL
,
2011 "rcu_torture_stats");
2012 if (IS_ERR(stats_task
)) {
2013 firsterr
= PTR_ERR(stats_task
);
2014 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
2019 if (test_no_idle_hz
) {
2020 rcu_idle_cpu
= num_online_cpus() - 1;
2022 if (!alloc_cpumask_var(&shuffle_tmp_mask
, GFP_KERNEL
)) {
2024 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
2028 /* Create the shuffler thread */
2029 shuffler_task
= kthread_run(rcu_torture_shuffle
, NULL
,
2030 "rcu_torture_shuffle");
2031 if (IS_ERR(shuffler_task
)) {
2032 free_cpumask_var(shuffle_tmp_mask
);
2033 firsterr
= PTR_ERR(shuffler_task
);
2034 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
2035 shuffler_task
= NULL
;
2042 /* Create the stutter thread */
2043 stutter_task
= kthread_run(rcu_torture_stutter
, NULL
,
2044 "rcu_torture_stutter");
2045 if (IS_ERR(stutter_task
)) {
2046 firsterr
= PTR_ERR(stutter_task
);
2047 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
2048 stutter_task
= NULL
;
2052 if (fqs_duration
< 0)
2055 /* Create the stutter thread */
2056 fqs_task
= kthread_run(rcu_torture_fqs
, NULL
,
2058 if (IS_ERR(fqs_task
)) {
2059 firsterr
= PTR_ERR(fqs_task
);
2060 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
2065 if (test_boost_interval
< 1)
2066 test_boost_interval
= 1;
2067 if (test_boost_duration
< 2)
2068 test_boost_duration
= 2;
2069 if ((test_boost
== 1 && cur_ops
->can_boost
) ||
2072 boost_starttime
= jiffies
+ test_boost_interval
* HZ
;
2073 register_cpu_notifier(&rcutorture_cpu_nb
);
2074 for_each_possible_cpu(i
) {
2075 if (cpu_is_offline(i
))
2076 continue; /* Heuristic: CPU can go offline. */
2077 retval
= rcutorture_booster_init(i
);
2084 if (shutdown_secs
> 0) {
2085 shutdown_time
= jiffies
+ shutdown_secs
* HZ
;
2086 shutdown_task
= kthread_create(rcu_torture_shutdown
, NULL
,
2087 "rcu_torture_shutdown");
2088 if (IS_ERR(shutdown_task
)) {
2089 firsterr
= PTR_ERR(shutdown_task
);
2090 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
2091 shutdown_task
= NULL
;
2094 wake_up_process(shutdown_task
);
2096 i
= rcu_torture_onoff_init();
2101 register_reboot_notifier(&rcutorture_shutdown_nb
);
2102 i
= rcu_torture_stall_init();
2107 retval
= rcu_torture_barrier_init();
2113 rcu_test_debug_objects();
2114 rcutorture_record_test_transition();
2115 mutex_unlock(&fullstop_mutex
);
2119 mutex_unlock(&fullstop_mutex
);
2120 rcu_torture_cleanup();
2124 module_init(rcu_torture_init
);
2125 module_exit(rcu_torture_cleanup
);