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