blob: d89328e260df6f4f953b649fea98587aacf12318 [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 Triplette0198b292014-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 Triplette0198b292014-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);
Boqun Fengdb3e8db2015-07-29 13:29:39 +0800255 call_rcu_func_t call;
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
Boqun Fengb6a4ae72015-07-29 13:29:38 +0800451call_rcu_busted(struct rcu_head *head, rcu_callback_t func)
Paul E. McKenneyff20e252014-02-06 08:45:56 -0800452{
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,
Boqun Fengb6a4ae72015-07-29 13:29:38 +0800526 rcu_callback_t func)
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700527{
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. McKenney4f441a22015-08-24 13:13:51 -0700698static bool __maybe_unused torturing_tasks(void)
Paul E. McKenney5be5d1a2015-06-30 08:57:57 -0700699{
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. McKenney628edaa2014-01-31 11:57:43 -0800771 stutter_wait("rcu_torture_boost");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800772 if (torture_must_stop())
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700773 goto checkwait;
774 }
775
776 /*
777 * Set the start time of the next test interval.
778 * Yes, this is vulnerable to long delays, but such
779 * delays simply cause a false negative for the next
780 * interval. Besides, we are running at RT priority,
781 * so delays should be relatively rare.
782 */
Paul E. McKenneyab8f11e2011-08-18 09:30:32 -0700783 while (oldstarttime == boost_starttime &&
784 !kthread_should_stop()) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700785 if (mutex_trylock(&boost_mutex)) {
786 boost_starttime = jiffies +
787 test_boost_interval * HZ;
788 n_rcu_torture_boosts++;
789 mutex_unlock(&boost_mutex);
790 break;
791 }
792 schedule_timeout_uninterruptible(1);
793 }
794
795 /* Go do the stutter. */
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800796checkwait: stutter_wait("rcu_torture_boost");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800797 } while (!torture_must_stop());
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700798
799 /* Clean up and exit. */
Paul E. McKenney6c7ed422015-04-13 11:58:08 -0700800 while (!kthread_should_stop() || smp_load_acquire(&rbi.inflight)) {
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800801 torture_shutdown_absorb("rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700802 schedule_timeout_uninterruptible(1);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800803 }
Paul E. McKenney9d681972011-06-21 01:48:03 -0700804 destroy_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800805 torture_kthread_stopping("rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700806 return 0;
807}
808
Paul E. McKenney38706bc2014-08-18 21:12:17 -0700809static void rcu_torture_cbflood_cb(struct rcu_head *rhp)
810{
811}
812
813/*
814 * RCU torture callback-flood kthread. Repeatedly induces bursts of calls
815 * to call_rcu() or analogous, increasing the probability of occurrence
816 * of callback-overflow corner cases.
817 */
818static int
819rcu_torture_cbflood(void *arg)
820{
821 int err = 1;
822 int i;
823 int j;
824 struct rcu_head *rhp;
825
826 if (cbflood_n_per_burst > 0 &&
827 cbflood_inter_holdoff > 0 &&
828 cbflood_intra_holdoff > 0 &&
829 cur_ops->call &&
830 cur_ops->cb_barrier) {
831 rhp = vmalloc(sizeof(*rhp) *
832 cbflood_n_burst * cbflood_n_per_burst);
833 err = !rhp;
834 }
835 if (err) {
836 VERBOSE_TOROUT_STRING("rcu_torture_cbflood disabled: Bad args or OOM");
Paul E. McKenney3a0af332015-06-22 18:11:31 -0700837 goto wait_for_stop;
Paul E. McKenney38706bc2014-08-18 21:12:17 -0700838 }
839 VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started");
840 do {
841 schedule_timeout_interruptible(cbflood_inter_holdoff);
842 atomic_long_inc(&n_cbfloods);
843 WARN_ON(signal_pending(current));
844 for (i = 0; i < cbflood_n_burst; i++) {
845 for (j = 0; j < cbflood_n_per_burst; j++) {
846 cur_ops->call(&rhp[i * cbflood_n_per_burst + j],
847 rcu_torture_cbflood_cb);
848 }
849 schedule_timeout_interruptible(cbflood_intra_holdoff);
850 WARN_ON(signal_pending(current));
851 }
852 cur_ops->cb_barrier();
853 stutter_wait("rcu_torture_cbflood");
854 } while (!torture_must_stop());
Paul E. McKenneyb8969d12014-10-27 15:52:04 -0700855 vfree(rhp);
Paul E. McKenney3a0af332015-06-22 18:11:31 -0700856wait_for_stop:
Paul E. McKenney38706bc2014-08-18 21:12:17 -0700857 torture_kthread_stopping("rcu_torture_cbflood");
858 return 0;
859}
860
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700861/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800862 * RCU torture force-quiescent-state kthread. Repeatedly induces
863 * bursts of calls to force_quiescent_state(), increasing the probability
864 * of occurrence of some important types of race conditions.
865 */
866static int
867rcu_torture_fqs(void *arg)
868{
869 unsigned long fqs_resume_time;
870 int fqs_burst_remaining;
871
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800872 VERBOSE_TOROUT_STRING("rcu_torture_fqs task started");
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800873 do {
874 fqs_resume_time = jiffies + fqs_stutter * HZ;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700875 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
876 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800877 schedule_timeout_interruptible(1);
878 }
879 fqs_burst_remaining = fqs_duration;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700880 while (fqs_burst_remaining > 0 &&
881 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800882 cur_ops->fqs();
883 udelay(fqs_holdoff);
884 fqs_burst_remaining -= fqs_holdoff;
885 }
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800886 stutter_wait("rcu_torture_fqs");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800887 } while (!torture_must_stop());
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800888 torture_kthread_stopping("rcu_torture_fqs");
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800889 return 0;
890}
891
892/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800893 * RCU torture writer kthread. Repeatedly substitutes a new structure
894 * for that pointed to by rcu_torture_current, freeing the old structure
895 * after a series of grace periods (the "pipeline").
896 */
897static int
898rcu_torture_writer(void *arg)
899{
Paul E. McKenney4bb3c5f2015-02-18 16:31:29 -0800900 bool can_expedite = !rcu_gp_is_expedited();
901 int expediting = 0;
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700902 unsigned long gp_snap;
903 bool gp_cond1 = gp_cond, gp_exp1 = gp_exp, gp_normal1 = gp_normal;
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700904 bool gp_sync1 = gp_sync;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800905 int i;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800906 struct rcu_torture *rp;
907 struct rcu_torture *old_rp;
Paul E. McKenney51b11302014-01-27 11:49:39 -0800908 static DEFINE_TORTURE_RANDOM(rand);
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700909 int synctype[] = { RTWS_DEF_FREE, RTWS_EXP_SYNC,
910 RTWS_COND_GET, RTWS_SYNC };
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700911 int nsynctypes = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800912
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800913 VERBOSE_TOROUT_STRING("rcu_torture_writer task started");
Paul E. McKenney4bb3c5f2015-02-18 16:31:29 -0800914 pr_alert("%s" TORTURE_FLAG
915 " Grace periods expedited from boot/sysfs for %s,\n",
916 torture_type, cur_ops->name);
917 pr_alert("%s" TORTURE_FLAG
918 " Testing of dynamic grace-period expediting diabled.\n",
919 torture_type);
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800920
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700921 /* Initialize synctype[] array. If none set, take default. */
Paul E. McKenneyc136f992015-02-19 12:15:19 -0800922 if (!gp_cond1 && !gp_exp1 && !gp_normal1 && !gp_sync1)
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700923 gp_cond1 = gp_exp1 = gp_normal1 = gp_sync1 = true;
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700924 if (gp_cond1 && cur_ops->get_state && cur_ops->cond_sync)
925 synctype[nsynctypes++] = RTWS_COND_GET;
926 else if (gp_cond && (!cur_ops->get_state || !cur_ops->cond_sync))
927 pr_alert("rcu_torture_writer: gp_cond without primitives.\n");
928 if (gp_exp1 && cur_ops->exp_sync)
929 synctype[nsynctypes++] = RTWS_EXP_SYNC;
930 else if (gp_exp && !cur_ops->exp_sync)
931 pr_alert("rcu_torture_writer: gp_exp without primitives.\n");
932 if (gp_normal1 && cur_ops->deferred_free)
933 synctype[nsynctypes++] = RTWS_DEF_FREE;
934 else if (gp_normal && !cur_ops->deferred_free)
935 pr_alert("rcu_torture_writer: gp_normal without primitives.\n");
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700936 if (gp_sync1 && cur_ops->sync)
937 synctype[nsynctypes++] = RTWS_SYNC;
938 else if (gp_sync && !cur_ops->sync)
939 pr_alert("rcu_torture_writer: gp_sync without primitives.\n");
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700940 if (WARN_ONCE(nsynctypes == 0,
941 "rcu_torture_writer: No update-side primitives.\n")) {
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700942 /*
943 * No updates primitives, so don't try updating.
944 * The resulting test won't be testing much, hence the
945 * above WARN_ONCE().
946 */
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700947 rcu_torture_writer_state = RTWS_STOPPING;
948 torture_kthread_stopping("rcu_torture_writer");
949 }
950
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800951 do {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800952 rcu_torture_writer_state = RTWS_FIXED_DELAY;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800953 schedule_timeout_uninterruptible(1);
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700954 rp = rcu_torture_alloc();
955 if (rp == NULL)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800956 continue;
957 rp->rtort_pipe_count = 0;
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800958 rcu_torture_writer_state = RTWS_DELAY;
Paul E. McKenney51b11302014-01-27 11:49:39 -0800959 udelay(torture_random(&rand) & 0x3ff);
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800960 rcu_torture_writer_state = RTWS_REPLACE;
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700961 old_rp = rcu_dereference_check(rcu_torture_current,
962 current == writer_task);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800963 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800964 rcu_assign_pointer(rcu_torture_current, rp);
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700965 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
Josh Triplettc8e5b162007-05-08 00:33:20 -0700966 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800967 i = old_rp->rtort_pipe_count;
968 if (i > RCU_TORTURE_PIPE_LEN)
969 i = RCU_TORTURE_PIPE_LEN;
970 atomic_inc(&rcu_torture_wcount[i]);
971 old_rp->rtort_pipe_count++;
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700972 switch (synctype[torture_random(&rand) % nsynctypes]) {
973 case RTWS_DEF_FREE:
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800974 rcu_torture_writer_state = RTWS_DEF_FREE;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700975 cur_ops->deferred_free(old_rp);
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700976 break;
977 case RTWS_EXP_SYNC:
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800978 rcu_torture_writer_state = RTWS_EXP_SYNC;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700979 cur_ops->exp_sync();
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700980 rcu_torture_pipe_update(old_rp);
981 break;
982 case RTWS_COND_GET:
983 rcu_torture_writer_state = RTWS_COND_GET;
984 gp_snap = cur_ops->get_state();
985 i = torture_random(&rand) % 16;
986 if (i != 0)
987 schedule_timeout_interruptible(i);
988 udelay(torture_random(&rand) % 1000);
989 rcu_torture_writer_state = RTWS_COND_SYNC;
990 cur_ops->cond_sync(gp_snap);
991 rcu_torture_pipe_update(old_rp);
992 break;
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700993 case RTWS_SYNC:
994 rcu_torture_writer_state = RTWS_SYNC;
995 cur_ops->sync();
996 rcu_torture_pipe_update(old_rp);
997 break;
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700998 default:
999 WARN_ON_ONCE(1);
1000 break;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001001 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001002 }
Paul E. McKenney4a298652011-04-03 21:33:51 -07001003 rcutorture_record_progress(++rcu_torture_current_version);
Paul E. McKenney4bb3c5f2015-02-18 16:31:29 -08001004 /* Cycle through nesting levels of rcu_expedite_gp() calls. */
1005 if (can_expedite &&
1006 !(torture_random(&rand) & 0xff & (!!expediting - 1))) {
1007 WARN_ON_ONCE(expediting == 0 && rcu_gp_is_expedited());
1008 if (expediting >= 0)
1009 rcu_expedite_gp();
1010 else
1011 rcu_unexpedite_gp();
1012 if (++expediting > 3)
1013 expediting = -expediting;
1014 }
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001015 rcu_torture_writer_state = RTWS_STUTTER;
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001016 stutter_wait("rcu_torture_writer");
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001017 } while (!torture_must_stop());
Paul E. McKenney4bb3c5f2015-02-18 16:31:29 -08001018 /* Reset expediting back to unexpedited. */
1019 if (expediting > 0)
1020 expediting = -expediting;
1021 while (can_expedite && expediting++ < 0)
1022 rcu_unexpedite_gp();
1023 WARN_ON_ONCE(can_expedite && rcu_gp_is_expedited());
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001024 rcu_torture_writer_state = RTWS_STOPPING;
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001025 torture_kthread_stopping("rcu_torture_writer");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001026 return 0;
1027}
1028
1029/*
Josh Triplettb772e1d2006-10-04 02:17:13 -07001030 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
1031 * delay between calls.
1032 */
1033static int
1034rcu_torture_fakewriter(void *arg)
1035{
Paul E. McKenney51b11302014-01-27 11:49:39 -08001036 DEFINE_TORTURE_RANDOM(rand);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001037
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001038 VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task started");
Linus Torvalds971eae72014-03-31 11:21:19 -07001039 set_user_nice(current, MAX_NICE);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001040
1041 do {
Paul E. McKenney51b11302014-01-27 11:49:39 -08001042 schedule_timeout_uninterruptible(1 + torture_random(&rand)%10);
1043 udelay(torture_random(&rand) & 0x3ff);
Paul E. McKenney72472a02012-05-29 17:50:51 -07001044 if (cur_ops->cb_barrier != NULL &&
Paul E. McKenney51b11302014-01-27 11:49:39 -08001045 torture_random(&rand) % (nfakewriters * 8) == 0) {
Paul E. McKenney72472a02012-05-29 17:50:51 -07001046 cur_ops->cb_barrier();
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001047 } else if (gp_normal == gp_exp) {
Paul E. McKenney51b11302014-01-27 11:49:39 -08001048 if (torture_random(&rand) & 0x80)
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001049 cur_ops->sync();
1050 else
1051 cur_ops->exp_sync();
1052 } else if (gp_normal) {
Paul E. McKenney72472a02012-05-29 17:50:51 -07001053 cur_ops->sync();
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001054 } else {
1055 cur_ops->exp_sync();
1056 }
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001057 stutter_wait("rcu_torture_fakewriter");
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001058 } while (!torture_must_stop());
Josh Triplettb772e1d2006-10-04 02:17:13 -07001059
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001060 torture_kthread_stopping("rcu_torture_fakewriter");
Josh Triplettb772e1d2006-10-04 02:17:13 -07001061 return 0;
1062}
1063
Rashika Kheriab3b8a4d2014-02-27 17:16:57 +05301064static void rcutorture_trace_dump(void)
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001065{
1066 static atomic_t beenhere = ATOMIC_INIT(0);
1067
1068 if (atomic_read(&beenhere))
1069 return;
1070 if (atomic_xchg(&beenhere, 1) != 0)
1071 return;
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001072 ftrace_dump(DUMP_ALL);
1073}
1074
Josh Triplettb772e1d2006-10-04 02:17:13 -07001075/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001076 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
1077 * incrementing the corresponding element of the pipeline array. The
1078 * counter in the element should never be greater than 1, otherwise, the
1079 * RCU implementation is broken.
1080 */
1081static void rcu_torture_timer(unsigned long unused)
1082{
1083 int idx;
Paul E. McKenney917963d2014-11-21 17:10:16 -08001084 unsigned long started;
Paul E. McKenney6b80da42014-11-21 14:19:26 -08001085 unsigned long completed;
Paul E. McKenney51b11302014-01-27 11:49:39 -08001086 static DEFINE_TORTURE_RANDOM(rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001087 static DEFINE_SPINLOCK(rand_lock);
1088 struct rcu_torture *p;
1089 int pipe_count;
Paul E. McKenney52494532012-11-14 16:26:40 -08001090 unsigned long long ts;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001091
1092 idx = cur_ops->readlock();
Paul E. McKenney917963d2014-11-21 17:10:16 -08001093 if (cur_ops->started)
1094 started = cur_ops->started();
1095 else
1096 started = cur_ops->completed();
Steven Rostedte4aa0da2013-02-04 13:36:13 -05001097 ts = rcu_trace_clock_local();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001098 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001099 rcu_read_lock_bh_held() ||
1100 rcu_read_lock_sched_held() ||
Paul E. McKenney5be5d1a2015-06-30 08:57:57 -07001101 srcu_read_lock_held(srcu_ctlp) ||
1102 torturing_tasks());
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001103 if (p == NULL) {
1104 /* Leave because rcu_torture_writer is not yet underway */
1105 cur_ops->readunlock(idx);
1106 return;
1107 }
1108 if (p->rtort_mbtest == 0)
1109 atomic_inc(&n_rcu_torture_mberror);
1110 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001111 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001112 n_rcu_torture_timers++;
1113 spin_unlock(&rand_lock);
1114 preempt_disable();
1115 pipe_count = p->rtort_pipe_count;
1116 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1117 /* Should not happen, but... */
1118 pipe_count = RCU_TORTURE_PIPE_LEN;
1119 }
Paul E. McKenney917963d2014-11-21 17:10:16 -08001120 completed = cur_ops->completed();
Paul E. McKenney52494532012-11-14 16:26:40 -08001121 if (pipe_count > 1) {
Paul E. McKenney52494532012-11-14 16:26:40 -08001122 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, ts,
Paul E. McKenney917963d2014-11-21 17:10:16 -08001123 started, completed);
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001124 rcutorture_trace_dump();
Paul E. McKenney52494532012-11-14 16:26:40 -08001125 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001126 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney917963d2014-11-21 17:10:16 -08001127 completed = completed - started;
1128 if (cur_ops->started)
1129 completed++;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001130 if (completed > RCU_TORTURE_PIPE_LEN) {
1131 /* Should not happen, but... */
1132 completed = RCU_TORTURE_PIPE_LEN;
1133 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001134 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001135 preempt_enable();
1136 cur_ops->readunlock(idx);
1137}
1138
1139/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001140 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
1141 * incrementing the corresponding element of the pipeline array. The
1142 * counter in the element should never be greater than 1, otherwise, the
1143 * RCU implementation is broken.
1144 */
1145static int
1146rcu_torture_reader(void *arg)
1147{
Paul E. McKenney917963d2014-11-21 17:10:16 -08001148 unsigned long started;
Paul E. McKenney6b80da42014-11-21 14:19:26 -08001149 unsigned long completed;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001150 int idx;
Paul E. McKenney51b11302014-01-27 11:49:39 -08001151 DEFINE_TORTURE_RANDOM(rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001152 struct rcu_torture *p;
1153 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001154 struct timer_list t;
Paul E. McKenney52494532012-11-14 16:26:40 -08001155 unsigned long long ts;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001156
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001157 VERBOSE_TOROUT_STRING("rcu_torture_reader task started");
Linus Torvalds971eae72014-03-31 11:21:19 -07001158 set_user_nice(current, MAX_NICE);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001159 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001160 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001161
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001162 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001163 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001164 if (!timer_pending(&t))
Paul E. McKenney6155fec2010-02-22 17:05:04 -08001165 mod_timer(&t, jiffies + 1);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001166 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001167 idx = cur_ops->readlock();
Paul E. McKenney917963d2014-11-21 17:10:16 -08001168 if (cur_ops->started)
1169 started = cur_ops->started();
1170 else
1171 started = cur_ops->completed();
Steven Rostedte4aa0da2013-02-04 13:36:13 -05001172 ts = rcu_trace_clock_local();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001173 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001174 rcu_read_lock_bh_held() ||
1175 rcu_read_lock_sched_held() ||
Paul E. McKenney5be5d1a2015-06-30 08:57:57 -07001176 srcu_read_lock_held(srcu_ctlp) ||
1177 torturing_tasks());
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001178 if (p == NULL) {
1179 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001180 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001181 schedule_timeout_interruptible(HZ);
1182 continue;
1183 }
Paul E. McKenney996417d2005-11-18 01:10:50 -08001184 if (p->rtort_mbtest == 0)
1185 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001186 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001187 preempt_disable();
1188 pipe_count = p->rtort_pipe_count;
1189 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1190 /* Should not happen, but... */
1191 pipe_count = RCU_TORTURE_PIPE_LEN;
1192 }
Paul E. McKenney917963d2014-11-21 17:10:16 -08001193 completed = cur_ops->completed();
Paul E. McKenney52494532012-11-14 16:26:40 -08001194 if (pipe_count > 1) {
Paul E. McKenney52494532012-11-14 16:26:40 -08001195 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu,
Paul E. McKenney917963d2014-11-21 17:10:16 -08001196 ts, started, completed);
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001197 rcutorture_trace_dump();
Paul E. McKenney52494532012-11-14 16:26:40 -08001198 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001199 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney917963d2014-11-21 17:10:16 -08001200 completed = completed - started;
1201 if (cur_ops->started)
1202 completed++;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001203 if (completed > RCU_TORTURE_PIPE_LEN) {
1204 /* Should not happen, but... */
1205 completed = RCU_TORTURE_PIPE_LEN;
1206 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001207 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001208 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001209 cur_ops->readunlock(idx);
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001210 stutter_wait("rcu_torture_reader");
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001211 } while (!torture_must_stop());
Thomas Gleixner424c1b62014-03-23 08:58:27 -07001212 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001213 del_timer_sync(&t);
Thomas Gleixner424c1b62014-03-23 08:58:27 -07001214 destroy_timer_on_stack(&t);
1215 }
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001216 torture_kthread_stopping("rcu_torture_reader");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001217 return 0;
1218}
1219
1220/*
Joe Percheseea203f2014-07-14 09:16:15 -04001221 * Print torture statistics. Caller must ensure that there is only
1222 * one call to this function at a given time!!! This is normally
1223 * accomplished by relying on the module system to only have one copy
1224 * of the module loaded, and then by giving the rcu_torture_stats
1225 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1226 * thread is not running).
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001227 */
Chen Gangd1008952013-11-07 10:30:25 +08001228static void
Joe Percheseea203f2014-07-14 09:16:15 -04001229rcu_torture_stats_print(void)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001230{
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001231 int cpu;
1232 int i;
1233 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1234 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001235 static unsigned long rtcv_snap = ULONG_MAX;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001236
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001237 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001238 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1239 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1240 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1241 }
1242 }
1243 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1244 if (pipesummary[i] != 0)
1245 break;
1246 }
Joe Percheseea203f2014-07-14 09:16:15 -04001247
1248 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
1249 pr_cont("rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
1250 rcu_torture_current,
1251 rcu_torture_current_version,
1252 list_empty(&rcu_torture_freelist),
1253 atomic_read(&n_rcu_torture_alloc),
1254 atomic_read(&n_rcu_torture_alloc_fail),
1255 atomic_read(&n_rcu_torture_free));
1256 pr_cont("rtmbe: %d rtbke: %ld rtbre: %ld ",
1257 atomic_read(&n_rcu_torture_mberror),
1258 n_rcu_torture_boost_ktrerror,
1259 n_rcu_torture_boost_rterror);
1260 pr_cont("rtbf: %ld rtb: %ld nt: %ld ",
1261 n_rcu_torture_boost_failure,
1262 n_rcu_torture_boosts,
1263 n_rcu_torture_timers);
1264 torture_onoff_stats();
Paul E. McKenney38706bc2014-08-18 21:12:17 -07001265 pr_cont("barrier: %ld/%ld:%ld ",
Joe Percheseea203f2014-07-14 09:16:15 -04001266 n_barrier_successes,
1267 n_barrier_attempts,
1268 n_rcu_torture_barrier_error);
Paul E. McKenney38706bc2014-08-18 21:12:17 -07001269 pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods));
Joe Percheseea203f2014-07-14 09:16:15 -04001270
1271 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001272 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001273 n_rcu_torture_barrier_error != 0 ||
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001274 n_rcu_torture_boost_ktrerror != 0 ||
1275 n_rcu_torture_boost_rterror != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001276 n_rcu_torture_boost_failure != 0 ||
1277 i > 1) {
Joe Percheseea203f2014-07-14 09:16:15 -04001278 pr_cont("%s", "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -08001279 atomic_inc(&n_rcu_torture_error);
Ingo Molnar5af970a2008-06-18 10:09:48 +02001280 WARN_ON_ONCE(1);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001281 }
Joe Percheseea203f2014-07-14 09:16:15 -04001282 pr_cont("Reader Pipe: ");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001283 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Joe Percheseea203f2014-07-14 09:16:15 -04001284 pr_cont(" %ld", pipesummary[i]);
1285 pr_cont("\n");
1286
1287 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
1288 pr_cont("Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001289 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Joe Percheseea203f2014-07-14 09:16:15 -04001290 pr_cont(" %ld", batchsummary[i]);
1291 pr_cont("\n");
1292
1293 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
1294 pr_cont("Free-Block Circulation: ");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001295 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
Joe Percheseea203f2014-07-14 09:16:15 -04001296 pr_cont(" %d", atomic_read(&rcu_torture_wcount[i]));
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001297 }
Joe Percheseea203f2014-07-14 09:16:15 -04001298 pr_cont("\n");
1299
Josh Triplettc8e5b162007-05-08 00:33:20 -07001300 if (cur_ops->stats)
Joe Percheseea203f2014-07-14 09:16:15 -04001301 cur_ops->stats();
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001302 if (rtcv_snap == rcu_torture_current_version &&
1303 rcu_torture_current != NULL) {
1304 int __maybe_unused flags;
1305 unsigned long __maybe_unused gpnum;
1306 unsigned long __maybe_unused completed;
1307
1308 rcutorture_get_gp_data(cur_ops->ttype,
1309 &flags, &gpnum, &completed);
Joe Percheseea203f2014-07-14 09:16:15 -04001310 pr_alert("??? Writer stall state %d g%lu c%lu f%#x\n",
1311 rcu_torture_writer_state,
1312 gpnum, completed, flags);
Paul E. McKenneyafea2272014-03-12 07:10:41 -07001313 show_rcu_gp_kthreads();
Paul E. McKenney945fa9c2014-03-07 14:15:28 -08001314 rcutorture_trace_dump();
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001315 }
1316 rtcv_snap = rcu_torture_current_version;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001317}
1318
1319/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001320 * Periodically prints torture statistics, if periodic statistics printing
1321 * was specified via the stat_interval module parameter.
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001322 */
1323static int
1324rcu_torture_stats(void *arg)
1325{
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001326 VERBOSE_TOROUT_STRING("rcu_torture_stats task started");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001327 do {
1328 schedule_timeout_interruptible(stat_interval * HZ);
1329 rcu_torture_stats_print();
Paul E. McKenneyf67a3352014-01-29 07:40:27 -08001330 torture_shutdown_absorb("rcu_torture_stats");
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001331 } while (!torture_must_stop());
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001332 torture_kthread_stopping("rcu_torture_stats");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001333 return 0;
1334}
1335
Paul E. McKenney95c38322006-03-24 03:15:58 -08001336static inline void
Steven Rostedt (Red Hat)e66c33d2013-07-12 16:50:28 -04001337rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag)
Paul E. McKenney95c38322006-03-24 03:15:58 -08001338{
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001339 pr_alert("%s" TORTURE_FLAG
1340 "--- %s: nreaders=%d nfakewriters=%d "
1341 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1342 "shuffle_interval=%d stutter=%d irqreader=%d "
1343 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1344 "test_boost=%d/%d test_boost_interval=%d "
1345 "test_boost_duration=%d shutdown_secs=%d "
Paul E. McKenney67afeed2012-10-20 12:56:06 -07001346 "stall_cpu=%d stall_cpu_holdoff=%d "
1347 "n_barrier_cbs=%d "
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001348 "onoff_interval=%d onoff_holdoff=%d\n",
1349 torture_type, tag, nrealreaders, nfakewriters,
1350 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
1351 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1352 test_boost, cur_ops->can_boost,
1353 test_boost_interval, test_boost_duration, shutdown_secs,
Paul E. McKenney67afeed2012-10-20 12:56:06 -07001354 stall_cpu, stall_cpu_holdoff,
1355 n_barrier_cbs,
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001356 onoff_interval, onoff_holdoff);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001357}
1358
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001359static void rcutorture_booster_cleanup(int cpu)
1360{
1361 struct task_struct *t;
1362
1363 if (boost_tasks[cpu] == NULL)
1364 return;
1365 mutex_lock(&boost_mutex);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001366 t = boost_tasks[cpu];
1367 boost_tasks[cpu] = NULL;
1368 mutex_unlock(&boost_mutex);
1369
1370 /* This must be outside of the mutex, otherwise deadlock! */
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001371 torture_stop_kthread(rcu_torture_boost, t);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001372}
1373
1374static int rcutorture_booster_init(int cpu)
1375{
1376 int retval;
1377
1378 if (boost_tasks[cpu] != NULL)
1379 return 0; /* Already created, nothing more to do. */
1380
1381 /* Don't allow time recalculation while creating a new task. */
1382 mutex_lock(&boost_mutex);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001383 VERBOSE_TOROUT_STRING("Creating rcu_torture_boost task");
Eric Dumazet1f288092011-06-16 15:53:18 -07001384 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1385 cpu_to_node(cpu),
1386 "rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001387 if (IS_ERR(boost_tasks[cpu])) {
1388 retval = PTR_ERR(boost_tasks[cpu]);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001389 VERBOSE_TOROUT_STRING("rcu_torture_boost task create failed");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001390 n_rcu_torture_boost_ktrerror++;
1391 boost_tasks[cpu] = NULL;
1392 mutex_unlock(&boost_mutex);
1393 return retval;
1394 }
1395 kthread_bind(boost_tasks[cpu], cpu);
1396 wake_up_process(boost_tasks[cpu]);
1397 mutex_unlock(&boost_mutex);
1398 return 0;
1399}
1400
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001401/*
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001402 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1403 * induces a CPU stall for the time specified by stall_cpu.
1404 */
Paul Gortmaker49fb4c62013-06-19 14:52:21 -04001405static int rcu_torture_stall(void *args)
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001406{
1407 unsigned long stop_at;
1408
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001409 VERBOSE_TOROUT_STRING("rcu_torture_stall task started");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001410 if (stall_cpu_holdoff > 0) {
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001411 VERBOSE_TOROUT_STRING("rcu_torture_stall begin holdoff");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001412 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001413 VERBOSE_TOROUT_STRING("rcu_torture_stall end holdoff");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001414 }
1415 if (!kthread_should_stop()) {
1416 stop_at = get_seconds() + stall_cpu;
1417 /* RCU CPU stall is expected behavior in following code. */
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001418 pr_alert("rcu_torture_stall start.\n");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001419 rcu_read_lock();
1420 preempt_disable();
1421 while (ULONG_CMP_LT(get_seconds(), stop_at))
1422 continue; /* Induce RCU CPU stall warning. */
1423 preempt_enable();
1424 rcu_read_unlock();
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001425 pr_alert("rcu_torture_stall end.\n");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001426 }
Paul E. McKenneyf67a3352014-01-29 07:40:27 -08001427 torture_shutdown_absorb("rcu_torture_stall");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001428 while (!kthread_should_stop())
1429 schedule_timeout_interruptible(10 * HZ);
1430 return 0;
1431}
1432
1433/* Spawn CPU-stall kthread, if stall_cpu specified. */
1434static int __init rcu_torture_stall_init(void)
1435{
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001436 if (stall_cpu <= 0)
1437 return 0;
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001438 return torture_create_kthread(rcu_torture_stall, NULL, stall_task);
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001439}
1440
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001441/* Callback function for RCU barrier testing. */
Rashika Kheriab3b8a4d2014-02-27 17:16:57 +05301442static void rcu_torture_barrier_cbf(struct rcu_head *rcu)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001443{
1444 atomic_inc(&barrier_cbs_invoked);
1445}
1446
1447/* kthread function to register callbacks used to test RCU barriers. */
1448static int rcu_torture_barrier_cbs(void *arg)
1449{
1450 long myid = (long)arg;
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001451 bool lastphase = 0;
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001452 bool newphase;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001453 struct rcu_head rcu;
1454
1455 init_rcu_head_on_stack(&rcu);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001456 VERBOSE_TOROUT_STRING("rcu_torture_barrier_cbs task started");
Linus Torvalds971eae72014-03-31 11:21:19 -07001457 set_user_nice(current, MAX_NICE);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001458 do {
1459 wait_event(barrier_cbs_wq[myid],
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001460 (newphase =
Paul E. McKenney6c7ed422015-04-13 11:58:08 -07001461 smp_load_acquire(&barrier_phase)) != lastphase ||
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001462 torture_must_stop());
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001463 lastphase = newphase;
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001464 if (torture_must_stop())
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001465 break;
Paul E. McKenney6c7ed422015-04-13 11:58:08 -07001466 /*
1467 * The above smp_load_acquire() ensures barrier_phase load
1468 * is ordered before the folloiwng ->call().
1469 */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001470 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1471 if (atomic_dec_and_test(&barrier_cbs_count))
1472 wake_up(&barrier_wq);
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001473 } while (!torture_must_stop());
Paul E. McKenney69c60452014-07-01 11:59:36 -07001474 if (cur_ops->cb_barrier != NULL)
1475 cur_ops->cb_barrier();
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001476 destroy_rcu_head_on_stack(&rcu);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001477 torture_kthread_stopping("rcu_torture_barrier_cbs");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001478 return 0;
1479}
1480
1481/* kthread function to drive and coordinate RCU barrier testing. */
1482static int rcu_torture_barrier(void *arg)
1483{
1484 int i;
1485
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001486 VERBOSE_TOROUT_STRING("rcu_torture_barrier task starting");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001487 do {
1488 atomic_set(&barrier_cbs_invoked, 0);
1489 atomic_set(&barrier_cbs_count, n_barrier_cbs);
Paul E. McKenney6c7ed422015-04-13 11:58:08 -07001490 /* Ensure barrier_phase ordered after prior assignments. */
1491 smp_store_release(&barrier_phase, !barrier_phase);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001492 for (i = 0; i < n_barrier_cbs; i++)
1493 wake_up(&barrier_cbs_wq[i]);
1494 wait_event(barrier_wq,
1495 atomic_read(&barrier_cbs_count) == 0 ||
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001496 torture_must_stop());
1497 if (torture_must_stop())
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001498 break;
1499 n_barrier_attempts++;
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001500 cur_ops->cb_barrier(); /* Implies smp_mb() for wait_event(). */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001501 if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
1502 n_rcu_torture_barrier_error++;
Paul E. McKenney7602de4a2014-12-17 18:39:54 -08001503 pr_err("barrier_cbs_invoked = %d, n_barrier_cbs = %d\n",
1504 atomic_read(&barrier_cbs_invoked),
1505 n_barrier_cbs);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001506 WARN_ON_ONCE(1);
1507 }
1508 n_barrier_successes++;
1509 schedule_timeout_interruptible(HZ / 10);
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001510 } while (!torture_must_stop());
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001511 torture_kthread_stopping("rcu_torture_barrier");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001512 return 0;
1513}
1514
1515/* Initialize RCU barrier testing. */
1516static int rcu_torture_barrier_init(void)
1517{
1518 int i;
1519 int ret;
1520
Paul E. McKenneyd9eba7682015-05-14 15:35:43 -07001521 if (n_barrier_cbs <= 0)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001522 return 0;
1523 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001524 pr_alert("%s" TORTURE_FLAG
1525 " Call or barrier ops missing for %s,\n",
1526 torture_type, cur_ops->name);
1527 pr_alert("%s" TORTURE_FLAG
1528 " RCU barrier testing omitted from run.\n",
1529 torture_type);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001530 return 0;
1531 }
1532 atomic_set(&barrier_cbs_count, 0);
1533 atomic_set(&barrier_cbs_invoked, 0);
1534 barrier_cbs_tasks =
1535 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
1536 GFP_KERNEL);
1537 barrier_cbs_wq =
1538 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
1539 GFP_KERNEL);
Sasha Levinde5e6432012-12-20 14:11:28 -05001540 if (barrier_cbs_tasks == NULL || !barrier_cbs_wq)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001541 return -ENOMEM;
1542 for (i = 0; i < n_barrier_cbs; i++) {
1543 init_waitqueue_head(&barrier_cbs_wq[i]);
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001544 ret = torture_create_kthread(rcu_torture_barrier_cbs,
1545 (void *)(long)i,
1546 barrier_cbs_tasks[i]);
1547 if (ret)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001548 return ret;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001549 }
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001550 return torture_create_kthread(rcu_torture_barrier, NULL, barrier_task);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001551}
1552
1553/* Clean up after RCU barrier testing. */
1554static void rcu_torture_barrier_cleanup(void)
1555{
1556 int i;
1557
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001558 torture_stop_kthread(rcu_torture_barrier, barrier_task);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001559 if (barrier_cbs_tasks != NULL) {
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001560 for (i = 0; i < n_barrier_cbs; i++)
1561 torture_stop_kthread(rcu_torture_barrier_cbs,
1562 barrier_cbs_tasks[i]);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001563 kfree(barrier_cbs_tasks);
1564 barrier_cbs_tasks = NULL;
1565 }
1566 if (barrier_cbs_wq != NULL) {
1567 kfree(barrier_cbs_wq);
1568 barrier_cbs_wq = NULL;
1569 }
1570}
1571
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001572static int rcutorture_cpu_notify(struct notifier_block *self,
1573 unsigned long action, void *hcpu)
1574{
1575 long cpu = (long)hcpu;
1576
1577 switch (action) {
1578 case CPU_ONLINE:
1579 case CPU_DOWN_FAILED:
1580 (void)rcutorture_booster_init(cpu);
1581 break;
1582 case CPU_DOWN_PREPARE:
1583 rcutorture_booster_cleanup(cpu);
1584 break;
1585 default:
1586 break;
1587 }
1588 return NOTIFY_OK;
1589}
1590
1591static struct notifier_block rcutorture_cpu_nb = {
1592 .notifier_call = rcutorture_cpu_notify,
1593};
1594
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001595static void
1596rcu_torture_cleanup(void)
1597{
1598 int i;
1599
Paul E. McKenney4a298652011-04-03 21:33:51 -07001600 rcutorture_record_test_transition();
Davidlohr Buesod36a7a02014-09-11 20:40:21 -07001601 if (torture_cleanup_begin()) {
Paul E. McKenney343e9092008-12-15 16:13:07 -08001602 if (cur_ops->cb_barrier != NULL)
1603 cur_ops->cb_barrier();
1604 return;
1605 }
Paul E. McKenney3808dc92014-01-28 15:29:21 -08001606
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001607 rcu_torture_barrier_cleanup();
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001608 torture_stop_kthread(rcu_torture_stall, stall_task);
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001609 torture_stop_kthread(rcu_torture_writer, writer_task);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001610
Josh Triplettc8e5b162007-05-08 00:33:20 -07001611 if (reader_tasks) {
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001612 for (i = 0; i < nrealreaders; i++)
1613 torture_stop_kthread(rcu_torture_reader,
1614 reader_tasks[i]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001615 kfree(reader_tasks);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001616 }
1617 rcu_torture_current = NULL;
1618
Josh Triplettc8e5b162007-05-08 00:33:20 -07001619 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001620 for (i = 0; i < nfakewriters; i++) {
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001621 torture_stop_kthread(rcu_torture_fakewriter,
1622 fakewriter_tasks[i]);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001623 }
1624 kfree(fakewriter_tasks);
1625 fakewriter_tasks = NULL;
1626 }
1627
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001628 torture_stop_kthread(rcu_torture_stats, stats_task);
1629 torture_stop_kthread(rcu_torture_fqs, fqs_task);
Paul E. McKenney38706bc2014-08-18 21:12:17 -07001630 for (i = 0; i < ncbflooders; i++)
1631 torture_stop_kthread(rcu_torture_cbflood, cbflood_task[i]);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001632 if ((test_boost == 1 && cur_ops->can_boost) ||
1633 test_boost == 2) {
1634 unregister_cpu_notifier(&rcutorture_cpu_nb);
1635 for_each_possible_cpu(i)
1636 rcutorture_booster_cleanup(i);
1637 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001638
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -07001639 /*
1640 * Wait for all RCU callbacks to fire, then do flavor-specific
1641 * cleanup operations.
1642 */
Paul E. McKenney23269742008-05-12 21:21:05 +02001643 if (cur_ops->cb_barrier != NULL)
1644 cur_ops->cb_barrier();
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -07001645 if (cur_ops->cleanup != NULL)
1646 cur_ops->cleanup();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001647
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001648 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001649
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001650 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001651 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
Paul E. McKenney2e9e8082014-01-28 15:58:22 -08001652 else if (torture_onoff_failures())
Paul E. McKenney091541b2012-01-10 12:51:14 -08001653 rcu_torture_print_module_parms(cur_ops,
1654 "End of test: RCU_HOTPLUG");
Paul E. McKenney95c38322006-03-24 03:15:58 -08001655 else
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001656 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
Davidlohr Buesod36a7a02014-09-11 20:40:21 -07001657 torture_cleanup_end();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001658}
1659
Paul E. McKenneyd2818df2013-04-23 17:05:42 -07001660#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1661static void rcu_torture_leak_cb(struct rcu_head *rhp)
1662{
1663}
1664
1665static void rcu_torture_err_cb(struct rcu_head *rhp)
1666{
1667 /*
1668 * This -might- happen due to race conditions, but is unlikely.
1669 * The scenario that leads to this happening is that the
1670 * first of the pair of duplicate callbacks is queued,
1671 * someone else starts a grace period that includes that
1672 * callback, then the second of the pair must wait for the
1673 * next grace period. Unlikely, but can happen. If it
1674 * does happen, the debug-objects subsystem won't have splatted.
1675 */
1676 pr_alert("rcutorture: duplicated callback was invoked.\n");
1677}
1678#endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1679
1680/*
1681 * Verify that double-free causes debug-objects to complain, but only
1682 * if CONFIG_DEBUG_OBJECTS_RCU_HEAD=y. Otherwise, say that the test
1683 * cannot be carried out.
1684 */
1685static void rcu_test_debug_objects(void)
1686{
1687#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1688 struct rcu_head rh1;
1689 struct rcu_head rh2;
1690
1691 init_rcu_head_on_stack(&rh1);
1692 init_rcu_head_on_stack(&rh2);
1693 pr_alert("rcutorture: WARN: Duplicate call_rcu() test starting.\n");
1694
1695 /* Try to queue the rh2 pair of callbacks for the same grace period. */
1696 preempt_disable(); /* Prevent preemption from interrupting test. */
1697 rcu_read_lock(); /* Make it impossible to finish a grace period. */
1698 call_rcu(&rh1, rcu_torture_leak_cb); /* Start grace period. */
1699 local_irq_disable(); /* Make it harder to start a new grace period. */
1700 call_rcu(&rh2, rcu_torture_leak_cb);
1701 call_rcu(&rh2, rcu_torture_err_cb); /* Duplicate callback. */
1702 local_irq_enable();
1703 rcu_read_unlock();
1704 preempt_enable();
1705
1706 /* Wait for them all to get done so we can safely return. */
1707 rcu_barrier();
1708 pr_alert("rcutorture: WARN: Duplicate call_rcu() test complete.\n");
1709 destroy_rcu_head_on_stack(&rh1);
1710 destroy_rcu_head_on_stack(&rh2);
1711#else /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1712 pr_alert("rcutorture: !CONFIG_DEBUG_OBJECTS_RCU_HEAD, not testing duplicate call_rcu()\n");
1713#endif /* #else #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1714}
1715
Josh Triplett6f8bc5002007-05-08 00:25:24 -07001716static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001717rcu_torture_init(void)
1718{
1719 int i;
1720 int cpu;
1721 int firsterr = 0;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001722 static struct rcu_torture_ops *torture_ops[] = {
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -07001723 &rcu_ops, &rcu_bh_ops, &rcu_busted_ops, &srcu_ops, &srcud_ops,
1724 &sched_ops, RCUTORTURE_TASKS_OPS
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001725 };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001726
Paul E. McKenney59da22a2014-09-12 10:36:15 -07001727 if (!torture_init_begin(torture_type, verbose, &torture_runnable))
Paul E. McKenney52280842014-04-07 09:14:11 -07001728 return -EBUSY;
Paul E. McKenney343e9092008-12-15 16:13:07 -08001729
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001730 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001731 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001732 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001733 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001734 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001735 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001736 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001737 pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
1738 torture_type);
1739 pr_alert("rcu-torture types:");
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001740 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001741 pr_alert(" %s", torture_ops[i]->name);
1742 pr_alert("\n");
Paul E. McKenney889d4872015-08-24 11:37:58 -07001743 firsterr = -EINVAL;
1744 goto unwind;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001745 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001746 if (cur_ops->fqs == NULL && fqs_duration != 0) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001747 pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001748 fqs_duration = 0;
1749 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001750 if (cur_ops->init)
Paul E. McKenney889d4872015-08-24 11:37:58 -07001751 cur_ops->init();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001752
Paul E. McKenney64e4b432014-03-12 10:26:35 -07001753 if (nreaders >= 0) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001754 nrealreaders = nreaders;
Paul E. McKenney64e4b432014-03-12 10:26:35 -07001755 } else {
Paul E. McKenney3838cc12015-03-12 13:55:48 -07001756 nrealreaders = num_online_cpus() - 2 - nreaders;
Paul E. McKenney64e4b432014-03-12 10:26:35 -07001757 if (nrealreaders <= 0)
1758 nrealreaders = 1;
1759 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001760 rcu_torture_print_module_parms(cur_ops, "Start of test");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001761
1762 /* Set up the freelist. */
1763
1764 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07001765 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08001766 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001767 list_add_tail(&rcu_tortures[i].rtort_free,
1768 &rcu_torture_freelist);
1769 }
1770
1771 /* Initialize the statistics so that each run gets its own numbers. */
1772
1773 rcu_torture_current = NULL;
1774 rcu_torture_current_version = 0;
1775 atomic_set(&n_rcu_torture_alloc, 0);
1776 atomic_set(&n_rcu_torture_alloc_fail, 0);
1777 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001778 atomic_set(&n_rcu_torture_mberror, 0);
1779 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001780 n_rcu_torture_barrier_error = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001781 n_rcu_torture_boost_ktrerror = 0;
1782 n_rcu_torture_boost_rterror = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001783 n_rcu_torture_boost_failure = 0;
1784 n_rcu_torture_boosts = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001785 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1786 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001787 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001788 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1789 per_cpu(rcu_torture_count, cpu)[i] = 0;
1790 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1791 }
1792 }
1793
1794 /* Start up the kthreads. */
1795
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001796 firsterr = torture_create_kthread(rcu_torture_writer, NULL,
1797 writer_task);
1798 if (firsterr)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001799 goto unwind;
Paul E. McKenney4444d852015-05-14 15:42:40 -07001800 if (nfakewriters > 0) {
1801 fakewriter_tasks = kzalloc(nfakewriters *
1802 sizeof(fakewriter_tasks[0]),
1803 GFP_KERNEL);
1804 if (fakewriter_tasks == NULL) {
1805 VERBOSE_TOROUT_ERRSTRING("out of memory");
1806 firsterr = -ENOMEM;
1807 goto unwind;
1808 }
Josh Triplettb772e1d2006-10-04 02:17:13 -07001809 }
1810 for (i = 0; i < nfakewriters; i++) {
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001811 firsterr = torture_create_kthread(rcu_torture_fakewriter,
1812 NULL, fakewriter_tasks[i]);
1813 if (firsterr)
Josh Triplettb772e1d2006-10-04 02:17:13 -07001814 goto unwind;
Josh Triplettb772e1d2006-10-04 02:17:13 -07001815 }
Josh Triplett2860aab2006-10-04 02:17:11 -07001816 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001817 GFP_KERNEL);
1818 if (reader_tasks == NULL) {
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001819 VERBOSE_TOROUT_ERRSTRING("out of memory");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001820 firsterr = -ENOMEM;
1821 goto unwind;
1822 }
1823 for (i = 0; i < nrealreaders; i++) {
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001824 firsterr = torture_create_kthread(rcu_torture_reader, NULL,
1825 reader_tasks[i]);
1826 if (firsterr)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001827 goto unwind;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001828 }
1829 if (stat_interval > 0) {
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001830 firsterr = torture_create_kthread(rcu_torture_stats, NULL,
1831 stats_task);
1832 if (firsterr)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001833 goto unwind;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001834 }
Paul E. McKenneye8e255f2015-05-14 16:55:45 -07001835 if (test_no_idle_hz && shuffle_interval > 0) {
Paul E. McKenney3808dc92014-01-28 15:29:21 -08001836 firsterr = torture_shuffle_init(shuffle_interval * HZ);
1837 if (firsterr)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001838 goto unwind;
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001839 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001840 if (stutter < 0)
1841 stutter = 0;
1842 if (stutter) {
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001843 firsterr = torture_stutter_init(stutter * HZ);
1844 if (firsterr)
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001845 goto unwind;
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001846 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001847 if (fqs_duration < 0)
1848 fqs_duration = 0;
1849 if (fqs_duration) {
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001850 /* Create the fqs thread */
Paul E. McKenneyd0d06062014-03-17 20:56:45 -07001851 firsterr = torture_create_kthread(rcu_torture_fqs, NULL,
1852 fqs_task);
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001853 if (firsterr)
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001854 goto unwind;
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001855 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001856 if (test_boost_interval < 1)
1857 test_boost_interval = 1;
1858 if (test_boost_duration < 2)
1859 test_boost_duration = 2;
1860 if ((test_boost == 1 && cur_ops->can_boost) ||
1861 test_boost == 2) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001862
1863 boost_starttime = jiffies + test_boost_interval * HZ;
1864 register_cpu_notifier(&rcutorture_cpu_nb);
1865 for_each_possible_cpu(i) {
1866 if (cpu_is_offline(i))
1867 continue; /* Heuristic: CPU can go offline. */
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001868 firsterr = rcutorture_booster_init(i);
1869 if (firsterr)
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001870 goto unwind;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001871 }
1872 }
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001873 firsterr = torture_shutdown_init(shutdown_secs, rcu_torture_cleanup);
1874 if (firsterr)
Paul E. McKenneye991dbc2014-01-31 14:52:13 -08001875 goto unwind;
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001876 firsterr = torture_onoff_init(onoff_holdoff * HZ, onoff_interval * HZ);
1877 if (firsterr)
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001878 goto unwind;
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001879 firsterr = rcu_torture_stall_init();
1880 if (firsterr)
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001881 goto unwind;
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001882 firsterr = rcu_torture_barrier_init();
1883 if (firsterr)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001884 goto unwind;
Paul E. McKenneyd2818df2013-04-23 17:05:42 -07001885 if (object_debug)
1886 rcu_test_debug_objects();
Paul E. McKenney38706bc2014-08-18 21:12:17 -07001887 if (cbflood_n_burst > 0) {
1888 /* Create the cbflood threads */
1889 ncbflooders = (num_online_cpus() + 3) / 4;
1890 cbflood_task = kcalloc(ncbflooders, sizeof(*cbflood_task),
1891 GFP_KERNEL);
1892 if (!cbflood_task) {
1893 VERBOSE_TOROUT_ERRSTRING("out of memory");
1894 firsterr = -ENOMEM;
1895 goto unwind;
1896 }
1897 for (i = 0; i < ncbflooders; i++) {
1898 firsterr = torture_create_kthread(rcu_torture_cbflood,
1899 NULL,
1900 cbflood_task[i]);
1901 if (firsterr)
1902 goto unwind;
1903 }
1904 }
Paul E. McKenney4a298652011-04-03 21:33:51 -07001905 rcutorture_record_test_transition();
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -08001906 torture_init_end();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001907 return 0;
1908
1909unwind:
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -08001910 torture_init_end();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001911 rcu_torture_cleanup();
1912 return firsterr;
1913}
1914
1915module_init(rcu_torture_init);
1916module_exit(rcu_torture_cleanup);