2 * Read-Copy Update module-based torture test facility
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * Copyright (C) IBM Corporation, 2005, 2006
20 * Authors: Paul E. McKenney <paulmck@us.ibm.com>
21 * Josh Triplett <josh@freedesktop.org>
23 * See also: Documentation/RCU/torture.txt
25 #include <linux/types.h>
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/module.h>
29 #include <linux/kthread.h>
30 #include <linux/err.h>
31 #include <linux/spinlock.h>
32 #include <linux/smp.h>
33 #include <linux/rcupdate.h>
34 #include <linux/interrupt.h>
35 #include <linux/sched.h>
36 #include <linux/atomic.h>
37 #include <linux/bitops.h>
38 #include <linux/completion.h>
39 #include <linux/moduleparam.h>
40 #include <linux/percpu.h>
41 #include <linux/notifier.h>
42 #include <linux/reboot.h>
43 #include <linux/freezer.h>
44 #include <linux/cpu.h>
45 #include <linux/delay.h>
46 #include <linux/stat.h>
47 #include <linux/srcu.h>
48 #include <linux/slab.h>
49 #include <linux/trace_clock.h>
50 #include <asm/byteorder.h>
52 MODULE_LICENSE("GPL");
53 MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@freedesktop.org>");
55 MODULE_ALIAS("rcutorture");
56 #ifdef MODULE_PARAM_PREFIX
57 #undef MODULE_PARAM_PREFIX
59 #define MODULE_PARAM_PREFIX "rcutorture."
61 static int fqs_duration
;
62 module_param(fqs_duration
, int, 0444);
63 MODULE_PARM_DESC(fqs_duration
, "Duration of fqs bursts (us), 0 to disable");
64 static int fqs_holdoff
;
65 module_param(fqs_holdoff
, int, 0444);
66 MODULE_PARM_DESC(fqs_holdoff
, "Holdoff time within fqs bursts (us)");
67 static int fqs_stutter
= 3;
68 module_param(fqs_stutter
, int, 0444);
69 MODULE_PARM_DESC(fqs_stutter
, "Wait time between fqs bursts (s)");
71 module_param(gp_exp
, bool, 0444);
72 MODULE_PARM_DESC(gp_exp
, "Use expedited GP wait primitives");
73 static bool gp_normal
;
74 module_param(gp_normal
, bool, 0444);
75 MODULE_PARM_DESC(gp_normal
, "Use normal (non-expedited) GP wait primitives");
76 static int irqreader
= 1;
77 module_param(irqreader
, int, 0444);
78 MODULE_PARM_DESC(irqreader
, "Allow RCU readers from irq handlers");
79 static int n_barrier_cbs
;
80 module_param(n_barrier_cbs
, int, 0444);
81 MODULE_PARM_DESC(n_barrier_cbs
, "# of callbacks/kthreads for barrier testing");
82 static int nfakewriters
= 4;
83 module_param(nfakewriters
, int, 0444);
84 MODULE_PARM_DESC(nfakewriters
, "Number of RCU fake writer threads");
85 static int nreaders
= -1;
86 module_param(nreaders
, int, 0444);
87 MODULE_PARM_DESC(nreaders
, "Number of RCU reader threads");
88 static int object_debug
;
89 module_param(object_debug
, int, 0444);
90 MODULE_PARM_DESC(object_debug
, "Enable debug-object double call_rcu() testing");
91 static int onoff_holdoff
;
92 module_param(onoff_holdoff
, int, 0444);
93 MODULE_PARM_DESC(onoff_holdoff
, "Time after boot before CPU hotplugs (s)");
94 static int onoff_interval
;
95 module_param(onoff_interval
, int, 0444);
96 MODULE_PARM_DESC(onoff_interval
, "Time between CPU hotplugs (s), 0=disable");
97 static int shuffle_interval
= 3;
98 module_param(shuffle_interval
, int, 0444);
99 MODULE_PARM_DESC(shuffle_interval
, "Number of seconds between shuffles");
100 static int shutdown_secs
;
101 module_param(shutdown_secs
, int, 0444);
102 MODULE_PARM_DESC(shutdown_secs
, "Shutdown time (s), <= zero to disable.");
103 static int stall_cpu
;
104 module_param(stall_cpu
, int, 0444);
105 MODULE_PARM_DESC(stall_cpu
, "Stall duration (s), zero to disable.");
106 static int stall_cpu_holdoff
= 10;
107 module_param(stall_cpu_holdoff
, int, 0444);
108 MODULE_PARM_DESC(stall_cpu_holdoff
, "Time to wait before starting stall (s).");
109 static int stat_interval
= 60;
110 module_param(stat_interval
, int, 0644);
111 MODULE_PARM_DESC(stat_interval
, "Number of seconds between stats printk()s");
112 static int stutter
= 5;
113 module_param(stutter
, int, 0444);
114 MODULE_PARM_DESC(stutter
, "Number of seconds to run/halt test");
115 static int test_boost
= 1;
116 module_param(test_boost
, int, 0444);
117 MODULE_PARM_DESC(test_boost
, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
118 static int test_boost_duration
= 4;
119 module_param(test_boost_duration
, int, 0444);
120 MODULE_PARM_DESC(test_boost_duration
, "Duration of each boost test, seconds.");
121 static int test_boost_interval
= 7;
122 module_param(test_boost_interval
, int, 0444);
123 MODULE_PARM_DESC(test_boost_interval
, "Interval between boost tests, seconds.");
124 static bool test_no_idle_hz
= true;
125 module_param(test_no_idle_hz
, bool, 0444);
126 MODULE_PARM_DESC(test_no_idle_hz
, "Test support for tickless idle CPUs");
127 static char *torture_type
= "rcu";
128 module_param(torture_type
, charp
, 0444);
129 MODULE_PARM_DESC(torture_type
, "Type of RCU to torture (rcu, rcu_bh, ...)");
131 module_param(verbose
, bool, 0444);
132 MODULE_PARM_DESC(verbose
, "Enable verbose debugging printk()s");
134 #define TORTURE_FLAG "-torture:"
135 #define PRINTK_STRING(s) \
136 do { pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
137 #define VERBOSE_PRINTK_STRING(s) \
138 do { if (verbose) pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
139 #define VERBOSE_PRINTK_ERRSTRING(s) \
140 do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
142 static int nrealreaders
;
143 static struct task_struct
*writer_task
;
144 static struct task_struct
**fakewriter_tasks
;
145 static struct task_struct
**reader_tasks
;
146 static struct task_struct
*stats_task
;
147 static struct task_struct
*shuffler_task
;
148 static struct task_struct
*stutter_task
;
149 static struct task_struct
*fqs_task
;
150 static struct task_struct
*boost_tasks
[NR_CPUS
];
151 static struct task_struct
*shutdown_task
;
152 #ifdef CONFIG_HOTPLUG_CPU
153 static struct task_struct
*onoff_task
;
154 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
155 static struct task_struct
*stall_task
;
156 static struct task_struct
**barrier_cbs_tasks
;
157 static struct task_struct
*barrier_task
;
159 #define RCU_TORTURE_PIPE_LEN 10
162 struct rcu_head rtort_rcu
;
163 int rtort_pipe_count
;
164 struct list_head rtort_free
;
168 static LIST_HEAD(rcu_torture_freelist
);
169 static struct rcu_torture __rcu
*rcu_torture_current
;
170 static unsigned long rcu_torture_current_version
;
171 static struct rcu_torture rcu_tortures
[10 * RCU_TORTURE_PIPE_LEN
];
172 static DEFINE_SPINLOCK(rcu_torture_lock
);
173 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN
+ 1], rcu_torture_count
) =
175 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN
+ 1], rcu_torture_batch
) =
177 static atomic_t rcu_torture_wcount
[RCU_TORTURE_PIPE_LEN
+ 1];
178 static atomic_t n_rcu_torture_alloc
;
179 static atomic_t n_rcu_torture_alloc_fail
;
180 static atomic_t n_rcu_torture_free
;
181 static atomic_t n_rcu_torture_mberror
;
182 static atomic_t n_rcu_torture_error
;
183 static long n_rcu_torture_barrier_error
;
184 static long n_rcu_torture_boost_ktrerror
;
185 static long n_rcu_torture_boost_rterror
;
186 static long n_rcu_torture_boost_failure
;
187 static long n_rcu_torture_boosts
;
188 static long n_rcu_torture_timers
;
189 static long n_offline_attempts
;
190 static long n_offline_successes
;
191 static unsigned long sum_offline
;
192 static int min_offline
= -1;
193 static int max_offline
;
194 static long n_online_attempts
;
195 static long n_online_successes
;
196 static unsigned long sum_online
;
197 static int min_online
= -1;
198 static int max_online
;
199 static long n_barrier_attempts
;
200 static long n_barrier_successes
;
201 static struct list_head rcu_torture_removed
;
202 static cpumask_var_t shuffle_tmp_mask
;
204 static int stutter_pause_test
;
206 #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
207 #define RCUTORTURE_RUNNABLE_INIT 1
209 #define RCUTORTURE_RUNNABLE_INIT 0
211 int rcutorture_runnable
= RCUTORTURE_RUNNABLE_INIT
;
212 module_param(rcutorture_runnable
, int, 0444);
213 MODULE_PARM_DESC(rcutorture_runnable
, "Start rcutorture at boot");
215 #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
216 #define rcu_can_boost() 1
217 #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
218 #define rcu_can_boost() 0
219 #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
221 #ifdef CONFIG_RCU_TRACE
222 static u64 notrace
rcu_trace_clock_local(void)
224 u64 ts
= trace_clock_local();
225 unsigned long __maybe_unused ts_rem
= do_div(ts
, NSEC_PER_USEC
);
228 #else /* #ifdef CONFIG_RCU_TRACE */
229 static u64 notrace
rcu_trace_clock_local(void)
233 #endif /* #else #ifdef CONFIG_RCU_TRACE */
235 static unsigned long shutdown_time
; /* jiffies to system shutdown. */
236 static unsigned long boost_starttime
; /* jiffies of next boost test start. */
237 DEFINE_MUTEX(boost_mutex
); /* protect setting boost_starttime */
238 /* and boost task create/destroy. */
239 static atomic_t barrier_cbs_count
; /* Barrier callbacks registered. */
240 static bool barrier_phase
; /* Test phase. */
241 static atomic_t barrier_cbs_invoked
; /* Barrier callbacks invoked. */
242 static wait_queue_head_t
*barrier_cbs_wq
; /* Coordinate barrier testing. */
243 static DECLARE_WAIT_QUEUE_HEAD(barrier_wq
);
245 /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
247 #define FULLSTOP_DONTSTOP 0 /* Normal operation. */
248 #define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
249 #define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
250 static int fullstop
= FULLSTOP_RMMOD
;
252 * Protect fullstop transitions and spawning of kthreads.
254 static DEFINE_MUTEX(fullstop_mutex
);
256 /* Forward reference. */
257 static void rcu_torture_cleanup(void);
260 * Detect and respond to a system shutdown.
263 rcutorture_shutdown_notify(struct notifier_block
*unused1
,
264 unsigned long unused2
, void *unused3
)
266 mutex_lock(&fullstop_mutex
);
267 if (fullstop
== FULLSTOP_DONTSTOP
)
268 fullstop
= FULLSTOP_SHUTDOWN
;
270 pr_warn(/* but going down anyway, so... */
271 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
272 mutex_unlock(&fullstop_mutex
);
277 * Absorb kthreads into a kernel function that won't return, so that
278 * they won't ever access module text or data again.
280 static void rcutorture_shutdown_absorb(const char *title
)
282 if (ACCESS_ONCE(fullstop
) == FULLSTOP_SHUTDOWN
) {
284 "rcutorture thread %s parking due to system shutdown\n",
286 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT
);
291 * Allocate an element from the rcu_tortures pool.
293 static struct rcu_torture
*
294 rcu_torture_alloc(void)
298 spin_lock_bh(&rcu_torture_lock
);
299 if (list_empty(&rcu_torture_freelist
)) {
300 atomic_inc(&n_rcu_torture_alloc_fail
);
301 spin_unlock_bh(&rcu_torture_lock
);
304 atomic_inc(&n_rcu_torture_alloc
);
305 p
= rcu_torture_freelist
.next
;
307 spin_unlock_bh(&rcu_torture_lock
);
308 return container_of(p
, struct rcu_torture
, rtort_free
);
312 * Free an element to the rcu_tortures pool.
315 rcu_torture_free(struct rcu_torture
*p
)
317 atomic_inc(&n_rcu_torture_free
);
318 spin_lock_bh(&rcu_torture_lock
);
319 list_add_tail(&p
->rtort_free
, &rcu_torture_freelist
);
320 spin_unlock_bh(&rcu_torture_lock
);
323 struct rcu_random_state
{
324 unsigned long rrs_state
;
328 #define RCU_RANDOM_MULT 39916801 /* prime */
329 #define RCU_RANDOM_ADD 479001701 /* prime */
330 #define RCU_RANDOM_REFRESH 10000
332 #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
335 * Crude but fast random-number generator. Uses a linear congruential
336 * generator, with occasional help from cpu_clock().
339 rcu_random(struct rcu_random_state
*rrsp
)
341 if (--rrsp
->rrs_count
< 0) {
342 rrsp
->rrs_state
+= (unsigned long)local_clock();
343 rrsp
->rrs_count
= RCU_RANDOM_REFRESH
;
345 rrsp
->rrs_state
= rrsp
->rrs_state
* RCU_RANDOM_MULT
+ RCU_RANDOM_ADD
;
346 return swahw32(rrsp
->rrs_state
);
350 rcu_stutter_wait(const char *title
)
352 while (stutter_pause_test
|| !rcutorture_runnable
) {
353 if (rcutorture_runnable
)
354 schedule_timeout_interruptible(1);
356 schedule_timeout_interruptible(round_jiffies_relative(HZ
));
357 rcutorture_shutdown_absorb(title
);
362 * Operations vector for selecting different types of tests.
365 struct rcu_torture_ops
{
367 int (*readlock
)(void);
368 void (*read_delay
)(struct rcu_random_state
*rrsp
);
369 void (*readunlock
)(int idx
);
370 int (*completed
)(void);
371 void (*deferred_free
)(struct rcu_torture
*p
);
373 void (*exp_sync
)(void);
374 void (*call
)(struct rcu_head
*head
, void (*func
)(struct rcu_head
*rcu
));
375 void (*cb_barrier
)(void);
377 void (*stats
)(char *page
);
383 static struct rcu_torture_ops
*cur_ops
;
386 * Definitions for rcu torture testing.
389 static int rcu_torture_read_lock(void) __acquires(RCU
)
395 static void rcu_read_delay(struct rcu_random_state
*rrsp
)
397 const unsigned long shortdelay_us
= 200;
398 const unsigned long longdelay_ms
= 50;
400 /* We want a short delay sometimes to make a reader delay the grace
401 * period, and we want a long delay occasionally to trigger
402 * force_quiescent_state. */
404 if (!(rcu_random(rrsp
) % (nrealreaders
* 2000 * longdelay_ms
)))
405 mdelay(longdelay_ms
);
406 if (!(rcu_random(rrsp
) % (nrealreaders
* 2 * shortdelay_us
)))
407 udelay(shortdelay_us
);
408 #ifdef CONFIG_PREEMPT
409 if (!preempt_count() && !(rcu_random(rrsp
) % (nrealreaders
* 20000)))
410 preempt_schedule(); /* No QS if preempt_disable() in effect */
414 static void rcu_torture_read_unlock(int idx
) __releases(RCU
)
419 static int rcu_torture_completed(void)
421 return rcu_batches_completed();
425 rcu_torture_cb(struct rcu_head
*p
)
428 struct rcu_torture
*rp
= container_of(p
, struct rcu_torture
, rtort_rcu
);
430 if (fullstop
!= FULLSTOP_DONTSTOP
) {
431 /* Test is ending, just drop callbacks on the floor. */
432 /* The next initialization will pick up the pieces. */
435 i
= rp
->rtort_pipe_count
;
436 if (i
> RCU_TORTURE_PIPE_LEN
)
437 i
= RCU_TORTURE_PIPE_LEN
;
438 atomic_inc(&rcu_torture_wcount
[i
]);
439 if (++rp
->rtort_pipe_count
>= RCU_TORTURE_PIPE_LEN
) {
440 rp
->rtort_mbtest
= 0;
441 rcu_torture_free(rp
);
443 cur_ops
->deferred_free(rp
);
447 static int rcu_no_completed(void)
452 static void rcu_torture_deferred_free(struct rcu_torture
*p
)
454 call_rcu(&p
->rtort_rcu
, rcu_torture_cb
);
457 static void rcu_sync_torture_init(void)
459 INIT_LIST_HEAD(&rcu_torture_removed
);
462 static struct rcu_torture_ops rcu_ops
= {
463 .init
= rcu_sync_torture_init
,
464 .readlock
= rcu_torture_read_lock
,
465 .read_delay
= rcu_read_delay
,
466 .readunlock
= rcu_torture_read_unlock
,
467 .completed
= rcu_torture_completed
,
468 .deferred_free
= rcu_torture_deferred_free
,
469 .sync
= synchronize_rcu
,
470 .exp_sync
= synchronize_rcu_expedited
,
472 .cb_barrier
= rcu_barrier
,
473 .fqs
= rcu_force_quiescent_state
,
476 .can_boost
= rcu_can_boost(),
481 * Definitions for rcu_bh torture testing.
484 static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH
)
490 static void rcu_bh_torture_read_unlock(int idx
) __releases(RCU_BH
)
492 rcu_read_unlock_bh();
495 static int rcu_bh_torture_completed(void)
497 return rcu_batches_completed_bh();
500 static void rcu_bh_torture_deferred_free(struct rcu_torture
*p
)
502 call_rcu_bh(&p
->rtort_rcu
, rcu_torture_cb
);
505 static struct rcu_torture_ops rcu_bh_ops
= {
506 .init
= rcu_sync_torture_init
,
507 .readlock
= rcu_bh_torture_read_lock
,
508 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
509 .readunlock
= rcu_bh_torture_read_unlock
,
510 .completed
= rcu_bh_torture_completed
,
511 .deferred_free
= rcu_bh_torture_deferred_free
,
512 .sync
= synchronize_rcu_bh
,
513 .exp_sync
= synchronize_rcu_bh_expedited
,
515 .cb_barrier
= rcu_barrier_bh
,
516 .fqs
= rcu_bh_force_quiescent_state
,
523 * Definitions for srcu torture testing.
526 DEFINE_STATIC_SRCU(srcu_ctl
);
528 static int srcu_torture_read_lock(void) __acquires(&srcu_ctl
)
530 return srcu_read_lock(&srcu_ctl
);
533 static void srcu_read_delay(struct rcu_random_state
*rrsp
)
536 const long uspertick
= 1000000 / HZ
;
537 const long longdelay
= 10;
539 /* We want there to be long-running readers, but not all the time. */
541 delay
= rcu_random(rrsp
) % (nrealreaders
* 2 * longdelay
* uspertick
);
543 schedule_timeout_interruptible(longdelay
);
545 rcu_read_delay(rrsp
);
548 static void srcu_torture_read_unlock(int idx
) __releases(&srcu_ctl
)
550 srcu_read_unlock(&srcu_ctl
, idx
);
553 static int srcu_torture_completed(void)
555 return srcu_batches_completed(&srcu_ctl
);
558 static void srcu_torture_deferred_free(struct rcu_torture
*rp
)
560 call_srcu(&srcu_ctl
, &rp
->rtort_rcu
, rcu_torture_cb
);
563 static void srcu_torture_synchronize(void)
565 synchronize_srcu(&srcu_ctl
);
568 static void srcu_torture_call(struct rcu_head
*head
,
569 void (*func
)(struct rcu_head
*head
))
571 call_srcu(&srcu_ctl
, head
, func
);
574 static void srcu_torture_barrier(void)
576 srcu_barrier(&srcu_ctl
);
579 static void srcu_torture_stats(char *page
)
582 int idx
= srcu_ctl
.completed
& 0x1;
584 page
+= sprintf(page
, "%s%s per-CPU(idx=%d):",
585 torture_type
, TORTURE_FLAG
, idx
);
586 for_each_possible_cpu(cpu
) {
587 page
+= sprintf(page
, " %d(%lu,%lu)", cpu
,
588 per_cpu_ptr(srcu_ctl
.per_cpu_ref
, cpu
)->c
[!idx
],
589 per_cpu_ptr(srcu_ctl
.per_cpu_ref
, cpu
)->c
[idx
]);
594 static void srcu_torture_synchronize_expedited(void)
596 synchronize_srcu_expedited(&srcu_ctl
);
599 static struct rcu_torture_ops srcu_ops
= {
600 .init
= rcu_sync_torture_init
,
601 .readlock
= srcu_torture_read_lock
,
602 .read_delay
= srcu_read_delay
,
603 .readunlock
= srcu_torture_read_unlock
,
604 .completed
= srcu_torture_completed
,
605 .deferred_free
= srcu_torture_deferred_free
,
606 .sync
= srcu_torture_synchronize
,
607 .exp_sync
= srcu_torture_synchronize_expedited
,
608 .call
= srcu_torture_call
,
609 .cb_barrier
= srcu_torture_barrier
,
610 .stats
= srcu_torture_stats
,
615 * Definitions for sched torture testing.
618 static int sched_torture_read_lock(void)
624 static void sched_torture_read_unlock(int idx
)
629 static void rcu_sched_torture_deferred_free(struct rcu_torture
*p
)
631 call_rcu_sched(&p
->rtort_rcu
, rcu_torture_cb
);
634 static struct rcu_torture_ops sched_ops
= {
635 .init
= rcu_sync_torture_init
,
636 .readlock
= sched_torture_read_lock
,
637 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
638 .readunlock
= sched_torture_read_unlock
,
639 .completed
= rcu_no_completed
,
640 .deferred_free
= rcu_sched_torture_deferred_free
,
641 .sync
= synchronize_sched
,
642 .exp_sync
= synchronize_sched_expedited
,
643 .call
= call_rcu_sched
,
644 .cb_barrier
= rcu_barrier_sched
,
645 .fqs
= rcu_sched_force_quiescent_state
,
652 * RCU torture priority-boost testing. Runs one real-time thread per
653 * CPU for moderate bursts, repeatedly registering RCU callbacks and
654 * spinning waiting for them to be invoked. If a given callback takes
655 * too long to be invoked, we assume that priority inversion has occurred.
658 struct rcu_boost_inflight
{
663 static void rcu_torture_boost_cb(struct rcu_head
*head
)
665 struct rcu_boost_inflight
*rbip
=
666 container_of(head
, struct rcu_boost_inflight
, rcu
);
668 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
672 static int rcu_torture_boost(void *arg
)
674 unsigned long call_rcu_time
;
675 unsigned long endtime
;
676 unsigned long oldstarttime
;
677 struct rcu_boost_inflight rbi
= { .inflight
= 0 };
678 struct sched_param sp
;
680 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
682 /* Set real-time priority. */
683 sp
.sched_priority
= 1;
684 if (sched_setscheduler(current
, SCHED_FIFO
, &sp
) < 0) {
685 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
686 n_rcu_torture_boost_rterror
++;
689 init_rcu_head_on_stack(&rbi
.rcu
);
690 /* Each pass through the following loop does one boost-test cycle. */
692 /* Wait for the next test interval. */
693 oldstarttime
= boost_starttime
;
694 while (ULONG_CMP_LT(jiffies
, oldstarttime
)) {
695 schedule_timeout_interruptible(oldstarttime
- jiffies
);
696 rcu_stutter_wait("rcu_torture_boost");
697 if (kthread_should_stop() ||
698 fullstop
!= FULLSTOP_DONTSTOP
)
702 /* Do one boost-test interval. */
703 endtime
= oldstarttime
+ test_boost_duration
* HZ
;
704 call_rcu_time
= jiffies
;
705 while (ULONG_CMP_LT(jiffies
, endtime
)) {
706 /* If we don't have a callback in flight, post one. */
708 smp_mb(); /* RCU core before ->inflight = 1. */
710 call_rcu(&rbi
.rcu
, rcu_torture_boost_cb
);
711 if (jiffies
- call_rcu_time
>
712 test_boost_duration
* HZ
- HZ
/ 2) {
713 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
714 n_rcu_torture_boost_failure
++;
716 call_rcu_time
= jiffies
;
719 rcu_stutter_wait("rcu_torture_boost");
720 if (kthread_should_stop() ||
721 fullstop
!= FULLSTOP_DONTSTOP
)
726 * Set the start time of the next test interval.
727 * Yes, this is vulnerable to long delays, but such
728 * delays simply cause a false negative for the next
729 * interval. Besides, we are running at RT priority,
730 * so delays should be relatively rare.
732 while (oldstarttime
== boost_starttime
&&
733 !kthread_should_stop()) {
734 if (mutex_trylock(&boost_mutex
)) {
735 boost_starttime
= jiffies
+
736 test_boost_interval
* HZ
;
737 n_rcu_torture_boosts
++;
738 mutex_unlock(&boost_mutex
);
741 schedule_timeout_uninterruptible(1);
744 /* Go do the stutter. */
745 checkwait
: rcu_stutter_wait("rcu_torture_boost");
746 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
748 /* Clean up and exit. */
749 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
750 rcutorture_shutdown_absorb("rcu_torture_boost");
751 while (!kthread_should_stop() || rbi
.inflight
)
752 schedule_timeout_uninterruptible(1);
753 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
754 destroy_rcu_head_on_stack(&rbi
.rcu
);
759 * RCU torture force-quiescent-state kthread. Repeatedly induces
760 * bursts of calls to force_quiescent_state(), increasing the probability
761 * of occurrence of some important types of race conditions.
764 rcu_torture_fqs(void *arg
)
766 unsigned long fqs_resume_time
;
767 int fqs_burst_remaining
;
769 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
771 fqs_resume_time
= jiffies
+ fqs_stutter
* HZ
;
772 while (ULONG_CMP_LT(jiffies
, fqs_resume_time
) &&
773 !kthread_should_stop()) {
774 schedule_timeout_interruptible(1);
776 fqs_burst_remaining
= fqs_duration
;
777 while (fqs_burst_remaining
> 0 &&
778 !kthread_should_stop()) {
781 fqs_burst_remaining
-= fqs_holdoff
;
783 rcu_stutter_wait("rcu_torture_fqs");
784 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
785 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
786 rcutorture_shutdown_absorb("rcu_torture_fqs");
787 while (!kthread_should_stop())
788 schedule_timeout_uninterruptible(1);
793 * RCU torture writer kthread. Repeatedly substitutes a new structure
794 * for that pointed to by rcu_torture_current, freeing the old structure
795 * after a series of grace periods (the "pipeline").
798 rcu_torture_writer(void *arg
)
802 struct rcu_torture
*rp
;
803 struct rcu_torture
*rp1
;
804 struct rcu_torture
*old_rp
;
805 static DEFINE_RCU_RANDOM(rand
);
807 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
808 set_user_nice(current
, 19);
811 schedule_timeout_uninterruptible(1);
812 rp
= rcu_torture_alloc();
815 rp
->rtort_pipe_count
= 0;
816 udelay(rcu_random(&rand
) & 0x3ff);
817 old_rp
= rcu_dereference_check(rcu_torture_current
,
818 current
== writer_task
);
819 rp
->rtort_mbtest
= 1;
820 rcu_assign_pointer(rcu_torture_current
, rp
);
821 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
823 i
= old_rp
->rtort_pipe_count
;
824 if (i
> RCU_TORTURE_PIPE_LEN
)
825 i
= RCU_TORTURE_PIPE_LEN
;
826 atomic_inc(&rcu_torture_wcount
[i
]);
827 old_rp
->rtort_pipe_count
++;
828 if (gp_normal
== gp_exp
)
829 exp
= !!(rcu_random(&rand
) & 0x80);
833 cur_ops
->deferred_free(old_rp
);
836 list_add(&old_rp
->rtort_free
,
837 &rcu_torture_removed
);
838 list_for_each_entry_safe(rp
, rp1
,
839 &rcu_torture_removed
,
841 i
= rp
->rtort_pipe_count
;
842 if (i
> RCU_TORTURE_PIPE_LEN
)
843 i
= RCU_TORTURE_PIPE_LEN
;
844 atomic_inc(&rcu_torture_wcount
[i
]);
845 if (++rp
->rtort_pipe_count
>=
846 RCU_TORTURE_PIPE_LEN
) {
847 rp
->rtort_mbtest
= 0;
848 list_del(&rp
->rtort_free
);
849 rcu_torture_free(rp
);
854 rcutorture_record_progress(++rcu_torture_current_version
);
855 rcu_stutter_wait("rcu_torture_writer");
856 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
857 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
858 rcutorture_shutdown_absorb("rcu_torture_writer");
859 while (!kthread_should_stop())
860 schedule_timeout_uninterruptible(1);
865 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
866 * delay between calls.
869 rcu_torture_fakewriter(void *arg
)
871 DEFINE_RCU_RANDOM(rand
);
873 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
874 set_user_nice(current
, 19);
877 schedule_timeout_uninterruptible(1 + rcu_random(&rand
)%10);
878 udelay(rcu_random(&rand
) & 0x3ff);
879 if (cur_ops
->cb_barrier
!= NULL
&&
880 rcu_random(&rand
) % (nfakewriters
* 8) == 0) {
881 cur_ops
->cb_barrier();
882 } else if (gp_normal
== gp_exp
) {
883 if (rcu_random(&rand
) & 0x80)
887 } else if (gp_normal
) {
892 rcu_stutter_wait("rcu_torture_fakewriter");
893 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
895 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
896 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
897 while (!kthread_should_stop())
898 schedule_timeout_uninterruptible(1);
902 void rcutorture_trace_dump(void)
904 static atomic_t beenhere
= ATOMIC_INIT(0);
906 if (atomic_read(&beenhere
))
908 if (atomic_xchg(&beenhere
, 1) != 0)
910 ftrace_dump(DUMP_ALL
);
914 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
915 * incrementing the corresponding element of the pipeline array. The
916 * counter in the element should never be greater than 1, otherwise, the
917 * RCU implementation is broken.
919 static void rcu_torture_timer(unsigned long unused
)
924 static DEFINE_RCU_RANDOM(rand
);
925 static DEFINE_SPINLOCK(rand_lock
);
926 struct rcu_torture
*p
;
928 unsigned long long ts
;
930 idx
= cur_ops
->readlock();
931 completed
= cur_ops
->completed();
932 ts
= rcu_trace_clock_local();
933 p
= rcu_dereference_check(rcu_torture_current
,
934 rcu_read_lock_bh_held() ||
935 rcu_read_lock_sched_held() ||
936 srcu_read_lock_held(&srcu_ctl
));
938 /* Leave because rcu_torture_writer is not yet underway */
939 cur_ops
->readunlock(idx
);
942 if (p
->rtort_mbtest
== 0)
943 atomic_inc(&n_rcu_torture_mberror
);
944 spin_lock(&rand_lock
);
945 cur_ops
->read_delay(&rand
);
946 n_rcu_torture_timers
++;
947 spin_unlock(&rand_lock
);
949 pipe_count
= p
->rtort_pipe_count
;
950 if (pipe_count
> RCU_TORTURE_PIPE_LEN
) {
951 /* Should not happen, but... */
952 pipe_count
= RCU_TORTURE_PIPE_LEN
;
954 completed_end
= cur_ops
->completed();
955 if (pipe_count
> 1) {
956 do_trace_rcu_torture_read(cur_ops
->name
, &p
->rtort_rcu
, ts
,
957 completed
, completed_end
);
958 rcutorture_trace_dump();
960 __this_cpu_inc(rcu_torture_count
[pipe_count
]);
961 completed
= completed_end
- completed
;
962 if (completed
> RCU_TORTURE_PIPE_LEN
) {
963 /* Should not happen, but... */
964 completed
= RCU_TORTURE_PIPE_LEN
;
966 __this_cpu_inc(rcu_torture_batch
[completed
]);
968 cur_ops
->readunlock(idx
);
972 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
973 * incrementing the corresponding element of the pipeline array. The
974 * counter in the element should never be greater than 1, otherwise, the
975 * RCU implementation is broken.
978 rcu_torture_reader(void *arg
)
983 DEFINE_RCU_RANDOM(rand
);
984 struct rcu_torture
*p
;
987 unsigned long long ts
;
989 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
990 set_user_nice(current
, 19);
991 if (irqreader
&& cur_ops
->irq_capable
)
992 setup_timer_on_stack(&t
, rcu_torture_timer
, 0);
995 if (irqreader
&& cur_ops
->irq_capable
) {
996 if (!timer_pending(&t
))
997 mod_timer(&t
, jiffies
+ 1);
999 idx
= cur_ops
->readlock();
1000 completed
= cur_ops
->completed();
1001 ts
= rcu_trace_clock_local();
1002 p
= rcu_dereference_check(rcu_torture_current
,
1003 rcu_read_lock_bh_held() ||
1004 rcu_read_lock_sched_held() ||
1005 srcu_read_lock_held(&srcu_ctl
));
1007 /* Wait for rcu_torture_writer to get underway */
1008 cur_ops
->readunlock(idx
);
1009 schedule_timeout_interruptible(HZ
);
1012 if (p
->rtort_mbtest
== 0)
1013 atomic_inc(&n_rcu_torture_mberror
);
1014 cur_ops
->read_delay(&rand
);
1016 pipe_count
= p
->rtort_pipe_count
;
1017 if (pipe_count
> RCU_TORTURE_PIPE_LEN
) {
1018 /* Should not happen, but... */
1019 pipe_count
= RCU_TORTURE_PIPE_LEN
;
1021 completed_end
= cur_ops
->completed();
1022 if (pipe_count
> 1) {
1023 do_trace_rcu_torture_read(cur_ops
->name
, &p
->rtort_rcu
,
1024 ts
, completed
, completed_end
);
1025 rcutorture_trace_dump();
1027 __this_cpu_inc(rcu_torture_count
[pipe_count
]);
1028 completed
= completed_end
- completed
;
1029 if (completed
> RCU_TORTURE_PIPE_LEN
) {
1030 /* Should not happen, but... */
1031 completed
= RCU_TORTURE_PIPE_LEN
;
1033 __this_cpu_inc(rcu_torture_batch
[completed
]);
1035 cur_ops
->readunlock(idx
);
1037 rcu_stutter_wait("rcu_torture_reader");
1038 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
1039 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
1040 rcutorture_shutdown_absorb("rcu_torture_reader");
1041 if (irqreader
&& cur_ops
->irq_capable
)
1043 while (!kthread_should_stop())
1044 schedule_timeout_uninterruptible(1);
1049 * Create an RCU-torture statistics message in the specified buffer.
1052 rcu_torture_printk(char *page
)
1056 long pipesummary
[RCU_TORTURE_PIPE_LEN
+ 1] = { 0 };
1057 long batchsummary
[RCU_TORTURE_PIPE_LEN
+ 1] = { 0 };
1059 for_each_possible_cpu(cpu
) {
1060 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
1061 pipesummary
[i
] += per_cpu(rcu_torture_count
, cpu
)[i
];
1062 batchsummary
[i
] += per_cpu(rcu_torture_batch
, cpu
)[i
];
1065 for (i
= RCU_TORTURE_PIPE_LEN
- 1; i
>= 0; i
--) {
1066 if (pipesummary
[i
] != 0)
1069 page
+= sprintf(page
, "%s%s ", torture_type
, TORTURE_FLAG
);
1070 page
+= sprintf(page
,
1071 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
1072 rcu_torture_current
,
1073 rcu_torture_current_version
,
1074 list_empty(&rcu_torture_freelist
),
1075 atomic_read(&n_rcu_torture_alloc
),
1076 atomic_read(&n_rcu_torture_alloc_fail
),
1077 atomic_read(&n_rcu_torture_free
));
1078 page
+= sprintf(page
, "rtmbe: %d rtbke: %ld rtbre: %ld ",
1079 atomic_read(&n_rcu_torture_mberror
),
1080 n_rcu_torture_boost_ktrerror
,
1081 n_rcu_torture_boost_rterror
);
1082 page
+= sprintf(page
, "rtbf: %ld rtb: %ld nt: %ld ",
1083 n_rcu_torture_boost_failure
,
1084 n_rcu_torture_boosts
,
1085 n_rcu_torture_timers
);
1086 page
+= sprintf(page
,
1087 "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ",
1088 n_online_successes
, n_online_attempts
,
1089 n_offline_successes
, n_offline_attempts
,
1090 min_online
, max_online
,
1091 min_offline
, max_offline
,
1092 sum_online
, sum_offline
, HZ
);
1093 page
+= sprintf(page
, "barrier: %ld/%ld:%ld",
1094 n_barrier_successes
,
1096 n_rcu_torture_barrier_error
);
1097 page
+= sprintf(page
, "\n%s%s ", torture_type
, TORTURE_FLAG
);
1098 if (atomic_read(&n_rcu_torture_mberror
) != 0 ||
1099 n_rcu_torture_barrier_error
!= 0 ||
1100 n_rcu_torture_boost_ktrerror
!= 0 ||
1101 n_rcu_torture_boost_rterror
!= 0 ||
1102 n_rcu_torture_boost_failure
!= 0 ||
1104 page
+= sprintf(page
, "!!! ");
1105 atomic_inc(&n_rcu_torture_error
);
1108 page
+= sprintf(page
, "Reader Pipe: ");
1109 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
1110 page
+= sprintf(page
, " %ld", pipesummary
[i
]);
1111 page
+= sprintf(page
, "\n%s%s ", torture_type
, TORTURE_FLAG
);
1112 page
+= sprintf(page
, "Reader Batch: ");
1113 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
1114 page
+= sprintf(page
, " %ld", batchsummary
[i
]);
1115 page
+= sprintf(page
, "\n%s%s ", torture_type
, TORTURE_FLAG
);
1116 page
+= sprintf(page
, "Free-Block Circulation: ");
1117 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
1118 page
+= sprintf(page
, " %d",
1119 atomic_read(&rcu_torture_wcount
[i
]));
1121 page
+= sprintf(page
, "\n");
1123 cur_ops
->stats(page
);
1127 * Print torture statistics. Caller must ensure that there is only
1128 * one call to this function at a given time!!! This is normally
1129 * accomplished by relying on the module system to only have one copy
1130 * of the module loaded, and then by giving the rcu_torture_stats
1131 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1132 * thread is not running).
1135 rcu_torture_stats_print(void)
1137 int size
= nr_cpu_ids
* 200 + 8192;
1140 buf
= kmalloc(size
, GFP_KERNEL
);
1142 pr_err("rcu-torture: Out of memory, need: %d", size
);
1145 rcu_torture_printk(buf
);
1146 pr_alert("%s", buf
);
1151 * Periodically prints torture statistics, if periodic statistics printing
1152 * was specified via the stat_interval module parameter.
1154 * No need to worry about fullstop here, since this one doesn't reference
1155 * volatile state or register callbacks.
1158 rcu_torture_stats(void *arg
)
1160 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1162 schedule_timeout_interruptible(stat_interval
* HZ
);
1163 rcu_torture_stats_print();
1164 rcutorture_shutdown_absorb("rcu_torture_stats");
1165 } while (!kthread_should_stop());
1166 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1170 static int rcu_idle_cpu
; /* Force all torture tasks off this CPU */
1172 /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1173 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1175 static void rcu_torture_shuffle_tasks(void)
1179 cpumask_setall(shuffle_tmp_mask
);
1182 /* No point in shuffling if there is only one online CPU (ex: UP) */
1183 if (num_online_cpus() == 1) {
1188 if (rcu_idle_cpu
!= -1)
1189 cpumask_clear_cpu(rcu_idle_cpu
, shuffle_tmp_mask
);
1191 set_cpus_allowed_ptr(current
, shuffle_tmp_mask
);
1194 for (i
= 0; i
< nrealreaders
; i
++)
1195 if (reader_tasks
[i
])
1196 set_cpus_allowed_ptr(reader_tasks
[i
],
1199 if (fakewriter_tasks
) {
1200 for (i
= 0; i
< nfakewriters
; i
++)
1201 if (fakewriter_tasks
[i
])
1202 set_cpus_allowed_ptr(fakewriter_tasks
[i
],
1206 set_cpus_allowed_ptr(writer_task
, shuffle_tmp_mask
);
1208 set_cpus_allowed_ptr(stats_task
, shuffle_tmp_mask
);
1210 set_cpus_allowed_ptr(stutter_task
, shuffle_tmp_mask
);
1212 set_cpus_allowed_ptr(fqs_task
, shuffle_tmp_mask
);
1214 set_cpus_allowed_ptr(shutdown_task
, shuffle_tmp_mask
);
1215 #ifdef CONFIG_HOTPLUG_CPU
1217 set_cpus_allowed_ptr(onoff_task
, shuffle_tmp_mask
);
1218 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
1220 set_cpus_allowed_ptr(stall_task
, shuffle_tmp_mask
);
1221 if (barrier_cbs_tasks
)
1222 for (i
= 0; i
< n_barrier_cbs
; i
++)
1223 if (barrier_cbs_tasks
[i
])
1224 set_cpus_allowed_ptr(barrier_cbs_tasks
[i
],
1227 set_cpus_allowed_ptr(barrier_task
, shuffle_tmp_mask
);
1229 if (rcu_idle_cpu
== -1)
1230 rcu_idle_cpu
= num_online_cpus() - 1;
1237 /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1238 * system to become idle at a time and cut off its timer ticks. This is meant
1239 * to test the support for such tickless idle CPU in RCU.
1242 rcu_torture_shuffle(void *arg
)
1244 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1246 schedule_timeout_interruptible(shuffle_interval
* HZ
);
1247 rcu_torture_shuffle_tasks();
1248 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1249 } while (!kthread_should_stop());
1250 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1254 /* Cause the rcutorture test to "stutter", starting and stopping all
1255 * threads periodically.
1258 rcu_torture_stutter(void *arg
)
1260 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1262 schedule_timeout_interruptible(stutter
* HZ
);
1263 stutter_pause_test
= 1;
1264 if (!kthread_should_stop())
1265 schedule_timeout_interruptible(stutter
* HZ
);
1266 stutter_pause_test
= 0;
1267 rcutorture_shutdown_absorb("rcu_torture_stutter");
1268 } while (!kthread_should_stop());
1269 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1274 rcu_torture_print_module_parms(struct rcu_torture_ops
*cur_ops
, const char *tag
)
1276 pr_alert("%s" TORTURE_FLAG
1277 "--- %s: nreaders=%d nfakewriters=%d "
1278 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1279 "shuffle_interval=%d stutter=%d irqreader=%d "
1280 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1281 "test_boost=%d/%d test_boost_interval=%d "
1282 "test_boost_duration=%d shutdown_secs=%d "
1283 "stall_cpu=%d stall_cpu_holdoff=%d "
1285 "onoff_interval=%d onoff_holdoff=%d\n",
1286 torture_type
, tag
, nrealreaders
, nfakewriters
,
1287 stat_interval
, verbose
, test_no_idle_hz
, shuffle_interval
,
1288 stutter
, irqreader
, fqs_duration
, fqs_holdoff
, fqs_stutter
,
1289 test_boost
, cur_ops
->can_boost
,
1290 test_boost_interval
, test_boost_duration
, shutdown_secs
,
1291 stall_cpu
, stall_cpu_holdoff
,
1293 onoff_interval
, onoff_holdoff
);
1296 static struct notifier_block rcutorture_shutdown_nb
= {
1297 .notifier_call
= rcutorture_shutdown_notify
,
1300 static void rcutorture_booster_cleanup(int cpu
)
1302 struct task_struct
*t
;
1304 if (boost_tasks
[cpu
] == NULL
)
1306 mutex_lock(&boost_mutex
);
1307 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1308 t
= boost_tasks
[cpu
];
1309 boost_tasks
[cpu
] = NULL
;
1310 mutex_unlock(&boost_mutex
);
1312 /* This must be outside of the mutex, otherwise deadlock! */
1314 boost_tasks
[cpu
] = NULL
;
1317 static int rcutorture_booster_init(int cpu
)
1321 if (boost_tasks
[cpu
] != NULL
)
1322 return 0; /* Already created, nothing more to do. */
1324 /* Don't allow time recalculation while creating a new task. */
1325 mutex_lock(&boost_mutex
);
1326 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
1327 boost_tasks
[cpu
] = kthread_create_on_node(rcu_torture_boost
, NULL
,
1329 "rcu_torture_boost");
1330 if (IS_ERR(boost_tasks
[cpu
])) {
1331 retval
= PTR_ERR(boost_tasks
[cpu
]);
1332 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1333 n_rcu_torture_boost_ktrerror
++;
1334 boost_tasks
[cpu
] = NULL
;
1335 mutex_unlock(&boost_mutex
);
1338 kthread_bind(boost_tasks
[cpu
], cpu
);
1339 wake_up_process(boost_tasks
[cpu
]);
1340 mutex_unlock(&boost_mutex
);
1345 * Cause the rcutorture test to shutdown the system after the test has
1346 * run for the time specified by the shutdown_secs module parameter.
1349 rcu_torture_shutdown(void *arg
)
1352 unsigned long jiffies_snap
;
1354 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1355 jiffies_snap
= ACCESS_ONCE(jiffies
);
1356 while (ULONG_CMP_LT(jiffies_snap
, shutdown_time
) &&
1357 !kthread_should_stop()) {
1358 delta
= shutdown_time
- jiffies_snap
;
1360 pr_alert("%s" TORTURE_FLAG
1361 "rcu_torture_shutdown task: %lu jiffies remaining\n",
1362 torture_type
, delta
);
1363 schedule_timeout_interruptible(delta
);
1364 jiffies_snap
= ACCESS_ONCE(jiffies
);
1366 if (kthread_should_stop()) {
1367 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1371 /* OK, shut down the system. */
1373 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1374 shutdown_task
= NULL
; /* Avoid self-kill deadlock. */
1375 rcu_torture_cleanup(); /* Get the success/failure message. */
1376 kernel_power_off(); /* Shut down the system. */
1380 #ifdef CONFIG_HOTPLUG_CPU
1383 * Execute random CPU-hotplug operations at the interval specified
1384 * by the onoff_interval.
1387 rcu_torture_onoff(void *arg
)
1390 unsigned long delta
;
1392 DEFINE_RCU_RANDOM(rand
);
1394 unsigned long starttime
;
1396 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1397 for_each_online_cpu(cpu
)
1399 WARN_ON(maxcpu
< 0);
1400 if (onoff_holdoff
> 0) {
1401 VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff");
1402 schedule_timeout_interruptible(onoff_holdoff
* HZ
);
1403 VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff");
1405 while (!kthread_should_stop()) {
1406 cpu
= (rcu_random(&rand
) >> 4) % (maxcpu
+ 1);
1407 if (cpu_online(cpu
) && cpu_is_hotpluggable(cpu
)) {
1409 pr_alert("%s" TORTURE_FLAG
1410 "rcu_torture_onoff task: offlining %d\n",
1412 starttime
= jiffies
;
1413 n_offline_attempts
++;
1414 ret
= cpu_down(cpu
);
1417 pr_alert("%s" TORTURE_FLAG
1418 "rcu_torture_onoff task: offline %d failed: errno %d\n",
1419 torture_type
, cpu
, ret
);
1422 pr_alert("%s" TORTURE_FLAG
1423 "rcu_torture_onoff task: offlined %d\n",
1425 n_offline_successes
++;
1426 delta
= jiffies
- starttime
;
1427 sum_offline
+= delta
;
1428 if (min_offline
< 0) {
1429 min_offline
= delta
;
1430 max_offline
= delta
;
1432 if (min_offline
> delta
)
1433 min_offline
= delta
;
1434 if (max_offline
< delta
)
1435 max_offline
= delta
;
1437 } else if (cpu_is_hotpluggable(cpu
)) {
1439 pr_alert("%s" TORTURE_FLAG
1440 "rcu_torture_onoff task: onlining %d\n",
1442 starttime
= jiffies
;
1443 n_online_attempts
++;
1447 pr_alert("%s" TORTURE_FLAG
1448 "rcu_torture_onoff task: online %d failed: errno %d\n",
1449 torture_type
, cpu
, ret
);
1452 pr_alert("%s" TORTURE_FLAG
1453 "rcu_torture_onoff task: onlined %d\n",
1455 n_online_successes
++;
1456 delta
= jiffies
- starttime
;
1457 sum_online
+= delta
;
1458 if (min_online
< 0) {
1462 if (min_online
> delta
)
1464 if (max_online
< delta
)
1468 schedule_timeout_interruptible(onoff_interval
* HZ
);
1470 VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1475 rcu_torture_onoff_init(void)
1479 if (onoff_interval
<= 0)
1481 onoff_task
= kthread_run(rcu_torture_onoff
, NULL
, "rcu_torture_onoff");
1482 if (IS_ERR(onoff_task
)) {
1483 ret
= PTR_ERR(onoff_task
);
1490 static void rcu_torture_onoff_cleanup(void)
1492 if (onoff_task
== NULL
)
1494 VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1495 kthread_stop(onoff_task
);
1499 #else /* #ifdef CONFIG_HOTPLUG_CPU */
1502 rcu_torture_onoff_init(void)
1507 static void rcu_torture_onoff_cleanup(void)
1511 #endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1514 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1515 * induces a CPU stall for the time specified by stall_cpu.
1517 static int rcu_torture_stall(void *args
)
1519 unsigned long stop_at
;
1521 VERBOSE_PRINTK_STRING("rcu_torture_stall task started");
1522 if (stall_cpu_holdoff
> 0) {
1523 VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff");
1524 schedule_timeout_interruptible(stall_cpu_holdoff
* HZ
);
1525 VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff");
1527 if (!kthread_should_stop()) {
1528 stop_at
= get_seconds() + stall_cpu
;
1529 /* RCU CPU stall is expected behavior in following code. */
1530 pr_alert("rcu_torture_stall start.\n");
1533 while (ULONG_CMP_LT(get_seconds(), stop_at
))
1534 continue; /* Induce RCU CPU stall warning. */
1537 pr_alert("rcu_torture_stall end.\n");
1539 rcutorture_shutdown_absorb("rcu_torture_stall");
1540 while (!kthread_should_stop())
1541 schedule_timeout_interruptible(10 * HZ
);
1545 /* Spawn CPU-stall kthread, if stall_cpu specified. */
1546 static int __init
rcu_torture_stall_init(void)
1552 stall_task
= kthread_run(rcu_torture_stall
, NULL
, "rcu_torture_stall");
1553 if (IS_ERR(stall_task
)) {
1554 ret
= PTR_ERR(stall_task
);
1561 /* Clean up after the CPU-stall kthread, if one was spawned. */
1562 static void rcu_torture_stall_cleanup(void)
1564 if (stall_task
== NULL
)
1566 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task.");
1567 kthread_stop(stall_task
);
1571 /* Callback function for RCU barrier testing. */
1572 void rcu_torture_barrier_cbf(struct rcu_head
*rcu
)
1574 atomic_inc(&barrier_cbs_invoked
);
1577 /* kthread function to register callbacks used to test RCU barriers. */
1578 static int rcu_torture_barrier_cbs(void *arg
)
1580 long myid
= (long)arg
;
1583 struct rcu_head rcu
;
1585 init_rcu_head_on_stack(&rcu
);
1586 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
1587 set_user_nice(current
, 19);
1589 wait_event(barrier_cbs_wq
[myid
],
1591 ACCESS_ONCE(barrier_phase
)) != lastphase
||
1592 kthread_should_stop() ||
1593 fullstop
!= FULLSTOP_DONTSTOP
);
1594 lastphase
= newphase
;
1595 smp_mb(); /* ensure barrier_phase load before ->call(). */
1596 if (kthread_should_stop() || fullstop
!= FULLSTOP_DONTSTOP
)
1598 cur_ops
->call(&rcu
, rcu_torture_barrier_cbf
);
1599 if (atomic_dec_and_test(&barrier_cbs_count
))
1600 wake_up(&barrier_wq
);
1601 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
1602 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task stopping");
1603 rcutorture_shutdown_absorb("rcu_torture_barrier_cbs");
1604 while (!kthread_should_stop())
1605 schedule_timeout_interruptible(1);
1606 cur_ops
->cb_barrier();
1607 destroy_rcu_head_on_stack(&rcu
);
1611 /* kthread function to drive and coordinate RCU barrier testing. */
1612 static int rcu_torture_barrier(void *arg
)
1616 VERBOSE_PRINTK_STRING("rcu_torture_barrier task starting");
1618 atomic_set(&barrier_cbs_invoked
, 0);
1619 atomic_set(&barrier_cbs_count
, n_barrier_cbs
);
1620 smp_mb(); /* Ensure barrier_phase after prior assignments. */
1621 barrier_phase
= !barrier_phase
;
1622 for (i
= 0; i
< n_barrier_cbs
; i
++)
1623 wake_up(&barrier_cbs_wq
[i
]);
1624 wait_event(barrier_wq
,
1625 atomic_read(&barrier_cbs_count
) == 0 ||
1626 kthread_should_stop() ||
1627 fullstop
!= FULLSTOP_DONTSTOP
);
1628 if (kthread_should_stop() || fullstop
!= FULLSTOP_DONTSTOP
)
1630 n_barrier_attempts
++;
1631 cur_ops
->cb_barrier(); /* Implies smp_mb() for wait_event(). */
1632 if (atomic_read(&barrier_cbs_invoked
) != n_barrier_cbs
) {
1633 n_rcu_torture_barrier_error
++;
1636 n_barrier_successes
++;
1637 schedule_timeout_interruptible(HZ
/ 10);
1638 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
1639 VERBOSE_PRINTK_STRING("rcu_torture_barrier task stopping");
1640 rcutorture_shutdown_absorb("rcu_torture_barrier");
1641 while (!kthread_should_stop())
1642 schedule_timeout_interruptible(1);
1646 /* Initialize RCU barrier testing. */
1647 static int rcu_torture_barrier_init(void)
1652 if (n_barrier_cbs
== 0)
1654 if (cur_ops
->call
== NULL
|| cur_ops
->cb_barrier
== NULL
) {
1655 pr_alert("%s" TORTURE_FLAG
1656 " Call or barrier ops missing for %s,\n",
1657 torture_type
, cur_ops
->name
);
1658 pr_alert("%s" TORTURE_FLAG
1659 " RCU barrier testing omitted from run.\n",
1663 atomic_set(&barrier_cbs_count
, 0);
1664 atomic_set(&barrier_cbs_invoked
, 0);
1666 kzalloc(n_barrier_cbs
* sizeof(barrier_cbs_tasks
[0]),
1669 kzalloc(n_barrier_cbs
* sizeof(barrier_cbs_wq
[0]),
1671 if (barrier_cbs_tasks
== NULL
|| !barrier_cbs_wq
)
1673 for (i
= 0; i
< n_barrier_cbs
; i
++) {
1674 init_waitqueue_head(&barrier_cbs_wq
[i
]);
1675 barrier_cbs_tasks
[i
] = kthread_run(rcu_torture_barrier_cbs
,
1677 "rcu_torture_barrier_cbs");
1678 if (IS_ERR(barrier_cbs_tasks
[i
])) {
1679 ret
= PTR_ERR(barrier_cbs_tasks
[i
]);
1680 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier_cbs");
1681 barrier_cbs_tasks
[i
] = NULL
;
1685 barrier_task
= kthread_run(rcu_torture_barrier
, NULL
,
1686 "rcu_torture_barrier");
1687 if (IS_ERR(barrier_task
)) {
1688 ret
= PTR_ERR(barrier_task
);
1689 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier");
1690 barrier_task
= NULL
;
1695 /* Clean up after RCU barrier testing. */
1696 static void rcu_torture_barrier_cleanup(void)
1700 if (barrier_task
!= NULL
) {
1701 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier task");
1702 kthread_stop(barrier_task
);
1703 barrier_task
= NULL
;
1705 if (barrier_cbs_tasks
!= NULL
) {
1706 for (i
= 0; i
< n_barrier_cbs
; i
++) {
1707 if (barrier_cbs_tasks
[i
] != NULL
) {
1708 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier_cbs task");
1709 kthread_stop(barrier_cbs_tasks
[i
]);
1710 barrier_cbs_tasks
[i
] = NULL
;
1713 kfree(barrier_cbs_tasks
);
1714 barrier_cbs_tasks
= NULL
;
1716 if (barrier_cbs_wq
!= NULL
) {
1717 kfree(barrier_cbs_wq
);
1718 barrier_cbs_wq
= NULL
;
1722 static int rcutorture_cpu_notify(struct notifier_block
*self
,
1723 unsigned long action
, void *hcpu
)
1725 long cpu
= (long)hcpu
;
1729 case CPU_DOWN_FAILED
:
1730 (void)rcutorture_booster_init(cpu
);
1732 case CPU_DOWN_PREPARE
:
1733 rcutorture_booster_cleanup(cpu
);
1741 static struct notifier_block rcutorture_cpu_nb
= {
1742 .notifier_call
= rcutorture_cpu_notify
,
1746 rcu_torture_cleanup(void)
1750 mutex_lock(&fullstop_mutex
);
1751 rcutorture_record_test_transition();
1752 if (fullstop
== FULLSTOP_SHUTDOWN
) {
1753 pr_warn(/* but going down anyway, so... */
1754 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
1755 mutex_unlock(&fullstop_mutex
);
1756 schedule_timeout_uninterruptible(10);
1757 if (cur_ops
->cb_barrier
!= NULL
)
1758 cur_ops
->cb_barrier();
1761 fullstop
= FULLSTOP_RMMOD
;
1762 mutex_unlock(&fullstop_mutex
);
1763 unregister_reboot_notifier(&rcutorture_shutdown_nb
);
1764 rcu_torture_barrier_cleanup();
1765 rcu_torture_stall_cleanup();
1767 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1768 kthread_stop(stutter_task
);
1770 stutter_task
= NULL
;
1771 if (shuffler_task
) {
1772 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1773 kthread_stop(shuffler_task
);
1774 free_cpumask_var(shuffle_tmp_mask
);
1776 shuffler_task
= NULL
;
1779 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1780 kthread_stop(writer_task
);
1785 for (i
= 0; i
< nrealreaders
; i
++) {
1786 if (reader_tasks
[i
]) {
1787 VERBOSE_PRINTK_STRING(
1788 "Stopping rcu_torture_reader task");
1789 kthread_stop(reader_tasks
[i
]);
1791 reader_tasks
[i
] = NULL
;
1793 kfree(reader_tasks
);
1794 reader_tasks
= NULL
;
1796 rcu_torture_current
= NULL
;
1798 if (fakewriter_tasks
) {
1799 for (i
= 0; i
< nfakewriters
; i
++) {
1800 if (fakewriter_tasks
[i
]) {
1801 VERBOSE_PRINTK_STRING(
1802 "Stopping rcu_torture_fakewriter task");
1803 kthread_stop(fakewriter_tasks
[i
]);
1805 fakewriter_tasks
[i
] = NULL
;
1807 kfree(fakewriter_tasks
);
1808 fakewriter_tasks
= NULL
;
1812 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1813 kthread_stop(stats_task
);
1818 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1819 kthread_stop(fqs_task
);
1822 if ((test_boost
== 1 && cur_ops
->can_boost
) ||
1824 unregister_cpu_notifier(&rcutorture_cpu_nb
);
1825 for_each_possible_cpu(i
)
1826 rcutorture_booster_cleanup(i
);
1828 if (shutdown_task
!= NULL
) {
1829 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1830 kthread_stop(shutdown_task
);
1832 shutdown_task
= NULL
;
1833 rcu_torture_onoff_cleanup();
1835 /* Wait for all RCU callbacks to fire. */
1837 if (cur_ops
->cb_barrier
!= NULL
)
1838 cur_ops
->cb_barrier();
1840 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
1842 if (atomic_read(&n_rcu_torture_error
) || n_rcu_torture_barrier_error
)
1843 rcu_torture_print_module_parms(cur_ops
, "End of test: FAILURE");
1844 else if (n_online_successes
!= n_online_attempts
||
1845 n_offline_successes
!= n_offline_attempts
)
1846 rcu_torture_print_module_parms(cur_ops
,
1847 "End of test: RCU_HOTPLUG");
1849 rcu_torture_print_module_parms(cur_ops
, "End of test: SUCCESS");
1852 #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1853 static void rcu_torture_leak_cb(struct rcu_head
*rhp
)
1857 static void rcu_torture_err_cb(struct rcu_head
*rhp
)
1860 * This -might- happen due to race conditions, but is unlikely.
1861 * The scenario that leads to this happening is that the
1862 * first of the pair of duplicate callbacks is queued,
1863 * someone else starts a grace period that includes that
1864 * callback, then the second of the pair must wait for the
1865 * next grace period. Unlikely, but can happen. If it
1866 * does happen, the debug-objects subsystem won't have splatted.
1868 pr_alert("rcutorture: duplicated callback was invoked.\n");
1870 #endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1873 * Verify that double-free causes debug-objects to complain, but only
1874 * if CONFIG_DEBUG_OBJECTS_RCU_HEAD=y. Otherwise, say that the test
1875 * cannot be carried out.
1877 static void rcu_test_debug_objects(void)
1879 #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1880 struct rcu_head rh1
;
1881 struct rcu_head rh2
;
1883 init_rcu_head_on_stack(&rh1
);
1884 init_rcu_head_on_stack(&rh2
);
1885 pr_alert("rcutorture: WARN: Duplicate call_rcu() test starting.\n");
1887 /* Try to queue the rh2 pair of callbacks for the same grace period. */
1888 preempt_disable(); /* Prevent preemption from interrupting test. */
1889 rcu_read_lock(); /* Make it impossible to finish a grace period. */
1890 call_rcu(&rh1
, rcu_torture_leak_cb
); /* Start grace period. */
1891 local_irq_disable(); /* Make it harder to start a new grace period. */
1892 call_rcu(&rh2
, rcu_torture_leak_cb
);
1893 call_rcu(&rh2
, rcu_torture_err_cb
); /* Duplicate callback. */
1898 /* Wait for them all to get done so we can safely return. */
1900 pr_alert("rcutorture: WARN: Duplicate call_rcu() test complete.\n");
1901 destroy_rcu_head_on_stack(&rh1
);
1902 destroy_rcu_head_on_stack(&rh2
);
1903 #else /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1904 pr_alert("rcutorture: !CONFIG_DEBUG_OBJECTS_RCU_HEAD, not testing duplicate call_rcu()\n");
1905 #endif /* #else #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1909 rcu_torture_init(void)
1915 static struct rcu_torture_ops
*torture_ops
[] = {
1916 &rcu_ops
, &rcu_bh_ops
, &srcu_ops
, &sched_ops
,
1919 mutex_lock(&fullstop_mutex
);
1921 /* Process args and tell the world that the torturer is on the job. */
1922 for (i
= 0; i
< ARRAY_SIZE(torture_ops
); i
++) {
1923 cur_ops
= torture_ops
[i
];
1924 if (strcmp(torture_type
, cur_ops
->name
) == 0)
1927 if (i
== ARRAY_SIZE(torture_ops
)) {
1928 pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
1930 pr_alert("rcu-torture types:");
1931 for (i
= 0; i
< ARRAY_SIZE(torture_ops
); i
++)
1932 pr_alert(" %s", torture_ops
[i
]->name
);
1934 mutex_unlock(&fullstop_mutex
);
1937 if (cur_ops
->fqs
== NULL
&& fqs_duration
!= 0) {
1938 pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
1942 cur_ops
->init(); /* no "goto unwind" prior to this point!!! */
1945 nrealreaders
= nreaders
;
1947 nrealreaders
= 2 * num_online_cpus();
1948 rcu_torture_print_module_parms(cur_ops
, "Start of test");
1949 fullstop
= FULLSTOP_DONTSTOP
;
1951 /* Set up the freelist. */
1953 INIT_LIST_HEAD(&rcu_torture_freelist
);
1954 for (i
= 0; i
< ARRAY_SIZE(rcu_tortures
); i
++) {
1955 rcu_tortures
[i
].rtort_mbtest
= 0;
1956 list_add_tail(&rcu_tortures
[i
].rtort_free
,
1957 &rcu_torture_freelist
);
1960 /* Initialize the statistics so that each run gets its own numbers. */
1962 rcu_torture_current
= NULL
;
1963 rcu_torture_current_version
= 0;
1964 atomic_set(&n_rcu_torture_alloc
, 0);
1965 atomic_set(&n_rcu_torture_alloc_fail
, 0);
1966 atomic_set(&n_rcu_torture_free
, 0);
1967 atomic_set(&n_rcu_torture_mberror
, 0);
1968 atomic_set(&n_rcu_torture_error
, 0);
1969 n_rcu_torture_barrier_error
= 0;
1970 n_rcu_torture_boost_ktrerror
= 0;
1971 n_rcu_torture_boost_rterror
= 0;
1972 n_rcu_torture_boost_failure
= 0;
1973 n_rcu_torture_boosts
= 0;
1974 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
1975 atomic_set(&rcu_torture_wcount
[i
], 0);
1976 for_each_possible_cpu(cpu
) {
1977 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
1978 per_cpu(rcu_torture_count
, cpu
)[i
] = 0;
1979 per_cpu(rcu_torture_batch
, cpu
)[i
] = 0;
1983 /* Start up the kthreads. */
1985 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1986 writer_task
= kthread_create(rcu_torture_writer
, NULL
,
1987 "rcu_torture_writer");
1988 if (IS_ERR(writer_task
)) {
1989 firsterr
= PTR_ERR(writer_task
);
1990 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1994 wake_up_process(writer_task
);
1995 fakewriter_tasks
= kzalloc(nfakewriters
* sizeof(fakewriter_tasks
[0]),
1997 if (fakewriter_tasks
== NULL
) {
1998 VERBOSE_PRINTK_ERRSTRING("out of memory");
2002 for (i
= 0; i
< nfakewriters
; i
++) {
2003 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
2004 fakewriter_tasks
[i
] = kthread_run(rcu_torture_fakewriter
, NULL
,
2005 "rcu_torture_fakewriter");
2006 if (IS_ERR(fakewriter_tasks
[i
])) {
2007 firsterr
= PTR_ERR(fakewriter_tasks
[i
]);
2008 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
2009 fakewriter_tasks
[i
] = NULL
;
2013 reader_tasks
= kzalloc(nrealreaders
* sizeof(reader_tasks
[0]),
2015 if (reader_tasks
== NULL
) {
2016 VERBOSE_PRINTK_ERRSTRING("out of memory");
2020 for (i
= 0; i
< nrealreaders
; i
++) {
2021 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
2022 reader_tasks
[i
] = kthread_run(rcu_torture_reader
, NULL
,
2023 "rcu_torture_reader");
2024 if (IS_ERR(reader_tasks
[i
])) {
2025 firsterr
= PTR_ERR(reader_tasks
[i
]);
2026 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
2027 reader_tasks
[i
] = NULL
;
2031 if (stat_interval
> 0) {
2032 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
2033 stats_task
= kthread_run(rcu_torture_stats
, NULL
,
2034 "rcu_torture_stats");
2035 if (IS_ERR(stats_task
)) {
2036 firsterr
= PTR_ERR(stats_task
);
2037 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
2042 if (test_no_idle_hz
) {
2043 rcu_idle_cpu
= num_online_cpus() - 1;
2045 if (!alloc_cpumask_var(&shuffle_tmp_mask
, GFP_KERNEL
)) {
2047 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
2051 /* Create the shuffler thread */
2052 shuffler_task
= kthread_run(rcu_torture_shuffle
, NULL
,
2053 "rcu_torture_shuffle");
2054 if (IS_ERR(shuffler_task
)) {
2055 free_cpumask_var(shuffle_tmp_mask
);
2056 firsterr
= PTR_ERR(shuffler_task
);
2057 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
2058 shuffler_task
= NULL
;
2065 /* Create the stutter thread */
2066 stutter_task
= kthread_run(rcu_torture_stutter
, NULL
,
2067 "rcu_torture_stutter");
2068 if (IS_ERR(stutter_task
)) {
2069 firsterr
= PTR_ERR(stutter_task
);
2070 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
2071 stutter_task
= NULL
;
2075 if (fqs_duration
< 0)
2078 /* Create the stutter thread */
2079 fqs_task
= kthread_run(rcu_torture_fqs
, NULL
,
2081 if (IS_ERR(fqs_task
)) {
2082 firsterr
= PTR_ERR(fqs_task
);
2083 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
2088 if (test_boost_interval
< 1)
2089 test_boost_interval
= 1;
2090 if (test_boost_duration
< 2)
2091 test_boost_duration
= 2;
2092 if ((test_boost
== 1 && cur_ops
->can_boost
) ||
2095 boost_starttime
= jiffies
+ test_boost_interval
* HZ
;
2096 register_cpu_notifier(&rcutorture_cpu_nb
);
2097 for_each_possible_cpu(i
) {
2098 if (cpu_is_offline(i
))
2099 continue; /* Heuristic: CPU can go offline. */
2100 retval
= rcutorture_booster_init(i
);
2107 if (shutdown_secs
> 0) {
2108 shutdown_time
= jiffies
+ shutdown_secs
* HZ
;
2109 shutdown_task
= kthread_create(rcu_torture_shutdown
, NULL
,
2110 "rcu_torture_shutdown");
2111 if (IS_ERR(shutdown_task
)) {
2112 firsterr
= PTR_ERR(shutdown_task
);
2113 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
2114 shutdown_task
= NULL
;
2117 wake_up_process(shutdown_task
);
2119 i
= rcu_torture_onoff_init();
2124 register_reboot_notifier(&rcutorture_shutdown_nb
);
2125 i
= rcu_torture_stall_init();
2130 retval
= rcu_torture_barrier_init();
2136 rcu_test_debug_objects();
2137 rcutorture_record_test_transition();
2138 mutex_unlock(&fullstop_mutex
);
2142 mutex_unlock(&fullstop_mutex
);
2143 rcu_torture_cleanup();
2147 module_init(rcu_torture_init
);
2148 module_exit(rcu_torture_cleanup
);