2 * Read-Copy Update module-based torture test facility
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * Copyright (C) IBM Corporation, 2005, 2006
20 * Authors: Paul E. McKenney <paulmck@us.ibm.com>
21 * Josh Triplett <josh@freedesktop.org>
23 * See also: Documentation/RCU/torture.txt
25 #include <linux/types.h>
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/module.h>
29 #include <linux/kthread.h>
30 #include <linux/err.h>
31 #include <linux/spinlock.h>
32 #include <linux/smp.h>
33 #include <linux/rcupdate.h>
34 #include <linux/interrupt.h>
35 #include <linux/sched.h>
36 #include <linux/atomic.h>
37 #include <linux/bitops.h>
38 #include <linux/completion.h>
39 #include <linux/moduleparam.h>
40 #include <linux/percpu.h>
41 #include <linux/notifier.h>
42 #include <linux/reboot.h>
43 #include <linux/freezer.h>
44 #include <linux/cpu.h>
45 #include <linux/delay.h>
46 #include <linux/stat.h>
47 #include <linux/srcu.h>
48 #include <linux/slab.h>
49 #include <asm/byteorder.h>
51 MODULE_LICENSE("GPL");
52 MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and "
53 "Josh Triplett <josh@freedesktop.org>");
55 static int nreaders
= -1; /* # reader threads, defaults to 2*ncpus */
56 static int nfakewriters
= 4; /* # fake writer threads */
57 static int stat_interval
; /* Interval between stats, in seconds. */
58 /* Defaults to "only at end of test". */
59 static bool verbose
; /* Print more debug info. */
60 static bool test_no_idle_hz
; /* Test RCU's support for tickless idle CPUs. */
61 static int shuffle_interval
= 3; /* Interval between shuffles (in sec)*/
62 static int stutter
= 5; /* Start/stop testing interval (in sec) */
63 static int irqreader
= 1; /* RCU readers from irq (timers). */
64 static int fqs_duration
; /* Duration of bursts (us), 0 to disable. */
65 static int fqs_holdoff
; /* Hold time within burst (us). */
66 static int fqs_stutter
= 3; /* Wait time between bursts (s). */
67 static int n_barrier_cbs
; /* Number of callbacks to test RCU barriers. */
68 static int onoff_interval
; /* Wait time between CPU hotplugs, 0=disable. */
69 static int onoff_holdoff
; /* Seconds after boot before CPU hotplugs. */
70 static int shutdown_secs
; /* Shutdown time (s). <=0 for no shutdown. */
71 static int stall_cpu
; /* CPU-stall duration (s). 0 for no stall. */
72 static int stall_cpu_holdoff
= 10; /* Time to wait until stall (s). */
73 static int test_boost
= 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */
74 static int test_boost_interval
= 7; /* Interval between boost tests, seconds. */
75 static int test_boost_duration
= 4; /* Duration of each boost test, seconds. */
76 static char *torture_type
= "rcu"; /* What RCU implementation to torture. */
78 module_param(nreaders
, int, 0444);
79 MODULE_PARM_DESC(nreaders
, "Number of RCU reader threads");
80 module_param(nfakewriters
, int, 0444);
81 MODULE_PARM_DESC(nfakewriters
, "Number of RCU fake writer threads");
82 module_param(stat_interval
, int, 0644);
83 MODULE_PARM_DESC(stat_interval
, "Number of seconds between stats printk()s");
84 module_param(verbose
, bool, 0444);
85 MODULE_PARM_DESC(verbose
, "Enable verbose debugging printk()s");
86 module_param(test_no_idle_hz
, bool, 0444);
87 MODULE_PARM_DESC(test_no_idle_hz
, "Test support for tickless idle CPUs");
88 module_param(shuffle_interval
, int, 0444);
89 MODULE_PARM_DESC(shuffle_interval
, "Number of seconds between shuffles");
90 module_param(stutter
, int, 0444);
91 MODULE_PARM_DESC(stutter
, "Number of seconds to run/halt test");
92 module_param(irqreader
, int, 0444);
93 MODULE_PARM_DESC(irqreader
, "Allow RCU readers from irq handlers");
94 module_param(fqs_duration
, int, 0444);
95 MODULE_PARM_DESC(fqs_duration
, "Duration of fqs bursts (us)");
96 module_param(fqs_holdoff
, int, 0444);
97 MODULE_PARM_DESC(fqs_holdoff
, "Holdoff time within fqs bursts (us)");
98 module_param(fqs_stutter
, int, 0444);
99 MODULE_PARM_DESC(fqs_stutter
, "Wait time between fqs bursts (s)");
100 module_param(n_barrier_cbs
, int, 0444);
101 MODULE_PARM_DESC(n_barrier_cbs
, "# of callbacks/kthreads for barrier testing");
102 module_param(onoff_interval
, int, 0444);
103 MODULE_PARM_DESC(onoff_interval
, "Time between CPU hotplugs (s), 0=disable");
104 module_param(onoff_holdoff
, int, 0444);
105 MODULE_PARM_DESC(onoff_holdoff
, "Time after boot before CPU hotplugs (s)");
106 module_param(shutdown_secs
, int, 0444);
107 MODULE_PARM_DESC(shutdown_secs
, "Shutdown time (s), zero to disable.");
108 module_param(stall_cpu
, int, 0444);
109 MODULE_PARM_DESC(stall_cpu
, "Stall duration (s), zero to disable.");
110 module_param(stall_cpu_holdoff
, int, 0444);
111 MODULE_PARM_DESC(stall_cpu_holdoff
, "Time to wait before starting stall (s).");
112 module_param(test_boost
, int, 0444);
113 MODULE_PARM_DESC(test_boost
, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
114 module_param(test_boost_interval
, int, 0444);
115 MODULE_PARM_DESC(test_boost_interval
, "Interval between boost tests, seconds.");
116 module_param(test_boost_duration
, int, 0444);
117 MODULE_PARM_DESC(test_boost_duration
, "Duration of each boost test, seconds.");
118 module_param(torture_type
, charp
, 0444);
119 MODULE_PARM_DESC(torture_type
, "Type of RCU to torture (rcu, rcu_bh, srcu)");
121 #define TORTURE_FLAG "-torture:"
122 #define PRINTK_STRING(s) \
123 do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
124 #define VERBOSE_PRINTK_STRING(s) \
125 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
126 #define VERBOSE_PRINTK_ERRSTRING(s) \
127 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
129 static char printk_buf
[4096];
131 static int nrealreaders
;
132 static struct task_struct
*writer_task
;
133 static struct task_struct
**fakewriter_tasks
;
134 static struct task_struct
**reader_tasks
;
135 static struct task_struct
*stats_task
;
136 static struct task_struct
*shuffler_task
;
137 static struct task_struct
*stutter_task
;
138 static struct task_struct
*fqs_task
;
139 static struct task_struct
*boost_tasks
[NR_CPUS
];
140 static struct task_struct
*shutdown_task
;
141 #ifdef CONFIG_HOTPLUG_CPU
142 static struct task_struct
*onoff_task
;
143 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
144 static struct task_struct
*stall_task
;
145 static struct task_struct
**barrier_cbs_tasks
;
146 static struct task_struct
*barrier_task
;
148 #define RCU_TORTURE_PIPE_LEN 10
151 struct rcu_head rtort_rcu
;
152 int rtort_pipe_count
;
153 struct list_head rtort_free
;
157 static LIST_HEAD(rcu_torture_freelist
);
158 static struct rcu_torture __rcu
*rcu_torture_current
;
159 static unsigned long rcu_torture_current_version
;
160 static struct rcu_torture rcu_tortures
[10 * RCU_TORTURE_PIPE_LEN
];
161 static DEFINE_SPINLOCK(rcu_torture_lock
);
162 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN
+ 1], rcu_torture_count
) =
164 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN
+ 1], rcu_torture_batch
) =
166 static atomic_t rcu_torture_wcount
[RCU_TORTURE_PIPE_LEN
+ 1];
167 static atomic_t n_rcu_torture_alloc
;
168 static atomic_t n_rcu_torture_alloc_fail
;
169 static atomic_t n_rcu_torture_free
;
170 static atomic_t n_rcu_torture_mberror
;
171 static atomic_t n_rcu_torture_error
;
172 static long n_rcu_torture_barrier_error
;
173 static long n_rcu_torture_boost_ktrerror
;
174 static long n_rcu_torture_boost_rterror
;
175 static long n_rcu_torture_boost_failure
;
176 static long n_rcu_torture_boosts
;
177 static long n_rcu_torture_timers
;
178 static long n_offline_attempts
;
179 static long n_offline_successes
;
180 static long n_online_attempts
;
181 static long n_online_successes
;
182 static long n_barrier_attempts
;
183 static long n_barrier_successes
;
184 static struct list_head rcu_torture_removed
;
185 static cpumask_var_t shuffle_tmp_mask
;
187 static int stutter_pause_test
;
189 #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
190 #define RCUTORTURE_RUNNABLE_INIT 1
192 #define RCUTORTURE_RUNNABLE_INIT 0
194 int rcutorture_runnable
= RCUTORTURE_RUNNABLE_INIT
;
195 module_param(rcutorture_runnable
, int, 0444);
196 MODULE_PARM_DESC(rcutorture_runnable
, "Start rcutorture at boot");
198 #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
199 #define rcu_can_boost() 1
200 #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
201 #define rcu_can_boost() 0
202 #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
204 static unsigned long shutdown_time
; /* jiffies to system shutdown. */
205 static unsigned long boost_starttime
; /* jiffies of next boost test start. */
206 DEFINE_MUTEX(boost_mutex
); /* protect setting boost_starttime */
207 /* and boost task create/destroy. */
208 static atomic_t barrier_cbs_count
; /* Barrier callbacks registered. */
209 static bool barrier_phase
; /* Test phase. */
210 static atomic_t barrier_cbs_invoked
; /* Barrier callbacks invoked. */
211 static wait_queue_head_t
*barrier_cbs_wq
; /* Coordinate barrier testing. */
212 static DECLARE_WAIT_QUEUE_HEAD(barrier_wq
);
214 /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
216 #define FULLSTOP_DONTSTOP 0 /* Normal operation. */
217 #define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
218 #define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
219 static int fullstop
= FULLSTOP_RMMOD
;
221 * Protect fullstop transitions and spawning of kthreads.
223 static DEFINE_MUTEX(fullstop_mutex
);
225 /* Forward reference. */
226 static void rcu_torture_cleanup(void);
229 * Detect and respond to a system shutdown.
232 rcutorture_shutdown_notify(struct notifier_block
*unused1
,
233 unsigned long unused2
, void *unused3
)
235 mutex_lock(&fullstop_mutex
);
236 if (fullstop
== FULLSTOP_DONTSTOP
)
237 fullstop
= FULLSTOP_SHUTDOWN
;
239 printk(KERN_WARNING
/* but going down anyway, so... */
240 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
241 mutex_unlock(&fullstop_mutex
);
246 * Absorb kthreads into a kernel function that won't return, so that
247 * they won't ever access module text or data again.
249 static void rcutorture_shutdown_absorb(char *title
)
251 if (ACCESS_ONCE(fullstop
) == FULLSTOP_SHUTDOWN
) {
253 "rcutorture thread %s parking due to system shutdown\n",
255 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT
);
260 * Allocate an element from the rcu_tortures pool.
262 static struct rcu_torture
*
263 rcu_torture_alloc(void)
267 spin_lock_bh(&rcu_torture_lock
);
268 if (list_empty(&rcu_torture_freelist
)) {
269 atomic_inc(&n_rcu_torture_alloc_fail
);
270 spin_unlock_bh(&rcu_torture_lock
);
273 atomic_inc(&n_rcu_torture_alloc
);
274 p
= rcu_torture_freelist
.next
;
276 spin_unlock_bh(&rcu_torture_lock
);
277 return container_of(p
, struct rcu_torture
, rtort_free
);
281 * Free an element to the rcu_tortures pool.
284 rcu_torture_free(struct rcu_torture
*p
)
286 atomic_inc(&n_rcu_torture_free
);
287 spin_lock_bh(&rcu_torture_lock
);
288 list_add_tail(&p
->rtort_free
, &rcu_torture_freelist
);
289 spin_unlock_bh(&rcu_torture_lock
);
292 struct rcu_random_state
{
293 unsigned long rrs_state
;
297 #define RCU_RANDOM_MULT 39916801 /* prime */
298 #define RCU_RANDOM_ADD 479001701 /* prime */
299 #define RCU_RANDOM_REFRESH 10000
301 #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
304 * Crude but fast random-number generator. Uses a linear congruential
305 * generator, with occasional help from cpu_clock().
308 rcu_random(struct rcu_random_state
*rrsp
)
310 if (--rrsp
->rrs_count
< 0) {
311 rrsp
->rrs_state
+= (unsigned long)local_clock();
312 rrsp
->rrs_count
= RCU_RANDOM_REFRESH
;
314 rrsp
->rrs_state
= rrsp
->rrs_state
* RCU_RANDOM_MULT
+ RCU_RANDOM_ADD
;
315 return swahw32(rrsp
->rrs_state
);
319 rcu_stutter_wait(char *title
)
321 while (stutter_pause_test
|| !rcutorture_runnable
) {
322 if (rcutorture_runnable
)
323 schedule_timeout_interruptible(1);
325 schedule_timeout_interruptible(round_jiffies_relative(HZ
));
326 rcutorture_shutdown_absorb(title
);
331 * Operations vector for selecting different types of tests.
334 struct rcu_torture_ops
{
336 void (*cleanup
)(void);
337 int (*readlock
)(void);
338 void (*read_delay
)(struct rcu_random_state
*rrsp
);
339 void (*readunlock
)(int idx
);
340 int (*completed
)(void);
341 void (*deferred_free
)(struct rcu_torture
*p
);
343 void (*call
)(struct rcu_head
*head
, void (*func
)(struct rcu_head
*rcu
));
344 void (*cb_barrier
)(void);
346 int (*stats
)(char *page
);
352 static struct rcu_torture_ops
*cur_ops
;
355 * Definitions for rcu torture testing.
358 static int rcu_torture_read_lock(void) __acquires(RCU
)
364 static void rcu_read_delay(struct rcu_random_state
*rrsp
)
366 const unsigned long shortdelay_us
= 200;
367 const unsigned long longdelay_ms
= 50;
369 /* We want a short delay sometimes to make a reader delay the grace
370 * period, and we want a long delay occasionally to trigger
371 * force_quiescent_state. */
373 if (!(rcu_random(rrsp
) % (nrealreaders
* 2000 * longdelay_ms
)))
374 mdelay(longdelay_ms
);
375 if (!(rcu_random(rrsp
) % (nrealreaders
* 2 * shortdelay_us
)))
376 udelay(shortdelay_us
);
377 #ifdef CONFIG_PREEMPT
378 if (!preempt_count() && !(rcu_random(rrsp
) % (nrealreaders
* 20000)))
379 preempt_schedule(); /* No QS if preempt_disable() in effect */
383 static void rcu_torture_read_unlock(int idx
) __releases(RCU
)
388 static int rcu_torture_completed(void)
390 return rcu_batches_completed();
394 rcu_torture_cb(struct rcu_head
*p
)
397 struct rcu_torture
*rp
= container_of(p
, struct rcu_torture
, rtort_rcu
);
399 if (fullstop
!= FULLSTOP_DONTSTOP
) {
400 /* Test is ending, just drop callbacks on the floor. */
401 /* The next initialization will pick up the pieces. */
404 i
= rp
->rtort_pipe_count
;
405 if (i
> RCU_TORTURE_PIPE_LEN
)
406 i
= RCU_TORTURE_PIPE_LEN
;
407 atomic_inc(&rcu_torture_wcount
[i
]);
408 if (++rp
->rtort_pipe_count
>= RCU_TORTURE_PIPE_LEN
) {
409 rp
->rtort_mbtest
= 0;
410 rcu_torture_free(rp
);
412 cur_ops
->deferred_free(rp
);
416 static int rcu_no_completed(void)
421 static void rcu_torture_deferred_free(struct rcu_torture
*p
)
423 call_rcu(&p
->rtort_rcu
, rcu_torture_cb
);
426 static struct rcu_torture_ops rcu_ops
= {
429 .readlock
= rcu_torture_read_lock
,
430 .read_delay
= rcu_read_delay
,
431 .readunlock
= rcu_torture_read_unlock
,
432 .completed
= rcu_torture_completed
,
433 .deferred_free
= rcu_torture_deferred_free
,
434 .sync
= synchronize_rcu
,
436 .cb_barrier
= rcu_barrier
,
437 .fqs
= rcu_force_quiescent_state
,
440 .can_boost
= rcu_can_boost(),
444 static void rcu_sync_torture_deferred_free(struct rcu_torture
*p
)
447 struct rcu_torture
*rp
;
448 struct rcu_torture
*rp1
;
451 list_add(&p
->rtort_free
, &rcu_torture_removed
);
452 list_for_each_entry_safe(rp
, rp1
, &rcu_torture_removed
, rtort_free
) {
453 i
= rp
->rtort_pipe_count
;
454 if (i
> RCU_TORTURE_PIPE_LEN
)
455 i
= RCU_TORTURE_PIPE_LEN
;
456 atomic_inc(&rcu_torture_wcount
[i
]);
457 if (++rp
->rtort_pipe_count
>= RCU_TORTURE_PIPE_LEN
) {
458 rp
->rtort_mbtest
= 0;
459 list_del(&rp
->rtort_free
);
460 rcu_torture_free(rp
);
465 static void rcu_sync_torture_init(void)
467 INIT_LIST_HEAD(&rcu_torture_removed
);
470 static struct rcu_torture_ops rcu_sync_ops
= {
471 .init
= rcu_sync_torture_init
,
473 .readlock
= rcu_torture_read_lock
,
474 .read_delay
= rcu_read_delay
,
475 .readunlock
= rcu_torture_read_unlock
,
476 .completed
= rcu_torture_completed
,
477 .deferred_free
= rcu_sync_torture_deferred_free
,
478 .sync
= synchronize_rcu
,
481 .fqs
= rcu_force_quiescent_state
,
484 .can_boost
= rcu_can_boost(),
488 static struct rcu_torture_ops rcu_expedited_ops
= {
489 .init
= rcu_sync_torture_init
,
491 .readlock
= rcu_torture_read_lock
,
492 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
493 .readunlock
= rcu_torture_read_unlock
,
494 .completed
= rcu_no_completed
,
495 .deferred_free
= rcu_sync_torture_deferred_free
,
496 .sync
= synchronize_rcu_expedited
,
499 .fqs
= rcu_force_quiescent_state
,
502 .can_boost
= rcu_can_boost(),
503 .name
= "rcu_expedited"
507 * Definitions for rcu_bh torture testing.
510 static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH
)
516 static void rcu_bh_torture_read_unlock(int idx
) __releases(RCU_BH
)
518 rcu_read_unlock_bh();
521 static int rcu_bh_torture_completed(void)
523 return rcu_batches_completed_bh();
526 static void rcu_bh_torture_deferred_free(struct rcu_torture
*p
)
528 call_rcu_bh(&p
->rtort_rcu
, rcu_torture_cb
);
531 static struct rcu_torture_ops rcu_bh_ops
= {
534 .readlock
= rcu_bh_torture_read_lock
,
535 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
536 .readunlock
= rcu_bh_torture_read_unlock
,
537 .completed
= rcu_bh_torture_completed
,
538 .deferred_free
= rcu_bh_torture_deferred_free
,
539 .sync
= synchronize_rcu_bh
,
541 .cb_barrier
= rcu_barrier_bh
,
542 .fqs
= rcu_bh_force_quiescent_state
,
548 static struct rcu_torture_ops rcu_bh_sync_ops
= {
549 .init
= rcu_sync_torture_init
,
551 .readlock
= rcu_bh_torture_read_lock
,
552 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
553 .readunlock
= rcu_bh_torture_read_unlock
,
554 .completed
= rcu_bh_torture_completed
,
555 .deferred_free
= rcu_sync_torture_deferred_free
,
556 .sync
= synchronize_rcu_bh
,
559 .fqs
= rcu_bh_force_quiescent_state
,
562 .name
= "rcu_bh_sync"
565 static struct rcu_torture_ops rcu_bh_expedited_ops
= {
566 .init
= rcu_sync_torture_init
,
568 .readlock
= rcu_bh_torture_read_lock
,
569 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
570 .readunlock
= rcu_bh_torture_read_unlock
,
571 .completed
= rcu_bh_torture_completed
,
572 .deferred_free
= rcu_sync_torture_deferred_free
,
573 .sync
= synchronize_rcu_bh_expedited
,
576 .fqs
= rcu_bh_force_quiescent_state
,
579 .name
= "rcu_bh_expedited"
583 * Definitions for srcu torture testing.
586 static struct srcu_struct srcu_ctl
;
588 static void srcu_torture_init(void)
590 init_srcu_struct(&srcu_ctl
);
591 rcu_sync_torture_init();
594 static void srcu_torture_cleanup(void)
596 synchronize_srcu(&srcu_ctl
);
597 cleanup_srcu_struct(&srcu_ctl
);
600 static int srcu_torture_read_lock(void) __acquires(&srcu_ctl
)
602 return srcu_read_lock(&srcu_ctl
);
605 static void srcu_read_delay(struct rcu_random_state
*rrsp
)
608 const long uspertick
= 1000000 / HZ
;
609 const long longdelay
= 10;
611 /* We want there to be long-running readers, but not all the time. */
613 delay
= rcu_random(rrsp
) % (nrealreaders
* 2 * longdelay
* uspertick
);
615 schedule_timeout_interruptible(longdelay
);
617 rcu_read_delay(rrsp
);
620 static void srcu_torture_read_unlock(int idx
) __releases(&srcu_ctl
)
622 srcu_read_unlock(&srcu_ctl
, idx
);
625 static int srcu_torture_completed(void)
627 return srcu_batches_completed(&srcu_ctl
);
630 static void srcu_torture_deferred_free(struct rcu_torture
*rp
)
632 call_srcu(&srcu_ctl
, &rp
->rtort_rcu
, rcu_torture_cb
);
635 static void srcu_torture_synchronize(void)
637 synchronize_srcu(&srcu_ctl
);
640 static void srcu_torture_call(struct rcu_head
*head
,
641 void (*func
)(struct rcu_head
*head
))
643 call_srcu(&srcu_ctl
, head
, func
);
646 static void srcu_torture_barrier(void)
648 srcu_barrier(&srcu_ctl
);
651 static int srcu_torture_stats(char *page
)
655 int idx
= srcu_ctl
.completed
& 0x1;
657 cnt
+= sprintf(&page
[cnt
], "%s%s per-CPU(idx=%d):",
658 torture_type
, TORTURE_FLAG
, idx
);
659 for_each_possible_cpu(cpu
) {
660 cnt
+= sprintf(&page
[cnt
], " %d(%lu,%lu)", cpu
,
661 per_cpu_ptr(srcu_ctl
.per_cpu_ref
, cpu
)->c
[!idx
],
662 per_cpu_ptr(srcu_ctl
.per_cpu_ref
, cpu
)->c
[idx
]);
664 cnt
+= sprintf(&page
[cnt
], "\n");
668 static struct rcu_torture_ops srcu_ops
= {
669 .init
= srcu_torture_init
,
670 .cleanup
= srcu_torture_cleanup
,
671 .readlock
= srcu_torture_read_lock
,
672 .read_delay
= srcu_read_delay
,
673 .readunlock
= srcu_torture_read_unlock
,
674 .completed
= srcu_torture_completed
,
675 .deferred_free
= srcu_torture_deferred_free
,
676 .sync
= srcu_torture_synchronize
,
677 .call
= srcu_torture_call
,
678 .cb_barrier
= srcu_torture_barrier
,
679 .stats
= srcu_torture_stats
,
683 static struct rcu_torture_ops srcu_sync_ops
= {
684 .init
= srcu_torture_init
,
685 .cleanup
= srcu_torture_cleanup
,
686 .readlock
= srcu_torture_read_lock
,
687 .read_delay
= srcu_read_delay
,
688 .readunlock
= srcu_torture_read_unlock
,
689 .completed
= srcu_torture_completed
,
690 .deferred_free
= rcu_sync_torture_deferred_free
,
691 .sync
= srcu_torture_synchronize
,
694 .stats
= srcu_torture_stats
,
698 static int srcu_torture_read_lock_raw(void) __acquires(&srcu_ctl
)
700 return srcu_read_lock_raw(&srcu_ctl
);
703 static void srcu_torture_read_unlock_raw(int idx
) __releases(&srcu_ctl
)
705 srcu_read_unlock_raw(&srcu_ctl
, idx
);
708 static struct rcu_torture_ops srcu_raw_ops
= {
709 .init
= srcu_torture_init
,
710 .cleanup
= srcu_torture_cleanup
,
711 .readlock
= srcu_torture_read_lock_raw
,
712 .read_delay
= srcu_read_delay
,
713 .readunlock
= srcu_torture_read_unlock_raw
,
714 .completed
= srcu_torture_completed
,
715 .deferred_free
= srcu_torture_deferred_free
,
716 .sync
= srcu_torture_synchronize
,
719 .stats
= srcu_torture_stats
,
723 static struct rcu_torture_ops srcu_raw_sync_ops
= {
724 .init
= srcu_torture_init
,
725 .cleanup
= srcu_torture_cleanup
,
726 .readlock
= srcu_torture_read_lock_raw
,
727 .read_delay
= srcu_read_delay
,
728 .readunlock
= srcu_torture_read_unlock_raw
,
729 .completed
= srcu_torture_completed
,
730 .deferred_free
= rcu_sync_torture_deferred_free
,
731 .sync
= srcu_torture_synchronize
,
734 .stats
= srcu_torture_stats
,
735 .name
= "srcu_raw_sync"
738 static void srcu_torture_synchronize_expedited(void)
740 synchronize_srcu_expedited(&srcu_ctl
);
743 static struct rcu_torture_ops srcu_expedited_ops
= {
744 .init
= srcu_torture_init
,
745 .cleanup
= srcu_torture_cleanup
,
746 .readlock
= srcu_torture_read_lock
,
747 .read_delay
= srcu_read_delay
,
748 .readunlock
= srcu_torture_read_unlock
,
749 .completed
= srcu_torture_completed
,
750 .deferred_free
= rcu_sync_torture_deferred_free
,
751 .sync
= srcu_torture_synchronize_expedited
,
754 .stats
= srcu_torture_stats
,
755 .name
= "srcu_expedited"
759 * Definitions for sched torture testing.
762 static int sched_torture_read_lock(void)
768 static void sched_torture_read_unlock(int idx
)
773 static void rcu_sched_torture_deferred_free(struct rcu_torture
*p
)
775 call_rcu_sched(&p
->rtort_rcu
, rcu_torture_cb
);
778 static struct rcu_torture_ops sched_ops
= {
779 .init
= rcu_sync_torture_init
,
781 .readlock
= sched_torture_read_lock
,
782 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
783 .readunlock
= sched_torture_read_unlock
,
784 .completed
= rcu_no_completed
,
785 .deferred_free
= rcu_sched_torture_deferred_free
,
786 .sync
= synchronize_sched
,
787 .cb_barrier
= rcu_barrier_sched
,
788 .fqs
= rcu_sched_force_quiescent_state
,
794 static struct rcu_torture_ops sched_sync_ops
= {
795 .init
= rcu_sync_torture_init
,
797 .readlock
= sched_torture_read_lock
,
798 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
799 .readunlock
= sched_torture_read_unlock
,
800 .completed
= rcu_no_completed
,
801 .deferred_free
= rcu_sync_torture_deferred_free
,
802 .sync
= synchronize_sched
,
804 .fqs
= rcu_sched_force_quiescent_state
,
809 static struct rcu_torture_ops sched_expedited_ops
= {
810 .init
= rcu_sync_torture_init
,
812 .readlock
= sched_torture_read_lock
,
813 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
814 .readunlock
= sched_torture_read_unlock
,
815 .completed
= rcu_no_completed
,
816 .deferred_free
= rcu_sync_torture_deferred_free
,
817 .sync
= synchronize_sched_expedited
,
819 .fqs
= rcu_sched_force_quiescent_state
,
822 .name
= "sched_expedited"
826 * RCU torture priority-boost testing. Runs one real-time thread per
827 * CPU for moderate bursts, repeatedly registering RCU callbacks and
828 * spinning waiting for them to be invoked. If a given callback takes
829 * too long to be invoked, we assume that priority inversion has occurred.
832 struct rcu_boost_inflight
{
837 static void rcu_torture_boost_cb(struct rcu_head
*head
)
839 struct rcu_boost_inflight
*rbip
=
840 container_of(head
, struct rcu_boost_inflight
, rcu
);
842 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
846 static int rcu_torture_boost(void *arg
)
848 unsigned long call_rcu_time
;
849 unsigned long endtime
;
850 unsigned long oldstarttime
;
851 struct rcu_boost_inflight rbi
= { .inflight
= 0 };
852 struct sched_param sp
;
854 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
856 /* Set real-time priority. */
857 sp
.sched_priority
= 1;
858 if (sched_setscheduler(current
, SCHED_FIFO
, &sp
) < 0) {
859 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
860 n_rcu_torture_boost_rterror
++;
863 init_rcu_head_on_stack(&rbi
.rcu
);
864 /* Each pass through the following loop does one boost-test cycle. */
866 /* Wait for the next test interval. */
867 oldstarttime
= boost_starttime
;
868 while (ULONG_CMP_LT(jiffies
, oldstarttime
)) {
869 schedule_timeout_uninterruptible(1);
870 rcu_stutter_wait("rcu_torture_boost");
871 if (kthread_should_stop() ||
872 fullstop
!= FULLSTOP_DONTSTOP
)
876 /* Do one boost-test interval. */
877 endtime
= oldstarttime
+ test_boost_duration
* HZ
;
878 call_rcu_time
= jiffies
;
879 while (ULONG_CMP_LT(jiffies
, endtime
)) {
880 /* If we don't have a callback in flight, post one. */
882 smp_mb(); /* RCU core before ->inflight = 1. */
884 call_rcu(&rbi
.rcu
, rcu_torture_boost_cb
);
885 if (jiffies
- call_rcu_time
>
886 test_boost_duration
* HZ
- HZ
/ 2) {
887 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
888 n_rcu_torture_boost_failure
++;
890 call_rcu_time
= jiffies
;
893 rcu_stutter_wait("rcu_torture_boost");
894 if (kthread_should_stop() ||
895 fullstop
!= FULLSTOP_DONTSTOP
)
900 * Set the start time of the next test interval.
901 * Yes, this is vulnerable to long delays, but such
902 * delays simply cause a false negative for the next
903 * interval. Besides, we are running at RT priority,
904 * so delays should be relatively rare.
906 while (oldstarttime
== boost_starttime
&&
907 !kthread_should_stop()) {
908 if (mutex_trylock(&boost_mutex
)) {
909 boost_starttime
= jiffies
+
910 test_boost_interval
* HZ
;
911 n_rcu_torture_boosts
++;
912 mutex_unlock(&boost_mutex
);
915 schedule_timeout_uninterruptible(1);
918 /* Go do the stutter. */
919 checkwait
: rcu_stutter_wait("rcu_torture_boost");
920 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
922 /* Clean up and exit. */
923 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
924 rcutorture_shutdown_absorb("rcu_torture_boost");
925 while (!kthread_should_stop() || rbi
.inflight
)
926 schedule_timeout_uninterruptible(1);
927 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
928 destroy_rcu_head_on_stack(&rbi
.rcu
);
933 * RCU torture force-quiescent-state kthread. Repeatedly induces
934 * bursts of calls to force_quiescent_state(), increasing the probability
935 * of occurrence of some important types of race conditions.
938 rcu_torture_fqs(void *arg
)
940 unsigned long fqs_resume_time
;
941 int fqs_burst_remaining
;
943 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
945 fqs_resume_time
= jiffies
+ fqs_stutter
* HZ
;
946 while (ULONG_CMP_LT(jiffies
, fqs_resume_time
) &&
947 !kthread_should_stop()) {
948 schedule_timeout_interruptible(1);
950 fqs_burst_remaining
= fqs_duration
;
951 while (fqs_burst_remaining
> 0 &&
952 !kthread_should_stop()) {
955 fqs_burst_remaining
-= fqs_holdoff
;
957 rcu_stutter_wait("rcu_torture_fqs");
958 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
959 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
960 rcutorture_shutdown_absorb("rcu_torture_fqs");
961 while (!kthread_should_stop())
962 schedule_timeout_uninterruptible(1);
967 * RCU torture writer kthread. Repeatedly substitutes a new structure
968 * for that pointed to by rcu_torture_current, freeing the old structure
969 * after a series of grace periods (the "pipeline").
972 rcu_torture_writer(void *arg
)
975 long oldbatch
= rcu_batches_completed();
976 struct rcu_torture
*rp
;
977 struct rcu_torture
*old_rp
;
978 static DEFINE_RCU_RANDOM(rand
);
980 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
981 set_user_nice(current
, 19);
984 schedule_timeout_uninterruptible(1);
985 rp
= rcu_torture_alloc();
988 rp
->rtort_pipe_count
= 0;
989 udelay(rcu_random(&rand
) & 0x3ff);
990 old_rp
= rcu_dereference_check(rcu_torture_current
,
991 current
== writer_task
);
992 rp
->rtort_mbtest
= 1;
993 rcu_assign_pointer(rcu_torture_current
, rp
);
994 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
996 i
= old_rp
->rtort_pipe_count
;
997 if (i
> RCU_TORTURE_PIPE_LEN
)
998 i
= RCU_TORTURE_PIPE_LEN
;
999 atomic_inc(&rcu_torture_wcount
[i
]);
1000 old_rp
->rtort_pipe_count
++;
1001 cur_ops
->deferred_free(old_rp
);
1003 rcutorture_record_progress(++rcu_torture_current_version
);
1004 oldbatch
= cur_ops
->completed();
1005 rcu_stutter_wait("rcu_torture_writer");
1006 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
1007 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
1008 rcutorture_shutdown_absorb("rcu_torture_writer");
1009 while (!kthread_should_stop())
1010 schedule_timeout_uninterruptible(1);
1015 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
1016 * delay between calls.
1019 rcu_torture_fakewriter(void *arg
)
1021 DEFINE_RCU_RANDOM(rand
);
1023 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
1024 set_user_nice(current
, 19);
1027 schedule_timeout_uninterruptible(1 + rcu_random(&rand
)%10);
1028 udelay(rcu_random(&rand
) & 0x3ff);
1029 if (cur_ops
->cb_barrier
!= NULL
&&
1030 rcu_random(&rand
) % (nfakewriters
* 8) == 0)
1031 cur_ops
->cb_barrier();
1034 rcu_stutter_wait("rcu_torture_fakewriter");
1035 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
1037 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
1038 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
1039 while (!kthread_should_stop())
1040 schedule_timeout_uninterruptible(1);
1044 void rcutorture_trace_dump(void)
1046 static atomic_t beenhere
= ATOMIC_INIT(0);
1048 if (atomic_read(&beenhere
))
1050 if (atomic_xchg(&beenhere
, 1) != 0)
1052 do_trace_rcu_torture_read(cur_ops
->name
, (struct rcu_head
*)~0UL);
1053 ftrace_dump(DUMP_ALL
);
1057 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
1058 * incrementing the corresponding element of the pipeline array. The
1059 * counter in the element should never be greater than 1, otherwise, the
1060 * RCU implementation is broken.
1062 static void rcu_torture_timer(unsigned long unused
)
1066 static DEFINE_RCU_RANDOM(rand
);
1067 static DEFINE_SPINLOCK(rand_lock
);
1068 struct rcu_torture
*p
;
1071 idx
= cur_ops
->readlock();
1072 completed
= cur_ops
->completed();
1073 p
= rcu_dereference_check(rcu_torture_current
,
1074 rcu_read_lock_bh_held() ||
1075 rcu_read_lock_sched_held() ||
1076 srcu_read_lock_held(&srcu_ctl
));
1078 /* Leave because rcu_torture_writer is not yet underway */
1079 cur_ops
->readunlock(idx
);
1082 do_trace_rcu_torture_read(cur_ops
->name
, &p
->rtort_rcu
);
1083 if (p
->rtort_mbtest
== 0)
1084 atomic_inc(&n_rcu_torture_mberror
);
1085 spin_lock(&rand_lock
);
1086 cur_ops
->read_delay(&rand
);
1087 n_rcu_torture_timers
++;
1088 spin_unlock(&rand_lock
);
1090 pipe_count
= p
->rtort_pipe_count
;
1091 if (pipe_count
> RCU_TORTURE_PIPE_LEN
) {
1092 /* Should not happen, but... */
1093 pipe_count
= RCU_TORTURE_PIPE_LEN
;
1096 rcutorture_trace_dump();
1097 __this_cpu_inc(rcu_torture_count
[pipe_count
]);
1098 completed
= cur_ops
->completed() - completed
;
1099 if (completed
> RCU_TORTURE_PIPE_LEN
) {
1100 /* Should not happen, but... */
1101 completed
= RCU_TORTURE_PIPE_LEN
;
1103 __this_cpu_inc(rcu_torture_batch
[completed
]);
1105 cur_ops
->readunlock(idx
);
1109 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
1110 * incrementing the corresponding element of the pipeline array. The
1111 * counter in the element should never be greater than 1, otherwise, the
1112 * RCU implementation is broken.
1115 rcu_torture_reader(void *arg
)
1119 DEFINE_RCU_RANDOM(rand
);
1120 struct rcu_torture
*p
;
1122 struct timer_list t
;
1124 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
1125 set_user_nice(current
, 19);
1126 if (irqreader
&& cur_ops
->irq_capable
)
1127 setup_timer_on_stack(&t
, rcu_torture_timer
, 0);
1130 if (irqreader
&& cur_ops
->irq_capable
) {
1131 if (!timer_pending(&t
))
1132 mod_timer(&t
, jiffies
+ 1);
1134 idx
= cur_ops
->readlock();
1135 completed
= cur_ops
->completed();
1136 p
= rcu_dereference_check(rcu_torture_current
,
1137 rcu_read_lock_bh_held() ||
1138 rcu_read_lock_sched_held() ||
1139 srcu_read_lock_held(&srcu_ctl
));
1141 /* Wait for rcu_torture_writer to get underway */
1142 cur_ops
->readunlock(idx
);
1143 schedule_timeout_interruptible(HZ
);
1146 do_trace_rcu_torture_read(cur_ops
->name
, &p
->rtort_rcu
);
1147 if (p
->rtort_mbtest
== 0)
1148 atomic_inc(&n_rcu_torture_mberror
);
1149 cur_ops
->read_delay(&rand
);
1151 pipe_count
= p
->rtort_pipe_count
;
1152 if (pipe_count
> RCU_TORTURE_PIPE_LEN
) {
1153 /* Should not happen, but... */
1154 pipe_count
= RCU_TORTURE_PIPE_LEN
;
1157 rcutorture_trace_dump();
1158 __this_cpu_inc(rcu_torture_count
[pipe_count
]);
1159 completed
= cur_ops
->completed() - completed
;
1160 if (completed
> RCU_TORTURE_PIPE_LEN
) {
1161 /* Should not happen, but... */
1162 completed
= RCU_TORTURE_PIPE_LEN
;
1164 __this_cpu_inc(rcu_torture_batch
[completed
]);
1166 cur_ops
->readunlock(idx
);
1168 rcu_stutter_wait("rcu_torture_reader");
1169 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
1170 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
1171 rcutorture_shutdown_absorb("rcu_torture_reader");
1172 if (irqreader
&& cur_ops
->irq_capable
)
1174 while (!kthread_should_stop())
1175 schedule_timeout_uninterruptible(1);
1180 * Create an RCU-torture statistics message in the specified buffer.
1183 rcu_torture_printk(char *page
)
1188 long pipesummary
[RCU_TORTURE_PIPE_LEN
+ 1] = { 0 };
1189 long batchsummary
[RCU_TORTURE_PIPE_LEN
+ 1] = { 0 };
1191 for_each_possible_cpu(cpu
) {
1192 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
1193 pipesummary
[i
] += per_cpu(rcu_torture_count
, cpu
)[i
];
1194 batchsummary
[i
] += per_cpu(rcu_torture_batch
, cpu
)[i
];
1197 for (i
= RCU_TORTURE_PIPE_LEN
- 1; i
>= 0; i
--) {
1198 if (pipesummary
[i
] != 0)
1201 cnt
+= sprintf(&page
[cnt
], "%s%s ", torture_type
, TORTURE_FLAG
);
1202 cnt
+= sprintf(&page
[cnt
],
1203 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d "
1204 "rtmbe: %d rtbke: %ld rtbre: %ld "
1205 "rtbf: %ld rtb: %ld nt: %ld "
1206 "onoff: %ld/%ld:%ld/%ld "
1207 "barrier: %ld/%ld:%ld",
1208 rcu_torture_current
,
1209 rcu_torture_current_version
,
1210 list_empty(&rcu_torture_freelist
),
1211 atomic_read(&n_rcu_torture_alloc
),
1212 atomic_read(&n_rcu_torture_alloc_fail
),
1213 atomic_read(&n_rcu_torture_free
),
1214 atomic_read(&n_rcu_torture_mberror
),
1215 n_rcu_torture_boost_ktrerror
,
1216 n_rcu_torture_boost_rterror
,
1217 n_rcu_torture_boost_failure
,
1218 n_rcu_torture_boosts
,
1219 n_rcu_torture_timers
,
1222 n_offline_successes
,
1224 n_barrier_successes
,
1226 n_rcu_torture_barrier_error
);
1227 cnt
+= sprintf(&page
[cnt
], "\n%s%s ", torture_type
, TORTURE_FLAG
);
1228 if (atomic_read(&n_rcu_torture_mberror
) != 0 ||
1229 n_rcu_torture_barrier_error
!= 0 ||
1230 n_rcu_torture_boost_ktrerror
!= 0 ||
1231 n_rcu_torture_boost_rterror
!= 0 ||
1232 n_rcu_torture_boost_failure
!= 0 ||
1234 cnt
+= sprintf(&page
[cnt
], "!!! ");
1235 atomic_inc(&n_rcu_torture_error
);
1238 cnt
+= sprintf(&page
[cnt
], "Reader Pipe: ");
1239 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
1240 cnt
+= sprintf(&page
[cnt
], " %ld", pipesummary
[i
]);
1241 cnt
+= sprintf(&page
[cnt
], "\n%s%s ", torture_type
, TORTURE_FLAG
);
1242 cnt
+= sprintf(&page
[cnt
], "Reader Batch: ");
1243 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
1244 cnt
+= sprintf(&page
[cnt
], " %ld", batchsummary
[i
]);
1245 cnt
+= sprintf(&page
[cnt
], "\n%s%s ", torture_type
, TORTURE_FLAG
);
1246 cnt
+= sprintf(&page
[cnt
], "Free-Block Circulation: ");
1247 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
1248 cnt
+= sprintf(&page
[cnt
], " %d",
1249 atomic_read(&rcu_torture_wcount
[i
]));
1251 cnt
+= sprintf(&page
[cnt
], "\n");
1253 cnt
+= cur_ops
->stats(&page
[cnt
]);
1258 * Print torture statistics. Caller must ensure that there is only
1259 * one call to this function at a given time!!! This is normally
1260 * accomplished by relying on the module system to only have one copy
1261 * of the module loaded, and then by giving the rcu_torture_stats
1262 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1263 * thread is not running).
1266 rcu_torture_stats_print(void)
1270 cnt
= rcu_torture_printk(printk_buf
);
1271 printk(KERN_ALERT
"%s", printk_buf
);
1275 * Periodically prints torture statistics, if periodic statistics printing
1276 * was specified via the stat_interval module parameter.
1278 * No need to worry about fullstop here, since this one doesn't reference
1279 * volatile state or register callbacks.
1282 rcu_torture_stats(void *arg
)
1284 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1286 schedule_timeout_interruptible(stat_interval
* HZ
);
1287 rcu_torture_stats_print();
1288 rcutorture_shutdown_absorb("rcu_torture_stats");
1289 } while (!kthread_should_stop());
1290 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1294 static int rcu_idle_cpu
; /* Force all torture tasks off this CPU */
1296 /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1297 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1299 static void rcu_torture_shuffle_tasks(void)
1303 cpumask_setall(shuffle_tmp_mask
);
1306 /* No point in shuffling if there is only one online CPU (ex: UP) */
1307 if (num_online_cpus() == 1) {
1312 if (rcu_idle_cpu
!= -1)
1313 cpumask_clear_cpu(rcu_idle_cpu
, shuffle_tmp_mask
);
1315 set_cpus_allowed_ptr(current
, shuffle_tmp_mask
);
1318 for (i
= 0; i
< nrealreaders
; i
++)
1319 if (reader_tasks
[i
])
1320 set_cpus_allowed_ptr(reader_tasks
[i
],
1324 if (fakewriter_tasks
) {
1325 for (i
= 0; i
< nfakewriters
; i
++)
1326 if (fakewriter_tasks
[i
])
1327 set_cpus_allowed_ptr(fakewriter_tasks
[i
],
1332 set_cpus_allowed_ptr(writer_task
, shuffle_tmp_mask
);
1335 set_cpus_allowed_ptr(stats_task
, shuffle_tmp_mask
);
1337 if (rcu_idle_cpu
== -1)
1338 rcu_idle_cpu
= num_online_cpus() - 1;
1345 /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1346 * system to become idle at a time and cut off its timer ticks. This is meant
1347 * to test the support for such tickless idle CPU in RCU.
1350 rcu_torture_shuffle(void *arg
)
1352 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1354 schedule_timeout_interruptible(shuffle_interval
* HZ
);
1355 rcu_torture_shuffle_tasks();
1356 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1357 } while (!kthread_should_stop());
1358 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1362 /* Cause the rcutorture test to "stutter", starting and stopping all
1363 * threads periodically.
1366 rcu_torture_stutter(void *arg
)
1368 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1370 schedule_timeout_interruptible(stutter
* HZ
);
1371 stutter_pause_test
= 1;
1372 if (!kthread_should_stop())
1373 schedule_timeout_interruptible(stutter
* HZ
);
1374 stutter_pause_test
= 0;
1375 rcutorture_shutdown_absorb("rcu_torture_stutter");
1376 } while (!kthread_should_stop());
1377 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1382 rcu_torture_print_module_parms(struct rcu_torture_ops
*cur_ops
, char *tag
)
1384 printk(KERN_ALERT
"%s" TORTURE_FLAG
1385 "--- %s: nreaders=%d nfakewriters=%d "
1386 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1387 "shuffle_interval=%d stutter=%d irqreader=%d "
1388 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1389 "test_boost=%d/%d test_boost_interval=%d "
1390 "test_boost_duration=%d shutdown_secs=%d "
1391 "onoff_interval=%d onoff_holdoff=%d\n",
1392 torture_type
, tag
, nrealreaders
, nfakewriters
,
1393 stat_interval
, verbose
, test_no_idle_hz
, shuffle_interval
,
1394 stutter
, irqreader
, fqs_duration
, fqs_holdoff
, fqs_stutter
,
1395 test_boost
, cur_ops
->can_boost
,
1396 test_boost_interval
, test_boost_duration
, shutdown_secs
,
1397 onoff_interval
, onoff_holdoff
);
1400 static struct notifier_block rcutorture_shutdown_nb
= {
1401 .notifier_call
= rcutorture_shutdown_notify
,
1404 static void rcutorture_booster_cleanup(int cpu
)
1406 struct task_struct
*t
;
1408 if (boost_tasks
[cpu
] == NULL
)
1410 mutex_lock(&boost_mutex
);
1411 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1412 t
= boost_tasks
[cpu
];
1413 boost_tasks
[cpu
] = NULL
;
1414 mutex_unlock(&boost_mutex
);
1416 /* This must be outside of the mutex, otherwise deadlock! */
1418 boost_tasks
[cpu
] = NULL
;
1421 static int rcutorture_booster_init(int cpu
)
1425 if (boost_tasks
[cpu
] != NULL
)
1426 return 0; /* Already created, nothing more to do. */
1428 /* Don't allow time recalculation while creating a new task. */
1429 mutex_lock(&boost_mutex
);
1430 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
1431 boost_tasks
[cpu
] = kthread_create_on_node(rcu_torture_boost
, NULL
,
1433 "rcu_torture_boost");
1434 if (IS_ERR(boost_tasks
[cpu
])) {
1435 retval
= PTR_ERR(boost_tasks
[cpu
]);
1436 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1437 n_rcu_torture_boost_ktrerror
++;
1438 boost_tasks
[cpu
] = NULL
;
1439 mutex_unlock(&boost_mutex
);
1442 kthread_bind(boost_tasks
[cpu
], cpu
);
1443 wake_up_process(boost_tasks
[cpu
]);
1444 mutex_unlock(&boost_mutex
);
1449 * Cause the rcutorture test to shutdown the system after the test has
1450 * run for the time specified by the shutdown_secs module parameter.
1453 rcu_torture_shutdown(void *arg
)
1456 unsigned long jiffies_snap
;
1458 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1459 jiffies_snap
= ACCESS_ONCE(jiffies
);
1460 while (ULONG_CMP_LT(jiffies_snap
, shutdown_time
) &&
1461 !kthread_should_stop()) {
1462 delta
= shutdown_time
- jiffies_snap
;
1464 printk(KERN_ALERT
"%s" TORTURE_FLAG
1465 "rcu_torture_shutdown task: %lu "
1466 "jiffies remaining\n",
1467 torture_type
, delta
);
1468 schedule_timeout_interruptible(delta
);
1469 jiffies_snap
= ACCESS_ONCE(jiffies
);
1471 if (kthread_should_stop()) {
1472 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1476 /* OK, shut down the system. */
1478 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1479 shutdown_task
= NULL
; /* Avoid self-kill deadlock. */
1480 rcu_torture_cleanup(); /* Get the success/failure message. */
1481 kernel_power_off(); /* Shut down the system. */
1485 #ifdef CONFIG_HOTPLUG_CPU
1488 * Execute random CPU-hotplug operations at the interval specified
1489 * by the onoff_interval.
1491 static int __cpuinit
1492 rcu_torture_onoff(void *arg
)
1496 DEFINE_RCU_RANDOM(rand
);
1498 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1499 for_each_online_cpu(cpu
)
1501 WARN_ON(maxcpu
< 0);
1502 if (onoff_holdoff
> 0) {
1503 VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff");
1504 schedule_timeout_interruptible(onoff_holdoff
* HZ
);
1505 VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff");
1507 while (!kthread_should_stop()) {
1508 cpu
= (rcu_random(&rand
) >> 4) % (maxcpu
+ 1);
1509 if (cpu_online(cpu
) && cpu_is_hotpluggable(cpu
)) {
1511 printk(KERN_ALERT
"%s" TORTURE_FLAG
1512 "rcu_torture_onoff task: offlining %d\n",
1514 n_offline_attempts
++;
1515 if (cpu_down(cpu
) == 0) {
1517 printk(KERN_ALERT
"%s" TORTURE_FLAG
1518 "rcu_torture_onoff task: "
1521 n_offline_successes
++;
1523 } else if (cpu_is_hotpluggable(cpu
)) {
1525 printk(KERN_ALERT
"%s" TORTURE_FLAG
1526 "rcu_torture_onoff task: onlining %d\n",
1528 n_online_attempts
++;
1529 if (cpu_up(cpu
) == 0) {
1531 printk(KERN_ALERT
"%s" TORTURE_FLAG
1532 "rcu_torture_onoff task: "
1535 n_online_successes
++;
1538 schedule_timeout_interruptible(onoff_interval
* HZ
);
1540 VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1544 static int __cpuinit
1545 rcu_torture_onoff_init(void)
1549 if (onoff_interval
<= 0)
1551 onoff_task
= kthread_run(rcu_torture_onoff
, NULL
, "rcu_torture_onoff");
1552 if (IS_ERR(onoff_task
)) {
1553 ret
= PTR_ERR(onoff_task
);
1560 static void rcu_torture_onoff_cleanup(void)
1562 if (onoff_task
== NULL
)
1564 VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1565 kthread_stop(onoff_task
);
1569 #else /* #ifdef CONFIG_HOTPLUG_CPU */
1572 rcu_torture_onoff_init(void)
1577 static void rcu_torture_onoff_cleanup(void)
1581 #endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1584 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1585 * induces a CPU stall for the time specified by stall_cpu.
1587 static int __cpuinit
rcu_torture_stall(void *args
)
1589 unsigned long stop_at
;
1591 VERBOSE_PRINTK_STRING("rcu_torture_stall task started");
1592 if (stall_cpu_holdoff
> 0) {
1593 VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff");
1594 schedule_timeout_interruptible(stall_cpu_holdoff
* HZ
);
1595 VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff");
1597 if (!kthread_should_stop()) {
1598 stop_at
= get_seconds() + stall_cpu
;
1599 /* RCU CPU stall is expected behavior in following code. */
1600 printk(KERN_ALERT
"rcu_torture_stall start.\n");
1603 while (ULONG_CMP_LT(get_seconds(), stop_at
))
1604 continue; /* Induce RCU CPU stall warning. */
1607 printk(KERN_ALERT
"rcu_torture_stall end.\n");
1609 rcutorture_shutdown_absorb("rcu_torture_stall");
1610 while (!kthread_should_stop())
1611 schedule_timeout_interruptible(10 * HZ
);
1615 /* Spawn CPU-stall kthread, if stall_cpu specified. */
1616 static int __init
rcu_torture_stall_init(void)
1622 stall_task
= kthread_run(rcu_torture_stall
, NULL
, "rcu_torture_stall");
1623 if (IS_ERR(stall_task
)) {
1624 ret
= PTR_ERR(stall_task
);
1631 /* Clean up after the CPU-stall kthread, if one was spawned. */
1632 static void rcu_torture_stall_cleanup(void)
1634 if (stall_task
== NULL
)
1636 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task.");
1637 kthread_stop(stall_task
);
1641 /* Callback function for RCU barrier testing. */
1642 void rcu_torture_barrier_cbf(struct rcu_head
*rcu
)
1644 atomic_inc(&barrier_cbs_invoked
);
1647 /* kthread function to register callbacks used to test RCU barriers. */
1648 static int rcu_torture_barrier_cbs(void *arg
)
1650 long myid
= (long)arg
;
1652 struct rcu_head rcu
;
1654 init_rcu_head_on_stack(&rcu
);
1655 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
1656 set_user_nice(current
, 19);
1658 wait_event(barrier_cbs_wq
[myid
],
1659 barrier_phase
!= lastphase
||
1660 kthread_should_stop() ||
1661 fullstop
!= FULLSTOP_DONTSTOP
);
1662 lastphase
= barrier_phase
;
1663 smp_mb(); /* ensure barrier_phase load before ->call(). */
1664 if (kthread_should_stop() || fullstop
!= FULLSTOP_DONTSTOP
)
1666 cur_ops
->call(&rcu
, rcu_torture_barrier_cbf
);
1667 if (atomic_dec_and_test(&barrier_cbs_count
))
1668 wake_up(&barrier_wq
);
1669 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
1670 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task stopping");
1671 rcutorture_shutdown_absorb("rcu_torture_barrier_cbs");
1672 while (!kthread_should_stop())
1673 schedule_timeout_interruptible(1);
1674 cur_ops
->cb_barrier();
1675 destroy_rcu_head_on_stack(&rcu
);
1679 /* kthread function to drive and coordinate RCU barrier testing. */
1680 static int rcu_torture_barrier(void *arg
)
1684 VERBOSE_PRINTK_STRING("rcu_torture_barrier task starting");
1686 atomic_set(&barrier_cbs_invoked
, 0);
1687 atomic_set(&barrier_cbs_count
, n_barrier_cbs
);
1688 smp_mb(); /* Ensure barrier_phase after prior assignments. */
1689 barrier_phase
= !barrier_phase
;
1690 for (i
= 0; i
< n_barrier_cbs
; i
++)
1691 wake_up(&barrier_cbs_wq
[i
]);
1692 wait_event(barrier_wq
,
1693 atomic_read(&barrier_cbs_count
) == 0 ||
1694 kthread_should_stop() ||
1695 fullstop
!= FULLSTOP_DONTSTOP
);
1696 if (kthread_should_stop() || fullstop
!= FULLSTOP_DONTSTOP
)
1698 n_barrier_attempts
++;
1699 cur_ops
->cb_barrier();
1700 if (atomic_read(&barrier_cbs_invoked
) != n_barrier_cbs
) {
1701 n_rcu_torture_barrier_error
++;
1704 n_barrier_successes
++;
1705 schedule_timeout_interruptible(HZ
/ 10);
1706 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
1707 VERBOSE_PRINTK_STRING("rcu_torture_barrier task stopping");
1708 rcutorture_shutdown_absorb("rcu_torture_barrier");
1709 while (!kthread_should_stop())
1710 schedule_timeout_interruptible(1);
1714 /* Initialize RCU barrier testing. */
1715 static int rcu_torture_barrier_init(void)
1720 if (n_barrier_cbs
== 0)
1722 if (cur_ops
->call
== NULL
|| cur_ops
->cb_barrier
== NULL
) {
1723 printk(KERN_ALERT
"%s" TORTURE_FLAG
1724 " Call or barrier ops missing for %s,\n",
1725 torture_type
, cur_ops
->name
);
1726 printk(KERN_ALERT
"%s" TORTURE_FLAG
1727 " RCU barrier testing omitted from run.\n",
1731 atomic_set(&barrier_cbs_count
, 0);
1732 atomic_set(&barrier_cbs_invoked
, 0);
1734 kzalloc(n_barrier_cbs
* sizeof(barrier_cbs_tasks
[0]),
1737 kzalloc(n_barrier_cbs
* sizeof(barrier_cbs_wq
[0]),
1739 if (barrier_cbs_tasks
== NULL
|| barrier_cbs_wq
== 0)
1741 for (i
= 0; i
< n_barrier_cbs
; i
++) {
1742 init_waitqueue_head(&barrier_cbs_wq
[i
]);
1743 barrier_cbs_tasks
[i
] = kthread_run(rcu_torture_barrier_cbs
,
1745 "rcu_torture_barrier_cbs");
1746 if (IS_ERR(barrier_cbs_tasks
[i
])) {
1747 ret
= PTR_ERR(barrier_cbs_tasks
[i
]);
1748 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier_cbs");
1749 barrier_cbs_tasks
[i
] = NULL
;
1753 barrier_task
= kthread_run(rcu_torture_barrier
, NULL
,
1754 "rcu_torture_barrier");
1755 if (IS_ERR(barrier_task
)) {
1756 ret
= PTR_ERR(barrier_task
);
1757 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier");
1758 barrier_task
= NULL
;
1763 /* Clean up after RCU barrier testing. */
1764 static void rcu_torture_barrier_cleanup(void)
1768 if (barrier_task
!= NULL
) {
1769 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier task");
1770 kthread_stop(barrier_task
);
1771 barrier_task
= NULL
;
1773 if (barrier_cbs_tasks
!= NULL
) {
1774 for (i
= 0; i
< n_barrier_cbs
; i
++) {
1775 if (barrier_cbs_tasks
[i
] != NULL
) {
1776 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier_cbs task");
1777 kthread_stop(barrier_cbs_tasks
[i
]);
1778 barrier_cbs_tasks
[i
] = NULL
;
1781 kfree(barrier_cbs_tasks
);
1782 barrier_cbs_tasks
= NULL
;
1784 if (barrier_cbs_wq
!= NULL
) {
1785 kfree(barrier_cbs_wq
);
1786 barrier_cbs_wq
= NULL
;
1790 static int rcutorture_cpu_notify(struct notifier_block
*self
,
1791 unsigned long action
, void *hcpu
)
1793 long cpu
= (long)hcpu
;
1797 case CPU_DOWN_FAILED
:
1798 (void)rcutorture_booster_init(cpu
);
1800 case CPU_DOWN_PREPARE
:
1801 rcutorture_booster_cleanup(cpu
);
1809 static struct notifier_block rcutorture_cpu_nb
= {
1810 .notifier_call
= rcutorture_cpu_notify
,
1814 rcu_torture_cleanup(void)
1818 mutex_lock(&fullstop_mutex
);
1819 rcutorture_record_test_transition();
1820 if (fullstop
== FULLSTOP_SHUTDOWN
) {
1821 printk(KERN_WARNING
/* but going down anyway, so... */
1822 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
1823 mutex_unlock(&fullstop_mutex
);
1824 schedule_timeout_uninterruptible(10);
1825 if (cur_ops
->cb_barrier
!= NULL
)
1826 cur_ops
->cb_barrier();
1829 fullstop
= FULLSTOP_RMMOD
;
1830 mutex_unlock(&fullstop_mutex
);
1831 unregister_reboot_notifier(&rcutorture_shutdown_nb
);
1832 rcu_torture_barrier_cleanup();
1833 rcu_torture_stall_cleanup();
1835 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1836 kthread_stop(stutter_task
);
1838 stutter_task
= NULL
;
1839 if (shuffler_task
) {
1840 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1841 kthread_stop(shuffler_task
);
1842 free_cpumask_var(shuffle_tmp_mask
);
1844 shuffler_task
= NULL
;
1847 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1848 kthread_stop(writer_task
);
1853 for (i
= 0; i
< nrealreaders
; i
++) {
1854 if (reader_tasks
[i
]) {
1855 VERBOSE_PRINTK_STRING(
1856 "Stopping rcu_torture_reader task");
1857 kthread_stop(reader_tasks
[i
]);
1859 reader_tasks
[i
] = NULL
;
1861 kfree(reader_tasks
);
1862 reader_tasks
= NULL
;
1864 rcu_torture_current
= NULL
;
1866 if (fakewriter_tasks
) {
1867 for (i
= 0; i
< nfakewriters
; i
++) {
1868 if (fakewriter_tasks
[i
]) {
1869 VERBOSE_PRINTK_STRING(
1870 "Stopping rcu_torture_fakewriter task");
1871 kthread_stop(fakewriter_tasks
[i
]);
1873 fakewriter_tasks
[i
] = NULL
;
1875 kfree(fakewriter_tasks
);
1876 fakewriter_tasks
= NULL
;
1880 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1881 kthread_stop(stats_task
);
1886 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1887 kthread_stop(fqs_task
);
1890 if ((test_boost
== 1 && cur_ops
->can_boost
) ||
1892 unregister_cpu_notifier(&rcutorture_cpu_nb
);
1893 for_each_possible_cpu(i
)
1894 rcutorture_booster_cleanup(i
);
1896 if (shutdown_task
!= NULL
) {
1897 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1898 kthread_stop(shutdown_task
);
1900 shutdown_task
= NULL
;
1901 rcu_torture_onoff_cleanup();
1903 /* Wait for all RCU callbacks to fire. */
1905 if (cur_ops
->cb_barrier
!= NULL
)
1906 cur_ops
->cb_barrier();
1908 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
1910 if (cur_ops
->cleanup
)
1912 if (atomic_read(&n_rcu_torture_error
) || n_rcu_torture_barrier_error
)
1913 rcu_torture_print_module_parms(cur_ops
, "End of test: FAILURE");
1914 else if (n_online_successes
!= n_online_attempts
||
1915 n_offline_successes
!= n_offline_attempts
)
1916 rcu_torture_print_module_parms(cur_ops
,
1917 "End of test: RCU_HOTPLUG");
1919 rcu_torture_print_module_parms(cur_ops
, "End of test: SUCCESS");
1923 rcu_torture_init(void)
1929 static struct rcu_torture_ops
*torture_ops
[] =
1930 { &rcu_ops
, &rcu_sync_ops
, &rcu_expedited_ops
,
1931 &rcu_bh_ops
, &rcu_bh_sync_ops
, &rcu_bh_expedited_ops
,
1932 &srcu_ops
, &srcu_sync_ops
, &srcu_expedited_ops
,
1933 &srcu_raw_ops
, &srcu_raw_sync_ops
,
1934 &sched_ops
, &sched_sync_ops
, &sched_expedited_ops
, };
1936 mutex_lock(&fullstop_mutex
);
1938 /* Process args and tell the world that the torturer is on the job. */
1939 for (i
= 0; i
< ARRAY_SIZE(torture_ops
); i
++) {
1940 cur_ops
= torture_ops
[i
];
1941 if (strcmp(torture_type
, cur_ops
->name
) == 0)
1944 if (i
== ARRAY_SIZE(torture_ops
)) {
1945 printk(KERN_ALERT
"rcu-torture: invalid torture type: \"%s\"\n",
1947 printk(KERN_ALERT
"rcu-torture types:");
1948 for (i
= 0; i
< ARRAY_SIZE(torture_ops
); i
++)
1949 printk(KERN_ALERT
" %s", torture_ops
[i
]->name
);
1950 printk(KERN_ALERT
"\n");
1951 mutex_unlock(&fullstop_mutex
);
1954 if (cur_ops
->fqs
== NULL
&& fqs_duration
!= 0) {
1955 printk(KERN_ALERT
"rcu-torture: ->fqs NULL and non-zero "
1956 "fqs_duration, fqs disabled.\n");
1960 cur_ops
->init(); /* no "goto unwind" prior to this point!!! */
1963 nrealreaders
= nreaders
;
1965 nrealreaders
= 2 * num_online_cpus();
1966 rcu_torture_print_module_parms(cur_ops
, "Start of test");
1967 fullstop
= FULLSTOP_DONTSTOP
;
1969 /* Set up the freelist. */
1971 INIT_LIST_HEAD(&rcu_torture_freelist
);
1972 for (i
= 0; i
< ARRAY_SIZE(rcu_tortures
); i
++) {
1973 rcu_tortures
[i
].rtort_mbtest
= 0;
1974 list_add_tail(&rcu_tortures
[i
].rtort_free
,
1975 &rcu_torture_freelist
);
1978 /* Initialize the statistics so that each run gets its own numbers. */
1980 rcu_torture_current
= NULL
;
1981 rcu_torture_current_version
= 0;
1982 atomic_set(&n_rcu_torture_alloc
, 0);
1983 atomic_set(&n_rcu_torture_alloc_fail
, 0);
1984 atomic_set(&n_rcu_torture_free
, 0);
1985 atomic_set(&n_rcu_torture_mberror
, 0);
1986 atomic_set(&n_rcu_torture_error
, 0);
1987 n_rcu_torture_barrier_error
= 0;
1988 n_rcu_torture_boost_ktrerror
= 0;
1989 n_rcu_torture_boost_rterror
= 0;
1990 n_rcu_torture_boost_failure
= 0;
1991 n_rcu_torture_boosts
= 0;
1992 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
1993 atomic_set(&rcu_torture_wcount
[i
], 0);
1994 for_each_possible_cpu(cpu
) {
1995 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
1996 per_cpu(rcu_torture_count
, cpu
)[i
] = 0;
1997 per_cpu(rcu_torture_batch
, cpu
)[i
] = 0;
2001 /* Start up the kthreads. */
2003 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
2004 writer_task
= kthread_run(rcu_torture_writer
, NULL
,
2005 "rcu_torture_writer");
2006 if (IS_ERR(writer_task
)) {
2007 firsterr
= PTR_ERR(writer_task
);
2008 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
2012 fakewriter_tasks
= kzalloc(nfakewriters
* sizeof(fakewriter_tasks
[0]),
2014 if (fakewriter_tasks
== NULL
) {
2015 VERBOSE_PRINTK_ERRSTRING("out of memory");
2019 for (i
= 0; i
< nfakewriters
; i
++) {
2020 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
2021 fakewriter_tasks
[i
] = kthread_run(rcu_torture_fakewriter
, NULL
,
2022 "rcu_torture_fakewriter");
2023 if (IS_ERR(fakewriter_tasks
[i
])) {
2024 firsterr
= PTR_ERR(fakewriter_tasks
[i
]);
2025 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
2026 fakewriter_tasks
[i
] = NULL
;
2030 reader_tasks
= kzalloc(nrealreaders
* sizeof(reader_tasks
[0]),
2032 if (reader_tasks
== NULL
) {
2033 VERBOSE_PRINTK_ERRSTRING("out of memory");
2037 for (i
= 0; i
< nrealreaders
; i
++) {
2038 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
2039 reader_tasks
[i
] = kthread_run(rcu_torture_reader
, NULL
,
2040 "rcu_torture_reader");
2041 if (IS_ERR(reader_tasks
[i
])) {
2042 firsterr
= PTR_ERR(reader_tasks
[i
]);
2043 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
2044 reader_tasks
[i
] = NULL
;
2048 if (stat_interval
> 0) {
2049 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
2050 stats_task
= kthread_run(rcu_torture_stats
, NULL
,
2051 "rcu_torture_stats");
2052 if (IS_ERR(stats_task
)) {
2053 firsterr
= PTR_ERR(stats_task
);
2054 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
2059 if (test_no_idle_hz
) {
2060 rcu_idle_cpu
= num_online_cpus() - 1;
2062 if (!alloc_cpumask_var(&shuffle_tmp_mask
, GFP_KERNEL
)) {
2064 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
2068 /* Create the shuffler thread */
2069 shuffler_task
= kthread_run(rcu_torture_shuffle
, NULL
,
2070 "rcu_torture_shuffle");
2071 if (IS_ERR(shuffler_task
)) {
2072 free_cpumask_var(shuffle_tmp_mask
);
2073 firsterr
= PTR_ERR(shuffler_task
);
2074 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
2075 shuffler_task
= NULL
;
2082 /* Create the stutter thread */
2083 stutter_task
= kthread_run(rcu_torture_stutter
, NULL
,
2084 "rcu_torture_stutter");
2085 if (IS_ERR(stutter_task
)) {
2086 firsterr
= PTR_ERR(stutter_task
);
2087 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
2088 stutter_task
= NULL
;
2092 if (fqs_duration
< 0)
2095 /* Create the stutter thread */
2096 fqs_task
= kthread_run(rcu_torture_fqs
, NULL
,
2098 if (IS_ERR(fqs_task
)) {
2099 firsterr
= PTR_ERR(fqs_task
);
2100 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
2105 if (test_boost_interval
< 1)
2106 test_boost_interval
= 1;
2107 if (test_boost_duration
< 2)
2108 test_boost_duration
= 2;
2109 if ((test_boost
== 1 && cur_ops
->can_boost
) ||
2112 boost_starttime
= jiffies
+ test_boost_interval
* HZ
;
2113 register_cpu_notifier(&rcutorture_cpu_nb
);
2114 for_each_possible_cpu(i
) {
2115 if (cpu_is_offline(i
))
2116 continue; /* Heuristic: CPU can go offline. */
2117 retval
= rcutorture_booster_init(i
);
2124 if (shutdown_secs
> 0) {
2125 shutdown_time
= jiffies
+ shutdown_secs
* HZ
;
2126 shutdown_task
= kthread_run(rcu_torture_shutdown
, NULL
,
2127 "rcu_torture_shutdown");
2128 if (IS_ERR(shutdown_task
)) {
2129 firsterr
= PTR_ERR(shutdown_task
);
2130 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
2131 shutdown_task
= NULL
;
2135 i
= rcu_torture_onoff_init();
2140 register_reboot_notifier(&rcutorture_shutdown_nb
);
2141 i
= rcu_torture_stall_init();
2146 retval
= rcu_torture_barrier_init();
2151 rcutorture_record_test_transition();
2152 mutex_unlock(&fullstop_mutex
);
2156 mutex_unlock(&fullstop_mutex
);
2157 rcu_torture_cleanup();
2161 module_init(rcu_torture_init
);
2162 module_exit(rcu_torture_cleanup
);