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