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 int verbose
; /* Print more debug info. */
60 static int 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 shutdown_secs
; /* Shutdown time (s). <=0 for no shutdown. */
68 static int test_boost
= 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */
69 static int test_boost_interval
= 7; /* Interval between boost tests, seconds. */
70 static int test_boost_duration
= 4; /* Duration of each boost test, seconds. */
71 static char *torture_type
= "rcu"; /* What RCU implementation to torture. */
73 module_param(nreaders
, int, 0444);
74 MODULE_PARM_DESC(nreaders
, "Number of RCU reader threads");
75 module_param(nfakewriters
, int, 0444);
76 MODULE_PARM_DESC(nfakewriters
, "Number of RCU fake writer threads");
77 module_param(stat_interval
, int, 0644);
78 MODULE_PARM_DESC(stat_interval
, "Number of seconds between stats printk()s");
79 module_param(verbose
, bool, 0444);
80 MODULE_PARM_DESC(verbose
, "Enable verbose debugging printk()s");
81 module_param(test_no_idle_hz
, bool, 0444);
82 MODULE_PARM_DESC(test_no_idle_hz
, "Test support for tickless idle CPUs");
83 module_param(shuffle_interval
, int, 0444);
84 MODULE_PARM_DESC(shuffle_interval
, "Number of seconds between shuffles");
85 module_param(stutter
, int, 0444);
86 MODULE_PARM_DESC(stutter
, "Number of seconds to run/halt test");
87 module_param(irqreader
, int, 0444);
88 MODULE_PARM_DESC(irqreader
, "Allow RCU readers from irq handlers");
89 module_param(fqs_duration
, int, 0444);
90 MODULE_PARM_DESC(fqs_duration
, "Duration of fqs bursts (us)");
91 module_param(fqs_holdoff
, int, 0444);
92 MODULE_PARM_DESC(fqs_holdoff
, "Holdoff time within fqs bursts (us)");
93 module_param(fqs_stutter
, int, 0444);
94 MODULE_PARM_DESC(fqs_stutter
, "Wait time between fqs bursts (s)");
95 module_param(shutdown_secs
, int, 0444);
96 MODULE_PARM_DESC(shutdown_secs
, "Shutdown time (s), zero to disable.");
97 module_param(test_boost
, int, 0444);
98 MODULE_PARM_DESC(test_boost
, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
99 module_param(test_boost_interval
, int, 0444);
100 MODULE_PARM_DESC(test_boost_interval
, "Interval between boost tests, seconds.");
101 module_param(test_boost_duration
, int, 0444);
102 MODULE_PARM_DESC(test_boost_duration
, "Duration of each boost test, seconds.");
103 module_param(torture_type
, charp
, 0444);
104 MODULE_PARM_DESC(torture_type
, "Type of RCU to torture (rcu, rcu_bh, srcu)");
106 #define TORTURE_FLAG "-torture:"
107 #define PRINTK_STRING(s) \
108 do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
109 #define VERBOSE_PRINTK_STRING(s) \
110 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
111 #define VERBOSE_PRINTK_ERRSTRING(s) \
112 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
114 static char printk_buf
[4096];
116 static int nrealreaders
;
117 static struct task_struct
*writer_task
;
118 static struct task_struct
**fakewriter_tasks
;
119 static struct task_struct
**reader_tasks
;
120 static struct task_struct
*stats_task
;
121 static struct task_struct
*shuffler_task
;
122 static struct task_struct
*stutter_task
;
123 static struct task_struct
*fqs_task
;
124 static struct task_struct
*boost_tasks
[NR_CPUS
];
125 static struct task_struct
*shutdown_task
;
127 #define RCU_TORTURE_PIPE_LEN 10
130 struct rcu_head rtort_rcu
;
131 int rtort_pipe_count
;
132 struct list_head rtort_free
;
136 static LIST_HEAD(rcu_torture_freelist
);
137 static struct rcu_torture __rcu
*rcu_torture_current
;
138 static unsigned long rcu_torture_current_version
;
139 static struct rcu_torture rcu_tortures
[10 * RCU_TORTURE_PIPE_LEN
];
140 static DEFINE_SPINLOCK(rcu_torture_lock
);
141 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN
+ 1], rcu_torture_count
) =
143 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN
+ 1], rcu_torture_batch
) =
145 static atomic_t rcu_torture_wcount
[RCU_TORTURE_PIPE_LEN
+ 1];
146 static atomic_t n_rcu_torture_alloc
;
147 static atomic_t n_rcu_torture_alloc_fail
;
148 static atomic_t n_rcu_torture_free
;
149 static atomic_t n_rcu_torture_mberror
;
150 static atomic_t n_rcu_torture_error
;
151 static long n_rcu_torture_boost_ktrerror
;
152 static long n_rcu_torture_boost_rterror
;
153 static long n_rcu_torture_boost_failure
;
154 static long n_rcu_torture_boosts
;
155 static long n_rcu_torture_timers
;
156 static struct list_head rcu_torture_removed
;
157 static cpumask_var_t shuffle_tmp_mask
;
159 static int stutter_pause_test
;
161 #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
162 #define RCUTORTURE_RUNNABLE_INIT 1
164 #define RCUTORTURE_RUNNABLE_INIT 0
166 int rcutorture_runnable
= RCUTORTURE_RUNNABLE_INIT
;
167 module_param(rcutorture_runnable
, int, 0444);
168 MODULE_PARM_DESC(rcutorture_runnable
, "Start rcutorture at boot");
170 #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
171 #define rcu_can_boost() 1
172 #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
173 #define rcu_can_boost() 0
174 #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
176 static unsigned long shutdown_time
; /* jiffies to system shutdown. */
177 static unsigned long boost_starttime
; /* jiffies of next boost test start. */
178 DEFINE_MUTEX(boost_mutex
); /* protect setting boost_starttime */
179 /* and boost task create/destroy. */
181 /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
183 #define FULLSTOP_DONTSTOP 0 /* Normal operation. */
184 #define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
185 #define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
186 static int fullstop
= FULLSTOP_RMMOD
;
188 * Protect fullstop transitions and spawning of kthreads.
190 static DEFINE_MUTEX(fullstop_mutex
);
192 /* Forward reference. */
193 static void rcu_torture_cleanup(void);
196 * Detect and respond to a system shutdown.
199 rcutorture_shutdown_notify(struct notifier_block
*unused1
,
200 unsigned long unused2
, void *unused3
)
202 mutex_lock(&fullstop_mutex
);
203 if (fullstop
== FULLSTOP_DONTSTOP
)
204 fullstop
= FULLSTOP_SHUTDOWN
;
206 printk(KERN_WARNING
/* but going down anyway, so... */
207 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
208 mutex_unlock(&fullstop_mutex
);
213 * Absorb kthreads into a kernel function that won't return, so that
214 * they won't ever access module text or data again.
216 static void rcutorture_shutdown_absorb(char *title
)
218 if (ACCESS_ONCE(fullstop
) == FULLSTOP_SHUTDOWN
) {
220 "rcutorture thread %s parking due to system shutdown\n",
222 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT
);
227 * Allocate an element from the rcu_tortures pool.
229 static struct rcu_torture
*
230 rcu_torture_alloc(void)
234 spin_lock_bh(&rcu_torture_lock
);
235 if (list_empty(&rcu_torture_freelist
)) {
236 atomic_inc(&n_rcu_torture_alloc_fail
);
237 spin_unlock_bh(&rcu_torture_lock
);
240 atomic_inc(&n_rcu_torture_alloc
);
241 p
= rcu_torture_freelist
.next
;
243 spin_unlock_bh(&rcu_torture_lock
);
244 return container_of(p
, struct rcu_torture
, rtort_free
);
248 * Free an element to the rcu_tortures pool.
251 rcu_torture_free(struct rcu_torture
*p
)
253 atomic_inc(&n_rcu_torture_free
);
254 spin_lock_bh(&rcu_torture_lock
);
255 list_add_tail(&p
->rtort_free
, &rcu_torture_freelist
);
256 spin_unlock_bh(&rcu_torture_lock
);
259 struct rcu_random_state
{
260 unsigned long rrs_state
;
264 #define RCU_RANDOM_MULT 39916801 /* prime */
265 #define RCU_RANDOM_ADD 479001701 /* prime */
266 #define RCU_RANDOM_REFRESH 10000
268 #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
271 * Crude but fast random-number generator. Uses a linear congruential
272 * generator, with occasional help from cpu_clock().
275 rcu_random(struct rcu_random_state
*rrsp
)
277 if (--rrsp
->rrs_count
< 0) {
278 rrsp
->rrs_state
+= (unsigned long)local_clock();
279 rrsp
->rrs_count
= RCU_RANDOM_REFRESH
;
281 rrsp
->rrs_state
= rrsp
->rrs_state
* RCU_RANDOM_MULT
+ RCU_RANDOM_ADD
;
282 return swahw32(rrsp
->rrs_state
);
286 rcu_stutter_wait(char *title
)
288 while (stutter_pause_test
|| !rcutorture_runnable
) {
289 if (rcutorture_runnable
)
290 schedule_timeout_interruptible(1);
292 schedule_timeout_interruptible(round_jiffies_relative(HZ
));
293 rcutorture_shutdown_absorb(title
);
298 * Operations vector for selecting different types of tests.
301 struct rcu_torture_ops
{
303 void (*cleanup
)(void);
304 int (*readlock
)(void);
305 void (*read_delay
)(struct rcu_random_state
*rrsp
);
306 void (*readunlock
)(int idx
);
307 int (*completed
)(void);
308 void (*deferred_free
)(struct rcu_torture
*p
);
310 void (*cb_barrier
)(void);
312 int (*stats
)(char *page
);
318 static struct rcu_torture_ops
*cur_ops
;
321 * Definitions for rcu torture testing.
324 static int rcu_torture_read_lock(void) __acquires(RCU
)
330 static void rcu_read_delay(struct rcu_random_state
*rrsp
)
332 const unsigned long shortdelay_us
= 200;
333 const unsigned long longdelay_ms
= 50;
335 /* We want a short delay sometimes to make a reader delay the grace
336 * period, and we want a long delay occasionally to trigger
337 * force_quiescent_state. */
339 if (!(rcu_random(rrsp
) % (nrealreaders
* 2000 * longdelay_ms
)))
340 mdelay(longdelay_ms
);
341 if (!(rcu_random(rrsp
) % (nrealreaders
* 2 * shortdelay_us
)))
342 udelay(shortdelay_us
);
343 #ifdef CONFIG_PREEMPT
344 if (!preempt_count() && !(rcu_random(rrsp
) % (nrealreaders
* 20000)))
345 preempt_schedule(); /* No QS if preempt_disable() in effect */
349 static void rcu_torture_read_unlock(int idx
) __releases(RCU
)
354 static int rcu_torture_completed(void)
356 return rcu_batches_completed();
360 rcu_torture_cb(struct rcu_head
*p
)
363 struct rcu_torture
*rp
= container_of(p
, struct rcu_torture
, rtort_rcu
);
365 if (fullstop
!= FULLSTOP_DONTSTOP
) {
366 /* Test is ending, just drop callbacks on the floor. */
367 /* The next initialization will pick up the pieces. */
370 i
= rp
->rtort_pipe_count
;
371 if (i
> RCU_TORTURE_PIPE_LEN
)
372 i
= RCU_TORTURE_PIPE_LEN
;
373 atomic_inc(&rcu_torture_wcount
[i
]);
374 if (++rp
->rtort_pipe_count
>= RCU_TORTURE_PIPE_LEN
) {
375 rp
->rtort_mbtest
= 0;
376 rcu_torture_free(rp
);
378 cur_ops
->deferred_free(rp
);
381 static int rcu_no_completed(void)
386 static void rcu_torture_deferred_free(struct rcu_torture
*p
)
388 call_rcu(&p
->rtort_rcu
, rcu_torture_cb
);
391 static struct rcu_torture_ops rcu_ops
= {
394 .readlock
= rcu_torture_read_lock
,
395 .read_delay
= rcu_read_delay
,
396 .readunlock
= rcu_torture_read_unlock
,
397 .completed
= rcu_torture_completed
,
398 .deferred_free
= rcu_torture_deferred_free
,
399 .sync
= synchronize_rcu
,
400 .cb_barrier
= rcu_barrier
,
401 .fqs
= rcu_force_quiescent_state
,
404 .can_boost
= rcu_can_boost(),
408 static void rcu_sync_torture_deferred_free(struct rcu_torture
*p
)
411 struct rcu_torture
*rp
;
412 struct rcu_torture
*rp1
;
415 list_add(&p
->rtort_free
, &rcu_torture_removed
);
416 list_for_each_entry_safe(rp
, rp1
, &rcu_torture_removed
, rtort_free
) {
417 i
= rp
->rtort_pipe_count
;
418 if (i
> RCU_TORTURE_PIPE_LEN
)
419 i
= RCU_TORTURE_PIPE_LEN
;
420 atomic_inc(&rcu_torture_wcount
[i
]);
421 if (++rp
->rtort_pipe_count
>= RCU_TORTURE_PIPE_LEN
) {
422 rp
->rtort_mbtest
= 0;
423 list_del(&rp
->rtort_free
);
424 rcu_torture_free(rp
);
429 static void rcu_sync_torture_init(void)
431 INIT_LIST_HEAD(&rcu_torture_removed
);
434 static struct rcu_torture_ops rcu_sync_ops
= {
435 .init
= rcu_sync_torture_init
,
437 .readlock
= rcu_torture_read_lock
,
438 .read_delay
= rcu_read_delay
,
439 .readunlock
= rcu_torture_read_unlock
,
440 .completed
= rcu_torture_completed
,
441 .deferred_free
= rcu_sync_torture_deferred_free
,
442 .sync
= synchronize_rcu
,
444 .fqs
= rcu_force_quiescent_state
,
447 .can_boost
= rcu_can_boost(),
451 static struct rcu_torture_ops rcu_expedited_ops
= {
452 .init
= rcu_sync_torture_init
,
454 .readlock
= rcu_torture_read_lock
,
455 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
456 .readunlock
= rcu_torture_read_unlock
,
457 .completed
= rcu_no_completed
,
458 .deferred_free
= rcu_sync_torture_deferred_free
,
459 .sync
= synchronize_rcu_expedited
,
461 .fqs
= rcu_force_quiescent_state
,
464 .can_boost
= rcu_can_boost(),
465 .name
= "rcu_expedited"
469 * Definitions for rcu_bh torture testing.
472 static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH
)
478 static void rcu_bh_torture_read_unlock(int idx
) __releases(RCU_BH
)
480 rcu_read_unlock_bh();
483 static int rcu_bh_torture_completed(void)
485 return rcu_batches_completed_bh();
488 static void rcu_bh_torture_deferred_free(struct rcu_torture
*p
)
490 call_rcu_bh(&p
->rtort_rcu
, rcu_torture_cb
);
493 static struct rcu_torture_ops rcu_bh_ops
= {
496 .readlock
= rcu_bh_torture_read_lock
,
497 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
498 .readunlock
= rcu_bh_torture_read_unlock
,
499 .completed
= rcu_bh_torture_completed
,
500 .deferred_free
= rcu_bh_torture_deferred_free
,
501 .sync
= synchronize_rcu_bh
,
502 .cb_barrier
= rcu_barrier_bh
,
503 .fqs
= rcu_bh_force_quiescent_state
,
509 static struct rcu_torture_ops rcu_bh_sync_ops
= {
510 .init
= rcu_sync_torture_init
,
512 .readlock
= rcu_bh_torture_read_lock
,
513 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
514 .readunlock
= rcu_bh_torture_read_unlock
,
515 .completed
= rcu_bh_torture_completed
,
516 .deferred_free
= rcu_sync_torture_deferred_free
,
517 .sync
= synchronize_rcu_bh
,
519 .fqs
= rcu_bh_force_quiescent_state
,
522 .name
= "rcu_bh_sync"
525 static struct rcu_torture_ops rcu_bh_expedited_ops
= {
526 .init
= rcu_sync_torture_init
,
528 .readlock
= rcu_bh_torture_read_lock
,
529 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
530 .readunlock
= rcu_bh_torture_read_unlock
,
531 .completed
= rcu_bh_torture_completed
,
532 .deferred_free
= rcu_sync_torture_deferred_free
,
533 .sync
= synchronize_rcu_bh_expedited
,
535 .fqs
= rcu_bh_force_quiescent_state
,
538 .name
= "rcu_bh_expedited"
542 * Definitions for srcu torture testing.
545 static struct srcu_struct srcu_ctl
;
547 static void srcu_torture_init(void)
549 init_srcu_struct(&srcu_ctl
);
550 rcu_sync_torture_init();
553 static void srcu_torture_cleanup(void)
555 synchronize_srcu(&srcu_ctl
);
556 cleanup_srcu_struct(&srcu_ctl
);
559 static int srcu_torture_read_lock(void) __acquires(&srcu_ctl
)
561 return srcu_read_lock(&srcu_ctl
);
564 static void srcu_read_delay(struct rcu_random_state
*rrsp
)
567 const long uspertick
= 1000000 / HZ
;
568 const long longdelay
= 10;
570 /* We want there to be long-running readers, but not all the time. */
572 delay
= rcu_random(rrsp
) % (nrealreaders
* 2 * longdelay
* uspertick
);
574 schedule_timeout_interruptible(longdelay
);
576 rcu_read_delay(rrsp
);
579 static void srcu_torture_read_unlock(int idx
) __releases(&srcu_ctl
)
581 srcu_read_unlock(&srcu_ctl
, idx
);
584 static int srcu_torture_completed(void)
586 return srcu_batches_completed(&srcu_ctl
);
589 static void srcu_torture_synchronize(void)
591 synchronize_srcu(&srcu_ctl
);
594 static int srcu_torture_stats(char *page
)
598 int idx
= srcu_ctl
.completed
& 0x1;
600 cnt
+= sprintf(&page
[cnt
], "%s%s per-CPU(idx=%d):",
601 torture_type
, TORTURE_FLAG
, idx
);
602 for_each_possible_cpu(cpu
) {
603 cnt
+= sprintf(&page
[cnt
], " %d(%d,%d)", cpu
,
604 per_cpu_ptr(srcu_ctl
.per_cpu_ref
, cpu
)->c
[!idx
],
605 per_cpu_ptr(srcu_ctl
.per_cpu_ref
, cpu
)->c
[idx
]);
607 cnt
+= sprintf(&page
[cnt
], "\n");
611 static struct rcu_torture_ops srcu_ops
= {
612 .init
= srcu_torture_init
,
613 .cleanup
= srcu_torture_cleanup
,
614 .readlock
= srcu_torture_read_lock
,
615 .read_delay
= srcu_read_delay
,
616 .readunlock
= srcu_torture_read_unlock
,
617 .completed
= srcu_torture_completed
,
618 .deferred_free
= rcu_sync_torture_deferred_free
,
619 .sync
= srcu_torture_synchronize
,
621 .stats
= srcu_torture_stats
,
625 static void srcu_torture_synchronize_expedited(void)
627 synchronize_srcu_expedited(&srcu_ctl
);
630 static struct rcu_torture_ops srcu_expedited_ops
= {
631 .init
= srcu_torture_init
,
632 .cleanup
= srcu_torture_cleanup
,
633 .readlock
= srcu_torture_read_lock
,
634 .read_delay
= srcu_read_delay
,
635 .readunlock
= srcu_torture_read_unlock
,
636 .completed
= srcu_torture_completed
,
637 .deferred_free
= rcu_sync_torture_deferred_free
,
638 .sync
= srcu_torture_synchronize_expedited
,
640 .stats
= srcu_torture_stats
,
641 .name
= "srcu_expedited"
645 * Definitions for sched torture testing.
648 static int sched_torture_read_lock(void)
654 static void sched_torture_read_unlock(int idx
)
659 static void rcu_sched_torture_deferred_free(struct rcu_torture
*p
)
661 call_rcu_sched(&p
->rtort_rcu
, rcu_torture_cb
);
664 static struct rcu_torture_ops sched_ops
= {
665 .init
= rcu_sync_torture_init
,
667 .readlock
= sched_torture_read_lock
,
668 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
669 .readunlock
= sched_torture_read_unlock
,
670 .completed
= rcu_no_completed
,
671 .deferred_free
= rcu_sched_torture_deferred_free
,
672 .sync
= synchronize_sched
,
673 .cb_barrier
= rcu_barrier_sched
,
674 .fqs
= rcu_sched_force_quiescent_state
,
680 static struct rcu_torture_ops sched_sync_ops
= {
681 .init
= rcu_sync_torture_init
,
683 .readlock
= sched_torture_read_lock
,
684 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
685 .readunlock
= sched_torture_read_unlock
,
686 .completed
= rcu_no_completed
,
687 .deferred_free
= rcu_sync_torture_deferred_free
,
688 .sync
= synchronize_sched
,
690 .fqs
= rcu_sched_force_quiescent_state
,
695 static struct rcu_torture_ops sched_expedited_ops
= {
696 .init
= rcu_sync_torture_init
,
698 .readlock
= sched_torture_read_lock
,
699 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
700 .readunlock
= sched_torture_read_unlock
,
701 .completed
= rcu_no_completed
,
702 .deferred_free
= rcu_sync_torture_deferred_free
,
703 .sync
= synchronize_sched_expedited
,
705 .fqs
= rcu_sched_force_quiescent_state
,
708 .name
= "sched_expedited"
712 * RCU torture priority-boost testing. Runs one real-time thread per
713 * CPU for moderate bursts, repeatedly registering RCU callbacks and
714 * spinning waiting for them to be invoked. If a given callback takes
715 * too long to be invoked, we assume that priority inversion has occurred.
718 struct rcu_boost_inflight
{
723 static void rcu_torture_boost_cb(struct rcu_head
*head
)
725 struct rcu_boost_inflight
*rbip
=
726 container_of(head
, struct rcu_boost_inflight
, rcu
);
728 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
732 static int rcu_torture_boost(void *arg
)
734 unsigned long call_rcu_time
;
735 unsigned long endtime
;
736 unsigned long oldstarttime
;
737 struct rcu_boost_inflight rbi
= { .inflight
= 0 };
738 struct sched_param sp
;
740 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
742 /* Set real-time priority. */
743 sp
.sched_priority
= 1;
744 if (sched_setscheduler(current
, SCHED_FIFO
, &sp
) < 0) {
745 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
746 n_rcu_torture_boost_rterror
++;
749 init_rcu_head_on_stack(&rbi
.rcu
);
750 /* Each pass through the following loop does one boost-test cycle. */
752 /* Wait for the next test interval. */
753 oldstarttime
= boost_starttime
;
754 while (ULONG_CMP_LT(jiffies
, oldstarttime
)) {
755 schedule_timeout_uninterruptible(1);
756 rcu_stutter_wait("rcu_torture_boost");
757 if (kthread_should_stop() ||
758 fullstop
!= FULLSTOP_DONTSTOP
)
762 /* Do one boost-test interval. */
763 endtime
= oldstarttime
+ test_boost_duration
* HZ
;
764 call_rcu_time
= jiffies
;
765 while (ULONG_CMP_LT(jiffies
, endtime
)) {
766 /* If we don't have a callback in flight, post one. */
768 smp_mb(); /* RCU core before ->inflight = 1. */
770 call_rcu(&rbi
.rcu
, rcu_torture_boost_cb
);
771 if (jiffies
- call_rcu_time
>
772 test_boost_duration
* HZ
- HZ
/ 2) {
773 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
774 n_rcu_torture_boost_failure
++;
776 call_rcu_time
= jiffies
;
779 rcu_stutter_wait("rcu_torture_boost");
780 if (kthread_should_stop() ||
781 fullstop
!= FULLSTOP_DONTSTOP
)
786 * Set the start time of the next test interval.
787 * Yes, this is vulnerable to long delays, but such
788 * delays simply cause a false negative for the next
789 * interval. Besides, we are running at RT priority,
790 * so delays should be relatively rare.
792 while (oldstarttime
== boost_starttime
&&
793 !kthread_should_stop()) {
794 if (mutex_trylock(&boost_mutex
)) {
795 boost_starttime
= jiffies
+
796 test_boost_interval
* HZ
;
797 n_rcu_torture_boosts
++;
798 mutex_unlock(&boost_mutex
);
801 schedule_timeout_uninterruptible(1);
804 /* Go do the stutter. */
805 checkwait
: rcu_stutter_wait("rcu_torture_boost");
806 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
808 /* Clean up and exit. */
809 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
810 rcutorture_shutdown_absorb("rcu_torture_boost");
811 while (!kthread_should_stop() || rbi
.inflight
)
812 schedule_timeout_uninterruptible(1);
813 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
814 destroy_rcu_head_on_stack(&rbi
.rcu
);
819 * RCU torture force-quiescent-state kthread. Repeatedly induces
820 * bursts of calls to force_quiescent_state(), increasing the probability
821 * of occurrence of some important types of race conditions.
824 rcu_torture_fqs(void *arg
)
826 unsigned long fqs_resume_time
;
827 int fqs_burst_remaining
;
829 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
831 fqs_resume_time
= jiffies
+ fqs_stutter
* HZ
;
832 while (ULONG_CMP_LT(jiffies
, fqs_resume_time
) &&
833 !kthread_should_stop()) {
834 schedule_timeout_interruptible(1);
836 fqs_burst_remaining
= fqs_duration
;
837 while (fqs_burst_remaining
> 0 &&
838 !kthread_should_stop()) {
841 fqs_burst_remaining
-= fqs_holdoff
;
843 rcu_stutter_wait("rcu_torture_fqs");
844 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
845 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
846 rcutorture_shutdown_absorb("rcu_torture_fqs");
847 while (!kthread_should_stop())
848 schedule_timeout_uninterruptible(1);
853 * RCU torture writer kthread. Repeatedly substitutes a new structure
854 * for that pointed to by rcu_torture_current, freeing the old structure
855 * after a series of grace periods (the "pipeline").
858 rcu_torture_writer(void *arg
)
861 long oldbatch
= rcu_batches_completed();
862 struct rcu_torture
*rp
;
863 struct rcu_torture
*old_rp
;
864 static DEFINE_RCU_RANDOM(rand
);
866 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
867 set_user_nice(current
, 19);
870 schedule_timeout_uninterruptible(1);
871 rp
= rcu_torture_alloc();
874 rp
->rtort_pipe_count
= 0;
875 udelay(rcu_random(&rand
) & 0x3ff);
876 old_rp
= rcu_dereference_check(rcu_torture_current
,
877 current
== writer_task
);
878 rp
->rtort_mbtest
= 1;
879 rcu_assign_pointer(rcu_torture_current
, rp
);
880 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
882 i
= old_rp
->rtort_pipe_count
;
883 if (i
> RCU_TORTURE_PIPE_LEN
)
884 i
= RCU_TORTURE_PIPE_LEN
;
885 atomic_inc(&rcu_torture_wcount
[i
]);
886 old_rp
->rtort_pipe_count
++;
887 cur_ops
->deferred_free(old_rp
);
889 rcutorture_record_progress(++rcu_torture_current_version
);
890 oldbatch
= cur_ops
->completed();
891 rcu_stutter_wait("rcu_torture_writer");
892 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
893 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
894 rcutorture_shutdown_absorb("rcu_torture_writer");
895 while (!kthread_should_stop())
896 schedule_timeout_uninterruptible(1);
901 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
902 * delay between calls.
905 rcu_torture_fakewriter(void *arg
)
907 DEFINE_RCU_RANDOM(rand
);
909 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
910 set_user_nice(current
, 19);
913 schedule_timeout_uninterruptible(1 + rcu_random(&rand
)%10);
914 udelay(rcu_random(&rand
) & 0x3ff);
916 rcu_stutter_wait("rcu_torture_fakewriter");
917 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
919 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
920 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
921 while (!kthread_should_stop())
922 schedule_timeout_uninterruptible(1);
926 void rcutorture_trace_dump(void)
928 static atomic_t beenhere
= ATOMIC_INIT(0);
930 if (atomic_read(&beenhere
))
932 if (atomic_xchg(&beenhere
, 1) != 0)
934 do_trace_rcu_torture_read(cur_ops
->name
, (struct rcu_head
*)~0UL);
935 ftrace_dump(DUMP_ALL
);
939 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
940 * incrementing the corresponding element of the pipeline array. The
941 * counter in the element should never be greater than 1, otherwise, the
942 * RCU implementation is broken.
944 static void rcu_torture_timer(unsigned long unused
)
948 static DEFINE_RCU_RANDOM(rand
);
949 static DEFINE_SPINLOCK(rand_lock
);
950 struct rcu_torture
*p
;
953 idx
= cur_ops
->readlock();
954 completed
= cur_ops
->completed();
955 p
= rcu_dereference_check(rcu_torture_current
,
956 rcu_read_lock_bh_held() ||
957 rcu_read_lock_sched_held() ||
958 srcu_read_lock_held(&srcu_ctl
));
959 do_trace_rcu_torture_read(cur_ops
->name
, &p
->rtort_rcu
);
961 /* Leave because rcu_torture_writer is not yet underway */
962 cur_ops
->readunlock(idx
);
965 if (p
->rtort_mbtest
== 0)
966 atomic_inc(&n_rcu_torture_mberror
);
967 spin_lock(&rand_lock
);
968 cur_ops
->read_delay(&rand
);
969 n_rcu_torture_timers
++;
970 spin_unlock(&rand_lock
);
972 pipe_count
= p
->rtort_pipe_count
;
973 if (pipe_count
> RCU_TORTURE_PIPE_LEN
) {
974 /* Should not happen, but... */
975 pipe_count
= RCU_TORTURE_PIPE_LEN
;
978 rcutorture_trace_dump();
979 __this_cpu_inc(rcu_torture_count
[pipe_count
]);
980 completed
= cur_ops
->completed() - completed
;
981 if (completed
> RCU_TORTURE_PIPE_LEN
) {
982 /* Should not happen, but... */
983 completed
= RCU_TORTURE_PIPE_LEN
;
985 __this_cpu_inc(rcu_torture_batch
[completed
]);
987 cur_ops
->readunlock(idx
);
991 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
992 * incrementing the corresponding element of the pipeline array. The
993 * counter in the element should never be greater than 1, otherwise, the
994 * RCU implementation is broken.
997 rcu_torture_reader(void *arg
)
1001 DEFINE_RCU_RANDOM(rand
);
1002 struct rcu_torture
*p
;
1004 struct timer_list t
;
1006 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
1007 set_user_nice(current
, 19);
1008 if (irqreader
&& cur_ops
->irq_capable
)
1009 setup_timer_on_stack(&t
, rcu_torture_timer
, 0);
1012 if (irqreader
&& cur_ops
->irq_capable
) {
1013 if (!timer_pending(&t
))
1014 mod_timer(&t
, jiffies
+ 1);
1016 idx
= cur_ops
->readlock();
1017 completed
= cur_ops
->completed();
1018 p
= rcu_dereference_check(rcu_torture_current
,
1019 rcu_read_lock_bh_held() ||
1020 rcu_read_lock_sched_held() ||
1021 srcu_read_lock_held(&srcu_ctl
));
1022 do_trace_rcu_torture_read(cur_ops
->name
, &p
->rtort_rcu
);
1024 /* Wait for rcu_torture_writer to get underway */
1025 cur_ops
->readunlock(idx
);
1026 schedule_timeout_interruptible(HZ
);
1029 if (p
->rtort_mbtest
== 0)
1030 atomic_inc(&n_rcu_torture_mberror
);
1031 cur_ops
->read_delay(&rand
);
1033 pipe_count
= p
->rtort_pipe_count
;
1034 if (pipe_count
> RCU_TORTURE_PIPE_LEN
) {
1035 /* Should not happen, but... */
1036 pipe_count
= RCU_TORTURE_PIPE_LEN
;
1039 rcutorture_trace_dump();
1040 __this_cpu_inc(rcu_torture_count
[pipe_count
]);
1041 completed
= cur_ops
->completed() - completed
;
1042 if (completed
> RCU_TORTURE_PIPE_LEN
) {
1043 /* Should not happen, but... */
1044 completed
= RCU_TORTURE_PIPE_LEN
;
1046 __this_cpu_inc(rcu_torture_batch
[completed
]);
1048 cur_ops
->readunlock(idx
);
1050 rcu_stutter_wait("rcu_torture_reader");
1051 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
1052 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
1053 rcutorture_shutdown_absorb("rcu_torture_reader");
1054 if (irqreader
&& cur_ops
->irq_capable
)
1056 while (!kthread_should_stop())
1057 schedule_timeout_uninterruptible(1);
1062 * Create an RCU-torture statistics message in the specified buffer.
1065 rcu_torture_printk(char *page
)
1070 long pipesummary
[RCU_TORTURE_PIPE_LEN
+ 1] = { 0 };
1071 long batchsummary
[RCU_TORTURE_PIPE_LEN
+ 1] = { 0 };
1073 for_each_possible_cpu(cpu
) {
1074 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
1075 pipesummary
[i
] += per_cpu(rcu_torture_count
, cpu
)[i
];
1076 batchsummary
[i
] += per_cpu(rcu_torture_batch
, cpu
)[i
];
1079 for (i
= RCU_TORTURE_PIPE_LEN
- 1; i
>= 0; i
--) {
1080 if (pipesummary
[i
] != 0)
1083 cnt
+= sprintf(&page
[cnt
], "%s%s ", torture_type
, TORTURE_FLAG
);
1084 cnt
+= sprintf(&page
[cnt
],
1085 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d "
1086 "rtmbe: %d rtbke: %ld rtbre: %ld "
1087 "rtbf: %ld rtb: %ld nt: %ld",
1088 rcu_torture_current
,
1089 rcu_torture_current_version
,
1090 list_empty(&rcu_torture_freelist
),
1091 atomic_read(&n_rcu_torture_alloc
),
1092 atomic_read(&n_rcu_torture_alloc_fail
),
1093 atomic_read(&n_rcu_torture_free
),
1094 atomic_read(&n_rcu_torture_mberror
),
1095 n_rcu_torture_boost_ktrerror
,
1096 n_rcu_torture_boost_rterror
,
1097 n_rcu_torture_boost_failure
,
1098 n_rcu_torture_boosts
,
1099 n_rcu_torture_timers
);
1100 if (atomic_read(&n_rcu_torture_mberror
) != 0 ||
1101 n_rcu_torture_boost_ktrerror
!= 0 ||
1102 n_rcu_torture_boost_rterror
!= 0 ||
1103 n_rcu_torture_boost_failure
!= 0)
1104 cnt
+= sprintf(&page
[cnt
], " !!!");
1105 cnt
+= sprintf(&page
[cnt
], "\n%s%s ", torture_type
, TORTURE_FLAG
);
1107 cnt
+= sprintf(&page
[cnt
], "!!! ");
1108 atomic_inc(&n_rcu_torture_error
);
1111 cnt
+= sprintf(&page
[cnt
], "Reader Pipe: ");
1112 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
1113 cnt
+= sprintf(&page
[cnt
], " %ld", pipesummary
[i
]);
1114 cnt
+= sprintf(&page
[cnt
], "\n%s%s ", torture_type
, TORTURE_FLAG
);
1115 cnt
+= sprintf(&page
[cnt
], "Reader Batch: ");
1116 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
1117 cnt
+= sprintf(&page
[cnt
], " %ld", batchsummary
[i
]);
1118 cnt
+= sprintf(&page
[cnt
], "\n%s%s ", torture_type
, TORTURE_FLAG
);
1119 cnt
+= sprintf(&page
[cnt
], "Free-Block Circulation: ");
1120 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
1121 cnt
+= sprintf(&page
[cnt
], " %d",
1122 atomic_read(&rcu_torture_wcount
[i
]));
1124 cnt
+= sprintf(&page
[cnt
], "\n");
1126 cnt
+= cur_ops
->stats(&page
[cnt
]);
1131 * Print torture statistics. Caller must ensure that there is only
1132 * one call to this function at a given time!!! This is normally
1133 * accomplished by relying on the module system to only have one copy
1134 * of the module loaded, and then by giving the rcu_torture_stats
1135 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1136 * thread is not running).
1139 rcu_torture_stats_print(void)
1143 cnt
= rcu_torture_printk(printk_buf
);
1144 printk(KERN_ALERT
"%s", printk_buf
);
1148 * Periodically prints torture statistics, if periodic statistics printing
1149 * was specified via the stat_interval module parameter.
1151 * No need to worry about fullstop here, since this one doesn't reference
1152 * volatile state or register callbacks.
1155 rcu_torture_stats(void *arg
)
1157 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1159 schedule_timeout_interruptible(stat_interval
* HZ
);
1160 rcu_torture_stats_print();
1161 rcutorture_shutdown_absorb("rcu_torture_stats");
1162 } while (!kthread_should_stop());
1163 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1167 static int rcu_idle_cpu
; /* Force all torture tasks off this CPU */
1169 /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1170 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1172 static void rcu_torture_shuffle_tasks(void)
1176 cpumask_setall(shuffle_tmp_mask
);
1179 /* No point in shuffling if there is only one online CPU (ex: UP) */
1180 if (num_online_cpus() == 1) {
1185 if (rcu_idle_cpu
!= -1)
1186 cpumask_clear_cpu(rcu_idle_cpu
, shuffle_tmp_mask
);
1188 set_cpus_allowed_ptr(current
, shuffle_tmp_mask
);
1191 for (i
= 0; i
< nrealreaders
; i
++)
1192 if (reader_tasks
[i
])
1193 set_cpus_allowed_ptr(reader_tasks
[i
],
1197 if (fakewriter_tasks
) {
1198 for (i
= 0; i
< nfakewriters
; i
++)
1199 if (fakewriter_tasks
[i
])
1200 set_cpus_allowed_ptr(fakewriter_tasks
[i
],
1205 set_cpus_allowed_ptr(writer_task
, shuffle_tmp_mask
);
1208 set_cpus_allowed_ptr(stats_task
, shuffle_tmp_mask
);
1210 if (rcu_idle_cpu
== -1)
1211 rcu_idle_cpu
= num_online_cpus() - 1;
1218 /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1219 * system to become idle at a time and cut off its timer ticks. This is meant
1220 * to test the support for such tickless idle CPU in RCU.
1223 rcu_torture_shuffle(void *arg
)
1225 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1227 schedule_timeout_interruptible(shuffle_interval
* HZ
);
1228 rcu_torture_shuffle_tasks();
1229 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1230 } while (!kthread_should_stop());
1231 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1235 /* Cause the rcutorture test to "stutter", starting and stopping all
1236 * threads periodically.
1239 rcu_torture_stutter(void *arg
)
1241 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1243 schedule_timeout_interruptible(stutter
* HZ
);
1244 stutter_pause_test
= 1;
1245 if (!kthread_should_stop())
1246 schedule_timeout_interruptible(stutter
* HZ
);
1247 stutter_pause_test
= 0;
1248 rcutorture_shutdown_absorb("rcu_torture_stutter");
1249 } while (!kthread_should_stop());
1250 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1255 rcu_torture_print_module_parms(struct rcu_torture_ops
*cur_ops
, char *tag
)
1257 printk(KERN_ALERT
"%s" TORTURE_FLAG
1258 "--- %s: nreaders=%d nfakewriters=%d "
1259 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1260 "shuffle_interval=%d stutter=%d irqreader=%d "
1261 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1262 "test_boost=%d/%d test_boost_interval=%d "
1263 "test_boost_duration=%d shutdown_secs=%d\n",
1264 torture_type
, tag
, nrealreaders
, nfakewriters
,
1265 stat_interval
, verbose
, test_no_idle_hz
, shuffle_interval
,
1266 stutter
, irqreader
, fqs_duration
, fqs_holdoff
, fqs_stutter
,
1267 test_boost
, cur_ops
->can_boost
,
1268 test_boost_interval
, test_boost_duration
, shutdown_secs
);
1271 static struct notifier_block rcutorture_shutdown_nb
= {
1272 .notifier_call
= rcutorture_shutdown_notify
,
1275 static void rcutorture_booster_cleanup(int cpu
)
1277 struct task_struct
*t
;
1279 if (boost_tasks
[cpu
] == NULL
)
1281 mutex_lock(&boost_mutex
);
1282 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1283 t
= boost_tasks
[cpu
];
1284 boost_tasks
[cpu
] = NULL
;
1285 mutex_unlock(&boost_mutex
);
1287 /* This must be outside of the mutex, otherwise deadlock! */
1291 static int rcutorture_booster_init(int cpu
)
1295 if (boost_tasks
[cpu
] != NULL
)
1296 return 0; /* Already created, nothing more to do. */
1298 /* Don't allow time recalculation while creating a new task. */
1299 mutex_lock(&boost_mutex
);
1300 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
1301 boost_tasks
[cpu
] = kthread_create_on_node(rcu_torture_boost
, NULL
,
1303 "rcu_torture_boost");
1304 if (IS_ERR(boost_tasks
[cpu
])) {
1305 retval
= PTR_ERR(boost_tasks
[cpu
]);
1306 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1307 n_rcu_torture_boost_ktrerror
++;
1308 boost_tasks
[cpu
] = NULL
;
1309 mutex_unlock(&boost_mutex
);
1312 kthread_bind(boost_tasks
[cpu
], cpu
);
1313 wake_up_process(boost_tasks
[cpu
]);
1314 mutex_unlock(&boost_mutex
);
1319 * Cause the rcutorture test to shutdown the system after the test has
1320 * run for the time specified by the shutdown_secs module parameter.
1323 rcu_torture_shutdown(void *arg
)
1326 unsigned long jiffies_snap
;
1328 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1329 jiffies_snap
= ACCESS_ONCE(jiffies
);
1330 while (ULONG_CMP_LT(jiffies_snap
, shutdown_time
) &&
1331 !kthread_should_stop()) {
1332 delta
= shutdown_time
- jiffies_snap
;
1334 printk(KERN_ALERT
"%s" TORTURE_FLAG
1335 "rcu_torture_shutdown task: %lu "
1336 "jiffies remaining\n",
1337 torture_type
, delta
);
1338 schedule_timeout_interruptible(delta
);
1339 jiffies_snap
= ACCESS_ONCE(jiffies
);
1341 if (ULONG_CMP_LT(jiffies
, shutdown_time
)) {
1342 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1346 /* OK, shut down the system. */
1348 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1349 shutdown_task
= NULL
; /* Avoid self-kill deadlock. */
1350 rcu_torture_cleanup(); /* Get the success/failure message. */
1351 kernel_power_off(); /* Shut down the system. */
1355 static int rcutorture_cpu_notify(struct notifier_block
*self
,
1356 unsigned long action
, void *hcpu
)
1358 long cpu
= (long)hcpu
;
1362 case CPU_DOWN_FAILED
:
1363 (void)rcutorture_booster_init(cpu
);
1365 case CPU_DOWN_PREPARE
:
1366 rcutorture_booster_cleanup(cpu
);
1374 static struct notifier_block rcutorture_cpu_nb
= {
1375 .notifier_call
= rcutorture_cpu_notify
,
1379 rcu_torture_cleanup(void)
1383 mutex_lock(&fullstop_mutex
);
1384 rcutorture_record_test_transition();
1385 if (fullstop
== FULLSTOP_SHUTDOWN
) {
1386 printk(KERN_WARNING
/* but going down anyway, so... */
1387 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
1388 mutex_unlock(&fullstop_mutex
);
1389 schedule_timeout_uninterruptible(10);
1390 if (cur_ops
->cb_barrier
!= NULL
)
1391 cur_ops
->cb_barrier();
1394 fullstop
= FULLSTOP_RMMOD
;
1395 mutex_unlock(&fullstop_mutex
);
1396 unregister_reboot_notifier(&rcutorture_shutdown_nb
);
1398 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1399 kthread_stop(stutter_task
);
1401 stutter_task
= NULL
;
1402 if (shuffler_task
) {
1403 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1404 kthread_stop(shuffler_task
);
1405 free_cpumask_var(shuffle_tmp_mask
);
1407 shuffler_task
= NULL
;
1410 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1411 kthread_stop(writer_task
);
1416 for (i
= 0; i
< nrealreaders
; i
++) {
1417 if (reader_tasks
[i
]) {
1418 VERBOSE_PRINTK_STRING(
1419 "Stopping rcu_torture_reader task");
1420 kthread_stop(reader_tasks
[i
]);
1422 reader_tasks
[i
] = NULL
;
1424 kfree(reader_tasks
);
1425 reader_tasks
= NULL
;
1427 rcu_torture_current
= NULL
;
1429 if (fakewriter_tasks
) {
1430 for (i
= 0; i
< nfakewriters
; i
++) {
1431 if (fakewriter_tasks
[i
]) {
1432 VERBOSE_PRINTK_STRING(
1433 "Stopping rcu_torture_fakewriter task");
1434 kthread_stop(fakewriter_tasks
[i
]);
1436 fakewriter_tasks
[i
] = NULL
;
1438 kfree(fakewriter_tasks
);
1439 fakewriter_tasks
= NULL
;
1443 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1444 kthread_stop(stats_task
);
1449 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1450 kthread_stop(fqs_task
);
1453 if ((test_boost
== 1 && cur_ops
->can_boost
) ||
1455 unregister_cpu_notifier(&rcutorture_cpu_nb
);
1456 for_each_possible_cpu(i
)
1457 rcutorture_booster_cleanup(i
);
1459 if (shutdown_task
!= NULL
) {
1460 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1461 kthread_stop(shutdown_task
);
1464 /* Wait for all RCU callbacks to fire. */
1466 if (cur_ops
->cb_barrier
!= NULL
)
1467 cur_ops
->cb_barrier();
1469 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
1471 if (cur_ops
->cleanup
)
1473 if (atomic_read(&n_rcu_torture_error
))
1474 rcu_torture_print_module_parms(cur_ops
, "End of test: FAILURE");
1476 rcu_torture_print_module_parms(cur_ops
, "End of test: SUCCESS");
1480 rcu_torture_init(void)
1485 static struct rcu_torture_ops
*torture_ops
[] =
1486 { &rcu_ops
, &rcu_sync_ops
, &rcu_expedited_ops
,
1487 &rcu_bh_ops
, &rcu_bh_sync_ops
, &rcu_bh_expedited_ops
,
1488 &srcu_ops
, &srcu_expedited_ops
,
1489 &sched_ops
, &sched_sync_ops
, &sched_expedited_ops
, };
1491 mutex_lock(&fullstop_mutex
);
1493 /* Process args and tell the world that the torturer is on the job. */
1494 for (i
= 0; i
< ARRAY_SIZE(torture_ops
); i
++) {
1495 cur_ops
= torture_ops
[i
];
1496 if (strcmp(torture_type
, cur_ops
->name
) == 0)
1499 if (i
== ARRAY_SIZE(torture_ops
)) {
1500 printk(KERN_ALERT
"rcu-torture: invalid torture type: \"%s\"\n",
1502 printk(KERN_ALERT
"rcu-torture types:");
1503 for (i
= 0; i
< ARRAY_SIZE(torture_ops
); i
++)
1504 printk(KERN_ALERT
" %s", torture_ops
[i
]->name
);
1505 printk(KERN_ALERT
"\n");
1506 mutex_unlock(&fullstop_mutex
);
1509 if (cur_ops
->fqs
== NULL
&& fqs_duration
!= 0) {
1510 printk(KERN_ALERT
"rcu-torture: ->fqs NULL and non-zero "
1511 "fqs_duration, fqs disabled.\n");
1515 cur_ops
->init(); /* no "goto unwind" prior to this point!!! */
1518 nrealreaders
= nreaders
;
1520 nrealreaders
= 2 * num_online_cpus();
1521 rcu_torture_print_module_parms(cur_ops
, "Start of test");
1522 fullstop
= FULLSTOP_DONTSTOP
;
1524 /* Set up the freelist. */
1526 INIT_LIST_HEAD(&rcu_torture_freelist
);
1527 for (i
= 0; i
< ARRAY_SIZE(rcu_tortures
); i
++) {
1528 rcu_tortures
[i
].rtort_mbtest
= 0;
1529 list_add_tail(&rcu_tortures
[i
].rtort_free
,
1530 &rcu_torture_freelist
);
1533 /* Initialize the statistics so that each run gets its own numbers. */
1535 rcu_torture_current
= NULL
;
1536 rcu_torture_current_version
= 0;
1537 atomic_set(&n_rcu_torture_alloc
, 0);
1538 atomic_set(&n_rcu_torture_alloc_fail
, 0);
1539 atomic_set(&n_rcu_torture_free
, 0);
1540 atomic_set(&n_rcu_torture_mberror
, 0);
1541 atomic_set(&n_rcu_torture_error
, 0);
1542 n_rcu_torture_boost_ktrerror
= 0;
1543 n_rcu_torture_boost_rterror
= 0;
1544 n_rcu_torture_boost_failure
= 0;
1545 n_rcu_torture_boosts
= 0;
1546 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
1547 atomic_set(&rcu_torture_wcount
[i
], 0);
1548 for_each_possible_cpu(cpu
) {
1549 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
1550 per_cpu(rcu_torture_count
, cpu
)[i
] = 0;
1551 per_cpu(rcu_torture_batch
, cpu
)[i
] = 0;
1555 /* Start up the kthreads. */
1557 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1558 writer_task
= kthread_run(rcu_torture_writer
, NULL
,
1559 "rcu_torture_writer");
1560 if (IS_ERR(writer_task
)) {
1561 firsterr
= PTR_ERR(writer_task
);
1562 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1566 fakewriter_tasks
= kzalloc(nfakewriters
* sizeof(fakewriter_tasks
[0]),
1568 if (fakewriter_tasks
== NULL
) {
1569 VERBOSE_PRINTK_ERRSTRING("out of memory");
1573 for (i
= 0; i
< nfakewriters
; i
++) {
1574 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
1575 fakewriter_tasks
[i
] = kthread_run(rcu_torture_fakewriter
, NULL
,
1576 "rcu_torture_fakewriter");
1577 if (IS_ERR(fakewriter_tasks
[i
])) {
1578 firsterr
= PTR_ERR(fakewriter_tasks
[i
]);
1579 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
1580 fakewriter_tasks
[i
] = NULL
;
1584 reader_tasks
= kzalloc(nrealreaders
* sizeof(reader_tasks
[0]),
1586 if (reader_tasks
== NULL
) {
1587 VERBOSE_PRINTK_ERRSTRING("out of memory");
1591 for (i
= 0; i
< nrealreaders
; i
++) {
1592 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
1593 reader_tasks
[i
] = kthread_run(rcu_torture_reader
, NULL
,
1594 "rcu_torture_reader");
1595 if (IS_ERR(reader_tasks
[i
])) {
1596 firsterr
= PTR_ERR(reader_tasks
[i
]);
1597 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
1598 reader_tasks
[i
] = NULL
;
1602 if (stat_interval
> 0) {
1603 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
1604 stats_task
= kthread_run(rcu_torture_stats
, NULL
,
1605 "rcu_torture_stats");
1606 if (IS_ERR(stats_task
)) {
1607 firsterr
= PTR_ERR(stats_task
);
1608 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
1613 if (test_no_idle_hz
) {
1614 rcu_idle_cpu
= num_online_cpus() - 1;
1616 if (!alloc_cpumask_var(&shuffle_tmp_mask
, GFP_KERNEL
)) {
1618 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
1622 /* Create the shuffler thread */
1623 shuffler_task
= kthread_run(rcu_torture_shuffle
, NULL
,
1624 "rcu_torture_shuffle");
1625 if (IS_ERR(shuffler_task
)) {
1626 free_cpumask_var(shuffle_tmp_mask
);
1627 firsterr
= PTR_ERR(shuffler_task
);
1628 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
1629 shuffler_task
= NULL
;
1636 /* Create the stutter thread */
1637 stutter_task
= kthread_run(rcu_torture_stutter
, NULL
,
1638 "rcu_torture_stutter");
1639 if (IS_ERR(stutter_task
)) {
1640 firsterr
= PTR_ERR(stutter_task
);
1641 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
1642 stutter_task
= NULL
;
1646 if (fqs_duration
< 0)
1649 /* Create the stutter thread */
1650 fqs_task
= kthread_run(rcu_torture_fqs
, NULL
,
1652 if (IS_ERR(fqs_task
)) {
1653 firsterr
= PTR_ERR(fqs_task
);
1654 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
1659 if (test_boost_interval
< 1)
1660 test_boost_interval
= 1;
1661 if (test_boost_duration
< 2)
1662 test_boost_duration
= 2;
1663 if ((test_boost
== 1 && cur_ops
->can_boost
) ||
1667 boost_starttime
= jiffies
+ test_boost_interval
* HZ
;
1668 register_cpu_notifier(&rcutorture_cpu_nb
);
1669 for_each_possible_cpu(i
) {
1670 if (cpu_is_offline(i
))
1671 continue; /* Heuristic: CPU can go offline. */
1672 retval
= rcutorture_booster_init(i
);
1679 if (shutdown_secs
> 0) {
1680 shutdown_time
= jiffies
+ shutdown_secs
* HZ
;
1681 shutdown_task
= kthread_run(rcu_torture_shutdown
, NULL
,
1682 "rcu_torture_shutdown");
1683 if (IS_ERR(shutdown_task
)) {
1684 firsterr
= PTR_ERR(shutdown_task
);
1685 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
1686 shutdown_task
= NULL
;
1690 register_reboot_notifier(&rcutorture_shutdown_nb
);
1691 rcutorture_record_test_transition();
1692 mutex_unlock(&fullstop_mutex
);
1696 mutex_unlock(&fullstop_mutex
);
1697 rcu_torture_cleanup();
1701 module_init(rcu_torture_init
);
1702 module_exit(rcu_torture_cleanup
);