blob: 233768f21f9735845c32c6ee9e3b27974a73e3b8 [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>
Paul E. McKenneya71fca52009-09-18 10:28:19 -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 "
Paul E. McKenneya71fca52009-09-18 10:28:19 -070053 "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);
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700113static struct rcu_torture *rcu_torture_current;
114static long rcu_torture_current_version;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800115static 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. McKenneya71fca52009-09-18 10:28:19 -0700127static long n_rcu_torture_timers;
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. McKenneya71fca52009-09-18 10:28:19 -0700131static int stutter_pause_test;
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700132
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};
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700270
271static struct rcu_torture_ops *cur_ops;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700272
273/*
274 * Definitions for rcu torture testing.
275 */
276
Josh Tripletta49a4af2006-09-29 01:59:30 -0700277static int rcu_torture_read_lock(void) __acquires(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700278{
279 rcu_read_lock();
280 return 0;
281}
282
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700283static void rcu_read_delay(struct rcu_random_state *rrsp)
284{
Josh Triplettb8d57a72009-09-08 15:54:35 -0700285 const unsigned long shortdelay_us = 200;
286 const unsigned long longdelay_ms = 50;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700287
Josh Triplettb8d57a72009-09-08 15:54:35 -0700288 /* We want a short delay sometimes to make a reader delay the grace
289 * period, and we want a long delay occasionally to trigger
290 * force_quiescent_state. */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700291
Josh Triplettb8d57a72009-09-08 15:54:35 -0700292 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
293 mdelay(longdelay_ms);
294 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
295 udelay(shortdelay_us);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700296}
297
Josh Tripletta49a4af2006-09-29 01:59:30 -0700298static void rcu_torture_read_unlock(int idx) __releases(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700299{
300 rcu_read_unlock();
301}
302
303static int rcu_torture_completed(void)
304{
305 return rcu_batches_completed();
306}
307
308static void
309rcu_torture_cb(struct rcu_head *p)
310{
311 int i;
312 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
313
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800314 if (fullstop != FULLSTOP_DONTSTOP) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700315 /* Test is ending, just drop callbacks on the floor. */
316 /* The next initialization will pick up the pieces. */
317 return;
318 }
319 i = rp->rtort_pipe_count;
320 if (i > RCU_TORTURE_PIPE_LEN)
321 i = RCU_TORTURE_PIPE_LEN;
322 atomic_inc(&rcu_torture_wcount[i]);
323 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
324 rp->rtort_mbtest = 0;
325 rcu_torture_free(rp);
326 } else
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700327 cur_ops->deferred_free(rp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700328}
329
330static void rcu_torture_deferred_free(struct rcu_torture *p)
331{
332 call_rcu(&p->rtort_rcu, rcu_torture_cb);
333}
334
335static struct rcu_torture_ops rcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700336 .init = NULL,
337 .cleanup = NULL,
338 .readlock = rcu_torture_read_lock,
339 .read_delay = rcu_read_delay,
340 .readunlock = rcu_torture_read_unlock,
341 .completed = rcu_torture_completed,
342 .deferred_free = rcu_torture_deferred_free,
343 .sync = synchronize_rcu,
344 .cb_barrier = rcu_barrier,
345 .stats = NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700346 .irq_capable = 1,
347 .name = "rcu"
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700348};
349
Josh Triplette3033732006-10-04 02:17:14 -0700350static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
351{
352 int i;
353 struct rcu_torture *rp;
354 struct rcu_torture *rp1;
355
356 cur_ops->sync();
357 list_add(&p->rtort_free, &rcu_torture_removed);
358 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
359 i = rp->rtort_pipe_count;
360 if (i > RCU_TORTURE_PIPE_LEN)
361 i = RCU_TORTURE_PIPE_LEN;
362 atomic_inc(&rcu_torture_wcount[i]);
363 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
364 rp->rtort_mbtest = 0;
365 list_del(&rp->rtort_free);
366 rcu_torture_free(rp);
367 }
368 }
369}
370
371static void rcu_sync_torture_init(void)
372{
373 INIT_LIST_HEAD(&rcu_torture_removed);
374}
375
Josh Triplett20d2e422006-10-04 02:17:15 -0700376static struct rcu_torture_ops rcu_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700377 .init = rcu_sync_torture_init,
378 .cleanup = NULL,
379 .readlock = rcu_torture_read_lock,
380 .read_delay = rcu_read_delay,
381 .readunlock = rcu_torture_read_unlock,
382 .completed = rcu_torture_completed,
383 .deferred_free = rcu_sync_torture_deferred_free,
384 .sync = synchronize_rcu,
385 .cb_barrier = NULL,
386 .stats = NULL,
387 .irq_capable = 1,
388 .name = "rcu_sync"
Josh Triplett20d2e422006-10-04 02:17:15 -0700389};
390
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700391/*
392 * Definitions for rcu_bh torture testing.
393 */
394
Josh Tripletta49a4af2006-09-29 01:59:30 -0700395static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700396{
397 rcu_read_lock_bh();
398 return 0;
399}
400
Josh Tripletta49a4af2006-09-29 01:59:30 -0700401static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700402{
403 rcu_read_unlock_bh();
404}
405
406static int rcu_bh_torture_completed(void)
407{
408 return rcu_batches_completed_bh();
409}
410
411static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
412{
413 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
414}
415
Josh Triplettb772e1d2006-10-04 02:17:13 -0700416struct rcu_bh_torture_synchronize {
417 struct rcu_head head;
418 struct completion completion;
419};
420
421static void rcu_bh_torture_wakeme_after_cb(struct rcu_head *head)
422{
423 struct rcu_bh_torture_synchronize *rcu;
424
425 rcu = container_of(head, struct rcu_bh_torture_synchronize, head);
426 complete(&rcu->completion);
427}
428
429static void rcu_bh_torture_synchronize(void)
430{
431 struct rcu_bh_torture_synchronize rcu;
432
433 init_completion(&rcu.completion);
434 call_rcu_bh(&rcu.head, rcu_bh_torture_wakeme_after_cb);
435 wait_for_completion(&rcu.completion);
436}
437
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700438static struct rcu_torture_ops rcu_bh_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700439 .init = NULL,
440 .cleanup = NULL,
441 .readlock = rcu_bh_torture_read_lock,
442 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
443 .readunlock = rcu_bh_torture_read_unlock,
444 .completed = rcu_bh_torture_completed,
445 .deferred_free = rcu_bh_torture_deferred_free,
446 .sync = rcu_bh_torture_synchronize,
447 .cb_barrier = rcu_barrier_bh,
448 .stats = NULL,
449 .irq_capable = 1,
450 .name = "rcu_bh"
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700451};
452
Josh Triplett11a14702006-10-04 02:17:16 -0700453static struct rcu_torture_ops rcu_bh_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700454 .init = rcu_sync_torture_init,
455 .cleanup = NULL,
456 .readlock = rcu_bh_torture_read_lock,
457 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
458 .readunlock = rcu_bh_torture_read_unlock,
459 .completed = rcu_bh_torture_completed,
460 .deferred_free = rcu_sync_torture_deferred_free,
461 .sync = rcu_bh_torture_synchronize,
462 .cb_barrier = NULL,
463 .stats = NULL,
464 .irq_capable = 1,
465 .name = "rcu_bh_sync"
Josh Triplett11a14702006-10-04 02:17:16 -0700466};
467
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700468/*
469 * Definitions for srcu torture testing.
470 */
471
472static struct srcu_struct srcu_ctl;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700473
474static void srcu_torture_init(void)
475{
476 init_srcu_struct(&srcu_ctl);
Josh Triplette3033732006-10-04 02:17:14 -0700477 rcu_sync_torture_init();
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700478}
479
480static void srcu_torture_cleanup(void)
481{
482 synchronize_srcu(&srcu_ctl);
483 cleanup_srcu_struct(&srcu_ctl);
484}
485
Josh Triplett012d3ca2006-12-06 20:40:19 -0800486static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700487{
488 return srcu_read_lock(&srcu_ctl);
489}
490
491static void srcu_read_delay(struct rcu_random_state *rrsp)
492{
493 long delay;
494 const long uspertick = 1000000 / HZ;
495 const long longdelay = 10;
496
497 /* We want there to be long-running readers, but not all the time. */
498
499 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
500 if (!delay)
501 schedule_timeout_interruptible(longdelay);
502}
503
Josh Triplett012d3ca2006-12-06 20:40:19 -0800504static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700505{
506 srcu_read_unlock(&srcu_ctl, idx);
507}
508
509static int srcu_torture_completed(void)
510{
511 return srcu_batches_completed(&srcu_ctl);
512}
513
Josh Triplettb772e1d2006-10-04 02:17:13 -0700514static void srcu_torture_synchronize(void)
515{
516 synchronize_srcu(&srcu_ctl);
517}
518
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700519static int srcu_torture_stats(char *page)
520{
521 int cnt = 0;
522 int cpu;
523 int idx = srcu_ctl.completed & 0x1;
524
525 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
526 torture_type, TORTURE_FLAG, idx);
527 for_each_possible_cpu(cpu) {
528 cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu,
529 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
530 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
531 }
532 cnt += sprintf(&page[cnt], "\n");
533 return cnt;
534}
535
536static struct rcu_torture_ops srcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700537 .init = srcu_torture_init,
538 .cleanup = srcu_torture_cleanup,
539 .readlock = srcu_torture_read_lock,
540 .read_delay = srcu_read_delay,
541 .readunlock = srcu_torture_read_unlock,
542 .completed = srcu_torture_completed,
543 .deferred_free = rcu_sync_torture_deferred_free,
544 .sync = srcu_torture_synchronize,
545 .cb_barrier = NULL,
546 .stats = srcu_torture_stats,
547 .name = "srcu"
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700548};
549
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700550/*
551 * Definitions for sched torture testing.
552 */
553
554static int sched_torture_read_lock(void)
555{
556 preempt_disable();
557 return 0;
558}
559
560static void sched_torture_read_unlock(int idx)
561{
562 preempt_enable();
563}
564
565static int sched_torture_completed(void)
566{
567 return 0;
568}
569
Paul E. McKenney23269742008-05-12 21:21:05 +0200570static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
571{
572 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
573}
574
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700575static void sched_torture_synchronize(void)
576{
577 synchronize_sched();
578}
579
580static struct rcu_torture_ops sched_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700581 .init = rcu_sync_torture_init,
582 .cleanup = NULL,
583 .readlock = sched_torture_read_lock,
584 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
585 .readunlock = sched_torture_read_unlock,
586 .completed = sched_torture_completed,
587 .deferred_free = rcu_sched_torture_deferred_free,
588 .sync = sched_torture_synchronize,
589 .cb_barrier = rcu_barrier_sched,
590 .stats = NULL,
591 .irq_capable = 1,
592 .name = "sched"
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700593};
594
Paul E. McKenney23269742008-05-12 21:21:05 +0200595static struct rcu_torture_ops sched_ops_sync = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700596 .init = rcu_sync_torture_init,
597 .cleanup = NULL,
598 .readlock = sched_torture_read_lock,
599 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
600 .readunlock = sched_torture_read_unlock,
601 .completed = sched_torture_completed,
602 .deferred_free = rcu_sync_torture_deferred_free,
603 .sync = sched_torture_synchronize,
604 .cb_barrier = NULL,
605 .stats = NULL,
606 .name = "sched_sync"
607};
608
609extern int rcu_expedited_torture_stats(char *page);
610
611static struct rcu_torture_ops sched_expedited_ops = {
612 .init = rcu_sync_torture_init,
613 .cleanup = NULL,
614 .readlock = sched_torture_read_lock,
615 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
616 .readunlock = sched_torture_read_unlock,
617 .completed = sched_torture_completed,
618 .deferred_free = rcu_sync_torture_deferred_free,
619 .sync = synchronize_sched_expedited,
620 .cb_barrier = NULL,
621 .stats = rcu_expedited_torture_stats,
622 .irq_capable = 1,
623 .name = "sched_expedited"
Paul E. McKenney23269742008-05-12 21:21:05 +0200624};
625
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700626/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800627 * RCU torture writer kthread. Repeatedly substitutes a new structure
628 * for that pointed to by rcu_torture_current, freeing the old structure
629 * after a series of grace periods (the "pipeline").
630 */
631static int
632rcu_torture_writer(void *arg)
633{
634 int i;
635 long oldbatch = rcu_batches_completed();
636 struct rcu_torture *rp;
637 struct rcu_torture *old_rp;
638 static DEFINE_RCU_RANDOM(rand);
639
640 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800641 set_user_nice(current, 19);
642
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800643 do {
644 schedule_timeout_uninterruptible(1);
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700645 rp = rcu_torture_alloc();
646 if (rp == NULL)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800647 continue;
648 rp->rtort_pipe_count = 0;
649 udelay(rcu_random(&rand) & 0x3ff);
650 old_rp = rcu_torture_current;
Paul E. McKenney996417d2005-11-18 01:10:50 -0800651 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800652 rcu_assign_pointer(rcu_torture_current, rp);
653 smp_wmb();
Josh Triplettc8e5b162007-05-08 00:33:20 -0700654 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800655 i = old_rp->rtort_pipe_count;
656 if (i > RCU_TORTURE_PIPE_LEN)
657 i = RCU_TORTURE_PIPE_LEN;
658 atomic_inc(&rcu_torture_wcount[i]);
659 old_rp->rtort_pipe_count++;
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700660 cur_ops->deferred_free(old_rp);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800661 }
662 rcu_torture_current_version++;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700663 oldbatch = cur_ops->completed();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800664 rcu_stutter_wait("rcu_torture_writer");
665 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800666 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800667 rcutorture_shutdown_absorb("rcu_torture_writer");
668 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800669 schedule_timeout_uninterruptible(1);
670 return 0;
671}
672
673/*
Josh Triplettb772e1d2006-10-04 02:17:13 -0700674 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
675 * delay between calls.
676 */
677static int
678rcu_torture_fakewriter(void *arg)
679{
680 DEFINE_RCU_RANDOM(rand);
681
682 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
683 set_user_nice(current, 19);
684
685 do {
686 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
687 udelay(rcu_random(&rand) & 0x3ff);
688 cur_ops->sync();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800689 rcu_stutter_wait("rcu_torture_fakewriter");
690 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700691
692 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800693 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
694 while (!kthread_should_stop())
Josh Triplettb772e1d2006-10-04 02:17:13 -0700695 schedule_timeout_uninterruptible(1);
696 return 0;
697}
698
699/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700700 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
701 * incrementing the corresponding element of the pipeline array. The
702 * counter in the element should never be greater than 1, otherwise, the
703 * RCU implementation is broken.
704 */
705static void rcu_torture_timer(unsigned long unused)
706{
707 int idx;
708 int completed;
709 static DEFINE_RCU_RANDOM(rand);
710 static DEFINE_SPINLOCK(rand_lock);
711 struct rcu_torture *p;
712 int pipe_count;
713
714 idx = cur_ops->readlock();
715 completed = cur_ops->completed();
716 p = rcu_dereference(rcu_torture_current);
717 if (p == NULL) {
718 /* Leave because rcu_torture_writer is not yet underway */
719 cur_ops->readunlock(idx);
720 return;
721 }
722 if (p->rtort_mbtest == 0)
723 atomic_inc(&n_rcu_torture_mberror);
724 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700725 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700726 n_rcu_torture_timers++;
727 spin_unlock(&rand_lock);
728 preempt_disable();
729 pipe_count = p->rtort_pipe_count;
730 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
731 /* Should not happen, but... */
732 pipe_count = RCU_TORTURE_PIPE_LEN;
733 }
734 ++__get_cpu_var(rcu_torture_count)[pipe_count];
735 completed = cur_ops->completed() - completed;
736 if (completed > RCU_TORTURE_PIPE_LEN) {
737 /* Should not happen, but... */
738 completed = RCU_TORTURE_PIPE_LEN;
739 }
740 ++__get_cpu_var(rcu_torture_batch)[completed];
741 preempt_enable();
742 cur_ops->readunlock(idx);
743}
744
745/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800746 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
747 * incrementing the corresponding element of the pipeline array. The
748 * counter in the element should never be greater than 1, otherwise, the
749 * RCU implementation is broken.
750 */
751static int
752rcu_torture_reader(void *arg)
753{
754 int completed;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700755 int idx;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800756 DEFINE_RCU_RANDOM(rand);
757 struct rcu_torture *p;
758 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700759 struct timer_list t;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800760
761 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800762 set_user_nice(current, 19);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700763 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700764 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800765
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800766 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700767 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700768 if (!timer_pending(&t))
769 mod_timer(&t, 1);
770 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700771 idx = cur_ops->readlock();
772 completed = cur_ops->completed();
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800773 p = rcu_dereference(rcu_torture_current);
774 if (p == NULL) {
775 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700776 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800777 schedule_timeout_interruptible(HZ);
778 continue;
779 }
Paul E. McKenney996417d2005-11-18 01:10:50 -0800780 if (p->rtort_mbtest == 0)
781 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700782 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800783 preempt_disable();
784 pipe_count = p->rtort_pipe_count;
785 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
786 /* Should not happen, but... */
787 pipe_count = RCU_TORTURE_PIPE_LEN;
788 }
789 ++__get_cpu_var(rcu_torture_count)[pipe_count];
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700790 completed = cur_ops->completed() - completed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800791 if (completed > RCU_TORTURE_PIPE_LEN) {
792 /* Should not happen, but... */
793 completed = RCU_TORTURE_PIPE_LEN;
794 }
795 ++__get_cpu_var(rcu_torture_batch)[completed];
796 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700797 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800798 schedule();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800799 rcu_stutter_wait("rcu_torture_reader");
800 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800801 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800802 rcutorture_shutdown_absorb("rcu_torture_reader");
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700803 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700804 del_timer_sync(&t);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800805 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800806 schedule_timeout_uninterruptible(1);
807 return 0;
808}
809
810/*
811 * Create an RCU-torture statistics message in the specified buffer.
812 */
813static int
814rcu_torture_printk(char *page)
815{
816 int cnt = 0;
817 int cpu;
818 int i;
819 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
820 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
821
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -0800822 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800823 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
824 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
825 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
826 }
827 }
828 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
829 if (pipesummary[i] != 0)
830 break;
831 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700832 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800833 cnt += sprintf(&page[cnt],
Paul E. McKenney996417d2005-11-18 01:10:50 -0800834 "rtc: %p ver: %ld tfle: %d rta: %d rtaf: %d rtf: %d "
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700835 "rtmbe: %d nt: %ld",
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800836 rcu_torture_current,
837 rcu_torture_current_version,
838 list_empty(&rcu_torture_freelist),
839 atomic_read(&n_rcu_torture_alloc),
840 atomic_read(&n_rcu_torture_alloc_fail),
Paul E. McKenney996417d2005-11-18 01:10:50 -0800841 atomic_read(&n_rcu_torture_free),
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700842 atomic_read(&n_rcu_torture_mberror),
843 n_rcu_torture_timers);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800844 if (atomic_read(&n_rcu_torture_mberror) != 0)
845 cnt += sprintf(&page[cnt], " !!!");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700846 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800847 if (i > 1) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800848 cnt += sprintf(&page[cnt], "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -0800849 atomic_inc(&n_rcu_torture_error);
Ingo Molnar5af970a2008-06-18 10:09:48 +0200850 WARN_ON_ONCE(1);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800851 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800852 cnt += sprintf(&page[cnt], "Reader Pipe: ");
853 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
854 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700855 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800856 cnt += sprintf(&page[cnt], "Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700857 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800858 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700859 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800860 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
861 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
862 cnt += sprintf(&page[cnt], " %d",
863 atomic_read(&rcu_torture_wcount[i]));
864 }
865 cnt += sprintf(&page[cnt], "\n");
Josh Triplettc8e5b162007-05-08 00:33:20 -0700866 if (cur_ops->stats)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700867 cnt += cur_ops->stats(&page[cnt]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800868 return cnt;
869}
870
871/*
872 * Print torture statistics. Caller must ensure that there is only
873 * one call to this function at a given time!!! This is normally
874 * accomplished by relying on the module system to only have one copy
875 * of the module loaded, and then by giving the rcu_torture_stats
876 * kthread full control (or the init/cleanup functions when rcu_torture_stats
877 * thread is not running).
878 */
879static void
880rcu_torture_stats_print(void)
881{
882 int cnt;
883
884 cnt = rcu_torture_printk(printk_buf);
885 printk(KERN_ALERT "%s", printk_buf);
886}
887
888/*
889 * Periodically prints torture statistics, if periodic statistics printing
890 * was specified via the stat_interval module parameter.
891 *
892 * No need to worry about fullstop here, since this one doesn't reference
893 * volatile state or register callbacks.
894 */
895static int
896rcu_torture_stats(void *arg)
897{
898 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
899 do {
900 schedule_timeout_interruptible(stat_interval * HZ);
901 rcu_torture_stats_print();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800902 rcutorture_shutdown_absorb("rcu_torture_stats");
903 } while (!kthread_should_stop());
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800904 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
905 return 0;
906}
907
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800908static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
909
910/* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
911 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
912 */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700913static void rcu_torture_shuffle_tasks(void)
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800914{
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800915 int i;
916
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600917 cpumask_setall(shuffle_tmp_mask);
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +0100918 get_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800919
920 /* No point in shuffling if there is only one online CPU (ex: UP) */
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800921 if (num_online_cpus() == 1) {
922 put_online_cpus();
923 return;
924 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800925
926 if (rcu_idle_cpu != -1)
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600927 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800928
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600929 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800930
Josh Triplettc8e5b162007-05-08 00:33:20 -0700931 if (reader_tasks) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800932 for (i = 0; i < nrealreaders; i++)
933 if (reader_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -0700934 set_cpus_allowed_ptr(reader_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600935 shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800936 }
937
Josh Triplettc8e5b162007-05-08 00:33:20 -0700938 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -0700939 for (i = 0; i < nfakewriters; i++)
940 if (fakewriter_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -0700941 set_cpus_allowed_ptr(fakewriter_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600942 shuffle_tmp_mask);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700943 }
944
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800945 if (writer_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600946 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800947
948 if (stats_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600949 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800950
951 if (rcu_idle_cpu == -1)
952 rcu_idle_cpu = num_online_cpus() - 1;
953 else
954 rcu_idle_cpu--;
955
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +0100956 put_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800957}
958
959/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
960 * system to become idle at a time and cut off its timer ticks. This is meant
961 * to test the support for such tickless idle CPU in RCU.
962 */
963static int
964rcu_torture_shuffle(void *arg)
965{
966 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
967 do {
968 schedule_timeout_interruptible(shuffle_interval * HZ);
969 rcu_torture_shuffle_tasks();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800970 rcutorture_shutdown_absorb("rcu_torture_shuffle");
971 } while (!kthread_should_stop());
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800972 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
973 return 0;
974}
975
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700976/* Cause the rcutorture test to "stutter", starting and stopping all
977 * threads periodically.
978 */
979static int
980rcu_torture_stutter(void *arg)
981{
982 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
983 do {
984 schedule_timeout_interruptible(stutter * HZ);
985 stutter_pause_test = 1;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800986 if (!kthread_should_stop())
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700987 schedule_timeout_interruptible(stutter * HZ);
988 stutter_pause_test = 0;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800989 rcutorture_shutdown_absorb("rcu_torture_stutter");
990 } while (!kthread_should_stop());
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700991 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
992 return 0;
993}
994
Paul E. McKenney95c38322006-03-24 03:15:58 -0800995static inline void
996rcu_torture_print_module_parms(char *tag)
997{
Josh Triplettb772e1d2006-10-04 02:17:13 -0700998 printk(KERN_ALERT "%s" TORTURE_FLAG
999 "--- %s: nreaders=%d nfakewriters=%d "
Paul E. McKenney95c38322006-03-24 03:15:58 -08001000 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001001 "shuffle_interval=%d stutter=%d irqreader=%d\n",
Josh Triplettb772e1d2006-10-04 02:17:13 -07001002 torture_type, tag, nrealreaders, nfakewriters,
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001003 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001004 stutter, irqreader);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001005}
1006
Paul E. McKenney343e9092008-12-15 16:13:07 -08001007static struct notifier_block rcutorture_nb = {
1008 .notifier_call = rcutorture_shutdown_notify,
1009};
1010
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001011static void
1012rcu_torture_cleanup(void)
1013{
1014 int i;
1015
Paul E. McKenney343e9092008-12-15 16:13:07 -08001016 mutex_lock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001017 if (fullstop == FULLSTOP_SHUTDOWN) {
1018 printk(KERN_WARNING /* but going down anyway, so... */
1019 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001020 mutex_unlock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001021 schedule_timeout_uninterruptible(10);
Paul E. McKenney343e9092008-12-15 16:13:07 -08001022 if (cur_ops->cb_barrier != NULL)
1023 cur_ops->cb_barrier();
1024 return;
1025 }
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001026 fullstop = FULLSTOP_RMMOD;
Paul E. McKenney343e9092008-12-15 16:13:07 -08001027 mutex_unlock(&fullstop_mutex);
1028 unregister_reboot_notifier(&rcutorture_nb);
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001029 if (stutter_task) {
1030 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1031 kthread_stop(stutter_task);
1032 }
1033 stutter_task = NULL;
Josh Triplettc8e5b162007-05-08 00:33:20 -07001034 if (shuffler_task) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001035 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1036 kthread_stop(shuffler_task);
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001037 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001038 }
1039 shuffler_task = NULL;
1040
Josh Triplettc8e5b162007-05-08 00:33:20 -07001041 if (writer_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001042 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1043 kthread_stop(writer_task);
1044 }
1045 writer_task = NULL;
1046
Josh Triplettc8e5b162007-05-08 00:33:20 -07001047 if (reader_tasks) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001048 for (i = 0; i < nrealreaders; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001049 if (reader_tasks[i]) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001050 VERBOSE_PRINTK_STRING(
1051 "Stopping rcu_torture_reader task");
1052 kthread_stop(reader_tasks[i]);
1053 }
1054 reader_tasks[i] = NULL;
1055 }
1056 kfree(reader_tasks);
1057 reader_tasks = NULL;
1058 }
1059 rcu_torture_current = NULL;
1060
Josh Triplettc8e5b162007-05-08 00:33:20 -07001061 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001062 for (i = 0; i < nfakewriters; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001063 if (fakewriter_tasks[i]) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001064 VERBOSE_PRINTK_STRING(
1065 "Stopping rcu_torture_fakewriter task");
1066 kthread_stop(fakewriter_tasks[i]);
1067 }
1068 fakewriter_tasks[i] = NULL;
1069 }
1070 kfree(fakewriter_tasks);
1071 fakewriter_tasks = NULL;
1072 }
1073
Josh Triplettc8e5b162007-05-08 00:33:20 -07001074 if (stats_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001075 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1076 kthread_stop(stats_task);
1077 }
1078 stats_task = NULL;
1079
1080 /* Wait for all RCU callbacks to fire. */
Paul E. McKenney23269742008-05-12 21:21:05 +02001081
1082 if (cur_ops->cb_barrier != NULL)
1083 cur_ops->cb_barrier();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001084
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001085 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001086
Josh Triplettc8e5b162007-05-08 00:33:20 -07001087 if (cur_ops->cleanup)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001088 cur_ops->cleanup();
Paul E. McKenney95c38322006-03-24 03:15:58 -08001089 if (atomic_read(&n_rcu_torture_error))
1090 rcu_torture_print_module_parms("End of test: FAILURE");
1091 else
1092 rcu_torture_print_module_parms("End of test: SUCCESS");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001093}
1094
Josh Triplett6f8bc502007-05-08 00:25:24 -07001095static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001096rcu_torture_init(void)
1097{
1098 int i;
1099 int cpu;
1100 int firsterr = 0;
Josh Triplettade5fb82007-05-08 00:33:22 -07001101 static struct rcu_torture_ops *torture_ops[] =
1102 { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops,
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001103 &sched_expedited_ops,
Paul E. McKenney23269742008-05-12 21:21:05 +02001104 &srcu_ops, &sched_ops, &sched_ops_sync, };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001105
Paul E. McKenney343e9092008-12-15 16:13:07 -08001106 mutex_lock(&fullstop_mutex);
1107
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001108 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001109 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001110 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001111 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001112 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001113 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001114 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001115 printk(KERN_ALERT "rcutorture: invalid torture type: \"%s\"\n",
1116 torture_type);
Paul E. McKenney343e9092008-12-15 16:13:07 -08001117 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001118 return -EINVAL;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001119 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001120 if (cur_ops->init)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001121 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1122
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001123 if (nreaders >= 0)
1124 nrealreaders = nreaders;
1125 else
1126 nrealreaders = 2 * num_online_cpus();
Paul E. McKenney95c38322006-03-24 03:15:58 -08001127 rcu_torture_print_module_parms("Start of test");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001128 fullstop = FULLSTOP_DONTSTOP;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001129
1130 /* Set up the freelist. */
1131
1132 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07001133 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08001134 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001135 list_add_tail(&rcu_tortures[i].rtort_free,
1136 &rcu_torture_freelist);
1137 }
1138
1139 /* Initialize the statistics so that each run gets its own numbers. */
1140
1141 rcu_torture_current = NULL;
1142 rcu_torture_current_version = 0;
1143 atomic_set(&n_rcu_torture_alloc, 0);
1144 atomic_set(&n_rcu_torture_alloc_fail, 0);
1145 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001146 atomic_set(&n_rcu_torture_mberror, 0);
1147 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001148 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1149 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001150 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001151 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1152 per_cpu(rcu_torture_count, cpu)[i] = 0;
1153 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1154 }
1155 }
1156
1157 /* Start up the kthreads. */
1158
1159 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1160 writer_task = kthread_run(rcu_torture_writer, NULL,
1161 "rcu_torture_writer");
1162 if (IS_ERR(writer_task)) {
1163 firsterr = PTR_ERR(writer_task);
1164 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1165 writer_task = NULL;
1166 goto unwind;
1167 }
Josh Triplettb772e1d2006-10-04 02:17:13 -07001168 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001169 GFP_KERNEL);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001170 if (fakewriter_tasks == NULL) {
1171 VERBOSE_PRINTK_ERRSTRING("out of memory");
1172 firsterr = -ENOMEM;
1173 goto unwind;
1174 }
1175 for (i = 0; i < nfakewriters; i++) {
1176 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
1177 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001178 "rcu_torture_fakewriter");
Josh Triplettb772e1d2006-10-04 02:17:13 -07001179 if (IS_ERR(fakewriter_tasks[i])) {
1180 firsterr = PTR_ERR(fakewriter_tasks[i]);
1181 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
1182 fakewriter_tasks[i] = NULL;
1183 goto unwind;
1184 }
1185 }
Josh Triplett2860aab2006-10-04 02:17:11 -07001186 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001187 GFP_KERNEL);
1188 if (reader_tasks == NULL) {
1189 VERBOSE_PRINTK_ERRSTRING("out of memory");
1190 firsterr = -ENOMEM;
1191 goto unwind;
1192 }
1193 for (i = 0; i < nrealreaders; i++) {
1194 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
1195 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
1196 "rcu_torture_reader");
1197 if (IS_ERR(reader_tasks[i])) {
1198 firsterr = PTR_ERR(reader_tasks[i]);
1199 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
1200 reader_tasks[i] = NULL;
1201 goto unwind;
1202 }
1203 }
1204 if (stat_interval > 0) {
1205 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
1206 stats_task = kthread_run(rcu_torture_stats, NULL,
1207 "rcu_torture_stats");
1208 if (IS_ERR(stats_task)) {
1209 firsterr = PTR_ERR(stats_task);
1210 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
1211 stats_task = NULL;
1212 goto unwind;
1213 }
1214 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001215 if (test_no_idle_hz) {
1216 rcu_idle_cpu = num_online_cpus() - 1;
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001217
1218 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
1219 firsterr = -ENOMEM;
1220 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
1221 goto unwind;
1222 }
1223
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001224 /* Create the shuffler thread */
1225 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
1226 "rcu_torture_shuffle");
1227 if (IS_ERR(shuffler_task)) {
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001228 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001229 firsterr = PTR_ERR(shuffler_task);
1230 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
1231 shuffler_task = NULL;
1232 goto unwind;
1233 }
1234 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001235 if (stutter < 0)
1236 stutter = 0;
1237 if (stutter) {
1238 /* Create the stutter thread */
1239 stutter_task = kthread_run(rcu_torture_stutter, NULL,
1240 "rcu_torture_stutter");
1241 if (IS_ERR(stutter_task)) {
1242 firsterr = PTR_ERR(stutter_task);
1243 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
1244 stutter_task = NULL;
1245 goto unwind;
1246 }
1247 }
Paul E. McKenney343e9092008-12-15 16:13:07 -08001248 register_reboot_notifier(&rcutorture_nb);
1249 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001250 return 0;
1251
1252unwind:
Paul E. McKenney343e9092008-12-15 16:13:07 -08001253 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001254 rcu_torture_cleanup();
1255 return firsterr;
1256}
1257
1258module_init(rcu_torture_init);
1259module_exit(rcu_torture_cleanup);