blob: 9234e75b106aea6268ca15d4a60331c70267e018 [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);
Peter Zijlstra25528212016-03-15 14:52:49 -0700133static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) = { 0 };
134static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) = { 0 };
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800135static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700136static atomic_t n_rcu_torture_alloc;
137static atomic_t n_rcu_torture_alloc_fail;
138static atomic_t n_rcu_torture_free;
139static atomic_t n_rcu_torture_mberror;
140static atomic_t n_rcu_torture_error;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800141static long n_rcu_torture_barrier_error;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700142static long n_rcu_torture_boost_ktrerror;
143static long n_rcu_torture_boost_rterror;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700144static long n_rcu_torture_boost_failure;
145static long n_rcu_torture_boosts;
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700146static long n_rcu_torture_timers;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800147static long n_barrier_attempts;
148static long n_barrier_successes;
Paul E. McKenney38706bc2014-08-18 21:12:17 -0700149static atomic_long_t n_cbfloods;
Josh Triplette3033732006-10-04 02:17:14 -0700150static struct list_head rcu_torture_removed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800151
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800152static int rcu_torture_writer_state;
153#define RTWS_FIXED_DELAY 0
154#define RTWS_DELAY 1
155#define RTWS_REPLACE 2
156#define RTWS_DEF_FREE 3
157#define RTWS_EXP_SYNC 4
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700158#define RTWS_COND_GET 5
159#define RTWS_COND_SYNC 6
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700160#define RTWS_SYNC 7
161#define RTWS_STUTTER 8
162#define RTWS_STOPPING 9
Paul E. McKenney18aff332015-11-17 13:35:28 -0800163static const char * const rcu_torture_writer_state_names[] = {
164 "RTWS_FIXED_DELAY",
165 "RTWS_DELAY",
166 "RTWS_REPLACE",
167 "RTWS_DEF_FREE",
168 "RTWS_EXP_SYNC",
169 "RTWS_COND_GET",
170 "RTWS_COND_SYNC",
171 "RTWS_SYNC",
172 "RTWS_STUTTER",
173 "RTWS_STOPPING",
174};
175
176static const char *rcu_torture_writer_state_getname(void)
177{
178 unsigned int i = READ_ONCE(rcu_torture_writer_state);
179
180 if (i >= ARRAY_SIZE(rcu_torture_writer_state_names))
181 return "???";
182 return rcu_torture_writer_state_names[i];
183}
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800184
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700185#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
186#define RCUTORTURE_RUNNABLE_INIT 1
187#else
188#define RCUTORTURE_RUNNABLE_INIT 0
189#endif
Paul E. McKenney59da22a2014-09-12 10:36:15 -0700190static int torture_runnable = RCUTORTURE_RUNNABLE_INIT;
191module_param(torture_runnable, int, 0444);
192MODULE_PARM_DESC(torture_runnable, "Start rcutorture at boot");
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700193
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700194#if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700195#define rcu_can_boost() 1
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700196#else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700197#define rcu_can_boost() 0
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700198#endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700199
Steven Rostedte4aa0da2013-02-04 13:36:13 -0500200#ifdef CONFIG_RCU_TRACE
201static u64 notrace rcu_trace_clock_local(void)
202{
203 u64 ts = trace_clock_local();
204 unsigned long __maybe_unused ts_rem = do_div(ts, NSEC_PER_USEC);
205 return ts;
206}
207#else /* #ifdef CONFIG_RCU_TRACE */
208static u64 notrace rcu_trace_clock_local(void)
209{
210 return 0ULL;
211}
212#endif /* #else #ifdef CONFIG_RCU_TRACE */
213
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700214static unsigned long boost_starttime; /* jiffies of next boost test start. */
Pranith Kumar58ade2d2014-06-11 16:39:43 -0400215static DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700216 /* and boost task create/destroy. */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800217static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -0700218static bool barrier_phase; /* Test phase. */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800219static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */
220static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */
221static DECLARE_WAIT_QUEUE_HEAD(barrier_wq);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700222
Paul E. McKenney343e9092008-12-15 16:13:07 -0800223/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800224 * Allocate an element from the rcu_tortures pool.
225 */
Adrian Bunk97a41e22006-01-08 01:02:17 -0800226static struct rcu_torture *
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800227rcu_torture_alloc(void)
228{
229 struct list_head *p;
230
Ingo Molnaradac1662006-01-25 19:50:12 +0100231 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800232 if (list_empty(&rcu_torture_freelist)) {
233 atomic_inc(&n_rcu_torture_alloc_fail);
Ingo Molnaradac1662006-01-25 19:50:12 +0100234 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800235 return NULL;
236 }
237 atomic_inc(&n_rcu_torture_alloc);
238 p = rcu_torture_freelist.next;
239 list_del_init(p);
Ingo Molnaradac1662006-01-25 19:50:12 +0100240 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800241 return container_of(p, struct rcu_torture, rtort_free);
242}
243
244/*
245 * Free an element to the rcu_tortures pool.
246 */
247static void
248rcu_torture_free(struct rcu_torture *p)
249{
250 atomic_inc(&n_rcu_torture_free);
Ingo Molnaradac1662006-01-25 19:50:12 +0100251 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800252 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
Ingo Molnaradac1662006-01-25 19:50:12 +0100253 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800254}
255
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800256/*
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700257 * Operations vector for selecting different types of tests.
258 */
259
260struct rcu_torture_ops {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800261 int ttype;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700262 void (*init)(void);
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700263 void (*cleanup)(void);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700264 int (*readlock)(void);
Paul E. McKenney51b11302014-01-27 11:49:39 -0800265 void (*read_delay)(struct torture_random_state *rrsp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700266 void (*readunlock)(int idx);
Paul E. McKenney917963d2014-11-21 17:10:16 -0800267 unsigned long (*started)(void);
Paul E. McKenney6b80da42014-11-21 14:19:26 -0800268 unsigned long (*completed)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700269 void (*deferred_free)(struct rcu_torture *p);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700270 void (*sync)(void);
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700271 void (*exp_sync)(void);
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700272 unsigned long (*get_state)(void);
273 void (*cond_sync)(unsigned long oldstate);
Boqun Fengdb3e8db2015-07-29 13:29:39 +0800274 call_rcu_func_t call;
Paul E. McKenney23269742008-05-12 21:21:05 +0200275 void (*cb_barrier)(void);
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800276 void (*fqs)(void);
Joe Percheseea203f2014-07-14 09:16:15 -0400277 void (*stats)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700278 int irq_capable;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700279 int can_boost;
Steven Rostedt (Red Hat)e66c33d2013-07-12 16:50:28 -0400280 const char *name;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700281};
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700282
283static struct rcu_torture_ops *cur_ops;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700284
285/*
286 * Definitions for rcu torture testing.
287 */
288
Josh Tripletta49a4af2006-09-29 01:59:30 -0700289static int rcu_torture_read_lock(void) __acquires(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700290{
291 rcu_read_lock();
292 return 0;
293}
294
Paul E. McKenney51b11302014-01-27 11:49:39 -0800295static void rcu_read_delay(struct torture_random_state *rrsp)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700296{
Josh Triplettb8d57a72009-09-08 15:54:35 -0700297 const unsigned long shortdelay_us = 200;
298 const unsigned long longdelay_ms = 50;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700299
Josh Triplettb8d57a72009-09-08 15:54:35 -0700300 /* We want a short delay sometimes to make a reader delay the grace
301 * period, and we want a long delay occasionally to trigger
302 * force_quiescent_state. */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700303
Paul E. McKenney51b11302014-01-27 11:49:39 -0800304 if (!(torture_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
Josh Triplettb8d57a72009-09-08 15:54:35 -0700305 mdelay(longdelay_ms);
Paul E. McKenney51b11302014-01-27 11:49:39 -0800306 if (!(torture_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
Josh Triplettb8d57a72009-09-08 15:54:35 -0700307 udelay(shortdelay_us);
Lai Jiangshane546f482010-06-21 16:57:42 +0800308#ifdef CONFIG_PREEMPT
Paul E. McKenney51b11302014-01-27 11:49:39 -0800309 if (!preempt_count() &&
310 !(torture_random(rrsp) % (nrealreaders * 20000)))
Lai Jiangshane546f482010-06-21 16:57:42 +0800311 preempt_schedule(); /* No QS if preempt_disable() in effect */
312#endif
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700313}
314
Josh Tripletta49a4af2006-09-29 01:59:30 -0700315static void rcu_torture_read_unlock(int idx) __releases(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700316{
317 rcu_read_unlock();
318}
319
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700320/*
321 * Update callback in the pipe. This should be invoked after a grace period.
322 */
323static bool
324rcu_torture_pipe_update_one(struct rcu_torture *rp)
325{
326 int i;
327
328 i = rp->rtort_pipe_count;
329 if (i > RCU_TORTURE_PIPE_LEN)
330 i = RCU_TORTURE_PIPE_LEN;
331 atomic_inc(&rcu_torture_wcount[i]);
332 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
333 rp->rtort_mbtest = 0;
334 return true;
335 }
336 return false;
337}
338
339/*
340 * Update all callbacks in the pipe. Suitable for synchronous grace-period
341 * primitives.
342 */
343static void
344rcu_torture_pipe_update(struct rcu_torture *old_rp)
345{
346 struct rcu_torture *rp;
347 struct rcu_torture *rp1;
348
349 if (old_rp)
350 list_add(&old_rp->rtort_free, &rcu_torture_removed);
351 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
352 if (rcu_torture_pipe_update_one(rp)) {
353 list_del(&rp->rtort_free);
354 rcu_torture_free(rp);
355 }
356 }
357}
358
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700359static void
360rcu_torture_cb(struct rcu_head *p)
361{
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700362 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
363
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800364 if (torture_must_stop_irq()) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700365 /* Test is ending, just drop callbacks on the floor. */
366 /* The next initialization will pick up the pieces. */
367 return;
368 }
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700369 if (rcu_torture_pipe_update_one(rp))
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700370 rcu_torture_free(rp);
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700371 else
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700372 cur_ops->deferred_free(rp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700373}
374
Paul E. McKenney6b80da42014-11-21 14:19:26 -0800375static unsigned long rcu_no_completed(void)
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800376{
377 return 0;
378}
379
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700380static void rcu_torture_deferred_free(struct rcu_torture *p)
381{
382 call_rcu(&p->rtort_rcu, rcu_torture_cb);
383}
384
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700385static void rcu_sync_torture_init(void)
386{
387 INIT_LIST_HEAD(&rcu_torture_removed);
388}
389
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700390static struct rcu_torture_ops rcu_ops = {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800391 .ttype = RCU_FLAVOR,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700392 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700393 .readlock = rcu_torture_read_lock,
394 .read_delay = rcu_read_delay,
395 .readunlock = rcu_torture_read_unlock,
Paul E. McKenney917963d2014-11-21 17:10:16 -0800396 .started = rcu_batches_started,
Paul E. McKenney1e32eae2014-11-21 16:04:34 -0800397 .completed = rcu_batches_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700398 .deferred_free = rcu_torture_deferred_free,
399 .sync = synchronize_rcu,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700400 .exp_sync = synchronize_rcu_expedited,
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700401 .get_state = get_state_synchronize_rcu,
402 .cond_sync = cond_synchronize_rcu,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800403 .call = call_rcu,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700404 .cb_barrier = rcu_barrier,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800405 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700406 .stats = NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700407 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700408 .can_boost = rcu_can_boost(),
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700409 .name = "rcu"
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700410};
411
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700412/*
413 * Definitions for rcu_bh torture testing.
414 */
415
Josh Tripletta49a4af2006-09-29 01:59:30 -0700416static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700417{
418 rcu_read_lock_bh();
419 return 0;
420}
421
Josh Tripletta49a4af2006-09-29 01:59:30 -0700422static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700423{
424 rcu_read_unlock_bh();
425}
426
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700427static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
428{
429 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
430}
431
432static struct rcu_torture_ops rcu_bh_ops = {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800433 .ttype = RCU_BH_FLAVOR,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700434 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700435 .readlock = rcu_bh_torture_read_lock,
436 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
437 .readunlock = rcu_bh_torture_read_unlock,
Paul E. McKenney917963d2014-11-21 17:10:16 -0800438 .started = rcu_batches_started_bh,
Paul E. McKenney1e32eae2014-11-21 16:04:34 -0800439 .completed = rcu_batches_completed_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700440 .deferred_free = rcu_bh_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700441 .sync = synchronize_rcu_bh,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700442 .exp_sync = synchronize_rcu_bh_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800443 .call = call_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700444 .cb_barrier = rcu_barrier_bh,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800445 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700446 .stats = NULL,
447 .irq_capable = 1,
448 .name = "rcu_bh"
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700449};
450
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700451/*
Paul E. McKenneyff20e252014-02-06 08:45:56 -0800452 * Don't even think about trying any of these in real life!!!
453 * The names includes "busted", and they really means it!
454 * The only purpose of these functions is to provide a buggy RCU
455 * implementation to make sure that rcutorture correctly emits
456 * buggy-RCU error messages.
457 */
458static void rcu_busted_torture_deferred_free(struct rcu_torture *p)
459{
460 /* This is a deliberate bug for testing purposes only! */
461 rcu_torture_cb(&p->rtort_rcu);
462}
463
464static void synchronize_rcu_busted(void)
465{
466 /* This is a deliberate bug for testing purposes only! */
467}
468
469static void
Boqun Fengb6a4ae72015-07-29 13:29:38 +0800470call_rcu_busted(struct rcu_head *head, rcu_callback_t func)
Paul E. McKenneyff20e252014-02-06 08:45:56 -0800471{
472 /* This is a deliberate bug for testing purposes only! */
473 func(head);
474}
475
476static struct rcu_torture_ops rcu_busted_ops = {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800477 .ttype = INVALID_RCU_FLAVOR,
Paul E. McKenneyff20e252014-02-06 08:45:56 -0800478 .init = rcu_sync_torture_init,
479 .readlock = rcu_torture_read_lock,
480 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
481 .readunlock = rcu_torture_read_unlock,
Paul E. McKenney917963d2014-11-21 17:10:16 -0800482 .started = rcu_no_completed,
Paul E. McKenneyff20e252014-02-06 08:45:56 -0800483 .completed = rcu_no_completed,
484 .deferred_free = rcu_busted_torture_deferred_free,
485 .sync = synchronize_rcu_busted,
486 .exp_sync = synchronize_rcu_busted,
487 .call = call_rcu_busted,
488 .cb_barrier = NULL,
489 .fqs = NULL,
490 .stats = NULL,
491 .irq_capable = 1,
492 .name = "rcu_busted"
493};
494
495/*
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700496 * Definitions for srcu torture testing.
497 */
498
Lai Jiangshancda4dc82012-10-13 01:14:17 +0800499DEFINE_STATIC_SRCU(srcu_ctl);
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700500static struct srcu_struct srcu_ctld;
501static struct srcu_struct *srcu_ctlp = &srcu_ctl;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700502
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700503static int srcu_torture_read_lock(void) __acquires(srcu_ctlp)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700504{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700505 return srcu_read_lock(srcu_ctlp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700506}
507
Paul E. McKenney51b11302014-01-27 11:49:39 -0800508static void srcu_read_delay(struct torture_random_state *rrsp)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700509{
510 long delay;
511 const long uspertick = 1000000 / HZ;
512 const long longdelay = 10;
513
514 /* We want there to be long-running readers, but not all the time. */
515
Paul E. McKenney51b11302014-01-27 11:49:39 -0800516 delay = torture_random(rrsp) %
517 (nrealreaders * 2 * longdelay * uspertick);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700518 if (!delay)
519 schedule_timeout_interruptible(longdelay);
Lai Jiangshane546f482010-06-21 16:57:42 +0800520 else
521 rcu_read_delay(rrsp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700522}
523
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700524static void srcu_torture_read_unlock(int idx) __releases(srcu_ctlp)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700525{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700526 srcu_read_unlock(srcu_ctlp, idx);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700527}
528
Paul E. McKenney6b80da42014-11-21 14:19:26 -0800529static unsigned long srcu_torture_completed(void)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700530{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700531 return srcu_batches_completed(srcu_ctlp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700532}
533
Lai Jiangshan9059c942012-03-19 16:12:14 +0800534static void srcu_torture_deferred_free(struct rcu_torture *rp)
535{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700536 call_srcu(srcu_ctlp, &rp->rtort_rcu, rcu_torture_cb);
Lai Jiangshan9059c942012-03-19 16:12:14 +0800537}
538
Josh Triplettb772e1d2006-10-04 02:17:13 -0700539static void srcu_torture_synchronize(void)
540{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700541 synchronize_srcu(srcu_ctlp);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700542}
543
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700544static void srcu_torture_call(struct rcu_head *head,
Boqun Fengb6a4ae72015-07-29 13:29:38 +0800545 rcu_callback_t func)
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700546{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700547 call_srcu(srcu_ctlp, head, func);
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700548}
549
550static void srcu_torture_barrier(void)
551{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700552 srcu_barrier(srcu_ctlp);
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700553}
554
Joe Percheseea203f2014-07-14 09:16:15 -0400555static void srcu_torture_stats(void)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700556{
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700557 int cpu;
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700558 int idx = srcu_ctlp->completed & 0x1;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700559
Joe Percheseea203f2014-07-14 09:16:15 -0400560 pr_alert("%s%s per-CPU(idx=%d):",
561 torture_type, TORTURE_FLAG, idx);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700562 for_each_possible_cpu(cpu) {
Paul E. McKenney589a8f52014-03-03 16:51:08 -0800563 long c0, c1;
564
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700565 c0 = (long)per_cpu_ptr(srcu_ctlp->per_cpu_ref, cpu)->c[!idx];
566 c1 = (long)per_cpu_ptr(srcu_ctlp->per_cpu_ref, cpu)->c[idx];
Joe Percheseea203f2014-07-14 09:16:15 -0400567 pr_cont(" %d(%ld,%ld)", cpu, c0, c1);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700568 }
Joe Percheseea203f2014-07-14 09:16:15 -0400569 pr_cont("\n");
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700570}
571
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700572static void srcu_torture_synchronize_expedited(void)
573{
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700574 synchronize_srcu_expedited(srcu_ctlp);
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700575}
576
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700577static struct rcu_torture_ops srcu_ops = {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800578 .ttype = SRCU_FLAVOR,
Lai Jiangshancda4dc82012-10-13 01:14:17 +0800579 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700580 .readlock = srcu_torture_read_lock,
581 .read_delay = srcu_read_delay,
582 .readunlock = srcu_torture_read_unlock,
Paul E. McKenney917963d2014-11-21 17:10:16 -0800583 .started = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700584 .completed = srcu_torture_completed,
Lai Jiangshan9059c942012-03-19 16:12:14 +0800585 .deferred_free = srcu_torture_deferred_free,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700586 .sync = srcu_torture_synchronize,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700587 .exp_sync = srcu_torture_synchronize_expedited,
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700588 .call = srcu_torture_call,
589 .cb_barrier = srcu_torture_barrier,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700590 .stats = srcu_torture_stats,
591 .name = "srcu"
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700592};
593
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -0700594static void srcu_torture_init(void)
595{
596 rcu_sync_torture_init();
597 WARN_ON(init_srcu_struct(&srcu_ctld));
598 srcu_ctlp = &srcu_ctld;
599}
600
601static void srcu_torture_cleanup(void)
602{
603 cleanup_srcu_struct(&srcu_ctld);
604 srcu_ctlp = &srcu_ctl; /* In case of a later rcutorture run. */
605}
606
607/* As above, but dynamically allocated. */
608static struct rcu_torture_ops srcud_ops = {
609 .ttype = SRCU_FLAVOR,
610 .init = srcu_torture_init,
611 .cleanup = srcu_torture_cleanup,
612 .readlock = srcu_torture_read_lock,
613 .read_delay = srcu_read_delay,
614 .readunlock = srcu_torture_read_unlock,
615 .started = NULL,
616 .completed = srcu_torture_completed,
617 .deferred_free = srcu_torture_deferred_free,
618 .sync = srcu_torture_synchronize,
619 .exp_sync = srcu_torture_synchronize_expedited,
620 .call = srcu_torture_call,
621 .cb_barrier = srcu_torture_barrier,
622 .stats = srcu_torture_stats,
623 .name = "srcud"
624};
625
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700626/*
627 * Definitions for sched torture testing.
628 */
629
630static int sched_torture_read_lock(void)
631{
632 preempt_disable();
633 return 0;
634}
635
636static void sched_torture_read_unlock(int idx)
637{
638 preempt_enable();
639}
640
Paul E. McKenney23269742008-05-12 21:21:05 +0200641static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
642{
643 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
644}
645
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700646static struct rcu_torture_ops sched_ops = {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800647 .ttype = RCU_SCHED_FLAVOR,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700648 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700649 .readlock = sched_torture_read_lock,
650 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
651 .readunlock = sched_torture_read_unlock,
Paul E. McKenney917963d2014-11-21 17:10:16 -0800652 .started = rcu_batches_started_sched,
Paul E. McKenney1e32eae2014-11-21 16:04:34 -0800653 .completed = rcu_batches_completed_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700654 .deferred_free = rcu_sched_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700655 .sync = synchronize_sched,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700656 .exp_sync = synchronize_sched_expedited,
Paul E. McKenney24560052015-05-30 10:11:24 -0700657 .get_state = get_state_synchronize_sched,
658 .cond_sync = cond_synchronize_sched,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700659 .call = call_rcu_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700660 .cb_barrier = rcu_barrier_sched,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800661 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700662 .stats = NULL,
663 .irq_capable = 1,
664 .name = "sched"
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700665};
666
Paul E. McKenney69c60452014-07-01 11:59:36 -0700667#ifdef CONFIG_TASKS_RCU
668
669/*
670 * Definitions for RCU-tasks torture testing.
671 */
672
673static int tasks_torture_read_lock(void)
674{
675 return 0;
676}
677
678static void tasks_torture_read_unlock(int idx)
679{
680}
681
682static void rcu_tasks_torture_deferred_free(struct rcu_torture *p)
683{
684 call_rcu_tasks(&p->rtort_rcu, rcu_torture_cb);
685}
686
687static struct rcu_torture_ops tasks_ops = {
688 .ttype = RCU_TASKS_FLAVOR,
689 .init = rcu_sync_torture_init,
690 .readlock = tasks_torture_read_lock,
691 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
692 .readunlock = tasks_torture_read_unlock,
Paul E. McKenney917963d2014-11-21 17:10:16 -0800693 .started = rcu_no_completed,
Paul E. McKenney69c60452014-07-01 11:59:36 -0700694 .completed = rcu_no_completed,
695 .deferred_free = rcu_tasks_torture_deferred_free,
696 .sync = synchronize_rcu_tasks,
697 .exp_sync = synchronize_rcu_tasks,
698 .call = call_rcu_tasks,
699 .cb_barrier = rcu_barrier_tasks,
700 .fqs = NULL,
701 .stats = NULL,
702 .irq_capable = 1,
703 .name = "tasks"
704};
705
706#define RCUTORTURE_TASKS_OPS &tasks_ops,
707
Paul E. McKenney5be5d1a2015-06-30 08:57:57 -0700708static bool __maybe_unused torturing_tasks(void)
709{
710 return cur_ops == &tasks_ops;
711}
712
Paul E. McKenney69c60452014-07-01 11:59:36 -0700713#else /* #ifdef CONFIG_TASKS_RCU */
714
715#define RCUTORTURE_TASKS_OPS
716
Paul E. McKenney4f441a22015-08-24 13:13:51 -0700717static bool __maybe_unused torturing_tasks(void)
Paul E. McKenney5be5d1a2015-06-30 08:57:57 -0700718{
719 return false;
720}
721
Paul E. McKenney69c60452014-07-01 11:59:36 -0700722#endif /* #else #ifdef CONFIG_TASKS_RCU */
723
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700724/*
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700725 * RCU torture priority-boost testing. Runs one real-time thread per
726 * CPU for moderate bursts, repeatedly registering RCU callbacks and
727 * spinning waiting for them to be invoked. If a given callback takes
728 * too long to be invoked, we assume that priority inversion has occurred.
729 */
730
731struct rcu_boost_inflight {
732 struct rcu_head rcu;
733 int inflight;
734};
735
736static void rcu_torture_boost_cb(struct rcu_head *head)
737{
738 struct rcu_boost_inflight *rbip =
739 container_of(head, struct rcu_boost_inflight, rcu);
740
Paul E. McKenney6c7ed422015-04-13 11:58:08 -0700741 /* Ensure RCU-core accesses precede clearing ->inflight */
742 smp_store_release(&rbip->inflight, 0);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700743}
744
745static int rcu_torture_boost(void *arg)
746{
747 unsigned long call_rcu_time;
748 unsigned long endtime;
749 unsigned long oldstarttime;
750 struct rcu_boost_inflight rbi = { .inflight = 0 };
751 struct sched_param sp;
752
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800753 VERBOSE_TOROUT_STRING("rcu_torture_boost started");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700754
755 /* Set real-time priority. */
756 sp.sched_priority = 1;
757 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800758 VERBOSE_TOROUT_STRING("rcu_torture_boost RT prio failed!");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700759 n_rcu_torture_boost_rterror++;
760 }
761
Paul E. McKenney561190e2011-03-30 09:10:44 -0700762 init_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700763 /* Each pass through the following loop does one boost-test cycle. */
764 do {
765 /* Wait for the next test interval. */
766 oldstarttime = boost_starttime;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700767 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
Paul E. McKenney0e11c8e2013-01-10 16:21:07 -0800768 schedule_timeout_interruptible(oldstarttime - jiffies);
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800769 stutter_wait("rcu_torture_boost");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800770 if (torture_must_stop())
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700771 goto checkwait;
772 }
773
774 /* Do one boost-test interval. */
775 endtime = oldstarttime + test_boost_duration * HZ;
776 call_rcu_time = jiffies;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700777 while (ULONG_CMP_LT(jiffies, endtime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700778 /* If we don't have a callback in flight, post one. */
Paul E. McKenney6c7ed422015-04-13 11:58:08 -0700779 if (!smp_load_acquire(&rbi.inflight)) {
780 /* RCU core before ->inflight = 1. */
781 smp_store_release(&rbi.inflight, 1);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700782 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
783 if (jiffies - call_rcu_time >
784 test_boost_duration * HZ - HZ / 2) {
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800785 VERBOSE_TOROUT_STRING("rcu_torture_boost boosting failed");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700786 n_rcu_torture_boost_failure++;
787 }
788 call_rcu_time = jiffies;
789 }
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800790 stutter_wait("rcu_torture_boost");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800791 if (torture_must_stop())
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700792 goto checkwait;
793 }
794
795 /*
796 * Set the start time of the next test interval.
797 * Yes, this is vulnerable to long delays, but such
798 * delays simply cause a false negative for the next
799 * interval. Besides, we are running at RT priority,
800 * so delays should be relatively rare.
801 */
Paul E. McKenneyab8f11e2011-08-18 09:30:32 -0700802 while (oldstarttime == boost_starttime &&
803 !kthread_should_stop()) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700804 if (mutex_trylock(&boost_mutex)) {
805 boost_starttime = jiffies +
806 test_boost_interval * HZ;
807 n_rcu_torture_boosts++;
808 mutex_unlock(&boost_mutex);
809 break;
810 }
811 schedule_timeout_uninterruptible(1);
812 }
813
814 /* Go do the stutter. */
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800815checkwait: stutter_wait("rcu_torture_boost");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800816 } while (!torture_must_stop());
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700817
818 /* Clean up and exit. */
Paul E. McKenney6c7ed422015-04-13 11:58:08 -0700819 while (!kthread_should_stop() || smp_load_acquire(&rbi.inflight)) {
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800820 torture_shutdown_absorb("rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700821 schedule_timeout_uninterruptible(1);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800822 }
Paul E. McKenney9d681972011-06-21 01:48:03 -0700823 destroy_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800824 torture_kthread_stopping("rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700825 return 0;
826}
827
Paul E. McKenney38706bc2014-08-18 21:12:17 -0700828static void rcu_torture_cbflood_cb(struct rcu_head *rhp)
829{
830}
831
832/*
833 * RCU torture callback-flood kthread. Repeatedly induces bursts of calls
834 * to call_rcu() or analogous, increasing the probability of occurrence
835 * of callback-overflow corner cases.
836 */
837static int
838rcu_torture_cbflood(void *arg)
839{
840 int err = 1;
841 int i;
842 int j;
843 struct rcu_head *rhp;
844
845 if (cbflood_n_per_burst > 0 &&
846 cbflood_inter_holdoff > 0 &&
847 cbflood_intra_holdoff > 0 &&
848 cur_ops->call &&
849 cur_ops->cb_barrier) {
850 rhp = vmalloc(sizeof(*rhp) *
851 cbflood_n_burst * cbflood_n_per_burst);
852 err = !rhp;
853 }
854 if (err) {
855 VERBOSE_TOROUT_STRING("rcu_torture_cbflood disabled: Bad args or OOM");
Paul E. McKenney3a0af332015-06-22 18:11:31 -0700856 goto wait_for_stop;
Paul E. McKenney38706bc2014-08-18 21:12:17 -0700857 }
858 VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started");
859 do {
860 schedule_timeout_interruptible(cbflood_inter_holdoff);
861 atomic_long_inc(&n_cbfloods);
862 WARN_ON(signal_pending(current));
863 for (i = 0; i < cbflood_n_burst; i++) {
864 for (j = 0; j < cbflood_n_per_burst; j++) {
865 cur_ops->call(&rhp[i * cbflood_n_per_burst + j],
866 rcu_torture_cbflood_cb);
867 }
868 schedule_timeout_interruptible(cbflood_intra_holdoff);
869 WARN_ON(signal_pending(current));
870 }
871 cur_ops->cb_barrier();
872 stutter_wait("rcu_torture_cbflood");
873 } while (!torture_must_stop());
Paul E. McKenneyb8969d12014-10-27 15:52:04 -0700874 vfree(rhp);
Paul E. McKenney3a0af332015-06-22 18:11:31 -0700875wait_for_stop:
Paul E. McKenney38706bc2014-08-18 21:12:17 -0700876 torture_kthread_stopping("rcu_torture_cbflood");
877 return 0;
878}
879
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700880/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800881 * RCU torture force-quiescent-state kthread. Repeatedly induces
882 * bursts of calls to force_quiescent_state(), increasing the probability
883 * of occurrence of some important types of race conditions.
884 */
885static int
886rcu_torture_fqs(void *arg)
887{
888 unsigned long fqs_resume_time;
889 int fqs_burst_remaining;
890
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800891 VERBOSE_TOROUT_STRING("rcu_torture_fqs task started");
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800892 do {
893 fqs_resume_time = jiffies + fqs_stutter * HZ;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700894 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
895 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800896 schedule_timeout_interruptible(1);
897 }
898 fqs_burst_remaining = fqs_duration;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700899 while (fqs_burst_remaining > 0 &&
900 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800901 cur_ops->fqs();
902 udelay(fqs_holdoff);
903 fqs_burst_remaining -= fqs_holdoff;
904 }
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800905 stutter_wait("rcu_torture_fqs");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800906 } while (!torture_must_stop());
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800907 torture_kthread_stopping("rcu_torture_fqs");
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800908 return 0;
909}
910
911/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800912 * RCU torture writer kthread. Repeatedly substitutes a new structure
913 * for that pointed to by rcu_torture_current, freeing the old structure
914 * after a series of grace periods (the "pipeline").
915 */
916static int
917rcu_torture_writer(void *arg)
918{
Paul E. McKenney9efafb82015-12-31 18:11:47 -0800919 bool can_expedite = !rcu_gp_is_expedited() && !rcu_gp_is_normal();
Paul E. McKenney4bb3c5f2015-02-18 16:31:29 -0800920 int expediting = 0;
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700921 unsigned long gp_snap;
922 bool gp_cond1 = gp_cond, gp_exp1 = gp_exp, gp_normal1 = gp_normal;
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700923 bool gp_sync1 = gp_sync;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800924 int i;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800925 struct rcu_torture *rp;
926 struct rcu_torture *old_rp;
Paul E. McKenney51b11302014-01-27 11:49:39 -0800927 static DEFINE_TORTURE_RANDOM(rand);
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700928 int synctype[] = { RTWS_DEF_FREE, RTWS_EXP_SYNC,
929 RTWS_COND_GET, RTWS_SYNC };
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700930 int nsynctypes = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800931
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800932 VERBOSE_TOROUT_STRING("rcu_torture_writer task started");
Paul E. McKenneyaa5a8982015-12-31 16:27:06 -0800933 if (!can_expedite) {
934 pr_alert("%s" TORTURE_FLAG
Paul E. McKenney9efafb82015-12-31 18:11:47 -0800935 " GP expediting controlled from boot/sysfs for %s,\n",
Paul E. McKenneyaa5a8982015-12-31 16:27:06 -0800936 torture_type, cur_ops->name);
937 pr_alert("%s" TORTURE_FLAG
938 " Disabled dynamic grace-period expediting.\n",
939 torture_type);
940 }
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800941
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700942 /* Initialize synctype[] array. If none set, take default. */
Paul E. McKenneyc136f992015-02-19 12:15:19 -0800943 if (!gp_cond1 && !gp_exp1 && !gp_normal1 && !gp_sync1)
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700944 gp_cond1 = gp_exp1 = gp_normal1 = gp_sync1 = true;
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700945 if (gp_cond1 && cur_ops->get_state && cur_ops->cond_sync)
946 synctype[nsynctypes++] = RTWS_COND_GET;
947 else if (gp_cond && (!cur_ops->get_state || !cur_ops->cond_sync))
948 pr_alert("rcu_torture_writer: gp_cond without primitives.\n");
949 if (gp_exp1 && cur_ops->exp_sync)
950 synctype[nsynctypes++] = RTWS_EXP_SYNC;
951 else if (gp_exp && !cur_ops->exp_sync)
952 pr_alert("rcu_torture_writer: gp_exp without primitives.\n");
953 if (gp_normal1 && cur_ops->deferred_free)
954 synctype[nsynctypes++] = RTWS_DEF_FREE;
955 else if (gp_normal && !cur_ops->deferred_free)
956 pr_alert("rcu_torture_writer: gp_normal without primitives.\n");
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700957 if (gp_sync1 && cur_ops->sync)
958 synctype[nsynctypes++] = RTWS_SYNC;
959 else if (gp_sync && !cur_ops->sync)
960 pr_alert("rcu_torture_writer: gp_sync without primitives.\n");
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700961 if (WARN_ONCE(nsynctypes == 0,
962 "rcu_torture_writer: No update-side primitives.\n")) {
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -0700963 /*
964 * No updates primitives, so don't try updating.
965 * The resulting test won't be testing much, hence the
966 * above WARN_ONCE().
967 */
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700968 rcu_torture_writer_state = RTWS_STOPPING;
969 torture_kthread_stopping("rcu_torture_writer");
970 }
971
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800972 do {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800973 rcu_torture_writer_state = RTWS_FIXED_DELAY;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800974 schedule_timeout_uninterruptible(1);
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700975 rp = rcu_torture_alloc();
976 if (rp == NULL)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800977 continue;
978 rp->rtort_pipe_count = 0;
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800979 rcu_torture_writer_state = RTWS_DELAY;
Paul E. McKenney51b11302014-01-27 11:49:39 -0800980 udelay(torture_random(&rand) & 0x3ff);
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800981 rcu_torture_writer_state = RTWS_REPLACE;
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700982 old_rp = rcu_dereference_check(rcu_torture_current,
983 current == writer_task);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800984 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800985 rcu_assign_pointer(rcu_torture_current, rp);
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700986 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
Josh Triplettc8e5b162007-05-08 00:33:20 -0700987 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800988 i = old_rp->rtort_pipe_count;
989 if (i > RCU_TORTURE_PIPE_LEN)
990 i = RCU_TORTURE_PIPE_LEN;
991 atomic_inc(&rcu_torture_wcount[i]);
992 old_rp->rtort_pipe_count++;
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700993 switch (synctype[torture_random(&rand) % nsynctypes]) {
994 case RTWS_DEF_FREE:
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800995 rcu_torture_writer_state = RTWS_DEF_FREE;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700996 cur_ops->deferred_free(old_rp);
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -0700997 break;
998 case RTWS_EXP_SYNC:
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800999 rcu_torture_writer_state = RTWS_EXP_SYNC;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001000 cur_ops->exp_sync();
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -07001001 rcu_torture_pipe_update(old_rp);
1002 break;
1003 case RTWS_COND_GET:
1004 rcu_torture_writer_state = RTWS_COND_GET;
1005 gp_snap = cur_ops->get_state();
1006 i = torture_random(&rand) % 16;
1007 if (i != 0)
1008 schedule_timeout_interruptible(i);
1009 udelay(torture_random(&rand) % 1000);
1010 rcu_torture_writer_state = RTWS_COND_SYNC;
1011 cur_ops->cond_sync(gp_snap);
1012 rcu_torture_pipe_update(old_rp);
1013 break;
Paul E. McKenneyf0bf8fa2014-03-21 16:17:56 -07001014 case RTWS_SYNC:
1015 rcu_torture_writer_state = RTWS_SYNC;
1016 cur_ops->sync();
1017 rcu_torture_pipe_update(old_rp);
1018 break;
Paul E. McKenneya48f3fa2014-03-18 15:57:41 -07001019 default:
1020 WARN_ON_ONCE(1);
1021 break;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001022 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001023 }
Paul E. McKenney4a298652011-04-03 21:33:51 -07001024 rcutorture_record_progress(++rcu_torture_current_version);
Paul E. McKenney4bb3c5f2015-02-18 16:31:29 -08001025 /* Cycle through nesting levels of rcu_expedite_gp() calls. */
1026 if (can_expedite &&
1027 !(torture_random(&rand) & 0xff & (!!expediting - 1))) {
1028 WARN_ON_ONCE(expediting == 0 && rcu_gp_is_expedited());
1029 if (expediting >= 0)
1030 rcu_expedite_gp();
1031 else
1032 rcu_unexpedite_gp();
1033 if (++expediting > 3)
1034 expediting = -expediting;
1035 }
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001036 rcu_torture_writer_state = RTWS_STUTTER;
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001037 stutter_wait("rcu_torture_writer");
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001038 } while (!torture_must_stop());
Paul E. McKenney4bb3c5f2015-02-18 16:31:29 -08001039 /* Reset expediting back to unexpedited. */
1040 if (expediting > 0)
1041 expediting = -expediting;
1042 while (can_expedite && expediting++ < 0)
1043 rcu_unexpedite_gp();
1044 WARN_ON_ONCE(can_expedite && rcu_gp_is_expedited());
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001045 rcu_torture_writer_state = RTWS_STOPPING;
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001046 torture_kthread_stopping("rcu_torture_writer");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001047 return 0;
1048}
1049
1050/*
Josh Triplettb772e1d2006-10-04 02:17:13 -07001051 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
1052 * delay between calls.
1053 */
1054static int
1055rcu_torture_fakewriter(void *arg)
1056{
Paul E. McKenney51b11302014-01-27 11:49:39 -08001057 DEFINE_TORTURE_RANDOM(rand);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001058
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001059 VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task started");
Linus Torvalds971eae72014-03-31 11:21:19 -07001060 set_user_nice(current, MAX_NICE);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001061
1062 do {
Paul E. McKenney51b11302014-01-27 11:49:39 -08001063 schedule_timeout_uninterruptible(1 + torture_random(&rand)%10);
1064 udelay(torture_random(&rand) & 0x3ff);
Paul E. McKenney72472a02012-05-29 17:50:51 -07001065 if (cur_ops->cb_barrier != NULL &&
Paul E. McKenney51b11302014-01-27 11:49:39 -08001066 torture_random(&rand) % (nfakewriters * 8) == 0) {
Paul E. McKenney72472a02012-05-29 17:50:51 -07001067 cur_ops->cb_barrier();
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001068 } else if (gp_normal == gp_exp) {
Paul E. McKenney51b11302014-01-27 11:49:39 -08001069 if (torture_random(&rand) & 0x80)
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001070 cur_ops->sync();
1071 else
1072 cur_ops->exp_sync();
1073 } else if (gp_normal) {
Paul E. McKenney72472a02012-05-29 17:50:51 -07001074 cur_ops->sync();
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001075 } else {
1076 cur_ops->exp_sync();
1077 }
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001078 stutter_wait("rcu_torture_fakewriter");
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001079 } while (!torture_must_stop());
Josh Triplettb772e1d2006-10-04 02:17:13 -07001080
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001081 torture_kthread_stopping("rcu_torture_fakewriter");
Josh Triplettb772e1d2006-10-04 02:17:13 -07001082 return 0;
1083}
1084
1085/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001086 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
1087 * incrementing the corresponding element of the pipeline array. The
1088 * counter in the element should never be greater than 1, otherwise, the
1089 * RCU implementation is broken.
1090 */
1091static void rcu_torture_timer(unsigned long unused)
1092{
1093 int idx;
Paul E. McKenney917963d2014-11-21 17:10:16 -08001094 unsigned long started;
Paul E. McKenney6b80da42014-11-21 14:19:26 -08001095 unsigned long completed;
Paul E. McKenney51b11302014-01-27 11:49:39 -08001096 static DEFINE_TORTURE_RANDOM(rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001097 static DEFINE_SPINLOCK(rand_lock);
1098 struct rcu_torture *p;
1099 int pipe_count;
Paul E. McKenney52494532012-11-14 16:26:40 -08001100 unsigned long long ts;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001101
1102 idx = cur_ops->readlock();
Paul E. McKenney917963d2014-11-21 17:10:16 -08001103 if (cur_ops->started)
1104 started = cur_ops->started();
1105 else
1106 started = cur_ops->completed();
Steven Rostedte4aa0da2013-02-04 13:36:13 -05001107 ts = rcu_trace_clock_local();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001108 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001109 rcu_read_lock_bh_held() ||
1110 rcu_read_lock_sched_held() ||
Paul E. McKenney5be5d1a2015-06-30 08:57:57 -07001111 srcu_read_lock_held(srcu_ctlp) ||
1112 torturing_tasks());
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001113 if (p == NULL) {
1114 /* Leave because rcu_torture_writer is not yet underway */
1115 cur_ops->readunlock(idx);
1116 return;
1117 }
1118 if (p->rtort_mbtest == 0)
1119 atomic_inc(&n_rcu_torture_mberror);
1120 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001121 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001122 n_rcu_torture_timers++;
1123 spin_unlock(&rand_lock);
1124 preempt_disable();
1125 pipe_count = p->rtort_pipe_count;
1126 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1127 /* Should not happen, but... */
1128 pipe_count = RCU_TORTURE_PIPE_LEN;
1129 }
Paul E. McKenney917963d2014-11-21 17:10:16 -08001130 completed = cur_ops->completed();
Paul E. McKenney52494532012-11-14 16:26:40 -08001131 if (pipe_count > 1) {
Paul E. McKenney52494532012-11-14 16:26:40 -08001132 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, ts,
Paul E. McKenney917963d2014-11-21 17:10:16 -08001133 started, completed);
Paul E. McKenney274529b2016-03-21 19:46:04 -07001134 rcu_ftrace_dump(DUMP_ALL);
Paul E. McKenney52494532012-11-14 16:26:40 -08001135 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001136 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney917963d2014-11-21 17:10:16 -08001137 completed = completed - started;
1138 if (cur_ops->started)
1139 completed++;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001140 if (completed > RCU_TORTURE_PIPE_LEN) {
1141 /* Should not happen, but... */
1142 completed = RCU_TORTURE_PIPE_LEN;
1143 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001144 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001145 preempt_enable();
1146 cur_ops->readunlock(idx);
1147}
1148
1149/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001150 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
1151 * incrementing the corresponding element of the pipeline array. The
1152 * counter in the element should never be greater than 1, otherwise, the
1153 * RCU implementation is broken.
1154 */
1155static int
1156rcu_torture_reader(void *arg)
1157{
Paul E. McKenney917963d2014-11-21 17:10:16 -08001158 unsigned long started;
Paul E. McKenney6b80da42014-11-21 14:19:26 -08001159 unsigned long completed;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001160 int idx;
Paul E. McKenney51b11302014-01-27 11:49:39 -08001161 DEFINE_TORTURE_RANDOM(rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001162 struct rcu_torture *p;
1163 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001164 struct timer_list t;
Paul E. McKenney52494532012-11-14 16:26:40 -08001165 unsigned long long ts;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001166
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001167 VERBOSE_TOROUT_STRING("rcu_torture_reader task started");
Linus Torvalds971eae72014-03-31 11:21:19 -07001168 set_user_nice(current, MAX_NICE);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001169 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001170 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001171
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001172 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001173 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001174 if (!timer_pending(&t))
Paul E. McKenney6155fec2010-02-22 17:05:04 -08001175 mod_timer(&t, jiffies + 1);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001176 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001177 idx = cur_ops->readlock();
Paul E. McKenney917963d2014-11-21 17:10:16 -08001178 if (cur_ops->started)
1179 started = cur_ops->started();
1180 else
1181 started = cur_ops->completed();
Steven Rostedte4aa0da2013-02-04 13:36:13 -05001182 ts = rcu_trace_clock_local();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001183 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001184 rcu_read_lock_bh_held() ||
1185 rcu_read_lock_sched_held() ||
Paul E. McKenney5be5d1a2015-06-30 08:57:57 -07001186 srcu_read_lock_held(srcu_ctlp) ||
1187 torturing_tasks());
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001188 if (p == NULL) {
1189 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001190 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001191 schedule_timeout_interruptible(HZ);
1192 continue;
1193 }
Paul E. McKenney996417d2005-11-18 01:10:50 -08001194 if (p->rtort_mbtest == 0)
1195 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001196 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001197 preempt_disable();
1198 pipe_count = p->rtort_pipe_count;
1199 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1200 /* Should not happen, but... */
1201 pipe_count = RCU_TORTURE_PIPE_LEN;
1202 }
Paul E. McKenney917963d2014-11-21 17:10:16 -08001203 completed = cur_ops->completed();
Paul E. McKenney52494532012-11-14 16:26:40 -08001204 if (pipe_count > 1) {
Paul E. McKenney52494532012-11-14 16:26:40 -08001205 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu,
Paul E. McKenney917963d2014-11-21 17:10:16 -08001206 ts, started, completed);
Paul E. McKenney274529b2016-03-21 19:46:04 -07001207 rcu_ftrace_dump(DUMP_ALL);
Paul E. McKenney52494532012-11-14 16:26:40 -08001208 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001209 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney917963d2014-11-21 17:10:16 -08001210 completed = completed - started;
1211 if (cur_ops->started)
1212 completed++;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001213 if (completed > RCU_TORTURE_PIPE_LEN) {
1214 /* Should not happen, but... */
1215 completed = RCU_TORTURE_PIPE_LEN;
1216 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001217 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001218 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001219 cur_ops->readunlock(idx);
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001220 stutter_wait("rcu_torture_reader");
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001221 } while (!torture_must_stop());
Thomas Gleixner424c1b62014-03-23 08:58:27 -07001222 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001223 del_timer_sync(&t);
Thomas Gleixner424c1b62014-03-23 08:58:27 -07001224 destroy_timer_on_stack(&t);
1225 }
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001226 torture_kthread_stopping("rcu_torture_reader");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001227 return 0;
1228}
1229
1230/*
Joe Percheseea203f2014-07-14 09:16:15 -04001231 * Print torture statistics. Caller must ensure that there is only
1232 * one call to this function at a given time!!! This is normally
1233 * accomplished by relying on the module system to only have one copy
1234 * of the module loaded, and then by giving the rcu_torture_stats
1235 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1236 * thread is not running).
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001237 */
Chen Gangd1008952013-11-07 10:30:25 +08001238static void
Joe Percheseea203f2014-07-14 09:16:15 -04001239rcu_torture_stats_print(void)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001240{
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001241 int cpu;
1242 int i;
1243 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1244 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001245 static unsigned long rtcv_snap = ULONG_MAX;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001246
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001247 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001248 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1249 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1250 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1251 }
1252 }
1253 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1254 if (pipesummary[i] != 0)
1255 break;
1256 }
Joe Percheseea203f2014-07-14 09:16:15 -04001257
1258 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
1259 pr_cont("rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
1260 rcu_torture_current,
1261 rcu_torture_current_version,
1262 list_empty(&rcu_torture_freelist),
1263 atomic_read(&n_rcu_torture_alloc),
1264 atomic_read(&n_rcu_torture_alloc_fail),
1265 atomic_read(&n_rcu_torture_free));
1266 pr_cont("rtmbe: %d rtbke: %ld rtbre: %ld ",
1267 atomic_read(&n_rcu_torture_mberror),
1268 n_rcu_torture_boost_ktrerror,
1269 n_rcu_torture_boost_rterror);
1270 pr_cont("rtbf: %ld rtb: %ld nt: %ld ",
1271 n_rcu_torture_boost_failure,
1272 n_rcu_torture_boosts,
1273 n_rcu_torture_timers);
1274 torture_onoff_stats();
Paul E. McKenney38706bc2014-08-18 21:12:17 -07001275 pr_cont("barrier: %ld/%ld:%ld ",
Joe Percheseea203f2014-07-14 09:16:15 -04001276 n_barrier_successes,
1277 n_barrier_attempts,
1278 n_rcu_torture_barrier_error);
Paul E. McKenney38706bc2014-08-18 21:12:17 -07001279 pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods));
Joe Percheseea203f2014-07-14 09:16:15 -04001280
1281 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001282 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001283 n_rcu_torture_barrier_error != 0 ||
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001284 n_rcu_torture_boost_ktrerror != 0 ||
1285 n_rcu_torture_boost_rterror != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001286 n_rcu_torture_boost_failure != 0 ||
1287 i > 1) {
Joe Percheseea203f2014-07-14 09:16:15 -04001288 pr_cont("%s", "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -08001289 atomic_inc(&n_rcu_torture_error);
Ingo Molnar5af970a2008-06-18 10:09:48 +02001290 WARN_ON_ONCE(1);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001291 }
Joe Percheseea203f2014-07-14 09:16:15 -04001292 pr_cont("Reader Pipe: ");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001293 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Joe Percheseea203f2014-07-14 09:16:15 -04001294 pr_cont(" %ld", pipesummary[i]);
1295 pr_cont("\n");
1296
1297 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
1298 pr_cont("Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001299 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Joe Percheseea203f2014-07-14 09:16:15 -04001300 pr_cont(" %ld", batchsummary[i]);
1301 pr_cont("\n");
1302
1303 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
1304 pr_cont("Free-Block Circulation: ");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001305 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
Joe Percheseea203f2014-07-14 09:16:15 -04001306 pr_cont(" %d", atomic_read(&rcu_torture_wcount[i]));
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001307 }
Joe Percheseea203f2014-07-14 09:16:15 -04001308 pr_cont("\n");
1309
Josh Triplettc8e5b162007-05-08 00:33:20 -07001310 if (cur_ops->stats)
Joe Percheseea203f2014-07-14 09:16:15 -04001311 cur_ops->stats();
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001312 if (rtcv_snap == rcu_torture_current_version &&
1313 rcu_torture_current != NULL) {
1314 int __maybe_unused flags;
1315 unsigned long __maybe_unused gpnum;
1316 unsigned long __maybe_unused completed;
1317
1318 rcutorture_get_gp_data(cur_ops->ttype,
1319 &flags, &gpnum, &completed);
Paul E. McKenney18aff332015-11-17 13:35:28 -08001320 pr_alert("??? Writer stall state %s(%d) g%lu c%lu f%#x\n",
1321 rcu_torture_writer_state_getname(),
Joe Percheseea203f2014-07-14 09:16:15 -04001322 rcu_torture_writer_state,
1323 gpnum, completed, flags);
Paul E. McKenneyafea2272014-03-12 07:10:41 -07001324 show_rcu_gp_kthreads();
Paul E. McKenney274529b2016-03-21 19:46:04 -07001325 rcu_ftrace_dump(DUMP_ALL);
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001326 }
1327 rtcv_snap = rcu_torture_current_version;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001328}
1329
1330/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001331 * Periodically prints torture statistics, if periodic statistics printing
1332 * was specified via the stat_interval module parameter.
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001333 */
1334static int
1335rcu_torture_stats(void *arg)
1336{
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001337 VERBOSE_TOROUT_STRING("rcu_torture_stats task started");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001338 do {
1339 schedule_timeout_interruptible(stat_interval * HZ);
1340 rcu_torture_stats_print();
Paul E. McKenneyf67a3352014-01-29 07:40:27 -08001341 torture_shutdown_absorb("rcu_torture_stats");
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001342 } while (!torture_must_stop());
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001343 torture_kthread_stopping("rcu_torture_stats");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001344 return 0;
1345}
1346
Paul E. McKenney95c38322006-03-24 03:15:58 -08001347static inline void
Steven Rostedt (Red Hat)e66c33d2013-07-12 16:50:28 -04001348rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag)
Paul E. McKenney95c38322006-03-24 03:15:58 -08001349{
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001350 pr_alert("%s" TORTURE_FLAG
1351 "--- %s: nreaders=%d nfakewriters=%d "
1352 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1353 "shuffle_interval=%d stutter=%d irqreader=%d "
1354 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1355 "test_boost=%d/%d test_boost_interval=%d "
1356 "test_boost_duration=%d shutdown_secs=%d "
Paul E. McKenney67afeed2012-10-20 12:56:06 -07001357 "stall_cpu=%d stall_cpu_holdoff=%d "
1358 "n_barrier_cbs=%d "
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001359 "onoff_interval=%d onoff_holdoff=%d\n",
1360 torture_type, tag, nrealreaders, nfakewriters,
1361 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
1362 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1363 test_boost, cur_ops->can_boost,
1364 test_boost_interval, test_boost_duration, shutdown_secs,
Paul E. McKenney67afeed2012-10-20 12:56:06 -07001365 stall_cpu, stall_cpu_holdoff,
1366 n_barrier_cbs,
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001367 onoff_interval, onoff_holdoff);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001368}
1369
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001370static void rcutorture_booster_cleanup(int cpu)
1371{
1372 struct task_struct *t;
1373
1374 if (boost_tasks[cpu] == NULL)
1375 return;
1376 mutex_lock(&boost_mutex);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001377 t = boost_tasks[cpu];
1378 boost_tasks[cpu] = NULL;
1379 mutex_unlock(&boost_mutex);
1380
1381 /* This must be outside of the mutex, otherwise deadlock! */
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001382 torture_stop_kthread(rcu_torture_boost, t);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001383}
1384
1385static int rcutorture_booster_init(int cpu)
1386{
1387 int retval;
1388
1389 if (boost_tasks[cpu] != NULL)
1390 return 0; /* Already created, nothing more to do. */
1391
1392 /* Don't allow time recalculation while creating a new task. */
1393 mutex_lock(&boost_mutex);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001394 VERBOSE_TOROUT_STRING("Creating rcu_torture_boost task");
Eric Dumazet1f288092011-06-16 15:53:18 -07001395 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1396 cpu_to_node(cpu),
1397 "rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001398 if (IS_ERR(boost_tasks[cpu])) {
1399 retval = PTR_ERR(boost_tasks[cpu]);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001400 VERBOSE_TOROUT_STRING("rcu_torture_boost task create failed");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001401 n_rcu_torture_boost_ktrerror++;
1402 boost_tasks[cpu] = NULL;
1403 mutex_unlock(&boost_mutex);
1404 return retval;
1405 }
1406 kthread_bind(boost_tasks[cpu], cpu);
1407 wake_up_process(boost_tasks[cpu]);
1408 mutex_unlock(&boost_mutex);
1409 return 0;
1410}
1411
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001412/*
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001413 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1414 * induces a CPU stall for the time specified by stall_cpu.
1415 */
Paul Gortmaker49fb4c62013-06-19 14:52:21 -04001416static int rcu_torture_stall(void *args)
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001417{
1418 unsigned long stop_at;
1419
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001420 VERBOSE_TOROUT_STRING("rcu_torture_stall task started");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001421 if (stall_cpu_holdoff > 0) {
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001422 VERBOSE_TOROUT_STRING("rcu_torture_stall begin holdoff");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001423 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001424 VERBOSE_TOROUT_STRING("rcu_torture_stall end holdoff");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001425 }
1426 if (!kthread_should_stop()) {
1427 stop_at = get_seconds() + stall_cpu;
1428 /* RCU CPU stall is expected behavior in following code. */
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001429 pr_alert("rcu_torture_stall start.\n");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001430 rcu_read_lock();
1431 preempt_disable();
1432 while (ULONG_CMP_LT(get_seconds(), stop_at))
1433 continue; /* Induce RCU CPU stall warning. */
1434 preempt_enable();
1435 rcu_read_unlock();
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001436 pr_alert("rcu_torture_stall end.\n");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001437 }
Paul E. McKenneyf67a3352014-01-29 07:40:27 -08001438 torture_shutdown_absorb("rcu_torture_stall");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001439 while (!kthread_should_stop())
1440 schedule_timeout_interruptible(10 * HZ);
1441 return 0;
1442}
1443
1444/* Spawn CPU-stall kthread, if stall_cpu specified. */
1445static int __init rcu_torture_stall_init(void)
1446{
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001447 if (stall_cpu <= 0)
1448 return 0;
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001449 return torture_create_kthread(rcu_torture_stall, NULL, stall_task);
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001450}
1451
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001452/* Callback function for RCU barrier testing. */
Rashika Kheriab3b8a4d2014-02-27 17:16:57 +05301453static void rcu_torture_barrier_cbf(struct rcu_head *rcu)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001454{
1455 atomic_inc(&barrier_cbs_invoked);
1456}
1457
1458/* kthread function to register callbacks used to test RCU barriers. */
1459static int rcu_torture_barrier_cbs(void *arg)
1460{
1461 long myid = (long)arg;
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001462 bool lastphase = 0;
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001463 bool newphase;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001464 struct rcu_head rcu;
1465
1466 init_rcu_head_on_stack(&rcu);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001467 VERBOSE_TOROUT_STRING("rcu_torture_barrier_cbs task started");
Linus Torvalds971eae72014-03-31 11:21:19 -07001468 set_user_nice(current, MAX_NICE);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001469 do {
1470 wait_event(barrier_cbs_wq[myid],
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001471 (newphase =
Paul E. McKenney6c7ed422015-04-13 11:58:08 -07001472 smp_load_acquire(&barrier_phase)) != lastphase ||
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001473 torture_must_stop());
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001474 lastphase = newphase;
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001475 if (torture_must_stop())
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001476 break;
Paul E. McKenney6c7ed422015-04-13 11:58:08 -07001477 /*
1478 * The above smp_load_acquire() ensures barrier_phase load
1479 * is ordered before the folloiwng ->call().
1480 */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001481 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1482 if (atomic_dec_and_test(&barrier_cbs_count))
1483 wake_up(&barrier_wq);
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001484 } while (!torture_must_stop());
Paul E. McKenney69c60452014-07-01 11:59:36 -07001485 if (cur_ops->cb_barrier != NULL)
1486 cur_ops->cb_barrier();
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001487 destroy_rcu_head_on_stack(&rcu);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001488 torture_kthread_stopping("rcu_torture_barrier_cbs");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001489 return 0;
1490}
1491
1492/* kthread function to drive and coordinate RCU barrier testing. */
1493static int rcu_torture_barrier(void *arg)
1494{
1495 int i;
1496
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001497 VERBOSE_TOROUT_STRING("rcu_torture_barrier task starting");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001498 do {
1499 atomic_set(&barrier_cbs_invoked, 0);
1500 atomic_set(&barrier_cbs_count, n_barrier_cbs);
Paul E. McKenney6c7ed422015-04-13 11:58:08 -07001501 /* Ensure barrier_phase ordered after prior assignments. */
1502 smp_store_release(&barrier_phase, !barrier_phase);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001503 for (i = 0; i < n_barrier_cbs; i++)
1504 wake_up(&barrier_cbs_wq[i]);
1505 wait_event(barrier_wq,
1506 atomic_read(&barrier_cbs_count) == 0 ||
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001507 torture_must_stop());
1508 if (torture_must_stop())
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001509 break;
1510 n_barrier_attempts++;
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001511 cur_ops->cb_barrier(); /* Implies smp_mb() for wait_event(). */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001512 if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
1513 n_rcu_torture_barrier_error++;
Paul E. McKenney7602de4a2014-12-17 18:39:54 -08001514 pr_err("barrier_cbs_invoked = %d, n_barrier_cbs = %d\n",
1515 atomic_read(&barrier_cbs_invoked),
1516 n_barrier_cbs);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001517 WARN_ON_ONCE(1);
1518 }
1519 n_barrier_successes++;
1520 schedule_timeout_interruptible(HZ / 10);
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001521 } while (!torture_must_stop());
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001522 torture_kthread_stopping("rcu_torture_barrier");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001523 return 0;
1524}
1525
1526/* Initialize RCU barrier testing. */
1527static int rcu_torture_barrier_init(void)
1528{
1529 int i;
1530 int ret;
1531
Paul E. McKenneyd9eba7682015-05-14 15:35:43 -07001532 if (n_barrier_cbs <= 0)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001533 return 0;
1534 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001535 pr_alert("%s" TORTURE_FLAG
1536 " Call or barrier ops missing for %s,\n",
1537 torture_type, cur_ops->name);
1538 pr_alert("%s" TORTURE_FLAG
1539 " RCU barrier testing omitted from run.\n",
1540 torture_type);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001541 return 0;
1542 }
1543 atomic_set(&barrier_cbs_count, 0);
1544 atomic_set(&barrier_cbs_invoked, 0);
1545 barrier_cbs_tasks =
1546 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
1547 GFP_KERNEL);
1548 barrier_cbs_wq =
1549 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
1550 GFP_KERNEL);
Sasha Levinde5e6432012-12-20 14:11:28 -05001551 if (barrier_cbs_tasks == NULL || !barrier_cbs_wq)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001552 return -ENOMEM;
1553 for (i = 0; i < n_barrier_cbs; i++) {
1554 init_waitqueue_head(&barrier_cbs_wq[i]);
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001555 ret = torture_create_kthread(rcu_torture_barrier_cbs,
1556 (void *)(long)i,
1557 barrier_cbs_tasks[i]);
1558 if (ret)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001559 return ret;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001560 }
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001561 return torture_create_kthread(rcu_torture_barrier, NULL, barrier_task);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001562}
1563
1564/* Clean up after RCU barrier testing. */
1565static void rcu_torture_barrier_cleanup(void)
1566{
1567 int i;
1568
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001569 torture_stop_kthread(rcu_torture_barrier, barrier_task);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001570 if (barrier_cbs_tasks != NULL) {
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001571 for (i = 0; i < n_barrier_cbs; i++)
1572 torture_stop_kthread(rcu_torture_barrier_cbs,
1573 barrier_cbs_tasks[i]);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001574 kfree(barrier_cbs_tasks);
1575 barrier_cbs_tasks = NULL;
1576 }
1577 if (barrier_cbs_wq != NULL) {
1578 kfree(barrier_cbs_wq);
1579 barrier_cbs_wq = NULL;
1580 }
1581}
1582
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001583static int rcutorture_cpu_notify(struct notifier_block *self,
1584 unsigned long action, void *hcpu)
1585{
1586 long cpu = (long)hcpu;
1587
1588 switch (action) {
1589 case CPU_ONLINE:
1590 case CPU_DOWN_FAILED:
1591 (void)rcutorture_booster_init(cpu);
1592 break;
1593 case CPU_DOWN_PREPARE:
1594 rcutorture_booster_cleanup(cpu);
1595 break;
1596 default:
1597 break;
1598 }
1599 return NOTIFY_OK;
1600}
1601
1602static struct notifier_block rcutorture_cpu_nb = {
1603 .notifier_call = rcutorture_cpu_notify,
1604};
1605
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001606static void
1607rcu_torture_cleanup(void)
1608{
1609 int i;
1610
Paul E. McKenney4a298652011-04-03 21:33:51 -07001611 rcutorture_record_test_transition();
Davidlohr Buesod36a7a02014-09-11 20:40:21 -07001612 if (torture_cleanup_begin()) {
Paul E. McKenney343e9092008-12-15 16:13:07 -08001613 if (cur_ops->cb_barrier != NULL)
1614 cur_ops->cb_barrier();
1615 return;
1616 }
Paul E. McKenney3808dc92014-01-28 15:29:21 -08001617
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001618 rcu_torture_barrier_cleanup();
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001619 torture_stop_kthread(rcu_torture_stall, stall_task);
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001620 torture_stop_kthread(rcu_torture_writer, writer_task);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001621
Josh Triplettc8e5b162007-05-08 00:33:20 -07001622 if (reader_tasks) {
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001623 for (i = 0; i < nrealreaders; i++)
1624 torture_stop_kthread(rcu_torture_reader,
1625 reader_tasks[i]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001626 kfree(reader_tasks);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001627 }
1628 rcu_torture_current = NULL;
1629
Josh Triplettc8e5b162007-05-08 00:33:20 -07001630 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001631 for (i = 0; i < nfakewriters; i++) {
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001632 torture_stop_kthread(rcu_torture_fakewriter,
1633 fakewriter_tasks[i]);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001634 }
1635 kfree(fakewriter_tasks);
1636 fakewriter_tasks = NULL;
1637 }
1638
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001639 torture_stop_kthread(rcu_torture_stats, stats_task);
1640 torture_stop_kthread(rcu_torture_fqs, fqs_task);
Paul E. McKenney38706bc2014-08-18 21:12:17 -07001641 for (i = 0; i < ncbflooders; i++)
1642 torture_stop_kthread(rcu_torture_cbflood, cbflood_task[i]);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001643 if ((test_boost == 1 && cur_ops->can_boost) ||
1644 test_boost == 2) {
1645 unregister_cpu_notifier(&rcutorture_cpu_nb);
1646 for_each_possible_cpu(i)
1647 rcutorture_booster_cleanup(i);
1648 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001649
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -07001650 /*
1651 * Wait for all RCU callbacks to fire, then do flavor-specific
1652 * cleanup operations.
1653 */
Paul E. McKenney23269742008-05-12 21:21:05 +02001654 if (cur_ops->cb_barrier != NULL)
1655 cur_ops->cb_barrier();
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -07001656 if (cur_ops->cleanup != NULL)
1657 cur_ops->cleanup();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001658
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001659 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001660
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001661 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001662 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
Paul E. McKenney2e9e8082014-01-28 15:58:22 -08001663 else if (torture_onoff_failures())
Paul E. McKenney091541b2012-01-10 12:51:14 -08001664 rcu_torture_print_module_parms(cur_ops,
1665 "End of test: RCU_HOTPLUG");
Paul E. McKenney95c38322006-03-24 03:15:58 -08001666 else
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001667 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
Davidlohr Buesod36a7a02014-09-11 20:40:21 -07001668 torture_cleanup_end();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001669}
1670
Paul E. McKenneyd2818df2013-04-23 17:05:42 -07001671#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1672static void rcu_torture_leak_cb(struct rcu_head *rhp)
1673{
1674}
1675
1676static void rcu_torture_err_cb(struct rcu_head *rhp)
1677{
1678 /*
1679 * This -might- happen due to race conditions, but is unlikely.
1680 * The scenario that leads to this happening is that the
1681 * first of the pair of duplicate callbacks is queued,
1682 * someone else starts a grace period that includes that
1683 * callback, then the second of the pair must wait for the
1684 * next grace period. Unlikely, but can happen. If it
1685 * does happen, the debug-objects subsystem won't have splatted.
1686 */
1687 pr_alert("rcutorture: duplicated callback was invoked.\n");
1688}
1689#endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1690
1691/*
1692 * Verify that double-free causes debug-objects to complain, but only
1693 * if CONFIG_DEBUG_OBJECTS_RCU_HEAD=y. Otherwise, say that the test
1694 * cannot be carried out.
1695 */
1696static void rcu_test_debug_objects(void)
1697{
1698#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1699 struct rcu_head rh1;
1700 struct rcu_head rh2;
1701
1702 init_rcu_head_on_stack(&rh1);
1703 init_rcu_head_on_stack(&rh2);
1704 pr_alert("rcutorture: WARN: Duplicate call_rcu() test starting.\n");
1705
1706 /* Try to queue the rh2 pair of callbacks for the same grace period. */
1707 preempt_disable(); /* Prevent preemption from interrupting test. */
1708 rcu_read_lock(); /* Make it impossible to finish a grace period. */
1709 call_rcu(&rh1, rcu_torture_leak_cb); /* Start grace period. */
1710 local_irq_disable(); /* Make it harder to start a new grace period. */
1711 call_rcu(&rh2, rcu_torture_leak_cb);
1712 call_rcu(&rh2, rcu_torture_err_cb); /* Duplicate callback. */
1713 local_irq_enable();
1714 rcu_read_unlock();
1715 preempt_enable();
1716
1717 /* Wait for them all to get done so we can safely return. */
1718 rcu_barrier();
1719 pr_alert("rcutorture: WARN: Duplicate call_rcu() test complete.\n");
1720 destroy_rcu_head_on_stack(&rh1);
1721 destroy_rcu_head_on_stack(&rh2);
1722#else /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1723 pr_alert("rcutorture: !CONFIG_DEBUG_OBJECTS_RCU_HEAD, not testing duplicate call_rcu()\n");
1724#endif /* #else #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1725}
1726
Josh Triplett6f8bc5002007-05-08 00:25:24 -07001727static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001728rcu_torture_init(void)
1729{
1730 int i;
1731 int cpu;
1732 int firsterr = 0;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001733 static struct rcu_torture_ops *torture_ops[] = {
Paul E. McKenneyca1d51e2015-04-14 12:28:22 -07001734 &rcu_ops, &rcu_bh_ops, &rcu_busted_ops, &srcu_ops, &srcud_ops,
1735 &sched_ops, RCUTORTURE_TASKS_OPS
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001736 };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001737
Paul E. McKenney59da22a2014-09-12 10:36:15 -07001738 if (!torture_init_begin(torture_type, verbose, &torture_runnable))
Paul E. McKenney52280842014-04-07 09:14:11 -07001739 return -EBUSY;
Paul E. McKenney343e9092008-12-15 16:13:07 -08001740
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001741 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001742 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001743 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001744 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001745 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001746 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001747 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001748 pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
1749 torture_type);
1750 pr_alert("rcu-torture types:");
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001751 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001752 pr_alert(" %s", torture_ops[i]->name);
1753 pr_alert("\n");
Paul E. McKenney889d4872015-08-24 11:37:58 -07001754 firsterr = -EINVAL;
1755 goto unwind;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001756 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001757 if (cur_ops->fqs == NULL && fqs_duration != 0) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001758 pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001759 fqs_duration = 0;
1760 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001761 if (cur_ops->init)
Paul E. McKenney889d4872015-08-24 11:37:58 -07001762 cur_ops->init();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001763
Paul E. McKenney64e4b432014-03-12 10:26:35 -07001764 if (nreaders >= 0) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001765 nrealreaders = nreaders;
Paul E. McKenney64e4b432014-03-12 10:26:35 -07001766 } else {
Paul E. McKenney3838cc12015-03-12 13:55:48 -07001767 nrealreaders = num_online_cpus() - 2 - nreaders;
Paul E. McKenney64e4b432014-03-12 10:26:35 -07001768 if (nrealreaders <= 0)
1769 nrealreaders = 1;
1770 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001771 rcu_torture_print_module_parms(cur_ops, "Start of test");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001772
1773 /* Set up the freelist. */
1774
1775 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07001776 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08001777 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001778 list_add_tail(&rcu_tortures[i].rtort_free,
1779 &rcu_torture_freelist);
1780 }
1781
1782 /* Initialize the statistics so that each run gets its own numbers. */
1783
1784 rcu_torture_current = NULL;
1785 rcu_torture_current_version = 0;
1786 atomic_set(&n_rcu_torture_alloc, 0);
1787 atomic_set(&n_rcu_torture_alloc_fail, 0);
1788 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001789 atomic_set(&n_rcu_torture_mberror, 0);
1790 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001791 n_rcu_torture_barrier_error = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001792 n_rcu_torture_boost_ktrerror = 0;
1793 n_rcu_torture_boost_rterror = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001794 n_rcu_torture_boost_failure = 0;
1795 n_rcu_torture_boosts = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001796 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1797 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001798 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001799 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1800 per_cpu(rcu_torture_count, cpu)[i] = 0;
1801 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1802 }
1803 }
1804
1805 /* Start up the kthreads. */
1806
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001807 firsterr = torture_create_kthread(rcu_torture_writer, NULL,
1808 writer_task);
1809 if (firsterr)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001810 goto unwind;
Paul E. McKenney4444d852015-05-14 15:42:40 -07001811 if (nfakewriters > 0) {
1812 fakewriter_tasks = kzalloc(nfakewriters *
1813 sizeof(fakewriter_tasks[0]),
1814 GFP_KERNEL);
1815 if (fakewriter_tasks == NULL) {
1816 VERBOSE_TOROUT_ERRSTRING("out of memory");
1817 firsterr = -ENOMEM;
1818 goto unwind;
1819 }
Josh Triplettb772e1d2006-10-04 02:17:13 -07001820 }
1821 for (i = 0; i < nfakewriters; i++) {
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001822 firsterr = torture_create_kthread(rcu_torture_fakewriter,
1823 NULL, fakewriter_tasks[i]);
1824 if (firsterr)
Josh Triplettb772e1d2006-10-04 02:17:13 -07001825 goto unwind;
Josh Triplettb772e1d2006-10-04 02:17:13 -07001826 }
Josh Triplett2860aab2006-10-04 02:17:11 -07001827 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001828 GFP_KERNEL);
1829 if (reader_tasks == NULL) {
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001830 VERBOSE_TOROUT_ERRSTRING("out of memory");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001831 firsterr = -ENOMEM;
1832 goto unwind;
1833 }
1834 for (i = 0; i < nrealreaders; i++) {
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001835 firsterr = torture_create_kthread(rcu_torture_reader, NULL,
1836 reader_tasks[i]);
1837 if (firsterr)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001838 goto unwind;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001839 }
1840 if (stat_interval > 0) {
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001841 firsterr = torture_create_kthread(rcu_torture_stats, NULL,
1842 stats_task);
1843 if (firsterr)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001844 goto unwind;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001845 }
Paul E. McKenneye8e255f2015-05-14 16:55:45 -07001846 if (test_no_idle_hz && shuffle_interval > 0) {
Paul E. McKenney3808dc92014-01-28 15:29:21 -08001847 firsterr = torture_shuffle_init(shuffle_interval * HZ);
1848 if (firsterr)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001849 goto unwind;
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001850 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001851 if (stutter < 0)
1852 stutter = 0;
1853 if (stutter) {
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001854 firsterr = torture_stutter_init(stutter * HZ);
1855 if (firsterr)
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001856 goto unwind;
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001857 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001858 if (fqs_duration < 0)
1859 fqs_duration = 0;
1860 if (fqs_duration) {
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001861 /* Create the fqs thread */
Paul E. McKenneyd0d06062014-03-17 20:56:45 -07001862 firsterr = torture_create_kthread(rcu_torture_fqs, NULL,
1863 fqs_task);
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001864 if (firsterr)
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001865 goto unwind;
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001866 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001867 if (test_boost_interval < 1)
1868 test_boost_interval = 1;
1869 if (test_boost_duration < 2)
1870 test_boost_duration = 2;
1871 if ((test_boost == 1 && cur_ops->can_boost) ||
1872 test_boost == 2) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001873
1874 boost_starttime = jiffies + test_boost_interval * HZ;
1875 register_cpu_notifier(&rcutorture_cpu_nb);
1876 for_each_possible_cpu(i) {
1877 if (cpu_is_offline(i))
1878 continue; /* Heuristic: CPU can go offline. */
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001879 firsterr = rcutorture_booster_init(i);
1880 if (firsterr)
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001881 goto unwind;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001882 }
1883 }
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001884 firsterr = torture_shutdown_init(shutdown_secs, rcu_torture_cleanup);
1885 if (firsterr)
Paul E. McKenneye991dbc2014-01-31 14:52:13 -08001886 goto unwind;
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001887 firsterr = torture_onoff_init(onoff_holdoff * HZ, onoff_interval * HZ);
1888 if (firsterr)
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001889 goto unwind;
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001890 firsterr = rcu_torture_stall_init();
1891 if (firsterr)
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001892 goto unwind;
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001893 firsterr = rcu_torture_barrier_init();
1894 if (firsterr)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001895 goto unwind;
Paul E. McKenneyd2818df2013-04-23 17:05:42 -07001896 if (object_debug)
1897 rcu_test_debug_objects();
Paul E. McKenney38706bc2014-08-18 21:12:17 -07001898 if (cbflood_n_burst > 0) {
1899 /* Create the cbflood threads */
1900 ncbflooders = (num_online_cpus() + 3) / 4;
1901 cbflood_task = kcalloc(ncbflooders, sizeof(*cbflood_task),
1902 GFP_KERNEL);
1903 if (!cbflood_task) {
1904 VERBOSE_TOROUT_ERRSTRING("out of memory");
1905 firsterr = -ENOMEM;
1906 goto unwind;
1907 }
1908 for (i = 0; i < ncbflooders; i++) {
1909 firsterr = torture_create_kthread(rcu_torture_cbflood,
1910 NULL,
1911 cbflood_task[i]);
1912 if (firsterr)
1913 goto unwind;
1914 }
1915 }
Paul E. McKenney4a298652011-04-03 21:33:51 -07001916 rcutorture_record_test_transition();
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -08001917 torture_init_end();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001918 return 0;
1919
1920unwind:
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -08001921 torture_init_end();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001922 rcu_torture_cleanup();
1923 return firsterr;
1924}
1925
1926module_init(rcu_torture_init);
1927module_exit(rcu_torture_cleanup);