Merge branches 'doctorture.2013.01.29a', 'fixes.2013.01.26a', 'tagcb.2013.01.24a...
[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)) {
0e11c8e8 849 schedule_timeout_interruptible(oldstarttime - jiffies);
8e8be45e
PM
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 1320 }
c8e5b163 1321 if (fakewriter_tasks) {
b772e1dd
JT
1322 for (i = 0; i < nfakewriters; i++)
1323 if (fakewriter_tasks[i])
f70316da 1324 set_cpus_allowed_ptr(fakewriter_tasks[i],
73d0a4b1 1325 shuffle_tmp_mask);
b772e1dd 1326 }
d84f5203 1327 if (writer_task)
73d0a4b1 1328 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
d84f5203 1329 if (stats_task)
73d0a4b1 1330 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
0e11c8e8
PM
1331 if (stutter_task)
1332 set_cpus_allowed_ptr(stutter_task, shuffle_tmp_mask);
1333 if (fqs_task)
1334 set_cpus_allowed_ptr(fqs_task, shuffle_tmp_mask);
1335 if (shutdown_task)
1336 set_cpus_allowed_ptr(shutdown_task, shuffle_tmp_mask);
1337#ifdef CONFIG_HOTPLUG_CPU
1338 if (onoff_task)
1339 set_cpus_allowed_ptr(onoff_task, shuffle_tmp_mask);
1340#endif /* #ifdef CONFIG_HOTPLUG_CPU */
1341 if (stall_task)
1342 set_cpus_allowed_ptr(stall_task, shuffle_tmp_mask);
1343 if (barrier_cbs_tasks)
1344 for (i = 0; i < n_barrier_cbs; i++)
1345 if (barrier_cbs_tasks[i])
1346 set_cpus_allowed_ptr(barrier_cbs_tasks[i],
1347 shuffle_tmp_mask);
1348 if (barrier_task)
1349 set_cpus_allowed_ptr(barrier_task, shuffle_tmp_mask);
d84f5203
SV
1350
1351 if (rcu_idle_cpu == -1)
1352 rcu_idle_cpu = num_online_cpus() - 1;
1353 else
1354 rcu_idle_cpu--;
1355
86ef5c9a 1356 put_online_cpus();
d84f5203
SV
1357}
1358
1359/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1360 * system to become idle at a time and cut off its timer ticks. This is meant
1361 * to test the support for such tickless idle CPU in RCU.
1362 */
1363static int
1364rcu_torture_shuffle(void *arg)
1365{
1366 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1367 do {
1368 schedule_timeout_interruptible(shuffle_interval * HZ);
1369 rcu_torture_shuffle_tasks();
c9d557c1
PM
1370 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1371 } while (!kthread_should_stop());
d84f5203
SV
1372 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1373 return 0;
1374}
1375
d120f65f
PM
1376/* Cause the rcutorture test to "stutter", starting and stopping all
1377 * threads periodically.
1378 */
1379static int
1380rcu_torture_stutter(void *arg)
1381{
1382 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1383 do {
1384 schedule_timeout_interruptible(stutter * HZ);
1385 stutter_pause_test = 1;
c9d557c1 1386 if (!kthread_should_stop())
d120f65f
PM
1387 schedule_timeout_interruptible(stutter * HZ);
1388 stutter_pause_test = 0;
c9d557c1
PM
1389 rcutorture_shutdown_absorb("rcu_torture_stutter");
1390 } while (!kthread_should_stop());
d120f65f
PM
1391 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1392 return 0;
1393}
1394
95c38322 1395static inline void
8e8be45e 1396rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
95c38322 1397{
2caa1e44
PM
1398 pr_alert("%s" TORTURE_FLAG
1399 "--- %s: nreaders=%d nfakewriters=%d "
1400 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1401 "shuffle_interval=%d stutter=%d irqreader=%d "
1402 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1403 "test_boost=%d/%d test_boost_interval=%d "
1404 "test_boost_duration=%d shutdown_secs=%d "
67afeed2
PM
1405 "stall_cpu=%d stall_cpu_holdoff=%d "
1406 "n_barrier_cbs=%d "
2caa1e44
PM
1407 "onoff_interval=%d onoff_holdoff=%d\n",
1408 torture_type, tag, nrealreaders, nfakewriters,
1409 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
1410 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1411 test_boost, cur_ops->can_boost,
1412 test_boost_interval, test_boost_duration, shutdown_secs,
67afeed2
PM
1413 stall_cpu, stall_cpu_holdoff,
1414 n_barrier_cbs,
2caa1e44 1415 onoff_interval, onoff_holdoff);
95c38322
PM
1416}
1417
8e8be45e 1418static struct notifier_block rcutorture_shutdown_nb = {
343e9099
PM
1419 .notifier_call = rcutorture_shutdown_notify,
1420};
1421
8e8be45e
PM
1422static void rcutorture_booster_cleanup(int cpu)
1423{
1424 struct task_struct *t;
1425
1426 if (boost_tasks[cpu] == NULL)
1427 return;
1428 mutex_lock(&boost_mutex);
1429 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1430 t = boost_tasks[cpu];
1431 boost_tasks[cpu] = NULL;
1432 mutex_unlock(&boost_mutex);
1433
1434 /* This must be outside of the mutex, otherwise deadlock! */
1435 kthread_stop(t);
37e377d2 1436 boost_tasks[cpu] = NULL;
8e8be45e
PM
1437}
1438
1439static int rcutorture_booster_init(int cpu)
1440{
1441 int retval;
1442
1443 if (boost_tasks[cpu] != NULL)
1444 return 0; /* Already created, nothing more to do. */
1445
1446 /* Don't allow time recalculation while creating a new task. */
1447 mutex_lock(&boost_mutex);
1448 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
1f288094
ED
1449 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1450 cpu_to_node(cpu),
1451 "rcu_torture_boost");
8e8be45e
PM
1452 if (IS_ERR(boost_tasks[cpu])) {
1453 retval = PTR_ERR(boost_tasks[cpu]);
1454 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1455 n_rcu_torture_boost_ktrerror++;
1456 boost_tasks[cpu] = NULL;
1457 mutex_unlock(&boost_mutex);
1458 return retval;
1459 }
1460 kthread_bind(boost_tasks[cpu], cpu);
1461 wake_up_process(boost_tasks[cpu]);
1462 mutex_unlock(&boost_mutex);
1463 return 0;
1464}
1465
d5f546d8
PM
1466/*
1467 * Cause the rcutorture test to shutdown the system after the test has
1468 * run for the time specified by the shutdown_secs module parameter.
1469 */
1470static int
1471rcu_torture_shutdown(void *arg)
1472{
1473 long delta;
1474 unsigned long jiffies_snap;
1475
1476 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1477 jiffies_snap = ACCESS_ONCE(jiffies);
1478 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
1479 !kthread_should_stop()) {
1480 delta = shutdown_time - jiffies_snap;
1481 if (verbose)
2caa1e44
PM
1482 pr_alert("%s" TORTURE_FLAG
1483 "rcu_torture_shutdown task: %lu jiffies remaining\n",
1484 torture_type, delta);
d5f546d8
PM
1485 schedule_timeout_interruptible(delta);
1486 jiffies_snap = ACCESS_ONCE(jiffies);
1487 }
b58bdcca 1488 if (kthread_should_stop()) {
d5f546d8
PM
1489 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1490 return 0;
1491 }
1492
1493 /* OK, shut down the system. */
1494
1495 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1496 shutdown_task = NULL; /* Avoid self-kill deadlock. */
1497 rcu_torture_cleanup(); /* Get the success/failure message. */
1498 kernel_power_off(); /* Shut down the system. */
1499 return 0;
1500}
1501
b58bdcca
PM
1502#ifdef CONFIG_HOTPLUG_CPU
1503
1504/*
1505 * Execute random CPU-hotplug operations at the interval specified
1506 * by the onoff_interval.
1507 */
44100306 1508static int __cpuinit
b58bdcca
PM
1509rcu_torture_onoff(void *arg)
1510{
1511 int cpu;
13dbf914 1512 unsigned long delta;
b58bdcca
PM
1513 int maxcpu = -1;
1514 DEFINE_RCU_RANDOM(rand);
48983260 1515 int ret;
13dbf914 1516 unsigned long starttime;
b58bdcca
PM
1517
1518 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1519 for_each_online_cpu(cpu)
1520 maxcpu = cpu;
1521 WARN_ON(maxcpu < 0);
9b9ec9b9
PM
1522 if (onoff_holdoff > 0) {
1523 VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff");
1524 schedule_timeout_interruptible(onoff_holdoff * HZ);
1525 VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff");
1526 }
b58bdcca
PM
1527 while (!kthread_should_stop()) {
1528 cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
f220242a 1529 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) {
b58bdcca 1530 if (verbose)
2caa1e44
PM
1531 pr_alert("%s" TORTURE_FLAG
1532 "rcu_torture_onoff task: offlining %d\n",
1533 torture_type, cpu);
13dbf914 1534 starttime = jiffies;
b58bdcca 1535 n_offline_attempts++;
48983260
PM
1536 ret = cpu_down(cpu);
1537 if (ret) {
1538 if (verbose)
1539 pr_alert("%s" TORTURE_FLAG
1540 "rcu_torture_onoff task: offline %d failed: errno %d\n",
1541 torture_type, cpu, ret);
1542 } else {
b58bdcca 1543 if (verbose)
2caa1e44
PM
1544 pr_alert("%s" TORTURE_FLAG
1545 "rcu_torture_onoff task: offlined %d\n",
1546 torture_type, cpu);
b58bdcca 1547 n_offline_successes++;
13dbf914
PM
1548 delta = jiffies - starttime;
1549 sum_offline += delta;
1550 if (min_offline < 0) {
1551 min_offline = delta;
1552 max_offline = delta;
1553 }
1554 if (min_offline > delta)
1555 min_offline = delta;
1556 if (max_offline < delta)
1557 max_offline = delta;
b58bdcca 1558 }
f220242a 1559 } else if (cpu_is_hotpluggable(cpu)) {
b58bdcca 1560 if (verbose)
2caa1e44
PM
1561 pr_alert("%s" TORTURE_FLAG
1562 "rcu_torture_onoff task: onlining %d\n",
1563 torture_type, cpu);
13dbf914 1564 starttime = jiffies;
b58bdcca
PM
1565 n_online_attempts++;
1566 if (cpu_up(cpu) == 0) {
1567 if (verbose)
2caa1e44
PM
1568 pr_alert("%s" TORTURE_FLAG
1569 "rcu_torture_onoff task: onlined %d\n",
1570 torture_type, cpu);
b58bdcca 1571 n_online_successes++;
13dbf914
PM
1572 delta = jiffies - starttime;
1573 sum_online += delta;
1574 if (min_online < 0) {
1575 min_online = delta;
1576 max_online = delta;
1577 }
1578 if (min_online > delta)
1579 min_online = delta;
1580 if (max_online < delta)
1581 max_online = delta;
b58bdcca
PM
1582 }
1583 }
1584 schedule_timeout_interruptible(onoff_interval * HZ);
1585 }
1586 VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1587 return 0;
1588}
1589
44100306 1590static int __cpuinit
b58bdcca
PM
1591rcu_torture_onoff_init(void)
1592{
3c1b1ce0
JL
1593 int ret;
1594
b58bdcca
PM
1595 if (onoff_interval <= 0)
1596 return 0;
1597 onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff");
1598 if (IS_ERR(onoff_task)) {
3c1b1ce0 1599 ret = PTR_ERR(onoff_task);
b58bdcca 1600 onoff_task = NULL;
3c1b1ce0 1601 return ret;
b58bdcca
PM
1602 }
1603 return 0;
1604}
1605
1606static void rcu_torture_onoff_cleanup(void)
1607{
1608 if (onoff_task == NULL)
1609 return;
1610 VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1611 kthread_stop(onoff_task);
37e377d2 1612 onoff_task = NULL;
b58bdcca
PM
1613}
1614
1615#else /* #ifdef CONFIG_HOTPLUG_CPU */
1616
37e377d2 1617static int
b58bdcca
PM
1618rcu_torture_onoff_init(void)
1619{
37e377d2 1620 return 0;
b58bdcca
PM
1621}
1622
1623static void rcu_torture_onoff_cleanup(void)
1624{
1625}
1626
1627#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1628
c13f3757
PM
1629/*
1630 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1631 * induces a CPU stall for the time specified by stall_cpu.
1632 */
1633static int __cpuinit rcu_torture_stall(void *args)
1634{
1635 unsigned long stop_at;
1636
1637 VERBOSE_PRINTK_STRING("rcu_torture_stall task started");
1638 if (stall_cpu_holdoff > 0) {
1639 VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff");
1640 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
1641 VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff");
1642 }
1643 if (!kthread_should_stop()) {
1644 stop_at = get_seconds() + stall_cpu;
1645 /* RCU CPU stall is expected behavior in following code. */
2caa1e44 1646 pr_alert("rcu_torture_stall start.\n");
c13f3757
PM
1647 rcu_read_lock();
1648 preempt_disable();
1649 while (ULONG_CMP_LT(get_seconds(), stop_at))
1650 continue; /* Induce RCU CPU stall warning. */
1651 preempt_enable();
1652 rcu_read_unlock();
2caa1e44 1653 pr_alert("rcu_torture_stall end.\n");
c13f3757
PM
1654 }
1655 rcutorture_shutdown_absorb("rcu_torture_stall");
1656 while (!kthread_should_stop())
1657 schedule_timeout_interruptible(10 * HZ);
1658 return 0;
1659}
1660
1661/* Spawn CPU-stall kthread, if stall_cpu specified. */
1662static int __init rcu_torture_stall_init(void)
1663{
1664 int ret;
1665
1666 if (stall_cpu <= 0)
1667 return 0;
1668 stall_task = kthread_run(rcu_torture_stall, NULL, "rcu_torture_stall");
1669 if (IS_ERR(stall_task)) {
1670 ret = PTR_ERR(stall_task);
1671 stall_task = NULL;
1672 return ret;
1673 }
1674 return 0;
1675}
1676
1677/* Clean up after the CPU-stall kthread, if one was spawned. */
1678static void rcu_torture_stall_cleanup(void)
1679{
1680 if (stall_task == NULL)
1681 return;
1682 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task.");
1683 kthread_stop(stall_task);
37e377d2 1684 stall_task = NULL;
c13f3757
PM
1685}
1686
fae4b54f
PM
1687/* Callback function for RCU barrier testing. */
1688void rcu_torture_barrier_cbf(struct rcu_head *rcu)
1689{
1690 atomic_inc(&barrier_cbs_invoked);
1691}
1692
1693/* kthread function to register callbacks used to test RCU barriers. */
1694static int rcu_torture_barrier_cbs(void *arg)
1695{
1696 long myid = (long)arg;
c6ebcbb6 1697 bool lastphase = 0;
fae4b54f
PM
1698 struct rcu_head rcu;
1699
1700 init_rcu_head_on_stack(&rcu);
1701 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
1702 set_user_nice(current, 19);
1703 do {
1704 wait_event(barrier_cbs_wq[myid],
c6ebcbb6 1705 barrier_phase != lastphase ||
fae4b54f
PM
1706 kthread_should_stop() ||
1707 fullstop != FULLSTOP_DONTSTOP);
c6ebcbb6
PM
1708 lastphase = barrier_phase;
1709 smp_mb(); /* ensure barrier_phase load before ->call(). */
fae4b54f
PM
1710 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1711 break;
1712 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1713 if (atomic_dec_and_test(&barrier_cbs_count))
1714 wake_up(&barrier_wq);
1715 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1716 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task stopping");
1717 rcutorture_shutdown_absorb("rcu_torture_barrier_cbs");
1718 while (!kthread_should_stop())
1719 schedule_timeout_interruptible(1);
1720 cur_ops->cb_barrier();
1721 destroy_rcu_head_on_stack(&rcu);
1722 return 0;
1723}
1724
1725/* kthread function to drive and coordinate RCU barrier testing. */
1726static int rcu_torture_barrier(void *arg)
1727{
1728 int i;
1729
1730 VERBOSE_PRINTK_STRING("rcu_torture_barrier task starting");
1731 do {
1732 atomic_set(&barrier_cbs_invoked, 0);
1733 atomic_set(&barrier_cbs_count, n_barrier_cbs);
c6ebcbb6
PM
1734 smp_mb(); /* Ensure barrier_phase after prior assignments. */
1735 barrier_phase = !barrier_phase;
fae4b54f
PM
1736 for (i = 0; i < n_barrier_cbs; i++)
1737 wake_up(&barrier_cbs_wq[i]);
1738 wait_event(barrier_wq,
1739 atomic_read(&barrier_cbs_count) == 0 ||
1740 kthread_should_stop() ||
1741 fullstop != FULLSTOP_DONTSTOP);
1742 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1743 break;
1744 n_barrier_attempts++;
1745 cur_ops->cb_barrier();
1746 if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
1747 n_rcu_torture_barrier_error++;
1748 WARN_ON_ONCE(1);
1749 }
1750 n_barrier_successes++;
1751 schedule_timeout_interruptible(HZ / 10);
1752 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1753 VERBOSE_PRINTK_STRING("rcu_torture_barrier task stopping");
143aa672 1754 rcutorture_shutdown_absorb("rcu_torture_barrier");
fae4b54f
PM
1755 while (!kthread_should_stop())
1756 schedule_timeout_interruptible(1);
1757 return 0;
1758}
1759
1760/* Initialize RCU barrier testing. */
1761static int rcu_torture_barrier_init(void)
1762{
1763 int i;
1764 int ret;
1765
1766 if (n_barrier_cbs == 0)
1767 return 0;
1768 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
2caa1e44
PM
1769 pr_alert("%s" TORTURE_FLAG
1770 " Call or barrier ops missing for %s,\n",
1771 torture_type, cur_ops->name);
1772 pr_alert("%s" TORTURE_FLAG
1773 " RCU barrier testing omitted from run.\n",
1774 torture_type);
fae4b54f
PM
1775 return 0;
1776 }
1777 atomic_set(&barrier_cbs_count, 0);
1778 atomic_set(&barrier_cbs_invoked, 0);
1779 barrier_cbs_tasks =
1780 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
1781 GFP_KERNEL);
1782 barrier_cbs_wq =
1783 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
1784 GFP_KERNEL);
de5e6437 1785 if (barrier_cbs_tasks == NULL || !barrier_cbs_wq)
fae4b54f
PM
1786 return -ENOMEM;
1787 for (i = 0; i < n_barrier_cbs; i++) {
1788 init_waitqueue_head(&barrier_cbs_wq[i]);
1789 barrier_cbs_tasks[i] = kthread_run(rcu_torture_barrier_cbs,
9059c940 1790 (void *)(long)i,
fae4b54f
PM
1791 "rcu_torture_barrier_cbs");
1792 if (IS_ERR(barrier_cbs_tasks[i])) {
1793 ret = PTR_ERR(barrier_cbs_tasks[i]);
1794 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier_cbs");
1795 barrier_cbs_tasks[i] = NULL;
1796 return ret;
1797 }
1798 }
1799 barrier_task = kthread_run(rcu_torture_barrier, NULL,
1800 "rcu_torture_barrier");
1801 if (IS_ERR(barrier_task)) {
1802 ret = PTR_ERR(barrier_task);
1803 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier");
1804 barrier_task = NULL;
1805 }
1806 return 0;
1807}
1808
1809/* Clean up after RCU barrier testing. */
1810static void rcu_torture_barrier_cleanup(void)
1811{
1812 int i;
1813
1814 if (barrier_task != NULL) {
1815 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier task");
1816 kthread_stop(barrier_task);
1817 barrier_task = NULL;
1818 }
1819 if (barrier_cbs_tasks != NULL) {
1820 for (i = 0; i < n_barrier_cbs; i++) {
1821 if (barrier_cbs_tasks[i] != NULL) {
1822 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier_cbs task");
1823 kthread_stop(barrier_cbs_tasks[i]);
1824 barrier_cbs_tasks[i] = NULL;
1825 }
1826 }
1827 kfree(barrier_cbs_tasks);
1828 barrier_cbs_tasks = NULL;
1829 }
1830 if (barrier_cbs_wq != NULL) {
1831 kfree(barrier_cbs_wq);
1832 barrier_cbs_wq = NULL;
1833 }
1834}
1835
8e8be45e
PM
1836static int rcutorture_cpu_notify(struct notifier_block *self,
1837 unsigned long action, void *hcpu)
1838{
1839 long cpu = (long)hcpu;
1840
1841 switch (action) {
1842 case CPU_ONLINE:
1843 case CPU_DOWN_FAILED:
1844 (void)rcutorture_booster_init(cpu);
1845 break;
1846 case CPU_DOWN_PREPARE:
1847 rcutorture_booster_cleanup(cpu);
1848 break;
1849 default:
1850 break;
1851 }
1852 return NOTIFY_OK;
1853}
1854
1855static struct notifier_block rcutorture_cpu_nb = {
1856 .notifier_call = rcutorture_cpu_notify,
1857};
1858
a241ec65
PM
1859static void
1860rcu_torture_cleanup(void)
1861{
1862 int i;
1863
343e9099 1864 mutex_lock(&fullstop_mutex);
4a298656 1865 rcutorture_record_test_transition();
c9d557c1 1866 if (fullstop == FULLSTOP_SHUTDOWN) {
2caa1e44 1867 pr_warn(/* but going down anyway, so... */
c9d557c1 1868 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
343e9099 1869 mutex_unlock(&fullstop_mutex);
c9d557c1 1870 schedule_timeout_uninterruptible(10);
343e9099
PM
1871 if (cur_ops->cb_barrier != NULL)
1872 cur_ops->cb_barrier();
1873 return;
1874 }
c9d557c1 1875 fullstop = FULLSTOP_RMMOD;
343e9099 1876 mutex_unlock(&fullstop_mutex);
8e8be45e 1877 unregister_reboot_notifier(&rcutorture_shutdown_nb);
fae4b54f 1878 rcu_torture_barrier_cleanup();
c13f3757 1879 rcu_torture_stall_cleanup();
d120f65f
PM
1880 if (stutter_task) {
1881 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1882 kthread_stop(stutter_task);
1883 }
1884 stutter_task = NULL;
c8e5b163 1885 if (shuffler_task) {
d84f5203
SV
1886 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1887 kthread_stop(shuffler_task);
73d0a4b1 1888 free_cpumask_var(shuffle_tmp_mask);
d84f5203
SV
1889 }
1890 shuffler_task = NULL;
1891
c8e5b163 1892 if (writer_task) {
a241ec65
PM
1893 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1894 kthread_stop(writer_task);
1895 }
1896 writer_task = NULL;
1897
c8e5b163 1898 if (reader_tasks) {
a241ec65 1899 for (i = 0; i < nrealreaders; i++) {
c8e5b163 1900 if (reader_tasks[i]) {
a241ec65
PM
1901 VERBOSE_PRINTK_STRING(
1902 "Stopping rcu_torture_reader task");
1903 kthread_stop(reader_tasks[i]);
1904 }
1905 reader_tasks[i] = NULL;
1906 }
1907 kfree(reader_tasks);
1908 reader_tasks = NULL;
1909 }
1910 rcu_torture_current = NULL;
1911
c8e5b163 1912 if (fakewriter_tasks) {
b772e1dd 1913 for (i = 0; i < nfakewriters; i++) {
c8e5b163 1914 if (fakewriter_tasks[i]) {
b772e1dd
JT
1915 VERBOSE_PRINTK_STRING(
1916 "Stopping rcu_torture_fakewriter task");
1917 kthread_stop(fakewriter_tasks[i]);
1918 }
1919 fakewriter_tasks[i] = NULL;
1920 }
1921 kfree(fakewriter_tasks);
1922 fakewriter_tasks = NULL;
1923 }
1924
c8e5b163 1925 if (stats_task) {
a241ec65
PM
1926 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1927 kthread_stop(stats_task);
1928 }
1929 stats_task = NULL;
1930
bf66f18e
PM
1931 if (fqs_task) {
1932 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1933 kthread_stop(fqs_task);
1934 }
1935 fqs_task = NULL;
8e8be45e
PM
1936 if ((test_boost == 1 && cur_ops->can_boost) ||
1937 test_boost == 2) {
1938 unregister_cpu_notifier(&rcutorture_cpu_nb);
1939 for_each_possible_cpu(i)
1940 rcutorture_booster_cleanup(i);
1941 }
d5f546d8
PM
1942 if (shutdown_task != NULL) {
1943 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1944 kthread_stop(shutdown_task);
1945 }
37e377d2 1946 shutdown_task = NULL;
b58bdcca 1947 rcu_torture_onoff_cleanup();
bf66f18e 1948
a241ec65 1949 /* Wait for all RCU callbacks to fire. */
2326974d
PM
1950
1951 if (cur_ops->cb_barrier != NULL)
1952 cur_ops->cb_barrier();
a241ec65 1953
a241ec65 1954 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
72e9bb54 1955
fae4b54f 1956 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
8e8be45e 1957 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
091541bb
PM
1958 else if (n_online_successes != n_online_attempts ||
1959 n_offline_successes != n_offline_attempts)
1960 rcu_torture_print_module_parms(cur_ops,
1961 "End of test: RCU_HOTPLUG");
95c38322 1962 else
8e8be45e 1963 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
a241ec65
PM
1964}
1965
6f8bc500 1966static int __init
a241ec65
PM
1967rcu_torture_init(void)
1968{
1969 int i;
1970 int cpu;
1971 int firsterr = 0;
fae4b54f 1972 int retval;
ade5fb81 1973 static struct rcu_torture_ops *torture_ops[] =
d9a3da06 1974 { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
bdf2a436 1975 &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops,
751a68b2
PM
1976 &srcu_ops, &srcu_sync_ops, &srcu_expedited_ops,
1977 &srcu_raw_ops, &srcu_raw_sync_ops,
804bb837 1978 &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
a241ec65 1979
343e9099
PM
1980 mutex_lock(&fullstop_mutex);
1981
a241ec65 1982 /* Process args and tell the world that the torturer is on the job. */
ade5fb81 1983 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
72e9bb54 1984 cur_ops = torture_ops[i];
ade5fb81 1985 if (strcmp(torture_type, cur_ops->name) == 0)
72e9bb54 1986 break;
72e9bb54 1987 }
ade5fb81 1988 if (i == ARRAY_SIZE(torture_ops)) {
2caa1e44
PM
1989 pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
1990 torture_type);
1991 pr_alert("rcu-torture types:");
cf886c44 1992 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
2caa1e44
PM
1993 pr_alert(" %s", torture_ops[i]->name);
1994 pr_alert("\n");
343e9099 1995 mutex_unlock(&fullstop_mutex);
a71fca58 1996 return -EINVAL;
72e9bb54 1997 }
bf66f18e 1998 if (cur_ops->fqs == NULL && fqs_duration != 0) {
2caa1e44 1999 pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
bf66f18e
PM
2000 fqs_duration = 0;
2001 }
c8e5b163 2002 if (cur_ops->init)
72e9bb54
PM
2003 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
2004
a241ec65
PM
2005 if (nreaders >= 0)
2006 nrealreaders = nreaders;
2007 else
2008 nrealreaders = 2 * num_online_cpus();
8e8be45e 2009 rcu_torture_print_module_parms(cur_ops, "Start of test");
c9d557c1 2010 fullstop = FULLSTOP_DONTSTOP;
a241ec65
PM
2011
2012 /* Set up the freelist. */
2013
2014 INIT_LIST_HEAD(&rcu_torture_freelist);
788e770e 2015 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
996417d2 2016 rcu_tortures[i].rtort_mbtest = 0;
a241ec65
PM
2017 list_add_tail(&rcu_tortures[i].rtort_free,
2018 &rcu_torture_freelist);
2019 }
2020
2021 /* Initialize the statistics so that each run gets its own numbers. */
2022
2023 rcu_torture_current = NULL;
2024 rcu_torture_current_version = 0;
2025 atomic_set(&n_rcu_torture_alloc, 0);
2026 atomic_set(&n_rcu_torture_alloc_fail, 0);
2027 atomic_set(&n_rcu_torture_free, 0);
996417d2
PM
2028 atomic_set(&n_rcu_torture_mberror, 0);
2029 atomic_set(&n_rcu_torture_error, 0);
fae4b54f 2030 n_rcu_torture_barrier_error = 0;
8e8be45e
PM
2031 n_rcu_torture_boost_ktrerror = 0;
2032 n_rcu_torture_boost_rterror = 0;
8e8be45e
PM
2033 n_rcu_torture_boost_failure = 0;
2034 n_rcu_torture_boosts = 0;
a241ec65
PM
2035 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
2036 atomic_set(&rcu_torture_wcount[i], 0);
0a945022 2037 for_each_possible_cpu(cpu) {
a241ec65
PM
2038 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
2039 per_cpu(rcu_torture_count, cpu)[i] = 0;
2040 per_cpu(rcu_torture_batch, cpu)[i] = 0;
2041 }
2042 }
2043
2044 /* Start up the kthreads. */
2045
2046 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
60f53782
PM
2047 writer_task = kthread_create(rcu_torture_writer, NULL,
2048 "rcu_torture_writer");
a241ec65
PM
2049 if (IS_ERR(writer_task)) {
2050 firsterr = PTR_ERR(writer_task);
2051 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
2052 writer_task = NULL;
2053 goto unwind;
2054 }
60f53782 2055 wake_up_process(writer_task);
b772e1dd 2056 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
a71fca58 2057 GFP_KERNEL);
b772e1dd
JT
2058 if (fakewriter_tasks == NULL) {
2059 VERBOSE_PRINTK_ERRSTRING("out of memory");
2060 firsterr = -ENOMEM;
2061 goto unwind;
2062 }
2063 for (i = 0; i < nfakewriters; i++) {
2064 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
2065 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
a71fca58 2066 "rcu_torture_fakewriter");
b772e1dd
JT
2067 if (IS_ERR(fakewriter_tasks[i])) {
2068 firsterr = PTR_ERR(fakewriter_tasks[i]);
2069 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
2070 fakewriter_tasks[i] = NULL;
2071 goto unwind;
2072 }
2073 }
2860aaba 2074 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
a241ec65
PM
2075 GFP_KERNEL);
2076 if (reader_tasks == NULL) {
2077 VERBOSE_PRINTK_ERRSTRING("out of memory");
2078 firsterr = -ENOMEM;
2079 goto unwind;
2080 }
2081 for (i = 0; i < nrealreaders; i++) {
2082 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
2083 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
2084 "rcu_torture_reader");
2085 if (IS_ERR(reader_tasks[i])) {
2086 firsterr = PTR_ERR(reader_tasks[i]);
2087 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
2088 reader_tasks[i] = NULL;
2089 goto unwind;
2090 }
2091 }
2092 if (stat_interval > 0) {
2093 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
2094 stats_task = kthread_run(rcu_torture_stats, NULL,
2095 "rcu_torture_stats");
2096 if (IS_ERR(stats_task)) {
2097 firsterr = PTR_ERR(stats_task);
2098 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
2099 stats_task = NULL;
2100 goto unwind;
2101 }
2102 }
d84f5203
SV
2103 if (test_no_idle_hz) {
2104 rcu_idle_cpu = num_online_cpus() - 1;
73d0a4b1
RR
2105
2106 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
2107 firsterr = -ENOMEM;
2108 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
2109 goto unwind;
2110 }
2111
d84f5203
SV
2112 /* Create the shuffler thread */
2113 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
2114 "rcu_torture_shuffle");
2115 if (IS_ERR(shuffler_task)) {
73d0a4b1 2116 free_cpumask_var(shuffle_tmp_mask);
d84f5203
SV
2117 firsterr = PTR_ERR(shuffler_task);
2118 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
2119 shuffler_task = NULL;
2120 goto unwind;
2121 }
2122 }
d120f65f
PM
2123 if (stutter < 0)
2124 stutter = 0;
2125 if (stutter) {
2126 /* Create the stutter thread */
2127 stutter_task = kthread_run(rcu_torture_stutter, NULL,
2128 "rcu_torture_stutter");
2129 if (IS_ERR(stutter_task)) {
2130 firsterr = PTR_ERR(stutter_task);
2131 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
2132 stutter_task = NULL;
2133 goto unwind;
2134 }
2135 }
bf66f18e
PM
2136 if (fqs_duration < 0)
2137 fqs_duration = 0;
2138 if (fqs_duration) {
2139 /* Create the stutter thread */
2140 fqs_task = kthread_run(rcu_torture_fqs, NULL,
2141 "rcu_torture_fqs");
2142 if (IS_ERR(fqs_task)) {
2143 firsterr = PTR_ERR(fqs_task);
2144 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
2145 fqs_task = NULL;
2146 goto unwind;
2147 }
2148 }
8e8be45e
PM
2149 if (test_boost_interval < 1)
2150 test_boost_interval = 1;
2151 if (test_boost_duration < 2)
2152 test_boost_duration = 2;
2153 if ((test_boost == 1 && cur_ops->can_boost) ||
2154 test_boost == 2) {
8e8be45e
PM
2155
2156 boost_starttime = jiffies + test_boost_interval * HZ;
2157 register_cpu_notifier(&rcutorture_cpu_nb);
2158 for_each_possible_cpu(i) {
2159 if (cpu_is_offline(i))
2160 continue; /* Heuristic: CPU can go offline. */
2161 retval = rcutorture_booster_init(i);
2162 if (retval < 0) {
2163 firsterr = retval;
2164 goto unwind;
2165 }
2166 }
2167 }
d5f546d8
PM
2168 if (shutdown_secs > 0) {
2169 shutdown_time = jiffies + shutdown_secs * HZ;
60f53782
PM
2170 shutdown_task = kthread_create(rcu_torture_shutdown, NULL,
2171 "rcu_torture_shutdown");
d5f546d8
PM
2172 if (IS_ERR(shutdown_task)) {
2173 firsterr = PTR_ERR(shutdown_task);
2174 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
2175 shutdown_task = NULL;
2176 goto unwind;
2177 }
60f53782 2178 wake_up_process(shutdown_task);
d5f546d8 2179 }
37e377d2
PM
2180 i = rcu_torture_onoff_init();
2181 if (i != 0) {
2182 firsterr = i;
2183 goto unwind;
2184 }
8e8be45e 2185 register_reboot_notifier(&rcutorture_shutdown_nb);
37e377d2
PM
2186 i = rcu_torture_stall_init();
2187 if (i != 0) {
2188 firsterr = i;
2189 goto unwind;
2190 }
fae4b54f
PM
2191 retval = rcu_torture_barrier_init();
2192 if (retval != 0) {
2193 firsterr = retval;
2194 goto unwind;
2195 }
4a298656 2196 rcutorture_record_test_transition();
343e9099 2197 mutex_unlock(&fullstop_mutex);
a241ec65
PM
2198 return 0;
2199
2200unwind:
343e9099 2201 mutex_unlock(&fullstop_mutex);
a241ec65
PM
2202 rcu_torture_cleanup();
2203 return firsterr;
2204}
2205
2206module_init(rcu_torture_init);
2207module_exit(rcu_torture_cleanup);
This page took 0.742647 seconds and 5 git commands to generate.