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