blob: 80d2d2440210b3cf92ac4df6c6681074878d7040 [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>
Paul E. McKenneya71fca52009-09-18 10:28:19 -070021 * Josh Triplett <josh@freedesktop.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. McKenneya241ec62005-10-30 15:03:12 -080052
53MODULE_LICENSE("GPL");
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -070054MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@freedesktop.org>");
Paul E. McKenneya241ec62005-10-30 15:03:12 -080055
Paul E. McKenney4102ada2013-10-08 20:23:47 -070056
Paul E. McKenney9e250222014-01-27 16:27:00 -080057torture_param(int, fqs_duration, 0,
58 "Duration of fqs bursts (us), 0 to disable");
59torture_param(int, fqs_holdoff, 0, "Holdoff time within fqs bursts (us)");
60torture_param(int, fqs_stutter, 3, "Wait time between fqs bursts (s)");
61torture_param(bool, gp_exp, false, "Use expedited GP wait primitives");
62torture_param(bool, gp_normal, false,
63 "Use normal (non-expedited) GP wait primitives");
64torture_param(int, irqreader, 1, "Allow RCU readers from irq handlers");
65torture_param(int, n_barrier_cbs, 0,
66 "# of callbacks/kthreads for barrier testing");
67torture_param(int, nfakewriters, 4, "Number of RCU fake writer threads");
68torture_param(int, nreaders, -1, "Number of RCU reader threads");
69torture_param(int, object_debug, 0,
70 "Enable debug-object double call_rcu() testing");
71torture_param(int, onoff_holdoff, 0, "Time after boot before CPU hotplugs (s)");
72torture_param(int, onoff_interval, 0,
73 "Time between CPU hotplugs (s), 0=disable");
74torture_param(int, shuffle_interval, 3, "Number of seconds between shuffles");
75torture_param(int, shutdown_secs, 0, "Shutdown time (s), <= zero to disable.");
76torture_param(int, stall_cpu, 0, "Stall duration (s), zero to disable.");
77torture_param(int, stall_cpu_holdoff, 10,
78 "Time to wait before starting stall (s).");
79torture_param(int, stat_interval, 60,
80 "Number of seconds between stats printk()s");
81torture_param(int, stutter, 5, "Number of seconds to run/halt test");
82torture_param(int, test_boost, 1, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
83torture_param(int, test_boost_duration, 4,
84 "Duration of each boost test, seconds.");
85torture_param(int, test_boost_interval, 7,
86 "Interval between boost tests, seconds.");
87torture_param(bool, test_no_idle_hz, true,
88 "Test support for tickless idle CPUs");
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -080089torture_param(bool, verbose, true,
90 "Enable verbose debugging printk()s");
Paul E. McKenney9e250222014-01-27 16:27:00 -080091
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -080092static char *torture_type = "rcu";
Josh Triplettd6ad6712007-03-06 01:42:13 -080093module_param(torture_type, charp, 0444);
Paul E. McKenneyd10453e2013-06-13 15:12:24 -070094MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -070095
Paul E. McKenneya241ec62005-10-30 15:03:12 -080096static int nrealreaders;
97static struct task_struct *writer_task;
Josh Triplettb772e1d2006-10-04 02:17:13 -070098static struct task_struct **fakewriter_tasks;
Paul E. McKenneya241ec62005-10-30 15:03:12 -080099static struct task_struct **reader_tasks;
100static struct task_struct *stats_task;
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800101static struct task_struct *fqs_task;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700102static struct task_struct *boost_tasks[NR_CPUS];
Paul E. McKenneyc13f3752012-01-20 15:36:33 -0800103static struct task_struct *stall_task;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800104static struct task_struct **barrier_cbs_tasks;
105static struct task_struct *barrier_task;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800106
107#define RCU_TORTURE_PIPE_LEN 10
108
109struct rcu_torture {
110 struct rcu_head rtort_rcu;
111 int rtort_pipe_count;
112 struct list_head rtort_free;
Paul E. McKenney996417d2005-11-18 01:10:50 -0800113 int rtort_mbtest;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800114};
115
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800116static LIST_HEAD(rcu_torture_freelist);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700117static struct rcu_torture __rcu *rcu_torture_current;
Paul E. McKenney4a298652011-04-03 21:33:51 -0700118static unsigned long rcu_torture_current_version;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800119static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
120static DEFINE_SPINLOCK(rcu_torture_lock);
Paul E. McKenney806274c2014-02-17 13:13:05 -0800121static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
122 rcu_torture_count) = { 0 };
123static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
124 rcu_torture_batch) = { 0 };
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800125static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700126static atomic_t n_rcu_torture_alloc;
127static atomic_t n_rcu_torture_alloc_fail;
128static atomic_t n_rcu_torture_free;
129static atomic_t n_rcu_torture_mberror;
130static atomic_t n_rcu_torture_error;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800131static long n_rcu_torture_barrier_error;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700132static long n_rcu_torture_boost_ktrerror;
133static long n_rcu_torture_boost_rterror;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700134static long n_rcu_torture_boost_failure;
135static long n_rcu_torture_boosts;
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700136static long n_rcu_torture_timers;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800137static long n_barrier_attempts;
138static long n_barrier_successes;
Josh Triplette3033732006-10-04 02:17:14 -0700139static struct list_head rcu_torture_removed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800140
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800141static int rcu_torture_writer_state;
142#define RTWS_FIXED_DELAY 0
143#define RTWS_DELAY 1
144#define RTWS_REPLACE 2
145#define RTWS_DEF_FREE 3
146#define RTWS_EXP_SYNC 4
147#define RTWS_STUTTER 5
148#define RTWS_STOPPING 6
149
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700150#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
151#define RCUTORTURE_RUNNABLE_INIT 1
152#else
153#define RCUTORTURE_RUNNABLE_INIT 0
154#endif
155int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
Paul E. McKenneybb3bf702011-11-04 13:24:07 -0700156module_param(rcutorture_runnable, int, 0444);
157MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot");
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700158
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700159#if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700160#define rcu_can_boost() 1
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700161#else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700162#define rcu_can_boost() 0
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700163#endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700164
Steven Rostedte4aa0da2013-02-04 13:36:13 -0500165#ifdef CONFIG_RCU_TRACE
166static u64 notrace rcu_trace_clock_local(void)
167{
168 u64 ts = trace_clock_local();
169 unsigned long __maybe_unused ts_rem = do_div(ts, NSEC_PER_USEC);
170 return ts;
171}
172#else /* #ifdef CONFIG_RCU_TRACE */
173static u64 notrace rcu_trace_clock_local(void)
174{
175 return 0ULL;
176}
177#endif /* #else #ifdef CONFIG_RCU_TRACE */
178
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700179static unsigned long boost_starttime; /* jiffies of next boost test start. */
180DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
181 /* and boost task create/destroy. */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800182static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -0700183static bool barrier_phase; /* Test phase. */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800184static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */
185static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */
186static DECLARE_WAIT_QUEUE_HEAD(barrier_wq);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700187
Paul E. McKenney343e9092008-12-15 16:13:07 -0800188/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800189 * Allocate an element from the rcu_tortures pool.
190 */
Adrian Bunk97a41e22006-01-08 01:02:17 -0800191static struct rcu_torture *
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800192rcu_torture_alloc(void)
193{
194 struct list_head *p;
195
Ingo Molnaradac1662006-01-25 19:50:12 +0100196 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800197 if (list_empty(&rcu_torture_freelist)) {
198 atomic_inc(&n_rcu_torture_alloc_fail);
Ingo Molnaradac1662006-01-25 19:50:12 +0100199 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800200 return NULL;
201 }
202 atomic_inc(&n_rcu_torture_alloc);
203 p = rcu_torture_freelist.next;
204 list_del_init(p);
Ingo Molnaradac1662006-01-25 19:50:12 +0100205 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800206 return container_of(p, struct rcu_torture, rtort_free);
207}
208
209/*
210 * Free an element to the rcu_tortures pool.
211 */
212static void
213rcu_torture_free(struct rcu_torture *p)
214{
215 atomic_inc(&n_rcu_torture_free);
Ingo Molnaradac1662006-01-25 19:50:12 +0100216 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800217 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
Ingo Molnaradac1662006-01-25 19:50:12 +0100218 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800219}
220
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800221/*
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700222 * Operations vector for selecting different types of tests.
223 */
224
225struct rcu_torture_ops {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800226 int ttype;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700227 void (*init)(void);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700228 int (*readlock)(void);
Paul E. McKenney51b11302014-01-27 11:49:39 -0800229 void (*read_delay)(struct torture_random_state *rrsp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700230 void (*readunlock)(int idx);
231 int (*completed)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700232 void (*deferred_free)(struct rcu_torture *p);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700233 void (*sync)(void);
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700234 void (*exp_sync)(void);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800235 void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu));
Paul E. McKenney23269742008-05-12 21:21:05 +0200236 void (*cb_barrier)(void);
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800237 void (*fqs)(void);
Chen Gangd1008952013-11-07 10:30:25 +0800238 void (*stats)(char *page);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700239 int irq_capable;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700240 int can_boost;
Steven Rostedt (Red Hat)e66c33d2013-07-12 16:50:28 -0400241 const char *name;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700242};
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700243
244static struct rcu_torture_ops *cur_ops;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700245
246/*
247 * Definitions for rcu torture testing.
248 */
249
Josh Tripletta49a4af2006-09-29 01:59:30 -0700250static int rcu_torture_read_lock(void) __acquires(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700251{
252 rcu_read_lock();
253 return 0;
254}
255
Paul E. McKenney51b11302014-01-27 11:49:39 -0800256static void rcu_read_delay(struct torture_random_state *rrsp)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700257{
Josh Triplettb8d57a72009-09-08 15:54:35 -0700258 const unsigned long shortdelay_us = 200;
259 const unsigned long longdelay_ms = 50;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700260
Josh Triplettb8d57a72009-09-08 15:54:35 -0700261 /* We want a short delay sometimes to make a reader delay the grace
262 * period, and we want a long delay occasionally to trigger
263 * force_quiescent_state. */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700264
Paul E. McKenney51b11302014-01-27 11:49:39 -0800265 if (!(torture_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
Josh Triplettb8d57a72009-09-08 15:54:35 -0700266 mdelay(longdelay_ms);
Paul E. McKenney51b11302014-01-27 11:49:39 -0800267 if (!(torture_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
Josh Triplettb8d57a72009-09-08 15:54:35 -0700268 udelay(shortdelay_us);
Lai Jiangshane546f482010-06-21 16:57:42 +0800269#ifdef CONFIG_PREEMPT
Paul E. McKenney51b11302014-01-27 11:49:39 -0800270 if (!preempt_count() &&
271 !(torture_random(rrsp) % (nrealreaders * 20000)))
Lai Jiangshane546f482010-06-21 16:57:42 +0800272 preempt_schedule(); /* No QS if preempt_disable() in effect */
273#endif
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700274}
275
Josh Tripletta49a4af2006-09-29 01:59:30 -0700276static void rcu_torture_read_unlock(int idx) __releases(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700277{
278 rcu_read_unlock();
279}
280
281static int rcu_torture_completed(void)
282{
283 return rcu_batches_completed();
284}
285
286static void
287rcu_torture_cb(struct rcu_head *p)
288{
289 int i;
290 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
291
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800292 if (torture_must_stop_irq()) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700293 /* Test is ending, just drop callbacks on the floor. */
294 /* The next initialization will pick up the pieces. */
295 return;
296 }
297 i = rp->rtort_pipe_count;
298 if (i > RCU_TORTURE_PIPE_LEN)
299 i = RCU_TORTURE_PIPE_LEN;
300 atomic_inc(&rcu_torture_wcount[i]);
301 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
302 rp->rtort_mbtest = 0;
303 rcu_torture_free(rp);
Paul E. McKenneyc701d5d2012-06-28 08:08:25 -0700304 } else {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700305 cur_ops->deferred_free(rp);
Paul E. McKenneyc701d5d2012-06-28 08:08:25 -0700306 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700307}
308
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800309static int rcu_no_completed(void)
310{
311 return 0;
312}
313
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700314static void rcu_torture_deferred_free(struct rcu_torture *p)
315{
316 call_rcu(&p->rtort_rcu, rcu_torture_cb);
317}
318
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700319static void rcu_sync_torture_init(void)
320{
321 INIT_LIST_HEAD(&rcu_torture_removed);
322}
323
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700324static struct rcu_torture_ops rcu_ops = {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800325 .ttype = RCU_FLAVOR,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700326 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700327 .readlock = rcu_torture_read_lock,
328 .read_delay = rcu_read_delay,
329 .readunlock = rcu_torture_read_unlock,
330 .completed = rcu_torture_completed,
331 .deferred_free = rcu_torture_deferred_free,
332 .sync = synchronize_rcu,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700333 .exp_sync = synchronize_rcu_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800334 .call = call_rcu,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700335 .cb_barrier = rcu_barrier,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800336 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700337 .stats = NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700338 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700339 .can_boost = rcu_can_boost(),
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700340 .name = "rcu"
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700341};
342
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700343/*
344 * Definitions for rcu_bh torture testing.
345 */
346
Josh Tripletta49a4af2006-09-29 01:59:30 -0700347static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700348{
349 rcu_read_lock_bh();
350 return 0;
351}
352
Josh Tripletta49a4af2006-09-29 01:59:30 -0700353static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700354{
355 rcu_read_unlock_bh();
356}
357
358static int rcu_bh_torture_completed(void)
359{
360 return rcu_batches_completed_bh();
361}
362
363static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
364{
365 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
366}
367
368static struct rcu_torture_ops rcu_bh_ops = {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800369 .ttype = RCU_BH_FLAVOR,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700370 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700371 .readlock = rcu_bh_torture_read_lock,
372 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
373 .readunlock = rcu_bh_torture_read_unlock,
374 .completed = rcu_bh_torture_completed,
375 .deferred_free = rcu_bh_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700376 .sync = synchronize_rcu_bh,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700377 .exp_sync = synchronize_rcu_bh_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800378 .call = call_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700379 .cb_barrier = rcu_barrier_bh,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800380 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700381 .stats = NULL,
382 .irq_capable = 1,
383 .name = "rcu_bh"
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700384};
385
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700386/*
Paul E. McKenneyff20e252014-02-06 08:45:56 -0800387 * Don't even think about trying any of these in real life!!!
388 * The names includes "busted", and they really means it!
389 * The only purpose of these functions is to provide a buggy RCU
390 * implementation to make sure that rcutorture correctly emits
391 * buggy-RCU error messages.
392 */
393static void rcu_busted_torture_deferred_free(struct rcu_torture *p)
394{
395 /* This is a deliberate bug for testing purposes only! */
396 rcu_torture_cb(&p->rtort_rcu);
397}
398
399static void synchronize_rcu_busted(void)
400{
401 /* This is a deliberate bug for testing purposes only! */
402}
403
404static void
405call_rcu_busted(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
406{
407 /* This is a deliberate bug for testing purposes only! */
408 func(head);
409}
410
411static struct rcu_torture_ops rcu_busted_ops = {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800412 .ttype = INVALID_RCU_FLAVOR,
Paul E. McKenneyff20e252014-02-06 08:45:56 -0800413 .init = rcu_sync_torture_init,
414 .readlock = rcu_torture_read_lock,
415 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
416 .readunlock = rcu_torture_read_unlock,
417 .completed = rcu_no_completed,
418 .deferred_free = rcu_busted_torture_deferred_free,
419 .sync = synchronize_rcu_busted,
420 .exp_sync = synchronize_rcu_busted,
421 .call = call_rcu_busted,
422 .cb_barrier = NULL,
423 .fqs = NULL,
424 .stats = NULL,
425 .irq_capable = 1,
426 .name = "rcu_busted"
427};
428
429/*
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700430 * Definitions for srcu torture testing.
431 */
432
Lai Jiangshancda4dc82012-10-13 01:14:17 +0800433DEFINE_STATIC_SRCU(srcu_ctl);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700434
Josh Triplett012d3ca2006-12-06 20:40:19 -0800435static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700436{
437 return srcu_read_lock(&srcu_ctl);
438}
439
Paul E. McKenney51b11302014-01-27 11:49:39 -0800440static void srcu_read_delay(struct torture_random_state *rrsp)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700441{
442 long delay;
443 const long uspertick = 1000000 / HZ;
444 const long longdelay = 10;
445
446 /* We want there to be long-running readers, but not all the time. */
447
Paul E. McKenney51b11302014-01-27 11:49:39 -0800448 delay = torture_random(rrsp) %
449 (nrealreaders * 2 * longdelay * uspertick);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700450 if (!delay)
451 schedule_timeout_interruptible(longdelay);
Lai Jiangshane546f482010-06-21 16:57:42 +0800452 else
453 rcu_read_delay(rrsp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700454}
455
Josh Triplett012d3ca2006-12-06 20:40:19 -0800456static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700457{
458 srcu_read_unlock(&srcu_ctl, idx);
459}
460
461static int srcu_torture_completed(void)
462{
463 return srcu_batches_completed(&srcu_ctl);
464}
465
Lai Jiangshan9059c942012-03-19 16:12:14 +0800466static void srcu_torture_deferred_free(struct rcu_torture *rp)
467{
468 call_srcu(&srcu_ctl, &rp->rtort_rcu, rcu_torture_cb);
469}
470
Josh Triplettb772e1d2006-10-04 02:17:13 -0700471static void srcu_torture_synchronize(void)
472{
473 synchronize_srcu(&srcu_ctl);
474}
475
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700476static void srcu_torture_call(struct rcu_head *head,
477 void (*func)(struct rcu_head *head))
478{
479 call_srcu(&srcu_ctl, head, func);
480}
481
482static void srcu_torture_barrier(void)
483{
484 srcu_barrier(&srcu_ctl);
485}
486
Chen Gangd1008952013-11-07 10:30:25 +0800487static void srcu_torture_stats(char *page)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700488{
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700489 int cpu;
490 int idx = srcu_ctl.completed & 0x1;
491
Chen Gangd1008952013-11-07 10:30:25 +0800492 page += sprintf(page, "%s%s per-CPU(idx=%d):",
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700493 torture_type, TORTURE_FLAG, idx);
494 for_each_possible_cpu(cpu) {
Paul E. McKenney589a8f52014-03-03 16:51:08 -0800495 long c0, c1;
496
497 c0 = (long)per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx];
498 c1 = (long)per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx];
499 page += sprintf(page, " %d(%ld,%ld)", cpu, c0, c1);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700500 }
Chen Gangd1008952013-11-07 10:30:25 +0800501 sprintf(page, "\n");
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700502}
503
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700504static void srcu_torture_synchronize_expedited(void)
505{
506 synchronize_srcu_expedited(&srcu_ctl);
507}
508
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700509static struct rcu_torture_ops srcu_ops = {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800510 .ttype = SRCU_FLAVOR,
Lai Jiangshancda4dc82012-10-13 01:14:17 +0800511 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700512 .readlock = srcu_torture_read_lock,
513 .read_delay = srcu_read_delay,
514 .readunlock = srcu_torture_read_unlock,
515 .completed = srcu_torture_completed,
Lai Jiangshan9059c942012-03-19 16:12:14 +0800516 .deferred_free = srcu_torture_deferred_free,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700517 .sync = srcu_torture_synchronize,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700518 .exp_sync = srcu_torture_synchronize_expedited,
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700519 .call = srcu_torture_call,
520 .cb_barrier = srcu_torture_barrier,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700521 .stats = srcu_torture_stats,
522 .name = "srcu"
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700523};
524
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700525/*
526 * Definitions for sched torture testing.
527 */
528
529static int sched_torture_read_lock(void)
530{
531 preempt_disable();
532 return 0;
533}
534
535static void sched_torture_read_unlock(int idx)
536{
537 preempt_enable();
538}
539
Paul E. McKenney23269742008-05-12 21:21:05 +0200540static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
541{
542 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
543}
544
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700545static struct rcu_torture_ops sched_ops = {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800546 .ttype = RCU_SCHED_FLAVOR,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700547 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700548 .readlock = sched_torture_read_lock,
549 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
550 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800551 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700552 .deferred_free = rcu_sched_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700553 .sync = synchronize_sched,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700554 .exp_sync = synchronize_sched_expedited,
555 .call = call_rcu_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700556 .cb_barrier = rcu_barrier_sched,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800557 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700558 .stats = NULL,
559 .irq_capable = 1,
560 .name = "sched"
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700561};
562
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700563/*
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700564 * RCU torture priority-boost testing. Runs one real-time thread per
565 * CPU for moderate bursts, repeatedly registering RCU callbacks and
566 * spinning waiting for them to be invoked. If a given callback takes
567 * too long to be invoked, we assume that priority inversion has occurred.
568 */
569
570struct rcu_boost_inflight {
571 struct rcu_head rcu;
572 int inflight;
573};
574
575static void rcu_torture_boost_cb(struct rcu_head *head)
576{
577 struct rcu_boost_inflight *rbip =
578 container_of(head, struct rcu_boost_inflight, rcu);
579
580 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
581 rbip->inflight = 0;
582}
583
584static int rcu_torture_boost(void *arg)
585{
586 unsigned long call_rcu_time;
587 unsigned long endtime;
588 unsigned long oldstarttime;
589 struct rcu_boost_inflight rbi = { .inflight = 0 };
590 struct sched_param sp;
591
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800592 VERBOSE_TOROUT_STRING("rcu_torture_boost started");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700593
594 /* Set real-time priority. */
595 sp.sched_priority = 1;
596 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800597 VERBOSE_TOROUT_STRING("rcu_torture_boost RT prio failed!");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700598 n_rcu_torture_boost_rterror++;
599 }
600
Paul E. McKenney561190e2011-03-30 09:10:44 -0700601 init_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700602 /* Each pass through the following loop does one boost-test cycle. */
603 do {
604 /* Wait for the next test interval. */
605 oldstarttime = boost_starttime;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700606 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
Paul E. McKenney0e11c8e2013-01-10 16:21:07 -0800607 schedule_timeout_interruptible(oldstarttime - jiffies);
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800608 stutter_wait("rcu_torture_boost");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800609 if (torture_must_stop())
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700610 goto checkwait;
611 }
612
613 /* Do one boost-test interval. */
614 endtime = oldstarttime + test_boost_duration * HZ;
615 call_rcu_time = jiffies;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700616 while (ULONG_CMP_LT(jiffies, endtime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700617 /* If we don't have a callback in flight, post one. */
618 if (!rbi.inflight) {
619 smp_mb(); /* RCU core before ->inflight = 1. */
620 rbi.inflight = 1;
621 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
622 if (jiffies - call_rcu_time >
623 test_boost_duration * HZ - HZ / 2) {
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800624 VERBOSE_TOROUT_STRING("rcu_torture_boost boosting failed");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700625 n_rcu_torture_boost_failure++;
626 }
627 call_rcu_time = jiffies;
628 }
629 cond_resched();
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800630 stutter_wait("rcu_torture_boost");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800631 if (torture_must_stop())
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700632 goto checkwait;
633 }
634
635 /*
636 * Set the start time of the next test interval.
637 * Yes, this is vulnerable to long delays, but such
638 * delays simply cause a false negative for the next
639 * interval. Besides, we are running at RT priority,
640 * so delays should be relatively rare.
641 */
Paul E. McKenneyab8f11e2011-08-18 09:30:32 -0700642 while (oldstarttime == boost_starttime &&
643 !kthread_should_stop()) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700644 if (mutex_trylock(&boost_mutex)) {
645 boost_starttime = jiffies +
646 test_boost_interval * HZ;
647 n_rcu_torture_boosts++;
648 mutex_unlock(&boost_mutex);
649 break;
650 }
651 schedule_timeout_uninterruptible(1);
652 }
653
654 /* Go do the stutter. */
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800655checkwait: stutter_wait("rcu_torture_boost");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800656 } while (!torture_must_stop());
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700657
658 /* Clean up and exit. */
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800659 while (!kthread_should_stop() || rbi.inflight) {
660 torture_shutdown_absorb("rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700661 schedule_timeout_uninterruptible(1);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800662 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700663 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
Paul E. McKenney9d681972011-06-21 01:48:03 -0700664 destroy_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800665 torture_kthread_stopping("rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700666 return 0;
667}
668
669/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800670 * RCU torture force-quiescent-state kthread. Repeatedly induces
671 * bursts of calls to force_quiescent_state(), increasing the probability
672 * of occurrence of some important types of race conditions.
673 */
674static int
675rcu_torture_fqs(void *arg)
676{
677 unsigned long fqs_resume_time;
678 int fqs_burst_remaining;
679
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800680 VERBOSE_TOROUT_STRING("rcu_torture_fqs task started");
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800681 do {
682 fqs_resume_time = jiffies + fqs_stutter * HZ;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700683 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
684 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800685 schedule_timeout_interruptible(1);
686 }
687 fqs_burst_remaining = fqs_duration;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700688 while (fqs_burst_remaining > 0 &&
689 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800690 cur_ops->fqs();
691 udelay(fqs_holdoff);
692 fqs_burst_remaining -= fqs_holdoff;
693 }
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800694 stutter_wait("rcu_torture_fqs");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800695 } while (!torture_must_stop());
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800696 torture_kthread_stopping("rcu_torture_fqs");
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800697 return 0;
698}
699
700/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800701 * RCU torture writer kthread. Repeatedly substitutes a new structure
702 * for that pointed to by rcu_torture_current, freeing the old structure
703 * after a series of grace periods (the "pipeline").
704 */
705static int
706rcu_torture_writer(void *arg)
707{
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700708 bool exp;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800709 int i;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800710 struct rcu_torture *rp;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700711 struct rcu_torture *rp1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800712 struct rcu_torture *old_rp;
Paul E. McKenney51b11302014-01-27 11:49:39 -0800713 static DEFINE_TORTURE_RANDOM(rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800714
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800715 VERBOSE_TOROUT_STRING("rcu_torture_writer task started");
Linus Torvalds971eae72014-03-31 11:21:19 -0700716 set_user_nice(current, MAX_NICE);
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800717
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800718 do {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800719 rcu_torture_writer_state = RTWS_FIXED_DELAY;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800720 schedule_timeout_uninterruptible(1);
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700721 rp = rcu_torture_alloc();
722 if (rp == NULL)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800723 continue;
724 rp->rtort_pipe_count = 0;
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800725 rcu_torture_writer_state = RTWS_DELAY;
Paul E. McKenney51b11302014-01-27 11:49:39 -0800726 udelay(torture_random(&rand) & 0x3ff);
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800727 rcu_torture_writer_state = RTWS_REPLACE;
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700728 old_rp = rcu_dereference_check(rcu_torture_current,
729 current == writer_task);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800730 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800731 rcu_assign_pointer(rcu_torture_current, rp);
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700732 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
Josh Triplettc8e5b162007-05-08 00:33:20 -0700733 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800734 i = old_rp->rtort_pipe_count;
735 if (i > RCU_TORTURE_PIPE_LEN)
736 i = RCU_TORTURE_PIPE_LEN;
737 atomic_inc(&rcu_torture_wcount[i]);
738 old_rp->rtort_pipe_count++;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700739 if (gp_normal == gp_exp)
Paul E. McKenney51b11302014-01-27 11:49:39 -0800740 exp = !!(torture_random(&rand) & 0x80);
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700741 else
742 exp = gp_exp;
743 if (!exp) {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800744 rcu_torture_writer_state = RTWS_DEF_FREE;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700745 cur_ops->deferred_free(old_rp);
746 } else {
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800747 rcu_torture_writer_state = RTWS_EXP_SYNC;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700748 cur_ops->exp_sync();
749 list_add(&old_rp->rtort_free,
750 &rcu_torture_removed);
751 list_for_each_entry_safe(rp, rp1,
752 &rcu_torture_removed,
753 rtort_free) {
754 i = rp->rtort_pipe_count;
755 if (i > RCU_TORTURE_PIPE_LEN)
756 i = RCU_TORTURE_PIPE_LEN;
757 atomic_inc(&rcu_torture_wcount[i]);
758 if (++rp->rtort_pipe_count >=
759 RCU_TORTURE_PIPE_LEN) {
760 rp->rtort_mbtest = 0;
761 list_del(&rp->rtort_free);
762 rcu_torture_free(rp);
763 }
764 }
765 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800766 }
Paul E. McKenney4a298652011-04-03 21:33:51 -0700767 rcutorture_record_progress(++rcu_torture_current_version);
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800768 rcu_torture_writer_state = RTWS_STUTTER;
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800769 stutter_wait("rcu_torture_writer");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800770 } while (!torture_must_stop());
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800771 rcu_torture_writer_state = RTWS_STOPPING;
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800772 torture_kthread_stopping("rcu_torture_writer");
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800773 return 0;
774}
775
776/*
Josh Triplettb772e1d2006-10-04 02:17:13 -0700777 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
778 * delay between calls.
779 */
780static int
781rcu_torture_fakewriter(void *arg)
782{
Paul E. McKenney51b11302014-01-27 11:49:39 -0800783 DEFINE_TORTURE_RANDOM(rand);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700784
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800785 VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task started");
Linus Torvalds971eae72014-03-31 11:21:19 -0700786 set_user_nice(current, MAX_NICE);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700787
788 do {
Paul E. McKenney51b11302014-01-27 11:49:39 -0800789 schedule_timeout_uninterruptible(1 + torture_random(&rand)%10);
790 udelay(torture_random(&rand) & 0x3ff);
Paul E. McKenney72472a02012-05-29 17:50:51 -0700791 if (cur_ops->cb_barrier != NULL &&
Paul E. McKenney51b11302014-01-27 11:49:39 -0800792 torture_random(&rand) % (nfakewriters * 8) == 0) {
Paul E. McKenney72472a02012-05-29 17:50:51 -0700793 cur_ops->cb_barrier();
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700794 } else if (gp_normal == gp_exp) {
Paul E. McKenney51b11302014-01-27 11:49:39 -0800795 if (torture_random(&rand) & 0x80)
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700796 cur_ops->sync();
797 else
798 cur_ops->exp_sync();
799 } else if (gp_normal) {
Paul E. McKenney72472a02012-05-29 17:50:51 -0700800 cur_ops->sync();
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700801 } else {
802 cur_ops->exp_sync();
803 }
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800804 stutter_wait("rcu_torture_fakewriter");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800805 } while (!torture_must_stop());
Josh Triplettb772e1d2006-10-04 02:17:13 -0700806
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800807 torture_kthread_stopping("rcu_torture_fakewriter");
Josh Triplettb772e1d2006-10-04 02:17:13 -0700808 return 0;
809}
810
Rashika Kheriab3b8a4d2014-02-27 17:16:57 +0530811static void rcutorture_trace_dump(void)
Paul E. McKenney91afaf32011-10-02 07:44:32 -0700812{
813 static atomic_t beenhere = ATOMIC_INIT(0);
814
815 if (atomic_read(&beenhere))
816 return;
817 if (atomic_xchg(&beenhere, 1) != 0)
818 return;
Paul E. McKenney91afaf32011-10-02 07:44:32 -0700819 ftrace_dump(DUMP_ALL);
820}
821
Josh Triplettb772e1d2006-10-04 02:17:13 -0700822/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700823 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
824 * incrementing the corresponding element of the pipeline array. The
825 * counter in the element should never be greater than 1, otherwise, the
826 * RCU implementation is broken.
827 */
828static void rcu_torture_timer(unsigned long unused)
829{
830 int idx;
831 int completed;
Paul E. McKenney52494532012-11-14 16:26:40 -0800832 int completed_end;
Paul E. McKenney51b11302014-01-27 11:49:39 -0800833 static DEFINE_TORTURE_RANDOM(rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700834 static DEFINE_SPINLOCK(rand_lock);
835 struct rcu_torture *p;
836 int pipe_count;
Paul E. McKenney52494532012-11-14 16:26:40 -0800837 unsigned long long ts;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700838
839 idx = cur_ops->readlock();
840 completed = cur_ops->completed();
Steven Rostedte4aa0da2013-02-04 13:36:13 -0500841 ts = rcu_trace_clock_local();
Paul E. McKenney632ee202010-02-22 17:04:45 -0800842 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -0800843 rcu_read_lock_bh_held() ||
844 rcu_read_lock_sched_held() ||
845 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700846 if (p == NULL) {
847 /* Leave because rcu_torture_writer is not yet underway */
848 cur_ops->readunlock(idx);
849 return;
850 }
851 if (p->rtort_mbtest == 0)
852 atomic_inc(&n_rcu_torture_mberror);
853 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700854 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700855 n_rcu_torture_timers++;
856 spin_unlock(&rand_lock);
857 preempt_disable();
858 pipe_count = p->rtort_pipe_count;
859 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
860 /* Should not happen, but... */
861 pipe_count = RCU_TORTURE_PIPE_LEN;
862 }
Paul E. McKenney52494532012-11-14 16:26:40 -0800863 completed_end = cur_ops->completed();
864 if (pipe_count > 1) {
Paul E. McKenney52494532012-11-14 16:26:40 -0800865 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, ts,
866 completed, completed_end);
Paul E. McKenney91afaf32011-10-02 07:44:32 -0700867 rcutorture_trace_dump();
Paul E. McKenney52494532012-11-14 16:26:40 -0800868 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +0900869 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney52494532012-11-14 16:26:40 -0800870 completed = completed_end - completed;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700871 if (completed > RCU_TORTURE_PIPE_LEN) {
872 /* Should not happen, but... */
873 completed = RCU_TORTURE_PIPE_LEN;
874 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +0900875 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700876 preempt_enable();
877 cur_ops->readunlock(idx);
878}
879
880/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800881 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
882 * incrementing the corresponding element of the pipeline array. The
883 * counter in the element should never be greater than 1, otherwise, the
884 * RCU implementation is broken.
885 */
886static int
887rcu_torture_reader(void *arg)
888{
889 int completed;
Paul E. McKenney52494532012-11-14 16:26:40 -0800890 int completed_end;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700891 int idx;
Paul E. McKenney51b11302014-01-27 11:49:39 -0800892 DEFINE_TORTURE_RANDOM(rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800893 struct rcu_torture *p;
894 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700895 struct timer_list t;
Paul E. McKenney52494532012-11-14 16:26:40 -0800896 unsigned long long ts;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800897
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -0800898 VERBOSE_TOROUT_STRING("rcu_torture_reader task started");
Linus Torvalds971eae72014-03-31 11:21:19 -0700899 set_user_nice(current, MAX_NICE);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700900 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700901 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800902
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800903 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700904 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700905 if (!timer_pending(&t))
Paul E. McKenney6155fec2010-02-22 17:05:04 -0800906 mod_timer(&t, jiffies + 1);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700907 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700908 idx = cur_ops->readlock();
909 completed = cur_ops->completed();
Steven Rostedte4aa0da2013-02-04 13:36:13 -0500910 ts = rcu_trace_clock_local();
Paul E. McKenney632ee202010-02-22 17:04:45 -0800911 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -0800912 rcu_read_lock_bh_held() ||
913 rcu_read_lock_sched_held() ||
914 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800915 if (p == NULL) {
916 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700917 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800918 schedule_timeout_interruptible(HZ);
919 continue;
920 }
Paul E. McKenney996417d2005-11-18 01:10:50 -0800921 if (p->rtort_mbtest == 0)
922 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700923 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800924 preempt_disable();
925 pipe_count = p->rtort_pipe_count;
926 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
927 /* Should not happen, but... */
928 pipe_count = RCU_TORTURE_PIPE_LEN;
929 }
Paul E. McKenney52494532012-11-14 16:26:40 -0800930 completed_end = cur_ops->completed();
931 if (pipe_count > 1) {
Paul E. McKenney52494532012-11-14 16:26:40 -0800932 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu,
933 ts, completed, completed_end);
Paul E. McKenney91afaf32011-10-02 07:44:32 -0700934 rcutorture_trace_dump();
Paul E. McKenney52494532012-11-14 16:26:40 -0800935 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +0900936 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney52494532012-11-14 16:26:40 -0800937 completed = completed_end - completed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800938 if (completed > RCU_TORTURE_PIPE_LEN) {
939 /* Should not happen, but... */
940 completed = RCU_TORTURE_PIPE_LEN;
941 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +0900942 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800943 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700944 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800945 schedule();
Paul E. McKenney628edaa2014-01-31 11:57:43 -0800946 stutter_wait("rcu_torture_reader");
Paul E. McKenney36970bb2014-01-30 15:49:29 -0800947 } while (!torture_must_stop());
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700948 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700949 del_timer_sync(&t);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -0800950 torture_kthread_stopping("rcu_torture_reader");
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800951 return 0;
952}
953
954/*
955 * Create an RCU-torture statistics message in the specified buffer.
956 */
Chen Gangd1008952013-11-07 10:30:25 +0800957static void
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800958rcu_torture_printk(char *page)
959{
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800960 int cpu;
961 int i;
962 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
963 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -0800964 static unsigned long rtcv_snap = ULONG_MAX;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800965
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -0800966 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800967 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
968 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
969 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
970 }
971 }
972 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
973 if (pipesummary[i] != 0)
974 break;
975 }
Chen Gangd1008952013-11-07 10:30:25 +0800976 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
977 page += sprintf(page,
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -0700978 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800979 rcu_torture_current,
980 rcu_torture_current_version,
981 list_empty(&rcu_torture_freelist),
982 atomic_read(&n_rcu_torture_alloc),
983 atomic_read(&n_rcu_torture_alloc_fail),
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -0700984 atomic_read(&n_rcu_torture_free));
Chen Gangd1008952013-11-07 10:30:25 +0800985 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700986 atomic_read(&n_rcu_torture_mberror),
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700987 n_rcu_torture_boost_ktrerror,
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -0700988 n_rcu_torture_boost_rterror);
Chen Gangd1008952013-11-07 10:30:25 +0800989 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700990 n_rcu_torture_boost_failure,
991 n_rcu_torture_boosts,
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -0700992 n_rcu_torture_timers);
Paul E. McKenney2e9e8082014-01-28 15:58:22 -0800993 page = torture_onoff_stats(page);
Chen Gangd1008952013-11-07 10:30:25 +0800994 page += sprintf(page, "barrier: %ld/%ld:%ld",
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800995 n_barrier_successes,
996 n_barrier_attempts,
997 n_rcu_torture_barrier_error);
Chen Gangd1008952013-11-07 10:30:25 +0800998 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700999 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001000 n_rcu_torture_barrier_error != 0 ||
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001001 n_rcu_torture_boost_ktrerror != 0 ||
1002 n_rcu_torture_boost_rterror != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001003 n_rcu_torture_boost_failure != 0 ||
1004 i > 1) {
Chen Gangd1008952013-11-07 10:30:25 +08001005 page += sprintf(page, "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -08001006 atomic_inc(&n_rcu_torture_error);
Ingo Molnar5af970a2008-06-18 10:09:48 +02001007 WARN_ON_ONCE(1);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001008 }
Chen Gangd1008952013-11-07 10:30:25 +08001009 page += sprintf(page, "Reader Pipe: ");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001010 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Chen Gangd1008952013-11-07 10:30:25 +08001011 page += sprintf(page, " %ld", pipesummary[i]);
1012 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
1013 page += sprintf(page, "Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001014 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Chen Gangd1008952013-11-07 10:30:25 +08001015 page += sprintf(page, " %ld", batchsummary[i]);
1016 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
1017 page += sprintf(page, "Free-Block Circulation: ");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001018 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
Chen Gangd1008952013-11-07 10:30:25 +08001019 page += sprintf(page, " %d",
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001020 atomic_read(&rcu_torture_wcount[i]));
1021 }
Chen Gangd1008952013-11-07 10:30:25 +08001022 page += sprintf(page, "\n");
Josh Triplettc8e5b162007-05-08 00:33:20 -07001023 if (cur_ops->stats)
Chen Gangd1008952013-11-07 10:30:25 +08001024 cur_ops->stats(page);
Paul E. McKenneyad0dc7f2014-02-19 10:51:42 -08001025 if (rtcv_snap == rcu_torture_current_version &&
1026 rcu_torture_current != NULL) {
1027 int __maybe_unused flags;
1028 unsigned long __maybe_unused gpnum;
1029 unsigned long __maybe_unused completed;
1030
1031 rcutorture_get_gp_data(cur_ops->ttype,
1032 &flags, &gpnum, &completed);
1033 page += sprintf(page,
1034 "??? Writer stall state %d g%lu c%lu f%#x\n",
1035 rcu_torture_writer_state,
1036 gpnum, completed, flags);
1037 }
1038 rtcv_snap = rcu_torture_current_version;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001039}
1040
1041/*
1042 * Print torture statistics. Caller must ensure that there is only
1043 * one call to this function at a given time!!! This is normally
1044 * accomplished by relying on the module system to only have one copy
1045 * of the module loaded, and then by giving the rcu_torture_stats
1046 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1047 * thread is not running).
1048 */
1049static void
1050rcu_torture_stats_print(void)
1051{
Chen Gangd1008952013-11-07 10:30:25 +08001052 int size = nr_cpu_ids * 200 + 8192;
1053 char *buf;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001054
Chen Gangd1008952013-11-07 10:30:25 +08001055 buf = kmalloc(size, GFP_KERNEL);
1056 if (!buf) {
1057 pr_err("rcu-torture: Out of memory, need: %d", size);
1058 return;
1059 }
1060 rcu_torture_printk(buf);
1061 pr_alert("%s", buf);
1062 kfree(buf);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001063}
1064
1065/*
1066 * Periodically prints torture statistics, if periodic statistics printing
1067 * was specified via the stat_interval module parameter.
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001068 */
1069static int
1070rcu_torture_stats(void *arg)
1071{
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001072 VERBOSE_TOROUT_STRING("rcu_torture_stats task started");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001073 do {
1074 schedule_timeout_interruptible(stat_interval * HZ);
1075 rcu_torture_stats_print();
Paul E. McKenneyf67a3352014-01-29 07:40:27 -08001076 torture_shutdown_absorb("rcu_torture_stats");
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001077 } while (!torture_must_stop());
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001078 torture_kthread_stopping("rcu_torture_stats");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001079 return 0;
1080}
1081
Paul E. McKenney95c38322006-03-24 03:15:58 -08001082static inline void
Steven Rostedt (Red Hat)e66c33d2013-07-12 16:50:28 -04001083rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag)
Paul E. McKenney95c38322006-03-24 03:15:58 -08001084{
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001085 pr_alert("%s" TORTURE_FLAG
1086 "--- %s: nreaders=%d nfakewriters=%d "
1087 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1088 "shuffle_interval=%d stutter=%d irqreader=%d "
1089 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1090 "test_boost=%d/%d test_boost_interval=%d "
1091 "test_boost_duration=%d shutdown_secs=%d "
Paul E. McKenney67afeed2012-10-20 12:56:06 -07001092 "stall_cpu=%d stall_cpu_holdoff=%d "
1093 "n_barrier_cbs=%d "
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001094 "onoff_interval=%d onoff_holdoff=%d\n",
1095 torture_type, tag, nrealreaders, nfakewriters,
1096 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
1097 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1098 test_boost, cur_ops->can_boost,
1099 test_boost_interval, test_boost_duration, shutdown_secs,
Paul E. McKenney67afeed2012-10-20 12:56:06 -07001100 stall_cpu, stall_cpu_holdoff,
1101 n_barrier_cbs,
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001102 onoff_interval, onoff_holdoff);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001103}
1104
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001105static void rcutorture_booster_cleanup(int cpu)
1106{
1107 struct task_struct *t;
1108
1109 if (boost_tasks[cpu] == NULL)
1110 return;
1111 mutex_lock(&boost_mutex);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001112 t = boost_tasks[cpu];
1113 boost_tasks[cpu] = NULL;
1114 mutex_unlock(&boost_mutex);
1115
1116 /* This must be outside of the mutex, otherwise deadlock! */
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001117 torture_stop_kthread(rcu_torture_boost, t);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001118}
1119
1120static int rcutorture_booster_init(int cpu)
1121{
1122 int retval;
1123
1124 if (boost_tasks[cpu] != NULL)
1125 return 0; /* Already created, nothing more to do. */
1126
1127 /* Don't allow time recalculation while creating a new task. */
1128 mutex_lock(&boost_mutex);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001129 VERBOSE_TOROUT_STRING("Creating rcu_torture_boost task");
Eric Dumazet1f288092011-06-16 15:53:18 -07001130 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1131 cpu_to_node(cpu),
1132 "rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001133 if (IS_ERR(boost_tasks[cpu])) {
1134 retval = PTR_ERR(boost_tasks[cpu]);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001135 VERBOSE_TOROUT_STRING("rcu_torture_boost task create failed");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001136 n_rcu_torture_boost_ktrerror++;
1137 boost_tasks[cpu] = NULL;
1138 mutex_unlock(&boost_mutex);
1139 return retval;
1140 }
1141 kthread_bind(boost_tasks[cpu], cpu);
1142 wake_up_process(boost_tasks[cpu]);
1143 mutex_unlock(&boost_mutex);
1144 return 0;
1145}
1146
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001147/*
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001148 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1149 * induces a CPU stall for the time specified by stall_cpu.
1150 */
Paul Gortmaker49fb4c62013-06-19 14:52:21 -04001151static int rcu_torture_stall(void *args)
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001152{
1153 unsigned long stop_at;
1154
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001155 VERBOSE_TOROUT_STRING("rcu_torture_stall task started");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001156 if (stall_cpu_holdoff > 0) {
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001157 VERBOSE_TOROUT_STRING("rcu_torture_stall begin holdoff");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001158 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001159 VERBOSE_TOROUT_STRING("rcu_torture_stall end holdoff");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001160 }
1161 if (!kthread_should_stop()) {
1162 stop_at = get_seconds() + stall_cpu;
1163 /* RCU CPU stall is expected behavior in following code. */
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001164 pr_alert("rcu_torture_stall start.\n");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001165 rcu_read_lock();
1166 preempt_disable();
1167 while (ULONG_CMP_LT(get_seconds(), stop_at))
1168 continue; /* Induce RCU CPU stall warning. */
1169 preempt_enable();
1170 rcu_read_unlock();
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001171 pr_alert("rcu_torture_stall end.\n");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001172 }
Paul E. McKenneyf67a3352014-01-29 07:40:27 -08001173 torture_shutdown_absorb("rcu_torture_stall");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001174 while (!kthread_should_stop())
1175 schedule_timeout_interruptible(10 * HZ);
1176 return 0;
1177}
1178
1179/* Spawn CPU-stall kthread, if stall_cpu specified. */
1180static int __init rcu_torture_stall_init(void)
1181{
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001182 if (stall_cpu <= 0)
1183 return 0;
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001184 return torture_create_kthread(rcu_torture_stall, NULL, stall_task);
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001185}
1186
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001187/* Callback function for RCU barrier testing. */
Rashika Kheriab3b8a4d2014-02-27 17:16:57 +05301188static void rcu_torture_barrier_cbf(struct rcu_head *rcu)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001189{
1190 atomic_inc(&barrier_cbs_invoked);
1191}
1192
1193/* kthread function to register callbacks used to test RCU barriers. */
1194static int rcu_torture_barrier_cbs(void *arg)
1195{
1196 long myid = (long)arg;
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001197 bool lastphase = 0;
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001198 bool newphase;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001199 struct rcu_head rcu;
1200
1201 init_rcu_head_on_stack(&rcu);
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001202 VERBOSE_TOROUT_STRING("rcu_torture_barrier_cbs task started");
Linus Torvalds971eae72014-03-31 11:21:19 -07001203 set_user_nice(current, MAX_NICE);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001204 do {
1205 wait_event(barrier_cbs_wq[myid],
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001206 (newphase =
1207 ACCESS_ONCE(barrier_phase)) != lastphase ||
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001208 torture_must_stop());
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001209 lastphase = newphase;
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001210 smp_mb(); /* ensure barrier_phase load before ->call(). */
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001211 if (torture_must_stop())
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001212 break;
1213 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1214 if (atomic_dec_and_test(&barrier_cbs_count))
1215 wake_up(&barrier_wq);
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001216 } while (!torture_must_stop());
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001217 cur_ops->cb_barrier();
1218 destroy_rcu_head_on_stack(&rcu);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001219 torture_kthread_stopping("rcu_torture_barrier_cbs");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001220 return 0;
1221}
1222
1223/* kthread function to drive and coordinate RCU barrier testing. */
1224static int rcu_torture_barrier(void *arg)
1225{
1226 int i;
1227
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001228 VERBOSE_TOROUT_STRING("rcu_torture_barrier task starting");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001229 do {
1230 atomic_set(&barrier_cbs_invoked, 0);
1231 atomic_set(&barrier_cbs_count, n_barrier_cbs);
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001232 smp_mb(); /* Ensure barrier_phase after prior assignments. */
1233 barrier_phase = !barrier_phase;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001234 for (i = 0; i < n_barrier_cbs; i++)
1235 wake_up(&barrier_cbs_wq[i]);
1236 wait_event(barrier_wq,
1237 atomic_read(&barrier_cbs_count) == 0 ||
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001238 torture_must_stop());
1239 if (torture_must_stop())
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001240 break;
1241 n_barrier_attempts++;
Paul E. McKenney78e4bc32013-09-24 15:04:06 -07001242 cur_ops->cb_barrier(); /* Implies smp_mb() for wait_event(). */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001243 if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
1244 n_rcu_torture_barrier_error++;
1245 WARN_ON_ONCE(1);
1246 }
1247 n_barrier_successes++;
1248 schedule_timeout_interruptible(HZ / 10);
Paul E. McKenney36970bb2014-01-30 15:49:29 -08001249 } while (!torture_must_stop());
Paul E. McKenney7fafaac2014-01-31 17:37:28 -08001250 torture_kthread_stopping("rcu_torture_barrier");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001251 return 0;
1252}
1253
1254/* Initialize RCU barrier testing. */
1255static int rcu_torture_barrier_init(void)
1256{
1257 int i;
1258 int ret;
1259
1260 if (n_barrier_cbs == 0)
1261 return 0;
1262 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001263 pr_alert("%s" TORTURE_FLAG
1264 " Call or barrier ops missing for %s,\n",
1265 torture_type, cur_ops->name);
1266 pr_alert("%s" TORTURE_FLAG
1267 " RCU barrier testing omitted from run.\n",
1268 torture_type);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001269 return 0;
1270 }
1271 atomic_set(&barrier_cbs_count, 0);
1272 atomic_set(&barrier_cbs_invoked, 0);
1273 barrier_cbs_tasks =
1274 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
1275 GFP_KERNEL);
1276 barrier_cbs_wq =
1277 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
1278 GFP_KERNEL);
Sasha Levinde5e6432012-12-20 14:11:28 -05001279 if (barrier_cbs_tasks == NULL || !barrier_cbs_wq)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001280 return -ENOMEM;
1281 for (i = 0; i < n_barrier_cbs; i++) {
1282 init_waitqueue_head(&barrier_cbs_wq[i]);
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001283 ret = torture_create_kthread(rcu_torture_barrier_cbs,
1284 (void *)(long)i,
1285 barrier_cbs_tasks[i]);
1286 if (ret)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001287 return ret;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001288 }
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001289 return torture_create_kthread(rcu_torture_barrier, NULL, barrier_task);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001290}
1291
1292/* Clean up after RCU barrier testing. */
1293static void rcu_torture_barrier_cleanup(void)
1294{
1295 int i;
1296
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001297 torture_stop_kthread(rcu_torture_barrier, barrier_task);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001298 if (barrier_cbs_tasks != NULL) {
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001299 for (i = 0; i < n_barrier_cbs; i++)
1300 torture_stop_kthread(rcu_torture_barrier_cbs,
1301 barrier_cbs_tasks[i]);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001302 kfree(barrier_cbs_tasks);
1303 barrier_cbs_tasks = NULL;
1304 }
1305 if (barrier_cbs_wq != NULL) {
1306 kfree(barrier_cbs_wq);
1307 barrier_cbs_wq = NULL;
1308 }
1309}
1310
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001311static int rcutorture_cpu_notify(struct notifier_block *self,
1312 unsigned long action, void *hcpu)
1313{
1314 long cpu = (long)hcpu;
1315
1316 switch (action) {
1317 case CPU_ONLINE:
1318 case CPU_DOWN_FAILED:
1319 (void)rcutorture_booster_init(cpu);
1320 break;
1321 case CPU_DOWN_PREPARE:
1322 rcutorture_booster_cleanup(cpu);
1323 break;
1324 default:
1325 break;
1326 }
1327 return NOTIFY_OK;
1328}
1329
1330static struct notifier_block rcutorture_cpu_nb = {
1331 .notifier_call = rcutorture_cpu_notify,
1332};
1333
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001334static void
1335rcu_torture_cleanup(void)
1336{
1337 int i;
1338
Paul E. McKenney4a298652011-04-03 21:33:51 -07001339 rcutorture_record_test_transition();
Paul E. McKenneycc47ae02014-01-30 14:21:11 -08001340 if (torture_cleanup()) {
Paul E. McKenney343e9092008-12-15 16:13:07 -08001341 if (cur_ops->cb_barrier != NULL)
1342 cur_ops->cb_barrier();
1343 return;
1344 }
Paul E. McKenney3808dc92014-01-28 15:29:21 -08001345
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001346 rcu_torture_barrier_cleanup();
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001347 torture_stop_kthread(rcu_torture_stall, stall_task);
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001348 torture_stop_kthread(rcu_torture_writer, writer_task);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001349
Josh Triplettc8e5b162007-05-08 00:33:20 -07001350 if (reader_tasks) {
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001351 for (i = 0; i < nrealreaders; i++)
1352 torture_stop_kthread(rcu_torture_reader,
1353 reader_tasks[i]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001354 kfree(reader_tasks);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001355 }
1356 rcu_torture_current = NULL;
1357
Josh Triplettc8e5b162007-05-08 00:33:20 -07001358 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001359 for (i = 0; i < nfakewriters; i++) {
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001360 torture_stop_kthread(rcu_torture_fakewriter,
1361 fakewriter_tasks[i]);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001362 }
1363 kfree(fakewriter_tasks);
1364 fakewriter_tasks = NULL;
1365 }
1366
Paul E. McKenney9c029b82014-02-04 11:47:08 -08001367 torture_stop_kthread(rcu_torture_stats, stats_task);
1368 torture_stop_kthread(rcu_torture_fqs, fqs_task);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001369 if ((test_boost == 1 && cur_ops->can_boost) ||
1370 test_boost == 2) {
1371 unregister_cpu_notifier(&rcutorture_cpu_nb);
1372 for_each_possible_cpu(i)
1373 rcutorture_booster_cleanup(i);
1374 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001375
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001376 /* Wait for all RCU callbacks to fire. */
Paul E. McKenney23269742008-05-12 21:21:05 +02001377
1378 if (cur_ops->cb_barrier != NULL)
1379 cur_ops->cb_barrier();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001380
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001381 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001382
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001383 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001384 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
Paul E. McKenney2e9e8082014-01-28 15:58:22 -08001385 else if (torture_onoff_failures())
Paul E. McKenney091541b2012-01-10 12:51:14 -08001386 rcu_torture_print_module_parms(cur_ops,
1387 "End of test: RCU_HOTPLUG");
Paul E. McKenney95c38322006-03-24 03:15:58 -08001388 else
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001389 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001390}
1391
Paul E. McKenneyd2818df2013-04-23 17:05:42 -07001392#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1393static void rcu_torture_leak_cb(struct rcu_head *rhp)
1394{
1395}
1396
1397static void rcu_torture_err_cb(struct rcu_head *rhp)
1398{
1399 /*
1400 * This -might- happen due to race conditions, but is unlikely.
1401 * The scenario that leads to this happening is that the
1402 * first of the pair of duplicate callbacks is queued,
1403 * someone else starts a grace period that includes that
1404 * callback, then the second of the pair must wait for the
1405 * next grace period. Unlikely, but can happen. If it
1406 * does happen, the debug-objects subsystem won't have splatted.
1407 */
1408 pr_alert("rcutorture: duplicated callback was invoked.\n");
1409}
1410#endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1411
1412/*
1413 * Verify that double-free causes debug-objects to complain, but only
1414 * if CONFIG_DEBUG_OBJECTS_RCU_HEAD=y. Otherwise, say that the test
1415 * cannot be carried out.
1416 */
1417static void rcu_test_debug_objects(void)
1418{
1419#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1420 struct rcu_head rh1;
1421 struct rcu_head rh2;
1422
1423 init_rcu_head_on_stack(&rh1);
1424 init_rcu_head_on_stack(&rh2);
1425 pr_alert("rcutorture: WARN: Duplicate call_rcu() test starting.\n");
1426
1427 /* Try to queue the rh2 pair of callbacks for the same grace period. */
1428 preempt_disable(); /* Prevent preemption from interrupting test. */
1429 rcu_read_lock(); /* Make it impossible to finish a grace period. */
1430 call_rcu(&rh1, rcu_torture_leak_cb); /* Start grace period. */
1431 local_irq_disable(); /* Make it harder to start a new grace period. */
1432 call_rcu(&rh2, rcu_torture_leak_cb);
1433 call_rcu(&rh2, rcu_torture_err_cb); /* Duplicate callback. */
1434 local_irq_enable();
1435 rcu_read_unlock();
1436 preempt_enable();
1437
1438 /* Wait for them all to get done so we can safely return. */
1439 rcu_barrier();
1440 pr_alert("rcutorture: WARN: Duplicate call_rcu() test complete.\n");
1441 destroy_rcu_head_on_stack(&rh1);
1442 destroy_rcu_head_on_stack(&rh2);
1443#else /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1444 pr_alert("rcutorture: !CONFIG_DEBUG_OBJECTS_RCU_HEAD, not testing duplicate call_rcu()\n");
1445#endif /* #else #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1446}
1447
Josh Triplett6f8bc5002007-05-08 00:25:24 -07001448static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001449rcu_torture_init(void)
1450{
1451 int i;
1452 int cpu;
1453 int firsterr = 0;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001454 static struct rcu_torture_ops *torture_ops[] = {
Paul E. McKenneyff20e252014-02-06 08:45:56 -08001455 &rcu_ops, &rcu_bh_ops, &rcu_busted_ops, &srcu_ops, &sched_ops,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001456 };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001457
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001458 torture_init_begin(torture_type, verbose, &rcutorture_runnable);
Paul E. McKenney343e9092008-12-15 16:13:07 -08001459
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001460 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001461 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001462 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001463 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001464 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001465 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001466 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001467 pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
1468 torture_type);
1469 pr_alert("rcu-torture types:");
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001470 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001471 pr_alert(" %s", torture_ops[i]->name);
1472 pr_alert("\n");
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -08001473 torture_init_end();
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001474 return -EINVAL;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001475 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001476 if (cur_ops->fqs == NULL && fqs_duration != 0) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001477 pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001478 fqs_duration = 0;
1479 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001480 if (cur_ops->init)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001481 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1482
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001483 if (nreaders >= 0)
1484 nrealreaders = nreaders;
1485 else
1486 nrealreaders = 2 * num_online_cpus();
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001487 rcu_torture_print_module_parms(cur_ops, "Start of test");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001488
1489 /* Set up the freelist. */
1490
1491 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07001492 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08001493 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001494 list_add_tail(&rcu_tortures[i].rtort_free,
1495 &rcu_torture_freelist);
1496 }
1497
1498 /* Initialize the statistics so that each run gets its own numbers. */
1499
1500 rcu_torture_current = NULL;
1501 rcu_torture_current_version = 0;
1502 atomic_set(&n_rcu_torture_alloc, 0);
1503 atomic_set(&n_rcu_torture_alloc_fail, 0);
1504 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001505 atomic_set(&n_rcu_torture_mberror, 0);
1506 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001507 n_rcu_torture_barrier_error = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001508 n_rcu_torture_boost_ktrerror = 0;
1509 n_rcu_torture_boost_rterror = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001510 n_rcu_torture_boost_failure = 0;
1511 n_rcu_torture_boosts = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001512 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1513 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001514 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001515 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1516 per_cpu(rcu_torture_count, cpu)[i] = 0;
1517 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1518 }
1519 }
1520
1521 /* Start up the kthreads. */
1522
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001523 firsterr = torture_create_kthread(rcu_torture_writer, NULL,
1524 writer_task);
1525 if (firsterr)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001526 goto unwind;
Josh Triplettb772e1d2006-10-04 02:17:13 -07001527 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001528 GFP_KERNEL);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001529 if (fakewriter_tasks == NULL) {
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001530 VERBOSE_TOROUT_ERRSTRING("out of memory");
Josh Triplettb772e1d2006-10-04 02:17:13 -07001531 firsterr = -ENOMEM;
1532 goto unwind;
1533 }
1534 for (i = 0; i < nfakewriters; i++) {
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001535 firsterr = torture_create_kthread(rcu_torture_fakewriter,
1536 NULL, fakewriter_tasks[i]);
1537 if (firsterr)
Josh Triplettb772e1d2006-10-04 02:17:13 -07001538 goto unwind;
Josh Triplettb772e1d2006-10-04 02:17:13 -07001539 }
Josh Triplett2860aab2006-10-04 02:17:11 -07001540 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001541 GFP_KERNEL);
1542 if (reader_tasks == NULL) {
Paul E. McKenney5ccf60f2014-01-29 07:25:25 -08001543 VERBOSE_TOROUT_ERRSTRING("out of memory");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001544 firsterr = -ENOMEM;
1545 goto unwind;
1546 }
1547 for (i = 0; i < nrealreaders; i++) {
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001548 firsterr = torture_create_kthread(rcu_torture_reader, NULL,
1549 reader_tasks[i]);
1550 if (firsterr)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001551 goto unwind;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001552 }
1553 if (stat_interval > 0) {
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001554 firsterr = torture_create_kthread(rcu_torture_stats, NULL,
1555 stats_task);
1556 if (firsterr)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001557 goto unwind;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001558 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001559 if (test_no_idle_hz) {
Paul E. McKenney3808dc92014-01-28 15:29:21 -08001560 firsterr = torture_shuffle_init(shuffle_interval * HZ);
1561 if (firsterr)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001562 goto unwind;
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001563 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001564 if (stutter < 0)
1565 stutter = 0;
1566 if (stutter) {
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001567 firsterr = torture_stutter_init(stutter * HZ);
1568 if (firsterr)
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001569 goto unwind;
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001570 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001571 if (fqs_duration < 0)
1572 fqs_duration = 0;
1573 if (fqs_duration) {
Paul E. McKenney628edaa2014-01-31 11:57:43 -08001574 /* Create the fqs thread */
Paul E. McKenney47cf29b2014-02-03 11:52:27 -08001575 torture_create_kthread(rcu_torture_fqs, NULL, fqs_task);
1576 if (firsterr)
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001577 goto unwind;
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001578 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001579 if (test_boost_interval < 1)
1580 test_boost_interval = 1;
1581 if (test_boost_duration < 2)
1582 test_boost_duration = 2;
1583 if ((test_boost == 1 && cur_ops->can_boost) ||
1584 test_boost == 2) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001585
1586 boost_starttime = jiffies + test_boost_interval * HZ;
1587 register_cpu_notifier(&rcutorture_cpu_nb);
1588 for_each_possible_cpu(i) {
1589 if (cpu_is_offline(i))
1590 continue; /* Heuristic: CPU can go offline. */
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001591 firsterr = rcutorture_booster_init(i);
1592 if (firsterr)
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001593 goto unwind;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001594 }
1595 }
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001596 firsterr = torture_shutdown_init(shutdown_secs, rcu_torture_cleanup);
1597 if (firsterr)
Paul E. McKenneye991dbc2014-01-31 14:52:13 -08001598 goto unwind;
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001599 firsterr = torture_onoff_init(onoff_holdoff * HZ, onoff_interval * HZ);
1600 if (firsterr)
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001601 goto unwind;
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001602 firsterr = rcu_torture_stall_init();
1603 if (firsterr)
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001604 goto unwind;
Paul E. McKenney01025eb2014-01-31 15:15:02 -08001605 firsterr = rcu_torture_barrier_init();
1606 if (firsterr)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001607 goto unwind;
Paul E. McKenneyd2818df2013-04-23 17:05:42 -07001608 if (object_debug)
1609 rcu_test_debug_objects();
Paul E. McKenney4a298652011-04-03 21:33:51 -07001610 rcutorture_record_test_transition();
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -08001611 torture_init_end();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001612 return 0;
1613
1614unwind:
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -08001615 torture_init_end();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001616 rcu_torture_cleanup();
1617 return firsterr;
1618}
1619
1620module_init(rcu_torture_init);
1621module_exit(rcu_torture_cleanup);