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