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