blob: e3a1244eeb569c039186f909e2357d1964f03d8b [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
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
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. McKenneya241ec62005-10-30 15:03:12 -080051
52MODULE_LICENSE("GPL");
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -070053MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@freedesktop.org>");
Paul E. McKenneya241ec62005-10-30 15:03:12 -080054
Paul E. McKenneyd10453e2013-06-13 15:12:24 -070055static int fqs_duration;
Paul E. McKenneybf66f182010-01-04 15:09:10 -080056module_param(fqs_duration, int, 0444);
Paul E. McKenneyd10453e2013-06-13 15:12:24 -070057MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us), 0 to disable");
58static int fqs_holdoff;
Paul E. McKenneybf66f182010-01-04 15:09:10 -080059module_param(fqs_holdoff, int, 0444);
60MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)");
Paul E. McKenneyd10453e2013-06-13 15:12:24 -070061static int fqs_stutter = 3;
Paul E. McKenneybf66f182010-01-04 15:09:10 -080062module_param(fqs_stutter, int, 0444);
63MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)");
Paul E. McKenneyd10453e2013-06-13 15:12:24 -070064static bool gp_exp;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -070065module_param(gp_exp, bool, 0444);
66MODULE_PARM_DESC(gp_exp, "Use expedited GP wait primitives");
Paul E. McKenneyd10453e2013-06-13 15:12:24 -070067static bool gp_normal;
68module_param(gp_normal, bool, 0444);
69MODULE_PARM_DESC(gp_normal, "Use normal (non-expedited) GP wait primitives");
70static int irqreader = 1;
71module_param(irqreader, int, 0444);
72MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
73static int n_barrier_cbs;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -080074module_param(n_barrier_cbs, int, 0444);
75MODULE_PARM_DESC(n_barrier_cbs, "# of callbacks/kthreads for barrier testing");
Paul E. McKenneyd10453e2013-06-13 15:12:24 -070076static int nfakewriters = 4;
77module_param(nfakewriters, int, 0444);
78MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
79static int nreaders = -1;
80module_param(nreaders, int, 0444);
81MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
82static int object_debug;
Paul E. McKenneyd2818df2013-04-23 17:05:42 -070083module_param(object_debug, int, 0444);
84MODULE_PARM_DESC(object_debug, "Enable debug-object double call_rcu() testing");
Paul E. McKenneyd10453e2013-06-13 15:12:24 -070085static int onoff_holdoff;
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -080086module_param(onoff_holdoff, int, 0444);
87MODULE_PARM_DESC(onoff_holdoff, "Time after boot before CPU hotplugs (s)");
Paul E. McKenneyd10453e2013-06-13 15:12:24 -070088static int onoff_interval;
89module_param(onoff_interval, int, 0444);
90MODULE_PARM_DESC(onoff_interval, "Time between CPU hotplugs (s), 0=disable");
91static int shuffle_interval = 3;
92module_param(shuffle_interval, int, 0444);
93MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
94static int shutdown_secs;
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -070095module_param(shutdown_secs, int, 0444);
Paul E. McKenneyd10453e2013-06-13 15:12:24 -070096MODULE_PARM_DESC(shutdown_secs, "Shutdown time (s), <= zero to disable.");
97static int stall_cpu;
Paul E. McKenneyc13f3752012-01-20 15:36:33 -080098module_param(stall_cpu, int, 0444);
99MODULE_PARM_DESC(stall_cpu, "Stall duration (s), zero to disable.");
Paul E. McKenneyd10453e2013-06-13 15:12:24 -0700100static int stall_cpu_holdoff = 10;
Paul E. McKenneyc13f3752012-01-20 15:36:33 -0800101module_param(stall_cpu_holdoff, int, 0444);
102MODULE_PARM_DESC(stall_cpu_holdoff, "Time to wait before starting stall (s).");
Paul E. McKenneyd10453e2013-06-13 15:12:24 -0700103static int stat_interval = 60;
104module_param(stat_interval, int, 0644);
105MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
106static int stutter = 5;
107module_param(stutter, int, 0444);
108MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
109static int test_boost = 1;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700110module_param(test_boost, int, 0444);
111MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
Paul E. McKenneyd10453e2013-06-13 15:12:24 -0700112static int test_boost_duration = 4;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700113module_param(test_boost_duration, int, 0444);
114MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds.");
Paul E. McKenneyd10453e2013-06-13 15:12:24 -0700115static int test_boost_interval = 7;
116module_param(test_boost_interval, int, 0444);
117MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds.");
118static bool test_no_idle_hz = true;
119module_param(test_no_idle_hz, bool, 0444);
120MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
121static char *torture_type = "rcu";
Josh Triplettd6ad6712007-03-06 01:42:13 -0800122module_param(torture_type, charp, 0444);
Paul E. McKenneyd10453e2013-06-13 15:12:24 -0700123MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)");
124static bool verbose;
125module_param(verbose, bool, 0444);
126MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700127
128#define TORTURE_FLAG "-torture:"
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800129#define PRINTK_STRING(s) \
Paul E. McKenney2caa1e42012-08-09 16:30:45 -0700130 do { pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800131#define VERBOSE_PRINTK_STRING(s) \
Paul E. McKenney2caa1e42012-08-09 16:30:45 -0700132 do { if (verbose) pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800133#define VERBOSE_PRINTK_ERRSTRING(s) \
Paul E. McKenney2caa1e42012-08-09 16:30:45 -0700134 do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800135
136static char printk_buf[4096];
137
138static int nrealreaders;
139static struct task_struct *writer_task;
Josh Triplettb772e1d2006-10-04 02:17:13 -0700140static struct task_struct **fakewriter_tasks;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800141static struct task_struct **reader_tasks;
142static struct task_struct *stats_task;
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800143static struct task_struct *shuffler_task;
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700144static struct task_struct *stutter_task;
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800145static struct task_struct *fqs_task;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700146static struct task_struct *boost_tasks[NR_CPUS];
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700147static struct task_struct *shutdown_task;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -0800148#ifdef CONFIG_HOTPLUG_CPU
149static struct task_struct *onoff_task;
150#endif /* #ifdef CONFIG_HOTPLUG_CPU */
Paul E. McKenneyc13f3752012-01-20 15:36:33 -0800151static struct task_struct *stall_task;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800152static struct task_struct **barrier_cbs_tasks;
153static struct task_struct *barrier_task;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800154
155#define RCU_TORTURE_PIPE_LEN 10
156
157struct rcu_torture {
158 struct rcu_head rtort_rcu;
159 int rtort_pipe_count;
160 struct list_head rtort_free;
Paul E. McKenney996417d2005-11-18 01:10:50 -0800161 int rtort_mbtest;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800162};
163
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800164static LIST_HEAD(rcu_torture_freelist);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700165static struct rcu_torture __rcu *rcu_torture_current;
Paul E. McKenney4a298652011-04-03 21:33:51 -0700166static unsigned long rcu_torture_current_version;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800167static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
168static DEFINE_SPINLOCK(rcu_torture_lock);
169static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
170 { 0 };
171static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
172 { 0 };
173static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700174static atomic_t n_rcu_torture_alloc;
175static atomic_t n_rcu_torture_alloc_fail;
176static atomic_t n_rcu_torture_free;
177static atomic_t n_rcu_torture_mberror;
178static atomic_t n_rcu_torture_error;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800179static long n_rcu_torture_barrier_error;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700180static long n_rcu_torture_boost_ktrerror;
181static long n_rcu_torture_boost_rterror;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700182static long n_rcu_torture_boost_failure;
183static long n_rcu_torture_boosts;
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700184static long n_rcu_torture_timers;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -0800185static long n_offline_attempts;
186static long n_offline_successes;
Paul E. McKenney13dbf912012-07-23 12:05:55 -0700187static unsigned long sum_offline;
188static int min_offline = -1;
189static int max_offline;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -0800190static long n_online_attempts;
191static long n_online_successes;
Paul E. McKenney13dbf912012-07-23 12:05:55 -0700192static unsigned long sum_online;
193static int min_online = -1;
194static int max_online;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800195static long n_barrier_attempts;
196static long n_barrier_successes;
Josh Triplette3033732006-10-04 02:17:14 -0700197static struct list_head rcu_torture_removed;
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600198static cpumask_var_t shuffle_tmp_mask;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800199
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700200static int stutter_pause_test;
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700201
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700202#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
203#define RCUTORTURE_RUNNABLE_INIT 1
204#else
205#define RCUTORTURE_RUNNABLE_INIT 0
206#endif
207int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
Paul E. McKenneybb3bf702011-11-04 13:24:07 -0700208module_param(rcutorture_runnable, int, 0444);
209MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot");
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700210
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700211#if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700212#define rcu_can_boost() 1
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700213#else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700214#define rcu_can_boost() 0
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700215#endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700216
Steven Rostedte4aa0da2013-02-04 13:36:13 -0500217#ifdef CONFIG_RCU_TRACE
218static u64 notrace rcu_trace_clock_local(void)
219{
220 u64 ts = trace_clock_local();
221 unsigned long __maybe_unused ts_rem = do_div(ts, NSEC_PER_USEC);
222 return ts;
223}
224#else /* #ifdef CONFIG_RCU_TRACE */
225static u64 notrace rcu_trace_clock_local(void)
226{
227 return 0ULL;
228}
229#endif /* #else #ifdef CONFIG_RCU_TRACE */
230
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700231static unsigned long shutdown_time; /* jiffies to system shutdown. */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700232static unsigned long boost_starttime; /* jiffies of next boost test start. */
233DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
234 /* and boost task create/destroy. */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800235static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -0700236static bool barrier_phase; /* Test phase. */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800237static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */
238static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */
239static DECLARE_WAIT_QUEUE_HEAD(barrier_wq);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700240
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800241/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
242
243#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
244#define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
245#define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
246static int fullstop = FULLSTOP_RMMOD;
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700247/*
248 * Protect fullstop transitions and spawning of kthreads.
249 */
250static DEFINE_MUTEX(fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800251
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700252/* Forward reference. */
253static void rcu_torture_cleanup(void);
254
Paul E. McKenney343e9092008-12-15 16:13:07 -0800255/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800256 * Detect and respond to a system shutdown.
Paul E. McKenney343e9092008-12-15 16:13:07 -0800257 */
258static int
259rcutorture_shutdown_notify(struct notifier_block *unused1,
260 unsigned long unused2, void *unused3)
261{
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800262 mutex_lock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800263 if (fullstop == FULLSTOP_DONTSTOP)
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800264 fullstop = FULLSTOP_SHUTDOWN;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800265 else
Paul E. McKenney2caa1e42012-08-09 16:30:45 -0700266 pr_warn(/* but going down anyway, so... */
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800267 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800268 mutex_unlock(&fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800269 return NOTIFY_DONE;
270}
271
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800272/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800273 * Absorb kthreads into a kernel function that won't return, so that
274 * they won't ever access module text or data again.
275 */
Steven Rostedt (Red Hat)e66c33d2013-07-12 16:50:28 -0400276static void rcutorture_shutdown_absorb(const char *title)
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800277{
278 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -0700279 pr_notice(
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800280 "rcutorture thread %s parking due to system shutdown\n",
281 title);
282 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
283 }
284}
285
286/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800287 * Allocate an element from the rcu_tortures pool.
288 */
Adrian Bunk97a41e22006-01-08 01:02:17 -0800289static struct rcu_torture *
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800290rcu_torture_alloc(void)
291{
292 struct list_head *p;
293
Ingo Molnaradac1662006-01-25 19:50:12 +0100294 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800295 if (list_empty(&rcu_torture_freelist)) {
296 atomic_inc(&n_rcu_torture_alloc_fail);
Ingo Molnaradac1662006-01-25 19:50:12 +0100297 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800298 return NULL;
299 }
300 atomic_inc(&n_rcu_torture_alloc);
301 p = rcu_torture_freelist.next;
302 list_del_init(p);
Ingo Molnaradac1662006-01-25 19:50:12 +0100303 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800304 return container_of(p, struct rcu_torture, rtort_free);
305}
306
307/*
308 * Free an element to the rcu_tortures pool.
309 */
310static void
311rcu_torture_free(struct rcu_torture *p)
312{
313 atomic_inc(&n_rcu_torture_free);
Ingo Molnaradac1662006-01-25 19:50:12 +0100314 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800315 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
Ingo Molnaradac1662006-01-25 19:50:12 +0100316 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800317}
318
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800319struct rcu_random_state {
320 unsigned long rrs_state;
Josh Triplett75cfef32006-10-04 02:17:12 -0700321 long rrs_count;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800322};
323
324#define RCU_RANDOM_MULT 39916801 /* prime */
325#define RCU_RANDOM_ADD 479001701 /* prime */
326#define RCU_RANDOM_REFRESH 10000
327
328#define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
329
330/*
331 * Crude but fast random-number generator. Uses a linear congruential
Paul E. McKenneyc17ac852007-10-16 23:27:19 -0700332 * generator, with occasional help from cpu_clock().
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800333 */
Josh Triplett75cfef32006-10-04 02:17:12 -0700334static unsigned long
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800335rcu_random(struct rcu_random_state *rrsp)
336{
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800337 if (--rrsp->rrs_count < 0) {
Peter Zijlstrac6763292010-05-25 10:48:51 +0200338 rrsp->rrs_state += (unsigned long)local_clock();
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800339 rrsp->rrs_count = RCU_RANDOM_REFRESH;
340 }
341 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
342 return swahw32(rrsp->rrs_state);
343}
344
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700345static void
Steven Rostedt (Red Hat)e66c33d2013-07-12 16:50:28 -0400346rcu_stutter_wait(const char *title)
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700347{
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800348 while (stutter_pause_test || !rcutorture_runnable) {
Paul E. McKenneye3d7be22008-06-22 13:06:38 -0700349 if (rcutorture_runnable)
350 schedule_timeout_interruptible(1);
351 else
Paul E. McKenney3ccf79f2008-06-22 14:02:55 -0700352 schedule_timeout_interruptible(round_jiffies_relative(HZ));
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800353 rcutorture_shutdown_absorb(title);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800354 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700355}
356
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800357/*
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700358 * Operations vector for selecting different types of tests.
359 */
360
361struct rcu_torture_ops {
362 void (*init)(void);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700363 int (*readlock)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700364 void (*read_delay)(struct rcu_random_state *rrsp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700365 void (*readunlock)(int idx);
366 int (*completed)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700367 void (*deferred_free)(struct rcu_torture *p);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700368 void (*sync)(void);
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700369 void (*exp_sync)(void);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800370 void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu));
Paul E. McKenney23269742008-05-12 21:21:05 +0200371 void (*cb_barrier)(void);
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800372 void (*fqs)(void);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700373 int (*stats)(char *page);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700374 int irq_capable;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700375 int can_boost;
Steven Rostedt (Red Hat)e66c33d2013-07-12 16:50:28 -0400376 const char *name;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700377};
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700378
379static struct rcu_torture_ops *cur_ops;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700380
381/*
382 * Definitions for rcu torture testing.
383 */
384
Josh Tripletta49a4af2006-09-29 01:59:30 -0700385static int rcu_torture_read_lock(void) __acquires(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700386{
387 rcu_read_lock();
388 return 0;
389}
390
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700391static void rcu_read_delay(struct rcu_random_state *rrsp)
392{
Josh Triplettb8d57a72009-09-08 15:54:35 -0700393 const unsigned long shortdelay_us = 200;
394 const unsigned long longdelay_ms = 50;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700395
Josh Triplettb8d57a72009-09-08 15:54:35 -0700396 /* We want a short delay sometimes to make a reader delay the grace
397 * period, and we want a long delay occasionally to trigger
398 * force_quiescent_state. */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700399
Josh Triplettb8d57a72009-09-08 15:54:35 -0700400 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
401 mdelay(longdelay_ms);
402 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
403 udelay(shortdelay_us);
Lai Jiangshane546f482010-06-21 16:57:42 +0800404#ifdef CONFIG_PREEMPT
405 if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000)))
406 preempt_schedule(); /* No QS if preempt_disable() in effect */
407#endif
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700408}
409
Josh Tripletta49a4af2006-09-29 01:59:30 -0700410static void rcu_torture_read_unlock(int idx) __releases(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700411{
412 rcu_read_unlock();
413}
414
415static int rcu_torture_completed(void)
416{
417 return rcu_batches_completed();
418}
419
420static void
421rcu_torture_cb(struct rcu_head *p)
422{
423 int i;
424 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
425
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800426 if (fullstop != FULLSTOP_DONTSTOP) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700427 /* Test is ending, just drop callbacks on the floor. */
428 /* The next initialization will pick up the pieces. */
429 return;
430 }
431 i = rp->rtort_pipe_count;
432 if (i > RCU_TORTURE_PIPE_LEN)
433 i = RCU_TORTURE_PIPE_LEN;
434 atomic_inc(&rcu_torture_wcount[i]);
435 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
436 rp->rtort_mbtest = 0;
437 rcu_torture_free(rp);
Paul E. McKenneyc701d5d2012-06-28 08:08:25 -0700438 } else {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700439 cur_ops->deferred_free(rp);
Paul E. McKenneyc701d5d2012-06-28 08:08:25 -0700440 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700441}
442
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800443static int rcu_no_completed(void)
444{
445 return 0;
446}
447
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700448static void rcu_torture_deferred_free(struct rcu_torture *p)
449{
450 call_rcu(&p->rtort_rcu, rcu_torture_cb);
451}
452
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700453static void rcu_sync_torture_init(void)
454{
455 INIT_LIST_HEAD(&rcu_torture_removed);
456}
457
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700458static struct rcu_torture_ops rcu_ops = {
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700459 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700460 .readlock = rcu_torture_read_lock,
461 .read_delay = rcu_read_delay,
462 .readunlock = rcu_torture_read_unlock,
463 .completed = rcu_torture_completed,
464 .deferred_free = rcu_torture_deferred_free,
465 .sync = synchronize_rcu,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700466 .exp_sync = synchronize_rcu_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800467 .call = call_rcu,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700468 .cb_barrier = rcu_barrier,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800469 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700470 .stats = NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700471 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700472 .can_boost = rcu_can_boost(),
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700473 .name = "rcu"
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700474};
475
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700476/*
477 * Definitions for rcu_bh torture testing.
478 */
479
Josh Tripletta49a4af2006-09-29 01:59:30 -0700480static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700481{
482 rcu_read_lock_bh();
483 return 0;
484}
485
Josh Tripletta49a4af2006-09-29 01:59:30 -0700486static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700487{
488 rcu_read_unlock_bh();
489}
490
491static int rcu_bh_torture_completed(void)
492{
493 return rcu_batches_completed_bh();
494}
495
496static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
497{
498 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
499}
500
501static struct rcu_torture_ops rcu_bh_ops = {
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700502 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700503 .readlock = rcu_bh_torture_read_lock,
504 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
505 .readunlock = rcu_bh_torture_read_unlock,
506 .completed = rcu_bh_torture_completed,
507 .deferred_free = rcu_bh_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700508 .sync = synchronize_rcu_bh,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700509 .exp_sync = synchronize_rcu_bh_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800510 .call = call_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700511 .cb_barrier = rcu_barrier_bh,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800512 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700513 .stats = NULL,
514 .irq_capable = 1,
515 .name = "rcu_bh"
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700516};
517
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700518/*
519 * Definitions for srcu torture testing.
520 */
521
Lai Jiangshancda4dc82012-10-13 01:14:17 +0800522DEFINE_STATIC_SRCU(srcu_ctl);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700523
Josh Triplett012d3ca2006-12-06 20:40:19 -0800524static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700525{
526 return srcu_read_lock(&srcu_ctl);
527}
528
529static void srcu_read_delay(struct rcu_random_state *rrsp)
530{
531 long delay;
532 const long uspertick = 1000000 / HZ;
533 const long longdelay = 10;
534
535 /* We want there to be long-running readers, but not all the time. */
536
537 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
538 if (!delay)
539 schedule_timeout_interruptible(longdelay);
Lai Jiangshane546f482010-06-21 16:57:42 +0800540 else
541 rcu_read_delay(rrsp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700542}
543
Josh Triplett012d3ca2006-12-06 20:40:19 -0800544static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700545{
546 srcu_read_unlock(&srcu_ctl, idx);
547}
548
549static int srcu_torture_completed(void)
550{
551 return srcu_batches_completed(&srcu_ctl);
552}
553
Lai Jiangshan9059c942012-03-19 16:12:14 +0800554static void srcu_torture_deferred_free(struct rcu_torture *rp)
555{
556 call_srcu(&srcu_ctl, &rp->rtort_rcu, rcu_torture_cb);
557}
558
Josh Triplettb772e1d2006-10-04 02:17:13 -0700559static void srcu_torture_synchronize(void)
560{
561 synchronize_srcu(&srcu_ctl);
562}
563
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700564static void srcu_torture_call(struct rcu_head *head,
565 void (*func)(struct rcu_head *head))
566{
567 call_srcu(&srcu_ctl, head, func);
568}
569
570static void srcu_torture_barrier(void)
571{
572 srcu_barrier(&srcu_ctl);
573}
574
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700575static int srcu_torture_stats(char *page)
576{
577 int cnt = 0;
578 int cpu;
579 int idx = srcu_ctl.completed & 0x1;
580
581 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
582 torture_type, TORTURE_FLAG, idx);
583 for_each_possible_cpu(cpu) {
Paul E. McKenneycef50122012-02-05 07:42:44 -0800584 cnt += sprintf(&page[cnt], " %d(%lu,%lu)", cpu,
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700585 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
586 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
587 }
588 cnt += sprintf(&page[cnt], "\n");
589 return cnt;
590}
591
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700592static void srcu_torture_synchronize_expedited(void)
593{
594 synchronize_srcu_expedited(&srcu_ctl);
595}
596
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700597static struct rcu_torture_ops srcu_ops = {
Lai Jiangshancda4dc82012-10-13 01:14:17 +0800598 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700599 .readlock = srcu_torture_read_lock,
600 .read_delay = srcu_read_delay,
601 .readunlock = srcu_torture_read_unlock,
602 .completed = srcu_torture_completed,
Lai Jiangshan9059c942012-03-19 16:12:14 +0800603 .deferred_free = srcu_torture_deferred_free,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700604 .sync = srcu_torture_synchronize,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700605 .exp_sync = srcu_torture_synchronize_expedited,
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700606 .call = srcu_torture_call,
607 .cb_barrier = srcu_torture_barrier,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700608 .stats = srcu_torture_stats,
609 .name = "srcu"
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700610};
611
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700612/*
613 * Definitions for sched torture testing.
614 */
615
616static int sched_torture_read_lock(void)
617{
618 preempt_disable();
619 return 0;
620}
621
622static void sched_torture_read_unlock(int idx)
623{
624 preempt_enable();
625}
626
Paul E. McKenney23269742008-05-12 21:21:05 +0200627static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
628{
629 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
630}
631
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700632static struct rcu_torture_ops sched_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700633 .init = rcu_sync_torture_init,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700634 .readlock = sched_torture_read_lock,
635 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
636 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800637 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700638 .deferred_free = rcu_sched_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700639 .sync = synchronize_sched,
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700640 .exp_sync = synchronize_sched_expedited,
641 .call = call_rcu_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700642 .cb_barrier = rcu_barrier_sched,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800643 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700644 .stats = NULL,
645 .irq_capable = 1,
646 .name = "sched"
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700647};
648
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700649/*
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700650 * RCU torture priority-boost testing. Runs one real-time thread per
651 * CPU for moderate bursts, repeatedly registering RCU callbacks and
652 * spinning waiting for them to be invoked. If a given callback takes
653 * too long to be invoked, we assume that priority inversion has occurred.
654 */
655
656struct rcu_boost_inflight {
657 struct rcu_head rcu;
658 int inflight;
659};
660
661static void rcu_torture_boost_cb(struct rcu_head *head)
662{
663 struct rcu_boost_inflight *rbip =
664 container_of(head, struct rcu_boost_inflight, rcu);
665
666 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
667 rbip->inflight = 0;
668}
669
670static int rcu_torture_boost(void *arg)
671{
672 unsigned long call_rcu_time;
673 unsigned long endtime;
674 unsigned long oldstarttime;
675 struct rcu_boost_inflight rbi = { .inflight = 0 };
676 struct sched_param sp;
677
678 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
679
680 /* Set real-time priority. */
681 sp.sched_priority = 1;
682 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
683 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
684 n_rcu_torture_boost_rterror++;
685 }
686
Paul E. McKenney561190e2011-03-30 09:10:44 -0700687 init_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700688 /* Each pass through the following loop does one boost-test cycle. */
689 do {
690 /* Wait for the next test interval. */
691 oldstarttime = boost_starttime;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700692 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
Paul E. McKenney0e11c8e2013-01-10 16:21:07 -0800693 schedule_timeout_interruptible(oldstarttime - jiffies);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700694 rcu_stutter_wait("rcu_torture_boost");
695 if (kthread_should_stop() ||
696 fullstop != FULLSTOP_DONTSTOP)
697 goto checkwait;
698 }
699
700 /* Do one boost-test interval. */
701 endtime = oldstarttime + test_boost_duration * HZ;
702 call_rcu_time = jiffies;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700703 while (ULONG_CMP_LT(jiffies, endtime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700704 /* If we don't have a callback in flight, post one. */
705 if (!rbi.inflight) {
706 smp_mb(); /* RCU core before ->inflight = 1. */
707 rbi.inflight = 1;
708 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
709 if (jiffies - call_rcu_time >
710 test_boost_duration * HZ - HZ / 2) {
711 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
712 n_rcu_torture_boost_failure++;
713 }
714 call_rcu_time = jiffies;
715 }
716 cond_resched();
717 rcu_stutter_wait("rcu_torture_boost");
718 if (kthread_should_stop() ||
719 fullstop != FULLSTOP_DONTSTOP)
720 goto checkwait;
721 }
722
723 /*
724 * Set the start time of the next test interval.
725 * Yes, this is vulnerable to long delays, but such
726 * delays simply cause a false negative for the next
727 * interval. Besides, we are running at RT priority,
728 * so delays should be relatively rare.
729 */
Paul E. McKenneyab8f11e2011-08-18 09:30:32 -0700730 while (oldstarttime == boost_starttime &&
731 !kthread_should_stop()) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700732 if (mutex_trylock(&boost_mutex)) {
733 boost_starttime = jiffies +
734 test_boost_interval * HZ;
735 n_rcu_torture_boosts++;
736 mutex_unlock(&boost_mutex);
737 break;
738 }
739 schedule_timeout_uninterruptible(1);
740 }
741
742 /* Go do the stutter. */
743checkwait: rcu_stutter_wait("rcu_torture_boost");
744 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
745
746 /* Clean up and exit. */
747 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
748 rcutorture_shutdown_absorb("rcu_torture_boost");
749 while (!kthread_should_stop() || rbi.inflight)
750 schedule_timeout_uninterruptible(1);
751 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
Paul E. McKenney9d681972011-06-21 01:48:03 -0700752 destroy_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700753 return 0;
754}
755
756/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800757 * RCU torture force-quiescent-state kthread. Repeatedly induces
758 * bursts of calls to force_quiescent_state(), increasing the probability
759 * of occurrence of some important types of race conditions.
760 */
761static int
762rcu_torture_fqs(void *arg)
763{
764 unsigned long fqs_resume_time;
765 int fqs_burst_remaining;
766
767 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
768 do {
769 fqs_resume_time = jiffies + fqs_stutter * HZ;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700770 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
771 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800772 schedule_timeout_interruptible(1);
773 }
774 fqs_burst_remaining = fqs_duration;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700775 while (fqs_burst_remaining > 0 &&
776 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800777 cur_ops->fqs();
778 udelay(fqs_holdoff);
779 fqs_burst_remaining -= fqs_holdoff;
780 }
781 rcu_stutter_wait("rcu_torture_fqs");
782 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
783 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
784 rcutorture_shutdown_absorb("rcu_torture_fqs");
785 while (!kthread_should_stop())
786 schedule_timeout_uninterruptible(1);
787 return 0;
788}
789
790/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800791 * RCU torture writer kthread. Repeatedly substitutes a new structure
792 * for that pointed to by rcu_torture_current, freeing the old structure
793 * after a series of grace periods (the "pipeline").
794 */
795static int
796rcu_torture_writer(void *arg)
797{
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700798 bool exp;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800799 int i;
800 long oldbatch = rcu_batches_completed();
801 struct rcu_torture *rp;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700802 struct rcu_torture *rp1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800803 struct rcu_torture *old_rp;
804 static DEFINE_RCU_RANDOM(rand);
805
806 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800807 set_user_nice(current, 19);
808
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800809 do {
810 schedule_timeout_uninterruptible(1);
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700811 rp = rcu_torture_alloc();
812 if (rp == NULL)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800813 continue;
814 rp->rtort_pipe_count = 0;
815 udelay(rcu_random(&rand) & 0x3ff);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700816 old_rp = rcu_dereference_check(rcu_torture_current,
817 current == writer_task);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800818 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800819 rcu_assign_pointer(rcu_torture_current, rp);
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700820 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
Josh Triplettc8e5b162007-05-08 00:33:20 -0700821 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800822 i = old_rp->rtort_pipe_count;
823 if (i > RCU_TORTURE_PIPE_LEN)
824 i = RCU_TORTURE_PIPE_LEN;
825 atomic_inc(&rcu_torture_wcount[i]);
826 old_rp->rtort_pipe_count++;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700827 if (gp_normal == gp_exp)
828 exp = !!(rcu_random(&rand) & 0x80);
829 else
830 exp = gp_exp;
831 if (!exp) {
832 cur_ops->deferred_free(old_rp);
833 } else {
834 cur_ops->exp_sync();
835 list_add(&old_rp->rtort_free,
836 &rcu_torture_removed);
837 list_for_each_entry_safe(rp, rp1,
838 &rcu_torture_removed,
839 rtort_free) {
840 i = rp->rtort_pipe_count;
841 if (i > RCU_TORTURE_PIPE_LEN)
842 i = RCU_TORTURE_PIPE_LEN;
843 atomic_inc(&rcu_torture_wcount[i]);
844 if (++rp->rtort_pipe_count >=
845 RCU_TORTURE_PIPE_LEN) {
846 rp->rtort_mbtest = 0;
847 list_del(&rp->rtort_free);
848 rcu_torture_free(rp);
849 }
850 }
851 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800852 }
Paul E. McKenney4a298652011-04-03 21:33:51 -0700853 rcutorture_record_progress(++rcu_torture_current_version);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700854 oldbatch = cur_ops->completed();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800855 rcu_stutter_wait("rcu_torture_writer");
856 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800857 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800858 rcutorture_shutdown_absorb("rcu_torture_writer");
859 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800860 schedule_timeout_uninterruptible(1);
861 return 0;
862}
863
864/*
Josh Triplettb772e1d2006-10-04 02:17:13 -0700865 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
866 * delay between calls.
867 */
868static int
869rcu_torture_fakewriter(void *arg)
870{
871 DEFINE_RCU_RANDOM(rand);
872
873 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
874 set_user_nice(current, 19);
875
876 do {
877 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
878 udelay(rcu_random(&rand) & 0x3ff);
Paul E. McKenney72472a02012-05-29 17:50:51 -0700879 if (cur_ops->cb_barrier != NULL &&
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700880 rcu_random(&rand) % (nfakewriters * 8) == 0) {
Paul E. McKenney72472a02012-05-29 17:50:51 -0700881 cur_ops->cb_barrier();
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700882 } else if (gp_normal == gp_exp) {
883 if (rcu_random(&rand) & 0x80)
884 cur_ops->sync();
885 else
886 cur_ops->exp_sync();
887 } else if (gp_normal) {
Paul E. McKenney72472a02012-05-29 17:50:51 -0700888 cur_ops->sync();
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -0700889 } else {
890 cur_ops->exp_sync();
891 }
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800892 rcu_stutter_wait("rcu_torture_fakewriter");
893 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700894
895 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800896 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
897 while (!kthread_should_stop())
Josh Triplettb772e1d2006-10-04 02:17:13 -0700898 schedule_timeout_uninterruptible(1);
899 return 0;
900}
901
Paul E. McKenney91afaf32011-10-02 07:44:32 -0700902void rcutorture_trace_dump(void)
903{
904 static atomic_t beenhere = ATOMIC_INIT(0);
905
906 if (atomic_read(&beenhere))
907 return;
908 if (atomic_xchg(&beenhere, 1) != 0)
909 return;
Paul E. McKenney91afaf32011-10-02 07:44:32 -0700910 ftrace_dump(DUMP_ALL);
911}
912
Josh Triplettb772e1d2006-10-04 02:17:13 -0700913/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700914 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
915 * incrementing the corresponding element of the pipeline array. The
916 * counter in the element should never be greater than 1, otherwise, the
917 * RCU implementation is broken.
918 */
919static void rcu_torture_timer(unsigned long unused)
920{
921 int idx;
922 int completed;
Paul E. McKenney52494532012-11-14 16:26:40 -0800923 int completed_end;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700924 static DEFINE_RCU_RANDOM(rand);
925 static DEFINE_SPINLOCK(rand_lock);
926 struct rcu_torture *p;
927 int pipe_count;
Paul E. McKenney52494532012-11-14 16:26:40 -0800928 unsigned long long ts;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700929
930 idx = cur_ops->readlock();
931 completed = cur_ops->completed();
Steven Rostedte4aa0da2013-02-04 13:36:13 -0500932 ts = rcu_trace_clock_local();
Paul E. McKenney632ee202010-02-22 17:04:45 -0800933 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -0800934 rcu_read_lock_bh_held() ||
935 rcu_read_lock_sched_held() ||
936 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700937 if (p == NULL) {
938 /* Leave because rcu_torture_writer is not yet underway */
939 cur_ops->readunlock(idx);
940 return;
941 }
942 if (p->rtort_mbtest == 0)
943 atomic_inc(&n_rcu_torture_mberror);
944 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700945 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700946 n_rcu_torture_timers++;
947 spin_unlock(&rand_lock);
948 preempt_disable();
949 pipe_count = p->rtort_pipe_count;
950 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
951 /* Should not happen, but... */
952 pipe_count = RCU_TORTURE_PIPE_LEN;
953 }
Paul E. McKenney52494532012-11-14 16:26:40 -0800954 completed_end = cur_ops->completed();
955 if (pipe_count > 1) {
Paul E. McKenney52494532012-11-14 16:26:40 -0800956 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, ts,
957 completed, completed_end);
Paul E. McKenney91afaf32011-10-02 07:44:32 -0700958 rcutorture_trace_dump();
Paul E. McKenney52494532012-11-14 16:26:40 -0800959 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +0900960 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney52494532012-11-14 16:26:40 -0800961 completed = completed_end - completed;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700962 if (completed > RCU_TORTURE_PIPE_LEN) {
963 /* Should not happen, but... */
964 completed = RCU_TORTURE_PIPE_LEN;
965 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +0900966 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700967 preempt_enable();
968 cur_ops->readunlock(idx);
969}
970
971/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800972 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
973 * incrementing the corresponding element of the pipeline array. The
974 * counter in the element should never be greater than 1, otherwise, the
975 * RCU implementation is broken.
976 */
977static int
978rcu_torture_reader(void *arg)
979{
980 int completed;
Paul E. McKenney52494532012-11-14 16:26:40 -0800981 int completed_end;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700982 int idx;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800983 DEFINE_RCU_RANDOM(rand);
984 struct rcu_torture *p;
985 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700986 struct timer_list t;
Paul E. McKenney52494532012-11-14 16:26:40 -0800987 unsigned long long ts;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800988
989 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800990 set_user_nice(current, 19);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700991 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700992 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800993
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800994 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700995 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700996 if (!timer_pending(&t))
Paul E. McKenney6155fec2010-02-22 17:05:04 -0800997 mod_timer(&t, jiffies + 1);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700998 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700999 idx = cur_ops->readlock();
1000 completed = cur_ops->completed();
Steven Rostedte4aa0da2013-02-04 13:36:13 -05001001 ts = rcu_trace_clock_local();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001002 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001003 rcu_read_lock_bh_held() ||
1004 rcu_read_lock_sched_held() ||
1005 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001006 if (p == NULL) {
1007 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001008 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001009 schedule_timeout_interruptible(HZ);
1010 continue;
1011 }
Paul E. McKenney996417d2005-11-18 01:10:50 -08001012 if (p->rtort_mbtest == 0)
1013 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001014 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001015 preempt_disable();
1016 pipe_count = p->rtort_pipe_count;
1017 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1018 /* Should not happen, but... */
1019 pipe_count = RCU_TORTURE_PIPE_LEN;
1020 }
Paul E. McKenney52494532012-11-14 16:26:40 -08001021 completed_end = cur_ops->completed();
1022 if (pipe_count > 1) {
Paul E. McKenney52494532012-11-14 16:26:40 -08001023 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu,
1024 ts, completed, completed_end);
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001025 rcutorture_trace_dump();
Paul E. McKenney52494532012-11-14 16:26:40 -08001026 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001027 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney52494532012-11-14 16:26:40 -08001028 completed = completed_end - completed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001029 if (completed > RCU_TORTURE_PIPE_LEN) {
1030 /* Should not happen, but... */
1031 completed = RCU_TORTURE_PIPE_LEN;
1032 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001033 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001034 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001035 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001036 schedule();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001037 rcu_stutter_wait("rcu_torture_reader");
1038 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001039 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001040 rcutorture_shutdown_absorb("rcu_torture_reader");
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001041 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001042 del_timer_sync(&t);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001043 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001044 schedule_timeout_uninterruptible(1);
1045 return 0;
1046}
1047
1048/*
1049 * Create an RCU-torture statistics message in the specified buffer.
1050 */
1051static int
1052rcu_torture_printk(char *page)
1053{
1054 int cnt = 0;
1055 int cpu;
1056 int i;
1057 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1058 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1059
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001060 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001061 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1062 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1063 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1064 }
1065 }
1066 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1067 if (pipesummary[i] != 0)
1068 break;
1069 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001070 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001071 cnt += sprintf(&page[cnt],
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -07001072 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001073 rcu_torture_current,
1074 rcu_torture_current_version,
1075 list_empty(&rcu_torture_freelist),
1076 atomic_read(&n_rcu_torture_alloc),
1077 atomic_read(&n_rcu_torture_alloc_fail),
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -07001078 atomic_read(&n_rcu_torture_free));
1079 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001080 atomic_read(&n_rcu_torture_mberror),
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001081 n_rcu_torture_boost_ktrerror,
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -07001082 n_rcu_torture_boost_rterror);
1083 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001084 n_rcu_torture_boost_failure,
1085 n_rcu_torture_boosts,
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -07001086 n_rcu_torture_timers);
Paul E. McKenney13dbf912012-07-23 12:05:55 -07001087 cnt += sprintf(&page[cnt],
1088 "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ",
1089 n_online_successes, n_online_attempts,
1090 n_offline_successes, n_offline_attempts,
1091 min_online, max_online,
1092 min_offline, max_offline,
1093 sum_online, sum_offline, HZ);
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -07001094 cnt += sprintf(&page[cnt], "barrier: %ld/%ld:%ld",
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001095 n_barrier_successes,
1096 n_barrier_attempts,
1097 n_rcu_torture_barrier_error);
1098 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001099 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001100 n_rcu_torture_barrier_error != 0 ||
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001101 n_rcu_torture_boost_ktrerror != 0 ||
1102 n_rcu_torture_boost_rterror != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001103 n_rcu_torture_boost_failure != 0 ||
1104 i > 1) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001105 cnt += sprintf(&page[cnt], "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -08001106 atomic_inc(&n_rcu_torture_error);
Ingo Molnar5af970a2008-06-18 10:09:48 +02001107 WARN_ON_ONCE(1);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001108 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001109 cnt += sprintf(&page[cnt], "Reader Pipe: ");
1110 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1111 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001112 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001113 cnt += sprintf(&page[cnt], "Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001114 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001115 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001116 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001117 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
1118 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1119 cnt += sprintf(&page[cnt], " %d",
1120 atomic_read(&rcu_torture_wcount[i]));
1121 }
1122 cnt += sprintf(&page[cnt], "\n");
Josh Triplettc8e5b162007-05-08 00:33:20 -07001123 if (cur_ops->stats)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001124 cnt += cur_ops->stats(&page[cnt]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001125 return cnt;
1126}
1127
1128/*
1129 * Print torture statistics. Caller must ensure that there is only
1130 * one call to this function at a given time!!! This is normally
1131 * accomplished by relying on the module system to only have one copy
1132 * of the module loaded, and then by giving the rcu_torture_stats
1133 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1134 * thread is not running).
1135 */
1136static void
1137rcu_torture_stats_print(void)
1138{
1139 int cnt;
1140
1141 cnt = rcu_torture_printk(printk_buf);
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001142 pr_alert("%s", printk_buf);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001143}
1144
1145/*
1146 * Periodically prints torture statistics, if periodic statistics printing
1147 * was specified via the stat_interval module parameter.
1148 *
1149 * No need to worry about fullstop here, since this one doesn't reference
1150 * volatile state or register callbacks.
1151 */
1152static int
1153rcu_torture_stats(void *arg)
1154{
1155 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1156 do {
1157 schedule_timeout_interruptible(stat_interval * HZ);
1158 rcu_torture_stats_print();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001159 rcutorture_shutdown_absorb("rcu_torture_stats");
1160 } while (!kthread_should_stop());
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001161 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1162 return 0;
1163}
1164
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001165static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
1166
1167/* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1168 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1169 */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -07001170static void rcu_torture_shuffle_tasks(void)
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001171{
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001172 int i;
1173
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001174 cpumask_setall(shuffle_tmp_mask);
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001175 get_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001176
1177 /* No point in shuffling if there is only one online CPU (ex: UP) */
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001178 if (num_online_cpus() == 1) {
1179 put_online_cpus();
1180 return;
1181 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001182
1183 if (rcu_idle_cpu != -1)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001184 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001185
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001186 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001187
Josh Triplettc8e5b162007-05-08 00:33:20 -07001188 if (reader_tasks) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001189 for (i = 0; i < nrealreaders; i++)
1190 if (reader_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001191 set_cpus_allowed_ptr(reader_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001192 shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001193 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001194 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001195 for (i = 0; i < nfakewriters; i++)
1196 if (fakewriter_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001197 set_cpus_allowed_ptr(fakewriter_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001198 shuffle_tmp_mask);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001199 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001200 if (writer_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001201 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001202 if (stats_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001203 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
Paul E. McKenney0e11c8e2013-01-10 16:21:07 -08001204 if (stutter_task)
1205 set_cpus_allowed_ptr(stutter_task, shuffle_tmp_mask);
1206 if (fqs_task)
1207 set_cpus_allowed_ptr(fqs_task, shuffle_tmp_mask);
1208 if (shutdown_task)
1209 set_cpus_allowed_ptr(shutdown_task, shuffle_tmp_mask);
1210#ifdef CONFIG_HOTPLUG_CPU
1211 if (onoff_task)
1212 set_cpus_allowed_ptr(onoff_task, shuffle_tmp_mask);
1213#endif /* #ifdef CONFIG_HOTPLUG_CPU */
1214 if (stall_task)
1215 set_cpus_allowed_ptr(stall_task, shuffle_tmp_mask);
1216 if (barrier_cbs_tasks)
1217 for (i = 0; i < n_barrier_cbs; i++)
1218 if (barrier_cbs_tasks[i])
1219 set_cpus_allowed_ptr(barrier_cbs_tasks[i],
1220 shuffle_tmp_mask);
1221 if (barrier_task)
1222 set_cpus_allowed_ptr(barrier_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001223
1224 if (rcu_idle_cpu == -1)
1225 rcu_idle_cpu = num_online_cpus() - 1;
1226 else
1227 rcu_idle_cpu--;
1228
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001229 put_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001230}
1231
1232/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1233 * system to become idle at a time and cut off its timer ticks. This is meant
1234 * to test the support for such tickless idle CPU in RCU.
1235 */
1236static int
1237rcu_torture_shuffle(void *arg)
1238{
1239 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1240 do {
1241 schedule_timeout_interruptible(shuffle_interval * HZ);
1242 rcu_torture_shuffle_tasks();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001243 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1244 } while (!kthread_should_stop());
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001245 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1246 return 0;
1247}
1248
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001249/* Cause the rcutorture test to "stutter", starting and stopping all
1250 * threads periodically.
1251 */
1252static int
1253rcu_torture_stutter(void *arg)
1254{
1255 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1256 do {
1257 schedule_timeout_interruptible(stutter * HZ);
1258 stutter_pause_test = 1;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001259 if (!kthread_should_stop())
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001260 schedule_timeout_interruptible(stutter * HZ);
1261 stutter_pause_test = 0;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001262 rcutorture_shutdown_absorb("rcu_torture_stutter");
1263 } while (!kthread_should_stop());
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001264 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1265 return 0;
1266}
1267
Paul E. McKenney95c38322006-03-24 03:15:58 -08001268static inline void
Steven Rostedt (Red Hat)e66c33d2013-07-12 16:50:28 -04001269rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag)
Paul E. McKenney95c38322006-03-24 03:15:58 -08001270{
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001271 pr_alert("%s" TORTURE_FLAG
1272 "--- %s: nreaders=%d nfakewriters=%d "
1273 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1274 "shuffle_interval=%d stutter=%d irqreader=%d "
1275 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1276 "test_boost=%d/%d test_boost_interval=%d "
1277 "test_boost_duration=%d shutdown_secs=%d "
Paul E. McKenney67afeed2012-10-20 12:56:06 -07001278 "stall_cpu=%d stall_cpu_holdoff=%d "
1279 "n_barrier_cbs=%d "
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001280 "onoff_interval=%d onoff_holdoff=%d\n",
1281 torture_type, tag, nrealreaders, nfakewriters,
1282 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
1283 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1284 test_boost, cur_ops->can_boost,
1285 test_boost_interval, test_boost_duration, shutdown_secs,
Paul E. McKenney67afeed2012-10-20 12:56:06 -07001286 stall_cpu, stall_cpu_holdoff,
1287 n_barrier_cbs,
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001288 onoff_interval, onoff_holdoff);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001289}
1290
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001291static struct notifier_block rcutorture_shutdown_nb = {
Paul E. McKenney343e9092008-12-15 16:13:07 -08001292 .notifier_call = rcutorture_shutdown_notify,
1293};
1294
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001295static void rcutorture_booster_cleanup(int cpu)
1296{
1297 struct task_struct *t;
1298
1299 if (boost_tasks[cpu] == NULL)
1300 return;
1301 mutex_lock(&boost_mutex);
1302 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1303 t = boost_tasks[cpu];
1304 boost_tasks[cpu] = NULL;
1305 mutex_unlock(&boost_mutex);
1306
1307 /* This must be outside of the mutex, otherwise deadlock! */
1308 kthread_stop(t);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001309 boost_tasks[cpu] = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001310}
1311
1312static int rcutorture_booster_init(int cpu)
1313{
1314 int retval;
1315
1316 if (boost_tasks[cpu] != NULL)
1317 return 0; /* Already created, nothing more to do. */
1318
1319 /* Don't allow time recalculation while creating a new task. */
1320 mutex_lock(&boost_mutex);
1321 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
Eric Dumazet1f288092011-06-16 15:53:18 -07001322 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1323 cpu_to_node(cpu),
1324 "rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001325 if (IS_ERR(boost_tasks[cpu])) {
1326 retval = PTR_ERR(boost_tasks[cpu]);
1327 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1328 n_rcu_torture_boost_ktrerror++;
1329 boost_tasks[cpu] = NULL;
1330 mutex_unlock(&boost_mutex);
1331 return retval;
1332 }
1333 kthread_bind(boost_tasks[cpu], cpu);
1334 wake_up_process(boost_tasks[cpu]);
1335 mutex_unlock(&boost_mutex);
1336 return 0;
1337}
1338
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001339/*
1340 * Cause the rcutorture test to shutdown the system after the test has
1341 * run for the time specified by the shutdown_secs module parameter.
1342 */
1343static int
1344rcu_torture_shutdown(void *arg)
1345{
1346 long delta;
1347 unsigned long jiffies_snap;
1348
1349 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1350 jiffies_snap = ACCESS_ONCE(jiffies);
1351 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
1352 !kthread_should_stop()) {
1353 delta = shutdown_time - jiffies_snap;
1354 if (verbose)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001355 pr_alert("%s" TORTURE_FLAG
1356 "rcu_torture_shutdown task: %lu jiffies remaining\n",
1357 torture_type, delta);
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001358 schedule_timeout_interruptible(delta);
1359 jiffies_snap = ACCESS_ONCE(jiffies);
1360 }
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001361 if (kthread_should_stop()) {
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001362 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1363 return 0;
1364 }
1365
1366 /* OK, shut down the system. */
1367
1368 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1369 shutdown_task = NULL; /* Avoid self-kill deadlock. */
1370 rcu_torture_cleanup(); /* Get the success/failure message. */
1371 kernel_power_off(); /* Shut down the system. */
1372 return 0;
1373}
1374
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001375#ifdef CONFIG_HOTPLUG_CPU
1376
1377/*
1378 * Execute random CPU-hotplug operations at the interval specified
1379 * by the onoff_interval.
1380 */
Paul Gortmaker49fb4c62013-06-19 14:52:21 -04001381static int
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001382rcu_torture_onoff(void *arg)
1383{
1384 int cpu;
Paul E. McKenney13dbf912012-07-23 12:05:55 -07001385 unsigned long delta;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001386 int maxcpu = -1;
1387 DEFINE_RCU_RANDOM(rand);
Paul E. McKenney48983262012-09-24 16:08:31 -07001388 int ret;
Paul E. McKenney13dbf912012-07-23 12:05:55 -07001389 unsigned long starttime;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001390
1391 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1392 for_each_online_cpu(cpu)
1393 maxcpu = cpu;
1394 WARN_ON(maxcpu < 0);
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -08001395 if (onoff_holdoff > 0) {
1396 VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff");
1397 schedule_timeout_interruptible(onoff_holdoff * HZ);
1398 VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff");
1399 }
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001400 while (!kthread_should_stop()) {
1401 cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
Paul E. McKenneyf2202422011-12-03 15:09:28 -08001402 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001403 if (verbose)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001404 pr_alert("%s" TORTURE_FLAG
1405 "rcu_torture_onoff task: offlining %d\n",
1406 torture_type, cpu);
Paul E. McKenney13dbf912012-07-23 12:05:55 -07001407 starttime = jiffies;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001408 n_offline_attempts++;
Paul E. McKenney48983262012-09-24 16:08:31 -07001409 ret = cpu_down(cpu);
1410 if (ret) {
1411 if (verbose)
1412 pr_alert("%s" TORTURE_FLAG
1413 "rcu_torture_onoff task: offline %d failed: errno %d\n",
1414 torture_type, cpu, ret);
1415 } else {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001416 if (verbose)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001417 pr_alert("%s" TORTURE_FLAG
1418 "rcu_torture_onoff task: offlined %d\n",
1419 torture_type, cpu);
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001420 n_offline_successes++;
Paul E. McKenney13dbf912012-07-23 12:05:55 -07001421 delta = jiffies - starttime;
1422 sum_offline += delta;
1423 if (min_offline < 0) {
1424 min_offline = delta;
1425 max_offline = delta;
1426 }
1427 if (min_offline > delta)
1428 min_offline = delta;
1429 if (max_offline < delta)
1430 max_offline = delta;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001431 }
Paul E. McKenneyf2202422011-12-03 15:09:28 -08001432 } else if (cpu_is_hotpluggable(cpu)) {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001433 if (verbose)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001434 pr_alert("%s" TORTURE_FLAG
1435 "rcu_torture_onoff task: onlining %d\n",
1436 torture_type, cpu);
Paul E. McKenney13dbf912012-07-23 12:05:55 -07001437 starttime = jiffies;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001438 n_online_attempts++;
1439 if (cpu_up(cpu) == 0) {
1440 if (verbose)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001441 pr_alert("%s" TORTURE_FLAG
1442 "rcu_torture_onoff task: onlined %d\n",
1443 torture_type, cpu);
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001444 n_online_successes++;
Paul E. McKenney13dbf912012-07-23 12:05:55 -07001445 delta = jiffies - starttime;
1446 sum_online += delta;
1447 if (min_online < 0) {
1448 min_online = delta;
1449 max_online = delta;
1450 }
1451 if (min_online > delta)
1452 min_online = delta;
1453 if (max_online < delta)
1454 max_online = delta;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001455 }
1456 }
1457 schedule_timeout_interruptible(onoff_interval * HZ);
1458 }
1459 VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1460 return 0;
1461}
1462
Paul Gortmaker49fb4c62013-06-19 14:52:21 -04001463static int
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001464rcu_torture_onoff_init(void)
1465{
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001466 int ret;
1467
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001468 if (onoff_interval <= 0)
1469 return 0;
1470 onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff");
1471 if (IS_ERR(onoff_task)) {
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001472 ret = PTR_ERR(onoff_task);
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001473 onoff_task = NULL;
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001474 return ret;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001475 }
1476 return 0;
1477}
1478
1479static void rcu_torture_onoff_cleanup(void)
1480{
1481 if (onoff_task == NULL)
1482 return;
1483 VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1484 kthread_stop(onoff_task);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001485 onoff_task = NULL;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001486}
1487
1488#else /* #ifdef CONFIG_HOTPLUG_CPU */
1489
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001490static int
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001491rcu_torture_onoff_init(void)
1492{
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001493 return 0;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001494}
1495
1496static void rcu_torture_onoff_cleanup(void)
1497{
1498}
1499
1500#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1501
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001502/*
1503 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1504 * induces a CPU stall for the time specified by stall_cpu.
1505 */
Paul Gortmaker49fb4c62013-06-19 14:52:21 -04001506static int rcu_torture_stall(void *args)
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001507{
1508 unsigned long stop_at;
1509
1510 VERBOSE_PRINTK_STRING("rcu_torture_stall task started");
1511 if (stall_cpu_holdoff > 0) {
1512 VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff");
1513 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
1514 VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff");
1515 }
1516 if (!kthread_should_stop()) {
1517 stop_at = get_seconds() + stall_cpu;
1518 /* RCU CPU stall is expected behavior in following code. */
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001519 pr_alert("rcu_torture_stall start.\n");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001520 rcu_read_lock();
1521 preempt_disable();
1522 while (ULONG_CMP_LT(get_seconds(), stop_at))
1523 continue; /* Induce RCU CPU stall warning. */
1524 preempt_enable();
1525 rcu_read_unlock();
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001526 pr_alert("rcu_torture_stall end.\n");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001527 }
1528 rcutorture_shutdown_absorb("rcu_torture_stall");
1529 while (!kthread_should_stop())
1530 schedule_timeout_interruptible(10 * HZ);
1531 return 0;
1532}
1533
1534/* Spawn CPU-stall kthread, if stall_cpu specified. */
1535static int __init rcu_torture_stall_init(void)
1536{
1537 int ret;
1538
1539 if (stall_cpu <= 0)
1540 return 0;
1541 stall_task = kthread_run(rcu_torture_stall, NULL, "rcu_torture_stall");
1542 if (IS_ERR(stall_task)) {
1543 ret = PTR_ERR(stall_task);
1544 stall_task = NULL;
1545 return ret;
1546 }
1547 return 0;
1548}
1549
1550/* Clean up after the CPU-stall kthread, if one was spawned. */
1551static void rcu_torture_stall_cleanup(void)
1552{
1553 if (stall_task == NULL)
1554 return;
1555 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task.");
1556 kthread_stop(stall_task);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001557 stall_task = NULL;
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001558}
1559
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001560/* Callback function for RCU barrier testing. */
1561void rcu_torture_barrier_cbf(struct rcu_head *rcu)
1562{
1563 atomic_inc(&barrier_cbs_invoked);
1564}
1565
1566/* kthread function to register callbacks used to test RCU barriers. */
1567static int rcu_torture_barrier_cbs(void *arg)
1568{
1569 long myid = (long)arg;
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001570 bool lastphase = 0;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001571 struct rcu_head rcu;
1572
1573 init_rcu_head_on_stack(&rcu);
1574 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
1575 set_user_nice(current, 19);
1576 do {
1577 wait_event(barrier_cbs_wq[myid],
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001578 barrier_phase != lastphase ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001579 kthread_should_stop() ||
1580 fullstop != FULLSTOP_DONTSTOP);
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001581 lastphase = barrier_phase;
1582 smp_mb(); /* ensure barrier_phase load before ->call(). */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001583 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1584 break;
1585 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1586 if (atomic_dec_and_test(&barrier_cbs_count))
1587 wake_up(&barrier_wq);
1588 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1589 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task stopping");
1590 rcutorture_shutdown_absorb("rcu_torture_barrier_cbs");
1591 while (!kthread_should_stop())
1592 schedule_timeout_interruptible(1);
1593 cur_ops->cb_barrier();
1594 destroy_rcu_head_on_stack(&rcu);
1595 return 0;
1596}
1597
1598/* kthread function to drive and coordinate RCU barrier testing. */
1599static int rcu_torture_barrier(void *arg)
1600{
1601 int i;
1602
1603 VERBOSE_PRINTK_STRING("rcu_torture_barrier task starting");
1604 do {
1605 atomic_set(&barrier_cbs_invoked, 0);
1606 atomic_set(&barrier_cbs_count, n_barrier_cbs);
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001607 smp_mb(); /* Ensure barrier_phase after prior assignments. */
1608 barrier_phase = !barrier_phase;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001609 for (i = 0; i < n_barrier_cbs; i++)
1610 wake_up(&barrier_cbs_wq[i]);
1611 wait_event(barrier_wq,
1612 atomic_read(&barrier_cbs_count) == 0 ||
1613 kthread_should_stop() ||
1614 fullstop != FULLSTOP_DONTSTOP);
1615 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1616 break;
1617 n_barrier_attempts++;
1618 cur_ops->cb_barrier();
1619 if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
1620 n_rcu_torture_barrier_error++;
1621 WARN_ON_ONCE(1);
1622 }
1623 n_barrier_successes++;
1624 schedule_timeout_interruptible(HZ / 10);
1625 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1626 VERBOSE_PRINTK_STRING("rcu_torture_barrier task stopping");
Paul E. McKenney143aa672012-05-24 18:17:48 -07001627 rcutorture_shutdown_absorb("rcu_torture_barrier");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001628 while (!kthread_should_stop())
1629 schedule_timeout_interruptible(1);
1630 return 0;
1631}
1632
1633/* Initialize RCU barrier testing. */
1634static int rcu_torture_barrier_init(void)
1635{
1636 int i;
1637 int ret;
1638
1639 if (n_barrier_cbs == 0)
1640 return 0;
1641 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001642 pr_alert("%s" TORTURE_FLAG
1643 " Call or barrier ops missing for %s,\n",
1644 torture_type, cur_ops->name);
1645 pr_alert("%s" TORTURE_FLAG
1646 " RCU barrier testing omitted from run.\n",
1647 torture_type);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001648 return 0;
1649 }
1650 atomic_set(&barrier_cbs_count, 0);
1651 atomic_set(&barrier_cbs_invoked, 0);
1652 barrier_cbs_tasks =
1653 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
1654 GFP_KERNEL);
1655 barrier_cbs_wq =
1656 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
1657 GFP_KERNEL);
Sasha Levinde5e6432012-12-20 14:11:28 -05001658 if (barrier_cbs_tasks == NULL || !barrier_cbs_wq)
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001659 return -ENOMEM;
1660 for (i = 0; i < n_barrier_cbs; i++) {
1661 init_waitqueue_head(&barrier_cbs_wq[i]);
1662 barrier_cbs_tasks[i] = kthread_run(rcu_torture_barrier_cbs,
Lai Jiangshan9059c942012-03-19 16:12:14 +08001663 (void *)(long)i,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001664 "rcu_torture_barrier_cbs");
1665 if (IS_ERR(barrier_cbs_tasks[i])) {
1666 ret = PTR_ERR(barrier_cbs_tasks[i]);
1667 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier_cbs");
1668 barrier_cbs_tasks[i] = NULL;
1669 return ret;
1670 }
1671 }
1672 barrier_task = kthread_run(rcu_torture_barrier, NULL,
1673 "rcu_torture_barrier");
1674 if (IS_ERR(barrier_task)) {
1675 ret = PTR_ERR(barrier_task);
1676 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier");
1677 barrier_task = NULL;
1678 }
1679 return 0;
1680}
1681
1682/* Clean up after RCU barrier testing. */
1683static void rcu_torture_barrier_cleanup(void)
1684{
1685 int i;
1686
1687 if (barrier_task != NULL) {
1688 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier task");
1689 kthread_stop(barrier_task);
1690 barrier_task = NULL;
1691 }
1692 if (barrier_cbs_tasks != NULL) {
1693 for (i = 0; i < n_barrier_cbs; i++) {
1694 if (barrier_cbs_tasks[i] != NULL) {
1695 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier_cbs task");
1696 kthread_stop(barrier_cbs_tasks[i]);
1697 barrier_cbs_tasks[i] = NULL;
1698 }
1699 }
1700 kfree(barrier_cbs_tasks);
1701 barrier_cbs_tasks = NULL;
1702 }
1703 if (barrier_cbs_wq != NULL) {
1704 kfree(barrier_cbs_wq);
1705 barrier_cbs_wq = NULL;
1706 }
1707}
1708
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001709static int rcutorture_cpu_notify(struct notifier_block *self,
1710 unsigned long action, void *hcpu)
1711{
1712 long cpu = (long)hcpu;
1713
1714 switch (action) {
1715 case CPU_ONLINE:
1716 case CPU_DOWN_FAILED:
1717 (void)rcutorture_booster_init(cpu);
1718 break;
1719 case CPU_DOWN_PREPARE:
1720 rcutorture_booster_cleanup(cpu);
1721 break;
1722 default:
1723 break;
1724 }
1725 return NOTIFY_OK;
1726}
1727
1728static struct notifier_block rcutorture_cpu_nb = {
1729 .notifier_call = rcutorture_cpu_notify,
1730};
1731
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001732static void
1733rcu_torture_cleanup(void)
1734{
1735 int i;
1736
Paul E. McKenney343e9092008-12-15 16:13:07 -08001737 mutex_lock(&fullstop_mutex);
Paul E. McKenney4a298652011-04-03 21:33:51 -07001738 rcutorture_record_test_transition();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001739 if (fullstop == FULLSTOP_SHUTDOWN) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001740 pr_warn(/* but going down anyway, so... */
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001741 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001742 mutex_unlock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001743 schedule_timeout_uninterruptible(10);
Paul E. McKenney343e9092008-12-15 16:13:07 -08001744 if (cur_ops->cb_barrier != NULL)
1745 cur_ops->cb_barrier();
1746 return;
1747 }
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001748 fullstop = FULLSTOP_RMMOD;
Paul E. McKenney343e9092008-12-15 16:13:07 -08001749 mutex_unlock(&fullstop_mutex);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001750 unregister_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001751 rcu_torture_barrier_cleanup();
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001752 rcu_torture_stall_cleanup();
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001753 if (stutter_task) {
1754 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1755 kthread_stop(stutter_task);
1756 }
1757 stutter_task = NULL;
Josh Triplettc8e5b162007-05-08 00:33:20 -07001758 if (shuffler_task) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001759 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1760 kthread_stop(shuffler_task);
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001761 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001762 }
1763 shuffler_task = NULL;
1764
Josh Triplettc8e5b162007-05-08 00:33:20 -07001765 if (writer_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001766 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1767 kthread_stop(writer_task);
1768 }
1769 writer_task = NULL;
1770
Josh Triplettc8e5b162007-05-08 00:33:20 -07001771 if (reader_tasks) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001772 for (i = 0; i < nrealreaders; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001773 if (reader_tasks[i]) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001774 VERBOSE_PRINTK_STRING(
1775 "Stopping rcu_torture_reader task");
1776 kthread_stop(reader_tasks[i]);
1777 }
1778 reader_tasks[i] = NULL;
1779 }
1780 kfree(reader_tasks);
1781 reader_tasks = NULL;
1782 }
1783 rcu_torture_current = NULL;
1784
Josh Triplettc8e5b162007-05-08 00:33:20 -07001785 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001786 for (i = 0; i < nfakewriters; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001787 if (fakewriter_tasks[i]) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001788 VERBOSE_PRINTK_STRING(
1789 "Stopping rcu_torture_fakewriter task");
1790 kthread_stop(fakewriter_tasks[i]);
1791 }
1792 fakewriter_tasks[i] = NULL;
1793 }
1794 kfree(fakewriter_tasks);
1795 fakewriter_tasks = NULL;
1796 }
1797
Josh Triplettc8e5b162007-05-08 00:33:20 -07001798 if (stats_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001799 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1800 kthread_stop(stats_task);
1801 }
1802 stats_task = NULL;
1803
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001804 if (fqs_task) {
1805 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1806 kthread_stop(fqs_task);
1807 }
1808 fqs_task = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001809 if ((test_boost == 1 && cur_ops->can_boost) ||
1810 test_boost == 2) {
1811 unregister_cpu_notifier(&rcutorture_cpu_nb);
1812 for_each_possible_cpu(i)
1813 rcutorture_booster_cleanup(i);
1814 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001815 if (shutdown_task != NULL) {
1816 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1817 kthread_stop(shutdown_task);
1818 }
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001819 shutdown_task = NULL;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001820 rcu_torture_onoff_cleanup();
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001821
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001822 /* Wait for all RCU callbacks to fire. */
Paul E. McKenney23269742008-05-12 21:21:05 +02001823
1824 if (cur_ops->cb_barrier != NULL)
1825 cur_ops->cb_barrier();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001826
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001827 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001828
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001829 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001830 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
Paul E. McKenney091541b2012-01-10 12:51:14 -08001831 else if (n_online_successes != n_online_attempts ||
1832 n_offline_successes != n_offline_attempts)
1833 rcu_torture_print_module_parms(cur_ops,
1834 "End of test: RCU_HOTPLUG");
Paul E. McKenney95c38322006-03-24 03:15:58 -08001835 else
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001836 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001837}
1838
Paul E. McKenneyd2818df2013-04-23 17:05:42 -07001839#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1840static void rcu_torture_leak_cb(struct rcu_head *rhp)
1841{
1842}
1843
1844static void rcu_torture_err_cb(struct rcu_head *rhp)
1845{
1846 /*
1847 * This -might- happen due to race conditions, but is unlikely.
1848 * The scenario that leads to this happening is that the
1849 * first of the pair of duplicate callbacks is queued,
1850 * someone else starts a grace period that includes that
1851 * callback, then the second of the pair must wait for the
1852 * next grace period. Unlikely, but can happen. If it
1853 * does happen, the debug-objects subsystem won't have splatted.
1854 */
1855 pr_alert("rcutorture: duplicated callback was invoked.\n");
1856}
1857#endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1858
1859/*
1860 * Verify that double-free causes debug-objects to complain, but only
1861 * if CONFIG_DEBUG_OBJECTS_RCU_HEAD=y. Otherwise, say that the test
1862 * cannot be carried out.
1863 */
1864static void rcu_test_debug_objects(void)
1865{
1866#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
1867 struct rcu_head rh1;
1868 struct rcu_head rh2;
1869
1870 init_rcu_head_on_stack(&rh1);
1871 init_rcu_head_on_stack(&rh2);
1872 pr_alert("rcutorture: WARN: Duplicate call_rcu() test starting.\n");
1873
1874 /* Try to queue the rh2 pair of callbacks for the same grace period. */
1875 preempt_disable(); /* Prevent preemption from interrupting test. */
1876 rcu_read_lock(); /* Make it impossible to finish a grace period. */
1877 call_rcu(&rh1, rcu_torture_leak_cb); /* Start grace period. */
1878 local_irq_disable(); /* Make it harder to start a new grace period. */
1879 call_rcu(&rh2, rcu_torture_leak_cb);
1880 call_rcu(&rh2, rcu_torture_err_cb); /* Duplicate callback. */
1881 local_irq_enable();
1882 rcu_read_unlock();
1883 preempt_enable();
1884
1885 /* Wait for them all to get done so we can safely return. */
1886 rcu_barrier();
1887 pr_alert("rcutorture: WARN: Duplicate call_rcu() test complete.\n");
1888 destroy_rcu_head_on_stack(&rh1);
1889 destroy_rcu_head_on_stack(&rh2);
1890#else /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1891 pr_alert("rcutorture: !CONFIG_DEBUG_OBJECTS_RCU_HEAD, not testing duplicate call_rcu()\n");
1892#endif /* #else #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
1893}
1894
Josh Triplett6f8bc502007-05-08 00:25:24 -07001895static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001896rcu_torture_init(void)
1897{
1898 int i;
1899 int cpu;
1900 int firsterr = 0;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001901 int retval;
Paul E. McKenney2ec1f2d2013-06-12 15:12:21 -07001902 static struct rcu_torture_ops *torture_ops[] = {
1903 &rcu_ops, &rcu_bh_ops, &srcu_ops, &sched_ops,
1904 };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001905
Paul E. McKenney343e9092008-12-15 16:13:07 -08001906 mutex_lock(&fullstop_mutex);
1907
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001908 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001909 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001910 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001911 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001912 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001913 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001914 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001915 pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
1916 torture_type);
1917 pr_alert("rcu-torture types:");
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001918 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001919 pr_alert(" %s", torture_ops[i]->name);
1920 pr_alert("\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001921 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001922 return -EINVAL;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001923 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001924 if (cur_ops->fqs == NULL && fqs_duration != 0) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001925 pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001926 fqs_duration = 0;
1927 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001928 if (cur_ops->init)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001929 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1930
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001931 if (nreaders >= 0)
1932 nrealreaders = nreaders;
1933 else
1934 nrealreaders = 2 * num_online_cpus();
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001935 rcu_torture_print_module_parms(cur_ops, "Start of test");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001936 fullstop = FULLSTOP_DONTSTOP;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001937
1938 /* Set up the freelist. */
1939
1940 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07001941 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08001942 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001943 list_add_tail(&rcu_tortures[i].rtort_free,
1944 &rcu_torture_freelist);
1945 }
1946
1947 /* Initialize the statistics so that each run gets its own numbers. */
1948
1949 rcu_torture_current = NULL;
1950 rcu_torture_current_version = 0;
1951 atomic_set(&n_rcu_torture_alloc, 0);
1952 atomic_set(&n_rcu_torture_alloc_fail, 0);
1953 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001954 atomic_set(&n_rcu_torture_mberror, 0);
1955 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001956 n_rcu_torture_barrier_error = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001957 n_rcu_torture_boost_ktrerror = 0;
1958 n_rcu_torture_boost_rterror = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001959 n_rcu_torture_boost_failure = 0;
1960 n_rcu_torture_boosts = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001961 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1962 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001963 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001964 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1965 per_cpu(rcu_torture_count, cpu)[i] = 0;
1966 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1967 }
1968 }
1969
1970 /* Start up the kthreads. */
1971
1972 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
Paul E. McKenney60f53782012-08-25 15:27:40 -07001973 writer_task = kthread_create(rcu_torture_writer, NULL,
1974 "rcu_torture_writer");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001975 if (IS_ERR(writer_task)) {
1976 firsterr = PTR_ERR(writer_task);
1977 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1978 writer_task = NULL;
1979 goto unwind;
1980 }
Paul E. McKenney60f53782012-08-25 15:27:40 -07001981 wake_up_process(writer_task);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001982 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001983 GFP_KERNEL);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001984 if (fakewriter_tasks == NULL) {
1985 VERBOSE_PRINTK_ERRSTRING("out of memory");
1986 firsterr = -ENOMEM;
1987 goto unwind;
1988 }
1989 for (i = 0; i < nfakewriters; i++) {
1990 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
1991 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001992 "rcu_torture_fakewriter");
Josh Triplettb772e1d2006-10-04 02:17:13 -07001993 if (IS_ERR(fakewriter_tasks[i])) {
1994 firsterr = PTR_ERR(fakewriter_tasks[i]);
1995 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
1996 fakewriter_tasks[i] = NULL;
1997 goto unwind;
1998 }
1999 }
Josh Triplett2860aab2006-10-04 02:17:11 -07002000 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002001 GFP_KERNEL);
2002 if (reader_tasks == NULL) {
2003 VERBOSE_PRINTK_ERRSTRING("out of memory");
2004 firsterr = -ENOMEM;
2005 goto unwind;
2006 }
2007 for (i = 0; i < nrealreaders; i++) {
2008 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
2009 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
2010 "rcu_torture_reader");
2011 if (IS_ERR(reader_tasks[i])) {
2012 firsterr = PTR_ERR(reader_tasks[i]);
2013 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
2014 reader_tasks[i] = NULL;
2015 goto unwind;
2016 }
2017 }
2018 if (stat_interval > 0) {
2019 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
2020 stats_task = kthread_run(rcu_torture_stats, NULL,
2021 "rcu_torture_stats");
2022 if (IS_ERR(stats_task)) {
2023 firsterr = PTR_ERR(stats_task);
2024 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
2025 stats_task = NULL;
2026 goto unwind;
2027 }
2028 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08002029 if (test_no_idle_hz) {
2030 rcu_idle_cpu = num_online_cpus() - 1;
Rusty Russell73d0a4b2009-03-30 22:05:16 -06002031
2032 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
2033 firsterr = -ENOMEM;
2034 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
2035 goto unwind;
2036 }
2037
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08002038 /* Create the shuffler thread */
2039 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
2040 "rcu_torture_shuffle");
2041 if (IS_ERR(shuffler_task)) {
Rusty Russell73d0a4b2009-03-30 22:05:16 -06002042 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08002043 firsterr = PTR_ERR(shuffler_task);
2044 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
2045 shuffler_task = NULL;
2046 goto unwind;
2047 }
2048 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07002049 if (stutter < 0)
2050 stutter = 0;
2051 if (stutter) {
2052 /* Create the stutter thread */
2053 stutter_task = kthread_run(rcu_torture_stutter, NULL,
2054 "rcu_torture_stutter");
2055 if (IS_ERR(stutter_task)) {
2056 firsterr = PTR_ERR(stutter_task);
2057 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
2058 stutter_task = NULL;
2059 goto unwind;
2060 }
2061 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08002062 if (fqs_duration < 0)
2063 fqs_duration = 0;
2064 if (fqs_duration) {
2065 /* Create the stutter thread */
2066 fqs_task = kthread_run(rcu_torture_fqs, NULL,
2067 "rcu_torture_fqs");
2068 if (IS_ERR(fqs_task)) {
2069 firsterr = PTR_ERR(fqs_task);
2070 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
2071 fqs_task = NULL;
2072 goto unwind;
2073 }
2074 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002075 if (test_boost_interval < 1)
2076 test_boost_interval = 1;
2077 if (test_boost_duration < 2)
2078 test_boost_duration = 2;
2079 if ((test_boost == 1 && cur_ops->can_boost) ||
2080 test_boost == 2) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002081
2082 boost_starttime = jiffies + test_boost_interval * HZ;
2083 register_cpu_notifier(&rcutorture_cpu_nb);
2084 for_each_possible_cpu(i) {
2085 if (cpu_is_offline(i))
2086 continue; /* Heuristic: CPU can go offline. */
2087 retval = rcutorture_booster_init(i);
2088 if (retval < 0) {
2089 firsterr = retval;
2090 goto unwind;
2091 }
2092 }
2093 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07002094 if (shutdown_secs > 0) {
2095 shutdown_time = jiffies + shutdown_secs * HZ;
Paul E. McKenney60f53782012-08-25 15:27:40 -07002096 shutdown_task = kthread_create(rcu_torture_shutdown, NULL,
2097 "rcu_torture_shutdown");
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07002098 if (IS_ERR(shutdown_task)) {
2099 firsterr = PTR_ERR(shutdown_task);
2100 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
2101 shutdown_task = NULL;
2102 goto unwind;
2103 }
Paul E. McKenney60f53782012-08-25 15:27:40 -07002104 wake_up_process(shutdown_task);
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07002105 }
Paul E. McKenney37e377d2012-02-17 22:12:18 -08002106 i = rcu_torture_onoff_init();
2107 if (i != 0) {
2108 firsterr = i;
2109 goto unwind;
2110 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002111 register_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08002112 i = rcu_torture_stall_init();
2113 if (i != 0) {
2114 firsterr = i;
2115 goto unwind;
2116 }
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08002117 retval = rcu_torture_barrier_init();
2118 if (retval != 0) {
2119 firsterr = retval;
2120 goto unwind;
2121 }
Paul E. McKenneyd2818df2013-04-23 17:05:42 -07002122 if (object_debug)
2123 rcu_test_debug_objects();
Paul E. McKenney4a298652011-04-03 21:33:51 -07002124 rcutorture_record_test_transition();
Paul E. McKenney343e9092008-12-15 16:13:07 -08002125 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002126 return 0;
2127
2128unwind:
Paul E. McKenney343e9092008-12-15 16:13:07 -08002129 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002130 rcu_torture_cleanup();
2131 return firsterr;
2132}
2133
2134module_init(rcu_torture_init);
2135module_exit(rcu_torture_cleanup);