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/export.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/module.h>
36 #include <linux/sched.h>
37 #include <linux/atomic.h>
38 #include <linux/bitops.h>
39 #include <linux/completion.h>
40 #include <linux/moduleparam.h>
41 #include <linux/percpu.h>
42 #include <linux/notifier.h>
43 #include <linux/reboot.h>
44 #include <linux/freezer.h>
45 #include <linux/cpu.h>
46 #include <linux/delay.h>
47 #include <linux/stat.h>
48 #include <linux/srcu.h>
49 #include <linux/slab.h>
50 #include <asm/byteorder.h>
52 MODULE_LICENSE("GPL");
53 MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and "
54 "Josh Triplett <josh@freedesktop.org>");
56 static int nreaders
= -1; /* # reader threads, defaults to 2*ncpus */
57 static int nfakewriters
= 4; /* # fake writer threads */
58 static int stat_interval
; /* Interval between stats, in seconds. */
59 /* Defaults to "only at end of test". */
60 static int verbose
; /* Print more debug info. */
61 static int test_no_idle_hz
; /* Test RCU's support for tickless idle CPUs. */
62 static int shuffle_interval
= 3; /* Interval between shuffles (in sec)*/
63 static int stutter
= 5; /* Start/stop testing interval (in sec) */
64 static int irqreader
= 1; /* RCU readers from irq (timers). */
65 static int fqs_duration
= 0; /* Duration of bursts (us), 0 to disable. */
66 static int fqs_holdoff
= 0; /* Hold time within burst (us). */
67 static int fqs_stutter
= 3; /* Wait time between bursts (s). */
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(test_boost
, int, 0444);
96 MODULE_PARM_DESC(test_boost
, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
97 module_param(test_boost_interval
, int, 0444);
98 MODULE_PARM_DESC(test_boost_interval
, "Interval between boost tests, seconds.");
99 module_param(test_boost_duration
, int, 0444);
100 MODULE_PARM_DESC(test_boost_duration
, "Duration of each boost test, seconds.");
101 module_param(torture_type
, charp
, 0444);
102 MODULE_PARM_DESC(torture_type
, "Type of RCU to torture (rcu, rcu_bh, srcu)");
104 #define TORTURE_FLAG "-torture:"
105 #define PRINTK_STRING(s) \
106 do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
107 #define VERBOSE_PRINTK_STRING(s) \
108 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
109 #define VERBOSE_PRINTK_ERRSTRING(s) \
110 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
112 static char printk_buf
[4096];
114 static int nrealreaders
;
115 static struct task_struct
*writer_task
;
116 static struct task_struct
**fakewriter_tasks
;
117 static struct task_struct
**reader_tasks
;
118 static struct task_struct
*stats_task
;
119 static struct task_struct
*shuffler_task
;
120 static struct task_struct
*stutter_task
;
121 static struct task_struct
*fqs_task
;
122 static struct task_struct
*boost_tasks
[NR_CPUS
];
124 #define RCU_TORTURE_PIPE_LEN 10
127 struct rcu_head rtort_rcu
;
128 int rtort_pipe_count
;
129 struct list_head rtort_free
;
133 static LIST_HEAD(rcu_torture_freelist
);
134 static struct rcu_torture __rcu
*rcu_torture_current
;
135 static unsigned long rcu_torture_current_version
;
136 static struct rcu_torture rcu_tortures
[10 * RCU_TORTURE_PIPE_LEN
];
137 static DEFINE_SPINLOCK(rcu_torture_lock
);
138 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN
+ 1], rcu_torture_count
) =
140 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN
+ 1], rcu_torture_batch
) =
142 static atomic_t rcu_torture_wcount
[RCU_TORTURE_PIPE_LEN
+ 1];
143 static atomic_t n_rcu_torture_alloc
;
144 static atomic_t n_rcu_torture_alloc_fail
;
145 static atomic_t n_rcu_torture_free
;
146 static atomic_t n_rcu_torture_mberror
;
147 static atomic_t n_rcu_torture_error
;
148 static long n_rcu_torture_boost_ktrerror
;
149 static long n_rcu_torture_boost_rterror
;
150 static long n_rcu_torture_boost_failure
;
151 static long n_rcu_torture_boosts
;
152 static long n_rcu_torture_timers
;
153 static struct list_head rcu_torture_removed
;
154 static cpumask_var_t shuffle_tmp_mask
;
156 static int stutter_pause_test
;
158 #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
159 #define RCUTORTURE_RUNNABLE_INIT 1
161 #define RCUTORTURE_RUNNABLE_INIT 0
163 int rcutorture_runnable
= RCUTORTURE_RUNNABLE_INIT
;
165 #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
166 #define rcu_can_boost() 1
167 #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
168 #define rcu_can_boost() 0
169 #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
171 static unsigned long boost_starttime
; /* jiffies of next boost test start. */
172 DEFINE_MUTEX(boost_mutex
); /* protect setting boost_starttime */
173 /* and boost task create/destroy. */
175 /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
177 #define FULLSTOP_DONTSTOP 0 /* Normal operation. */
178 #define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
179 #define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
180 static int fullstop
= FULLSTOP_RMMOD
;
182 * Protect fullstop transitions and spawning of kthreads.
184 static DEFINE_MUTEX(fullstop_mutex
);
187 * Detect and respond to a system shutdown.
190 rcutorture_shutdown_notify(struct notifier_block
*unused1
,
191 unsigned long unused2
, void *unused3
)
193 mutex_lock(&fullstop_mutex
);
194 if (fullstop
== FULLSTOP_DONTSTOP
)
195 fullstop
= FULLSTOP_SHUTDOWN
;
197 printk(KERN_WARNING
/* but going down anyway, so... */
198 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
199 mutex_unlock(&fullstop_mutex
);
204 * Absorb kthreads into a kernel function that won't return, so that
205 * they won't ever access module text or data again.
207 static void rcutorture_shutdown_absorb(char *title
)
209 if (ACCESS_ONCE(fullstop
) == FULLSTOP_SHUTDOWN
) {
211 "rcutorture thread %s parking due to system shutdown\n",
213 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT
);
218 * Allocate an element from the rcu_tortures pool.
220 static struct rcu_torture
*
221 rcu_torture_alloc(void)
225 spin_lock_bh(&rcu_torture_lock
);
226 if (list_empty(&rcu_torture_freelist
)) {
227 atomic_inc(&n_rcu_torture_alloc_fail
);
228 spin_unlock_bh(&rcu_torture_lock
);
231 atomic_inc(&n_rcu_torture_alloc
);
232 p
= rcu_torture_freelist
.next
;
234 spin_unlock_bh(&rcu_torture_lock
);
235 return container_of(p
, struct rcu_torture
, rtort_free
);
239 * Free an element to the rcu_tortures pool.
242 rcu_torture_free(struct rcu_torture
*p
)
244 atomic_inc(&n_rcu_torture_free
);
245 spin_lock_bh(&rcu_torture_lock
);
246 list_add_tail(&p
->rtort_free
, &rcu_torture_freelist
);
247 spin_unlock_bh(&rcu_torture_lock
);
250 struct rcu_random_state
{
251 unsigned long rrs_state
;
255 #define RCU_RANDOM_MULT 39916801 /* prime */
256 #define RCU_RANDOM_ADD 479001701 /* prime */
257 #define RCU_RANDOM_REFRESH 10000
259 #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
262 * Crude but fast random-number generator. Uses a linear congruential
263 * generator, with occasional help from cpu_clock().
266 rcu_random(struct rcu_random_state
*rrsp
)
268 if (--rrsp
->rrs_count
< 0) {
269 rrsp
->rrs_state
+= (unsigned long)local_clock();
270 rrsp
->rrs_count
= RCU_RANDOM_REFRESH
;
272 rrsp
->rrs_state
= rrsp
->rrs_state
* RCU_RANDOM_MULT
+ RCU_RANDOM_ADD
;
273 return swahw32(rrsp
->rrs_state
);
277 rcu_stutter_wait(char *title
)
279 while (stutter_pause_test
|| !rcutorture_runnable
) {
280 if (rcutorture_runnable
)
281 schedule_timeout_interruptible(1);
283 schedule_timeout_interruptible(round_jiffies_relative(HZ
));
284 rcutorture_shutdown_absorb(title
);
289 * Operations vector for selecting different types of tests.
292 struct rcu_torture_ops
{
294 void (*cleanup
)(void);
295 int (*readlock
)(void);
296 void (*read_delay
)(struct rcu_random_state
*rrsp
);
297 void (*readunlock
)(int idx
);
298 int (*completed
)(void);
299 void (*deferred_free
)(struct rcu_torture
*p
);
301 void (*cb_barrier
)(void);
303 int (*stats
)(char *page
);
309 static struct rcu_torture_ops
*cur_ops
;
312 * Definitions for rcu torture testing.
315 static int rcu_torture_read_lock(void) __acquires(RCU
)
321 static void rcu_read_delay(struct rcu_random_state
*rrsp
)
323 const unsigned long shortdelay_us
= 200;
324 const unsigned long longdelay_ms
= 50;
326 /* We want a short delay sometimes to make a reader delay the grace
327 * period, and we want a long delay occasionally to trigger
328 * force_quiescent_state. */
330 if (!(rcu_random(rrsp
) % (nrealreaders
* 2000 * longdelay_ms
)))
331 mdelay(longdelay_ms
);
332 if (!(rcu_random(rrsp
) % (nrealreaders
* 2 * shortdelay_us
)))
333 udelay(shortdelay_us
);
334 #ifdef CONFIG_PREEMPT
335 if (!preempt_count() && !(rcu_random(rrsp
) % (nrealreaders
* 20000)))
336 preempt_schedule(); /* No QS if preempt_disable() in effect */
340 static void rcu_torture_read_unlock(int idx
) __releases(RCU
)
345 static int rcu_torture_completed(void)
347 return rcu_batches_completed();
351 rcu_torture_cb(struct rcu_head
*p
)
354 struct rcu_torture
*rp
= container_of(p
, struct rcu_torture
, rtort_rcu
);
356 if (fullstop
!= FULLSTOP_DONTSTOP
) {
357 /* Test is ending, just drop callbacks on the floor. */
358 /* The next initialization will pick up the pieces. */
361 i
= rp
->rtort_pipe_count
;
362 if (i
> RCU_TORTURE_PIPE_LEN
)
363 i
= RCU_TORTURE_PIPE_LEN
;
364 atomic_inc(&rcu_torture_wcount
[i
]);
365 if (++rp
->rtort_pipe_count
>= RCU_TORTURE_PIPE_LEN
) {
366 rp
->rtort_mbtest
= 0;
367 rcu_torture_free(rp
);
369 cur_ops
->deferred_free(rp
);
372 static int rcu_no_completed(void)
377 static void rcu_torture_deferred_free(struct rcu_torture
*p
)
379 call_rcu(&p
->rtort_rcu
, rcu_torture_cb
);
382 static struct rcu_torture_ops rcu_ops
= {
385 .readlock
= rcu_torture_read_lock
,
386 .read_delay
= rcu_read_delay
,
387 .readunlock
= rcu_torture_read_unlock
,
388 .completed
= rcu_torture_completed
,
389 .deferred_free
= rcu_torture_deferred_free
,
390 .sync
= synchronize_rcu
,
391 .cb_barrier
= rcu_barrier
,
392 .fqs
= rcu_force_quiescent_state
,
395 .can_boost
= rcu_can_boost(),
399 static void rcu_sync_torture_deferred_free(struct rcu_torture
*p
)
402 struct rcu_torture
*rp
;
403 struct rcu_torture
*rp1
;
406 list_add(&p
->rtort_free
, &rcu_torture_removed
);
407 list_for_each_entry_safe(rp
, rp1
, &rcu_torture_removed
, rtort_free
) {
408 i
= rp
->rtort_pipe_count
;
409 if (i
> RCU_TORTURE_PIPE_LEN
)
410 i
= RCU_TORTURE_PIPE_LEN
;
411 atomic_inc(&rcu_torture_wcount
[i
]);
412 if (++rp
->rtort_pipe_count
>= RCU_TORTURE_PIPE_LEN
) {
413 rp
->rtort_mbtest
= 0;
414 list_del(&rp
->rtort_free
);
415 rcu_torture_free(rp
);
420 static void rcu_sync_torture_init(void)
422 INIT_LIST_HEAD(&rcu_torture_removed
);
425 static struct rcu_torture_ops rcu_sync_ops
= {
426 .init
= rcu_sync_torture_init
,
428 .readlock
= rcu_torture_read_lock
,
429 .read_delay
= rcu_read_delay
,
430 .readunlock
= rcu_torture_read_unlock
,
431 .completed
= rcu_torture_completed
,
432 .deferred_free
= rcu_sync_torture_deferred_free
,
433 .sync
= synchronize_rcu
,
435 .fqs
= rcu_force_quiescent_state
,
438 .can_boost
= rcu_can_boost(),
442 static struct rcu_torture_ops rcu_expedited_ops
= {
443 .init
= rcu_sync_torture_init
,
445 .readlock
= rcu_torture_read_lock
,
446 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
447 .readunlock
= rcu_torture_read_unlock
,
448 .completed
= rcu_no_completed
,
449 .deferred_free
= rcu_sync_torture_deferred_free
,
450 .sync
= synchronize_rcu_expedited
,
452 .fqs
= rcu_force_quiescent_state
,
455 .can_boost
= rcu_can_boost(),
456 .name
= "rcu_expedited"
460 * Definitions for rcu_bh torture testing.
463 static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH
)
469 static void rcu_bh_torture_read_unlock(int idx
) __releases(RCU_BH
)
471 rcu_read_unlock_bh();
474 static int rcu_bh_torture_completed(void)
476 return rcu_batches_completed_bh();
479 static void rcu_bh_torture_deferred_free(struct rcu_torture
*p
)
481 call_rcu_bh(&p
->rtort_rcu
, rcu_torture_cb
);
484 static struct rcu_torture_ops rcu_bh_ops
= {
487 .readlock
= rcu_bh_torture_read_lock
,
488 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
489 .readunlock
= rcu_bh_torture_read_unlock
,
490 .completed
= rcu_bh_torture_completed
,
491 .deferred_free
= rcu_bh_torture_deferred_free
,
492 .sync
= synchronize_rcu_bh
,
493 .cb_barrier
= rcu_barrier_bh
,
494 .fqs
= rcu_bh_force_quiescent_state
,
500 static struct rcu_torture_ops rcu_bh_sync_ops
= {
501 .init
= rcu_sync_torture_init
,
503 .readlock
= rcu_bh_torture_read_lock
,
504 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
505 .readunlock
= rcu_bh_torture_read_unlock
,
506 .completed
= rcu_bh_torture_completed
,
507 .deferred_free
= rcu_sync_torture_deferred_free
,
508 .sync
= synchronize_rcu_bh
,
510 .fqs
= rcu_bh_force_quiescent_state
,
513 .name
= "rcu_bh_sync"
516 static struct rcu_torture_ops rcu_bh_expedited_ops
= {
517 .init
= rcu_sync_torture_init
,
519 .readlock
= rcu_bh_torture_read_lock
,
520 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
521 .readunlock
= rcu_bh_torture_read_unlock
,
522 .completed
= rcu_bh_torture_completed
,
523 .deferred_free
= rcu_sync_torture_deferred_free
,
524 .sync
= synchronize_rcu_bh_expedited
,
526 .fqs
= rcu_bh_force_quiescent_state
,
529 .name
= "rcu_bh_expedited"
533 * Definitions for srcu torture testing.
536 static struct srcu_struct srcu_ctl
;
538 static void srcu_torture_init(void)
540 init_srcu_struct(&srcu_ctl
);
541 rcu_sync_torture_init();
544 static void srcu_torture_cleanup(void)
546 synchronize_srcu(&srcu_ctl
);
547 cleanup_srcu_struct(&srcu_ctl
);
550 static int srcu_torture_read_lock(void) __acquires(&srcu_ctl
)
552 return srcu_read_lock(&srcu_ctl
);
555 static void srcu_read_delay(struct rcu_random_state
*rrsp
)
558 const long uspertick
= 1000000 / HZ
;
559 const long longdelay
= 10;
561 /* We want there to be long-running readers, but not all the time. */
563 delay
= rcu_random(rrsp
) % (nrealreaders
* 2 * longdelay
* uspertick
);
565 schedule_timeout_interruptible(longdelay
);
567 rcu_read_delay(rrsp
);
570 static void srcu_torture_read_unlock(int idx
) __releases(&srcu_ctl
)
572 srcu_read_unlock(&srcu_ctl
, idx
);
575 static int srcu_torture_completed(void)
577 return srcu_batches_completed(&srcu_ctl
);
580 static void srcu_torture_synchronize(void)
582 synchronize_srcu(&srcu_ctl
);
585 static int srcu_torture_stats(char *page
)
589 int idx
= srcu_ctl
.completed
& 0x1;
591 cnt
+= sprintf(&page
[cnt
], "%s%s per-CPU(idx=%d):",
592 torture_type
, TORTURE_FLAG
, idx
);
593 for_each_possible_cpu(cpu
) {
594 cnt
+= sprintf(&page
[cnt
], " %d(%d,%d)", cpu
,
595 per_cpu_ptr(srcu_ctl
.per_cpu_ref
, cpu
)->c
[!idx
],
596 per_cpu_ptr(srcu_ctl
.per_cpu_ref
, cpu
)->c
[idx
]);
598 cnt
+= sprintf(&page
[cnt
], "\n");
602 static struct rcu_torture_ops srcu_ops
= {
603 .init
= srcu_torture_init
,
604 .cleanup
= srcu_torture_cleanup
,
605 .readlock
= srcu_torture_read_lock
,
606 .read_delay
= srcu_read_delay
,
607 .readunlock
= srcu_torture_read_unlock
,
608 .completed
= srcu_torture_completed
,
609 .deferred_free
= rcu_sync_torture_deferred_free
,
610 .sync
= srcu_torture_synchronize
,
612 .stats
= srcu_torture_stats
,
616 static void srcu_torture_synchronize_expedited(void)
618 synchronize_srcu_expedited(&srcu_ctl
);
621 static struct rcu_torture_ops srcu_expedited_ops
= {
622 .init
= srcu_torture_init
,
623 .cleanup
= srcu_torture_cleanup
,
624 .readlock
= srcu_torture_read_lock
,
625 .read_delay
= srcu_read_delay
,
626 .readunlock
= srcu_torture_read_unlock
,
627 .completed
= srcu_torture_completed
,
628 .deferred_free
= rcu_sync_torture_deferred_free
,
629 .sync
= srcu_torture_synchronize_expedited
,
631 .stats
= srcu_torture_stats
,
632 .name
= "srcu_expedited"
636 * Definitions for sched torture testing.
639 static int sched_torture_read_lock(void)
645 static void sched_torture_read_unlock(int idx
)
650 static void rcu_sched_torture_deferred_free(struct rcu_torture
*p
)
652 call_rcu_sched(&p
->rtort_rcu
, rcu_torture_cb
);
655 static struct rcu_torture_ops sched_ops
= {
656 .init
= rcu_sync_torture_init
,
658 .readlock
= sched_torture_read_lock
,
659 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
660 .readunlock
= sched_torture_read_unlock
,
661 .completed
= rcu_no_completed
,
662 .deferred_free
= rcu_sched_torture_deferred_free
,
663 .sync
= synchronize_sched
,
664 .cb_barrier
= rcu_barrier_sched
,
665 .fqs
= rcu_sched_force_quiescent_state
,
671 static struct rcu_torture_ops sched_sync_ops
= {
672 .init
= rcu_sync_torture_init
,
674 .readlock
= sched_torture_read_lock
,
675 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
676 .readunlock
= sched_torture_read_unlock
,
677 .completed
= rcu_no_completed
,
678 .deferred_free
= rcu_sync_torture_deferred_free
,
679 .sync
= synchronize_sched
,
681 .fqs
= rcu_sched_force_quiescent_state
,
686 static struct rcu_torture_ops sched_expedited_ops
= {
687 .init
= rcu_sync_torture_init
,
689 .readlock
= sched_torture_read_lock
,
690 .read_delay
= rcu_read_delay
, /* just reuse rcu's version. */
691 .readunlock
= sched_torture_read_unlock
,
692 .completed
= rcu_no_completed
,
693 .deferred_free
= rcu_sync_torture_deferred_free
,
694 .sync
= synchronize_sched_expedited
,
696 .fqs
= rcu_sched_force_quiescent_state
,
699 .name
= "sched_expedited"
703 * RCU torture priority-boost testing. Runs one real-time thread per
704 * CPU for moderate bursts, repeatedly registering RCU callbacks and
705 * spinning waiting for them to be invoked. If a given callback takes
706 * too long to be invoked, we assume that priority inversion has occurred.
709 struct rcu_boost_inflight
{
714 static void rcu_torture_boost_cb(struct rcu_head
*head
)
716 struct rcu_boost_inflight
*rbip
=
717 container_of(head
, struct rcu_boost_inflight
, rcu
);
719 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
723 static int rcu_torture_boost(void *arg
)
725 unsigned long call_rcu_time
;
726 unsigned long endtime
;
727 unsigned long oldstarttime
;
728 struct rcu_boost_inflight rbi
= { .inflight
= 0 };
729 struct sched_param sp
;
731 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
733 /* Set real-time priority. */
734 sp
.sched_priority
= 1;
735 if (sched_setscheduler(current
, SCHED_FIFO
, &sp
) < 0) {
736 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
737 n_rcu_torture_boost_rterror
++;
740 init_rcu_head_on_stack(&rbi
.rcu
);
741 /* Each pass through the following loop does one boost-test cycle. */
743 /* Wait for the next test interval. */
744 oldstarttime
= boost_starttime
;
745 while (ULONG_CMP_LT(jiffies
, oldstarttime
)) {
746 schedule_timeout_uninterruptible(1);
747 rcu_stutter_wait("rcu_torture_boost");
748 if (kthread_should_stop() ||
749 fullstop
!= FULLSTOP_DONTSTOP
)
753 /* Do one boost-test interval. */
754 endtime
= oldstarttime
+ test_boost_duration
* HZ
;
755 call_rcu_time
= jiffies
;
756 while (ULONG_CMP_LT(jiffies
, endtime
)) {
757 /* If we don't have a callback in flight, post one. */
759 smp_mb(); /* RCU core before ->inflight = 1. */
761 call_rcu(&rbi
.rcu
, rcu_torture_boost_cb
);
762 if (jiffies
- call_rcu_time
>
763 test_boost_duration
* HZ
- HZ
/ 2) {
764 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
765 n_rcu_torture_boost_failure
++;
767 call_rcu_time
= jiffies
;
770 rcu_stutter_wait("rcu_torture_boost");
771 if (kthread_should_stop() ||
772 fullstop
!= FULLSTOP_DONTSTOP
)
777 * Set the start time of the next test interval.
778 * Yes, this is vulnerable to long delays, but such
779 * delays simply cause a false negative for the next
780 * interval. Besides, we are running at RT priority,
781 * so delays should be relatively rare.
783 while (oldstarttime
== boost_starttime
&&
784 !kthread_should_stop()) {
785 if (mutex_trylock(&boost_mutex
)) {
786 boost_starttime
= jiffies
+
787 test_boost_interval
* HZ
;
788 n_rcu_torture_boosts
++;
789 mutex_unlock(&boost_mutex
);
792 schedule_timeout_uninterruptible(1);
795 /* Go do the stutter. */
796 checkwait
: rcu_stutter_wait("rcu_torture_boost");
797 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
799 /* Clean up and exit. */
800 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
801 rcutorture_shutdown_absorb("rcu_torture_boost");
802 while (!kthread_should_stop() || rbi
.inflight
)
803 schedule_timeout_uninterruptible(1);
804 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
805 destroy_rcu_head_on_stack(&rbi
.rcu
);
810 * RCU torture force-quiescent-state kthread. Repeatedly induces
811 * bursts of calls to force_quiescent_state(), increasing the probability
812 * of occurrence of some important types of race conditions.
815 rcu_torture_fqs(void *arg
)
817 unsigned long fqs_resume_time
;
818 int fqs_burst_remaining
;
820 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
822 fqs_resume_time
= jiffies
+ fqs_stutter
* HZ
;
823 while (ULONG_CMP_LT(jiffies
, fqs_resume_time
) &&
824 !kthread_should_stop()) {
825 schedule_timeout_interruptible(1);
827 fqs_burst_remaining
= fqs_duration
;
828 while (fqs_burst_remaining
> 0 &&
829 !kthread_should_stop()) {
832 fqs_burst_remaining
-= fqs_holdoff
;
834 rcu_stutter_wait("rcu_torture_fqs");
835 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
836 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
837 rcutorture_shutdown_absorb("rcu_torture_fqs");
838 while (!kthread_should_stop())
839 schedule_timeout_uninterruptible(1);
844 * RCU torture writer kthread. Repeatedly substitutes a new structure
845 * for that pointed to by rcu_torture_current, freeing the old structure
846 * after a series of grace periods (the "pipeline").
849 rcu_torture_writer(void *arg
)
852 long oldbatch
= rcu_batches_completed();
853 struct rcu_torture
*rp
;
854 struct rcu_torture
*old_rp
;
855 static DEFINE_RCU_RANDOM(rand
);
857 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
858 set_user_nice(current
, 19);
861 schedule_timeout_uninterruptible(1);
862 rp
= rcu_torture_alloc();
865 rp
->rtort_pipe_count
= 0;
866 udelay(rcu_random(&rand
) & 0x3ff);
867 old_rp
= rcu_dereference_check(rcu_torture_current
,
868 current
== writer_task
);
869 rp
->rtort_mbtest
= 1;
870 rcu_assign_pointer(rcu_torture_current
, rp
);
871 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
873 i
= old_rp
->rtort_pipe_count
;
874 if (i
> RCU_TORTURE_PIPE_LEN
)
875 i
= RCU_TORTURE_PIPE_LEN
;
876 atomic_inc(&rcu_torture_wcount
[i
]);
877 old_rp
->rtort_pipe_count
++;
878 cur_ops
->deferred_free(old_rp
);
880 rcutorture_record_progress(++rcu_torture_current_version
);
881 oldbatch
= cur_ops
->completed();
882 rcu_stutter_wait("rcu_torture_writer");
883 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
884 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
885 rcutorture_shutdown_absorb("rcu_torture_writer");
886 while (!kthread_should_stop())
887 schedule_timeout_uninterruptible(1);
892 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
893 * delay between calls.
896 rcu_torture_fakewriter(void *arg
)
898 DEFINE_RCU_RANDOM(rand
);
900 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
901 set_user_nice(current
, 19);
904 schedule_timeout_uninterruptible(1 + rcu_random(&rand
)%10);
905 udelay(rcu_random(&rand
) & 0x3ff);
907 rcu_stutter_wait("rcu_torture_fakewriter");
908 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
910 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
911 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
912 while (!kthread_should_stop())
913 schedule_timeout_uninterruptible(1);
918 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
919 * incrementing the corresponding element of the pipeline array. The
920 * counter in the element should never be greater than 1, otherwise, the
921 * RCU implementation is broken.
923 static void rcu_torture_timer(unsigned long unused
)
927 static DEFINE_RCU_RANDOM(rand
);
928 static DEFINE_SPINLOCK(rand_lock
);
929 struct rcu_torture
*p
;
932 idx
= cur_ops
->readlock();
933 completed
= cur_ops
->completed();
934 p
= rcu_dereference_check(rcu_torture_current
,
935 rcu_read_lock_bh_held() ||
936 rcu_read_lock_sched_held() ||
937 srcu_read_lock_held(&srcu_ctl
));
939 /* Leave because rcu_torture_writer is not yet underway */
940 cur_ops
->readunlock(idx
);
943 if (p
->rtort_mbtest
== 0)
944 atomic_inc(&n_rcu_torture_mberror
);
945 spin_lock(&rand_lock
);
946 cur_ops
->read_delay(&rand
);
947 n_rcu_torture_timers
++;
948 spin_unlock(&rand_lock
);
950 pipe_count
= p
->rtort_pipe_count
;
951 if (pipe_count
> RCU_TORTURE_PIPE_LEN
) {
952 /* Should not happen, but... */
953 pipe_count
= RCU_TORTURE_PIPE_LEN
;
955 __this_cpu_inc(rcu_torture_count
[pipe_count
]);
956 completed
= cur_ops
->completed() - completed
;
957 if (completed
> RCU_TORTURE_PIPE_LEN
) {
958 /* Should not happen, but... */
959 completed
= RCU_TORTURE_PIPE_LEN
;
961 __this_cpu_inc(rcu_torture_batch
[completed
]);
963 cur_ops
->readunlock(idx
);
967 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
968 * incrementing the corresponding element of the pipeline array. The
969 * counter in the element should never be greater than 1, otherwise, the
970 * RCU implementation is broken.
973 rcu_torture_reader(void *arg
)
977 DEFINE_RCU_RANDOM(rand
);
978 struct rcu_torture
*p
;
982 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
983 set_user_nice(current
, 19);
984 if (irqreader
&& cur_ops
->irq_capable
)
985 setup_timer_on_stack(&t
, rcu_torture_timer
, 0);
988 if (irqreader
&& cur_ops
->irq_capable
) {
989 if (!timer_pending(&t
))
990 mod_timer(&t
, jiffies
+ 1);
992 idx
= cur_ops
->readlock();
993 completed
= cur_ops
->completed();
994 p
= rcu_dereference_check(rcu_torture_current
,
995 rcu_read_lock_bh_held() ||
996 rcu_read_lock_sched_held() ||
997 srcu_read_lock_held(&srcu_ctl
));
999 /* Wait for rcu_torture_writer to get underway */
1000 cur_ops
->readunlock(idx
);
1001 schedule_timeout_interruptible(HZ
);
1004 if (p
->rtort_mbtest
== 0)
1005 atomic_inc(&n_rcu_torture_mberror
);
1006 cur_ops
->read_delay(&rand
);
1008 pipe_count
= p
->rtort_pipe_count
;
1009 if (pipe_count
> RCU_TORTURE_PIPE_LEN
) {
1010 /* Should not happen, but... */
1011 pipe_count
= RCU_TORTURE_PIPE_LEN
;
1013 __this_cpu_inc(rcu_torture_count
[pipe_count
]);
1014 completed
= cur_ops
->completed() - completed
;
1015 if (completed
> RCU_TORTURE_PIPE_LEN
) {
1016 /* Should not happen, but... */
1017 completed
= RCU_TORTURE_PIPE_LEN
;
1019 __this_cpu_inc(rcu_torture_batch
[completed
]);
1021 cur_ops
->readunlock(idx
);
1023 rcu_stutter_wait("rcu_torture_reader");
1024 } while (!kthread_should_stop() && fullstop
== FULLSTOP_DONTSTOP
);
1025 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
1026 rcutorture_shutdown_absorb("rcu_torture_reader");
1027 if (irqreader
&& cur_ops
->irq_capable
)
1029 while (!kthread_should_stop())
1030 schedule_timeout_uninterruptible(1);
1035 * Create an RCU-torture statistics message in the specified buffer.
1038 rcu_torture_printk(char *page
)
1043 long pipesummary
[RCU_TORTURE_PIPE_LEN
+ 1] = { 0 };
1044 long batchsummary
[RCU_TORTURE_PIPE_LEN
+ 1] = { 0 };
1046 for_each_possible_cpu(cpu
) {
1047 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
1048 pipesummary
[i
] += per_cpu(rcu_torture_count
, cpu
)[i
];
1049 batchsummary
[i
] += per_cpu(rcu_torture_batch
, cpu
)[i
];
1052 for (i
= RCU_TORTURE_PIPE_LEN
- 1; i
>= 0; i
--) {
1053 if (pipesummary
[i
] != 0)
1056 cnt
+= sprintf(&page
[cnt
], "%s%s ", torture_type
, TORTURE_FLAG
);
1057 cnt
+= sprintf(&page
[cnt
],
1058 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d "
1059 "rtmbe: %d rtbke: %ld rtbre: %ld "
1060 "rtbf: %ld rtb: %ld nt: %ld",
1061 rcu_torture_current
,
1062 rcu_torture_current_version
,
1063 list_empty(&rcu_torture_freelist
),
1064 atomic_read(&n_rcu_torture_alloc
),
1065 atomic_read(&n_rcu_torture_alloc_fail
),
1066 atomic_read(&n_rcu_torture_free
),
1067 atomic_read(&n_rcu_torture_mberror
),
1068 n_rcu_torture_boost_ktrerror
,
1069 n_rcu_torture_boost_rterror
,
1070 n_rcu_torture_boost_failure
,
1071 n_rcu_torture_boosts
,
1072 n_rcu_torture_timers
);
1073 if (atomic_read(&n_rcu_torture_mberror
) != 0 ||
1074 n_rcu_torture_boost_ktrerror
!= 0 ||
1075 n_rcu_torture_boost_rterror
!= 0 ||
1076 n_rcu_torture_boost_failure
!= 0)
1077 cnt
+= sprintf(&page
[cnt
], " !!!");
1078 cnt
+= sprintf(&page
[cnt
], "\n%s%s ", torture_type
, TORTURE_FLAG
);
1080 cnt
+= sprintf(&page
[cnt
], "!!! ");
1081 atomic_inc(&n_rcu_torture_error
);
1084 cnt
+= sprintf(&page
[cnt
], "Reader Pipe: ");
1085 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
1086 cnt
+= sprintf(&page
[cnt
], " %ld", pipesummary
[i
]);
1087 cnt
+= sprintf(&page
[cnt
], "\n%s%s ", torture_type
, TORTURE_FLAG
);
1088 cnt
+= sprintf(&page
[cnt
], "Reader Batch: ");
1089 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
1090 cnt
+= sprintf(&page
[cnt
], " %ld", batchsummary
[i
]);
1091 cnt
+= sprintf(&page
[cnt
], "\n%s%s ", torture_type
, TORTURE_FLAG
);
1092 cnt
+= sprintf(&page
[cnt
], "Free-Block Circulation: ");
1093 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
1094 cnt
+= sprintf(&page
[cnt
], " %d",
1095 atomic_read(&rcu_torture_wcount
[i
]));
1097 cnt
+= sprintf(&page
[cnt
], "\n");
1099 cnt
+= cur_ops
->stats(&page
[cnt
]);
1104 * Print torture statistics. Caller must ensure that there is only
1105 * one call to this function at a given time!!! This is normally
1106 * accomplished by relying on the module system to only have one copy
1107 * of the module loaded, and then by giving the rcu_torture_stats
1108 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1109 * thread is not running).
1112 rcu_torture_stats_print(void)
1116 cnt
= rcu_torture_printk(printk_buf
);
1117 printk(KERN_ALERT
"%s", printk_buf
);
1121 * Periodically prints torture statistics, if periodic statistics printing
1122 * was specified via the stat_interval module parameter.
1124 * No need to worry about fullstop here, since this one doesn't reference
1125 * volatile state or register callbacks.
1128 rcu_torture_stats(void *arg
)
1130 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1132 schedule_timeout_interruptible(stat_interval
* HZ
);
1133 rcu_torture_stats_print();
1134 rcutorture_shutdown_absorb("rcu_torture_stats");
1135 } while (!kthread_should_stop());
1136 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1140 static int rcu_idle_cpu
; /* Force all torture tasks off this CPU */
1142 /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1143 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1145 static void rcu_torture_shuffle_tasks(void)
1149 cpumask_setall(shuffle_tmp_mask
);
1152 /* No point in shuffling if there is only one online CPU (ex: UP) */
1153 if (num_online_cpus() == 1) {
1158 if (rcu_idle_cpu
!= -1)
1159 cpumask_clear_cpu(rcu_idle_cpu
, shuffle_tmp_mask
);
1161 set_cpus_allowed_ptr(current
, shuffle_tmp_mask
);
1164 for (i
= 0; i
< nrealreaders
; i
++)
1165 if (reader_tasks
[i
])
1166 set_cpus_allowed_ptr(reader_tasks
[i
],
1170 if (fakewriter_tasks
) {
1171 for (i
= 0; i
< nfakewriters
; i
++)
1172 if (fakewriter_tasks
[i
])
1173 set_cpus_allowed_ptr(fakewriter_tasks
[i
],
1178 set_cpus_allowed_ptr(writer_task
, shuffle_tmp_mask
);
1181 set_cpus_allowed_ptr(stats_task
, shuffle_tmp_mask
);
1183 if (rcu_idle_cpu
== -1)
1184 rcu_idle_cpu
= num_online_cpus() - 1;
1191 /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1192 * system to become idle at a time and cut off its timer ticks. This is meant
1193 * to test the support for such tickless idle CPU in RCU.
1196 rcu_torture_shuffle(void *arg
)
1198 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1200 schedule_timeout_interruptible(shuffle_interval
* HZ
);
1201 rcu_torture_shuffle_tasks();
1202 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1203 } while (!kthread_should_stop());
1204 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1208 /* Cause the rcutorture test to "stutter", starting and stopping all
1209 * threads periodically.
1212 rcu_torture_stutter(void *arg
)
1214 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1216 schedule_timeout_interruptible(stutter
* HZ
);
1217 stutter_pause_test
= 1;
1218 if (!kthread_should_stop())
1219 schedule_timeout_interruptible(stutter
* HZ
);
1220 stutter_pause_test
= 0;
1221 rcutorture_shutdown_absorb("rcu_torture_stutter");
1222 } while (!kthread_should_stop());
1223 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1228 rcu_torture_print_module_parms(struct rcu_torture_ops
*cur_ops
, char *tag
)
1230 printk(KERN_ALERT
"%s" TORTURE_FLAG
1231 "--- %s: nreaders=%d nfakewriters=%d "
1232 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1233 "shuffle_interval=%d stutter=%d irqreader=%d "
1234 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1235 "test_boost=%d/%d test_boost_interval=%d "
1236 "test_boost_duration=%d\n",
1237 torture_type
, tag
, nrealreaders
, nfakewriters
,
1238 stat_interval
, verbose
, test_no_idle_hz
, shuffle_interval
,
1239 stutter
, irqreader
, fqs_duration
, fqs_holdoff
, fqs_stutter
,
1240 test_boost
, cur_ops
->can_boost
,
1241 test_boost_interval
, test_boost_duration
);
1244 static struct notifier_block rcutorture_shutdown_nb
= {
1245 .notifier_call
= rcutorture_shutdown_notify
,
1248 static void rcutorture_booster_cleanup(int cpu
)
1250 struct task_struct
*t
;
1252 if (boost_tasks
[cpu
] == NULL
)
1254 mutex_lock(&boost_mutex
);
1255 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1256 t
= boost_tasks
[cpu
];
1257 boost_tasks
[cpu
] = NULL
;
1258 mutex_unlock(&boost_mutex
);
1260 /* This must be outside of the mutex, otherwise deadlock! */
1264 static int rcutorture_booster_init(int cpu
)
1268 if (boost_tasks
[cpu
] != NULL
)
1269 return 0; /* Already created, nothing more to do. */
1271 /* Don't allow time recalculation while creating a new task. */
1272 mutex_lock(&boost_mutex
);
1273 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
1274 boost_tasks
[cpu
] = kthread_create_on_node(rcu_torture_boost
, NULL
,
1276 "rcu_torture_boost");
1277 if (IS_ERR(boost_tasks
[cpu
])) {
1278 retval
= PTR_ERR(boost_tasks
[cpu
]);
1279 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1280 n_rcu_torture_boost_ktrerror
++;
1281 boost_tasks
[cpu
] = NULL
;
1282 mutex_unlock(&boost_mutex
);
1285 kthread_bind(boost_tasks
[cpu
], cpu
);
1286 wake_up_process(boost_tasks
[cpu
]);
1287 mutex_unlock(&boost_mutex
);
1291 static int rcutorture_cpu_notify(struct notifier_block
*self
,
1292 unsigned long action
, void *hcpu
)
1294 long cpu
= (long)hcpu
;
1298 case CPU_DOWN_FAILED
:
1299 (void)rcutorture_booster_init(cpu
);
1301 case CPU_DOWN_PREPARE
:
1302 rcutorture_booster_cleanup(cpu
);
1310 static struct notifier_block rcutorture_cpu_nb
= {
1311 .notifier_call
= rcutorture_cpu_notify
,
1315 rcu_torture_cleanup(void)
1319 mutex_lock(&fullstop_mutex
);
1320 rcutorture_record_test_transition();
1321 if (fullstop
== FULLSTOP_SHUTDOWN
) {
1322 printk(KERN_WARNING
/* but going down anyway, so... */
1323 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
1324 mutex_unlock(&fullstop_mutex
);
1325 schedule_timeout_uninterruptible(10);
1326 if (cur_ops
->cb_barrier
!= NULL
)
1327 cur_ops
->cb_barrier();
1330 fullstop
= FULLSTOP_RMMOD
;
1331 mutex_unlock(&fullstop_mutex
);
1332 unregister_reboot_notifier(&rcutorture_shutdown_nb
);
1334 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1335 kthread_stop(stutter_task
);
1337 stutter_task
= NULL
;
1338 if (shuffler_task
) {
1339 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1340 kthread_stop(shuffler_task
);
1341 free_cpumask_var(shuffle_tmp_mask
);
1343 shuffler_task
= NULL
;
1346 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1347 kthread_stop(writer_task
);
1352 for (i
= 0; i
< nrealreaders
; i
++) {
1353 if (reader_tasks
[i
]) {
1354 VERBOSE_PRINTK_STRING(
1355 "Stopping rcu_torture_reader task");
1356 kthread_stop(reader_tasks
[i
]);
1358 reader_tasks
[i
] = NULL
;
1360 kfree(reader_tasks
);
1361 reader_tasks
= NULL
;
1363 rcu_torture_current
= NULL
;
1365 if (fakewriter_tasks
) {
1366 for (i
= 0; i
< nfakewriters
; i
++) {
1367 if (fakewriter_tasks
[i
]) {
1368 VERBOSE_PRINTK_STRING(
1369 "Stopping rcu_torture_fakewriter task");
1370 kthread_stop(fakewriter_tasks
[i
]);
1372 fakewriter_tasks
[i
] = NULL
;
1374 kfree(fakewriter_tasks
);
1375 fakewriter_tasks
= NULL
;
1379 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1380 kthread_stop(stats_task
);
1385 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1386 kthread_stop(fqs_task
);
1389 if ((test_boost
== 1 && cur_ops
->can_boost
) ||
1391 unregister_cpu_notifier(&rcutorture_cpu_nb
);
1392 for_each_possible_cpu(i
)
1393 rcutorture_booster_cleanup(i
);
1396 /* Wait for all RCU callbacks to fire. */
1398 if (cur_ops
->cb_barrier
!= NULL
)
1399 cur_ops
->cb_barrier();
1401 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
1403 if (cur_ops
->cleanup
)
1405 if (atomic_read(&n_rcu_torture_error
))
1406 rcu_torture_print_module_parms(cur_ops
, "End of test: FAILURE");
1408 rcu_torture_print_module_parms(cur_ops
, "End of test: SUCCESS");
1412 rcu_torture_init(void)
1417 static struct rcu_torture_ops
*torture_ops
[] =
1418 { &rcu_ops
, &rcu_sync_ops
, &rcu_expedited_ops
,
1419 &rcu_bh_ops
, &rcu_bh_sync_ops
, &rcu_bh_expedited_ops
,
1420 &srcu_ops
, &srcu_expedited_ops
,
1421 &sched_ops
, &sched_sync_ops
, &sched_expedited_ops
, };
1423 mutex_lock(&fullstop_mutex
);
1425 /* Process args and tell the world that the torturer is on the job. */
1426 for (i
= 0; i
< ARRAY_SIZE(torture_ops
); i
++) {
1427 cur_ops
= torture_ops
[i
];
1428 if (strcmp(torture_type
, cur_ops
->name
) == 0)
1431 if (i
== ARRAY_SIZE(torture_ops
)) {
1432 printk(KERN_ALERT
"rcu-torture: invalid torture type: \"%s\"\n",
1434 printk(KERN_ALERT
"rcu-torture types:");
1435 for (i
= 0; i
< ARRAY_SIZE(torture_ops
); i
++)
1436 printk(KERN_ALERT
" %s", torture_ops
[i
]->name
);
1437 printk(KERN_ALERT
"\n");
1438 mutex_unlock(&fullstop_mutex
);
1441 if (cur_ops
->fqs
== NULL
&& fqs_duration
!= 0) {
1442 printk(KERN_ALERT
"rcu-torture: ->fqs NULL and non-zero "
1443 "fqs_duration, fqs disabled.\n");
1447 cur_ops
->init(); /* no "goto unwind" prior to this point!!! */
1450 nrealreaders
= nreaders
;
1452 nrealreaders
= 2 * num_online_cpus();
1453 rcu_torture_print_module_parms(cur_ops
, "Start of test");
1454 fullstop
= FULLSTOP_DONTSTOP
;
1456 /* Set up the freelist. */
1458 INIT_LIST_HEAD(&rcu_torture_freelist
);
1459 for (i
= 0; i
< ARRAY_SIZE(rcu_tortures
); i
++) {
1460 rcu_tortures
[i
].rtort_mbtest
= 0;
1461 list_add_tail(&rcu_tortures
[i
].rtort_free
,
1462 &rcu_torture_freelist
);
1465 /* Initialize the statistics so that each run gets its own numbers. */
1467 rcu_torture_current
= NULL
;
1468 rcu_torture_current_version
= 0;
1469 atomic_set(&n_rcu_torture_alloc
, 0);
1470 atomic_set(&n_rcu_torture_alloc_fail
, 0);
1471 atomic_set(&n_rcu_torture_free
, 0);
1472 atomic_set(&n_rcu_torture_mberror
, 0);
1473 atomic_set(&n_rcu_torture_error
, 0);
1474 n_rcu_torture_boost_ktrerror
= 0;
1475 n_rcu_torture_boost_rterror
= 0;
1476 n_rcu_torture_boost_failure
= 0;
1477 n_rcu_torture_boosts
= 0;
1478 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
1479 atomic_set(&rcu_torture_wcount
[i
], 0);
1480 for_each_possible_cpu(cpu
) {
1481 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
1482 per_cpu(rcu_torture_count
, cpu
)[i
] = 0;
1483 per_cpu(rcu_torture_batch
, cpu
)[i
] = 0;
1487 /* Start up the kthreads. */
1489 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1490 writer_task
= kthread_run(rcu_torture_writer
, NULL
,
1491 "rcu_torture_writer");
1492 if (IS_ERR(writer_task
)) {
1493 firsterr
= PTR_ERR(writer_task
);
1494 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1498 fakewriter_tasks
= kzalloc(nfakewriters
* sizeof(fakewriter_tasks
[0]),
1500 if (fakewriter_tasks
== NULL
) {
1501 VERBOSE_PRINTK_ERRSTRING("out of memory");
1505 for (i
= 0; i
< nfakewriters
; i
++) {
1506 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
1507 fakewriter_tasks
[i
] = kthread_run(rcu_torture_fakewriter
, NULL
,
1508 "rcu_torture_fakewriter");
1509 if (IS_ERR(fakewriter_tasks
[i
])) {
1510 firsterr
= PTR_ERR(fakewriter_tasks
[i
]);
1511 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
1512 fakewriter_tasks
[i
] = NULL
;
1516 reader_tasks
= kzalloc(nrealreaders
* sizeof(reader_tasks
[0]),
1518 if (reader_tasks
== NULL
) {
1519 VERBOSE_PRINTK_ERRSTRING("out of memory");
1523 for (i
= 0; i
< nrealreaders
; i
++) {
1524 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
1525 reader_tasks
[i
] = kthread_run(rcu_torture_reader
, NULL
,
1526 "rcu_torture_reader");
1527 if (IS_ERR(reader_tasks
[i
])) {
1528 firsterr
= PTR_ERR(reader_tasks
[i
]);
1529 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
1530 reader_tasks
[i
] = NULL
;
1534 if (stat_interval
> 0) {
1535 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
1536 stats_task
= kthread_run(rcu_torture_stats
, NULL
,
1537 "rcu_torture_stats");
1538 if (IS_ERR(stats_task
)) {
1539 firsterr
= PTR_ERR(stats_task
);
1540 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
1545 if (test_no_idle_hz
) {
1546 rcu_idle_cpu
= num_online_cpus() - 1;
1548 if (!alloc_cpumask_var(&shuffle_tmp_mask
, GFP_KERNEL
)) {
1550 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
1554 /* Create the shuffler thread */
1555 shuffler_task
= kthread_run(rcu_torture_shuffle
, NULL
,
1556 "rcu_torture_shuffle");
1557 if (IS_ERR(shuffler_task
)) {
1558 free_cpumask_var(shuffle_tmp_mask
);
1559 firsterr
= PTR_ERR(shuffler_task
);
1560 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
1561 shuffler_task
= NULL
;
1568 /* Create the stutter thread */
1569 stutter_task
= kthread_run(rcu_torture_stutter
, NULL
,
1570 "rcu_torture_stutter");
1571 if (IS_ERR(stutter_task
)) {
1572 firsterr
= PTR_ERR(stutter_task
);
1573 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
1574 stutter_task
= NULL
;
1578 if (fqs_duration
< 0)
1581 /* Create the stutter thread */
1582 fqs_task
= kthread_run(rcu_torture_fqs
, NULL
,
1584 if (IS_ERR(fqs_task
)) {
1585 firsterr
= PTR_ERR(fqs_task
);
1586 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
1591 if (test_boost_interval
< 1)
1592 test_boost_interval
= 1;
1593 if (test_boost_duration
< 2)
1594 test_boost_duration
= 2;
1595 if ((test_boost
== 1 && cur_ops
->can_boost
) ||
1599 boost_starttime
= jiffies
+ test_boost_interval
* HZ
;
1600 register_cpu_notifier(&rcutorture_cpu_nb
);
1601 for_each_possible_cpu(i
) {
1602 if (cpu_is_offline(i
))
1603 continue; /* Heuristic: CPU can go offline. */
1604 retval
= rcutorture_booster_init(i
);
1611 register_reboot_notifier(&rcutorture_shutdown_nb
);
1612 rcutorture_record_test_transition();
1613 mutex_unlock(&fullstop_mutex
);
1617 mutex_unlock(&fullstop_mutex
);
1618 rcu_torture_cleanup();
1622 module_init(rcu_torture_init
);
1623 module_exit(rcu_torture_cleanup
);