]> bbs.cooldavid.org Git - net-next-2.6.git/blame - kernel/rcutorture.c
cpumask: use new cpumask_ functions in core code.
[net-next-2.6.git] / kernel / rcutorture.c
CommitLineData
a241ec65 1/*
29766f1e 2 * Read-Copy Update module-based torture test facility
a241ec65
PM
3 *
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 *
b772e1dd 18 * Copyright (C) IBM Corporation, 2005, 2006
a241ec65
PM
19 *
20 * Authors: Paul E. McKenney <paulmck@us.ibm.com>
b772e1dd 21 * Josh Triplett <josh@freedesktop.org>
a241ec65
PM
22 *
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>
a241ec65
PM
38#include <linux/completion.h>
39#include <linux/moduleparam.h>
40#include <linux/percpu.h>
41#include <linux/notifier.h>
343e9099 42#include <linux/reboot.h>
83144186 43#include <linux/freezer.h>
a241ec65 44#include <linux/cpu.h>
a241ec65 45#include <linux/delay.h>
a241ec65 46#include <linux/stat.h>
b2896d2e 47#include <linux/srcu.h>
1aeb272c 48#include <linux/slab.h>
f07767fd 49#include <asm/byteorder.h>
a241ec65
PM
50
51MODULE_LICENSE("GPL");
b772e1dd
JT
52MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and "
53 "Josh Triplett <josh@freedesktop.org>");
a241ec65 54
4802211c 55static int nreaders = -1; /* # reader threads, defaults to 2*ncpus */
b772e1dd 56static int nfakewriters = 4; /* # fake writer threads */
d84f5203 57static int stat_interval; /* Interval between stats, in seconds. */
a241ec65 58 /* Defaults to "only at end of test". */
d84f5203
SV
59static int verbose; /* Print more debug info. */
60static int test_no_idle_hz; /* Test RCU's support for tickless idle CPUs. */
d120f65f
PM
61static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/
62static int stutter = 5; /* Start/stop testing interval (in sec) */
0729fbf3 63static int irqreader = 1; /* RCU readers from irq (timers). */
20d2e428 64static char *torture_type = "rcu"; /* What RCU implementation to torture. */
a241ec65 65
d6ad6711 66module_param(nreaders, int, 0444);
a241ec65 67MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
d6ad6711 68module_param(nfakewriters, int, 0444);
b772e1dd 69MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
d6ad6711 70module_param(stat_interval, int, 0444);
a241ec65 71MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
d6ad6711 72module_param(verbose, bool, 0444);
a241ec65 73MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
d6ad6711 74module_param(test_no_idle_hz, bool, 0444);
d84f5203 75MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
d6ad6711 76module_param(shuffle_interval, int, 0444);
d84f5203 77MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
d120f65f
PM
78module_param(stutter, int, 0444);
79MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
0729fbf3
PM
80module_param(irqreader, int, 0444);
81MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
d6ad6711 82module_param(torture_type, charp, 0444);
b2896d2e 83MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
72e9bb54
PM
84
85#define TORTURE_FLAG "-torture:"
a241ec65 86#define PRINTK_STRING(s) \
72e9bb54 87 do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
a241ec65 88#define VERBOSE_PRINTK_STRING(s) \
72e9bb54 89 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
a241ec65 90#define VERBOSE_PRINTK_ERRSTRING(s) \
72e9bb54 91 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
a241ec65
PM
92
93static char printk_buf[4096];
94
95static int nrealreaders;
96static struct task_struct *writer_task;
b772e1dd 97static struct task_struct **fakewriter_tasks;
a241ec65
PM
98static struct task_struct **reader_tasks;
99static struct task_struct *stats_task;
d84f5203 100static struct task_struct *shuffler_task;
d120f65f 101static struct task_struct *stutter_task;
a241ec65
PM
102
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;
996417d2 109 int rtort_mbtest;
a241ec65
PM
110};
111
a241ec65
PM
112static 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];
b2896d2e
PM
122static 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;
0729fbf3 127static long n_rcu_torture_timers = 0;
e3033736 128static struct list_head rcu_torture_removed;
a241ec65 129
d120f65f
PM
130static int stutter_pause_test = 0;
131
31a72bce
PM
132#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
133#define RCUTORTURE_RUNNABLE_INIT 1
134#else
135#define RCUTORTURE_RUNNABLE_INIT 0
136#endif
137int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
138
c9d557c1
PM
139/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
140
141#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
142#define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
143#define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
144static int fullstop = FULLSTOP_RMMOD;
145DEFINE_MUTEX(fullstop_mutex); /* Protect fullstop transitions and spawning */
146 /* of kthreads. */
343e9099
PM
147
148/*
c9d557c1 149 * Detect and respond to a system shutdown.
343e9099
PM
150 */
151static int
152rcutorture_shutdown_notify(struct notifier_block *unused1,
153 unsigned long unused2, void *unused3)
154{
c59ab97e 155 mutex_lock(&fullstop_mutex);
c9d557c1 156 if (fullstop == FULLSTOP_DONTSTOP)
c59ab97e 157 fullstop = FULLSTOP_SHUTDOWN;
c9d557c1
PM
158 else
159 printk(KERN_WARNING /* but going down anyway, so... */
160 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
c59ab97e 161 mutex_unlock(&fullstop_mutex);
343e9099
PM
162 return NOTIFY_DONE;
163}
164
c9d557c1
PM
165/*
166 * Absorb kthreads into a kernel function that won't return, so that
167 * they won't ever access module text or data again.
168 */
169static void rcutorture_shutdown_absorb(char *title)
170{
171 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
172 printk(KERN_NOTICE
173 "rcutorture thread %s parking due to system shutdown\n",
174 title);
175 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
176 }
177}
178
a241ec65
PM
179/*
180 * Allocate an element from the rcu_tortures pool.
181 */
97a41e26 182static struct rcu_torture *
a241ec65
PM
183rcu_torture_alloc(void)
184{
185 struct list_head *p;
186
adac1665 187 spin_lock_bh(&rcu_torture_lock);
a241ec65
PM
188 if (list_empty(&rcu_torture_freelist)) {
189 atomic_inc(&n_rcu_torture_alloc_fail);
adac1665 190 spin_unlock_bh(&rcu_torture_lock);
a241ec65
PM
191 return NULL;
192 }
193 atomic_inc(&n_rcu_torture_alloc);
194 p = rcu_torture_freelist.next;
195 list_del_init(p);
adac1665 196 spin_unlock_bh(&rcu_torture_lock);
a241ec65
PM
197 return container_of(p, struct rcu_torture, rtort_free);
198}
199
200/*
201 * Free an element to the rcu_tortures pool.
202 */
203static void
204rcu_torture_free(struct rcu_torture *p)
205{
206 atomic_inc(&n_rcu_torture_free);
adac1665 207 spin_lock_bh(&rcu_torture_lock);
a241ec65 208 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
adac1665 209 spin_unlock_bh(&rcu_torture_lock);
a241ec65
PM
210}
211
a241ec65
PM
212struct rcu_random_state {
213 unsigned long rrs_state;
75cfef32 214 long rrs_count;
a241ec65
PM
215};
216
217#define RCU_RANDOM_MULT 39916801 /* prime */
218#define RCU_RANDOM_ADD 479001701 /* prime */
219#define RCU_RANDOM_REFRESH 10000
220
221#define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
222
223/*
224 * Crude but fast random-number generator. Uses a linear congruential
c17ac855 225 * generator, with occasional help from cpu_clock().
a241ec65 226 */
75cfef32 227static unsigned long
a241ec65
PM
228rcu_random(struct rcu_random_state *rrsp)
229{
a241ec65 230 if (--rrsp->rrs_count < 0) {
c17ac855
PM
231 rrsp->rrs_state +=
232 (unsigned long)cpu_clock(raw_smp_processor_id());
a241ec65
PM
233 rrsp->rrs_count = RCU_RANDOM_REFRESH;
234 }
235 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
236 return swahw32(rrsp->rrs_state);
237}
238
d120f65f 239static void
c9d557c1 240rcu_stutter_wait(char *title)
d120f65f 241{
c9d557c1 242 while (stutter_pause_test || !rcutorture_runnable) {
e3d7be27
PM
243 if (rcutorture_runnable)
244 schedule_timeout_interruptible(1);
245 else
3ccf79f4 246 schedule_timeout_interruptible(round_jiffies_relative(HZ));
c9d557c1 247 rcutorture_shutdown_absorb(title);
343e9099 248 }
d120f65f
PM
249}
250
72e9bb54
PM
251/*
252 * Operations vector for selecting different types of tests.
253 */
254
255struct rcu_torture_ops {
256 void (*init)(void);
257 void (*cleanup)(void);
258 int (*readlock)(void);
b2896d2e 259 void (*readdelay)(struct rcu_random_state *rrsp);
72e9bb54
PM
260 void (*readunlock)(int idx);
261 int (*completed)(void);
262 void (*deferredfree)(struct rcu_torture *p);
b772e1dd 263 void (*sync)(void);
2326974d 264 void (*cb_barrier)(void);
72e9bb54 265 int (*stats)(char *page);
0729fbf3 266 int irqcapable;
72e9bb54
PM
267 char *name;
268};
269static struct rcu_torture_ops *cur_ops = NULL;
270
271/*
272 * Definitions for rcu torture testing.
273 */
274
a49a4af7 275static int rcu_torture_read_lock(void) __acquires(RCU)
72e9bb54
PM
276{
277 rcu_read_lock();
278 return 0;
279}
280
b2896d2e
PM
281static void rcu_read_delay(struct rcu_random_state *rrsp)
282{
283 long delay;
284 const long longdelay = 200;
285
286 /* We want there to be long-running readers, but not all the time. */
287
288 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay);
289 if (!delay)
290 udelay(longdelay);
291}
292
a49a4af7 293static void rcu_torture_read_unlock(int idx) __releases(RCU)
72e9bb54
PM
294{
295 rcu_read_unlock();
296}
297
298static int rcu_torture_completed(void)
299{
300 return rcu_batches_completed();
301}
302
303static void
304rcu_torture_cb(struct rcu_head *p)
305{
306 int i;
307 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
308
c9d557c1 309 if (fullstop != FULLSTOP_DONTSTOP) {
72e9bb54
PM
310 /* Test is ending, just drop callbacks on the floor. */
311 /* The next initialization will pick up the pieces. */
312 return;
313 }
314 i = rp->rtort_pipe_count;
315 if (i > RCU_TORTURE_PIPE_LEN)
316 i = RCU_TORTURE_PIPE_LEN;
317 atomic_inc(&rcu_torture_wcount[i]);
318 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
319 rp->rtort_mbtest = 0;
320 rcu_torture_free(rp);
321 } else
322 cur_ops->deferredfree(rp);
323}
324
325static void rcu_torture_deferred_free(struct rcu_torture *p)
326{
327 call_rcu(&p->rtort_rcu, rcu_torture_cb);
328}
329
330static struct rcu_torture_ops rcu_ops = {
331 .init = NULL,
332 .cleanup = NULL,
333 .readlock = rcu_torture_read_lock,
b2896d2e 334 .readdelay = rcu_read_delay,
72e9bb54
PM
335 .readunlock = rcu_torture_read_unlock,
336 .completed = rcu_torture_completed,
337 .deferredfree = rcu_torture_deferred_free,
b772e1dd 338 .sync = synchronize_rcu,
2326974d 339 .cb_barrier = rcu_barrier,
72e9bb54 340 .stats = NULL,
0729fbf3 341 .irqcapable = 1,
72e9bb54
PM
342 .name = "rcu"
343};
344
e3033736
JT
345static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
346{
347 int i;
348 struct rcu_torture *rp;
349 struct rcu_torture *rp1;
350
351 cur_ops->sync();
352 list_add(&p->rtort_free, &rcu_torture_removed);
353 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
354 i = rp->rtort_pipe_count;
355 if (i > RCU_TORTURE_PIPE_LEN)
356 i = RCU_TORTURE_PIPE_LEN;
357 atomic_inc(&rcu_torture_wcount[i]);
358 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
359 rp->rtort_mbtest = 0;
360 list_del(&rp->rtort_free);
361 rcu_torture_free(rp);
362 }
363 }
364}
365
366static void rcu_sync_torture_init(void)
367{
368 INIT_LIST_HEAD(&rcu_torture_removed);
369}
370
20d2e428
JT
371static struct rcu_torture_ops rcu_sync_ops = {
372 .init = rcu_sync_torture_init,
373 .cleanup = NULL,
374 .readlock = rcu_torture_read_lock,
375 .readdelay = rcu_read_delay,
376 .readunlock = rcu_torture_read_unlock,
377 .completed = rcu_torture_completed,
378 .deferredfree = rcu_sync_torture_deferred_free,
379 .sync = synchronize_rcu,
2326974d 380 .cb_barrier = NULL,
20d2e428 381 .stats = NULL,
0729fbf3 382 .irqcapable = 1,
20d2e428
JT
383 .name = "rcu_sync"
384};
385
c32e0660
PM
386/*
387 * Definitions for rcu_bh torture testing.
388 */
389
a49a4af7 390static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
c32e0660
PM
391{
392 rcu_read_lock_bh();
393 return 0;
394}
395
a49a4af7 396static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
c32e0660
PM
397{
398 rcu_read_unlock_bh();
399}
400
401static int rcu_bh_torture_completed(void)
402{
403 return rcu_batches_completed_bh();
404}
405
406static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
407{
408 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
409}
410
b772e1dd
JT
411struct rcu_bh_torture_synchronize {
412 struct rcu_head head;
413 struct completion completion;
414};
415
416static void rcu_bh_torture_wakeme_after_cb(struct rcu_head *head)
417{
418 struct rcu_bh_torture_synchronize *rcu;
419
420 rcu = container_of(head, struct rcu_bh_torture_synchronize, head);
421 complete(&rcu->completion);
422}
423
424static void rcu_bh_torture_synchronize(void)
425{
426 struct rcu_bh_torture_synchronize rcu;
427
428 init_completion(&rcu.completion);
429 call_rcu_bh(&rcu.head, rcu_bh_torture_wakeme_after_cb);
430 wait_for_completion(&rcu.completion);
431}
432
c32e0660
PM
433static struct rcu_torture_ops rcu_bh_ops = {
434 .init = NULL,
435 .cleanup = NULL,
436 .readlock = rcu_bh_torture_read_lock,
b2896d2e 437 .readdelay = rcu_read_delay, /* just reuse rcu's version. */
c32e0660
PM
438 .readunlock = rcu_bh_torture_read_unlock,
439 .completed = rcu_bh_torture_completed,
440 .deferredfree = rcu_bh_torture_deferred_free,
b772e1dd 441 .sync = rcu_bh_torture_synchronize,
2326974d 442 .cb_barrier = rcu_barrier_bh,
c32e0660 443 .stats = NULL,
0729fbf3 444 .irqcapable = 1,
c32e0660
PM
445 .name = "rcu_bh"
446};
447
11a14701
JT
448static struct rcu_torture_ops rcu_bh_sync_ops = {
449 .init = rcu_sync_torture_init,
450 .cleanup = NULL,
451 .readlock = rcu_bh_torture_read_lock,
452 .readdelay = rcu_read_delay, /* just reuse rcu's version. */
453 .readunlock = rcu_bh_torture_read_unlock,
454 .completed = rcu_bh_torture_completed,
455 .deferredfree = rcu_sync_torture_deferred_free,
456 .sync = rcu_bh_torture_synchronize,
2326974d 457 .cb_barrier = NULL,
11a14701 458 .stats = NULL,
0729fbf3 459 .irqcapable = 1,
11a14701
JT
460 .name = "rcu_bh_sync"
461};
462
b2896d2e
PM
463/*
464 * Definitions for srcu torture testing.
465 */
466
467static struct srcu_struct srcu_ctl;
b2896d2e
PM
468
469static void srcu_torture_init(void)
470{
471 init_srcu_struct(&srcu_ctl);
e3033736 472 rcu_sync_torture_init();
b2896d2e
PM
473}
474
475static void srcu_torture_cleanup(void)
476{
477 synchronize_srcu(&srcu_ctl);
478 cleanup_srcu_struct(&srcu_ctl);
479}
480
012d3ca8 481static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
b2896d2e
PM
482{
483 return srcu_read_lock(&srcu_ctl);
484}
485
486static void srcu_read_delay(struct rcu_random_state *rrsp)
487{
488 long delay;
489 const long uspertick = 1000000 / HZ;
490 const long longdelay = 10;
491
492 /* We want there to be long-running readers, but not all the time. */
493
494 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
495 if (!delay)
496 schedule_timeout_interruptible(longdelay);
497}
498
012d3ca8 499static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
b2896d2e
PM
500{
501 srcu_read_unlock(&srcu_ctl, idx);
502}
503
504static int srcu_torture_completed(void)
505{
506 return srcu_batches_completed(&srcu_ctl);
507}
508
b772e1dd
JT
509static void srcu_torture_synchronize(void)
510{
511 synchronize_srcu(&srcu_ctl);
512}
513
b2896d2e
PM
514static int srcu_torture_stats(char *page)
515{
516 int cnt = 0;
517 int cpu;
518 int idx = srcu_ctl.completed & 0x1;
519
520 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
521 torture_type, TORTURE_FLAG, idx);
522 for_each_possible_cpu(cpu) {
523 cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu,
524 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
525 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
526 }
527 cnt += sprintf(&page[cnt], "\n");
528 return cnt;
529}
530
531static struct rcu_torture_ops srcu_ops = {
532 .init = srcu_torture_init,
533 .cleanup = srcu_torture_cleanup,
534 .readlock = srcu_torture_read_lock,
535 .readdelay = srcu_read_delay,
536 .readunlock = srcu_torture_read_unlock,
537 .completed = srcu_torture_completed,
e3033736 538 .deferredfree = rcu_sync_torture_deferred_free,
b772e1dd 539 .sync = srcu_torture_synchronize,
2326974d 540 .cb_barrier = NULL,
b2896d2e
PM
541 .stats = srcu_torture_stats,
542 .name = "srcu"
543};
544
4b6c2cca
JT
545/*
546 * Definitions for sched torture testing.
547 */
548
549static int sched_torture_read_lock(void)
550{
551 preempt_disable();
552 return 0;
553}
554
555static void sched_torture_read_unlock(int idx)
556{
557 preempt_enable();
558}
559
560static int sched_torture_completed(void)
561{
562 return 0;
563}
564
2326974d
PM
565static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
566{
567 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
568}
569
4b6c2cca
JT
570static void sched_torture_synchronize(void)
571{
572 synchronize_sched();
573}
574
575static struct rcu_torture_ops sched_ops = {
576 .init = rcu_sync_torture_init,
577 .cleanup = NULL,
578 .readlock = sched_torture_read_lock,
579 .readdelay = rcu_read_delay, /* just reuse rcu's version. */
580 .readunlock = sched_torture_read_unlock,
581 .completed = sched_torture_completed,
2326974d 582 .deferredfree = rcu_sched_torture_deferred_free,
4b6c2cca 583 .sync = sched_torture_synchronize,
2326974d 584 .cb_barrier = rcu_barrier_sched,
4b6c2cca 585 .stats = NULL,
0729fbf3 586 .irqcapable = 1,
4b6c2cca
JT
587 .name = "sched"
588};
589
2326974d
PM
590static struct rcu_torture_ops sched_ops_sync = {
591 .init = rcu_sync_torture_init,
592 .cleanup = NULL,
593 .readlock = sched_torture_read_lock,
594 .readdelay = rcu_read_delay, /* just reuse rcu's version. */
595 .readunlock = sched_torture_read_unlock,
596 .completed = sched_torture_completed,
597 .deferredfree = rcu_sync_torture_deferred_free,
598 .sync = sched_torture_synchronize,
599 .cb_barrier = NULL,
600 .stats = NULL,
601 .name = "sched_sync"
602};
603
a241ec65
PM
604/*
605 * RCU torture writer kthread. Repeatedly substitutes a new structure
606 * for that pointed to by rcu_torture_current, freeing the old structure
607 * after a series of grace periods (the "pipeline").
608 */
609static int
610rcu_torture_writer(void *arg)
611{
612 int i;
613 long oldbatch = rcu_batches_completed();
614 struct rcu_torture *rp;
615 struct rcu_torture *old_rp;
616 static DEFINE_RCU_RANDOM(rand);
617
618 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
dbdf65b1
IM
619 set_user_nice(current, 19);
620
a241ec65
PM
621 do {
622 schedule_timeout_uninterruptible(1);
a241ec65
PM
623 if ((rp = rcu_torture_alloc()) == NULL)
624 continue;
625 rp->rtort_pipe_count = 0;
626 udelay(rcu_random(&rand) & 0x3ff);
627 old_rp = rcu_torture_current;
996417d2 628 rp->rtort_mbtest = 1;
a241ec65
PM
629 rcu_assign_pointer(rcu_torture_current, rp);
630 smp_wmb();
c8e5b163 631 if (old_rp) {
a241ec65
PM
632 i = old_rp->rtort_pipe_count;
633 if (i > RCU_TORTURE_PIPE_LEN)
634 i = RCU_TORTURE_PIPE_LEN;
635 atomic_inc(&rcu_torture_wcount[i]);
636 old_rp->rtort_pipe_count++;
72e9bb54 637 cur_ops->deferredfree(old_rp);
a241ec65
PM
638 }
639 rcu_torture_current_version++;
72e9bb54 640 oldbatch = cur_ops->completed();
c9d557c1
PM
641 rcu_stutter_wait("rcu_torture_writer");
642 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
a241ec65 643 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
c9d557c1
PM
644 rcutorture_shutdown_absorb("rcu_torture_writer");
645 while (!kthread_should_stop())
a241ec65
PM
646 schedule_timeout_uninterruptible(1);
647 return 0;
648}
649
b772e1dd
JT
650/*
651 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
652 * delay between calls.
653 */
654static int
655rcu_torture_fakewriter(void *arg)
656{
657 DEFINE_RCU_RANDOM(rand);
658
659 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
660 set_user_nice(current, 19);
661
662 do {
663 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
664 udelay(rcu_random(&rand) & 0x3ff);
665 cur_ops->sync();
c9d557c1
PM
666 rcu_stutter_wait("rcu_torture_fakewriter");
667 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
b772e1dd
JT
668
669 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
c9d557c1
PM
670 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
671 while (!kthread_should_stop())
b772e1dd
JT
672 schedule_timeout_uninterruptible(1);
673 return 0;
674}
675
0729fbf3
PM
676/*
677 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
678 * incrementing the corresponding element of the pipeline array. The
679 * counter in the element should never be greater than 1, otherwise, the
680 * RCU implementation is broken.
681 */
682static void rcu_torture_timer(unsigned long unused)
683{
684 int idx;
685 int completed;
686 static DEFINE_RCU_RANDOM(rand);
687 static DEFINE_SPINLOCK(rand_lock);
688 struct rcu_torture *p;
689 int pipe_count;
690
691 idx = cur_ops->readlock();
692 completed = cur_ops->completed();
693 p = rcu_dereference(rcu_torture_current);
694 if (p == NULL) {
695 /* Leave because rcu_torture_writer is not yet underway */
696 cur_ops->readunlock(idx);
697 return;
698 }
699 if (p->rtort_mbtest == 0)
700 atomic_inc(&n_rcu_torture_mberror);
701 spin_lock(&rand_lock);
702 cur_ops->readdelay(&rand);
703 n_rcu_torture_timers++;
704 spin_unlock(&rand_lock);
705 preempt_disable();
706 pipe_count = p->rtort_pipe_count;
707 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
708 /* Should not happen, but... */
709 pipe_count = RCU_TORTURE_PIPE_LEN;
710 }
711 ++__get_cpu_var(rcu_torture_count)[pipe_count];
712 completed = cur_ops->completed() - completed;
713 if (completed > RCU_TORTURE_PIPE_LEN) {
714 /* Should not happen, but... */
715 completed = RCU_TORTURE_PIPE_LEN;
716 }
717 ++__get_cpu_var(rcu_torture_batch)[completed];
718 preempt_enable();
719 cur_ops->readunlock(idx);
720}
721
a241ec65
PM
722/*
723 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
724 * incrementing the corresponding element of the pipeline array. The
725 * counter in the element should never be greater than 1, otherwise, the
726 * RCU implementation is broken.
727 */
728static int
729rcu_torture_reader(void *arg)
730{
731 int completed;
72e9bb54 732 int idx;
a241ec65
PM
733 DEFINE_RCU_RANDOM(rand);
734 struct rcu_torture *p;
735 int pipe_count;
0729fbf3 736 struct timer_list t;
a241ec65
PM
737
738 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
dbdf65b1 739 set_user_nice(current, 19);
0729fbf3
PM
740 if (irqreader && cur_ops->irqcapable)
741 setup_timer_on_stack(&t, rcu_torture_timer, 0);
dbdf65b1 742
a241ec65 743 do {
0729fbf3
PM
744 if (irqreader && cur_ops->irqcapable) {
745 if (!timer_pending(&t))
746 mod_timer(&t, 1);
747 }
72e9bb54
PM
748 idx = cur_ops->readlock();
749 completed = cur_ops->completed();
a241ec65
PM
750 p = rcu_dereference(rcu_torture_current);
751 if (p == NULL) {
752 /* Wait for rcu_torture_writer to get underway */
72e9bb54 753 cur_ops->readunlock(idx);
a241ec65
PM
754 schedule_timeout_interruptible(HZ);
755 continue;
756 }
996417d2
PM
757 if (p->rtort_mbtest == 0)
758 atomic_inc(&n_rcu_torture_mberror);
b2896d2e 759 cur_ops->readdelay(&rand);
a241ec65
PM
760 preempt_disable();
761 pipe_count = p->rtort_pipe_count;
762 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
763 /* Should not happen, but... */
764 pipe_count = RCU_TORTURE_PIPE_LEN;
765 }
766 ++__get_cpu_var(rcu_torture_count)[pipe_count];
72e9bb54 767 completed = cur_ops->completed() - completed;
a241ec65
PM
768 if (completed > RCU_TORTURE_PIPE_LEN) {
769 /* Should not happen, but... */
770 completed = RCU_TORTURE_PIPE_LEN;
771 }
772 ++__get_cpu_var(rcu_torture_batch)[completed];
773 preempt_enable();
72e9bb54 774 cur_ops->readunlock(idx);
a241ec65 775 schedule();
c9d557c1
PM
776 rcu_stutter_wait("rcu_torture_reader");
777 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
a241ec65 778 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
c9d557c1 779 rcutorture_shutdown_absorb("rcu_torture_reader");
0729fbf3
PM
780 if (irqreader && cur_ops->irqcapable)
781 del_timer_sync(&t);
c9d557c1 782 while (!kthread_should_stop())
a241ec65
PM
783 schedule_timeout_uninterruptible(1);
784 return 0;
785}
786
787/*
788 * Create an RCU-torture statistics message in the specified buffer.
789 */
790static int
791rcu_torture_printk(char *page)
792{
793 int cnt = 0;
794 int cpu;
795 int i;
796 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
797 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
798
0a945022 799 for_each_possible_cpu(cpu) {
a241ec65
PM
800 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
801 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
802 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
803 }
804 }
805 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
806 if (pipesummary[i] != 0)
807 break;
808 }
72e9bb54 809 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
a241ec65 810 cnt += sprintf(&page[cnt],
996417d2 811 "rtc: %p ver: %ld tfle: %d rta: %d rtaf: %d rtf: %d "
0729fbf3 812 "rtmbe: %d nt: %ld",
a241ec65
PM
813 rcu_torture_current,
814 rcu_torture_current_version,
815 list_empty(&rcu_torture_freelist),
816 atomic_read(&n_rcu_torture_alloc),
817 atomic_read(&n_rcu_torture_alloc_fail),
996417d2 818 atomic_read(&n_rcu_torture_free),
0729fbf3
PM
819 atomic_read(&n_rcu_torture_mberror),
820 n_rcu_torture_timers);
996417d2
PM
821 if (atomic_read(&n_rcu_torture_mberror) != 0)
822 cnt += sprintf(&page[cnt], " !!!");
72e9bb54 823 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
996417d2 824 if (i > 1) {
a241ec65 825 cnt += sprintf(&page[cnt], "!!! ");
996417d2 826 atomic_inc(&n_rcu_torture_error);
5af970a4 827 WARN_ON_ONCE(1);
996417d2 828 }
a241ec65
PM
829 cnt += sprintf(&page[cnt], "Reader Pipe: ");
830 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
831 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
72e9bb54 832 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
a241ec65 833 cnt += sprintf(&page[cnt], "Reader Batch: ");
72e9bb54 834 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
a241ec65 835 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
72e9bb54 836 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
a241ec65
PM
837 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
838 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
839 cnt += sprintf(&page[cnt], " %d",
840 atomic_read(&rcu_torture_wcount[i]));
841 }
842 cnt += sprintf(&page[cnt], "\n");
c8e5b163 843 if (cur_ops->stats)
72e9bb54 844 cnt += cur_ops->stats(&page[cnt]);
a241ec65
PM
845 return cnt;
846}
847
848/*
849 * Print torture statistics. Caller must ensure that there is only
850 * one call to this function at a given time!!! This is normally
851 * accomplished by relying on the module system to only have one copy
852 * of the module loaded, and then by giving the rcu_torture_stats
853 * kthread full control (or the init/cleanup functions when rcu_torture_stats
854 * thread is not running).
855 */
856static void
857rcu_torture_stats_print(void)
858{
859 int cnt;
860
861 cnt = rcu_torture_printk(printk_buf);
862 printk(KERN_ALERT "%s", printk_buf);
863}
864
865/*
866 * Periodically prints torture statistics, if periodic statistics printing
867 * was specified via the stat_interval module parameter.
868 *
869 * No need to worry about fullstop here, since this one doesn't reference
870 * volatile state or register callbacks.
871 */
872static int
873rcu_torture_stats(void *arg)
874{
875 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
876 do {
877 schedule_timeout_interruptible(stat_interval * HZ);
878 rcu_torture_stats_print();
c9d557c1
PM
879 rcutorture_shutdown_absorb("rcu_torture_stats");
880 } while (!kthread_should_stop());
a241ec65
PM
881 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
882 return 0;
883}
884
d84f5203
SV
885static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
886
887/* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
888 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
889 */
b2896d2e 890static void rcu_torture_shuffle_tasks(void)
d84f5203 891{
c9d557c1 892 cpumask_t tmp_mask;
d84f5203
SV
893 int i;
894
c9d557c1 895 cpus_setall(tmp_mask);
86ef5c9a 896 get_online_cpus();
d84f5203
SV
897
898 /* No point in shuffling if there is only one online CPU (ex: UP) */
c9d557c1
PM
899 if (num_online_cpus() == 1) {
900 put_online_cpus();
901 return;
902 }
d84f5203
SV
903
904 if (rcu_idle_cpu != -1)
c9d557c1 905 cpu_clear(rcu_idle_cpu, tmp_mask);
d84f5203 906
c9d557c1 907 set_cpus_allowed_ptr(current, &tmp_mask);
d84f5203 908
c8e5b163 909 if (reader_tasks) {
d84f5203
SV
910 for (i = 0; i < nrealreaders; i++)
911 if (reader_tasks[i])
f70316da 912 set_cpus_allowed_ptr(reader_tasks[i],
c9d557c1 913 &tmp_mask);
d84f5203
SV
914 }
915
c8e5b163 916 if (fakewriter_tasks) {
b772e1dd
JT
917 for (i = 0; i < nfakewriters; i++)
918 if (fakewriter_tasks[i])
f70316da 919 set_cpus_allowed_ptr(fakewriter_tasks[i],
c9d557c1 920 &tmp_mask);
b772e1dd
JT
921 }
922
d84f5203 923 if (writer_task)
c9d557c1 924 set_cpus_allowed_ptr(writer_task, &tmp_mask);
d84f5203
SV
925
926 if (stats_task)
c9d557c1 927 set_cpus_allowed_ptr(stats_task, &tmp_mask);
d84f5203
SV
928
929 if (rcu_idle_cpu == -1)
930 rcu_idle_cpu = num_online_cpus() - 1;
931 else
932 rcu_idle_cpu--;
933
86ef5c9a 934 put_online_cpus();
d84f5203
SV
935}
936
937/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
938 * system to become idle at a time and cut off its timer ticks. This is meant
939 * to test the support for such tickless idle CPU in RCU.
940 */
941static int
942rcu_torture_shuffle(void *arg)
943{
944 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
945 do {
946 schedule_timeout_interruptible(shuffle_interval * HZ);
947 rcu_torture_shuffle_tasks();
c9d557c1
PM
948 rcutorture_shutdown_absorb("rcu_torture_shuffle");
949 } while (!kthread_should_stop());
d84f5203
SV
950 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
951 return 0;
952}
953
d120f65f
PM
954/* Cause the rcutorture test to "stutter", starting and stopping all
955 * threads periodically.
956 */
957static int
958rcu_torture_stutter(void *arg)
959{
960 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
961 do {
962 schedule_timeout_interruptible(stutter * HZ);
963 stutter_pause_test = 1;
c9d557c1 964 if (!kthread_should_stop())
d120f65f
PM
965 schedule_timeout_interruptible(stutter * HZ);
966 stutter_pause_test = 0;
c9d557c1
PM
967 rcutorture_shutdown_absorb("rcu_torture_stutter");
968 } while (!kthread_should_stop());
d120f65f
PM
969 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
970 return 0;
971}
972
95c38322
PM
973static inline void
974rcu_torture_print_module_parms(char *tag)
975{
b772e1dd
JT
976 printk(KERN_ALERT "%s" TORTURE_FLAG
977 "--- %s: nreaders=%d nfakewriters=%d "
95c38322 978 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
0729fbf3 979 "shuffle_interval=%d stutter=%d irqreader=%d\n",
b772e1dd 980 torture_type, tag, nrealreaders, nfakewriters,
d120f65f 981 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
0729fbf3 982 stutter, irqreader);
95c38322
PM
983}
984
343e9099
PM
985static struct notifier_block rcutorture_nb = {
986 .notifier_call = rcutorture_shutdown_notify,
987};
988
a241ec65
PM
989static void
990rcu_torture_cleanup(void)
991{
992 int i;
993
343e9099 994 mutex_lock(&fullstop_mutex);
c9d557c1
PM
995 if (fullstop == FULLSTOP_SHUTDOWN) {
996 printk(KERN_WARNING /* but going down anyway, so... */
997 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
343e9099 998 mutex_unlock(&fullstop_mutex);
c9d557c1 999 schedule_timeout_uninterruptible(10);
343e9099
PM
1000 if (cur_ops->cb_barrier != NULL)
1001 cur_ops->cb_barrier();
1002 return;
1003 }
c9d557c1 1004 fullstop = FULLSTOP_RMMOD;
343e9099
PM
1005 mutex_unlock(&fullstop_mutex);
1006 unregister_reboot_notifier(&rcutorture_nb);
d120f65f
PM
1007 if (stutter_task) {
1008 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1009 kthread_stop(stutter_task);
1010 }
1011 stutter_task = NULL;
c8e5b163 1012 if (shuffler_task) {
d84f5203
SV
1013 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1014 kthread_stop(shuffler_task);
1015 }
1016 shuffler_task = NULL;
1017
c8e5b163 1018 if (writer_task) {
a241ec65
PM
1019 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1020 kthread_stop(writer_task);
1021 }
1022 writer_task = NULL;
1023
c8e5b163 1024 if (reader_tasks) {
a241ec65 1025 for (i = 0; i < nrealreaders; i++) {
c8e5b163 1026 if (reader_tasks[i]) {
a241ec65
PM
1027 VERBOSE_PRINTK_STRING(
1028 "Stopping rcu_torture_reader task");
1029 kthread_stop(reader_tasks[i]);
1030 }
1031 reader_tasks[i] = NULL;
1032 }
1033 kfree(reader_tasks);
1034 reader_tasks = NULL;
1035 }
1036 rcu_torture_current = NULL;
1037
c8e5b163 1038 if (fakewriter_tasks) {
b772e1dd 1039 for (i = 0; i < nfakewriters; i++) {
c8e5b163 1040 if (fakewriter_tasks[i]) {
b772e1dd
JT
1041 VERBOSE_PRINTK_STRING(
1042 "Stopping rcu_torture_fakewriter task");
1043 kthread_stop(fakewriter_tasks[i]);
1044 }
1045 fakewriter_tasks[i] = NULL;
1046 }
1047 kfree(fakewriter_tasks);
1048 fakewriter_tasks = NULL;
1049 }
1050
c8e5b163 1051 if (stats_task) {
a241ec65
PM
1052 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1053 kthread_stop(stats_task);
1054 }
1055 stats_task = NULL;
1056
1057 /* Wait for all RCU callbacks to fire. */
2326974d
PM
1058
1059 if (cur_ops->cb_barrier != NULL)
1060 cur_ops->cb_barrier();
a241ec65 1061
a241ec65 1062 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
72e9bb54 1063
c8e5b163 1064 if (cur_ops->cleanup)
72e9bb54 1065 cur_ops->cleanup();
95c38322
PM
1066 if (atomic_read(&n_rcu_torture_error))
1067 rcu_torture_print_module_parms("End of test: FAILURE");
1068 else
1069 rcu_torture_print_module_parms("End of test: SUCCESS");
a241ec65
PM
1070}
1071
6f8bc500 1072static int __init
a241ec65
PM
1073rcu_torture_init(void)
1074{
1075 int i;
1076 int cpu;
1077 int firsterr = 0;
ade5fb81
JT
1078 static struct rcu_torture_ops *torture_ops[] =
1079 { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops,
2326974d 1080 &srcu_ops, &sched_ops, &sched_ops_sync, };
a241ec65 1081
343e9099
PM
1082 mutex_lock(&fullstop_mutex);
1083
a241ec65 1084 /* Process args and tell the world that the torturer is on the job. */
ade5fb81 1085 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
72e9bb54 1086 cur_ops = torture_ops[i];
ade5fb81 1087 if (strcmp(torture_type, cur_ops->name) == 0)
72e9bb54 1088 break;
72e9bb54 1089 }
ade5fb81 1090 if (i == ARRAY_SIZE(torture_ops)) {
72e9bb54
PM
1091 printk(KERN_ALERT "rcutorture: invalid torture type: \"%s\"\n",
1092 torture_type);
343e9099 1093 mutex_unlock(&fullstop_mutex);
72e9bb54
PM
1094 return (-EINVAL);
1095 }
c8e5b163 1096 if (cur_ops->init)
72e9bb54
PM
1097 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1098
a241ec65
PM
1099 if (nreaders >= 0)
1100 nrealreaders = nreaders;
1101 else
1102 nrealreaders = 2 * num_online_cpus();
95c38322 1103 rcu_torture_print_module_parms("Start of test");
c9d557c1 1104 fullstop = FULLSTOP_DONTSTOP;
a241ec65
PM
1105
1106 /* Set up the freelist. */
1107
1108 INIT_LIST_HEAD(&rcu_torture_freelist);
788e770e 1109 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
996417d2 1110 rcu_tortures[i].rtort_mbtest = 0;
a241ec65
PM
1111 list_add_tail(&rcu_tortures[i].rtort_free,
1112 &rcu_torture_freelist);
1113 }
1114
1115 /* Initialize the statistics so that each run gets its own numbers. */
1116
1117 rcu_torture_current = NULL;
1118 rcu_torture_current_version = 0;
1119 atomic_set(&n_rcu_torture_alloc, 0);
1120 atomic_set(&n_rcu_torture_alloc_fail, 0);
1121 atomic_set(&n_rcu_torture_free, 0);
996417d2
PM
1122 atomic_set(&n_rcu_torture_mberror, 0);
1123 atomic_set(&n_rcu_torture_error, 0);
a241ec65
PM
1124 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1125 atomic_set(&rcu_torture_wcount[i], 0);
0a945022 1126 for_each_possible_cpu(cpu) {
a241ec65
PM
1127 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1128 per_cpu(rcu_torture_count, cpu)[i] = 0;
1129 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1130 }
1131 }
1132
1133 /* Start up the kthreads. */
1134
1135 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1136 writer_task = kthread_run(rcu_torture_writer, NULL,
1137 "rcu_torture_writer");
1138 if (IS_ERR(writer_task)) {
1139 firsterr = PTR_ERR(writer_task);
1140 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1141 writer_task = NULL;
1142 goto unwind;
1143 }
b772e1dd
JT
1144 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
1145 GFP_KERNEL);
1146 if (fakewriter_tasks == NULL) {
1147 VERBOSE_PRINTK_ERRSTRING("out of memory");
1148 firsterr = -ENOMEM;
1149 goto unwind;
1150 }
1151 for (i = 0; i < nfakewriters; i++) {
1152 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
1153 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
1154 "rcu_torture_fakewriter");
1155 if (IS_ERR(fakewriter_tasks[i])) {
1156 firsterr = PTR_ERR(fakewriter_tasks[i]);
1157 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
1158 fakewriter_tasks[i] = NULL;
1159 goto unwind;
1160 }
1161 }
2860aaba 1162 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
a241ec65
PM
1163 GFP_KERNEL);
1164 if (reader_tasks == NULL) {
1165 VERBOSE_PRINTK_ERRSTRING("out of memory");
1166 firsterr = -ENOMEM;
1167 goto unwind;
1168 }
1169 for (i = 0; i < nrealreaders; i++) {
1170 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
1171 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
1172 "rcu_torture_reader");
1173 if (IS_ERR(reader_tasks[i])) {
1174 firsterr = PTR_ERR(reader_tasks[i]);
1175 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
1176 reader_tasks[i] = NULL;
1177 goto unwind;
1178 }
1179 }
1180 if (stat_interval > 0) {
1181 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
1182 stats_task = kthread_run(rcu_torture_stats, NULL,
1183 "rcu_torture_stats");
1184 if (IS_ERR(stats_task)) {
1185 firsterr = PTR_ERR(stats_task);
1186 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
1187 stats_task = NULL;
1188 goto unwind;
1189 }
1190 }
d84f5203
SV
1191 if (test_no_idle_hz) {
1192 rcu_idle_cpu = num_online_cpus() - 1;
1193 /* Create the shuffler thread */
1194 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
1195 "rcu_torture_shuffle");
1196 if (IS_ERR(shuffler_task)) {
1197 firsterr = PTR_ERR(shuffler_task);
1198 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
1199 shuffler_task = NULL;
1200 goto unwind;
1201 }
1202 }
d120f65f
PM
1203 if (stutter < 0)
1204 stutter = 0;
1205 if (stutter) {
1206 /* Create the stutter thread */
1207 stutter_task = kthread_run(rcu_torture_stutter, NULL,
1208 "rcu_torture_stutter");
1209 if (IS_ERR(stutter_task)) {
1210 firsterr = PTR_ERR(stutter_task);
1211 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
1212 stutter_task = NULL;
1213 goto unwind;
1214 }
1215 }
343e9099
PM
1216 register_reboot_notifier(&rcutorture_nb);
1217 mutex_unlock(&fullstop_mutex);
a241ec65
PM
1218 return 0;
1219
1220unwind:
343e9099 1221 mutex_unlock(&fullstop_mutex);
a241ec65
PM
1222 rcu_torture_cleanup();
1223 return firsterr;
1224}
1225
1226module_init(rcu_torture_init);
1227module_exit(rcu_torture_cleanup);