blob: 328a8257c8855133c617b123a7a9d4f417607592 [file] [log] [blame]
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001/*
Paul E. McKenney29766f12006-06-27 02:54:02 -07002 * Read-Copy Update module-based torture test facility
Paul E. McKenneya241ec62005-10-30 15:03:12 -08003 *
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.
8 *
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.
13 *
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.
17 *
Josh Triplettb772e1d2006-10-04 02:17:13 -070018 * Copyright (C) IBM Corporation, 2005, 2006
Paul E. McKenneya241ec62005-10-30 15:03:12 -080019 *
20 * Authors: Paul E. McKenney <paulmck@us.ibm.com>
Josh Triplettb772e1d2006-10-04 02:17:13 -070021 * Josh Triplett <josh@freedesktop.org>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080022 *
23 * See also: Documentation/RCU/torture.txt
24 */
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 <asm/atomic.h>
37#include <linux/bitops.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080038#include <linux/completion.h>
39#include <linux/moduleparam.h>
40#include <linux/percpu.h>
41#include <linux/notifier.h>
Paul E. McKenney343e9092008-12-15 16:13:07 -080042#include <linux/reboot.h>
Rafael J. Wysocki83144182007-07-17 04:03:35 -070043#include <linux/freezer.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080044#include <linux/cpu.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080045#include <linux/delay.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080046#include <linux/stat.h>
Paul E. McKenneyb2896d22006-10-04 02:17:03 -070047#include <linux/srcu.h>
Robert P. J. Day1aeb2722008-04-29 00:59:25 -070048#include <linux/slab.h>
Harvey Harrisonf07767f2008-10-20 10:23:38 -070049#include <asm/byteorder.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080050
51MODULE_LICENSE("GPL");
Josh Triplettb772e1d2006-10-04 02:17:13 -070052MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and "
53 "Josh Triplett <josh@freedesktop.org>");
Paul E. McKenneya241ec62005-10-30 15:03:12 -080054
Josh Triplett48022112006-10-03 23:26:16 +020055static int nreaders = -1; /* # reader threads, defaults to 2*ncpus */
Josh Triplettb772e1d2006-10-04 02:17:13 -070056static int nfakewriters = 4; /* # fake writer threads */
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080057static int stat_interval; /* Interval between stats, in seconds. */
Paul E. McKenneya241ec62005-10-30 15:03:12 -080058 /* Defaults to "only at end of test". */
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080059static int verbose; /* Print more debug info. */
60static int test_no_idle_hz; /* Test RCU's support for tickless idle CPUs. */
Paul E. McKenneyd120f652008-06-18 05:21:44 -070061static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/
62static int stutter = 5; /* Start/stop testing interval (in sec) */
Paul E. McKenney0729fbf2008-06-25 12:24:52 -070063static int irqreader = 1; /* RCU readers from irq (timers). */
Josh Triplett20d2e422006-10-04 02:17:15 -070064static char *torture_type = "rcu"; /* What RCU implementation to torture. */
Paul E. McKenneya241ec62005-10-30 15:03:12 -080065
Josh Triplettd6ad6712007-03-06 01:42:13 -080066module_param(nreaders, int, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080067MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
Josh Triplettd6ad6712007-03-06 01:42:13 -080068module_param(nfakewriters, int, 0444);
Josh Triplettb772e1d2006-10-04 02:17:13 -070069MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
Josh Triplettd6ad6712007-03-06 01:42:13 -080070module_param(stat_interval, int, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080071MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
Josh Triplettd6ad6712007-03-06 01:42:13 -080072module_param(verbose, bool, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080073MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
Josh Triplettd6ad6712007-03-06 01:42:13 -080074module_param(test_no_idle_hz, bool, 0444);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080075MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
Josh Triplettd6ad6712007-03-06 01:42:13 -080076module_param(shuffle_interval, int, 0444);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080077MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
Paul E. McKenneyd120f652008-06-18 05:21:44 -070078module_param(stutter, int, 0444);
79MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
Paul E. McKenney0729fbf2008-06-25 12:24:52 -070080module_param(irqreader, int, 0444);
81MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
Josh Triplettd6ad6712007-03-06 01:42:13 -080082module_param(torture_type, charp, 0444);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -070083MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -070084
85#define TORTURE_FLAG "-torture:"
Paul E. McKenneya241ec62005-10-30 15:03:12 -080086#define PRINTK_STRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -070087 do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -080088#define VERBOSE_PRINTK_STRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -070089 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -080090#define VERBOSE_PRINTK_ERRSTRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -070091 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -080092
93static char printk_buf[4096];
94
95static int nrealreaders;
96static struct task_struct *writer_task;
Josh Triplettb772e1d2006-10-04 02:17:13 -070097static struct task_struct **fakewriter_tasks;
Paul E. McKenneya241ec62005-10-30 15:03:12 -080098static struct task_struct **reader_tasks;
99static struct task_struct *stats_task;
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800100static struct task_struct *shuffler_task;
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700101static struct task_struct *stutter_task;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800102
103#define RCU_TORTURE_PIPE_LEN 10
104
105struct rcu_torture {
106 struct rcu_head rtort_rcu;
107 int rtort_pipe_count;
108 struct list_head rtort_free;
Paul E. McKenney996417d2005-11-18 01:10:50 -0800109 int rtort_mbtest;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800110};
111
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800112static LIST_HEAD(rcu_torture_freelist);
113static struct rcu_torture *rcu_torture_current = NULL;
114static long rcu_torture_current_version = 0;
115static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
116static DEFINE_SPINLOCK(rcu_torture_lock);
117static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
118 { 0 };
119static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
120 { 0 };
121static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700122static atomic_t n_rcu_torture_alloc;
123static atomic_t n_rcu_torture_alloc_fail;
124static atomic_t n_rcu_torture_free;
125static atomic_t n_rcu_torture_mberror;
126static atomic_t n_rcu_torture_error;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700127static long n_rcu_torture_timers = 0;
Josh Triplette3033732006-10-04 02:17:14 -0700128static struct list_head rcu_torture_removed;
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600129static cpumask_var_t shuffle_tmp_mask;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800130
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700131static int stutter_pause_test = 0;
132
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700133#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
134#define RCUTORTURE_RUNNABLE_INIT 1
135#else
136#define RCUTORTURE_RUNNABLE_INIT 0
137#endif
138int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
139
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800140/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
141
142#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
143#define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
144#define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
145static int fullstop = FULLSTOP_RMMOD;
146DEFINE_MUTEX(fullstop_mutex); /* Protect fullstop transitions and spawning */
147 /* of kthreads. */
Paul E. McKenney343e9092008-12-15 16:13:07 -0800148
149/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800150 * Detect and respond to a system shutdown.
Paul E. McKenney343e9092008-12-15 16:13:07 -0800151 */
152static int
153rcutorture_shutdown_notify(struct notifier_block *unused1,
154 unsigned long unused2, void *unused3)
155{
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800156 mutex_lock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800157 if (fullstop == FULLSTOP_DONTSTOP)
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800158 fullstop = FULLSTOP_SHUTDOWN;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800159 else
160 printk(KERN_WARNING /* but going down anyway, so... */
161 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800162 mutex_unlock(&fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800163 return NOTIFY_DONE;
164}
165
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800166/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800167 * Absorb kthreads into a kernel function that won't return, so that
168 * they won't ever access module text or data again.
169 */
170static void rcutorture_shutdown_absorb(char *title)
171{
172 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
173 printk(KERN_NOTICE
174 "rcutorture thread %s parking due to system shutdown\n",
175 title);
176 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
177 }
178}
179
180/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800181 * Allocate an element from the rcu_tortures pool.
182 */
Adrian Bunk97a41e22006-01-08 01:02:17 -0800183static struct rcu_torture *
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800184rcu_torture_alloc(void)
185{
186 struct list_head *p;
187
Ingo Molnaradac1662006-01-25 19:50:12 +0100188 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800189 if (list_empty(&rcu_torture_freelist)) {
190 atomic_inc(&n_rcu_torture_alloc_fail);
Ingo Molnaradac1662006-01-25 19:50:12 +0100191 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800192 return NULL;
193 }
194 atomic_inc(&n_rcu_torture_alloc);
195 p = rcu_torture_freelist.next;
196 list_del_init(p);
Ingo Molnaradac1662006-01-25 19:50:12 +0100197 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800198 return container_of(p, struct rcu_torture, rtort_free);
199}
200
201/*
202 * Free an element to the rcu_tortures pool.
203 */
204static void
205rcu_torture_free(struct rcu_torture *p)
206{
207 atomic_inc(&n_rcu_torture_free);
Ingo Molnaradac1662006-01-25 19:50:12 +0100208 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800209 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
Ingo Molnaradac1662006-01-25 19:50:12 +0100210 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800211}
212
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800213struct rcu_random_state {
214 unsigned long rrs_state;
Josh Triplett75cfef32006-10-04 02:17:12 -0700215 long rrs_count;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800216};
217
218#define RCU_RANDOM_MULT 39916801 /* prime */
219#define RCU_RANDOM_ADD 479001701 /* prime */
220#define RCU_RANDOM_REFRESH 10000
221
222#define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
223
224/*
225 * Crude but fast random-number generator. Uses a linear congruential
Paul E. McKenneyc17ac852007-10-16 23:27:19 -0700226 * generator, with occasional help from cpu_clock().
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800227 */
Josh Triplett75cfef32006-10-04 02:17:12 -0700228static unsigned long
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800229rcu_random(struct rcu_random_state *rrsp)
230{
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800231 if (--rrsp->rrs_count < 0) {
Paul E. McKenneyc17ac852007-10-16 23:27:19 -0700232 rrsp->rrs_state +=
233 (unsigned long)cpu_clock(raw_smp_processor_id());
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800234 rrsp->rrs_count = RCU_RANDOM_REFRESH;
235 }
236 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
237 return swahw32(rrsp->rrs_state);
238}
239
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700240static void
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800241rcu_stutter_wait(char *title)
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700242{
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800243 while (stutter_pause_test || !rcutorture_runnable) {
Paul E. McKenneye3d7be22008-06-22 13:06:38 -0700244 if (rcutorture_runnable)
245 schedule_timeout_interruptible(1);
246 else
Paul E. McKenney3ccf79f2008-06-22 14:02:55 -0700247 schedule_timeout_interruptible(round_jiffies_relative(HZ));
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800248 rcutorture_shutdown_absorb(title);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800249 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700250}
251
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800252/*
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700253 * Operations vector for selecting different types of tests.
254 */
255
256struct rcu_torture_ops {
257 void (*init)(void);
258 void (*cleanup)(void);
259 int (*readlock)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700260 void (*read_delay)(struct rcu_random_state *rrsp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700261 void (*readunlock)(int idx);
262 int (*completed)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700263 void (*deferred_free)(struct rcu_torture *p);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700264 void (*sync)(void);
Paul E. McKenney23269742008-05-12 21:21:05 +0200265 void (*cb_barrier)(void);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700266 int (*stats)(char *page);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700267 int irq_capable;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700268 char *name;
269};
270static struct rcu_torture_ops *cur_ops = NULL;
271
272/*
273 * Definitions for rcu torture testing.
274 */
275
Josh Tripletta49a4af2006-09-29 01:59:30 -0700276static int rcu_torture_read_lock(void) __acquires(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700277{
278 rcu_read_lock();
279 return 0;
280}
281
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700282static void rcu_read_delay(struct rcu_random_state *rrsp)
283{
Josh Triplettb8d57a72009-09-08 15:54:35 -0700284 const unsigned long shortdelay_us = 200;
285 const unsigned long longdelay_ms = 50;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700286
Josh Triplettb8d57a72009-09-08 15:54:35 -0700287 /* We want a short delay sometimes to make a reader delay the grace
288 * period, and we want a long delay occasionally to trigger
289 * force_quiescent_state. */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700290
Josh Triplettb8d57a72009-09-08 15:54:35 -0700291 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
292 mdelay(longdelay_ms);
293 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
294 udelay(shortdelay_us);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700295}
296
Josh Tripletta49a4af2006-09-29 01:59:30 -0700297static void rcu_torture_read_unlock(int idx) __releases(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700298{
299 rcu_read_unlock();
300}
301
302static int rcu_torture_completed(void)
303{
304 return rcu_batches_completed();
305}
306
307static void
308rcu_torture_cb(struct rcu_head *p)
309{
310 int i;
311 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
312
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800313 if (fullstop != FULLSTOP_DONTSTOP) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700314 /* Test is ending, just drop callbacks on the floor. */
315 /* The next initialization will pick up the pieces. */
316 return;
317 }
318 i = rp->rtort_pipe_count;
319 if (i > RCU_TORTURE_PIPE_LEN)
320 i = RCU_TORTURE_PIPE_LEN;
321 atomic_inc(&rcu_torture_wcount[i]);
322 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
323 rp->rtort_mbtest = 0;
324 rcu_torture_free(rp);
325 } else
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700326 cur_ops->deferred_free(rp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700327}
328
329static void rcu_torture_deferred_free(struct rcu_torture *p)
330{
331 call_rcu(&p->rtort_rcu, rcu_torture_cb);
332}
333
334static struct rcu_torture_ops rcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700335 .init = NULL,
336 .cleanup = NULL,
337 .readlock = rcu_torture_read_lock,
338 .read_delay = rcu_read_delay,
339 .readunlock = rcu_torture_read_unlock,
340 .completed = rcu_torture_completed,
341 .deferred_free = rcu_torture_deferred_free,
342 .sync = synchronize_rcu,
343 .cb_barrier = rcu_barrier,
344 .stats = NULL,
345 .irq_capable = 1,
346 .name = "rcu"
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700347};
348
Josh Triplette3033732006-10-04 02:17:14 -0700349static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
350{
351 int i;
352 struct rcu_torture *rp;
353 struct rcu_torture *rp1;
354
355 cur_ops->sync();
356 list_add(&p->rtort_free, &rcu_torture_removed);
357 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
358 i = rp->rtort_pipe_count;
359 if (i > RCU_TORTURE_PIPE_LEN)
360 i = RCU_TORTURE_PIPE_LEN;
361 atomic_inc(&rcu_torture_wcount[i]);
362 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
363 rp->rtort_mbtest = 0;
364 list_del(&rp->rtort_free);
365 rcu_torture_free(rp);
366 }
367 }
368}
369
370static void rcu_sync_torture_init(void)
371{
372 INIT_LIST_HEAD(&rcu_torture_removed);
373}
374
Josh Triplett20d2e422006-10-04 02:17:15 -0700375static struct rcu_torture_ops rcu_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700376 .init = rcu_sync_torture_init,
377 .cleanup = NULL,
378 .readlock = rcu_torture_read_lock,
379 .read_delay = rcu_read_delay,
380 .readunlock = rcu_torture_read_unlock,
381 .completed = rcu_torture_completed,
382 .deferred_free = rcu_sync_torture_deferred_free,
383 .sync = synchronize_rcu,
384 .cb_barrier = NULL,
385 .stats = NULL,
386 .irq_capable = 1,
387 .name = "rcu_sync"
Josh Triplett20d2e422006-10-04 02:17:15 -0700388};
389
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700390/*
391 * Definitions for rcu_bh torture testing.
392 */
393
Josh Tripletta49a4af2006-09-29 01:59:30 -0700394static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700395{
396 rcu_read_lock_bh();
397 return 0;
398}
399
Josh Tripletta49a4af2006-09-29 01:59:30 -0700400static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700401{
402 rcu_read_unlock_bh();
403}
404
405static int rcu_bh_torture_completed(void)
406{
407 return rcu_batches_completed_bh();
408}
409
410static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
411{
412 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
413}
414
Josh Triplettb772e1d2006-10-04 02:17:13 -0700415struct rcu_bh_torture_synchronize {
416 struct rcu_head head;
417 struct completion completion;
418};
419
420static void rcu_bh_torture_wakeme_after_cb(struct rcu_head *head)
421{
422 struct rcu_bh_torture_synchronize *rcu;
423
424 rcu = container_of(head, struct rcu_bh_torture_synchronize, head);
425 complete(&rcu->completion);
426}
427
428static void rcu_bh_torture_synchronize(void)
429{
430 struct rcu_bh_torture_synchronize rcu;
431
432 init_completion(&rcu.completion);
433 call_rcu_bh(&rcu.head, rcu_bh_torture_wakeme_after_cb);
434 wait_for_completion(&rcu.completion);
435}
436
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700437static struct rcu_torture_ops rcu_bh_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700438 .init = NULL,
439 .cleanup = NULL,
440 .readlock = rcu_bh_torture_read_lock,
441 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
442 .readunlock = rcu_bh_torture_read_unlock,
443 .completed = rcu_bh_torture_completed,
444 .deferred_free = rcu_bh_torture_deferred_free,
445 .sync = rcu_bh_torture_synchronize,
446 .cb_barrier = rcu_barrier_bh,
447 .stats = NULL,
448 .irq_capable = 1,
449 .name = "rcu_bh"
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700450};
451
Josh Triplett11a14702006-10-04 02:17:16 -0700452static struct rcu_torture_ops rcu_bh_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700453 .init = rcu_sync_torture_init,
454 .cleanup = NULL,
455 .readlock = rcu_bh_torture_read_lock,
456 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
457 .readunlock = rcu_bh_torture_read_unlock,
458 .completed = rcu_bh_torture_completed,
459 .deferred_free = rcu_sync_torture_deferred_free,
460 .sync = rcu_bh_torture_synchronize,
461 .cb_barrier = NULL,
462 .stats = NULL,
463 .irq_capable = 1,
464 .name = "rcu_bh_sync"
Josh Triplett11a14702006-10-04 02:17:16 -0700465};
466
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700467/*
468 * Definitions for srcu torture testing.
469 */
470
471static struct srcu_struct srcu_ctl;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700472
473static void srcu_torture_init(void)
474{
475 init_srcu_struct(&srcu_ctl);
Josh Triplette3033732006-10-04 02:17:14 -0700476 rcu_sync_torture_init();
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700477}
478
479static void srcu_torture_cleanup(void)
480{
481 synchronize_srcu(&srcu_ctl);
482 cleanup_srcu_struct(&srcu_ctl);
483}
484
Josh Triplett012d3ca2006-12-06 20:40:19 -0800485static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700486{
487 return srcu_read_lock(&srcu_ctl);
488}
489
490static void srcu_read_delay(struct rcu_random_state *rrsp)
491{
492 long delay;
493 const long uspertick = 1000000 / HZ;
494 const long longdelay = 10;
495
496 /* We want there to be long-running readers, but not all the time. */
497
498 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
499 if (!delay)
500 schedule_timeout_interruptible(longdelay);
501}
502
Josh Triplett012d3ca2006-12-06 20:40:19 -0800503static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700504{
505 srcu_read_unlock(&srcu_ctl, idx);
506}
507
508static int srcu_torture_completed(void)
509{
510 return srcu_batches_completed(&srcu_ctl);
511}
512
Josh Triplettb772e1d2006-10-04 02:17:13 -0700513static void srcu_torture_synchronize(void)
514{
515 synchronize_srcu(&srcu_ctl);
516}
517
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700518static int srcu_torture_stats(char *page)
519{
520 int cnt = 0;
521 int cpu;
522 int idx = srcu_ctl.completed & 0x1;
523
524 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
525 torture_type, TORTURE_FLAG, idx);
526 for_each_possible_cpu(cpu) {
527 cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu,
528 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
529 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
530 }
531 cnt += sprintf(&page[cnt], "\n");
532 return cnt;
533}
534
535static struct rcu_torture_ops srcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700536 .init = srcu_torture_init,
537 .cleanup = srcu_torture_cleanup,
538 .readlock = srcu_torture_read_lock,
539 .read_delay = srcu_read_delay,
540 .readunlock = srcu_torture_read_unlock,
541 .completed = srcu_torture_completed,
542 .deferred_free = rcu_sync_torture_deferred_free,
543 .sync = srcu_torture_synchronize,
544 .cb_barrier = NULL,
545 .stats = srcu_torture_stats,
546 .name = "srcu"
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700547};
548
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700549/*
550 * Definitions for sched torture testing.
551 */
552
553static int sched_torture_read_lock(void)
554{
555 preempt_disable();
556 return 0;
557}
558
559static void sched_torture_read_unlock(int idx)
560{
561 preempt_enable();
562}
563
564static int sched_torture_completed(void)
565{
566 return 0;
567}
568
Paul E. McKenney23269742008-05-12 21:21:05 +0200569static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
570{
571 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
572}
573
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700574static void sched_torture_synchronize(void)
575{
576 synchronize_sched();
577}
578
579static struct rcu_torture_ops sched_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700580 .init = rcu_sync_torture_init,
581 .cleanup = NULL,
582 .readlock = sched_torture_read_lock,
583 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
584 .readunlock = sched_torture_read_unlock,
585 .completed = sched_torture_completed,
586 .deferred_free = rcu_sched_torture_deferred_free,
587 .sync = sched_torture_synchronize,
588 .cb_barrier = rcu_barrier_sched,
589 .stats = NULL,
590 .irq_capable = 1,
591 .name = "sched"
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700592};
593
Paul E. McKenney23269742008-05-12 21:21:05 +0200594static struct rcu_torture_ops sched_ops_sync = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700595 .init = rcu_sync_torture_init,
596 .cleanup = NULL,
597 .readlock = sched_torture_read_lock,
598 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
599 .readunlock = sched_torture_read_unlock,
600 .completed = sched_torture_completed,
601 .deferred_free = rcu_sync_torture_deferred_free,
602 .sync = sched_torture_synchronize,
603 .cb_barrier = NULL,
604 .stats = NULL,
605 .name = "sched_sync"
606};
607
608extern int rcu_expedited_torture_stats(char *page);
609
610static struct rcu_torture_ops sched_expedited_ops = {
611 .init = rcu_sync_torture_init,
612 .cleanup = NULL,
613 .readlock = sched_torture_read_lock,
614 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
615 .readunlock = sched_torture_read_unlock,
616 .completed = sched_torture_completed,
617 .deferred_free = rcu_sync_torture_deferred_free,
618 .sync = synchronize_sched_expedited,
619 .cb_barrier = NULL,
620 .stats = rcu_expedited_torture_stats,
621 .irq_capable = 1,
622 .name = "sched_expedited"
Paul E. McKenney23269742008-05-12 21:21:05 +0200623};
624
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700625/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800626 * RCU torture writer kthread. Repeatedly substitutes a new structure
627 * for that pointed to by rcu_torture_current, freeing the old structure
628 * after a series of grace periods (the "pipeline").
629 */
630static int
631rcu_torture_writer(void *arg)
632{
633 int i;
634 long oldbatch = rcu_batches_completed();
635 struct rcu_torture *rp;
636 struct rcu_torture *old_rp;
637 static DEFINE_RCU_RANDOM(rand);
638
639 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800640 set_user_nice(current, 19);
641
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800642 do {
643 schedule_timeout_uninterruptible(1);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800644 if ((rp = rcu_torture_alloc()) == NULL)
645 continue;
646 rp->rtort_pipe_count = 0;
647 udelay(rcu_random(&rand) & 0x3ff);
648 old_rp = rcu_torture_current;
Paul E. McKenney996417d2005-11-18 01:10:50 -0800649 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800650 rcu_assign_pointer(rcu_torture_current, rp);
651 smp_wmb();
Josh Triplettc8e5b162007-05-08 00:33:20 -0700652 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800653 i = old_rp->rtort_pipe_count;
654 if (i > RCU_TORTURE_PIPE_LEN)
655 i = RCU_TORTURE_PIPE_LEN;
656 atomic_inc(&rcu_torture_wcount[i]);
657 old_rp->rtort_pipe_count++;
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700658 cur_ops->deferred_free(old_rp);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800659 }
660 rcu_torture_current_version++;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700661 oldbatch = cur_ops->completed();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800662 rcu_stutter_wait("rcu_torture_writer");
663 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800664 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800665 rcutorture_shutdown_absorb("rcu_torture_writer");
666 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800667 schedule_timeout_uninterruptible(1);
668 return 0;
669}
670
671/*
Josh Triplettb772e1d2006-10-04 02:17:13 -0700672 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
673 * delay between calls.
674 */
675static int
676rcu_torture_fakewriter(void *arg)
677{
678 DEFINE_RCU_RANDOM(rand);
679
680 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
681 set_user_nice(current, 19);
682
683 do {
684 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
685 udelay(rcu_random(&rand) & 0x3ff);
686 cur_ops->sync();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800687 rcu_stutter_wait("rcu_torture_fakewriter");
688 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700689
690 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800691 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
692 while (!kthread_should_stop())
Josh Triplettb772e1d2006-10-04 02:17:13 -0700693 schedule_timeout_uninterruptible(1);
694 return 0;
695}
696
697/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700698 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
699 * incrementing the corresponding element of the pipeline array. The
700 * counter in the element should never be greater than 1, otherwise, the
701 * RCU implementation is broken.
702 */
703static void rcu_torture_timer(unsigned long unused)
704{
705 int idx;
706 int completed;
707 static DEFINE_RCU_RANDOM(rand);
708 static DEFINE_SPINLOCK(rand_lock);
709 struct rcu_torture *p;
710 int pipe_count;
711
712 idx = cur_ops->readlock();
713 completed = cur_ops->completed();
714 p = rcu_dereference(rcu_torture_current);
715 if (p == NULL) {
716 /* Leave because rcu_torture_writer is not yet underway */
717 cur_ops->readunlock(idx);
718 return;
719 }
720 if (p->rtort_mbtest == 0)
721 atomic_inc(&n_rcu_torture_mberror);
722 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700723 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700724 n_rcu_torture_timers++;
725 spin_unlock(&rand_lock);
726 preempt_disable();
727 pipe_count = p->rtort_pipe_count;
728 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
729 /* Should not happen, but... */
730 pipe_count = RCU_TORTURE_PIPE_LEN;
731 }
732 ++__get_cpu_var(rcu_torture_count)[pipe_count];
733 completed = cur_ops->completed() - completed;
734 if (completed > RCU_TORTURE_PIPE_LEN) {
735 /* Should not happen, but... */
736 completed = RCU_TORTURE_PIPE_LEN;
737 }
738 ++__get_cpu_var(rcu_torture_batch)[completed];
739 preempt_enable();
740 cur_ops->readunlock(idx);
741}
742
743/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800744 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
745 * incrementing the corresponding element of the pipeline array. The
746 * counter in the element should never be greater than 1, otherwise, the
747 * RCU implementation is broken.
748 */
749static int
750rcu_torture_reader(void *arg)
751{
752 int completed;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700753 int idx;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800754 DEFINE_RCU_RANDOM(rand);
755 struct rcu_torture *p;
756 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700757 struct timer_list t;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800758
759 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800760 set_user_nice(current, 19);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700761 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700762 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800763
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800764 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700765 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700766 if (!timer_pending(&t))
767 mod_timer(&t, 1);
768 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700769 idx = cur_ops->readlock();
770 completed = cur_ops->completed();
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800771 p = rcu_dereference(rcu_torture_current);
772 if (p == NULL) {
773 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700774 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800775 schedule_timeout_interruptible(HZ);
776 continue;
777 }
Paul E. McKenney996417d2005-11-18 01:10:50 -0800778 if (p->rtort_mbtest == 0)
779 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700780 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800781 preempt_disable();
782 pipe_count = p->rtort_pipe_count;
783 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
784 /* Should not happen, but... */
785 pipe_count = RCU_TORTURE_PIPE_LEN;
786 }
787 ++__get_cpu_var(rcu_torture_count)[pipe_count];
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700788 completed = cur_ops->completed() - completed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800789 if (completed > RCU_TORTURE_PIPE_LEN) {
790 /* Should not happen, but... */
791 completed = RCU_TORTURE_PIPE_LEN;
792 }
793 ++__get_cpu_var(rcu_torture_batch)[completed];
794 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700795 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800796 schedule();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800797 rcu_stutter_wait("rcu_torture_reader");
798 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800799 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800800 rcutorture_shutdown_absorb("rcu_torture_reader");
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700801 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700802 del_timer_sync(&t);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800803 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800804 schedule_timeout_uninterruptible(1);
805 return 0;
806}
807
808/*
809 * Create an RCU-torture statistics message in the specified buffer.
810 */
811static int
812rcu_torture_printk(char *page)
813{
814 int cnt = 0;
815 int cpu;
816 int i;
817 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
818 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
819
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -0800820 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800821 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
822 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
823 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
824 }
825 }
826 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
827 if (pipesummary[i] != 0)
828 break;
829 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700830 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800831 cnt += sprintf(&page[cnt],
Paul E. McKenney996417d2005-11-18 01:10:50 -0800832 "rtc: %p ver: %ld tfle: %d rta: %d rtaf: %d rtf: %d "
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700833 "rtmbe: %d nt: %ld",
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800834 rcu_torture_current,
835 rcu_torture_current_version,
836 list_empty(&rcu_torture_freelist),
837 atomic_read(&n_rcu_torture_alloc),
838 atomic_read(&n_rcu_torture_alloc_fail),
Paul E. McKenney996417d2005-11-18 01:10:50 -0800839 atomic_read(&n_rcu_torture_free),
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700840 atomic_read(&n_rcu_torture_mberror),
841 n_rcu_torture_timers);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800842 if (atomic_read(&n_rcu_torture_mberror) != 0)
843 cnt += sprintf(&page[cnt], " !!!");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700844 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800845 if (i > 1) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800846 cnt += sprintf(&page[cnt], "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -0800847 atomic_inc(&n_rcu_torture_error);
Ingo Molnar5af970a2008-06-18 10:09:48 +0200848 WARN_ON_ONCE(1);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800849 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800850 cnt += sprintf(&page[cnt], "Reader Pipe: ");
851 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
852 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700853 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800854 cnt += sprintf(&page[cnt], "Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700855 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800856 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700857 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800858 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
859 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
860 cnt += sprintf(&page[cnt], " %d",
861 atomic_read(&rcu_torture_wcount[i]));
862 }
863 cnt += sprintf(&page[cnt], "\n");
Josh Triplettc8e5b162007-05-08 00:33:20 -0700864 if (cur_ops->stats)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700865 cnt += cur_ops->stats(&page[cnt]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800866 return cnt;
867}
868
869/*
870 * Print torture statistics. Caller must ensure that there is only
871 * one call to this function at a given time!!! This is normally
872 * accomplished by relying on the module system to only have one copy
873 * of the module loaded, and then by giving the rcu_torture_stats
874 * kthread full control (or the init/cleanup functions when rcu_torture_stats
875 * thread is not running).
876 */
877static void
878rcu_torture_stats_print(void)
879{
880 int cnt;
881
882 cnt = rcu_torture_printk(printk_buf);
883 printk(KERN_ALERT "%s", printk_buf);
884}
885
886/*
887 * Periodically prints torture statistics, if periodic statistics printing
888 * was specified via the stat_interval module parameter.
889 *
890 * No need to worry about fullstop here, since this one doesn't reference
891 * volatile state or register callbacks.
892 */
893static int
894rcu_torture_stats(void *arg)
895{
896 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
897 do {
898 schedule_timeout_interruptible(stat_interval * HZ);
899 rcu_torture_stats_print();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800900 rcutorture_shutdown_absorb("rcu_torture_stats");
901 } while (!kthread_should_stop());
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800902 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
903 return 0;
904}
905
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800906static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
907
908/* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
909 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
910 */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700911static void rcu_torture_shuffle_tasks(void)
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800912{
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800913 int i;
914
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600915 cpumask_setall(shuffle_tmp_mask);
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +0100916 get_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800917
918 /* No point in shuffling if there is only one online CPU (ex: UP) */
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800919 if (num_online_cpus() == 1) {
920 put_online_cpus();
921 return;
922 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800923
924 if (rcu_idle_cpu != -1)
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600925 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800926
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600927 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800928
Josh Triplettc8e5b162007-05-08 00:33:20 -0700929 if (reader_tasks) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800930 for (i = 0; i < nrealreaders; i++)
931 if (reader_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -0700932 set_cpus_allowed_ptr(reader_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600933 shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800934 }
935
Josh Triplettc8e5b162007-05-08 00:33:20 -0700936 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -0700937 for (i = 0; i < nfakewriters; i++)
938 if (fakewriter_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -0700939 set_cpus_allowed_ptr(fakewriter_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600940 shuffle_tmp_mask);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700941 }
942
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800943 if (writer_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600944 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800945
946 if (stats_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600947 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800948
949 if (rcu_idle_cpu == -1)
950 rcu_idle_cpu = num_online_cpus() - 1;
951 else
952 rcu_idle_cpu--;
953
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +0100954 put_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800955}
956
957/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
958 * system to become idle at a time and cut off its timer ticks. This is meant
959 * to test the support for such tickless idle CPU in RCU.
960 */
961static int
962rcu_torture_shuffle(void *arg)
963{
964 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
965 do {
966 schedule_timeout_interruptible(shuffle_interval * HZ);
967 rcu_torture_shuffle_tasks();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800968 rcutorture_shutdown_absorb("rcu_torture_shuffle");
969 } while (!kthread_should_stop());
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800970 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
971 return 0;
972}
973
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700974/* Cause the rcutorture test to "stutter", starting and stopping all
975 * threads periodically.
976 */
977static int
978rcu_torture_stutter(void *arg)
979{
980 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
981 do {
982 schedule_timeout_interruptible(stutter * HZ);
983 stutter_pause_test = 1;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800984 if (!kthread_should_stop())
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700985 schedule_timeout_interruptible(stutter * HZ);
986 stutter_pause_test = 0;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800987 rcutorture_shutdown_absorb("rcu_torture_stutter");
988 } while (!kthread_should_stop());
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700989 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
990 return 0;
991}
992
Paul E. McKenney95c38322006-03-24 03:15:58 -0800993static inline void
994rcu_torture_print_module_parms(char *tag)
995{
Josh Triplettb772e1d2006-10-04 02:17:13 -0700996 printk(KERN_ALERT "%s" TORTURE_FLAG
997 "--- %s: nreaders=%d nfakewriters=%d "
Paul E. McKenney95c38322006-03-24 03:15:58 -0800998 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700999 "shuffle_interval=%d stutter=%d irqreader=%d\n",
Josh Triplettb772e1d2006-10-04 02:17:13 -07001000 torture_type, tag, nrealreaders, nfakewriters,
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001001 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001002 stutter, irqreader);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001003}
1004
Paul E. McKenney343e9092008-12-15 16:13:07 -08001005static struct notifier_block rcutorture_nb = {
1006 .notifier_call = rcutorture_shutdown_notify,
1007};
1008
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001009static void
1010rcu_torture_cleanup(void)
1011{
1012 int i;
1013
Paul E. McKenney343e9092008-12-15 16:13:07 -08001014 mutex_lock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001015 if (fullstop == FULLSTOP_SHUTDOWN) {
1016 printk(KERN_WARNING /* but going down anyway, so... */
1017 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001018 mutex_unlock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001019 schedule_timeout_uninterruptible(10);
Paul E. McKenney343e9092008-12-15 16:13:07 -08001020 if (cur_ops->cb_barrier != NULL)
1021 cur_ops->cb_barrier();
1022 return;
1023 }
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001024 fullstop = FULLSTOP_RMMOD;
Paul E. McKenney343e9092008-12-15 16:13:07 -08001025 mutex_unlock(&fullstop_mutex);
1026 unregister_reboot_notifier(&rcutorture_nb);
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001027 if (stutter_task) {
1028 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1029 kthread_stop(stutter_task);
1030 }
1031 stutter_task = NULL;
Josh Triplettc8e5b162007-05-08 00:33:20 -07001032 if (shuffler_task) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001033 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1034 kthread_stop(shuffler_task);
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001035 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001036 }
1037 shuffler_task = NULL;
1038
Josh Triplettc8e5b162007-05-08 00:33:20 -07001039 if (writer_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001040 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1041 kthread_stop(writer_task);
1042 }
1043 writer_task = NULL;
1044
Josh Triplettc8e5b162007-05-08 00:33:20 -07001045 if (reader_tasks) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001046 for (i = 0; i < nrealreaders; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001047 if (reader_tasks[i]) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001048 VERBOSE_PRINTK_STRING(
1049 "Stopping rcu_torture_reader task");
1050 kthread_stop(reader_tasks[i]);
1051 }
1052 reader_tasks[i] = NULL;
1053 }
1054 kfree(reader_tasks);
1055 reader_tasks = NULL;
1056 }
1057 rcu_torture_current = NULL;
1058
Josh Triplettc8e5b162007-05-08 00:33:20 -07001059 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001060 for (i = 0; i < nfakewriters; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001061 if (fakewriter_tasks[i]) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001062 VERBOSE_PRINTK_STRING(
1063 "Stopping rcu_torture_fakewriter task");
1064 kthread_stop(fakewriter_tasks[i]);
1065 }
1066 fakewriter_tasks[i] = NULL;
1067 }
1068 kfree(fakewriter_tasks);
1069 fakewriter_tasks = NULL;
1070 }
1071
Josh Triplettc8e5b162007-05-08 00:33:20 -07001072 if (stats_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001073 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1074 kthread_stop(stats_task);
1075 }
1076 stats_task = NULL;
1077
1078 /* Wait for all RCU callbacks to fire. */
Paul E. McKenney23269742008-05-12 21:21:05 +02001079
1080 if (cur_ops->cb_barrier != NULL)
1081 cur_ops->cb_barrier();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001082
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001083 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001084
Josh Triplettc8e5b162007-05-08 00:33:20 -07001085 if (cur_ops->cleanup)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001086 cur_ops->cleanup();
Paul E. McKenney95c38322006-03-24 03:15:58 -08001087 if (atomic_read(&n_rcu_torture_error))
1088 rcu_torture_print_module_parms("End of test: FAILURE");
1089 else
1090 rcu_torture_print_module_parms("End of test: SUCCESS");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001091}
1092
Josh Triplett6f8bc502007-05-08 00:25:24 -07001093static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001094rcu_torture_init(void)
1095{
1096 int i;
1097 int cpu;
1098 int firsterr = 0;
Josh Triplettade5fb82007-05-08 00:33:22 -07001099 static struct rcu_torture_ops *torture_ops[] =
1100 { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops,
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001101 &sched_expedited_ops,
Paul E. McKenney23269742008-05-12 21:21:05 +02001102 &srcu_ops, &sched_ops, &sched_ops_sync, };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001103
Paul E. McKenney343e9092008-12-15 16:13:07 -08001104 mutex_lock(&fullstop_mutex);
1105
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001106 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001107 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001108 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001109 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001110 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001111 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001112 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001113 printk(KERN_ALERT "rcutorture: invalid torture type: \"%s\"\n",
1114 torture_type);
Paul E. McKenney343e9092008-12-15 16:13:07 -08001115 mutex_unlock(&fullstop_mutex);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001116 return (-EINVAL);
1117 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001118 if (cur_ops->init)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001119 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1120
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001121 if (nreaders >= 0)
1122 nrealreaders = nreaders;
1123 else
1124 nrealreaders = 2 * num_online_cpus();
Paul E. McKenney95c38322006-03-24 03:15:58 -08001125 rcu_torture_print_module_parms("Start of test");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001126 fullstop = FULLSTOP_DONTSTOP;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001127
1128 /* Set up the freelist. */
1129
1130 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07001131 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08001132 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001133 list_add_tail(&rcu_tortures[i].rtort_free,
1134 &rcu_torture_freelist);
1135 }
1136
1137 /* Initialize the statistics so that each run gets its own numbers. */
1138
1139 rcu_torture_current = NULL;
1140 rcu_torture_current_version = 0;
1141 atomic_set(&n_rcu_torture_alloc, 0);
1142 atomic_set(&n_rcu_torture_alloc_fail, 0);
1143 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001144 atomic_set(&n_rcu_torture_mberror, 0);
1145 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001146 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1147 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001148 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001149 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1150 per_cpu(rcu_torture_count, cpu)[i] = 0;
1151 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1152 }
1153 }
1154
1155 /* Start up the kthreads. */
1156
1157 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1158 writer_task = kthread_run(rcu_torture_writer, NULL,
1159 "rcu_torture_writer");
1160 if (IS_ERR(writer_task)) {
1161 firsterr = PTR_ERR(writer_task);
1162 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1163 writer_task = NULL;
1164 goto unwind;
1165 }
Josh Triplettb772e1d2006-10-04 02:17:13 -07001166 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
1167 GFP_KERNEL);
1168 if (fakewriter_tasks == NULL) {
1169 VERBOSE_PRINTK_ERRSTRING("out of memory");
1170 firsterr = -ENOMEM;
1171 goto unwind;
1172 }
1173 for (i = 0; i < nfakewriters; i++) {
1174 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
1175 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
1176 "rcu_torture_fakewriter");
1177 if (IS_ERR(fakewriter_tasks[i])) {
1178 firsterr = PTR_ERR(fakewriter_tasks[i]);
1179 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
1180 fakewriter_tasks[i] = NULL;
1181 goto unwind;
1182 }
1183 }
Josh Triplett2860aab2006-10-04 02:17:11 -07001184 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001185 GFP_KERNEL);
1186 if (reader_tasks == NULL) {
1187 VERBOSE_PRINTK_ERRSTRING("out of memory");
1188 firsterr = -ENOMEM;
1189 goto unwind;
1190 }
1191 for (i = 0; i < nrealreaders; i++) {
1192 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
1193 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
1194 "rcu_torture_reader");
1195 if (IS_ERR(reader_tasks[i])) {
1196 firsterr = PTR_ERR(reader_tasks[i]);
1197 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
1198 reader_tasks[i] = NULL;
1199 goto unwind;
1200 }
1201 }
1202 if (stat_interval > 0) {
1203 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
1204 stats_task = kthread_run(rcu_torture_stats, NULL,
1205 "rcu_torture_stats");
1206 if (IS_ERR(stats_task)) {
1207 firsterr = PTR_ERR(stats_task);
1208 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
1209 stats_task = NULL;
1210 goto unwind;
1211 }
1212 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001213 if (test_no_idle_hz) {
1214 rcu_idle_cpu = num_online_cpus() - 1;
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001215
1216 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
1217 firsterr = -ENOMEM;
1218 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
1219 goto unwind;
1220 }
1221
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001222 /* Create the shuffler thread */
1223 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
1224 "rcu_torture_shuffle");
1225 if (IS_ERR(shuffler_task)) {
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001226 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001227 firsterr = PTR_ERR(shuffler_task);
1228 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
1229 shuffler_task = NULL;
1230 goto unwind;
1231 }
1232 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001233 if (stutter < 0)
1234 stutter = 0;
1235 if (stutter) {
1236 /* Create the stutter thread */
1237 stutter_task = kthread_run(rcu_torture_stutter, NULL,
1238 "rcu_torture_stutter");
1239 if (IS_ERR(stutter_task)) {
1240 firsterr = PTR_ERR(stutter_task);
1241 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
1242 stutter_task = NULL;
1243 goto unwind;
1244 }
1245 }
Paul E. McKenney343e9092008-12-15 16:13:07 -08001246 register_reboot_notifier(&rcutorture_nb);
1247 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001248 return 0;
1249
1250unwind:
Paul E. McKenney343e9092008-12-15 16:13:07 -08001251 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001252 rcu_torture_cleanup();
1253 return firsterr;
1254}
1255
1256module_init(rcu_torture_init);
1257module_exit(rcu_torture_cleanup);