blob: 77192953dee5f5a54b10131ee70684fafb18c2c6 [file] [log] [blame]
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001/*
Paul E. McKenney29766f12006-06-27 02:54:02 -07002 * Read-Copy Update module-based torture test facility
Paul E. McKenneya241ec62005-10-30 15:03:12 -08003 *
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
Paul E. McKenneyf5604f62014-02-26 06:38:59 -080015 * along with this program; if not, you can access it online at
16 * http://www.gnu.org/licenses/gpl-2.0.html.
Paul E. McKenneya241ec62005-10-30 15:03:12 -080017 *
Josh Triplettb772e1d2006-10-04 02:17:13 -070018 * Copyright (C) IBM Corporation, 2005, 2006
Paul E. McKenneya241ec62005-10-30 15:03:12 -080019 *
20 * Authors: Paul E. McKenney <paulmck@us.ibm.com>
Josh Triplette0198b22014-07-30 16:08:42 -070021 * Josh Triplett <josh@joshtriplett.org>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080022 *
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>
Arun Sharma600634972011-07-26 16:09:06 -070036#include <linux/atomic.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080037#include <linux/bitops.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080038#include <linux/completion.h>
39#include <linux/moduleparam.h>
40#include <linux/percpu.h>
41#include <linux/notifier.h>
Paul E. McKenney343e9092008-12-15 16:13:07 -080042#include <linux/reboot.h>
Rafael J. Wysocki83144182007-07-17 04:03:35 -070043#include <linux/freezer.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080044#include <linux/cpu.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080045#include <linux/delay.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080046#include <linux/stat.h>
Paul E. McKenneyb2896d22006-10-04 02:17:03 -070047#include <linux/srcu.h>
Robert P. J. Day1aeb2722008-04-29 00:59:25 -070048#include <linux/slab.h>
Paul E. McKenney52494532012-11-14 16:26:40 -080049#include <linux/trace_clock.h>
Harvey Harrisonf07767f2008-10-20 10:23:38 -070050#include <asm/byteorder.h>
Paul E. McKenney51b11302014-01-27 11:49:39 -080051#include <linux/torture.h>
Paul E. McKenney38706bc2014-08-18 21:12:17 -070052#include <linux/vmalloc.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080053
54MODULE_LICENSE("GPL");
Josh Triplette0198b22014-07-30 16:08:42 -070055MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@joshtriplett.org>");
Paul E. McKenneya241ec62005-10-30 15:03:12 -080056
Paul E. McKenney4102ada2013-10-08 20:23:47 -070057
Paul E. McKenney38706bc2014-08-18 21:12:17 -070058torture_param(int, cbflood_inter_holdoff, HZ,
59 "Holdoff between floods (jiffies)");
60torture_param(int, cbflood_intra_holdoff, 1,
61 "Holdoff between bursts (jiffies)");
62torture_param(int, cbflood_n_burst, 3, "# bursts in flood, zero to disable");
63torture_param(int, cbflood_n_per_burst, 20000,
64 "# callbacks per burst in flood");
Paul E. McKenney9e250222014-01-27 16:27:00 -080065torture_param(int, fqs_duration, 0,
66 "Duration of fqs bursts (us), 0 to disable");
67torture_param(int, fqs_holdoff, 0, "Holdoff time within fqs bursts (us)");
68torture_param(int, fqs_stutter, 3, "Wait time between fqs bursts (s)");
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -070069torture_param(bool, gp_cond, false, "Use conditional/async GP wait primitives");
Paul E. McKenney9e250222014-01-27 16:27:00 -080070torture_param(bool, gp_exp, false, "Use expedited GP wait primitives");
71torture_param(bool, gp_normal, false,
72 "Use normal (non-expedited) GP wait primitives");
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -070073torture_param(bool, gp_sync, false, "Use synchronous GP wait primitives");
Paul E. McKenney9e250222014-01-27 16:27:00 -080074torture_param(int, irqreader, 1, "Allow RCU readers from irq handlers");
75torture_param(int, n_barrier_cbs, 0,
76 "# of callbacks/kthreads for barrier testing");
77torture_param(int, nfakewriters, 4, "Number of RCU fake writer threads");
78torture_param(int, nreaders, -1, "Number of RCU reader threads");
79torture_param(int, object_debug, 0,
80 "Enable debug-object double call_rcu() testing");
81torture_param(int, onoff_holdoff, 0, "Time after boot before CPU hotplugs (s)");
82torture_param(int, onoff_interval, 0,
83 "Time between CPU hotplugs (s), 0=disable");
84torture_param(int, shuffle_interval, 3, "Number of seconds between shuffles");
85torture_param(int, shutdown_secs, 0, "Shutdown time (s), <= zero to disable.");
86torture_param(int, stall_cpu, 0, "Stall duration (s), zero to disable.");
87torture_param(int, stall_cpu_holdoff, 10,
88 "Time to wait before starting stall (s).");
89torture_param(int, stat_interval, 60,
90 "Number of seconds between stats printk()s");
91torture_param(int, stutter, 5, "Number of seconds to run/halt test");
92torture_param(int, test_boost, 1, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
93torture_param(int, test_boost_duration, 4,
94 "Duration of each boost test, seconds.");
95torture_param(int, test_boost_interval, 7,
96 "Interval between boost tests, seconds.");
97torture_param(bool, test_no_idle_hz, true,
98 "Test support for tickless idle CPUs");
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -080099torture_param(bool, verbose, true,
100 "Enable verbose debugging printk()s");
Paul E. McKenney9e250222014-01-27 16:27:00 -0800101
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -0800102static char *torture_type = "rcu";
Josh Triplettd6ad6712007-03-06 01:42:13 -0800103module_param(torture_type, charp, 0444);
Paul E. McKenneyd10453e2013-06-13 15:12:24 -0700104MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700105
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800106static int nrealreaders;
Paul E. McKenney38706bc2014-08-18 21:12:17 -0700107static int ncbflooders;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800108static struct task_struct *writer_task;
Josh Triplettb772e1d2006-10-04 02:17:13 -0700109static struct task_struct **fakewriter_tasks;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800110static struct task_struct **reader_tasks;
111static struct task_struct *stats_task;
Paul E. McKenney38706bc2014-08-18 21:12:17 -0700112static struct task_struct **cbflood_task;
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800113static struct task_struct *fqs_task;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700114static struct task_struct *boost_tasks[NR_CPUS];
Paul E. McKenneyc13f3752012-01-20 15:36:33 -0800115static struct task_struct *stall_task;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800116static struct task_struct **barrier_cbs_tasks;
117static struct task_struct *barrier_task;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800118
119#define RCU_TORTURE_PIPE_LEN 10
120
121struct rcu_torture {
122 struct rcu_head rtort_rcu;
123 int rtort_pipe_count;
124 struct list_head rtort_free;
Paul E. McKenney996417d2005-11-18 01:10:50 -0800125 int rtort_mbtest;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800126};
127
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800128static LIST_HEAD(rcu_torture_freelist);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700129static struct rcu_torture __rcu *rcu_torture_current;
Paul E. McKenney4a298652011-04-03 21:33:51 -0700130static unsigned long rcu_torture_current_version;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800131static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
132static DEFINE_SPINLOCK(rcu_torture_lock);
Paul E. McKenney806274c2014-02-17 13:13:05 -0800133static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
134 rcu_torture_count) = { 0 };
135static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
136 rcu_torture_batch) = { 0 };
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800137static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700138static atomic_t n_rcu_torture_alloc;
139static atomic_t n_rcu_torture_alloc_fail;
140static atomic_t n_rcu_torture_free;
141static atomic_t n_rcu_torture_mberror;
142static atomic_t n_rcu_torture_error;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800143static long n_rcu_torture_barrier_error;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700144static long n_rcu_torture_boost_ktrerror;
145static long n_rcu_torture_boost_rterror;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700146static long n_rcu_torture_boost_failure;
147static long n_rcu_torture_boosts;
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700148static long n_rcu_torture_timers;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800149static long n_barrier_attempts;
150static long n_barrier_successes;
Paul E. McKenney38706bc2014-08-18 21:12:17 -0700151static atomic_long_t n_cbfloods;
Josh Triplette3033732006-10-04 02:17:14 -0700152static struct list_head rcu_torture_removed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800153
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800154static int rcu_torture_writer_state;
155#define RTWS_FIXED_DELAY 0
156#define RTWS_DELAY 1
157#define RTWS_REPLACE 2
158#define RTWS_DEF_FREE 3
159#define RTWS_EXP_SYNC 4
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700160#define RTWS_COND_GET 5
161#define RTWS_COND_SYNC 6
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700162#define RTWS_SYNC 7
163#define RTWS_STUTTER 8
164#define RTWS_STOPPING 9
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800165
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700166#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
167#define RCUTORTURE_RUNNABLE_INIT 1
168#else
169#define RCUTORTURE_RUNNABLE_INIT 0
170#endif
Paul E. McKenney59da22a2014-09-12 10:36:15 -0700171static int torture_runnable = RCUTORTURE_RUNNABLE_INIT;
172module_param(torture_runnable, int, 0444);
173MODULE_PARM_DESC(torture_runnable, "Start rcutorture at boot");
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700174
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700175#if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700176#define rcu_can_boost() 1
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700177#else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700178#define rcu_can_boost() 0
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700179#endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700180
Steven Rostedte4aa0da2013-02-04 13:36:13 -0500181#ifdef CONFIG_RCU_TRACE
182static u64 notrace rcu_trace_clock_local(void)
183{
184 u64 ts = trace_clock_local();
185 unsigned long __maybe_unused ts_rem = do_div(ts, NSEC_PER_USEC);
186 return ts;
187}
188#else /* #ifdef CONFIG_RCU_TRACE */
189static u64 notrace rcu_trace_clock_local(void)
190{
191 return 0ULL;
192}
193#endif /* #else #ifdef CONFIG_RCU_TRACE */
194
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700195static unsigned long boost_starttime; /* jiffies of next boost test start. */
Pranith Kumar58ade2d2014-06-11 16:39:43 -0400196static DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700197 /* and boost task create/destroy. */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800198static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -0700199static bool barrier_phase; /* Test phase. */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800200static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */
201static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */
202static DECLARE_WAIT_QUEUE_HEAD(barrier_wq);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700203
Paul E. McKenney343e9092008-12-15 16:13:07 -0800204/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800205 * Allocate an element from the rcu_tortures pool.
206 */
Adrian Bunk97a41e22006-01-08 01:02:17 -0800207static struct rcu_torture *
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800208rcu_torture_alloc(void)
209{
210 struct list_head *p;
211
Ingo Molnaradac1662006-01-25 19:50:12 +0100212 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800213 if (list_empty(&rcu_torture_freelist)) {
214 atomic_inc(&n_rcu_torture_alloc_fail);
Ingo Molnaradac1662006-01-25 19:50:12 +0100215 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800216 return NULL;
217 }
218 atomic_inc(&n_rcu_torture_alloc);
219 p = rcu_torture_freelist.next;
220 list_del_init(p);
Ingo Molnaradac1662006-01-25 19:50:12 +0100221 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800222 return container_of(p, struct rcu_torture, rtort_free);
223}
224
225/*
226 * Free an element to the rcu_tortures pool.
227 */
228static void
229rcu_torture_free(struct rcu_torture *p)
230{
231 atomic_inc(&n_rcu_torture_free);
Ingo Molnaradac1662006-01-25 19:50:12 +0100232 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800233 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
Ingo Molnaradac1662006-01-25 19:50:12 +0100234 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800235}
236
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800237/*
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700238 * Operations vector for selecting different types of tests.
239 */
240
241struct rcu_torture_ops {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800242 int ttype;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700243 void (*init)(void);
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700244 void (*cleanup)(void);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700245 int (*readlock)(void);
Paul E. McKenney51b11302014-01-27 11:49:39 -0800246 void (*read_delay)(struct torture_random_state *rrsp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700247 void (*readunlock)(int idx);
Paul E. McKenney917963d2014-11-21 17:10:16 -0800248 unsigned long (*started)(void);
Paul E. McKenney6b80da42014-11-21 14:19:26 -0800249 unsigned long (*completed)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700250 void (*deferred_free)(struct rcu_torture *p);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700251 void (*sync)(void);
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700252 void (*exp_sync)(void);
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700253 unsigned long (*get_state)(void);
254 void (*cond_sync)(unsigned long oldstate);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800255 void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu));
Paul E. McKenney23269742008-05-12 21:21:05 +0200256 void (*cb_barrier)(void);
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800257 void (*fqs)(void);
Joe Percheseea203f2014-07-14 09:16:15 -0400258 void (*stats)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700259 int irq_capable;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700260 int can_boost;
Steven Rostedt (Red Hat)e66c33d2013-07-12 16:50:28 -0400261 const char *name;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700262};
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700263
264static struct rcu_torture_ops *cur_ops;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700265
266/*
267 * Definitions for rcu torture testing.
268 */
269
Josh Tripletta49a4af2006-09-29 01:59:30 -0700270static int rcu_torture_read_lock(void) __acquires(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700271{
272 rcu_read_lock();
273 return 0;
274}
275
Paul E. McKenney51b11302014-01-27 11:49:39 -0800276static void rcu_read_delay(struct torture_random_state *rrsp)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700277{
Josh Triplettb8d57a72009-09-08 15:54:35 -0700278 const unsigned long shortdelay_us = 200;
279 const unsigned long longdelay_ms = 50;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700280
Josh Triplettb8d57a72009-09-08 15:54:35 -0700281 /* We want a short delay sometimes to make a reader delay the grace
282 * period, and we want a long delay occasionally to trigger
283 * force_quiescent_state. */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700284
Paul E. McKenney51b11302014-01-27 11:49:39 -0800285 if (!(torture_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
Josh Triplettb8d57a72009-09-08 15:54:35 -0700286 mdelay(longdelay_ms);
Paul E. McKenney51b11302014-01-27 11:49:39 -0800287 if (!(torture_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
Josh Triplettb8d57a72009-09-08 15:54:35 -0700288 udelay(shortdelay_us);
Lai Jiangshane546f482010-06-21 16:57:42 +0800289#ifdef CONFIG_PREEMPT
Paul E. McKenney51b11302014-01-27 11:49:39 -0800290 if (!preempt_count() &&
291 !(torture_random(rrsp) % (nrealreaders * 20000)))
Lai Jiangshane546f482010-06-21 16:57:42 +0800292 preempt_schedule(); /* No QS if preempt_disable() in effect */
293#endif
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700294}
295
Josh Tripletta49a4af2006-09-29 01:59:30 -0700296static void rcu_torture_read_unlock(int idx) __releases(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700297{
298 rcu_read_unlock();
299}
300
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700301/*
302 * Update callback in the pipe. This should be invoked after a grace period.
303 */
304static bool
305rcu_torture_pipe_update_one(struct rcu_torture *rp)
306{
307 int i;
308
309 i = rp->rtort_pipe_count;
310 if (i > RCU_TORTURE_PIPE_LEN)
311 i = RCU_TORTURE_PIPE_LEN;
312 atomic_inc(&rcu_torture_wcount[i]);
313 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
314 rp->rtort_mbtest = 0;
315 return true;
316 }
317 return false;
318}
319
320/*
321 * Update all callbacks in the pipe. Suitable for synchronous grace-period
322 * primitives.
323 */
324static void
325rcu_torture_pipe_update(struct rcu_torture *old_rp)
326{
327 struct rcu_torture *rp;
328 struct rcu_torture *rp1;
329
330 if (old_rp)
331 list_add(&old_rp->rtort_free, &rcu_torture_removed);
332 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
333 if (rcu_torture_pipe_update_one(rp)) {
334 list_del(&rp->rtort_free);
335 rcu_torture_free(rp);
336 }
337 }
338}
339
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700340static void
341rcu_torture_cb(struct rcu_head *p)
342{
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700343 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
344
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800345 if (torture_must_stop_irq()) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700346 /* Test is ending, just drop callbacks on the floor. */
347 /* The next initialization will pick up the pieces. */
348 return;
349 }
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700350 if (rcu_torture_pipe_update_one(rp))
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700351 rcu_torture_free(rp);
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700352 else
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700353 cur_ops->deferred_free(rp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700354}
355
Paul E. McKenney6b80da42014-11-21 14:19:26 -0800356static unsigned long rcu_no_completed(void)
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800357{
358 return 0;
359}
360
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700361static void rcu_torture_deferred_free(struct rcu_torture *p)
362{
363 call_rcu(&p->rtort_rcu, rcu_torture_cb);
364}
365
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700366static void rcu_sync_torture_init(void)
367{
368 INIT_LIST_HEAD(&rcu_torture_removed);
369}
370
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700371static struct rcu_torture_ops rcu_ops = {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800372 .ttype = RCU_FLAVOR,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700373 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700374 .readlock = rcu_torture_read_lock,
375 .read_delay = rcu_read_delay,
376 .readunlock = rcu_torture_read_unlock,
Paul E. McKenney917963d2014-11-21 17:10:16 -0800377 .started = rcu_batches_started,
Paul E. McKenney1e32eae2014-11-21 16:04:34 -0800378 .completed = rcu_batches_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700379 .deferred_free = rcu_torture_deferred_free,
380 .sync = synchronize_rcu,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700381 .exp_sync = synchronize_rcu_expedited,
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700382 .get_state = get_state_synchronize_rcu,
383 .cond_sync = cond_synchronize_rcu,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800384 .call = call_rcu,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700385 .cb_barrier = rcu_barrier,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800386 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700387 .stats = NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700388 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700389 .can_boost = rcu_can_boost(),
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700390 .name = "rcu"
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700391};
392
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700393/*
394 * Definitions for rcu_bh torture testing.
395 */
396
Josh Tripletta49a4af2006-09-29 01:59:30 -0700397static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700398{
399 rcu_read_lock_bh();
400 return 0;
401}
402
Josh Tripletta49a4af2006-09-29 01:59:30 -0700403static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700404{
405 rcu_read_unlock_bh();
406}
407
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700408static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
409{
410 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
411}
412
413static struct rcu_torture_ops rcu_bh_ops = {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800414 .ttype = RCU_BH_FLAVOR,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700415 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700416 .readlock = rcu_bh_torture_read_lock,
417 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
418 .readunlock = rcu_bh_torture_read_unlock,
Paul E. McKenney917963d2014-11-21 17:10:16 -0800419 .started = rcu_batches_started_bh,
Paul E. McKenney1e32eae2014-11-21 16:04:34 -0800420 .completed = rcu_batches_completed_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700421 .deferred_free = rcu_bh_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700422 .sync = synchronize_rcu_bh,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700423 .exp_sync = synchronize_rcu_bh_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800424 .call = call_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700425 .cb_barrier = rcu_barrier_bh,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800426 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700427 .stats = NULL,
428 .irq_capable = 1,
429 .name = "rcu_bh"
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700430};
431
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700432/*
Paul E. McKenneyff20e252014-02-06 08:45:56 -0800433 * Don't even think about trying any of these in real life!!!
434 * The names includes "busted", and they really means it!
435 * The only purpose of these functions is to provide a buggy RCU
436 * implementation to make sure that rcutorture correctly emits
437 * buggy-RCU error messages.
438 */
439static void rcu_busted_torture_deferred_free(struct rcu_torture *p)
440{
441 /* This is a deliberate bug for testing purposes only! */
442 rcu_torture_cb(&p->rtort_rcu);
443}
444
445static void synchronize_rcu_busted(void)
446{
447 /* This is a deliberate bug for testing purposes only! */
448}
449
450static void
451call_rcu_busted(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
452{
453 /* This is a deliberate bug for testing purposes only! */
454 func(head);
455}
456
457static struct rcu_torture_ops rcu_busted_ops = {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800458 .ttype = INVALID_RCU_FLAVOR,
Paul E. McKenneyff20e252014-02-06 08:45:56 -0800459 .init = rcu_sync_torture_init,
460 .readlock = rcu_torture_read_lock,
461 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
462 .readunlock = rcu_torture_read_unlock,
Paul E. McKenney917963d2014-11-21 17:10:16 -0800463 .started = rcu_no_completed,
Paul E. McKenneyff20e252014-02-06 08:45:56 -0800464 .completed = rcu_no_completed,
465 .deferred_free = rcu_busted_torture_deferred_free,
466 .sync = synchronize_rcu_busted,
467 .exp_sync = synchronize_rcu_busted,
468 .call = call_rcu_busted,
469 .cb_barrier = NULL,
470 .fqs = NULL,
471 .stats = NULL,
472 .irq_capable = 1,
473 .name = "rcu_busted"
474};
475
476/*
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700477 * Definitions for srcu torture testing.
478 */
479
Lai Jiangshancda4dc82012-10-13 01:14:17 +0800480DEFINE_STATIC_SRCU(srcu_ctl);
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700481static struct srcu_struct srcu_ctld;
482static struct srcu_struct *srcu_ctlp = &srcu_ctl;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700483
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700484static int srcu_torture_read_lock(void) __acquires(srcu_ctlp)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700485{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700486 return srcu_read_lock(srcu_ctlp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700487}
488
Paul E. McKenney51b11302014-01-27 11:49:39 -0800489static void srcu_read_delay(struct torture_random_state *rrsp)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700490{
491 long delay;
492 const long uspertick = 1000000 / HZ;
493 const long longdelay = 10;
494
495 /* We want there to be long-running readers, but not all the time. */
496
Paul E. McKenney51b11302014-01-27 11:49:39 -0800497 delay = torture_random(rrsp) %
498 (nrealreaders * 2 * longdelay * uspertick);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700499 if (!delay)
500 schedule_timeout_interruptible(longdelay);
Lai Jiangshane546f482010-06-21 16:57:42 +0800501 else
502 rcu_read_delay(rrsp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700503}
504
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700505static void srcu_torture_read_unlock(int idx) __releases(srcu_ctlp)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700506{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700507 srcu_read_unlock(srcu_ctlp, idx);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700508}
509
Paul E. McKenney6b80da42014-11-21 14:19:26 -0800510static unsigned long srcu_torture_completed(void)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700511{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700512 return srcu_batches_completed(srcu_ctlp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700513}
514
Lai Jiangshan9059c942012-03-19 16:12:14 +0800515static void srcu_torture_deferred_free(struct rcu_torture *rp)
516{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700517 call_srcu(srcu_ctlp, &rp->rtort_rcu, rcu_torture_cb);
Lai Jiangshan9059c942012-03-19 16:12:14 +0800518}
519
Josh Triplettb772e1d2006-10-04 02:17:13 -0700520static void srcu_torture_synchronize(void)
521{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700522 synchronize_srcu(srcu_ctlp);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700523}
524
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700525static void srcu_torture_call(struct rcu_head *head,
526 void (*func)(struct rcu_head *head))
527{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700528 call_srcu(srcu_ctlp, head, func);
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700529}
530
531static void srcu_torture_barrier(void)
532{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700533 srcu_barrier(srcu_ctlp);
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700534}
535
Joe Percheseea203f2014-07-14 09:16:15 -0400536static void srcu_torture_stats(void)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700537{
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700538 int cpu;
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700539 int idx = srcu_ctlp->completed & 0x1;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700540
Joe Percheseea203f2014-07-14 09:16:15 -0400541 pr_alert("%s%s per-CPU(idx=%d):",
542 torture_type, TORTURE_FLAG, idx);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700543 for_each_possible_cpu(cpu) {
Paul E. McKenney589a8f52014-03-03 16:51:08 -0800544 long c0, c1;
545
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700546 c0 = (long)per_cpu_ptr(srcu_ctlp->per_cpu_ref, cpu)->c[!idx];
547 c1 = (long)per_cpu_ptr(srcu_ctlp->per_cpu_ref, cpu)->c[idx];
Joe Percheseea203f2014-07-14 09:16:15 -0400548 pr_cont(" %d(%ld,%ld)", cpu, c0, c1);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700549 }
Joe Percheseea203f2014-07-14 09:16:15 -0400550 pr_cont("\n");
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700551}
552
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700553static void srcu_torture_synchronize_expedited(void)
554{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700555 synchronize_srcu_expedited(srcu_ctlp);
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700556}
557
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700558static struct rcu_torture_ops srcu_ops = {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800559 .ttype = SRCU_FLAVOR,
Lai Jiangshancda4dc82012-10-13 01:14:17 +0800560 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700561 .readlock = srcu_torture_read_lock,
562 .read_delay = srcu_read_delay,
563 .readunlock = srcu_torture_read_unlock,
Paul E. McKenney917963d2014-11-21 17:10:16 -0800564 .started = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700565 .completed = srcu_torture_completed,
Lai Jiangshan9059c942012-03-19 16:12:14 +0800566 .deferred_free = srcu_torture_deferred_free,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700567 .sync = srcu_torture_synchronize,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700568 .exp_sync = srcu_torture_synchronize_expedited,
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700569 .call = srcu_torture_call,
570 .cb_barrier = srcu_torture_barrier,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700571 .stats = srcu_torture_stats,
572 .name = "srcu"
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700573};
574
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700575static void srcu_torture_init(void)
576{
577 rcu_sync_torture_init();
578 WARN_ON(init_srcu_struct(&srcu_ctld));
579 srcu_ctlp = &srcu_ctld;
580}
581
582static void srcu_torture_cleanup(void)
583{
584 cleanup_srcu_struct(&srcu_ctld);
585 srcu_ctlp = &srcu_ctl; /* In case of a later rcutorture run. */
586}
587
588/* As above, but dynamically allocated. */
589static struct rcu_torture_ops srcud_ops = {
590 .ttype = SRCU_FLAVOR,
591 .init = srcu_torture_init,
592 .cleanup = srcu_torture_cleanup,
593 .readlock = srcu_torture_read_lock,
594 .read_delay = srcu_read_delay,
595 .readunlock = srcu_torture_read_unlock,
596 .started = NULL,
597 .completed = srcu_torture_completed,
598 .deferred_free = srcu_torture_deferred_free,
599 .sync = srcu_torture_synchronize,
600 .exp_sync = srcu_torture_synchronize_expedited,
601 .call = srcu_torture_call,
602 .cb_barrier = srcu_torture_barrier,
603 .stats = srcu_torture_stats,
604 .name = "srcud"
605};
606
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700607/*
608 * Definitions for sched torture testing.
609 */
610
611static int sched_torture_read_lock(void)
612{
613 preempt_disable();
614 return 0;
615}
616
617static void sched_torture_read_unlock(int idx)
618{
619 preempt_enable();
620}
621
Paul E. McKenney23269742008-05-12 21:21:05 +0200622static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
623{
624 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
625}
626
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700627static struct rcu_torture_ops sched_ops = {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800628 .ttype = RCU_SCHED_FLAVOR,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700629 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700630 .readlock = sched_torture_read_lock,
631 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
632 .readunlock = sched_torture_read_unlock,
Paul E. McKenney917963d2014-11-21 17:10:16 -0800633 .started = rcu_batches_started_sched,
Paul E. McKenney1e32eae2014-11-21 16:04:34 -0800634 .completed = rcu_batches_completed_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700635 .deferred_free = rcu_sched_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700636 .sync = synchronize_sched,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700637 .exp_sync = synchronize_sched_expedited,
Paul E. McKenney24560052015-05-30 10:11:24 -0700638 .get_state = get_state_synchronize_sched,
639 .cond_sync = cond_synchronize_sched,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700640 .call = call_rcu_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700641 .cb_barrier = rcu_barrier_sched,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800642 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700643 .stats = NULL,
644 .irq_capable = 1,
645 .name = "sched"
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700646};
647
Paul E. McKenney69c60452014-07-01 11:59:36 -0700648#ifdef CONFIG_TASKS_RCU
649
650/*
651 * Definitions for RCU-tasks torture testing.
652 */
653
654static int tasks_torture_read_lock(void)
655{
656 return 0;
657}
658
659static void tasks_torture_read_unlock(int idx)
660{
661}
662
663static void rcu_tasks_torture_deferred_free(struct rcu_torture *p)
664{
665 call_rcu_tasks(&p->rtort_rcu, rcu_torture_cb);
666}
667
668static struct rcu_torture_ops tasks_ops = {
669 .ttype = RCU_TASKS_FLAVOR,
670 .init = rcu_sync_torture_init,
671 .readlock = tasks_torture_read_lock,
672 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
673 .readunlock = tasks_torture_read_unlock,
Paul E. McKenney917963d2014-11-21 17:10:16 -0800674 .started = rcu_no_completed,
Paul E. McKenney69c60452014-07-01 11:59:36 -0700675 .completed = rcu_no_completed,
676 .deferred_free = rcu_tasks_torture_deferred_free,
677 .sync = synchronize_rcu_tasks,
678 .exp_sync = synchronize_rcu_tasks,
679 .call = call_rcu_tasks,
680 .cb_barrier = rcu_barrier_tasks,
681 .fqs = NULL,
682 .stats = NULL,
683 .irq_capable = 1,
684 .name = "tasks"
685};
686
687#define RCUTORTURE_TASKS_OPS &tasks_ops,
688
Paul E. McKenney5be5d1a2015-06-30 08:57:57 -0700689static bool __maybe_unused torturing_tasks(void)
690{
691 return cur_ops == &tasks_ops;
692}
693
Paul E. McKenney69c60452014-07-01 11:59:36 -0700694#else /* #ifdef CONFIG_TASKS_RCU */
695
696#define RCUTORTURE_TASKS_OPS
697
Paul E. McKenney5be5d1a2015-06-30 08:57:57 -0700698static bool torturing_tasks(void)
699{
700 return false;
701}
702
Paul E. McKenney69c60452014-07-01 11:59:36 -0700703#endif /* #else #ifdef CONFIG_TASKS_RCU */
704
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700705/*
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700706 * RCU torture priority-boost testing. Runs one real-time thread per
707 * CPU for moderate bursts, repeatedly registering RCU callbacks and
708 * spinning waiting for them to be invoked. If a given callback takes
709 * too long to be invoked, we assume that priority inversion has occurred.
710 */
711
712struct rcu_boost_inflight {
713 struct rcu_head rcu;
714 int inflight;
715};
716
717static void rcu_torture_boost_cb(struct rcu_head *head)
718{
719 struct rcu_boost_inflight *rbip =
720 container_of(head, struct rcu_boost_inflight, rcu);
721
Paul E. McKenney6c7ed422015-04-13 11:58:08 -0700722 /* Ensure RCU-core accesses precede clearing ->inflight */
723 smp_store_release(&rbip->inflight, 0);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700724}
725
726static int rcu_torture_boost(void *arg)
727{
728 unsigned long call_rcu_time;
729 unsigned long endtime;
730 unsigned long oldstarttime;
731 struct rcu_boost_inflight rbi = { .inflight = 0 };
732 struct sched_param sp;
733
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800734 VERBOSE_TOROUT_STRING("rcu_torture_boost started");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700735
736 /* Set real-time priority. */
737 sp.sched_priority = 1;
738 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800739 VERBOSE_TOROUT_STRING("rcu_torture_boost RT prio failed!");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700740 n_rcu_torture_boost_rterror++;
741 }
742
Paul E. McKenney561190e2011-03-30 09:10:44 -0700743 init_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700744 /* Each pass through the following loop does one boost-test cycle. */
745 do {
746 /* Wait for the next test interval. */
747 oldstarttime = boost_starttime;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700748 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
Paul E. McKenney0e11c8e2013-01-10 16:21:07 -0800749 schedule_timeout_interruptible(oldstarttime - jiffies);
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800750 stutter_wait("rcu_torture_boost");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800751 if (torture_must_stop())
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700752 goto checkwait;
753 }
754
755 /* Do one boost-test interval. */
756 endtime = oldstarttime + test_boost_duration * HZ;
757 call_rcu_time = jiffies;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700758 while (ULONG_CMP_LT(jiffies, endtime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700759 /* If we don't have a callback in flight, post one. */
Paul E. McKenney6c7ed422015-04-13 11:58:08 -0700760 if (!smp_load_acquire(&rbi.inflight)) {
761 /* RCU core before ->inflight = 1. */
762 smp_store_release(&rbi.inflight, 1);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700763 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
764 if (jiffies - call_rcu_time >
765 test_boost_duration * HZ - HZ / 2) {
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800766 VERBOSE_TOROUT_STRING("rcu_torture_boost boosting failed");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700767 n_rcu_torture_boost_failure++;
768 }
769 call_rcu_time = jiffies;
770 }
Paul E. McKenneybde6c3a2014-07-01 11:26:57 -0700771 cond_resched_rcu_qs();
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800772 stutter_wait("rcu_torture_boost");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800773 if (torture_must_stop())
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700774 goto checkwait;
775 }
776
777 /*
778 * Set the start time of the next test interval.
779 * Yes, this is vulnerable to long delays, but such
780 * delays simply cause a false negative for the next
781 * interval. Besides, we are running at RT priority,
782 * so delays should be relatively rare.
783 */
Paul E. McKenneyab8f11e2011-08-18 09:30:32 -0700784 while (oldstarttime == boost_starttime &&
785 !kthread_should_stop()) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700786 if (mutex_trylock(&boost_mutex)) {
787 boost_starttime = jiffies +
788 test_boost_interval * HZ;
789 n_rcu_torture_boosts++;
790 mutex_unlock(&boost_mutex);
791 break;
792 }
793 schedule_timeout_uninterruptible(1);
794 }
795
796 /* Go do the stutter. */
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800797checkwait: stutter_wait("rcu_torture_boost");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800798 } while (!torture_must_stop());
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700799
800 /* Clean up and exit. */
Paul E. McKenney6c7ed422015-04-13 11:58:08 -0700801 while (!kthread_should_stop() || smp_load_acquire(&rbi.inflight)) {
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800802 torture_shutdown_absorb("rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700803 schedule_timeout_uninterruptible(1);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800804 }
Paul E. McKenney9d681972011-06-21 01:48:03 -0700805 destroy_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800806 torture_kthread_stopping("rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700807 return 0;
808}
809
Paul E. McKenney38706bc2014-08-18 21:12:17 -0700810static void rcu_torture_cbflood_cb(struct rcu_head *rhp)
811{
812}
813
814/*
815 * RCU torture callback-flood kthread. Repeatedly induces bursts of calls
816 * to call_rcu() or analogous, increasing the probability of occurrence
817 * of callback-overflow corner cases.
818 */
819static int
820rcu_torture_cbflood(void *arg)
821{
822 int err = 1;
823 int i;
824 int j;
825 struct rcu_head *rhp;
826
827 if (cbflood_n_per_burst > 0 &&
828 cbflood_inter_holdoff > 0 &&
829 cbflood_intra_holdoff > 0 &&
830 cur_ops->call &&
831 cur_ops->cb_barrier) {
832 rhp = vmalloc(sizeof(*rhp) *
833 cbflood_n_burst * cbflood_n_per_burst);
834 err = !rhp;
835 }
836 if (err) {
837 VERBOSE_TOROUT_STRING("rcu_torture_cbflood disabled: Bad args or OOM");
Paul E. McKenney3a0af332015-06-22 18:11:31 -0700838 goto wait_for_stop;
Paul E. McKenney38706bc2014-08-18 21:12:17 -0700839 }
840 VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started");
841 do {
842 schedule_timeout_interruptible(cbflood_inter_holdoff);
843 atomic_long_inc(&n_cbfloods);
844 WARN_ON(signal_pending(current));
845 for (i = 0; i < cbflood_n_burst; i++) {
846 for (j = 0; j < cbflood_n_per_burst; j++) {
847 cur_ops->call(&rhp[i * cbflood_n_per_burst + j],
848 rcu_torture_cbflood_cb);
849 }
850 schedule_timeout_interruptible(cbflood_intra_holdoff);
851 WARN_ON(signal_pending(current));
852 }
853 cur_ops->cb_barrier();
854 stutter_wait("rcu_torture_cbflood");
855 } while (!torture_must_stop());
Paul E. McKenneyb8969d12014-10-27 15:52:04 -0700856 vfree(rhp);
Paul E. McKenney3a0af332015-06-22 18:11:31 -0700857wait_for_stop:
Paul E. McKenney38706bc2014-08-18 21:12:17 -0700858 torture_kthread_stopping("rcu_torture_cbflood");
859 return 0;
860}
861
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700862/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800863 * RCU torture force-quiescent-state kthread. Repeatedly induces
864 * bursts of calls to force_quiescent_state(), increasing the probability
865 * of occurrence of some important types of race conditions.
866 */
867static int
868rcu_torture_fqs(void *arg)
869{
870 unsigned long fqs_resume_time;
871 int fqs_burst_remaining;
872
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800873 VERBOSE_TOROUT_STRING("rcu_torture_fqs task started");
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800874 do {
875 fqs_resume_time = jiffies + fqs_stutter * HZ;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700876 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
877 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800878 schedule_timeout_interruptible(1);
879 }
880 fqs_burst_remaining = fqs_duration;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700881 while (fqs_burst_remaining > 0 &&
882 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800883 cur_ops->fqs();
884 udelay(fqs_holdoff);
885 fqs_burst_remaining -= fqs_holdoff;
886 }
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800887 stutter_wait("rcu_torture_fqs");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800888 } while (!torture_must_stop());
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800889 torture_kthread_stopping("rcu_torture_fqs");
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800890 return 0;
891}
892
893/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800894 * RCU torture writer kthread. Repeatedly substitutes a new structure
895 * for that pointed to by rcu_torture_current, freeing the old structure
896 * after a series of grace periods (the "pipeline").
897 */
898static int
899rcu_torture_writer(void *arg)
900{
Paul E. McKenney4bb3c5f2015-02-18 16:31:29 -0800901 bool can_expedite = !rcu_gp_is_expedited();
902 int expediting = 0;
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700903 unsigned long gp_snap;
904 bool gp_cond1 = gp_cond, gp_exp1 = gp_exp, gp_normal1 = gp_normal;
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700905 bool gp_sync1 = gp_sync;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800906 int i;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800907 struct rcu_torture *rp;
908 struct rcu_torture *old_rp;
Paul E. McKenney51b11302014-01-27 11:49:39 -0800909 static DEFINE_TORTURE_RANDOM(rand);
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700910 int synctype[] = { RTWS_DEF_FREE, RTWS_EXP_SYNC,
911 RTWS_COND_GET, RTWS_SYNC };
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700912 int nsynctypes = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800913
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800914 VERBOSE_TOROUT_STRING("rcu_torture_writer task started");
Paul E. McKenney4bb3c5f2015-02-18 16:31:29 -0800915 pr_alert("%s" TORTURE_FLAG
916 " Grace periods expedited from boot/sysfs for %s,\n",
917 torture_type, cur_ops->name);
918 pr_alert("%s" TORTURE_FLAG
919 " Testing of dynamic grace-period expediting diabled.\n",
920 torture_type);
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800921
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700922 /* Initialize synctype[] array. If none set, take default. */
Paul E. McKenneyc136f992015-02-19 12:15:19 -0800923 if (!gp_cond1 && !gp_exp1 && !gp_normal1 && !gp_sync1)
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700924 gp_cond1 = gp_exp1 = gp_normal1 = gp_sync1 = true;
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700925 if (gp_cond1 && cur_ops->get_state && cur_ops->cond_sync)
926 synctype[nsynctypes++] = RTWS_COND_GET;
927 else if (gp_cond && (!cur_ops->get_state || !cur_ops->cond_sync))
928 pr_alert("rcu_torture_writer: gp_cond without primitives.\n");
929 if (gp_exp1 && cur_ops->exp_sync)
930 synctype[nsynctypes++] = RTWS_EXP_SYNC;
931 else if (gp_exp && !cur_ops->exp_sync)
932 pr_alert("rcu_torture_writer: gp_exp without primitives.\n");
933 if (gp_normal1 && cur_ops->deferred_free)
934 synctype[nsynctypes++] = RTWS_DEF_FREE;
935 else if (gp_normal && !cur_ops->deferred_free)
936 pr_alert("rcu_torture_writer: gp_normal without primitives.\n");
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700937 if (gp_sync1 && cur_ops->sync)
938 synctype[nsynctypes++] = RTWS_SYNC;
939 else if (gp_sync && !cur_ops->sync)
940 pr_alert("rcu_torture_writer: gp_sync without primitives.\n");
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700941 if (WARN_ONCE(nsynctypes == 0,
942 "rcu_torture_writer: No update-side primitives.\n")) {
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700943 /*
944 * No updates primitives, so don't try updating.
945 * The resulting test won't be testing much, hence the
946 * above WARN_ONCE().
947 */
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700948 rcu_torture_writer_state = RTWS_STOPPING;
949 torture_kthread_stopping("rcu_torture_writer");
950 }
951
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800952 do {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800953 rcu_torture_writer_state = RTWS_FIXED_DELAY;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800954 schedule_timeout_uninterruptible(1);
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700955 rp = rcu_torture_alloc();
956 if (rp == NULL)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800957 continue;
958 rp->rtort_pipe_count = 0;
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800959 rcu_torture_writer_state = RTWS_DELAY;
Paul E. McKenney51b11302014-01-27 11:49:39 -0800960 udelay(torture_random(&rand) & 0x3ff);
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800961 rcu_torture_writer_state = RTWS_REPLACE;
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700962 old_rp = rcu_dereference_check(rcu_torture_current,
963 current == writer_task);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800964 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800965 rcu_assign_pointer(rcu_torture_current, rp);
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700966 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
Josh Triplettc8e5b162007-05-08 00:33:20 -0700967 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800968 i = old_rp->rtort_pipe_count;
969 if (i > RCU_TORTURE_PIPE_LEN)
970 i = RCU_TORTURE_PIPE_LEN;
971 atomic_inc(&rcu_torture_wcount[i]);
972 old_rp->rtort_pipe_count++;
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700973 switch (synctype[torture_random(&rand) % nsynctypes]) {
974 case RTWS_DEF_FREE:
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800975 rcu_torture_writer_state = RTWS_DEF_FREE;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700976 cur_ops->deferred_free(old_rp);
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700977 break;
978 case RTWS_EXP_SYNC:
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800979 rcu_torture_writer_state = RTWS_EXP_SYNC;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700980 cur_ops->exp_sync();
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700981 rcu_torture_pipe_update(old_rp);
982 break;
983 case RTWS_COND_GET:
984 rcu_torture_writer_state = RTWS_COND_GET;
985 gp_snap = cur_ops->get_state();
986 i = torture_random(&rand) % 16;
987 if (i != 0)
988 schedule_timeout_interruptible(i);
989 udelay(torture_random(&rand) % 1000);
990 rcu_torture_writer_state = RTWS_COND_SYNC;
991 cur_ops->cond_sync(gp_snap);
992 rcu_torture_pipe_update(old_rp);
993 break;
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700994 case RTWS_SYNC:
995 rcu_torture_writer_state = RTWS_SYNC;
996 cur_ops->sync();
997 rcu_torture_pipe_update(old_rp);
998 break;
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700999 default:
1000 WARN_ON_ONCE(1);
1001 break;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001002 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001003 }
Paul E. McKenney4a298652011-04-03 21:33:51 -07001004 rcutorture_record_progress(++rcu_torture_current_version);
Paul E. McKenney4bb3c5f2015-02-18 16:31:29 -08001005 /* Cycle through nesting levels of rcu_expedite_gp() calls. */
1006 if (can_expedite &&
1007 !(torture_random(&rand) & 0xff & (!!expediting - 1))) {
1008 WARN_ON_ONCE(expediting == 0 && rcu_gp_is_expedited());
1009 if (expediting >= 0)
1010 rcu_expedite_gp();
1011 else
1012 rcu_unexpedite_gp();
1013 if (++expediting > 3)
1014 expediting = -expediting;
1015 }
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001016 rcu_torture_writer_state = RTWS_STUTTER;
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001017 stutter_wait("rcu_torture_writer");
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001018 } while (!torture_must_stop());
Paul E. McKenney4bb3c5f2015-02-18 16:31:29 -08001019 /* Reset expediting back to unexpedited. */
1020 if (expediting > 0)
1021 expediting = -expediting;
1022 while (can_expedite && expediting++ < 0)
1023 rcu_unexpedite_gp();
1024 WARN_ON_ONCE(can_expedite && rcu_gp_is_expedited());
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001025 rcu_torture_writer_state = RTWS_STOPPING;
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001026 torture_kthread_stopping("rcu_torture_writer");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001027 return 0;
1028}
1029
1030/*
Josh Triplettb772e1d2006-10-04 02:17:13 -07001031 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
1032 * delay between calls.
1033 */
1034static int
1035rcu_torture_fakewriter(void *arg)
1036{
Paul E. McKenney51b11302014-01-27 11:49:39 -08001037 DEFINE_TORTURE_RANDOM(rand);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001038
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001039 VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task started");
Linus Torvalds971eae72014-03-31 11:21:19 -07001040 set_user_nice(current, MAX_NICE);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001041
1042 do {
Paul E. McKenney51b11302014-01-27 11:49:39 -08001043 schedule_timeout_uninterruptible(1 + torture_random(&rand)%10);
1044 udelay(torture_random(&rand) & 0x3ff);
Paul E. McKenney72472a02012-05-29 17:50:51 -07001045 if (cur_ops->cb_barrier != NULL &&
Paul E. McKenney51b11302014-01-27 11:49:39 -08001046 torture_random(&rand) % (nfakewriters * 8) == 0) {
Paul E. McKenney72472a02012-05-29 17:50:51 -07001047 cur_ops->cb_barrier();
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001048 } else if (gp_normal == gp_exp) {
Paul E. McKenney51b11302014-01-27 11:49:39 -08001049 if (torture_random(&rand) & 0x80)
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001050 cur_ops->sync();
1051 else
1052 cur_ops->exp_sync();
1053 } else if (gp_normal) {
Paul E. McKenney72472a02012-05-29 17:50:51 -07001054 cur_ops->sync();
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001055 } else {
1056 cur_ops->exp_sync();
1057 }
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001058 stutter_wait("rcu_torture_fakewriter");
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001059 } while (!torture_must_stop());
Josh Triplettb772e1d2006-10-04 02:17:13 -07001060
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001061 torture_kthread_stopping("rcu_torture_fakewriter");
Josh Triplettb772e1d2006-10-04 02:17:13 -07001062 return 0;
1063}
1064
Rashika Kheriab3b8a4d2014-02-27 17:16:57 +05301065static void rcutorture_trace_dump(void)
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001066{
1067 static atomic_t beenhere = ATOMIC_INIT(0);
1068
1069 if (atomic_read(&beenhere))
1070 return;
1071 if (atomic_xchg(&beenhere, 1) != 0)
1072 return;
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001073 ftrace_dump(DUMP_ALL);
1074}
1075
Josh Triplettb772e1d2006-10-04 02:17:13 -07001076/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001077 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
1078 * incrementing the corresponding element of the pipeline array. The
1079 * counter in the element should never be greater than 1, otherwise, the
1080 * RCU implementation is broken.
1081 */
1082static void rcu_torture_timer(unsigned long unused)
1083{
1084 int idx;
Paul E. McKenney917963d2014-11-21 17:10:16 -08001085 unsigned long started;
Paul E. McKenney6b80da42014-11-21 14:19:26 -08001086 unsigned long completed;
Paul E. McKenney51b11302014-01-27 11:49:39 -08001087 static DEFINE_TORTURE_RANDOM(rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001088 static DEFINE_SPINLOCK(rand_lock);
1089 struct rcu_torture *p;
1090 int pipe_count;
Paul E. McKenney52494532012-11-14 16:26:40 -08001091 unsigned long long ts;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001092
1093 idx = cur_ops->readlock();
Paul E. McKenney917963d2014-11-21 17:10:16 -08001094 if (cur_ops->started)
1095 started = cur_ops->started();
1096 else
1097 started = cur_ops->completed();
Steven Rostedte4aa0da2013-02-04 13:36:13 -05001098 ts = rcu_trace_clock_local();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001099 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001100 rcu_read_lock_bh_held() ||
1101 rcu_read_lock_sched_held() ||
Paul E. McKenney5be5d1a2015-06-30 08:57:57 -07001102 srcu_read_lock_held(srcu_ctlp) ||
1103 torturing_tasks());
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001104 if (p == NULL) {
1105 /* Leave because rcu_torture_writer is not yet underway */
1106 cur_ops->readunlock(idx);
1107 return;
1108 }
1109 if (p->rtort_mbtest == 0)
1110 atomic_inc(&n_rcu_torture_mberror);
1111 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001112 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001113 n_rcu_torture_timers++;
1114 spin_unlock(&rand_lock);
1115 preempt_disable();
1116 pipe_count = p->rtort_pipe_count;
1117 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1118 /* Should not happen, but... */
1119 pipe_count = RCU_TORTURE_PIPE_LEN;
1120 }
Paul E. McKenney917963d2014-11-21 17:10:16 -08001121 completed = cur_ops->completed();
Paul E. McKenney52494532012-11-14 16:26:40 -08001122 if (pipe_count > 1) {
Paul E. McKenney52494532012-11-14 16:26:40 -08001123 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, ts,
Paul E. McKenney917963d2014-11-21 17:10:16 -08001124 started, completed);
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001125 rcutorture_trace_dump();
Paul E. McKenney52494532012-11-14 16:26:40 -08001126 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001127 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney917963d2014-11-21 17:10:16 -08001128 completed = completed - started;
1129 if (cur_ops->started)
1130 completed++;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001131 if (completed > RCU_TORTURE_PIPE_LEN) {
1132 /* Should not happen, but... */
1133 completed = RCU_TORTURE_PIPE_LEN;
1134 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001135 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001136 preempt_enable();
1137 cur_ops->readunlock(idx);
1138}
1139
1140/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001141 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
1142 * incrementing the corresponding element of the pipeline array. The
1143 * counter in the element should never be greater than 1, otherwise, the
1144 * RCU implementation is broken.
1145 */
1146static int
1147rcu_torture_reader(void *arg)
1148{
Paul E. McKenney917963d2014-11-21 17:10:16 -08001149 unsigned long started;
Paul E. McKenney6b80da42014-11-21 14:19:26 -08001150 unsigned long completed;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001151 int idx;
Paul E. McKenney51b11302014-01-27 11:49:39 -08001152 DEFINE_TORTURE_RANDOM(rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001153 struct rcu_torture *p;
1154 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001155 struct timer_list t;
Paul E. McKenney52494532012-11-14 16:26:40 -08001156 unsigned long long ts;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001157
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001158 VERBOSE_TOROUT_STRING("rcu_torture_reader task started");
Linus Torvalds971eae72014-03-31 11:21:19 -07001159 set_user_nice(current, MAX_NICE);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001160 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001161 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001162
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001163 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001164 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001165 if (!timer_pending(&t))
Paul E. McKenney6155fec2010-02-22 17:05:04 -08001166 mod_timer(&t, jiffies + 1);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001167 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001168 idx = cur_ops->readlock();
Paul E. McKenney917963d2014-11-21 17:10:16 -08001169 if (cur_ops->started)
1170 started = cur_ops->started();
1171 else
1172 started = cur_ops->completed();
Steven Rostedte4aa0da2013-02-04 13:36:13 -05001173 ts = rcu_trace_clock_local();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001174 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001175 rcu_read_lock_bh_held() ||
1176 rcu_read_lock_sched_held() ||
Paul E. McKenney5be5d1a2015-06-30 08:57:57 -07001177 srcu_read_lock_held(srcu_ctlp) ||
1178 torturing_tasks());
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001179 if (p == NULL) {
1180 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001181 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001182 schedule_timeout_interruptible(HZ);
1183 continue;
1184 }
Paul E. McKenney996417d2005-11-18 01:10:50 -08001185 if (p->rtort_mbtest == 0)
1186 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001187 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001188 preempt_disable();
1189 pipe_count = p->rtort_pipe_count;
1190 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1191 /* Should not happen, but... */
1192 pipe_count = RCU_TORTURE_PIPE_LEN;
1193 }
Paul E. McKenney917963d2014-11-21 17:10:16 -08001194 completed = cur_ops->completed();
Paul E. McKenney52494532012-11-14 16:26:40 -08001195 if (pipe_count > 1) {
Paul E. McKenney52494532012-11-14 16:26:40 -08001196 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu,
Paul E. McKenney917963d2014-11-21 17:10:16 -08001197 ts, started, completed);
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001198 rcutorture_trace_dump();
Paul E. McKenney52494532012-11-14 16:26:40 -08001199 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001200 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney917963d2014-11-21 17:10:16 -08001201 completed = completed - started;
1202 if (cur_ops->started)
1203 completed++;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001204 if (completed > RCU_TORTURE_PIPE_LEN) {
1205 /* Should not happen, but... */
1206 completed = RCU_TORTURE_PIPE_LEN;
1207 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001208 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001209 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001210 cur_ops->readunlock(idx);
Paul E. McKenneybde6c3a2014-07-01 11:26:57 -07001211 cond_resched_rcu_qs();
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001212 stutter_wait("rcu_torture_reader");
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001213 } while (!torture_must_stop());
Thomas Gleixner424c1b62014-03-23 08:58:27 -07001214 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001215 del_timer_sync(&t);
Thomas Gleixner424c1b62014-03-23 08:58:27 -07001216 destroy_timer_on_stack(&t);
1217 }
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001218 torture_kthread_stopping("rcu_torture_reader");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001219 return 0;
1220}
1221
1222/*
Joe Percheseea203f2014-07-14 09:16:15 -04001223 * Print torture statistics. Caller must ensure that there is only
1224 * one call to this function at a given time!!! This is normally
1225 * accomplished by relying on the module system to only have one copy
1226 * of the module loaded, and then by giving the rcu_torture_stats
1227 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1228 * thread is not running).
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001229 */
Chen Gangd1008952013-11-07 10:30:25 +08001230static void
Joe Percheseea203f2014-07-14 09:16:15 -04001231rcu_torture_stats_print(void)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001232{
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001233 int cpu;
1234 int i;
1235 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1236 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001237 static unsigned long rtcv_snap = ULONG_MAX;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001238
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001239 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001240 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1241 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1242 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1243 }
1244 }
1245 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1246 if (pipesummary[i] != 0)
1247 break;
1248 }
Joe Percheseea203f2014-07-14 09:16:15 -04001249
1250 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
1251 pr_cont("rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
1252 rcu_torture_current,
1253 rcu_torture_current_version,
1254 list_empty(&rcu_torture_freelist),
1255 atomic_read(&n_rcu_torture_alloc),
1256 atomic_read(&n_rcu_torture_alloc_fail),
1257 atomic_read(&n_rcu_torture_free));
1258 pr_cont("rtmbe: %d rtbke: %ld rtbre: %ld ",
1259 atomic_read(&n_rcu_torture_mberror),
1260 n_rcu_torture_boost_ktrerror,
1261 n_rcu_torture_boost_rterror);
1262 pr_cont("rtbf: %ld rtb: %ld nt: %ld ",
1263 n_rcu_torture_boost_failure,
1264 n_rcu_torture_boosts,
1265 n_rcu_torture_timers);
1266 torture_onoff_stats();
Paul E. McKenney38706bc2014-08-18 21:12:17 -07001267 pr_cont("barrier: %ld/%ld:%ld ",
Joe Percheseea203f2014-07-14 09:16:15 -04001268 n_barrier_successes,
1269 n_barrier_attempts,
1270 n_rcu_torture_barrier_error);
Paul E. McKenney38706bc2014-08-18 21:12:17 -07001271 pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods));
Joe Percheseea203f2014-07-14 09:16:15 -04001272
1273 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001274 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001275 n_rcu_torture_barrier_error != 0 ||
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001276 n_rcu_torture_boost_ktrerror != 0 ||
1277 n_rcu_torture_boost_rterror != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001278 n_rcu_torture_boost_failure != 0 ||
1279 i > 1) {
Joe Percheseea203f2014-07-14 09:16:15 -04001280 pr_cont("%s", "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -08001281 atomic_inc(&n_rcu_torture_error);
Ingo Molnar5af970a2008-06-18 10:09:48 +02001282 WARN_ON_ONCE(1);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001283 }
Joe Percheseea203f2014-07-14 09:16:15 -04001284 pr_cont("Reader Pipe: ");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001285 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Joe Percheseea203f2014-07-14 09:16:15 -04001286 pr_cont(" %ld", pipesummary[i]);
1287 pr_cont("\n");
1288
1289 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
1290 pr_cont("Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001291 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Joe Percheseea203f2014-07-14 09:16:15 -04001292 pr_cont(" %ld", batchsummary[i]);
1293 pr_cont("\n");
1294
1295 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
1296 pr_cont("Free-Block Circulation: ");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001297 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
Joe Percheseea203f2014-07-14 09:16:15 -04001298 pr_cont(" %d", atomic_read(&rcu_torture_wcount[i]));
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001299 }
Joe Percheseea203f2014-07-14 09:16:15 -04001300 pr_cont("\n");
1301
Josh Triplettc8e5b162007-05-08 00:33:20 -07001302 if (cur_ops->stats)
Joe Percheseea203f2014-07-14 09:16:15 -04001303 cur_ops->stats();
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001304 if (rtcv_snap == rcu_torture_current_version &&
1305 rcu_torture_current != NULL) {
1306 int __maybe_unused flags;
1307 unsigned long __maybe_unused gpnum;
1308 unsigned long __maybe_unused completed;
1309
1310 rcutorture_get_gp_data(cur_ops->ttype,
1311 &flags, &gpnum, &completed);
Joe Percheseea203f2014-07-14 09:16:15 -04001312 pr_alert("??? Writer stall state %d g%lu c%lu f%#x\n",
1313 rcu_torture_writer_state,
1314 gpnum, completed, flags);
Paul E. McKenneyafea2272014-03-12 07:10:41 -07001315 show_rcu_gp_kthreads();
Paul E. McKenney945fa9c2014-03-07 14:15:28 -08001316 rcutorture_trace_dump();
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001317 }
1318 rtcv_snap = rcu_torture_current_version;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001319}
1320
1321/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001322 * Periodically prints torture statistics, if periodic statistics printing
1323 * was specified via the stat_interval module parameter.
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001324 */
1325static int
1326rcu_torture_stats(void *arg)
1327{
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001328 VERBOSE_TOROUT_STRING("rcu_torture_stats task started");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001329 do {
1330 schedule_timeout_interruptible(stat_interval * HZ);
1331 rcu_torture_stats_print();
Paul E. McKenneyf67a3352014-01-29 07:40:27 -08001332 torture_shutdown_absorb("rcu_torture_stats");
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001333 } while (!torture_must_stop());
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001334 torture_kthread_stopping("rcu_torture_stats");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001335 return 0;
1336}
1337
Paul E. McKenney95c38322006-03-24 03:15:58 -08001338static inline void
Steven Rostedt (Red Hat)e66c33d2013-07-12 16:50:28 -04001339rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag)
Paul E. McKenney95c38322006-03-24 03:15:58 -08001340{
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001341 pr_alert("%s" TORTURE_FLAG
1342 "--- %s: nreaders=%d nfakewriters=%d "
1343 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1344 "shuffle_interval=%d stutter=%d irqreader=%d "
1345 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1346 "test_boost=%d/%d test_boost_interval=%d "
1347 "test_boost_duration=%d shutdown_secs=%d "
Paul E. McKenney67afeed2012-10-20 12:56:06 -07001348 "stall_cpu=%d stall_cpu_holdoff=%d "
1349 "n_barrier_cbs=%d "
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001350 "onoff_interval=%d onoff_holdoff=%d\n",
1351 torture_type, tag, nrealreaders, nfakewriters,
1352 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
1353 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1354 test_boost, cur_ops->can_boost,
1355 test_boost_interval, test_boost_duration, shutdown_secs,
Paul E. McKenney67afeed2012-10-20 12:56:06 -07001356 stall_cpu, stall_cpu_holdoff,
1357 n_barrier_cbs,
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001358 onoff_interval, onoff_holdoff);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001359}
1360
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001361static void rcutorture_booster_cleanup(int cpu)
1362{
1363 struct task_struct *t;
1364
1365 if (boost_tasks[cpu] == NULL)
1366 return;
1367 mutex_lock(&boost_mutex);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001368 t = boost_tasks[cpu];
1369 boost_tasks[cpu] = NULL;
1370 mutex_unlock(&boost_mutex);
1371
1372 /* This must be outside of the mutex, otherwise deadlock! */
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001373 torture_stop_kthread(rcu_torture_boost, t);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001374}
1375
1376static int rcutorture_booster_init(int cpu)
1377{
1378 int retval;
1379
1380 if (boost_tasks[cpu] != NULL)
1381 return 0; /* Already created, nothing more to do. */
1382
1383 /* Don't allow time recalculation while creating a new task. */
1384 mutex_lock(&boost_mutex);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001385 VERBOSE_TOROUT_STRING("Creating rcu_torture_boost task");
Eric Dumazet1f288092011-06-16 15:53:18 -07001386 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1387 cpu_to_node(cpu),
1388 "rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001389 if (IS_ERR(boost_tasks[cpu])) {
1390 retval = PTR_ERR(boost_tasks[cpu]);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001391 VERBOSE_TOROUT_STRING("rcu_torture_boost task create failed");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001392 n_rcu_torture_boost_ktrerror++;
1393 boost_tasks[cpu] = NULL;
1394 mutex_unlock(&boost_mutex);
1395 return retval;
1396 }
1397 kthread_bind(boost_tasks[cpu], cpu);
1398 wake_up_process(boost_tasks[cpu]);
1399 mutex_unlock(&boost_mutex);
1400 return 0;
1401}
1402
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001403/*
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001404 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1405 * induces a CPU stall for the time specified by stall_cpu.
1406 */
Paul Gortmaker49fb4c62013-06-19 14:52:21 -04001407static int rcu_torture_stall(void *args)
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001408{
1409 unsigned long stop_at;
1410
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001411 VERBOSE_TOROUT_STRING("rcu_torture_stall task started");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001412 if (stall_cpu_holdoff > 0) {
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001413 VERBOSE_TOROUT_STRING("rcu_torture_stall begin holdoff");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001414 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001415 VERBOSE_TOROUT_STRING("rcu_torture_stall end holdoff");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001416 }
1417 if (!kthread_should_stop()) {
1418 stop_at = get_seconds() + stall_cpu;
1419 /* RCU CPU stall is expected behavior in following code. */
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001420 pr_alert("rcu_torture_stall start.\n");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001421 rcu_read_lock();
1422 preempt_disable();
1423 while (ULONG_CMP_LT(get_seconds(), stop_at))
1424 continue; /* Induce RCU CPU stall warning. */
1425 preempt_enable();
1426 rcu_read_unlock();
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001427 pr_alert("rcu_torture_stall end.\n");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001428 }
Paul E. McKenneyf67a3352014-01-29 07:40:27 -08001429 torture_shutdown_absorb("rcu_torture_stall");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001430 while (!kthread_should_stop())
1431 schedule_timeout_interruptible(10 * HZ);
1432 return 0;
1433}
1434
1435/* Spawn CPU-stall kthread, if stall_cpu specified. */
1436static int __init rcu_torture_stall_init(void)
1437{
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001438 if (stall_cpu <= 0)
1439 return 0;
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001440 return torture_create_kthread(rcu_torture_stall, NULL, stall_task);
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001441}
1442
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001443/* Callback function for RCU barrier testing. */
Rashika Kheriab3b8a4d2014-02-27 17:16:57 +05301444static void rcu_torture_barrier_cbf(struct rcu_head *rcu)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001445{
1446 atomic_inc(&barrier_cbs_invoked);
1447}
1448
1449/* kthread function to register callbacks used to test RCU barriers. */
1450static int rcu_torture_barrier_cbs(void *arg)
1451{
1452 long myid = (long)arg;
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001453 bool lastphase = 0;
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001454 bool newphase;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001455 struct rcu_head rcu;
1456
1457 init_rcu_head_on_stack(&rcu);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001458 VERBOSE_TOROUT_STRING("rcu_torture_barrier_cbs task started");
Linus Torvalds971eae72014-03-31 11:21:19 -07001459 set_user_nice(current, MAX_NICE);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001460 do {
1461 wait_event(barrier_cbs_wq[myid],
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001462 (newphase =
Paul E. McKenney6c7ed422015-04-13 11:58:08 -07001463 smp_load_acquire(&barrier_phase)) != lastphase ||
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001464 torture_must_stop());
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001465 lastphase = newphase;
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001466 if (torture_must_stop())
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001467 break;
Paul E. McKenney6c7ed422015-04-13 11:58:08 -07001468 /*
1469 * The above smp_load_acquire() ensures barrier_phase load
1470 * is ordered before the folloiwng ->call().
1471 */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001472 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1473 if (atomic_dec_and_test(&barrier_cbs_count))
1474 wake_up(&barrier_wq);
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001475 } while (!torture_must_stop());
Paul E. McKenney69c60452014-07-01 11:59:36 -07001476 if (cur_ops->cb_barrier != NULL)
1477 cur_ops->cb_barrier();
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001478 destroy_rcu_head_on_stack(&rcu);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001479 torture_kthread_stopping("rcu_torture_barrier_cbs");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001480 return 0;
1481}
1482
1483/* kthread function to drive and coordinate RCU barrier testing. */
1484static int rcu_torture_barrier(void *arg)
1485{
1486 int i;
1487
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001488 VERBOSE_TOROUT_STRING("rcu_torture_barrier task starting");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001489 do {
1490 atomic_set(&barrier_cbs_invoked, 0);
1491 atomic_set(&barrier_cbs_count, n_barrier_cbs);
Paul E. McKenney6c7ed422015-04-13 11:58:08 -07001492 /* Ensure barrier_phase ordered after prior assignments. */
1493 smp_store_release(&barrier_phase, !barrier_phase);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001494 for (i = 0; i < n_barrier_cbs; i++)
1495 wake_up(&barrier_cbs_wq[i]);
1496 wait_event(barrier_wq,
1497 atomic_read(&barrier_cbs_count) == 0 ||
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001498 torture_must_stop());
1499 if (torture_must_stop())
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001500 break;
1501 n_barrier_attempts++;
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001502 cur_ops->cb_barrier(); /* Implies smp_mb() for wait_event(). */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001503 if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
1504 n_rcu_torture_barrier_error++;
Paul E. McKenney7602de4a2014-12-17 18:39:54 -08001505 pr_err("barrier_cbs_invoked = %d, n_barrier_cbs = %d\n",
1506 atomic_read(&barrier_cbs_invoked),
1507 n_barrier_cbs);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001508 WARN_ON_ONCE(1);
1509 }
1510 n_barrier_successes++;
1511 schedule_timeout_interruptible(HZ / 10);
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001512 } while (!torture_must_stop());
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001513 torture_kthread_stopping("rcu_torture_barrier");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001514 return 0;
1515}
1516
1517/* Initialize RCU barrier testing. */
1518static int rcu_torture_barrier_init(void)
1519{
1520 int i;
1521 int ret;
1522
Paul E. McKenneyd9eba762015-05-14 15:35:43 -07001523 if (n_barrier_cbs <= 0)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001524 return 0;
1525 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001526 pr_alert("%s" TORTURE_FLAG
1527 " Call or barrier ops missing for %s,\n",
1528 torture_type, cur_ops->name);
1529 pr_alert("%s" TORTURE_FLAG
1530 " RCU barrier testing omitted from run.\n",
1531 torture_type);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001532 return 0;
1533 }
1534 atomic_set(&barrier_cbs_count, 0);
1535 atomic_set(&barrier_cbs_invoked, 0);
1536 barrier_cbs_tasks =
1537 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
1538 GFP_KERNEL);
1539 barrier_cbs_wq =
1540 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
1541 GFP_KERNEL);
Sasha Levinde5e6432012-12-20 14:11:28 -05001542 if (barrier_cbs_tasks == NULL || !barrier_cbs_wq)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001543 return -ENOMEM;
1544 for (i = 0; i < n_barrier_cbs; i++) {
1545 init_waitqueue_head(&barrier_cbs_wq[i]);
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001546 ret = torture_create_kthread(rcu_torture_barrier_cbs,
1547 (void *)(long)i,
1548 barrier_cbs_tasks[i]);
1549 if (ret)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001550 return ret;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001551 }
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001552 return torture_create_kthread(rcu_torture_barrier, NULL, barrier_task);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001553}
1554
1555/* Clean up after RCU barrier testing. */
1556static void rcu_torture_barrier_cleanup(void)
1557{
1558 int i;
1559
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001560 torture_stop_kthread(rcu_torture_barrier, barrier_task);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001561 if (barrier_cbs_tasks != NULL) {
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001562 for (i = 0; i < n_barrier_cbs; i++)
1563 torture_stop_kthread(rcu_torture_barrier_cbs,
1564 barrier_cbs_tasks[i]);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001565 kfree(barrier_cbs_tasks);
1566 barrier_cbs_tasks = NULL;
1567 }
1568 if (barrier_cbs_wq != NULL) {
1569 kfree(barrier_cbs_wq);
1570 barrier_cbs_wq = NULL;
1571 }
1572}
1573
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001574static int rcutorture_cpu_notify(struct notifier_block *self,
1575 unsigned long action, void *hcpu)
1576{
1577 long cpu = (long)hcpu;
1578
1579 switch (action) {
1580 case CPU_ONLINE:
1581 case CPU_DOWN_FAILED:
1582 (void)rcutorture_booster_init(cpu);
1583 break;
1584 case CPU_DOWN_PREPARE:
1585 rcutorture_booster_cleanup(cpu);
1586 break;
1587 default:
1588 break;
1589 }
1590 return NOTIFY_OK;
1591}
1592
1593static struct notifier_block rcutorture_cpu_nb = {
1594 .notifier_call = rcutorture_cpu_notify,
1595};
1596
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001597static void
1598rcu_torture_cleanup(void)
1599{
1600 int i;
1601
Paul E. McKenney4a298652011-04-03 21:33:51 -07001602 rcutorture_record_test_transition();
Davidlohr Buesod36a7a02014-09-11 20:40:21 -07001603 if (torture_cleanup_begin()) {
Paul E. McKenney343e9092008-12-15 16:13:07 -08001604 if (cur_ops->cb_barrier != NULL)
1605 cur_ops->cb_barrier();
1606 return;
1607 }
Paul E. McKenney3808dc92014-01-28 15:29:21 -08001608
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001609 rcu_torture_barrier_cleanup();
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001610 torture_stop_kthread(rcu_torture_stall, stall_task);
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001611 torture_stop_kthread(rcu_torture_writer, writer_task);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001612
Josh Triplettc8e5b162007-05-08 00:33:20 -07001613 if (reader_tasks) {
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001614 for (i = 0; i < nrealreaders; i++)
1615 torture_stop_kthread(rcu_torture_reader,
1616 reader_tasks[i]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001617 kfree(reader_tasks);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001618 }
1619 rcu_torture_current = NULL;
1620
Josh Triplettc8e5b162007-05-08 00:33:20 -07001621 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001622 for (i = 0; i < nfakewriters; i++) {
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001623 torture_stop_kthread(rcu_torture_fakewriter,
1624 fakewriter_tasks[i]);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001625 }
1626 kfree(fakewriter_tasks);
1627 fakewriter_tasks = NULL;
1628 }
1629
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001630 torture_stop_kthread(rcu_torture_stats, stats_task);
1631 torture_stop_kthread(rcu_torture_fqs, fqs_task);
Paul E. McKenney38706bc2014-08-18 21:12:17 -07001632 for (i = 0; i < ncbflooders; i++)
1633 torture_stop_kthread(rcu_torture_cbflood, cbflood_task[i]);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001634 if ((test_boost == 1 && cur_ops->can_boost) ||
1635 test_boost == 2) {
1636 unregister_cpu_notifier(&rcutorture_cpu_nb);
1637 for_each_possible_cpu(i)
1638 rcutorture_booster_cleanup(i);
1639 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001640
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -07001641 /*
1642 * Wait for all RCU callbacks to fire, then do flavor-specific
1643 * cleanup operations.
1644 */
Paul E. McKenney23269742008-05-12 21:21:05 +02001645 if (cur_ops->cb_barrier != NULL)
1646 cur_ops->cb_barrier();
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -07001647 if (cur_ops->cleanup != NULL)
1648 cur_ops->cleanup();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001649
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001650 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001651
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001652 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001653 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
Paul E. McKenney2e9e8082014-01-28 15:58:22 -08001654 else if (torture_onoff_failures())
Paul E. McKenney091541b2012-01-10 12:51:14 -08001655 rcu_torture_print_module_parms(cur_ops,
1656 "End of test: RCU_HOTPLUG");
Paul E. McKenney95c38322006-03-24 03:15:58 -08001657 else
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001658 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
Davidlohr Buesod36a7a02014-09-11 20:40:21 -07001659 torture_cleanup_end();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001660}
1661
Paul E. McKenneyd2818df2013-04-23 17:05:42 -07001662#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1663static void rcu_torture_leak_cb(struct rcu_head *rhp)
1664{
1665}
1666
1667static void rcu_torture_err_cb(struct rcu_head *rhp)
1668{
1669 /*
1670 * This -might- happen due to race conditions, but is unlikely.
1671 * The scenario that leads to this happening is that the
1672 * first of the pair of duplicate callbacks is queued,
1673 * someone else starts a grace period that includes that
1674 * callback, then the second of the pair must wait for the
1675 * next grace period. Unlikely, but can happen. If it
1676 * does happen, the debug-objects subsystem won't have splatted.
1677 */
1678 pr_alert("rcutorture: duplicated callback was invoked.\n");
1679}
1680#endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1681
1682/*
1683 * Verify that double-free causes debug-objects to complain, but only
1684 * if CONFIG_DEBUG_OBJECTS_RCU_HEAD=y. Otherwise, say that the test
1685 * cannot be carried out.
1686 */
1687static void rcu_test_debug_objects(void)
1688{
1689#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1690 struct rcu_head rh1;
1691 struct rcu_head rh2;
1692
1693 init_rcu_head_on_stack(&rh1);
1694 init_rcu_head_on_stack(&rh2);
1695 pr_alert("rcutorture: WARN: Duplicate call_rcu() test starting.\n");
1696
1697 /* Try to queue the rh2 pair of callbacks for the same grace period. */
1698 preempt_disable(); /* Prevent preemption from interrupting test. */
1699 rcu_read_lock(); /* Make it impossible to finish a grace period. */
1700 call_rcu(&rh1, rcu_torture_leak_cb); /* Start grace period. */
1701 local_irq_disable(); /* Make it harder to start a new grace period. */
1702 call_rcu(&rh2, rcu_torture_leak_cb);
1703 call_rcu(&rh2, rcu_torture_err_cb); /* Duplicate callback. */
1704 local_irq_enable();
1705 rcu_read_unlock();
1706 preempt_enable();
1707
1708 /* Wait for them all to get done so we can safely return. */
1709 rcu_barrier();
1710 pr_alert("rcutorture: WARN: Duplicate call_rcu() test complete.\n");
1711 destroy_rcu_head_on_stack(&rh1);
1712 destroy_rcu_head_on_stack(&rh2);
1713#else /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1714 pr_alert("rcutorture: !CONFIG_DEBUG_OBJECTS_RCU_HEAD, not testing duplicate call_rcu()\n");
1715#endif /* #else #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1716}
1717
Josh Triplett6f8bc502007-05-08 00:25:24 -07001718static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001719rcu_torture_init(void)
1720{
1721 int i;
1722 int cpu;
1723 int firsterr = 0;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001724 static struct rcu_torture_ops *torture_ops[] = {
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -07001725 &rcu_ops, &rcu_bh_ops, &rcu_busted_ops, &srcu_ops, &srcud_ops,
1726 &sched_ops, RCUTORTURE_TASKS_OPS
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001727 };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001728
Paul E. McKenney59da22a2014-09-12 10:36:15 -07001729 if (!torture_init_begin(torture_type, verbose, &torture_runnable))
Paul E. McKenney52280842014-04-07 09:14:11 -07001730 return -EBUSY;
Paul E. McKenney343e9092008-12-15 16:13:07 -08001731
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001732 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001733 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001734 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001735 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001736 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001737 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001738 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001739 pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
1740 torture_type);
1741 pr_alert("rcu-torture types:");
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001742 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001743 pr_alert(" %s", torture_ops[i]->name);
1744 pr_alert("\n");
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -08001745 torture_init_end();
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001746 return -EINVAL;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001747 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001748 if (cur_ops->fqs == NULL && fqs_duration != 0) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001749 pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001750 fqs_duration = 0;
1751 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001752 if (cur_ops->init)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001753 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1754
Paul E. McKenney64e4b432014-03-12 10:26:35 -07001755 if (nreaders >= 0) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001756 nrealreaders = nreaders;
Paul E. McKenney64e4b432014-03-12 10:26:35 -07001757 } else {
Paul E. McKenney3838cc12015-03-12 13:55:48 -07001758 nrealreaders = num_online_cpus() - 2 - nreaders;
Paul E. McKenney64e4b432014-03-12 10:26:35 -07001759 if (nrealreaders <= 0)
1760 nrealreaders = 1;
1761 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001762 rcu_torture_print_module_parms(cur_ops, "Start of test");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001763
1764 /* Set up the freelist. */
1765
1766 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07001767 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08001768 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001769 list_add_tail(&rcu_tortures[i].rtort_free,
1770 &rcu_torture_freelist);
1771 }
1772
1773 /* Initialize the statistics so that each run gets its own numbers. */
1774
1775 rcu_torture_current = NULL;
1776 rcu_torture_current_version = 0;
1777 atomic_set(&n_rcu_torture_alloc, 0);
1778 atomic_set(&n_rcu_torture_alloc_fail, 0);
1779 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001780 atomic_set(&n_rcu_torture_mberror, 0);
1781 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001782 n_rcu_torture_barrier_error = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001783 n_rcu_torture_boost_ktrerror = 0;
1784 n_rcu_torture_boost_rterror = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001785 n_rcu_torture_boost_failure = 0;
1786 n_rcu_torture_boosts = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001787 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1788 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001789 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001790 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1791 per_cpu(rcu_torture_count, cpu)[i] = 0;
1792 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1793 }
1794 }
1795
1796 /* Start up the kthreads. */
1797
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001798 firsterr = torture_create_kthread(rcu_torture_writer, NULL,
1799 writer_task);
1800 if (firsterr)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001801 goto unwind;
Paul E. McKenney4444d852015-05-14 15:42:40 -07001802 if (nfakewriters > 0) {
1803 fakewriter_tasks = kzalloc(nfakewriters *
1804 sizeof(fakewriter_tasks[0]),
1805 GFP_KERNEL);
1806 if (fakewriter_tasks == NULL) {
1807 VERBOSE_TOROUT_ERRSTRING("out of memory");
1808 firsterr = -ENOMEM;
1809 goto unwind;
1810 }
Josh Triplettb772e1d2006-10-04 02:17:13 -07001811 }
1812 for (i = 0; i < nfakewriters; i++) {
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001813 firsterr = torture_create_kthread(rcu_torture_fakewriter,
1814 NULL, fakewriter_tasks[i]);
1815 if (firsterr)
Josh Triplettb772e1d2006-10-04 02:17:13 -07001816 goto unwind;
Josh Triplettb772e1d2006-10-04 02:17:13 -07001817 }
Josh Triplett2860aab2006-10-04 02:17:11 -07001818 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001819 GFP_KERNEL);
1820 if (reader_tasks == NULL) {
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001821 VERBOSE_TOROUT_ERRSTRING("out of memory");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001822 firsterr = -ENOMEM;
1823 goto unwind;
1824 }
1825 for (i = 0; i < nrealreaders; i++) {
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001826 firsterr = torture_create_kthread(rcu_torture_reader, NULL,
1827 reader_tasks[i]);
1828 if (firsterr)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001829 goto unwind;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001830 }
1831 if (stat_interval > 0) {
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001832 firsterr = torture_create_kthread(rcu_torture_stats, NULL,
1833 stats_task);
1834 if (firsterr)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001835 goto unwind;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001836 }
Paul E. McKenneye8e255f2015-05-14 16:55:45 -07001837 if (test_no_idle_hz && shuffle_interval > 0) {
Paul E. McKenney3808dc92014-01-28 15:29:21 -08001838 firsterr = torture_shuffle_init(shuffle_interval * HZ);
1839 if (firsterr)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001840 goto unwind;
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001841 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001842 if (stutter < 0)
1843 stutter = 0;
1844 if (stutter) {
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001845 firsterr = torture_stutter_init(stutter * HZ);
1846 if (firsterr)
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001847 goto unwind;
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001848 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001849 if (fqs_duration < 0)
1850 fqs_duration = 0;
1851 if (fqs_duration) {
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001852 /* Create the fqs thread */
Paul E. McKenneyd0d06062014-03-17 20:56:45 -07001853 firsterr = torture_create_kthread(rcu_torture_fqs, NULL,
1854 fqs_task);
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001855 if (firsterr)
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001856 goto unwind;
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001857 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001858 if (test_boost_interval < 1)
1859 test_boost_interval = 1;
1860 if (test_boost_duration < 2)
1861 test_boost_duration = 2;
1862 if ((test_boost == 1 && cur_ops->can_boost) ||
1863 test_boost == 2) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001864
1865 boost_starttime = jiffies + test_boost_interval * HZ;
1866 register_cpu_notifier(&rcutorture_cpu_nb);
1867 for_each_possible_cpu(i) {
1868 if (cpu_is_offline(i))
1869 continue; /* Heuristic: CPU can go offline. */
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001870 firsterr = rcutorture_booster_init(i);
1871 if (firsterr)
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001872 goto unwind;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001873 }
1874 }
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001875 firsterr = torture_shutdown_init(shutdown_secs, rcu_torture_cleanup);
1876 if (firsterr)
Paul E. McKenneye991dbc2014-01-31 14:52:13 -08001877 goto unwind;
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001878 firsterr = torture_onoff_init(onoff_holdoff * HZ, onoff_interval * HZ);
1879 if (firsterr)
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001880 goto unwind;
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001881 firsterr = rcu_torture_stall_init();
1882 if (firsterr)
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001883 goto unwind;
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001884 firsterr = rcu_torture_barrier_init();
1885 if (firsterr)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001886 goto unwind;
Paul E. McKenneyd2818df2013-04-23 17:05:42 -07001887 if (object_debug)
1888 rcu_test_debug_objects();
Paul E. McKenney38706bc2014-08-18 21:12:17 -07001889 if (cbflood_n_burst > 0) {
1890 /* Create the cbflood threads */
1891 ncbflooders = (num_online_cpus() + 3) / 4;
1892 cbflood_task = kcalloc(ncbflooders, sizeof(*cbflood_task),
1893 GFP_KERNEL);
1894 if (!cbflood_task) {
1895 VERBOSE_TOROUT_ERRSTRING("out of memory");
1896 firsterr = -ENOMEM;
1897 goto unwind;
1898 }
1899 for (i = 0; i < ncbflooders; i++) {
1900 firsterr = torture_create_kthread(rcu_torture_cbflood,
1901 NULL,
1902 cbflood_task[i]);
1903 if (firsterr)
1904 goto unwind;
1905 }
1906 }
Paul E. McKenney4a298652011-04-03 21:33:51 -07001907 rcutorture_record_test_transition();
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -08001908 torture_init_end();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001909 return 0;
1910
1911unwind:
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -08001912 torture_init_end();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001913 rcu_torture_cleanup();
1914 return firsterr;
1915}
1916
1917module_init(rcu_torture_init);
1918module_exit(rcu_torture_cleanup);