]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - kernel/rcutorture.c
tile: Make tile use the new is_idle_task() API
[mirror_ubuntu-zesty-kernel.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>
a71fca58 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>
60063497 36#include <linux/atomic.h>
a241ec65 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 52MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and "
a71fca58 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). */
d5f546d8
PM
64static int fqs_duration; /* Duration of bursts (us), 0 to disable. */
65static int fqs_holdoff; /* Hold time within burst (us). */
bf66f18e 66static int fqs_stutter = 3; /* Wait time between bursts (s). */
d5f546d8 67static int shutdown_secs; /* Shutdown time (s). <=0 for no shutdown. */
8e8be45e
PM
68static int test_boost = 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */
69static int test_boost_interval = 7; /* Interval between boost tests, seconds. */
70static int test_boost_duration = 4; /* Duration of each boost test, seconds. */
20d2e428 71static char *torture_type = "rcu"; /* What RCU implementation to torture. */
a241ec65 72
d6ad6711 73module_param(nreaders, int, 0444);
a241ec65 74MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
d6ad6711 75module_param(nfakewriters, int, 0444);
b772e1dd 76MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
3721bc1d 77module_param(stat_interval, int, 0644);
a241ec65 78MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
d6ad6711 79module_param(verbose, bool, 0444);
a241ec65 80MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
d6ad6711 81module_param(test_no_idle_hz, bool, 0444);
d84f5203 82MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
d6ad6711 83module_param(shuffle_interval, int, 0444);
d84f5203 84MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
d120f65f
PM
85module_param(stutter, int, 0444);
86MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
0729fbf3
PM
87module_param(irqreader, int, 0444);
88MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
bf66f18e
PM
89module_param(fqs_duration, int, 0444);
90MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us)");
91module_param(fqs_holdoff, int, 0444);
92MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)");
93module_param(fqs_stutter, int, 0444);
94MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)");
d5f546d8
PM
95module_param(shutdown_secs, int, 0444);
96MODULE_PARM_DESC(shutdown_secs, "Shutdown time (s), zero to disable.");
8e8be45e
PM
97module_param(test_boost, int, 0444);
98MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
99module_param(test_boost_interval, int, 0444);
100MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds.");
101module_param(test_boost_duration, int, 0444);
102MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds.");
d6ad6711 103module_param(torture_type, charp, 0444);
b2896d2e 104MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
72e9bb54
PM
105
106#define TORTURE_FLAG "-torture:"
a241ec65 107#define PRINTK_STRING(s) \
72e9bb54 108 do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
a241ec65 109#define VERBOSE_PRINTK_STRING(s) \
72e9bb54 110 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
a241ec65 111#define VERBOSE_PRINTK_ERRSTRING(s) \
72e9bb54 112 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
a241ec65
PM
113
114static char printk_buf[4096];
115
116static int nrealreaders;
117static struct task_struct *writer_task;
b772e1dd 118static struct task_struct **fakewriter_tasks;
a241ec65
PM
119static struct task_struct **reader_tasks;
120static struct task_struct *stats_task;
d84f5203 121static struct task_struct *shuffler_task;
d120f65f 122static struct task_struct *stutter_task;
bf66f18e 123static struct task_struct *fqs_task;
8e8be45e 124static struct task_struct *boost_tasks[NR_CPUS];
d5f546d8 125static struct task_struct *shutdown_task;
a241ec65
PM
126
127#define RCU_TORTURE_PIPE_LEN 10
128
129struct rcu_torture {
130 struct rcu_head rtort_rcu;
131 int rtort_pipe_count;
132 struct list_head rtort_free;
996417d2 133 int rtort_mbtest;
a241ec65
PM
134};
135
a241ec65 136static LIST_HEAD(rcu_torture_freelist);
0ddea0ea 137static struct rcu_torture __rcu *rcu_torture_current;
4a298656 138static unsigned long rcu_torture_current_version;
a241ec65
PM
139static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
140static DEFINE_SPINLOCK(rcu_torture_lock);
141static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
142 { 0 };
143static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
144 { 0 };
145static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
b2896d2e
PM
146static atomic_t n_rcu_torture_alloc;
147static atomic_t n_rcu_torture_alloc_fail;
148static atomic_t n_rcu_torture_free;
149static atomic_t n_rcu_torture_mberror;
150static atomic_t n_rcu_torture_error;
8e8be45e
PM
151static long n_rcu_torture_boost_ktrerror;
152static long n_rcu_torture_boost_rterror;
8e8be45e
PM
153static long n_rcu_torture_boost_failure;
154static long n_rcu_torture_boosts;
a71fca58 155static long n_rcu_torture_timers;
e3033736 156static struct list_head rcu_torture_removed;
73d0a4b1 157static cpumask_var_t shuffle_tmp_mask;
a241ec65 158
a71fca58 159static int stutter_pause_test;
d120f65f 160
31a72bce
PM
161#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
162#define RCUTORTURE_RUNNABLE_INIT 1
163#else
164#define RCUTORTURE_RUNNABLE_INIT 0
165#endif
166int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
bb3bf705
PM
167module_param(rcutorture_runnable, int, 0444);
168MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot");
31a72bce 169
3acf4a9a 170#if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
8e8be45e 171#define rcu_can_boost() 1
3acf4a9a 172#else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
8e8be45e 173#define rcu_can_boost() 0
3acf4a9a 174#endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
8e8be45e 175
d5f546d8 176static unsigned long shutdown_time; /* jiffies to system shutdown. */
8e8be45e
PM
177static unsigned long boost_starttime; /* jiffies of next boost test start. */
178DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
179 /* and boost task create/destroy. */
180
c9d557c1
PM
181/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
182
183#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
184#define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
185#define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
186static int fullstop = FULLSTOP_RMMOD;
0ddea0ea
PM
187/*
188 * Protect fullstop transitions and spawning of kthreads.
189 */
190static DEFINE_MUTEX(fullstop_mutex);
343e9099 191
d5f546d8
PM
192/* Forward reference. */
193static void rcu_torture_cleanup(void);
194
343e9099 195/*
c9d557c1 196 * Detect and respond to a system shutdown.
343e9099
PM
197 */
198static int
199rcutorture_shutdown_notify(struct notifier_block *unused1,
200 unsigned long unused2, void *unused3)
201{
c59ab97e 202 mutex_lock(&fullstop_mutex);
c9d557c1 203 if (fullstop == FULLSTOP_DONTSTOP)
c59ab97e 204 fullstop = FULLSTOP_SHUTDOWN;
c9d557c1
PM
205 else
206 printk(KERN_WARNING /* but going down anyway, so... */
207 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
c59ab97e 208 mutex_unlock(&fullstop_mutex);
343e9099
PM
209 return NOTIFY_DONE;
210}
211
c9d557c1
PM
212/*
213 * Absorb kthreads into a kernel function that won't return, so that
214 * they won't ever access module text or data again.
215 */
216static void rcutorture_shutdown_absorb(char *title)
217{
218 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
219 printk(KERN_NOTICE
220 "rcutorture thread %s parking due to system shutdown\n",
221 title);
222 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
223 }
224}
225
a241ec65
PM
226/*
227 * Allocate an element from the rcu_tortures pool.
228 */
97a41e26 229static struct rcu_torture *
a241ec65
PM
230rcu_torture_alloc(void)
231{
232 struct list_head *p;
233
adac1665 234 spin_lock_bh(&rcu_torture_lock);
a241ec65
PM
235 if (list_empty(&rcu_torture_freelist)) {
236 atomic_inc(&n_rcu_torture_alloc_fail);
adac1665 237 spin_unlock_bh(&rcu_torture_lock);
a241ec65
PM
238 return NULL;
239 }
240 atomic_inc(&n_rcu_torture_alloc);
241 p = rcu_torture_freelist.next;
242 list_del_init(p);
adac1665 243 spin_unlock_bh(&rcu_torture_lock);
a241ec65
PM
244 return container_of(p, struct rcu_torture, rtort_free);
245}
246
247/*
248 * Free an element to the rcu_tortures pool.
249 */
250static void
251rcu_torture_free(struct rcu_torture *p)
252{
253 atomic_inc(&n_rcu_torture_free);
adac1665 254 spin_lock_bh(&rcu_torture_lock);
a241ec65 255 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
adac1665 256 spin_unlock_bh(&rcu_torture_lock);
a241ec65
PM
257}
258
a241ec65
PM
259struct rcu_random_state {
260 unsigned long rrs_state;
75cfef32 261 long rrs_count;
a241ec65
PM
262};
263
264#define RCU_RANDOM_MULT 39916801 /* prime */
265#define RCU_RANDOM_ADD 479001701 /* prime */
266#define RCU_RANDOM_REFRESH 10000
267
268#define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
269
270/*
271 * Crude but fast random-number generator. Uses a linear congruential
c17ac855 272 * generator, with occasional help from cpu_clock().
a241ec65 273 */
75cfef32 274static unsigned long
a241ec65
PM
275rcu_random(struct rcu_random_state *rrsp)
276{
a241ec65 277 if (--rrsp->rrs_count < 0) {
c676329a 278 rrsp->rrs_state += (unsigned long)local_clock();
a241ec65
PM
279 rrsp->rrs_count = RCU_RANDOM_REFRESH;
280 }
281 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
282 return swahw32(rrsp->rrs_state);
283}
284
d120f65f 285static void
c9d557c1 286rcu_stutter_wait(char *title)
d120f65f 287{
c9d557c1 288 while (stutter_pause_test || !rcutorture_runnable) {
e3d7be27
PM
289 if (rcutorture_runnable)
290 schedule_timeout_interruptible(1);
291 else
3ccf79f4 292 schedule_timeout_interruptible(round_jiffies_relative(HZ));
c9d557c1 293 rcutorture_shutdown_absorb(title);
343e9099 294 }
d120f65f
PM
295}
296
72e9bb54
PM
297/*
298 * Operations vector for selecting different types of tests.
299 */
300
301struct rcu_torture_ops {
302 void (*init)(void);
303 void (*cleanup)(void);
304 int (*readlock)(void);
0acc512c 305 void (*read_delay)(struct rcu_random_state *rrsp);
72e9bb54
PM
306 void (*readunlock)(int idx);
307 int (*completed)(void);
0acc512c 308 void (*deferred_free)(struct rcu_torture *p);
b772e1dd 309 void (*sync)(void);
2326974d 310 void (*cb_barrier)(void);
bf66f18e 311 void (*fqs)(void);
72e9bb54 312 int (*stats)(char *page);
0acc512c 313 int irq_capable;
8e8be45e 314 int can_boost;
72e9bb54
PM
315 char *name;
316};
a71fca58
PM
317
318static struct rcu_torture_ops *cur_ops;
72e9bb54
PM
319
320/*
321 * Definitions for rcu torture testing.
322 */
323
a49a4af7 324static int rcu_torture_read_lock(void) __acquires(RCU)
72e9bb54
PM
325{
326 rcu_read_lock();
327 return 0;
328}
329
b2896d2e
PM
330static void rcu_read_delay(struct rcu_random_state *rrsp)
331{
b8d57a76
JT
332 const unsigned long shortdelay_us = 200;
333 const unsigned long longdelay_ms = 50;
b2896d2e 334
b8d57a76
JT
335 /* We want a short delay sometimes to make a reader delay the grace
336 * period, and we want a long delay occasionally to trigger
337 * force_quiescent_state. */
b2896d2e 338
b8d57a76
JT
339 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
340 mdelay(longdelay_ms);
341 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
342 udelay(shortdelay_us);
e546f485
LJ
343#ifdef CONFIG_PREEMPT
344 if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000)))
345 preempt_schedule(); /* No QS if preempt_disable() in effect */
346#endif
b2896d2e
PM
347}
348
a49a4af7 349static void rcu_torture_read_unlock(int idx) __releases(RCU)
72e9bb54
PM
350{
351 rcu_read_unlock();
352}
353
354static int rcu_torture_completed(void)
355{
356 return rcu_batches_completed();
357}
358
359static void
360rcu_torture_cb(struct rcu_head *p)
361{
362 int i;
363 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
364
c9d557c1 365 if (fullstop != FULLSTOP_DONTSTOP) {
72e9bb54
PM
366 /* Test is ending, just drop callbacks on the floor. */
367 /* The next initialization will pick up the pieces. */
368 return;
369 }
370 i = rp->rtort_pipe_count;
371 if (i > RCU_TORTURE_PIPE_LEN)
372 i = RCU_TORTURE_PIPE_LEN;
373 atomic_inc(&rcu_torture_wcount[i]);
374 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
375 rp->rtort_mbtest = 0;
376 rcu_torture_free(rp);
377 } else
0acc512c 378 cur_ops->deferred_free(rp);
72e9bb54
PM
379}
380
d9a3da06
PM
381static int rcu_no_completed(void)
382{
383 return 0;
384}
385
72e9bb54
PM
386static void rcu_torture_deferred_free(struct rcu_torture *p)
387{
388 call_rcu(&p->rtort_rcu, rcu_torture_cb);
389}
390
391static struct rcu_torture_ops rcu_ops = {
0acc512c
PM
392 .init = NULL,
393 .cleanup = NULL,
394 .readlock = rcu_torture_read_lock,
395 .read_delay = rcu_read_delay,
396 .readunlock = rcu_torture_read_unlock,
397 .completed = rcu_torture_completed,
398 .deferred_free = rcu_torture_deferred_free,
399 .sync = synchronize_rcu,
400 .cb_barrier = rcu_barrier,
bf66f18e 401 .fqs = rcu_force_quiescent_state,
0acc512c 402 .stats = NULL,
a71fca58 403 .irq_capable = 1,
8e8be45e 404 .can_boost = rcu_can_boost(),
a71fca58 405 .name = "rcu"
72e9bb54
PM
406};
407
e3033736
JT
408static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
409{
410 int i;
411 struct rcu_torture *rp;
412 struct rcu_torture *rp1;
413
414 cur_ops->sync();
415 list_add(&p->rtort_free, &rcu_torture_removed);
416 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
417 i = rp->rtort_pipe_count;
418 if (i > RCU_TORTURE_PIPE_LEN)
419 i = RCU_TORTURE_PIPE_LEN;
420 atomic_inc(&rcu_torture_wcount[i]);
421 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
422 rp->rtort_mbtest = 0;
423 list_del(&rp->rtort_free);
424 rcu_torture_free(rp);
425 }
426 }
427}
428
429static void rcu_sync_torture_init(void)
430{
431 INIT_LIST_HEAD(&rcu_torture_removed);
432}
433
20d2e428 434static struct rcu_torture_ops rcu_sync_ops = {
0acc512c
PM
435 .init = rcu_sync_torture_init,
436 .cleanup = NULL,
437 .readlock = rcu_torture_read_lock,
438 .read_delay = rcu_read_delay,
439 .readunlock = rcu_torture_read_unlock,
440 .completed = rcu_torture_completed,
441 .deferred_free = rcu_sync_torture_deferred_free,
442 .sync = synchronize_rcu,
443 .cb_barrier = NULL,
bf66f18e 444 .fqs = rcu_force_quiescent_state,
0acc512c
PM
445 .stats = NULL,
446 .irq_capable = 1,
8e8be45e 447 .can_boost = rcu_can_boost(),
0acc512c 448 .name = "rcu_sync"
20d2e428
JT
449};
450
d9a3da06
PM
451static struct rcu_torture_ops rcu_expedited_ops = {
452 .init = rcu_sync_torture_init,
453 .cleanup = NULL,
454 .readlock = rcu_torture_read_lock,
455 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
456 .readunlock = rcu_torture_read_unlock,
457 .completed = rcu_no_completed,
458 .deferred_free = rcu_sync_torture_deferred_free,
459 .sync = synchronize_rcu_expedited,
460 .cb_barrier = NULL,
bf66f18e 461 .fqs = rcu_force_quiescent_state,
d9a3da06
PM
462 .stats = NULL,
463 .irq_capable = 1,
8e8be45e 464 .can_boost = rcu_can_boost(),
d9a3da06
PM
465 .name = "rcu_expedited"
466};
467
c32e0660
PM
468/*
469 * Definitions for rcu_bh torture testing.
470 */
471
a49a4af7 472static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
c32e0660
PM
473{
474 rcu_read_lock_bh();
475 return 0;
476}
477
a49a4af7 478static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
c32e0660
PM
479{
480 rcu_read_unlock_bh();
481}
482
483static int rcu_bh_torture_completed(void)
484{
485 return rcu_batches_completed_bh();
486}
487
488static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
489{
490 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
491}
492
493static struct rcu_torture_ops rcu_bh_ops = {
0acc512c
PM
494 .init = NULL,
495 .cleanup = NULL,
496 .readlock = rcu_bh_torture_read_lock,
497 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
498 .readunlock = rcu_bh_torture_read_unlock,
499 .completed = rcu_bh_torture_completed,
500 .deferred_free = rcu_bh_torture_deferred_free,
bdf2a436 501 .sync = synchronize_rcu_bh,
0acc512c 502 .cb_barrier = rcu_barrier_bh,
bf66f18e 503 .fqs = rcu_bh_force_quiescent_state,
0acc512c
PM
504 .stats = NULL,
505 .irq_capable = 1,
506 .name = "rcu_bh"
c32e0660
PM
507};
508
11a14701 509static struct rcu_torture_ops rcu_bh_sync_ops = {
0acc512c
PM
510 .init = rcu_sync_torture_init,
511 .cleanup = NULL,
512 .readlock = rcu_bh_torture_read_lock,
513 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
514 .readunlock = rcu_bh_torture_read_unlock,
515 .completed = rcu_bh_torture_completed,
516 .deferred_free = rcu_sync_torture_deferred_free,
bdf2a436 517 .sync = synchronize_rcu_bh,
0acc512c 518 .cb_barrier = NULL,
bf66f18e 519 .fqs = rcu_bh_force_quiescent_state,
0acc512c
PM
520 .stats = NULL,
521 .irq_capable = 1,
522 .name = "rcu_bh_sync"
11a14701
JT
523};
524
bdf2a436
PM
525static struct rcu_torture_ops rcu_bh_expedited_ops = {
526 .init = rcu_sync_torture_init,
527 .cleanup = NULL,
528 .readlock = rcu_bh_torture_read_lock,
529 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
530 .readunlock = rcu_bh_torture_read_unlock,
531 .completed = rcu_bh_torture_completed,
532 .deferred_free = rcu_sync_torture_deferred_free,
533 .sync = synchronize_rcu_bh_expedited,
534 .cb_barrier = NULL,
535 .fqs = rcu_bh_force_quiescent_state,
536 .stats = NULL,
537 .irq_capable = 1,
538 .name = "rcu_bh_expedited"
539};
540
b2896d2e
PM
541/*
542 * Definitions for srcu torture testing.
543 */
544
545static struct srcu_struct srcu_ctl;
b2896d2e
PM
546
547static void srcu_torture_init(void)
548{
549 init_srcu_struct(&srcu_ctl);
e3033736 550 rcu_sync_torture_init();
b2896d2e
PM
551}
552
553static void srcu_torture_cleanup(void)
554{
555 synchronize_srcu(&srcu_ctl);
556 cleanup_srcu_struct(&srcu_ctl);
557}
558
012d3ca8 559static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
b2896d2e
PM
560{
561 return srcu_read_lock(&srcu_ctl);
562}
563
564static void srcu_read_delay(struct rcu_random_state *rrsp)
565{
566 long delay;
567 const long uspertick = 1000000 / HZ;
568 const long longdelay = 10;
569
570 /* We want there to be long-running readers, but not all the time. */
571
572 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
573 if (!delay)
574 schedule_timeout_interruptible(longdelay);
e546f485
LJ
575 else
576 rcu_read_delay(rrsp);
b2896d2e
PM
577}
578
012d3ca8 579static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
b2896d2e
PM
580{
581 srcu_read_unlock(&srcu_ctl, idx);
582}
583
584static int srcu_torture_completed(void)
585{
586 return srcu_batches_completed(&srcu_ctl);
587}
588
b772e1dd
JT
589static void srcu_torture_synchronize(void)
590{
591 synchronize_srcu(&srcu_ctl);
592}
593
b2896d2e
PM
594static int srcu_torture_stats(char *page)
595{
596 int cnt = 0;
597 int cpu;
598 int idx = srcu_ctl.completed & 0x1;
599
600 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
601 torture_type, TORTURE_FLAG, idx);
602 for_each_possible_cpu(cpu) {
603 cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu,
604 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
605 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
606 }
607 cnt += sprintf(&page[cnt], "\n");
608 return cnt;
609}
610
611static struct rcu_torture_ops srcu_ops = {
0acc512c
PM
612 .init = srcu_torture_init,
613 .cleanup = srcu_torture_cleanup,
614 .readlock = srcu_torture_read_lock,
615 .read_delay = srcu_read_delay,
616 .readunlock = srcu_torture_read_unlock,
617 .completed = srcu_torture_completed,
618 .deferred_free = rcu_sync_torture_deferred_free,
619 .sync = srcu_torture_synchronize,
620 .cb_barrier = NULL,
621 .stats = srcu_torture_stats,
622 .name = "srcu"
b2896d2e
PM
623};
624
804bb837
PM
625static void srcu_torture_synchronize_expedited(void)
626{
627 synchronize_srcu_expedited(&srcu_ctl);
628}
629
630static struct rcu_torture_ops srcu_expedited_ops = {
631 .init = srcu_torture_init,
632 .cleanup = srcu_torture_cleanup,
633 .readlock = srcu_torture_read_lock,
634 .read_delay = srcu_read_delay,
635 .readunlock = srcu_torture_read_unlock,
636 .completed = srcu_torture_completed,
637 .deferred_free = rcu_sync_torture_deferred_free,
638 .sync = srcu_torture_synchronize_expedited,
639 .cb_barrier = NULL,
640 .stats = srcu_torture_stats,
641 .name = "srcu_expedited"
642};
643
4b6c2cca
JT
644/*
645 * Definitions for sched torture testing.
646 */
647
648static int sched_torture_read_lock(void)
649{
650 preempt_disable();
651 return 0;
652}
653
654static void sched_torture_read_unlock(int idx)
655{
656 preempt_enable();
657}
658
2326974d
PM
659static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
660{
661 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
662}
663
4b6c2cca 664static struct rcu_torture_ops sched_ops = {
0acc512c
PM
665 .init = rcu_sync_torture_init,
666 .cleanup = NULL,
667 .readlock = sched_torture_read_lock,
668 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
669 .readunlock = sched_torture_read_unlock,
d9a3da06 670 .completed = rcu_no_completed,
0acc512c 671 .deferred_free = rcu_sched_torture_deferred_free,
bdf2a436 672 .sync = synchronize_sched,
0acc512c 673 .cb_barrier = rcu_barrier_sched,
bf66f18e 674 .fqs = rcu_sched_force_quiescent_state,
0acc512c
PM
675 .stats = NULL,
676 .irq_capable = 1,
677 .name = "sched"
4b6c2cca
JT
678};
679
804bb837 680static struct rcu_torture_ops sched_sync_ops = {
0acc512c
PM
681 .init = rcu_sync_torture_init,
682 .cleanup = NULL,
683 .readlock = sched_torture_read_lock,
684 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
685 .readunlock = sched_torture_read_unlock,
d9a3da06 686 .completed = rcu_no_completed,
0acc512c 687 .deferred_free = rcu_sync_torture_deferred_free,
bdf2a436 688 .sync = synchronize_sched,
0acc512c 689 .cb_barrier = NULL,
bf66f18e 690 .fqs = rcu_sched_force_quiescent_state,
0acc512c
PM
691 .stats = NULL,
692 .name = "sched_sync"
693};
694
0acc512c
PM
695static struct rcu_torture_ops sched_expedited_ops = {
696 .init = rcu_sync_torture_init,
697 .cleanup = NULL,
698 .readlock = sched_torture_read_lock,
699 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
700 .readunlock = sched_torture_read_unlock,
d9a3da06 701 .completed = rcu_no_completed,
0acc512c
PM
702 .deferred_free = rcu_sync_torture_deferred_free,
703 .sync = synchronize_sched_expedited,
704 .cb_barrier = NULL,
bf66f18e 705 .fqs = rcu_sched_force_quiescent_state,
969c7921 706 .stats = NULL,
0acc512c
PM
707 .irq_capable = 1,
708 .name = "sched_expedited"
2326974d
PM
709};
710
8e8be45e
PM
711/*
712 * RCU torture priority-boost testing. Runs one real-time thread per
713 * CPU for moderate bursts, repeatedly registering RCU callbacks and
714 * spinning waiting for them to be invoked. If a given callback takes
715 * too long to be invoked, we assume that priority inversion has occurred.
716 */
717
718struct rcu_boost_inflight {
719 struct rcu_head rcu;
720 int inflight;
721};
722
723static void rcu_torture_boost_cb(struct rcu_head *head)
724{
725 struct rcu_boost_inflight *rbip =
726 container_of(head, struct rcu_boost_inflight, rcu);
727
728 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
729 rbip->inflight = 0;
730}
731
732static int rcu_torture_boost(void *arg)
733{
734 unsigned long call_rcu_time;
735 unsigned long endtime;
736 unsigned long oldstarttime;
737 struct rcu_boost_inflight rbi = { .inflight = 0 };
738 struct sched_param sp;
739
740 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
741
742 /* Set real-time priority. */
743 sp.sched_priority = 1;
744 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
745 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
746 n_rcu_torture_boost_rterror++;
747 }
748
561190e3 749 init_rcu_head_on_stack(&rbi.rcu);
8e8be45e
PM
750 /* Each pass through the following loop does one boost-test cycle. */
751 do {
752 /* Wait for the next test interval. */
753 oldstarttime = boost_starttime;
93898fb1 754 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
8e8be45e
PM
755 schedule_timeout_uninterruptible(1);
756 rcu_stutter_wait("rcu_torture_boost");
757 if (kthread_should_stop() ||
758 fullstop != FULLSTOP_DONTSTOP)
759 goto checkwait;
760 }
761
762 /* Do one boost-test interval. */
763 endtime = oldstarttime + test_boost_duration * HZ;
764 call_rcu_time = jiffies;
93898fb1 765 while (ULONG_CMP_LT(jiffies, endtime)) {
8e8be45e
PM
766 /* If we don't have a callback in flight, post one. */
767 if (!rbi.inflight) {
768 smp_mb(); /* RCU core before ->inflight = 1. */
769 rbi.inflight = 1;
770 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
771 if (jiffies - call_rcu_time >
772 test_boost_duration * HZ - HZ / 2) {
773 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
774 n_rcu_torture_boost_failure++;
775 }
776 call_rcu_time = jiffies;
777 }
778 cond_resched();
779 rcu_stutter_wait("rcu_torture_boost");
780 if (kthread_should_stop() ||
781 fullstop != FULLSTOP_DONTSTOP)
782 goto checkwait;
783 }
784
785 /*
786 * Set the start time of the next test interval.
787 * Yes, this is vulnerable to long delays, but such
788 * delays simply cause a false negative for the next
789 * interval. Besides, we are running at RT priority,
790 * so delays should be relatively rare.
791 */
ab8f11e5
PM
792 while (oldstarttime == boost_starttime &&
793 !kthread_should_stop()) {
8e8be45e
PM
794 if (mutex_trylock(&boost_mutex)) {
795 boost_starttime = jiffies +
796 test_boost_interval * HZ;
797 n_rcu_torture_boosts++;
798 mutex_unlock(&boost_mutex);
799 break;
800 }
801 schedule_timeout_uninterruptible(1);
802 }
803
804 /* Go do the stutter. */
805checkwait: rcu_stutter_wait("rcu_torture_boost");
806 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
807
808 /* Clean up and exit. */
809 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
810 rcutorture_shutdown_absorb("rcu_torture_boost");
811 while (!kthread_should_stop() || rbi.inflight)
812 schedule_timeout_uninterruptible(1);
813 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
9d68197c 814 destroy_rcu_head_on_stack(&rbi.rcu);
8e8be45e
PM
815 return 0;
816}
817
bf66f18e
PM
818/*
819 * RCU torture force-quiescent-state kthread. Repeatedly induces
820 * bursts of calls to force_quiescent_state(), increasing the probability
821 * of occurrence of some important types of race conditions.
822 */
823static int
824rcu_torture_fqs(void *arg)
825{
826 unsigned long fqs_resume_time;
827 int fqs_burst_remaining;
828
829 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
830 do {
831 fqs_resume_time = jiffies + fqs_stutter * HZ;
93898fb1
PM
832 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
833 !kthread_should_stop()) {
bf66f18e
PM
834 schedule_timeout_interruptible(1);
835 }
836 fqs_burst_remaining = fqs_duration;
93898fb1
PM
837 while (fqs_burst_remaining > 0 &&
838 !kthread_should_stop()) {
bf66f18e
PM
839 cur_ops->fqs();
840 udelay(fqs_holdoff);
841 fqs_burst_remaining -= fqs_holdoff;
842 }
843 rcu_stutter_wait("rcu_torture_fqs");
844 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
845 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
846 rcutorture_shutdown_absorb("rcu_torture_fqs");
847 while (!kthread_should_stop())
848 schedule_timeout_uninterruptible(1);
849 return 0;
850}
851
a241ec65
PM
852/*
853 * RCU torture writer kthread. Repeatedly substitutes a new structure
854 * for that pointed to by rcu_torture_current, freeing the old structure
855 * after a series of grace periods (the "pipeline").
856 */
857static int
858rcu_torture_writer(void *arg)
859{
860 int i;
861 long oldbatch = rcu_batches_completed();
862 struct rcu_torture *rp;
863 struct rcu_torture *old_rp;
864 static DEFINE_RCU_RANDOM(rand);
865
866 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
dbdf65b1
IM
867 set_user_nice(current, 19);
868
a241ec65
PM
869 do {
870 schedule_timeout_uninterruptible(1);
a71fca58
PM
871 rp = rcu_torture_alloc();
872 if (rp == NULL)
a241ec65
PM
873 continue;
874 rp->rtort_pipe_count = 0;
875 udelay(rcu_random(&rand) & 0x3ff);
0ddea0ea
PM
876 old_rp = rcu_dereference_check(rcu_torture_current,
877 current == writer_task);
996417d2 878 rp->rtort_mbtest = 1;
a241ec65 879 rcu_assign_pointer(rcu_torture_current, rp);
9b2619af 880 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
c8e5b163 881 if (old_rp) {
a241ec65
PM
882 i = old_rp->rtort_pipe_count;
883 if (i > RCU_TORTURE_PIPE_LEN)
884 i = RCU_TORTURE_PIPE_LEN;
885 atomic_inc(&rcu_torture_wcount[i]);
886 old_rp->rtort_pipe_count++;
0acc512c 887 cur_ops->deferred_free(old_rp);
a241ec65 888 }
4a298656 889 rcutorture_record_progress(++rcu_torture_current_version);
72e9bb54 890 oldbatch = cur_ops->completed();
c9d557c1
PM
891 rcu_stutter_wait("rcu_torture_writer");
892 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
a241ec65 893 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
c9d557c1
PM
894 rcutorture_shutdown_absorb("rcu_torture_writer");
895 while (!kthread_should_stop())
a241ec65
PM
896 schedule_timeout_uninterruptible(1);
897 return 0;
898}
899
b772e1dd
JT
900/*
901 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
902 * delay between calls.
903 */
904static int
905rcu_torture_fakewriter(void *arg)
906{
907 DEFINE_RCU_RANDOM(rand);
908
909 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
910 set_user_nice(current, 19);
911
912 do {
913 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
914 udelay(rcu_random(&rand) & 0x3ff);
915 cur_ops->sync();
c9d557c1
PM
916 rcu_stutter_wait("rcu_torture_fakewriter");
917 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
b772e1dd
JT
918
919 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
c9d557c1
PM
920 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
921 while (!kthread_should_stop())
b772e1dd
JT
922 schedule_timeout_uninterruptible(1);
923 return 0;
924}
925
91afaf30
PM
926void rcutorture_trace_dump(void)
927{
928 static atomic_t beenhere = ATOMIC_INIT(0);
929
930 if (atomic_read(&beenhere))
931 return;
932 if (atomic_xchg(&beenhere, 1) != 0)
933 return;
934 do_trace_rcu_torture_read(cur_ops->name, (struct rcu_head *)~0UL);
935 ftrace_dump(DUMP_ALL);
936}
937
0729fbf3
PM
938/*
939 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
940 * incrementing the corresponding element of the pipeline array. The
941 * counter in the element should never be greater than 1, otherwise, the
942 * RCU implementation is broken.
943 */
944static void rcu_torture_timer(unsigned long unused)
945{
946 int idx;
947 int completed;
948 static DEFINE_RCU_RANDOM(rand);
949 static DEFINE_SPINLOCK(rand_lock);
950 struct rcu_torture *p;
951 int pipe_count;
952
953 idx = cur_ops->readlock();
954 completed = cur_ops->completed();
632ee200 955 p = rcu_dereference_check(rcu_torture_current,
632ee200
PM
956 rcu_read_lock_bh_held() ||
957 rcu_read_lock_sched_held() ||
958 srcu_read_lock_held(&srcu_ctl));
91afaf30 959 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
0729fbf3
PM
960 if (p == NULL) {
961 /* Leave because rcu_torture_writer is not yet underway */
962 cur_ops->readunlock(idx);
963 return;
964 }
965 if (p->rtort_mbtest == 0)
966 atomic_inc(&n_rcu_torture_mberror);
967 spin_lock(&rand_lock);
0acc512c 968 cur_ops->read_delay(&rand);
0729fbf3
PM
969 n_rcu_torture_timers++;
970 spin_unlock(&rand_lock);
971 preempt_disable();
972 pipe_count = p->rtort_pipe_count;
973 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
974 /* Should not happen, but... */
975 pipe_count = RCU_TORTURE_PIPE_LEN;
976 }
91afaf30
PM
977 if (pipe_count > 1)
978 rcutorture_trace_dump();
dd17c8f7 979 __this_cpu_inc(rcu_torture_count[pipe_count]);
0729fbf3
PM
980 completed = cur_ops->completed() - completed;
981 if (completed > RCU_TORTURE_PIPE_LEN) {
982 /* Should not happen, but... */
983 completed = RCU_TORTURE_PIPE_LEN;
984 }
dd17c8f7 985 __this_cpu_inc(rcu_torture_batch[completed]);
0729fbf3
PM
986 preempt_enable();
987 cur_ops->readunlock(idx);
988}
989
a241ec65
PM
990/*
991 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
992 * incrementing the corresponding element of the pipeline array. The
993 * counter in the element should never be greater than 1, otherwise, the
994 * RCU implementation is broken.
995 */
996static int
997rcu_torture_reader(void *arg)
998{
999 int completed;
72e9bb54 1000 int idx;
a241ec65
PM
1001 DEFINE_RCU_RANDOM(rand);
1002 struct rcu_torture *p;
1003 int pipe_count;
0729fbf3 1004 struct timer_list t;
a241ec65
PM
1005
1006 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
dbdf65b1 1007 set_user_nice(current, 19);
0acc512c 1008 if (irqreader && cur_ops->irq_capable)
0729fbf3 1009 setup_timer_on_stack(&t, rcu_torture_timer, 0);
dbdf65b1 1010
a241ec65 1011 do {
0acc512c 1012 if (irqreader && cur_ops->irq_capable) {
0729fbf3 1013 if (!timer_pending(&t))
6155fec9 1014 mod_timer(&t, jiffies + 1);
0729fbf3 1015 }
72e9bb54
PM
1016 idx = cur_ops->readlock();
1017 completed = cur_ops->completed();
632ee200 1018 p = rcu_dereference_check(rcu_torture_current,
632ee200
PM
1019 rcu_read_lock_bh_held() ||
1020 rcu_read_lock_sched_held() ||
1021 srcu_read_lock_held(&srcu_ctl));
91afaf30 1022 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
a241ec65
PM
1023 if (p == NULL) {
1024 /* Wait for rcu_torture_writer to get underway */
72e9bb54 1025 cur_ops->readunlock(idx);
a241ec65
PM
1026 schedule_timeout_interruptible(HZ);
1027 continue;
1028 }
996417d2
PM
1029 if (p->rtort_mbtest == 0)
1030 atomic_inc(&n_rcu_torture_mberror);
0acc512c 1031 cur_ops->read_delay(&rand);
a241ec65
PM
1032 preempt_disable();
1033 pipe_count = p->rtort_pipe_count;
1034 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1035 /* Should not happen, but... */
1036 pipe_count = RCU_TORTURE_PIPE_LEN;
1037 }
91afaf30
PM
1038 if (pipe_count > 1)
1039 rcutorture_trace_dump();
dd17c8f7 1040 __this_cpu_inc(rcu_torture_count[pipe_count]);
72e9bb54 1041 completed = cur_ops->completed() - completed;
a241ec65
PM
1042 if (completed > RCU_TORTURE_PIPE_LEN) {
1043 /* Should not happen, but... */
1044 completed = RCU_TORTURE_PIPE_LEN;
1045 }
dd17c8f7 1046 __this_cpu_inc(rcu_torture_batch[completed]);
a241ec65 1047 preempt_enable();
72e9bb54 1048 cur_ops->readunlock(idx);
a241ec65 1049 schedule();
c9d557c1
PM
1050 rcu_stutter_wait("rcu_torture_reader");
1051 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
a241ec65 1052 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
c9d557c1 1053 rcutorture_shutdown_absorb("rcu_torture_reader");
0acc512c 1054 if (irqreader && cur_ops->irq_capable)
0729fbf3 1055 del_timer_sync(&t);
c9d557c1 1056 while (!kthread_should_stop())
a241ec65
PM
1057 schedule_timeout_uninterruptible(1);
1058 return 0;
1059}
1060
1061/*
1062 * Create an RCU-torture statistics message in the specified buffer.
1063 */
1064static int
1065rcu_torture_printk(char *page)
1066{
1067 int cnt = 0;
1068 int cpu;
1069 int i;
1070 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1071 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1072
0a945022 1073 for_each_possible_cpu(cpu) {
a241ec65
PM
1074 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1075 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1076 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1077 }
1078 }
1079 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1080 if (pipesummary[i] != 0)
1081 break;
1082 }
72e9bb54 1083 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
a241ec65 1084 cnt += sprintf(&page[cnt],
4a298656 1085 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d "
67b98dba 1086 "rtmbe: %d rtbke: %ld rtbre: %ld "
8e8be45e 1087 "rtbf: %ld rtb: %ld nt: %ld",
a241ec65
PM
1088 rcu_torture_current,
1089 rcu_torture_current_version,
1090 list_empty(&rcu_torture_freelist),
1091 atomic_read(&n_rcu_torture_alloc),
1092 atomic_read(&n_rcu_torture_alloc_fail),
996417d2 1093 atomic_read(&n_rcu_torture_free),
0729fbf3 1094 atomic_read(&n_rcu_torture_mberror),
8e8be45e
PM
1095 n_rcu_torture_boost_ktrerror,
1096 n_rcu_torture_boost_rterror,
8e8be45e
PM
1097 n_rcu_torture_boost_failure,
1098 n_rcu_torture_boosts,
0729fbf3 1099 n_rcu_torture_timers);
8e8be45e
PM
1100 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
1101 n_rcu_torture_boost_ktrerror != 0 ||
1102 n_rcu_torture_boost_rterror != 0 ||
8e8be45e 1103 n_rcu_torture_boost_failure != 0)
996417d2 1104 cnt += sprintf(&page[cnt], " !!!");
72e9bb54 1105 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
996417d2 1106 if (i > 1) {
a241ec65 1107 cnt += sprintf(&page[cnt], "!!! ");
996417d2 1108 atomic_inc(&n_rcu_torture_error);
5af970a4 1109 WARN_ON_ONCE(1);
996417d2 1110 }
a241ec65
PM
1111 cnt += sprintf(&page[cnt], "Reader Pipe: ");
1112 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1113 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
72e9bb54 1114 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
a241ec65 1115 cnt += sprintf(&page[cnt], "Reader Batch: ");
72e9bb54 1116 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
a241ec65 1117 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
72e9bb54 1118 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
a241ec65
PM
1119 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
1120 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1121 cnt += sprintf(&page[cnt], " %d",
1122 atomic_read(&rcu_torture_wcount[i]));
1123 }
1124 cnt += sprintf(&page[cnt], "\n");
c8e5b163 1125 if (cur_ops->stats)
72e9bb54 1126 cnt += cur_ops->stats(&page[cnt]);
a241ec65
PM
1127 return cnt;
1128}
1129
1130/*
1131 * Print torture statistics. Caller must ensure that there is only
1132 * one call to this function at a given time!!! This is normally
1133 * accomplished by relying on the module system to only have one copy
1134 * of the module loaded, and then by giving the rcu_torture_stats
1135 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1136 * thread is not running).
1137 */
1138static void
1139rcu_torture_stats_print(void)
1140{
1141 int cnt;
1142
1143 cnt = rcu_torture_printk(printk_buf);
1144 printk(KERN_ALERT "%s", printk_buf);
1145}
1146
1147/*
1148 * Periodically prints torture statistics, if periodic statistics printing
1149 * was specified via the stat_interval module parameter.
1150 *
1151 * No need to worry about fullstop here, since this one doesn't reference
1152 * volatile state or register callbacks.
1153 */
1154static int
1155rcu_torture_stats(void *arg)
1156{
1157 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1158 do {
1159 schedule_timeout_interruptible(stat_interval * HZ);
1160 rcu_torture_stats_print();
c9d557c1
PM
1161 rcutorture_shutdown_absorb("rcu_torture_stats");
1162 } while (!kthread_should_stop());
a241ec65
PM
1163 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1164 return 0;
1165}
1166
d84f5203
SV
1167static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
1168
1169/* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1170 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1171 */
b2896d2e 1172static void rcu_torture_shuffle_tasks(void)
d84f5203 1173{
d84f5203
SV
1174 int i;
1175
73d0a4b1 1176 cpumask_setall(shuffle_tmp_mask);
86ef5c9a 1177 get_online_cpus();
d84f5203
SV
1178
1179 /* No point in shuffling if there is only one online CPU (ex: UP) */
c9d557c1
PM
1180 if (num_online_cpus() == 1) {
1181 put_online_cpus();
1182 return;
1183 }
d84f5203
SV
1184
1185 if (rcu_idle_cpu != -1)
73d0a4b1 1186 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
d84f5203 1187
73d0a4b1 1188 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
d84f5203 1189
c8e5b163 1190 if (reader_tasks) {
d84f5203
SV
1191 for (i = 0; i < nrealreaders; i++)
1192 if (reader_tasks[i])
f70316da 1193 set_cpus_allowed_ptr(reader_tasks[i],
73d0a4b1 1194 shuffle_tmp_mask);
d84f5203
SV
1195 }
1196
c8e5b163 1197 if (fakewriter_tasks) {
b772e1dd
JT
1198 for (i = 0; i < nfakewriters; i++)
1199 if (fakewriter_tasks[i])
f70316da 1200 set_cpus_allowed_ptr(fakewriter_tasks[i],
73d0a4b1 1201 shuffle_tmp_mask);
b772e1dd
JT
1202 }
1203
d84f5203 1204 if (writer_task)
73d0a4b1 1205 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
d84f5203
SV
1206
1207 if (stats_task)
73d0a4b1 1208 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
d84f5203
SV
1209
1210 if (rcu_idle_cpu == -1)
1211 rcu_idle_cpu = num_online_cpus() - 1;
1212 else
1213 rcu_idle_cpu--;
1214
86ef5c9a 1215 put_online_cpus();
d84f5203
SV
1216}
1217
1218/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1219 * system to become idle at a time and cut off its timer ticks. This is meant
1220 * to test the support for such tickless idle CPU in RCU.
1221 */
1222static int
1223rcu_torture_shuffle(void *arg)
1224{
1225 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1226 do {
1227 schedule_timeout_interruptible(shuffle_interval * HZ);
1228 rcu_torture_shuffle_tasks();
c9d557c1
PM
1229 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1230 } while (!kthread_should_stop());
d84f5203
SV
1231 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1232 return 0;
1233}
1234
d120f65f
PM
1235/* Cause the rcutorture test to "stutter", starting and stopping all
1236 * threads periodically.
1237 */
1238static int
1239rcu_torture_stutter(void *arg)
1240{
1241 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1242 do {
1243 schedule_timeout_interruptible(stutter * HZ);
1244 stutter_pause_test = 1;
c9d557c1 1245 if (!kthread_should_stop())
d120f65f
PM
1246 schedule_timeout_interruptible(stutter * HZ);
1247 stutter_pause_test = 0;
c9d557c1
PM
1248 rcutorture_shutdown_absorb("rcu_torture_stutter");
1249 } while (!kthread_should_stop());
d120f65f
PM
1250 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1251 return 0;
1252}
1253
95c38322 1254static inline void
8e8be45e 1255rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
95c38322 1256{
b772e1dd
JT
1257 printk(KERN_ALERT "%s" TORTURE_FLAG
1258 "--- %s: nreaders=%d nfakewriters=%d "
95c38322 1259 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
bf66f18e 1260 "shuffle_interval=%d stutter=%d irqreader=%d "
8e8be45e
PM
1261 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1262 "test_boost=%d/%d test_boost_interval=%d "
d5f546d8 1263 "test_boost_duration=%d shutdown_secs=%d\n",
b772e1dd 1264 torture_type, tag, nrealreaders, nfakewriters,
d120f65f 1265 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
8e8be45e
PM
1266 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1267 test_boost, cur_ops->can_boost,
d5f546d8 1268 test_boost_interval, test_boost_duration, shutdown_secs);
95c38322
PM
1269}
1270
8e8be45e 1271static struct notifier_block rcutorture_shutdown_nb = {
343e9099
PM
1272 .notifier_call = rcutorture_shutdown_notify,
1273};
1274
8e8be45e
PM
1275static void rcutorture_booster_cleanup(int cpu)
1276{
1277 struct task_struct *t;
1278
1279 if (boost_tasks[cpu] == NULL)
1280 return;
1281 mutex_lock(&boost_mutex);
1282 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1283 t = boost_tasks[cpu];
1284 boost_tasks[cpu] = NULL;
1285 mutex_unlock(&boost_mutex);
1286
1287 /* This must be outside of the mutex, otherwise deadlock! */
1288 kthread_stop(t);
1289}
1290
1291static int rcutorture_booster_init(int cpu)
1292{
1293 int retval;
1294
1295 if (boost_tasks[cpu] != NULL)
1296 return 0; /* Already created, nothing more to do. */
1297
1298 /* Don't allow time recalculation while creating a new task. */
1299 mutex_lock(&boost_mutex);
1300 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
1f288094
ED
1301 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1302 cpu_to_node(cpu),
1303 "rcu_torture_boost");
8e8be45e
PM
1304 if (IS_ERR(boost_tasks[cpu])) {
1305 retval = PTR_ERR(boost_tasks[cpu]);
1306 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1307 n_rcu_torture_boost_ktrerror++;
1308 boost_tasks[cpu] = NULL;
1309 mutex_unlock(&boost_mutex);
1310 return retval;
1311 }
1312 kthread_bind(boost_tasks[cpu], cpu);
1313 wake_up_process(boost_tasks[cpu]);
1314 mutex_unlock(&boost_mutex);
1315 return 0;
1316}
1317
d5f546d8
PM
1318/*
1319 * Cause the rcutorture test to shutdown the system after the test has
1320 * run for the time specified by the shutdown_secs module parameter.
1321 */
1322static int
1323rcu_torture_shutdown(void *arg)
1324{
1325 long delta;
1326 unsigned long jiffies_snap;
1327
1328 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1329 jiffies_snap = ACCESS_ONCE(jiffies);
1330 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
1331 !kthread_should_stop()) {
1332 delta = shutdown_time - jiffies_snap;
1333 if (verbose)
1334 printk(KERN_ALERT "%s" TORTURE_FLAG
1335 "rcu_torture_shutdown task: %lu "
1336 "jiffies remaining\n",
1337 torture_type, delta);
1338 schedule_timeout_interruptible(delta);
1339 jiffies_snap = ACCESS_ONCE(jiffies);
1340 }
1341 if (ULONG_CMP_LT(jiffies, shutdown_time)) {
1342 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1343 return 0;
1344 }
1345
1346 /* OK, shut down the system. */
1347
1348 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1349 shutdown_task = NULL; /* Avoid self-kill deadlock. */
1350 rcu_torture_cleanup(); /* Get the success/failure message. */
1351 kernel_power_off(); /* Shut down the system. */
1352 return 0;
1353}
1354
8e8be45e
PM
1355static int rcutorture_cpu_notify(struct notifier_block *self,
1356 unsigned long action, void *hcpu)
1357{
1358 long cpu = (long)hcpu;
1359
1360 switch (action) {
1361 case CPU_ONLINE:
1362 case CPU_DOWN_FAILED:
1363 (void)rcutorture_booster_init(cpu);
1364 break;
1365 case CPU_DOWN_PREPARE:
1366 rcutorture_booster_cleanup(cpu);
1367 break;
1368 default:
1369 break;
1370 }
1371 return NOTIFY_OK;
1372}
1373
1374static struct notifier_block rcutorture_cpu_nb = {
1375 .notifier_call = rcutorture_cpu_notify,
1376};
1377
a241ec65
PM
1378static void
1379rcu_torture_cleanup(void)
1380{
1381 int i;
1382
343e9099 1383 mutex_lock(&fullstop_mutex);
4a298656 1384 rcutorture_record_test_transition();
c9d557c1
PM
1385 if (fullstop == FULLSTOP_SHUTDOWN) {
1386 printk(KERN_WARNING /* but going down anyway, so... */
1387 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
343e9099 1388 mutex_unlock(&fullstop_mutex);
c9d557c1 1389 schedule_timeout_uninterruptible(10);
343e9099
PM
1390 if (cur_ops->cb_barrier != NULL)
1391 cur_ops->cb_barrier();
1392 return;
1393 }
c9d557c1 1394 fullstop = FULLSTOP_RMMOD;
343e9099 1395 mutex_unlock(&fullstop_mutex);
8e8be45e 1396 unregister_reboot_notifier(&rcutorture_shutdown_nb);
d120f65f
PM
1397 if (stutter_task) {
1398 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1399 kthread_stop(stutter_task);
1400 }
1401 stutter_task = NULL;
c8e5b163 1402 if (shuffler_task) {
d84f5203
SV
1403 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1404 kthread_stop(shuffler_task);
73d0a4b1 1405 free_cpumask_var(shuffle_tmp_mask);
d84f5203
SV
1406 }
1407 shuffler_task = NULL;
1408
c8e5b163 1409 if (writer_task) {
a241ec65
PM
1410 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1411 kthread_stop(writer_task);
1412 }
1413 writer_task = NULL;
1414
c8e5b163 1415 if (reader_tasks) {
a241ec65 1416 for (i = 0; i < nrealreaders; i++) {
c8e5b163 1417 if (reader_tasks[i]) {
a241ec65
PM
1418 VERBOSE_PRINTK_STRING(
1419 "Stopping rcu_torture_reader task");
1420 kthread_stop(reader_tasks[i]);
1421 }
1422 reader_tasks[i] = NULL;
1423 }
1424 kfree(reader_tasks);
1425 reader_tasks = NULL;
1426 }
1427 rcu_torture_current = NULL;
1428
c8e5b163 1429 if (fakewriter_tasks) {
b772e1dd 1430 for (i = 0; i < nfakewriters; i++) {
c8e5b163 1431 if (fakewriter_tasks[i]) {
b772e1dd
JT
1432 VERBOSE_PRINTK_STRING(
1433 "Stopping rcu_torture_fakewriter task");
1434 kthread_stop(fakewriter_tasks[i]);
1435 }
1436 fakewriter_tasks[i] = NULL;
1437 }
1438 kfree(fakewriter_tasks);
1439 fakewriter_tasks = NULL;
1440 }
1441
c8e5b163 1442 if (stats_task) {
a241ec65
PM
1443 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1444 kthread_stop(stats_task);
1445 }
1446 stats_task = NULL;
1447
bf66f18e
PM
1448 if (fqs_task) {
1449 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1450 kthread_stop(fqs_task);
1451 }
1452 fqs_task = NULL;
8e8be45e
PM
1453 if ((test_boost == 1 && cur_ops->can_boost) ||
1454 test_boost == 2) {
1455 unregister_cpu_notifier(&rcutorture_cpu_nb);
1456 for_each_possible_cpu(i)
1457 rcutorture_booster_cleanup(i);
1458 }
d5f546d8
PM
1459 if (shutdown_task != NULL) {
1460 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1461 kthread_stop(shutdown_task);
1462 }
bf66f18e 1463
a241ec65 1464 /* Wait for all RCU callbacks to fire. */
2326974d
PM
1465
1466 if (cur_ops->cb_barrier != NULL)
1467 cur_ops->cb_barrier();
a241ec65 1468
a241ec65 1469 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
72e9bb54 1470
c8e5b163 1471 if (cur_ops->cleanup)
72e9bb54 1472 cur_ops->cleanup();
95c38322 1473 if (atomic_read(&n_rcu_torture_error))
8e8be45e 1474 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
95c38322 1475 else
8e8be45e 1476 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
a241ec65
PM
1477}
1478
6f8bc500 1479static int __init
a241ec65
PM
1480rcu_torture_init(void)
1481{
1482 int i;
1483 int cpu;
1484 int firsterr = 0;
ade5fb81 1485 static struct rcu_torture_ops *torture_ops[] =
d9a3da06 1486 { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
bdf2a436 1487 &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops,
804bb837
PM
1488 &srcu_ops, &srcu_expedited_ops,
1489 &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
a241ec65 1490
343e9099
PM
1491 mutex_lock(&fullstop_mutex);
1492
a241ec65 1493 /* Process args and tell the world that the torturer is on the job. */
ade5fb81 1494 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
72e9bb54 1495 cur_ops = torture_ops[i];
ade5fb81 1496 if (strcmp(torture_type, cur_ops->name) == 0)
72e9bb54 1497 break;
72e9bb54 1498 }
ade5fb81 1499 if (i == ARRAY_SIZE(torture_ops)) {
cf886c44 1500 printk(KERN_ALERT "rcu-torture: invalid torture type: \"%s\"\n",
72e9bb54 1501 torture_type);
cf886c44
PM
1502 printk(KERN_ALERT "rcu-torture types:");
1503 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
1504 printk(KERN_ALERT " %s", torture_ops[i]->name);
1505 printk(KERN_ALERT "\n");
343e9099 1506 mutex_unlock(&fullstop_mutex);
a71fca58 1507 return -EINVAL;
72e9bb54 1508 }
bf66f18e
PM
1509 if (cur_ops->fqs == NULL && fqs_duration != 0) {
1510 printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero "
1511 "fqs_duration, fqs disabled.\n");
1512 fqs_duration = 0;
1513 }
c8e5b163 1514 if (cur_ops->init)
72e9bb54
PM
1515 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1516
a241ec65
PM
1517 if (nreaders >= 0)
1518 nrealreaders = nreaders;
1519 else
1520 nrealreaders = 2 * num_online_cpus();
8e8be45e 1521 rcu_torture_print_module_parms(cur_ops, "Start of test");
c9d557c1 1522 fullstop = FULLSTOP_DONTSTOP;
a241ec65
PM
1523
1524 /* Set up the freelist. */
1525
1526 INIT_LIST_HEAD(&rcu_torture_freelist);
788e770e 1527 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
996417d2 1528 rcu_tortures[i].rtort_mbtest = 0;
a241ec65
PM
1529 list_add_tail(&rcu_tortures[i].rtort_free,
1530 &rcu_torture_freelist);
1531 }
1532
1533 /* Initialize the statistics so that each run gets its own numbers. */
1534
1535 rcu_torture_current = NULL;
1536 rcu_torture_current_version = 0;
1537 atomic_set(&n_rcu_torture_alloc, 0);
1538 atomic_set(&n_rcu_torture_alloc_fail, 0);
1539 atomic_set(&n_rcu_torture_free, 0);
996417d2
PM
1540 atomic_set(&n_rcu_torture_mberror, 0);
1541 atomic_set(&n_rcu_torture_error, 0);
8e8be45e
PM
1542 n_rcu_torture_boost_ktrerror = 0;
1543 n_rcu_torture_boost_rterror = 0;
8e8be45e
PM
1544 n_rcu_torture_boost_failure = 0;
1545 n_rcu_torture_boosts = 0;
a241ec65
PM
1546 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1547 atomic_set(&rcu_torture_wcount[i], 0);
0a945022 1548 for_each_possible_cpu(cpu) {
a241ec65
PM
1549 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1550 per_cpu(rcu_torture_count, cpu)[i] = 0;
1551 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1552 }
1553 }
1554
1555 /* Start up the kthreads. */
1556
1557 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1558 writer_task = kthread_run(rcu_torture_writer, NULL,
1559 "rcu_torture_writer");
1560 if (IS_ERR(writer_task)) {
1561 firsterr = PTR_ERR(writer_task);
1562 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1563 writer_task = NULL;
1564 goto unwind;
1565 }
b772e1dd 1566 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
a71fca58 1567 GFP_KERNEL);
b772e1dd
JT
1568 if (fakewriter_tasks == NULL) {
1569 VERBOSE_PRINTK_ERRSTRING("out of memory");
1570 firsterr = -ENOMEM;
1571 goto unwind;
1572 }
1573 for (i = 0; i < nfakewriters; i++) {
1574 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
1575 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
a71fca58 1576 "rcu_torture_fakewriter");
b772e1dd
JT
1577 if (IS_ERR(fakewriter_tasks[i])) {
1578 firsterr = PTR_ERR(fakewriter_tasks[i]);
1579 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
1580 fakewriter_tasks[i] = NULL;
1581 goto unwind;
1582 }
1583 }
2860aaba 1584 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
a241ec65
PM
1585 GFP_KERNEL);
1586 if (reader_tasks == NULL) {
1587 VERBOSE_PRINTK_ERRSTRING("out of memory");
1588 firsterr = -ENOMEM;
1589 goto unwind;
1590 }
1591 for (i = 0; i < nrealreaders; i++) {
1592 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
1593 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
1594 "rcu_torture_reader");
1595 if (IS_ERR(reader_tasks[i])) {
1596 firsterr = PTR_ERR(reader_tasks[i]);
1597 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
1598 reader_tasks[i] = NULL;
1599 goto unwind;
1600 }
1601 }
1602 if (stat_interval > 0) {
1603 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
1604 stats_task = kthread_run(rcu_torture_stats, NULL,
1605 "rcu_torture_stats");
1606 if (IS_ERR(stats_task)) {
1607 firsterr = PTR_ERR(stats_task);
1608 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
1609 stats_task = NULL;
1610 goto unwind;
1611 }
1612 }
d84f5203
SV
1613 if (test_no_idle_hz) {
1614 rcu_idle_cpu = num_online_cpus() - 1;
73d0a4b1
RR
1615
1616 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
1617 firsterr = -ENOMEM;
1618 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
1619 goto unwind;
1620 }
1621
d84f5203
SV
1622 /* Create the shuffler thread */
1623 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
1624 "rcu_torture_shuffle");
1625 if (IS_ERR(shuffler_task)) {
73d0a4b1 1626 free_cpumask_var(shuffle_tmp_mask);
d84f5203
SV
1627 firsterr = PTR_ERR(shuffler_task);
1628 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
1629 shuffler_task = NULL;
1630 goto unwind;
1631 }
1632 }
d120f65f
PM
1633 if (stutter < 0)
1634 stutter = 0;
1635 if (stutter) {
1636 /* Create the stutter thread */
1637 stutter_task = kthread_run(rcu_torture_stutter, NULL,
1638 "rcu_torture_stutter");
1639 if (IS_ERR(stutter_task)) {
1640 firsterr = PTR_ERR(stutter_task);
1641 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
1642 stutter_task = NULL;
1643 goto unwind;
1644 }
1645 }
bf66f18e
PM
1646 if (fqs_duration < 0)
1647 fqs_duration = 0;
1648 if (fqs_duration) {
1649 /* Create the stutter thread */
1650 fqs_task = kthread_run(rcu_torture_fqs, NULL,
1651 "rcu_torture_fqs");
1652 if (IS_ERR(fqs_task)) {
1653 firsterr = PTR_ERR(fqs_task);
1654 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
1655 fqs_task = NULL;
1656 goto unwind;
1657 }
1658 }
8e8be45e
PM
1659 if (test_boost_interval < 1)
1660 test_boost_interval = 1;
1661 if (test_boost_duration < 2)
1662 test_boost_duration = 2;
1663 if ((test_boost == 1 && cur_ops->can_boost) ||
1664 test_boost == 2) {
1665 int retval;
1666
1667 boost_starttime = jiffies + test_boost_interval * HZ;
1668 register_cpu_notifier(&rcutorture_cpu_nb);
1669 for_each_possible_cpu(i) {
1670 if (cpu_is_offline(i))
1671 continue; /* Heuristic: CPU can go offline. */
1672 retval = rcutorture_booster_init(i);
1673 if (retval < 0) {
1674 firsterr = retval;
1675 goto unwind;
1676 }
1677 }
1678 }
d5f546d8
PM
1679 if (shutdown_secs > 0) {
1680 shutdown_time = jiffies + shutdown_secs * HZ;
1681 shutdown_task = kthread_run(rcu_torture_shutdown, NULL,
1682 "rcu_torture_shutdown");
1683 if (IS_ERR(shutdown_task)) {
1684 firsterr = PTR_ERR(shutdown_task);
1685 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
1686 shutdown_task = NULL;
1687 goto unwind;
1688 }
1689 }
8e8be45e 1690 register_reboot_notifier(&rcutorture_shutdown_nb);
4a298656 1691 rcutorture_record_test_transition();
343e9099 1692 mutex_unlock(&fullstop_mutex);
a241ec65
PM
1693 return 0;
1694
1695unwind:
343e9099 1696 mutex_unlock(&fullstop_mutex);
a241ec65
PM
1697 rcu_torture_cleanup();
1698 return firsterr;
1699}
1700
1701module_init(rcu_torture_init);
1702module_exit(rcu_torture_cleanup);