torture: Make config-fragment filtering RCU-independent
[deliverable/linux.git] / kernel / rcu / 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
87de1cfd
PM
15 * along with this program; if not, you can access it online at
16 * http://www.gnu.org/licenses/gpl-2.0.html.
a241ec65 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>
51b1130e 51#include <linux/torture.h>
a241ec65
PM
52
53MODULE_LICENSE("GPL");
5cf05ad7 54MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@freedesktop.org>");
a241ec65 55
4102adab 56
9e250225
PM
57torture_param(int, fqs_duration, 0,
58 "Duration of fqs bursts (us), 0 to disable");
59torture_param(int, fqs_holdoff, 0, "Holdoff time within fqs bursts (us)");
60torture_param(int, fqs_stutter, 3, "Wait time between fqs bursts (s)");
61torture_param(bool, gp_exp, false, "Use expedited GP wait primitives");
62torture_param(bool, gp_normal, false,
63 "Use normal (non-expedited) GP wait primitives");
64torture_param(int, irqreader, 1, "Allow RCU readers from irq handlers");
65torture_param(int, n_barrier_cbs, 0,
66 "# of callbacks/kthreads for barrier testing");
67torture_param(int, nfakewriters, 4, "Number of RCU fake writer threads");
68torture_param(int, nreaders, -1, "Number of RCU reader threads");
69torture_param(int, object_debug, 0,
70 "Enable debug-object double call_rcu() testing");
71torture_param(int, onoff_holdoff, 0, "Time after boot before CPU hotplugs (s)");
72torture_param(int, onoff_interval, 0,
73 "Time between CPU hotplugs (s), 0=disable");
74torture_param(int, shuffle_interval, 3, "Number of seconds between shuffles");
75torture_param(int, shutdown_secs, 0, "Shutdown time (s), <= zero to disable.");
76torture_param(int, stall_cpu, 0, "Stall duration (s), zero to disable.");
77torture_param(int, stall_cpu_holdoff, 10,
78 "Time to wait before starting stall (s).");
79torture_param(int, stat_interval, 60,
80 "Number of seconds between stats printk()s");
81torture_param(int, stutter, 5, "Number of seconds to run/halt test");
82torture_param(int, test_boost, 1, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
83torture_param(int, test_boost_duration, 4,
84 "Duration of each boost test, seconds.");
85torture_param(int, test_boost_interval, 7,
86 "Interval between boost tests, seconds.");
87torture_param(bool, test_no_idle_hz, true,
88 "Test support for tickless idle CPUs");
b5daa8f3
PM
89torture_param(bool, verbose, true,
90 "Enable verbose debugging printk()s");
9e250225 91
d10453e9 92static char *torture_type = "rcu";
d6ad6711 93module_param(torture_type, charp, 0444);
d10453e9 94MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)");
a241ec65 95
a241ec65
PM
96static int nrealreaders;
97static struct task_struct *writer_task;
b772e1dd 98static struct task_struct **fakewriter_tasks;
a241ec65
PM
99static struct task_struct **reader_tasks;
100static struct task_struct *stats_task;
bf66f18e 101static struct task_struct *fqs_task;
8e8be45e 102static struct task_struct *boost_tasks[NR_CPUS];
c13f3757 103static struct task_struct *stall_task;
fae4b54f
PM
104static struct task_struct **barrier_cbs_tasks;
105static struct task_struct *barrier_task;
a241ec65
PM
106
107#define RCU_TORTURE_PIPE_LEN 10
108
109struct rcu_torture {
110 struct rcu_head rtort_rcu;
111 int rtort_pipe_count;
112 struct list_head rtort_free;
996417d2 113 int rtort_mbtest;
a241ec65
PM
114};
115
a241ec65 116static LIST_HEAD(rcu_torture_freelist);
0ddea0ea 117static struct rcu_torture __rcu *rcu_torture_current;
4a298656 118static unsigned long rcu_torture_current_version;
a241ec65
PM
119static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
120static DEFINE_SPINLOCK(rcu_torture_lock);
806274c0
PM
121static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
122 rcu_torture_count) = { 0 };
123static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
124 rcu_torture_batch) = { 0 };
a241ec65 125static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
b2896d2e
PM
126static atomic_t n_rcu_torture_alloc;
127static atomic_t n_rcu_torture_alloc_fail;
128static atomic_t n_rcu_torture_free;
129static atomic_t n_rcu_torture_mberror;
130static atomic_t n_rcu_torture_error;
fae4b54f 131static long n_rcu_torture_barrier_error;
8e8be45e
PM
132static long n_rcu_torture_boost_ktrerror;
133static long n_rcu_torture_boost_rterror;
8e8be45e
PM
134static long n_rcu_torture_boost_failure;
135static long n_rcu_torture_boosts;
a71fca58 136static long n_rcu_torture_timers;
fae4b54f
PM
137static long n_barrier_attempts;
138static long n_barrier_successes;
e3033736 139static struct list_head rcu_torture_removed;
d120f65f 140
ad0dc7f9
PM
141static int rcu_torture_writer_state;
142#define RTWS_FIXED_DELAY 0
143#define RTWS_DELAY 1
144#define RTWS_REPLACE 2
145#define RTWS_DEF_FREE 3
146#define RTWS_EXP_SYNC 4
147#define RTWS_STUTTER 5
148#define RTWS_STOPPING 6
149
31a72bce
PM
150#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
151#define RCUTORTURE_RUNNABLE_INIT 1
152#else
153#define RCUTORTURE_RUNNABLE_INIT 0
154#endif
155int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
bb3bf705
PM
156module_param(rcutorture_runnable, int, 0444);
157MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot");
31a72bce 158
3acf4a9a 159#if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
8e8be45e 160#define rcu_can_boost() 1
3acf4a9a 161#else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
8e8be45e 162#define rcu_can_boost() 0
3acf4a9a 163#endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
8e8be45e 164
e4aa0da3
SR
165#ifdef CONFIG_RCU_TRACE
166static u64 notrace rcu_trace_clock_local(void)
167{
168 u64 ts = trace_clock_local();
169 unsigned long __maybe_unused ts_rem = do_div(ts, NSEC_PER_USEC);
170 return ts;
171}
172#else /* #ifdef CONFIG_RCU_TRACE */
173static u64 notrace rcu_trace_clock_local(void)
174{
175 return 0ULL;
176}
177#endif /* #else #ifdef CONFIG_RCU_TRACE */
178
8e8be45e
PM
179static unsigned long boost_starttime; /* jiffies of next boost test start. */
180DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
181 /* and boost task create/destroy. */
fae4b54f 182static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */
c6ebcbb6 183static bool barrier_phase; /* Test phase. */
fae4b54f
PM
184static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */
185static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */
186static DECLARE_WAIT_QUEUE_HEAD(barrier_wq);
8e8be45e 187
a241ec65
PM
188/*
189 * Allocate an element from the rcu_tortures pool.
190 */
97a41e26 191static struct rcu_torture *
a241ec65
PM
192rcu_torture_alloc(void)
193{
194 struct list_head *p;
195
adac1665 196 spin_lock_bh(&rcu_torture_lock);
a241ec65
PM
197 if (list_empty(&rcu_torture_freelist)) {
198 atomic_inc(&n_rcu_torture_alloc_fail);
adac1665 199 spin_unlock_bh(&rcu_torture_lock);
a241ec65
PM
200 return NULL;
201 }
202 atomic_inc(&n_rcu_torture_alloc);
203 p = rcu_torture_freelist.next;
204 list_del_init(p);
adac1665 205 spin_unlock_bh(&rcu_torture_lock);
a241ec65
PM
206 return container_of(p, struct rcu_torture, rtort_free);
207}
208
209/*
210 * Free an element to the rcu_tortures pool.
211 */
212static void
213rcu_torture_free(struct rcu_torture *p)
214{
215 atomic_inc(&n_rcu_torture_free);
adac1665 216 spin_lock_bh(&rcu_torture_lock);
a241ec65 217 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
adac1665 218 spin_unlock_bh(&rcu_torture_lock);
a241ec65
PM
219}
220
72e9bb54
PM
221/*
222 * Operations vector for selecting different types of tests.
223 */
224
225struct rcu_torture_ops {
ad0dc7f9 226 int ttype;
72e9bb54 227 void (*init)(void);
72e9bb54 228 int (*readlock)(void);
51b1130e 229 void (*read_delay)(struct torture_random_state *rrsp);
72e9bb54
PM
230 void (*readunlock)(int idx);
231 int (*completed)(void);
0acc512c 232 void (*deferred_free)(struct rcu_torture *p);
b772e1dd 233 void (*sync)(void);
2ec1f2d9 234 void (*exp_sync)(void);
fae4b54f 235 void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu));
2326974d 236 void (*cb_barrier)(void);
bf66f18e 237 void (*fqs)(void);
d1008950 238 void (*stats)(char *page);
0acc512c 239 int irq_capable;
8e8be45e 240 int can_boost;
e66c33d5 241 const char *name;
72e9bb54 242};
a71fca58
PM
243
244static struct rcu_torture_ops *cur_ops;
72e9bb54
PM
245
246/*
247 * Definitions for rcu torture testing.
248 */
249
a49a4af7 250static int rcu_torture_read_lock(void) __acquires(RCU)
72e9bb54
PM
251{
252 rcu_read_lock();
253 return 0;
254}
255
51b1130e 256static void rcu_read_delay(struct torture_random_state *rrsp)
b2896d2e 257{
b8d57a76
JT
258 const unsigned long shortdelay_us = 200;
259 const unsigned long longdelay_ms = 50;
b2896d2e 260
b8d57a76
JT
261 /* We want a short delay sometimes to make a reader delay the grace
262 * period, and we want a long delay occasionally to trigger
263 * force_quiescent_state. */
b2896d2e 264
51b1130e 265 if (!(torture_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
b8d57a76 266 mdelay(longdelay_ms);
51b1130e 267 if (!(torture_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
b8d57a76 268 udelay(shortdelay_us);
e546f485 269#ifdef CONFIG_PREEMPT
51b1130e
PM
270 if (!preempt_count() &&
271 !(torture_random(rrsp) % (nrealreaders * 20000)))
e546f485
LJ
272 preempt_schedule(); /* No QS if preempt_disable() in effect */
273#endif
b2896d2e
PM
274}
275
a49a4af7 276static void rcu_torture_read_unlock(int idx) __releases(RCU)
72e9bb54
PM
277{
278 rcu_read_unlock();
279}
280
281static int rcu_torture_completed(void)
282{
283 return rcu_batches_completed();
284}
285
286static void
287rcu_torture_cb(struct rcu_head *p)
288{
289 int i;
290 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
291
36970bb9 292 if (torture_must_stop_irq()) {
72e9bb54
PM
293 /* Test is ending, just drop callbacks on the floor. */
294 /* The next initialization will pick up the pieces. */
295 return;
296 }
297 i = rp->rtort_pipe_count;
298 if (i > RCU_TORTURE_PIPE_LEN)
299 i = RCU_TORTURE_PIPE_LEN;
300 atomic_inc(&rcu_torture_wcount[i]);
301 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
302 rp->rtort_mbtest = 0;
303 rcu_torture_free(rp);
c701d5d9 304 } else {
0acc512c 305 cur_ops->deferred_free(rp);
c701d5d9 306 }
72e9bb54
PM
307}
308
d9a3da06
PM
309static int rcu_no_completed(void)
310{
311 return 0;
312}
313
72e9bb54
PM
314static void rcu_torture_deferred_free(struct rcu_torture *p)
315{
316 call_rcu(&p->rtort_rcu, rcu_torture_cb);
317}
318
e3033736
JT
319static void rcu_sync_torture_init(void)
320{
321 INIT_LIST_HEAD(&rcu_torture_removed);
322}
323
2ec1f2d9 324static struct rcu_torture_ops rcu_ops = {
ad0dc7f9 325 .ttype = RCU_FLAVOR,
0acc512c 326 .init = rcu_sync_torture_init,
0acc512c
PM
327 .readlock = rcu_torture_read_lock,
328 .read_delay = rcu_read_delay,
329 .readunlock = rcu_torture_read_unlock,
330 .completed = rcu_torture_completed,
2ec1f2d9 331 .deferred_free = rcu_torture_deferred_free,
0acc512c 332 .sync = synchronize_rcu,
2ec1f2d9
PM
333 .exp_sync = synchronize_rcu_expedited,
334 .call = call_rcu,
335 .cb_barrier = rcu_barrier,
bf66f18e 336 .fqs = rcu_force_quiescent_state,
d9a3da06
PM
337 .stats = NULL,
338 .irq_capable = 1,
8e8be45e 339 .can_boost = rcu_can_boost(),
2ec1f2d9 340 .name = "rcu"
d9a3da06
PM
341};
342
c32e0660
PM
343/*
344 * Definitions for rcu_bh torture testing.
345 */
346
a49a4af7 347static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
c32e0660
PM
348{
349 rcu_read_lock_bh();
350 return 0;
351}
352
a49a4af7 353static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
c32e0660
PM
354{
355 rcu_read_unlock_bh();
356}
357
358static int rcu_bh_torture_completed(void)
359{
360 return rcu_batches_completed_bh();
361}
362
363static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
364{
365 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
366}
367
368static struct rcu_torture_ops rcu_bh_ops = {
ad0dc7f9 369 .ttype = RCU_BH_FLAVOR,
2ec1f2d9 370 .init = rcu_sync_torture_init,
0acc512c
PM
371 .readlock = rcu_bh_torture_read_lock,
372 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
373 .readunlock = rcu_bh_torture_read_unlock,
374 .completed = rcu_bh_torture_completed,
375 .deferred_free = rcu_bh_torture_deferred_free,
bdf2a436 376 .sync = synchronize_rcu_bh,
2ec1f2d9 377 .exp_sync = synchronize_rcu_bh_expedited,
fae4b54f 378 .call = call_rcu_bh,
0acc512c 379 .cb_barrier = rcu_barrier_bh,
bf66f18e 380 .fqs = rcu_bh_force_quiescent_state,
0acc512c
PM
381 .stats = NULL,
382 .irq_capable = 1,
383 .name = "rcu_bh"
c32e0660
PM
384};
385
ff20e251
PM
386/*
387 * Don't even think about trying any of these in real life!!!
388 * The names includes "busted", and they really means it!
389 * The only purpose of these functions is to provide a buggy RCU
390 * implementation to make sure that rcutorture correctly emits
391 * buggy-RCU error messages.
392 */
393static void rcu_busted_torture_deferred_free(struct rcu_torture *p)
394{
395 /* This is a deliberate bug for testing purposes only! */
396 rcu_torture_cb(&p->rtort_rcu);
397}
398
399static void synchronize_rcu_busted(void)
400{
401 /* This is a deliberate bug for testing purposes only! */
402}
403
404static void
405call_rcu_busted(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
406{
407 /* This is a deliberate bug for testing purposes only! */
408 func(head);
409}
410
411static struct rcu_torture_ops rcu_busted_ops = {
ad0dc7f9 412 .ttype = INVALID_RCU_FLAVOR,
ff20e251
PM
413 .init = rcu_sync_torture_init,
414 .readlock = rcu_torture_read_lock,
415 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
416 .readunlock = rcu_torture_read_unlock,
417 .completed = rcu_no_completed,
418 .deferred_free = rcu_busted_torture_deferred_free,
419 .sync = synchronize_rcu_busted,
420 .exp_sync = synchronize_rcu_busted,
421 .call = call_rcu_busted,
422 .cb_barrier = NULL,
423 .fqs = NULL,
424 .stats = NULL,
425 .irq_capable = 1,
426 .name = "rcu_busted"
427};
428
b2896d2e
PM
429/*
430 * Definitions for srcu torture testing.
431 */
432
cda4dc81 433DEFINE_STATIC_SRCU(srcu_ctl);
b2896d2e 434
012d3ca8 435static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
b2896d2e
PM
436{
437 return srcu_read_lock(&srcu_ctl);
438}
439
51b1130e 440static void srcu_read_delay(struct torture_random_state *rrsp)
b2896d2e
PM
441{
442 long delay;
443 const long uspertick = 1000000 / HZ;
444 const long longdelay = 10;
445
446 /* We want there to be long-running readers, but not all the time. */
447
51b1130e
PM
448 delay = torture_random(rrsp) %
449 (nrealreaders * 2 * longdelay * uspertick);
b2896d2e
PM
450 if (!delay)
451 schedule_timeout_interruptible(longdelay);
e546f485
LJ
452 else
453 rcu_read_delay(rrsp);
b2896d2e
PM
454}
455
012d3ca8 456static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
b2896d2e
PM
457{
458 srcu_read_unlock(&srcu_ctl, idx);
459}
460
461static int srcu_torture_completed(void)
462{
463 return srcu_batches_completed(&srcu_ctl);
464}
465
9059c940
LJ
466static void srcu_torture_deferred_free(struct rcu_torture *rp)
467{
468 call_srcu(&srcu_ctl, &rp->rtort_rcu, rcu_torture_cb);
469}
470
b772e1dd
JT
471static void srcu_torture_synchronize(void)
472{
473 synchronize_srcu(&srcu_ctl);
474}
475
e3f8d378
PM
476static void srcu_torture_call(struct rcu_head *head,
477 void (*func)(struct rcu_head *head))
478{
479 call_srcu(&srcu_ctl, head, func);
480}
481
482static void srcu_torture_barrier(void)
483{
484 srcu_barrier(&srcu_ctl);
485}
486
d1008950 487static void srcu_torture_stats(char *page)
b2896d2e 488{
b2896d2e
PM
489 int cpu;
490 int idx = srcu_ctl.completed & 0x1;
491
d1008950 492 page += sprintf(page, "%s%s per-CPU(idx=%d):",
b2896d2e
PM
493 torture_type, TORTURE_FLAG, idx);
494 for_each_possible_cpu(cpu) {
d1008950 495 page += sprintf(page, " %d(%lu,%lu)", cpu,
b2896d2e
PM
496 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
497 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
498 }
d1008950 499 sprintf(page, "\n");
b2896d2e
PM
500}
501
2ec1f2d9
PM
502static void srcu_torture_synchronize_expedited(void)
503{
504 synchronize_srcu_expedited(&srcu_ctl);
505}
506
b2896d2e 507static struct rcu_torture_ops srcu_ops = {
ad0dc7f9 508 .ttype = SRCU_FLAVOR,
cda4dc81 509 .init = rcu_sync_torture_init,
0acc512c
PM
510 .readlock = srcu_torture_read_lock,
511 .read_delay = srcu_read_delay,
512 .readunlock = srcu_torture_read_unlock,
513 .completed = srcu_torture_completed,
9059c940 514 .deferred_free = srcu_torture_deferred_free,
0acc512c 515 .sync = srcu_torture_synchronize,
2ec1f2d9 516 .exp_sync = srcu_torture_synchronize_expedited,
e3f8d378
PM
517 .call = srcu_torture_call,
518 .cb_barrier = srcu_torture_barrier,
0acc512c
PM
519 .stats = srcu_torture_stats,
520 .name = "srcu"
b2896d2e
PM
521};
522
4b6c2cca
JT
523/*
524 * Definitions for sched torture testing.
525 */
526
527static int sched_torture_read_lock(void)
528{
529 preempt_disable();
530 return 0;
531}
532
533static void sched_torture_read_unlock(int idx)
534{
535 preempt_enable();
536}
537
2326974d
PM
538static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
539{
540 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
541}
542
4b6c2cca 543static struct rcu_torture_ops sched_ops = {
ad0dc7f9 544 .ttype = RCU_SCHED_FLAVOR,
0acc512c 545 .init = rcu_sync_torture_init,
0acc512c
PM
546 .readlock = sched_torture_read_lock,
547 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
548 .readunlock = sched_torture_read_unlock,
d9a3da06 549 .completed = rcu_no_completed,
0acc512c 550 .deferred_free = rcu_sched_torture_deferred_free,
bdf2a436 551 .sync = synchronize_sched,
2ec1f2d9
PM
552 .exp_sync = synchronize_sched_expedited,
553 .call = call_rcu_sched,
0acc512c 554 .cb_barrier = rcu_barrier_sched,
bf66f18e 555 .fqs = rcu_sched_force_quiescent_state,
0acc512c
PM
556 .stats = NULL,
557 .irq_capable = 1,
558 .name = "sched"
4b6c2cca
JT
559};
560
8e8be45e
PM
561/*
562 * RCU torture priority-boost testing. Runs one real-time thread per
563 * CPU for moderate bursts, repeatedly registering RCU callbacks and
564 * spinning waiting for them to be invoked. If a given callback takes
565 * too long to be invoked, we assume that priority inversion has occurred.
566 */
567
568struct rcu_boost_inflight {
569 struct rcu_head rcu;
570 int inflight;
571};
572
573static void rcu_torture_boost_cb(struct rcu_head *head)
574{
575 struct rcu_boost_inflight *rbip =
576 container_of(head, struct rcu_boost_inflight, rcu);
577
578 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
579 rbip->inflight = 0;
580}
581
582static int rcu_torture_boost(void *arg)
583{
584 unsigned long call_rcu_time;
585 unsigned long endtime;
586 unsigned long oldstarttime;
587 struct rcu_boost_inflight rbi = { .inflight = 0 };
588 struct sched_param sp;
589
5ccf60f2 590 VERBOSE_TOROUT_STRING("rcu_torture_boost started");
8e8be45e
PM
591
592 /* Set real-time priority. */
593 sp.sched_priority = 1;
594 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
5ccf60f2 595 VERBOSE_TOROUT_STRING("rcu_torture_boost RT prio failed!");
8e8be45e
PM
596 n_rcu_torture_boost_rterror++;
597 }
598
561190e3 599 init_rcu_head_on_stack(&rbi.rcu);
8e8be45e
PM
600 /* Each pass through the following loop does one boost-test cycle. */
601 do {
602 /* Wait for the next test interval. */
603 oldstarttime = boost_starttime;
93898fb1 604 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
0e11c8e8 605 schedule_timeout_interruptible(oldstarttime - jiffies);
628edaa5 606 stutter_wait("rcu_torture_boost");
36970bb9 607 if (torture_must_stop())
8e8be45e
PM
608 goto checkwait;
609 }
610
611 /* Do one boost-test interval. */
612 endtime = oldstarttime + test_boost_duration * HZ;
613 call_rcu_time = jiffies;
93898fb1 614 while (ULONG_CMP_LT(jiffies, endtime)) {
8e8be45e
PM
615 /* If we don't have a callback in flight, post one. */
616 if (!rbi.inflight) {
617 smp_mb(); /* RCU core before ->inflight = 1. */
618 rbi.inflight = 1;
619 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
620 if (jiffies - call_rcu_time >
621 test_boost_duration * HZ - HZ / 2) {
5ccf60f2 622 VERBOSE_TOROUT_STRING("rcu_torture_boost boosting failed");
8e8be45e
PM
623 n_rcu_torture_boost_failure++;
624 }
625 call_rcu_time = jiffies;
626 }
627 cond_resched();
628edaa5 628 stutter_wait("rcu_torture_boost");
36970bb9 629 if (torture_must_stop())
8e8be45e
PM
630 goto checkwait;
631 }
632
633 /*
634 * Set the start time of the next test interval.
635 * Yes, this is vulnerable to long delays, but such
636 * delays simply cause a false negative for the next
637 * interval. Besides, we are running at RT priority,
638 * so delays should be relatively rare.
639 */
ab8f11e5
PM
640 while (oldstarttime == boost_starttime &&
641 !kthread_should_stop()) {
8e8be45e
PM
642 if (mutex_trylock(&boost_mutex)) {
643 boost_starttime = jiffies +
644 test_boost_interval * HZ;
645 n_rcu_torture_boosts++;
646 mutex_unlock(&boost_mutex);
647 break;
648 }
649 schedule_timeout_uninterruptible(1);
650 }
651
652 /* Go do the stutter. */
628edaa5 653checkwait: stutter_wait("rcu_torture_boost");
36970bb9 654 } while (!torture_must_stop());
8e8be45e
PM
655
656 /* Clean up and exit. */
7fafaac5
PM
657 while (!kthread_should_stop() || rbi.inflight) {
658 torture_shutdown_absorb("rcu_torture_boost");
8e8be45e 659 schedule_timeout_uninterruptible(1);
7fafaac5 660 }
8e8be45e 661 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
9d68197c 662 destroy_rcu_head_on_stack(&rbi.rcu);
7fafaac5 663 torture_kthread_stopping("rcu_torture_boost");
8e8be45e
PM
664 return 0;
665}
666
bf66f18e
PM
667/*
668 * RCU torture force-quiescent-state kthread. Repeatedly induces
669 * bursts of calls to force_quiescent_state(), increasing the probability
670 * of occurrence of some important types of race conditions.
671 */
672static int
673rcu_torture_fqs(void *arg)
674{
675 unsigned long fqs_resume_time;
676 int fqs_burst_remaining;
677
5ccf60f2 678 VERBOSE_TOROUT_STRING("rcu_torture_fqs task started");
bf66f18e
PM
679 do {
680 fqs_resume_time = jiffies + fqs_stutter * HZ;
93898fb1
PM
681 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
682 !kthread_should_stop()) {
bf66f18e
PM
683 schedule_timeout_interruptible(1);
684 }
685 fqs_burst_remaining = fqs_duration;
93898fb1
PM
686 while (fqs_burst_remaining > 0 &&
687 !kthread_should_stop()) {
bf66f18e
PM
688 cur_ops->fqs();
689 udelay(fqs_holdoff);
690 fqs_burst_remaining -= fqs_holdoff;
691 }
628edaa5 692 stutter_wait("rcu_torture_fqs");
36970bb9 693 } while (!torture_must_stop());
7fafaac5 694 torture_kthread_stopping("rcu_torture_fqs");
bf66f18e
PM
695 return 0;
696}
697
a241ec65
PM
698/*
699 * RCU torture writer kthread. Repeatedly substitutes a new structure
700 * for that pointed to by rcu_torture_current, freeing the old structure
701 * after a series of grace periods (the "pipeline").
702 */
703static int
704rcu_torture_writer(void *arg)
705{
2ec1f2d9 706 bool exp;
a241ec65 707 int i;
a241ec65 708 struct rcu_torture *rp;
2ec1f2d9 709 struct rcu_torture *rp1;
a241ec65 710 struct rcu_torture *old_rp;
51b1130e 711 static DEFINE_TORTURE_RANDOM(rand);
a241ec65 712
5ccf60f2 713 VERBOSE_TOROUT_STRING("rcu_torture_writer task started");
d277d868 714 set_user_nice(current, MAX_NICE);
dbdf65b1 715
a241ec65 716 do {
ad0dc7f9 717 rcu_torture_writer_state = RTWS_FIXED_DELAY;
a241ec65 718 schedule_timeout_uninterruptible(1);
a71fca58
PM
719 rp = rcu_torture_alloc();
720 if (rp == NULL)
a241ec65
PM
721 continue;
722 rp->rtort_pipe_count = 0;
ad0dc7f9 723 rcu_torture_writer_state = RTWS_DELAY;
51b1130e 724 udelay(torture_random(&rand) & 0x3ff);
ad0dc7f9 725 rcu_torture_writer_state = RTWS_REPLACE;
0ddea0ea
PM
726 old_rp = rcu_dereference_check(rcu_torture_current,
727 current == writer_task);
996417d2 728 rp->rtort_mbtest = 1;
a241ec65 729 rcu_assign_pointer(rcu_torture_current, rp);
9b2619af 730 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
c8e5b163 731 if (old_rp) {
a241ec65
PM
732 i = old_rp->rtort_pipe_count;
733 if (i > RCU_TORTURE_PIPE_LEN)
734 i = RCU_TORTURE_PIPE_LEN;
735 atomic_inc(&rcu_torture_wcount[i]);
736 old_rp->rtort_pipe_count++;
2ec1f2d9 737 if (gp_normal == gp_exp)
51b1130e 738 exp = !!(torture_random(&rand) & 0x80);
2ec1f2d9
PM
739 else
740 exp = gp_exp;
741 if (!exp) {
ad0dc7f9 742 rcu_torture_writer_state = RTWS_DEF_FREE;
2ec1f2d9
PM
743 cur_ops->deferred_free(old_rp);
744 } else {
ad0dc7f9 745 rcu_torture_writer_state = RTWS_EXP_SYNC;
2ec1f2d9
PM
746 cur_ops->exp_sync();
747 list_add(&old_rp->rtort_free,
748 &rcu_torture_removed);
749 list_for_each_entry_safe(rp, rp1,
750 &rcu_torture_removed,
751 rtort_free) {
752 i = rp->rtort_pipe_count;
753 if (i > RCU_TORTURE_PIPE_LEN)
754 i = RCU_TORTURE_PIPE_LEN;
755 atomic_inc(&rcu_torture_wcount[i]);
756 if (++rp->rtort_pipe_count >=
757 RCU_TORTURE_PIPE_LEN) {
758 rp->rtort_mbtest = 0;
759 list_del(&rp->rtort_free);
760 rcu_torture_free(rp);
761 }
762 }
763 }
a241ec65 764 }
4a298656 765 rcutorture_record_progress(++rcu_torture_current_version);
ad0dc7f9 766 rcu_torture_writer_state = RTWS_STUTTER;
628edaa5 767 stutter_wait("rcu_torture_writer");
36970bb9 768 } while (!torture_must_stop());
ad0dc7f9 769 rcu_torture_writer_state = RTWS_STOPPING;
7fafaac5 770 torture_kthread_stopping("rcu_torture_writer");
a241ec65
PM
771 return 0;
772}
773
b772e1dd
JT
774/*
775 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
776 * delay between calls.
777 */
778static int
779rcu_torture_fakewriter(void *arg)
780{
51b1130e 781 DEFINE_TORTURE_RANDOM(rand);
b772e1dd 782
5ccf60f2 783 VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task started");
d277d868 784 set_user_nice(current, MAX_NICE);
b772e1dd
JT
785
786 do {
51b1130e
PM
787 schedule_timeout_uninterruptible(1 + torture_random(&rand)%10);
788 udelay(torture_random(&rand) & 0x3ff);
72472a02 789 if (cur_ops->cb_barrier != NULL &&
51b1130e 790 torture_random(&rand) % (nfakewriters * 8) == 0) {
72472a02 791 cur_ops->cb_barrier();
2ec1f2d9 792 } else if (gp_normal == gp_exp) {
51b1130e 793 if (torture_random(&rand) & 0x80)
2ec1f2d9
PM
794 cur_ops->sync();
795 else
796 cur_ops->exp_sync();
797 } else if (gp_normal) {
72472a02 798 cur_ops->sync();
2ec1f2d9
PM
799 } else {
800 cur_ops->exp_sync();
801 }
628edaa5 802 stutter_wait("rcu_torture_fakewriter");
36970bb9 803 } while (!torture_must_stop());
b772e1dd 804
7fafaac5 805 torture_kthread_stopping("rcu_torture_fakewriter");
b772e1dd
JT
806 return 0;
807}
808
91afaf30
PM
809void rcutorture_trace_dump(void)
810{
811 static atomic_t beenhere = ATOMIC_INIT(0);
812
813 if (atomic_read(&beenhere))
814 return;
815 if (atomic_xchg(&beenhere, 1) != 0)
816 return;
91afaf30
PM
817 ftrace_dump(DUMP_ALL);
818}
819
0729fbf3
PM
820/*
821 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
822 * incrementing the corresponding element of the pipeline array. The
823 * counter in the element should never be greater than 1, otherwise, the
824 * RCU implementation is broken.
825 */
826static void rcu_torture_timer(unsigned long unused)
827{
828 int idx;
829 int completed;
52494535 830 int completed_end;
51b1130e 831 static DEFINE_TORTURE_RANDOM(rand);
0729fbf3
PM
832 static DEFINE_SPINLOCK(rand_lock);
833 struct rcu_torture *p;
834 int pipe_count;
52494535 835 unsigned long long ts;
0729fbf3
PM
836
837 idx = cur_ops->readlock();
838 completed = cur_ops->completed();
e4aa0da3 839 ts = rcu_trace_clock_local();
632ee200 840 p = rcu_dereference_check(rcu_torture_current,
632ee200
PM
841 rcu_read_lock_bh_held() ||
842 rcu_read_lock_sched_held() ||
843 srcu_read_lock_held(&srcu_ctl));
0729fbf3
PM
844 if (p == NULL) {
845 /* Leave because rcu_torture_writer is not yet underway */
846 cur_ops->readunlock(idx);
847 return;
848 }
849 if (p->rtort_mbtest == 0)
850 atomic_inc(&n_rcu_torture_mberror);
851 spin_lock(&rand_lock);
0acc512c 852 cur_ops->read_delay(&rand);
0729fbf3
PM
853 n_rcu_torture_timers++;
854 spin_unlock(&rand_lock);
855 preempt_disable();
856 pipe_count = p->rtort_pipe_count;
857 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
858 /* Should not happen, but... */
859 pipe_count = RCU_TORTURE_PIPE_LEN;
860 }
52494535
PM
861 completed_end = cur_ops->completed();
862 if (pipe_count > 1) {
52494535
PM
863 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, ts,
864 completed, completed_end);
91afaf30 865 rcutorture_trace_dump();
52494535 866 }
dd17c8f7 867 __this_cpu_inc(rcu_torture_count[pipe_count]);
52494535 868 completed = completed_end - completed;
0729fbf3
PM
869 if (completed > RCU_TORTURE_PIPE_LEN) {
870 /* Should not happen, but... */
871 completed = RCU_TORTURE_PIPE_LEN;
872 }
dd17c8f7 873 __this_cpu_inc(rcu_torture_batch[completed]);
0729fbf3
PM
874 preempt_enable();
875 cur_ops->readunlock(idx);
876}
877
a241ec65
PM
878/*
879 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
880 * incrementing the corresponding element of the pipeline array. The
881 * counter in the element should never be greater than 1, otherwise, the
882 * RCU implementation is broken.
883 */
884static int
885rcu_torture_reader(void *arg)
886{
887 int completed;
52494535 888 int completed_end;
72e9bb54 889 int idx;
51b1130e 890 DEFINE_TORTURE_RANDOM(rand);
a241ec65
PM
891 struct rcu_torture *p;
892 int pipe_count;
0729fbf3 893 struct timer_list t;
52494535 894 unsigned long long ts;
a241ec65 895
5ccf60f2 896 VERBOSE_TOROUT_STRING("rcu_torture_reader task started");
d277d868 897 set_user_nice(current, MAX_NICE);
0acc512c 898 if (irqreader && cur_ops->irq_capable)
0729fbf3 899 setup_timer_on_stack(&t, rcu_torture_timer, 0);
dbdf65b1 900
a241ec65 901 do {
0acc512c 902 if (irqreader && cur_ops->irq_capable) {
0729fbf3 903 if (!timer_pending(&t))
6155fec9 904 mod_timer(&t, jiffies + 1);
0729fbf3 905 }
72e9bb54
PM
906 idx = cur_ops->readlock();
907 completed = cur_ops->completed();
e4aa0da3 908 ts = rcu_trace_clock_local();
632ee200 909 p = rcu_dereference_check(rcu_torture_current,
632ee200
PM
910 rcu_read_lock_bh_held() ||
911 rcu_read_lock_sched_held() ||
912 srcu_read_lock_held(&srcu_ctl));
a241ec65
PM
913 if (p == NULL) {
914 /* Wait for rcu_torture_writer to get underway */
72e9bb54 915 cur_ops->readunlock(idx);
a241ec65
PM
916 schedule_timeout_interruptible(HZ);
917 continue;
918 }
996417d2
PM
919 if (p->rtort_mbtest == 0)
920 atomic_inc(&n_rcu_torture_mberror);
0acc512c 921 cur_ops->read_delay(&rand);
a241ec65
PM
922 preempt_disable();
923 pipe_count = p->rtort_pipe_count;
924 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
925 /* Should not happen, but... */
926 pipe_count = RCU_TORTURE_PIPE_LEN;
927 }
52494535
PM
928 completed_end = cur_ops->completed();
929 if (pipe_count > 1) {
52494535
PM
930 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu,
931 ts, completed, completed_end);
91afaf30 932 rcutorture_trace_dump();
52494535 933 }
dd17c8f7 934 __this_cpu_inc(rcu_torture_count[pipe_count]);
52494535 935 completed = completed_end - completed;
a241ec65
PM
936 if (completed > RCU_TORTURE_PIPE_LEN) {
937 /* Should not happen, but... */
938 completed = RCU_TORTURE_PIPE_LEN;
939 }
dd17c8f7 940 __this_cpu_inc(rcu_torture_batch[completed]);
a241ec65 941 preempt_enable();
72e9bb54 942 cur_ops->readunlock(idx);
a241ec65 943 schedule();
628edaa5 944 stutter_wait("rcu_torture_reader");
36970bb9 945 } while (!torture_must_stop());
0acc512c 946 if (irqreader && cur_ops->irq_capable)
0729fbf3 947 del_timer_sync(&t);
7fafaac5 948 torture_kthread_stopping("rcu_torture_reader");
a241ec65
PM
949 return 0;
950}
951
952/*
953 * Create an RCU-torture statistics message in the specified buffer.
954 */
d1008950 955static void
a241ec65
PM
956rcu_torture_printk(char *page)
957{
a241ec65
PM
958 int cpu;
959 int i;
960 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
961 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
ad0dc7f9 962 static unsigned long rtcv_snap = ULONG_MAX;
a241ec65 963
0a945022 964 for_each_possible_cpu(cpu) {
a241ec65
PM
965 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
966 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
967 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
968 }
969 }
970 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
971 if (pipesummary[i] != 0)
972 break;
973 }
d1008950
CG
974 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
975 page += sprintf(page,
5cf05ad7 976 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
a241ec65
PM
977 rcu_torture_current,
978 rcu_torture_current_version,
979 list_empty(&rcu_torture_freelist),
980 atomic_read(&n_rcu_torture_alloc),
981 atomic_read(&n_rcu_torture_alloc_fail),
5cf05ad7 982 atomic_read(&n_rcu_torture_free));
d1008950 983 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
0729fbf3 984 atomic_read(&n_rcu_torture_mberror),
8e8be45e 985 n_rcu_torture_boost_ktrerror,
5cf05ad7 986 n_rcu_torture_boost_rterror);
d1008950 987 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
8e8be45e
PM
988 n_rcu_torture_boost_failure,
989 n_rcu_torture_boosts,
5cf05ad7 990 n_rcu_torture_timers);
2e9e8081 991 page = torture_onoff_stats(page);
d1008950 992 page += sprintf(page, "barrier: %ld/%ld:%ld",
fae4b54f
PM
993 n_barrier_successes,
994 n_barrier_attempts,
995 n_rcu_torture_barrier_error);
d1008950 996 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
8e8be45e 997 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
fae4b54f 998 n_rcu_torture_barrier_error != 0 ||
8e8be45e
PM
999 n_rcu_torture_boost_ktrerror != 0 ||
1000 n_rcu_torture_boost_rterror != 0 ||
fae4b54f
PM
1001 n_rcu_torture_boost_failure != 0 ||
1002 i > 1) {
d1008950 1003 page += sprintf(page, "!!! ");
996417d2 1004 atomic_inc(&n_rcu_torture_error);
5af970a4 1005 WARN_ON_ONCE(1);
996417d2 1006 }
d1008950 1007 page += sprintf(page, "Reader Pipe: ");
a241ec65 1008 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
d1008950
CG
1009 page += sprintf(page, " %ld", pipesummary[i]);
1010 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
1011 page += sprintf(page, "Reader Batch: ");
72e9bb54 1012 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
d1008950
CG
1013 page += sprintf(page, " %ld", batchsummary[i]);
1014 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
1015 page += sprintf(page, "Free-Block Circulation: ");
a241ec65 1016 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
d1008950 1017 page += sprintf(page, " %d",
a241ec65
PM
1018 atomic_read(&rcu_torture_wcount[i]));
1019 }
d1008950 1020 page += sprintf(page, "\n");
c8e5b163 1021 if (cur_ops->stats)
d1008950 1022 cur_ops->stats(page);
ad0dc7f9
PM
1023 if (rtcv_snap == rcu_torture_current_version &&
1024 rcu_torture_current != NULL) {
1025 int __maybe_unused flags;
1026 unsigned long __maybe_unused gpnum;
1027 unsigned long __maybe_unused completed;
1028
1029 rcutorture_get_gp_data(cur_ops->ttype,
1030 &flags, &gpnum, &completed);
1031 page += sprintf(page,
1032 "??? Writer stall state %d g%lu c%lu f%#x\n",
1033 rcu_torture_writer_state,
1034 gpnum, completed, flags);
1035 }
1036 rtcv_snap = rcu_torture_current_version;
a241ec65
PM
1037}
1038
1039/*
1040 * Print torture statistics. Caller must ensure that there is only
1041 * one call to this function at a given time!!! This is normally
1042 * accomplished by relying on the module system to only have one copy
1043 * of the module loaded, and then by giving the rcu_torture_stats
1044 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1045 * thread is not running).
1046 */
1047static void
1048rcu_torture_stats_print(void)
1049{
d1008950
CG
1050 int size = nr_cpu_ids * 200 + 8192;
1051 char *buf;
a241ec65 1052
d1008950
CG
1053 buf = kmalloc(size, GFP_KERNEL);
1054 if (!buf) {
1055 pr_err("rcu-torture: Out of memory, need: %d", size);
1056 return;
1057 }
1058 rcu_torture_printk(buf);
1059 pr_alert("%s", buf);
1060 kfree(buf);
a241ec65
PM
1061}
1062
1063/*
1064 * Periodically prints torture statistics, if periodic statistics printing
1065 * was specified via the stat_interval module parameter.
a241ec65
PM
1066 */
1067static int
1068rcu_torture_stats(void *arg)
1069{
5ccf60f2 1070 VERBOSE_TOROUT_STRING("rcu_torture_stats task started");
a241ec65
PM
1071 do {
1072 schedule_timeout_interruptible(stat_interval * HZ);
1073 rcu_torture_stats_print();
f67a3356 1074 torture_shutdown_absorb("rcu_torture_stats");
36970bb9 1075 } while (!torture_must_stop());
7fafaac5 1076 torture_kthread_stopping("rcu_torture_stats");
d120f65f
PM
1077 return 0;
1078}
1079
95c38322 1080static inline void
e66c33d5 1081rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag)
95c38322 1082{
2caa1e44
PM
1083 pr_alert("%s" TORTURE_FLAG
1084 "--- %s: nreaders=%d nfakewriters=%d "
1085 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1086 "shuffle_interval=%d stutter=%d irqreader=%d "
1087 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1088 "test_boost=%d/%d test_boost_interval=%d "
1089 "test_boost_duration=%d shutdown_secs=%d "
67afeed2
PM
1090 "stall_cpu=%d stall_cpu_holdoff=%d "
1091 "n_barrier_cbs=%d "
2caa1e44
PM
1092 "onoff_interval=%d onoff_holdoff=%d\n",
1093 torture_type, tag, nrealreaders, nfakewriters,
1094 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
1095 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1096 test_boost, cur_ops->can_boost,
1097 test_boost_interval, test_boost_duration, shutdown_secs,
67afeed2
PM
1098 stall_cpu, stall_cpu_holdoff,
1099 n_barrier_cbs,
2caa1e44 1100 onoff_interval, onoff_holdoff);
95c38322
PM
1101}
1102
8e8be45e
PM
1103static void rcutorture_booster_cleanup(int cpu)
1104{
1105 struct task_struct *t;
1106
1107 if (boost_tasks[cpu] == NULL)
1108 return;
1109 mutex_lock(&boost_mutex);
8e8be45e
PM
1110 t = boost_tasks[cpu];
1111 boost_tasks[cpu] = NULL;
1112 mutex_unlock(&boost_mutex);
1113
1114 /* This must be outside of the mutex, otherwise deadlock! */
9c029b86 1115 torture_stop_kthread(rcu_torture_boost, t);
8e8be45e
PM
1116}
1117
1118static int rcutorture_booster_init(int cpu)
1119{
1120 int retval;
1121
1122 if (boost_tasks[cpu] != NULL)
1123 return 0; /* Already created, nothing more to do. */
1124
1125 /* Don't allow time recalculation while creating a new task. */
1126 mutex_lock(&boost_mutex);
5ccf60f2 1127 VERBOSE_TOROUT_STRING("Creating rcu_torture_boost task");
1f288094
ED
1128 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1129 cpu_to_node(cpu),
1130 "rcu_torture_boost");
8e8be45e
PM
1131 if (IS_ERR(boost_tasks[cpu])) {
1132 retval = PTR_ERR(boost_tasks[cpu]);
5ccf60f2 1133 VERBOSE_TOROUT_STRING("rcu_torture_boost task create failed");
8e8be45e
PM
1134 n_rcu_torture_boost_ktrerror++;
1135 boost_tasks[cpu] = NULL;
1136 mutex_unlock(&boost_mutex);
1137 return retval;
1138 }
1139 kthread_bind(boost_tasks[cpu], cpu);
1140 wake_up_process(boost_tasks[cpu]);
1141 mutex_unlock(&boost_mutex);
1142 return 0;
1143}
1144
c13f3757
PM
1145/*
1146 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1147 * induces a CPU stall for the time specified by stall_cpu.
1148 */
49fb4c62 1149static int rcu_torture_stall(void *args)
c13f3757
PM
1150{
1151 unsigned long stop_at;
1152
5ccf60f2 1153 VERBOSE_TOROUT_STRING("rcu_torture_stall task started");
c13f3757 1154 if (stall_cpu_holdoff > 0) {
5ccf60f2 1155 VERBOSE_TOROUT_STRING("rcu_torture_stall begin holdoff");
c13f3757 1156 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
5ccf60f2 1157 VERBOSE_TOROUT_STRING("rcu_torture_stall end holdoff");
c13f3757
PM
1158 }
1159 if (!kthread_should_stop()) {
1160 stop_at = get_seconds() + stall_cpu;
1161 /* RCU CPU stall is expected behavior in following code. */
2caa1e44 1162 pr_alert("rcu_torture_stall start.\n");
c13f3757
PM
1163 rcu_read_lock();
1164 preempt_disable();
1165 while (ULONG_CMP_LT(get_seconds(), stop_at))
1166 continue; /* Induce RCU CPU stall warning. */
1167 preempt_enable();
1168 rcu_read_unlock();
2caa1e44 1169 pr_alert("rcu_torture_stall end.\n");
c13f3757 1170 }
f67a3356 1171 torture_shutdown_absorb("rcu_torture_stall");
c13f3757
PM
1172 while (!kthread_should_stop())
1173 schedule_timeout_interruptible(10 * HZ);
1174 return 0;
1175}
1176
1177/* Spawn CPU-stall kthread, if stall_cpu specified. */
1178static int __init rcu_torture_stall_init(void)
1179{
c13f3757
PM
1180 if (stall_cpu <= 0)
1181 return 0;
47cf29b9 1182 return torture_create_kthread(rcu_torture_stall, NULL, stall_task);
c13f3757
PM
1183}
1184
fae4b54f
PM
1185/* Callback function for RCU barrier testing. */
1186void rcu_torture_barrier_cbf(struct rcu_head *rcu)
1187{
1188 atomic_inc(&barrier_cbs_invoked);
1189}
1190
1191/* kthread function to register callbacks used to test RCU barriers. */
1192static int rcu_torture_barrier_cbs(void *arg)
1193{
1194 long myid = (long)arg;
c6ebcbb6 1195 bool lastphase = 0;
78e4bc34 1196 bool newphase;
fae4b54f
PM
1197 struct rcu_head rcu;
1198
1199 init_rcu_head_on_stack(&rcu);
5ccf60f2 1200 VERBOSE_TOROUT_STRING("rcu_torture_barrier_cbs task started");
d277d868 1201 set_user_nice(current, MAX_NICE);
fae4b54f
PM
1202 do {
1203 wait_event(barrier_cbs_wq[myid],
78e4bc34
PM
1204 (newphase =
1205 ACCESS_ONCE(barrier_phase)) != lastphase ||
36970bb9 1206 torture_must_stop());
78e4bc34 1207 lastphase = newphase;
c6ebcbb6 1208 smp_mb(); /* ensure barrier_phase load before ->call(). */
36970bb9 1209 if (torture_must_stop())
fae4b54f
PM
1210 break;
1211 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1212 if (atomic_dec_and_test(&barrier_cbs_count))
1213 wake_up(&barrier_wq);
36970bb9 1214 } while (!torture_must_stop());
fae4b54f
PM
1215 cur_ops->cb_barrier();
1216 destroy_rcu_head_on_stack(&rcu);
7fafaac5 1217 torture_kthread_stopping("rcu_torture_barrier_cbs");
fae4b54f
PM
1218 return 0;
1219}
1220
1221/* kthread function to drive and coordinate RCU barrier testing. */
1222static int rcu_torture_barrier(void *arg)
1223{
1224 int i;
1225
5ccf60f2 1226 VERBOSE_TOROUT_STRING("rcu_torture_barrier task starting");
fae4b54f
PM
1227 do {
1228 atomic_set(&barrier_cbs_invoked, 0);
1229 atomic_set(&barrier_cbs_count, n_barrier_cbs);
c6ebcbb6
PM
1230 smp_mb(); /* Ensure barrier_phase after prior assignments. */
1231 barrier_phase = !barrier_phase;
fae4b54f
PM
1232 for (i = 0; i < n_barrier_cbs; i++)
1233 wake_up(&barrier_cbs_wq[i]);
1234 wait_event(barrier_wq,
1235 atomic_read(&barrier_cbs_count) == 0 ||
36970bb9
PM
1236 torture_must_stop());
1237 if (torture_must_stop())
fae4b54f
PM
1238 break;
1239 n_barrier_attempts++;
78e4bc34 1240 cur_ops->cb_barrier(); /* Implies smp_mb() for wait_event(). */
fae4b54f
PM
1241 if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
1242 n_rcu_torture_barrier_error++;
1243 WARN_ON_ONCE(1);
1244 }
1245 n_barrier_successes++;
1246 schedule_timeout_interruptible(HZ / 10);
36970bb9 1247 } while (!torture_must_stop());
7fafaac5 1248 torture_kthread_stopping("rcu_torture_barrier");
fae4b54f
PM
1249 return 0;
1250}
1251
1252/* Initialize RCU barrier testing. */
1253static int rcu_torture_barrier_init(void)
1254{
1255 int i;
1256 int ret;
1257
1258 if (n_barrier_cbs == 0)
1259 return 0;
1260 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
2caa1e44
PM
1261 pr_alert("%s" TORTURE_FLAG
1262 " Call or barrier ops missing for %s,\n",
1263 torture_type, cur_ops->name);
1264 pr_alert("%s" TORTURE_FLAG
1265 " RCU barrier testing omitted from run.\n",
1266 torture_type);
fae4b54f
PM
1267 return 0;
1268 }
1269 atomic_set(&barrier_cbs_count, 0);
1270 atomic_set(&barrier_cbs_invoked, 0);
1271 barrier_cbs_tasks =
1272 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
1273 GFP_KERNEL);
1274 barrier_cbs_wq =
1275 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
1276 GFP_KERNEL);
de5e6437 1277 if (barrier_cbs_tasks == NULL || !barrier_cbs_wq)
fae4b54f
PM
1278 return -ENOMEM;
1279 for (i = 0; i < n_barrier_cbs; i++) {
1280 init_waitqueue_head(&barrier_cbs_wq[i]);
47cf29b9
PM
1281 ret = torture_create_kthread(rcu_torture_barrier_cbs,
1282 (void *)(long)i,
1283 barrier_cbs_tasks[i]);
1284 if (ret)
fae4b54f 1285 return ret;
fae4b54f 1286 }
47cf29b9 1287 return torture_create_kthread(rcu_torture_barrier, NULL, barrier_task);
fae4b54f
PM
1288}
1289
1290/* Clean up after RCU barrier testing. */
1291static void rcu_torture_barrier_cleanup(void)
1292{
1293 int i;
1294
9c029b86 1295 torture_stop_kthread(rcu_torture_barrier, barrier_task);
fae4b54f 1296 if (barrier_cbs_tasks != NULL) {
9c029b86
PM
1297 for (i = 0; i < n_barrier_cbs; i++)
1298 torture_stop_kthread(rcu_torture_barrier_cbs,
1299 barrier_cbs_tasks[i]);
fae4b54f
PM
1300 kfree(barrier_cbs_tasks);
1301 barrier_cbs_tasks = NULL;
1302 }
1303 if (barrier_cbs_wq != NULL) {
1304 kfree(barrier_cbs_wq);
1305 barrier_cbs_wq = NULL;
1306 }
1307}
1308
8e8be45e
PM
1309static int rcutorture_cpu_notify(struct notifier_block *self,
1310 unsigned long action, void *hcpu)
1311{
1312 long cpu = (long)hcpu;
1313
1314 switch (action) {
1315 case CPU_ONLINE:
1316 case CPU_DOWN_FAILED:
1317 (void)rcutorture_booster_init(cpu);
1318 break;
1319 case CPU_DOWN_PREPARE:
1320 rcutorture_booster_cleanup(cpu);
1321 break;
1322 default:
1323 break;
1324 }
1325 return NOTIFY_OK;
1326}
1327
1328static struct notifier_block rcutorture_cpu_nb = {
1329 .notifier_call = rcutorture_cpu_notify,
1330};
1331
a241ec65
PM
1332static void
1333rcu_torture_cleanup(void)
1334{
1335 int i;
1336
4a298656 1337 rcutorture_record_test_transition();
cc47ae08 1338 if (torture_cleanup()) {
343e9099
PM
1339 if (cur_ops->cb_barrier != NULL)
1340 cur_ops->cb_barrier();
1341 return;
1342 }
d84f5203 1343
fae4b54f 1344 rcu_torture_barrier_cleanup();
9c029b86 1345 torture_stop_kthread(rcu_torture_stall, stall_task);
9c029b86 1346 torture_stop_kthread(rcu_torture_writer, writer_task);
a241ec65 1347
c8e5b163 1348 if (reader_tasks) {
9c029b86
PM
1349 for (i = 0; i < nrealreaders; i++)
1350 torture_stop_kthread(rcu_torture_reader,
1351 reader_tasks[i]);
a241ec65 1352 kfree(reader_tasks);
a241ec65
PM
1353 }
1354 rcu_torture_current = NULL;
1355
c8e5b163 1356 if (fakewriter_tasks) {
b772e1dd 1357 for (i = 0; i < nfakewriters; i++) {
9c029b86
PM
1358 torture_stop_kthread(rcu_torture_fakewriter,
1359 fakewriter_tasks[i]);
b772e1dd
JT
1360 }
1361 kfree(fakewriter_tasks);
1362 fakewriter_tasks = NULL;
1363 }
1364
9c029b86
PM
1365 torture_stop_kthread(rcu_torture_stats, stats_task);
1366 torture_stop_kthread(rcu_torture_fqs, fqs_task);
8e8be45e
PM
1367 if ((test_boost == 1 && cur_ops->can_boost) ||
1368 test_boost == 2) {
1369 unregister_cpu_notifier(&rcutorture_cpu_nb);
1370 for_each_possible_cpu(i)
1371 rcutorture_booster_cleanup(i);
1372 }
bf66f18e 1373
a241ec65 1374 /* Wait for all RCU callbacks to fire. */
2326974d
PM
1375
1376 if (cur_ops->cb_barrier != NULL)
1377 cur_ops->cb_barrier();
a241ec65 1378
a241ec65 1379 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
72e9bb54 1380
fae4b54f 1381 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
8e8be45e 1382 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
2e9e8081 1383 else if (torture_onoff_failures())
091541bb
PM
1384 rcu_torture_print_module_parms(cur_ops,
1385 "End of test: RCU_HOTPLUG");
95c38322 1386 else
8e8be45e 1387 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
a241ec65
PM
1388}
1389
d2818df1
PM
1390#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1391static void rcu_torture_leak_cb(struct rcu_head *rhp)
1392{
1393}
1394
1395static void rcu_torture_err_cb(struct rcu_head *rhp)
1396{
1397 /*
1398 * This -might- happen due to race conditions, but is unlikely.
1399 * The scenario that leads to this happening is that the
1400 * first of the pair of duplicate callbacks is queued,
1401 * someone else starts a grace period that includes that
1402 * callback, then the second of the pair must wait for the
1403 * next grace period. Unlikely, but can happen. If it
1404 * does happen, the debug-objects subsystem won't have splatted.
1405 */
1406 pr_alert("rcutorture: duplicated callback was invoked.\n");
1407}
1408#endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1409
1410/*
1411 * Verify that double-free causes debug-objects to complain, but only
1412 * if CONFIG_DEBUG_OBJECTS_RCU_HEAD=y. Otherwise, say that the test
1413 * cannot be carried out.
1414 */
1415static void rcu_test_debug_objects(void)
1416{
1417#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1418 struct rcu_head rh1;
1419 struct rcu_head rh2;
1420
1421 init_rcu_head_on_stack(&rh1);
1422 init_rcu_head_on_stack(&rh2);
1423 pr_alert("rcutorture: WARN: Duplicate call_rcu() test starting.\n");
1424
1425 /* Try to queue the rh2 pair of callbacks for the same grace period. */
1426 preempt_disable(); /* Prevent preemption from interrupting test. */
1427 rcu_read_lock(); /* Make it impossible to finish a grace period. */
1428 call_rcu(&rh1, rcu_torture_leak_cb); /* Start grace period. */
1429 local_irq_disable(); /* Make it harder to start a new grace period. */
1430 call_rcu(&rh2, rcu_torture_leak_cb);
1431 call_rcu(&rh2, rcu_torture_err_cb); /* Duplicate callback. */
1432 local_irq_enable();
1433 rcu_read_unlock();
1434 preempt_enable();
1435
1436 /* Wait for them all to get done so we can safely return. */
1437 rcu_barrier();
1438 pr_alert("rcutorture: WARN: Duplicate call_rcu() test complete.\n");
1439 destroy_rcu_head_on_stack(&rh1);
1440 destroy_rcu_head_on_stack(&rh2);
1441#else /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1442 pr_alert("rcutorture: !CONFIG_DEBUG_OBJECTS_RCU_HEAD, not testing duplicate call_rcu()\n");
1443#endif /* #else #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1444}
1445
6f8bc500 1446static int __init
a241ec65
PM
1447rcu_torture_init(void)
1448{
1449 int i;
1450 int cpu;
1451 int firsterr = 0;
2ec1f2d9 1452 static struct rcu_torture_ops *torture_ops[] = {
ff20e251 1453 &rcu_ops, &rcu_bh_ops, &rcu_busted_ops, &srcu_ops, &sched_ops,
2ec1f2d9 1454 };
a241ec65 1455
628edaa5 1456 torture_init_begin(torture_type, verbose, &rcutorture_runnable);
343e9099 1457
a241ec65 1458 /* Process args and tell the world that the torturer is on the job. */
ade5fb81 1459 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
72e9bb54 1460 cur_ops = torture_ops[i];
ade5fb81 1461 if (strcmp(torture_type, cur_ops->name) == 0)
72e9bb54 1462 break;
72e9bb54 1463 }
ade5fb81 1464 if (i == ARRAY_SIZE(torture_ops)) {
2caa1e44
PM
1465 pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
1466 torture_type);
1467 pr_alert("rcu-torture types:");
cf886c44 1468 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
2caa1e44
PM
1469 pr_alert(" %s", torture_ops[i]->name);
1470 pr_alert("\n");
b5daa8f3 1471 torture_init_end();
a71fca58 1472 return -EINVAL;
72e9bb54 1473 }
bf66f18e 1474 if (cur_ops->fqs == NULL && fqs_duration != 0) {
2caa1e44 1475 pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
bf66f18e
PM
1476 fqs_duration = 0;
1477 }
c8e5b163 1478 if (cur_ops->init)
72e9bb54
PM
1479 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1480
a241ec65
PM
1481 if (nreaders >= 0)
1482 nrealreaders = nreaders;
1483 else
1484 nrealreaders = 2 * num_online_cpus();
8e8be45e 1485 rcu_torture_print_module_parms(cur_ops, "Start of test");
a241ec65
PM
1486
1487 /* Set up the freelist. */
1488
1489 INIT_LIST_HEAD(&rcu_torture_freelist);
788e770e 1490 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
996417d2 1491 rcu_tortures[i].rtort_mbtest = 0;
a241ec65
PM
1492 list_add_tail(&rcu_tortures[i].rtort_free,
1493 &rcu_torture_freelist);
1494 }
1495
1496 /* Initialize the statistics so that each run gets its own numbers. */
1497
1498 rcu_torture_current = NULL;
1499 rcu_torture_current_version = 0;
1500 atomic_set(&n_rcu_torture_alloc, 0);
1501 atomic_set(&n_rcu_torture_alloc_fail, 0);
1502 atomic_set(&n_rcu_torture_free, 0);
996417d2
PM
1503 atomic_set(&n_rcu_torture_mberror, 0);
1504 atomic_set(&n_rcu_torture_error, 0);
fae4b54f 1505 n_rcu_torture_barrier_error = 0;
8e8be45e
PM
1506 n_rcu_torture_boost_ktrerror = 0;
1507 n_rcu_torture_boost_rterror = 0;
8e8be45e
PM
1508 n_rcu_torture_boost_failure = 0;
1509 n_rcu_torture_boosts = 0;
a241ec65
PM
1510 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1511 atomic_set(&rcu_torture_wcount[i], 0);
0a945022 1512 for_each_possible_cpu(cpu) {
a241ec65
PM
1513 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1514 per_cpu(rcu_torture_count, cpu)[i] = 0;
1515 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1516 }
1517 }
1518
1519 /* Start up the kthreads. */
1520
47cf29b9
PM
1521 firsterr = torture_create_kthread(rcu_torture_writer, NULL,
1522 writer_task);
1523 if (firsterr)
a241ec65 1524 goto unwind;
b772e1dd 1525 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
a71fca58 1526 GFP_KERNEL);
b772e1dd 1527 if (fakewriter_tasks == NULL) {
5ccf60f2 1528 VERBOSE_TOROUT_ERRSTRING("out of memory");
b772e1dd
JT
1529 firsterr = -ENOMEM;
1530 goto unwind;
1531 }
1532 for (i = 0; i < nfakewriters; i++) {
47cf29b9
PM
1533 firsterr = torture_create_kthread(rcu_torture_fakewriter,
1534 NULL, fakewriter_tasks[i]);
1535 if (firsterr)
b772e1dd 1536 goto unwind;
b772e1dd 1537 }
2860aaba 1538 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
a241ec65
PM
1539 GFP_KERNEL);
1540 if (reader_tasks == NULL) {
5ccf60f2 1541 VERBOSE_TOROUT_ERRSTRING("out of memory");
a241ec65
PM
1542 firsterr = -ENOMEM;
1543 goto unwind;
1544 }
1545 for (i = 0; i < nrealreaders; i++) {
47cf29b9
PM
1546 firsterr = torture_create_kthread(rcu_torture_reader, NULL,
1547 reader_tasks[i]);
1548 if (firsterr)
a241ec65 1549 goto unwind;
a241ec65
PM
1550 }
1551 if (stat_interval > 0) {
47cf29b9
PM
1552 firsterr = torture_create_kthread(rcu_torture_stats, NULL,
1553 stats_task);
1554 if (firsterr)
a241ec65 1555 goto unwind;
a241ec65 1556 }
d84f5203 1557 if (test_no_idle_hz) {
3808dc9f
PM
1558 firsterr = torture_shuffle_init(shuffle_interval * HZ);
1559 if (firsterr)
d84f5203 1560 goto unwind;
d84f5203 1561 }
d120f65f
PM
1562 if (stutter < 0)
1563 stutter = 0;
1564 if (stutter) {
628edaa5
PM
1565 firsterr = torture_stutter_init(stutter * HZ);
1566 if (firsterr)
d120f65f 1567 goto unwind;
d120f65f 1568 }
bf66f18e
PM
1569 if (fqs_duration < 0)
1570 fqs_duration = 0;
1571 if (fqs_duration) {
628edaa5 1572 /* Create the fqs thread */
47cf29b9
PM
1573 torture_create_kthread(rcu_torture_fqs, NULL, fqs_task);
1574 if (firsterr)
bf66f18e 1575 goto unwind;
bf66f18e 1576 }
8e8be45e
PM
1577 if (test_boost_interval < 1)
1578 test_boost_interval = 1;
1579 if (test_boost_duration < 2)
1580 test_boost_duration = 2;
1581 if ((test_boost == 1 && cur_ops->can_boost) ||
1582 test_boost == 2) {
8e8be45e
PM
1583
1584 boost_starttime = jiffies + test_boost_interval * HZ;
1585 register_cpu_notifier(&rcutorture_cpu_nb);
1586 for_each_possible_cpu(i) {
1587 if (cpu_is_offline(i))
1588 continue; /* Heuristic: CPU can go offline. */
01025ebc
PM
1589 firsterr = rcutorture_booster_init(i);
1590 if (firsterr)
8e8be45e 1591 goto unwind;
8e8be45e
PM
1592 }
1593 }
01025ebc
PM
1594 firsterr = torture_shutdown_init(shutdown_secs, rcu_torture_cleanup);
1595 if (firsterr)
37e377d2 1596 goto unwind;
01025ebc
PM
1597 firsterr = torture_onoff_init(onoff_holdoff * HZ, onoff_interval * HZ);
1598 if (firsterr)
37e377d2 1599 goto unwind;
01025ebc
PM
1600 firsterr = rcu_torture_stall_init();
1601 if (firsterr)
37e377d2 1602 goto unwind;
01025ebc
PM
1603 firsterr = rcu_torture_barrier_init();
1604 if (firsterr)
fae4b54f 1605 goto unwind;
d2818df1
PM
1606 if (object_debug)
1607 rcu_test_debug_objects();
4a298656 1608 rcutorture_record_test_transition();
b5daa8f3 1609 torture_init_end();
a241ec65
PM
1610 return 0;
1611
1612unwind:
b5daa8f3 1613 torture_init_end();
a241ec65
PM
1614 rcu_torture_cleanup();
1615 return firsterr;
1616}
1617
1618module_init(rcu_torture_init);
1619module_exit(rcu_torture_cleanup);
This page took 1.265401 seconds and 5 git commands to generate.