blob: ce84091291b543a56444e5b6cdc166e8b54f1338 [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>
Harvey Harrisonf07767f2008-10-20 10:23:38 -070049#include <asm/byteorder.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080050
51MODULE_LICENSE("GPL");
Josh Triplettb772e1d2006-10-04 02:17:13 -070052MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and "
Paul E. McKenneya71fca52009-09-18 10:28:19 -070053 "Josh Triplett <josh@freedesktop.org>");
Paul E. McKenneya241ec62005-10-30 15:03:12 -080054
Josh Triplett48022112006-10-03 23:26:16 +020055static int nreaders = -1; /* # reader threads, defaults to 2*ncpus */
Josh Triplettb772e1d2006-10-04 02:17:13 -070056static int nfakewriters = 4; /* # fake writer threads */
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080057static int stat_interval; /* Interval between stats, in seconds. */
Paul E. McKenneya241ec62005-10-30 15:03:12 -080058 /* Defaults to "only at end of test". */
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080059static int verbose; /* Print more debug info. */
60static int test_no_idle_hz; /* Test RCU's support for tickless idle CPUs. */
Paul E. McKenneyd120f652008-06-18 05:21:44 -070061static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/
62static int stutter = 5; /* Start/stop testing interval (in sec) */
Paul E. McKenney0729fbf2008-06-25 12:24:52 -070063static int irqreader = 1; /* RCU readers from irq (timers). */
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -070064static int fqs_duration; /* Duration of bursts (us), 0 to disable. */
65static int fqs_holdoff; /* Hold time within burst (us). */
Paul E. McKenneybf66f182010-01-04 15:09:10 -080066static int fqs_stutter = 3; /* Wait time between bursts (s). */
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -070067static int shutdown_secs; /* Shutdown time (s). <=0 for no shutdown. */
Paul E. McKenney8e8be452010-09-02 16:16:14 -070068static int test_boost = 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */
69static int test_boost_interval = 7; /* Interval between boost tests, seconds. */
70static int test_boost_duration = 4; /* Duration of each boost test, seconds. */
Josh Triplett20d2e422006-10-04 02:17:15 -070071static char *torture_type = "rcu"; /* What RCU implementation to torture. */
Paul E. McKenneya241ec62005-10-30 15:03:12 -080072
Josh Triplettd6ad6712007-03-06 01:42:13 -080073module_param(nreaders, int, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080074MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
Josh Triplettd6ad6712007-03-06 01:42:13 -080075module_param(nfakewriters, int, 0444);
Josh Triplettb772e1d2006-10-04 02:17:13 -070076MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
Paul E. McKenney3721bc12011-07-21 16:00:17 -070077module_param(stat_interval, int, 0644);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080078MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
Josh Triplettd6ad6712007-03-06 01:42:13 -080079module_param(verbose, bool, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080080MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
Josh Triplettd6ad6712007-03-06 01:42:13 -080081module_param(test_no_idle_hz, bool, 0444);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080082MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
Josh Triplettd6ad6712007-03-06 01:42:13 -080083module_param(shuffle_interval, int, 0444);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080084MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
Paul E. McKenneyd120f652008-06-18 05:21:44 -070085module_param(stutter, int, 0444);
86MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
Paul E. McKenney0729fbf2008-06-25 12:24:52 -070087module_param(irqreader, int, 0444);
88MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
Paul E. McKenneybf66f182010-01-04 15:09:10 -080089module_param(fqs_duration, int, 0444);
90MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us)");
91module_param(fqs_holdoff, int, 0444);
92MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)");
93module_param(fqs_stutter, int, 0444);
94MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)");
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -070095module_param(shutdown_secs, int, 0444);
96MODULE_PARM_DESC(shutdown_secs, "Shutdown time (s), zero to disable.");
Paul E. McKenney8e8be452010-09-02 16:16:14 -070097module_param(test_boost, int, 0444);
98MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
99module_param(test_boost_interval, int, 0444);
100MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds.");
101module_param(test_boost_duration, int, 0444);
102MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds.");
Josh Triplettd6ad6712007-03-06 01:42:13 -0800103module_param(torture_type, charp, 0444);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700104MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700105
106#define TORTURE_FLAG "-torture:"
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800107#define PRINTK_STRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700108 do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800109#define VERBOSE_PRINTK_STRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700110 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800111#define VERBOSE_PRINTK_ERRSTRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700112 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800113
114static char printk_buf[4096];
115
116static int nrealreaders;
117static struct task_struct *writer_task;
Josh Triplettb772e1d2006-10-04 02:17:13 -0700118static struct task_struct **fakewriter_tasks;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800119static struct task_struct **reader_tasks;
120static struct task_struct *stats_task;
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800121static struct task_struct *shuffler_task;
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700122static struct task_struct *stutter_task;
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800123static struct task_struct *fqs_task;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700124static struct task_struct *boost_tasks[NR_CPUS];
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700125static struct task_struct *shutdown_task;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800126
127#define RCU_TORTURE_PIPE_LEN 10
128
129struct rcu_torture {
130 struct rcu_head rtort_rcu;
131 int rtort_pipe_count;
132 struct list_head rtort_free;
Paul E. McKenney996417d2005-11-18 01:10:50 -0800133 int rtort_mbtest;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800134};
135
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800136static LIST_HEAD(rcu_torture_freelist);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700137static struct rcu_torture __rcu *rcu_torture_current;
Paul E. McKenney4a298652011-04-03 21:33:51 -0700138static unsigned long rcu_torture_current_version;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800139static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
140static DEFINE_SPINLOCK(rcu_torture_lock);
141static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
142 { 0 };
143static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
144 { 0 };
145static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700146static atomic_t n_rcu_torture_alloc;
147static atomic_t n_rcu_torture_alloc_fail;
148static atomic_t n_rcu_torture_free;
149static atomic_t n_rcu_torture_mberror;
150static atomic_t n_rcu_torture_error;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700151static long n_rcu_torture_boost_ktrerror;
152static long n_rcu_torture_boost_rterror;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700153static long n_rcu_torture_boost_failure;
154static long n_rcu_torture_boosts;
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700155static long n_rcu_torture_timers;
Josh Triplette3033732006-10-04 02:17:14 -0700156static struct list_head rcu_torture_removed;
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600157static cpumask_var_t shuffle_tmp_mask;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800158
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700159static int stutter_pause_test;
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700160
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700161#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
162#define RCUTORTURE_RUNNABLE_INIT 1
163#else
164#define RCUTORTURE_RUNNABLE_INIT 0
165#endif
166int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
167
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700168#if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700169#define rcu_can_boost() 1
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700170#else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700171#define rcu_can_boost() 0
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700172#endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700173
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700174static unsigned long shutdown_time; /* jiffies to system shutdown. */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700175static unsigned long boost_starttime; /* jiffies of next boost test start. */
176DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
177 /* and boost task create/destroy. */
178
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800179/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
180
181#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
182#define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
183#define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
184static int fullstop = FULLSTOP_RMMOD;
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700185/*
186 * Protect fullstop transitions and spawning of kthreads.
187 */
188static DEFINE_MUTEX(fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800189
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700190/* Forward reference. */
191static void rcu_torture_cleanup(void);
192
Paul E. McKenney343e9092008-12-15 16:13:07 -0800193/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800194 * Detect and respond to a system shutdown.
Paul E. McKenney343e9092008-12-15 16:13:07 -0800195 */
196static int
197rcutorture_shutdown_notify(struct notifier_block *unused1,
198 unsigned long unused2, void *unused3)
199{
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800200 mutex_lock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800201 if (fullstop == FULLSTOP_DONTSTOP)
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800202 fullstop = FULLSTOP_SHUTDOWN;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800203 else
204 printk(KERN_WARNING /* but going down anyway, so... */
205 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800206 mutex_unlock(&fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800207 return NOTIFY_DONE;
208}
209
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800210/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800211 * Absorb kthreads into a kernel function that won't return, so that
212 * they won't ever access module text or data again.
213 */
214static void rcutorture_shutdown_absorb(char *title)
215{
216 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
217 printk(KERN_NOTICE
218 "rcutorture thread %s parking due to system shutdown\n",
219 title);
220 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
221 }
222}
223
224/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800225 * Allocate an element from the rcu_tortures pool.
226 */
Adrian Bunk97a41e22006-01-08 01:02:17 -0800227static struct rcu_torture *
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800228rcu_torture_alloc(void)
229{
230 struct list_head *p;
231
Ingo Molnaradac1662006-01-25 19:50:12 +0100232 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800233 if (list_empty(&rcu_torture_freelist)) {
234 atomic_inc(&n_rcu_torture_alloc_fail);
Ingo Molnaradac1662006-01-25 19:50:12 +0100235 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800236 return NULL;
237 }
238 atomic_inc(&n_rcu_torture_alloc);
239 p = rcu_torture_freelist.next;
240 list_del_init(p);
Ingo Molnaradac1662006-01-25 19:50:12 +0100241 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800242 return container_of(p, struct rcu_torture, rtort_free);
243}
244
245/*
246 * Free an element to the rcu_tortures pool.
247 */
248static void
249rcu_torture_free(struct rcu_torture *p)
250{
251 atomic_inc(&n_rcu_torture_free);
Ingo Molnaradac1662006-01-25 19:50:12 +0100252 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800253 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
Ingo Molnaradac1662006-01-25 19:50:12 +0100254 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800255}
256
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800257struct rcu_random_state {
258 unsigned long rrs_state;
Josh Triplett75cfef32006-10-04 02:17:12 -0700259 long rrs_count;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800260};
261
262#define RCU_RANDOM_MULT 39916801 /* prime */
263#define RCU_RANDOM_ADD 479001701 /* prime */
264#define RCU_RANDOM_REFRESH 10000
265
266#define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
267
268/*
269 * Crude but fast random-number generator. Uses a linear congruential
Paul E. McKenneyc17ac852007-10-16 23:27:19 -0700270 * generator, with occasional help from cpu_clock().
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800271 */
Josh Triplett75cfef32006-10-04 02:17:12 -0700272static unsigned long
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800273rcu_random(struct rcu_random_state *rrsp)
274{
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800275 if (--rrsp->rrs_count < 0) {
Peter Zijlstrac6763292010-05-25 10:48:51 +0200276 rrsp->rrs_state += (unsigned long)local_clock();
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800277 rrsp->rrs_count = RCU_RANDOM_REFRESH;
278 }
279 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
280 return swahw32(rrsp->rrs_state);
281}
282
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700283static void
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800284rcu_stutter_wait(char *title)
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700285{
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800286 while (stutter_pause_test || !rcutorture_runnable) {
Paul E. McKenneye3d7be22008-06-22 13:06:38 -0700287 if (rcutorture_runnable)
288 schedule_timeout_interruptible(1);
289 else
Paul E. McKenney3ccf79f2008-06-22 14:02:55 -0700290 schedule_timeout_interruptible(round_jiffies_relative(HZ));
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800291 rcutorture_shutdown_absorb(title);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800292 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700293}
294
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800295/*
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700296 * Operations vector for selecting different types of tests.
297 */
298
299struct rcu_torture_ops {
300 void (*init)(void);
301 void (*cleanup)(void);
302 int (*readlock)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700303 void (*read_delay)(struct rcu_random_state *rrsp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700304 void (*readunlock)(int idx);
305 int (*completed)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700306 void (*deferred_free)(struct rcu_torture *p);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700307 void (*sync)(void);
Paul E. McKenney23269742008-05-12 21:21:05 +0200308 void (*cb_barrier)(void);
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800309 void (*fqs)(void);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700310 int (*stats)(char *page);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700311 int irq_capable;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700312 int can_boost;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700313 char *name;
314};
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700315
316static struct rcu_torture_ops *cur_ops;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700317
318/*
319 * Definitions for rcu torture testing.
320 */
321
Josh Tripletta49a4af2006-09-29 01:59:30 -0700322static int rcu_torture_read_lock(void) __acquires(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700323{
324 rcu_read_lock();
325 return 0;
326}
327
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700328static void rcu_read_delay(struct rcu_random_state *rrsp)
329{
Josh Triplettb8d57a72009-09-08 15:54:35 -0700330 const unsigned long shortdelay_us = 200;
331 const unsigned long longdelay_ms = 50;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700332
Josh Triplettb8d57a72009-09-08 15:54:35 -0700333 /* We want a short delay sometimes to make a reader delay the grace
334 * period, and we want a long delay occasionally to trigger
335 * force_quiescent_state. */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700336
Josh Triplettb8d57a72009-09-08 15:54:35 -0700337 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
338 mdelay(longdelay_ms);
339 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
340 udelay(shortdelay_us);
Lai Jiangshane546f482010-06-21 16:57:42 +0800341#ifdef CONFIG_PREEMPT
342 if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000)))
343 preempt_schedule(); /* No QS if preempt_disable() in effect */
344#endif
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700345}
346
Josh Tripletta49a4af2006-09-29 01:59:30 -0700347static void rcu_torture_read_unlock(int idx) __releases(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700348{
349 rcu_read_unlock();
350}
351
352static int rcu_torture_completed(void)
353{
354 return rcu_batches_completed();
355}
356
357static void
358rcu_torture_cb(struct rcu_head *p)
359{
360 int i;
361 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
362
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800363 if (fullstop != FULLSTOP_DONTSTOP) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700364 /* Test is ending, just drop callbacks on the floor. */
365 /* The next initialization will pick up the pieces. */
366 return;
367 }
368 i = rp->rtort_pipe_count;
369 if (i > RCU_TORTURE_PIPE_LEN)
370 i = RCU_TORTURE_PIPE_LEN;
371 atomic_inc(&rcu_torture_wcount[i]);
372 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
373 rp->rtort_mbtest = 0;
374 rcu_torture_free(rp);
375 } else
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700376 cur_ops->deferred_free(rp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700377}
378
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800379static int rcu_no_completed(void)
380{
381 return 0;
382}
383
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700384static void rcu_torture_deferred_free(struct rcu_torture *p)
385{
386 call_rcu(&p->rtort_rcu, rcu_torture_cb);
387}
388
389static struct rcu_torture_ops rcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700390 .init = NULL,
391 .cleanup = NULL,
392 .readlock = rcu_torture_read_lock,
393 .read_delay = rcu_read_delay,
394 .readunlock = rcu_torture_read_unlock,
395 .completed = rcu_torture_completed,
396 .deferred_free = rcu_torture_deferred_free,
397 .sync = synchronize_rcu,
398 .cb_barrier = rcu_barrier,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800399 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700400 .stats = NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700401 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700402 .can_boost = rcu_can_boost(),
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700403 .name = "rcu"
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700404};
405
Josh Triplette3033732006-10-04 02:17:14 -0700406static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
407{
408 int i;
409 struct rcu_torture *rp;
410 struct rcu_torture *rp1;
411
412 cur_ops->sync();
413 list_add(&p->rtort_free, &rcu_torture_removed);
414 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
415 i = rp->rtort_pipe_count;
416 if (i > RCU_TORTURE_PIPE_LEN)
417 i = RCU_TORTURE_PIPE_LEN;
418 atomic_inc(&rcu_torture_wcount[i]);
419 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
420 rp->rtort_mbtest = 0;
421 list_del(&rp->rtort_free);
422 rcu_torture_free(rp);
423 }
424 }
425}
426
427static void rcu_sync_torture_init(void)
428{
429 INIT_LIST_HEAD(&rcu_torture_removed);
430}
431
Josh Triplett20d2e422006-10-04 02:17:15 -0700432static struct rcu_torture_ops rcu_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700433 .init = rcu_sync_torture_init,
434 .cleanup = NULL,
435 .readlock = rcu_torture_read_lock,
436 .read_delay = rcu_read_delay,
437 .readunlock = rcu_torture_read_unlock,
438 .completed = rcu_torture_completed,
439 .deferred_free = rcu_sync_torture_deferred_free,
440 .sync = synchronize_rcu,
441 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800442 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700443 .stats = NULL,
444 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700445 .can_boost = rcu_can_boost(),
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700446 .name = "rcu_sync"
Josh Triplett20d2e422006-10-04 02:17:15 -0700447};
448
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800449static struct rcu_torture_ops rcu_expedited_ops = {
450 .init = rcu_sync_torture_init,
451 .cleanup = NULL,
452 .readlock = rcu_torture_read_lock,
453 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
454 .readunlock = rcu_torture_read_unlock,
455 .completed = rcu_no_completed,
456 .deferred_free = rcu_sync_torture_deferred_free,
457 .sync = synchronize_rcu_expedited,
458 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800459 .fqs = rcu_force_quiescent_state,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800460 .stats = NULL,
461 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700462 .can_boost = rcu_can_boost(),
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800463 .name = "rcu_expedited"
464};
465
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700466/*
467 * Definitions for rcu_bh torture testing.
468 */
469
Josh Tripletta49a4af2006-09-29 01:59:30 -0700470static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700471{
472 rcu_read_lock_bh();
473 return 0;
474}
475
Josh Tripletta49a4af2006-09-29 01:59:30 -0700476static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700477{
478 rcu_read_unlock_bh();
479}
480
481static int rcu_bh_torture_completed(void)
482{
483 return rcu_batches_completed_bh();
484}
485
486static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
487{
488 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
489}
490
491static struct rcu_torture_ops rcu_bh_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700492 .init = NULL,
493 .cleanup = NULL,
494 .readlock = rcu_bh_torture_read_lock,
495 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
496 .readunlock = rcu_bh_torture_read_unlock,
497 .completed = rcu_bh_torture_completed,
498 .deferred_free = rcu_bh_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700499 .sync = synchronize_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700500 .cb_barrier = rcu_barrier_bh,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800501 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700502 .stats = NULL,
503 .irq_capable = 1,
504 .name = "rcu_bh"
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700505};
506
Josh Triplett11a14702006-10-04 02:17:16 -0700507static struct rcu_torture_ops rcu_bh_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700508 .init = rcu_sync_torture_init,
509 .cleanup = NULL,
510 .readlock = rcu_bh_torture_read_lock,
511 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
512 .readunlock = rcu_bh_torture_read_unlock,
513 .completed = rcu_bh_torture_completed,
514 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700515 .sync = synchronize_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700516 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800517 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700518 .stats = NULL,
519 .irq_capable = 1,
520 .name = "rcu_bh_sync"
Josh Triplett11a14702006-10-04 02:17:16 -0700521};
522
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700523static struct rcu_torture_ops rcu_bh_expedited_ops = {
524 .init = rcu_sync_torture_init,
525 .cleanup = NULL,
526 .readlock = rcu_bh_torture_read_lock,
527 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
528 .readunlock = rcu_bh_torture_read_unlock,
529 .completed = rcu_bh_torture_completed,
530 .deferred_free = rcu_sync_torture_deferred_free,
531 .sync = synchronize_rcu_bh_expedited,
532 .cb_barrier = NULL,
533 .fqs = rcu_bh_force_quiescent_state,
534 .stats = NULL,
535 .irq_capable = 1,
536 .name = "rcu_bh_expedited"
537};
538
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700539/*
540 * Definitions for srcu torture testing.
541 */
542
543static struct srcu_struct srcu_ctl;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700544
545static void srcu_torture_init(void)
546{
547 init_srcu_struct(&srcu_ctl);
Josh Triplette3033732006-10-04 02:17:14 -0700548 rcu_sync_torture_init();
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700549}
550
551static void srcu_torture_cleanup(void)
552{
553 synchronize_srcu(&srcu_ctl);
554 cleanup_srcu_struct(&srcu_ctl);
555}
556
Josh Triplett012d3ca2006-12-06 20:40:19 -0800557static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700558{
559 return srcu_read_lock(&srcu_ctl);
560}
561
562static void srcu_read_delay(struct rcu_random_state *rrsp)
563{
564 long delay;
565 const long uspertick = 1000000 / HZ;
566 const long longdelay = 10;
567
568 /* We want there to be long-running readers, but not all the time. */
569
570 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
571 if (!delay)
572 schedule_timeout_interruptible(longdelay);
Lai Jiangshane546f482010-06-21 16:57:42 +0800573 else
574 rcu_read_delay(rrsp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700575}
576
Josh Triplett012d3ca2006-12-06 20:40:19 -0800577static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700578{
579 srcu_read_unlock(&srcu_ctl, idx);
580}
581
582static int srcu_torture_completed(void)
583{
584 return srcu_batches_completed(&srcu_ctl);
585}
586
Josh Triplettb772e1d2006-10-04 02:17:13 -0700587static void srcu_torture_synchronize(void)
588{
589 synchronize_srcu(&srcu_ctl);
590}
591
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700592static int srcu_torture_stats(char *page)
593{
594 int cnt = 0;
595 int cpu;
596 int idx = srcu_ctl.completed & 0x1;
597
598 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
599 torture_type, TORTURE_FLAG, idx);
600 for_each_possible_cpu(cpu) {
601 cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu,
602 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
603 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
604 }
605 cnt += sprintf(&page[cnt], "\n");
606 return cnt;
607}
608
609static struct rcu_torture_ops srcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700610 .init = srcu_torture_init,
611 .cleanup = srcu_torture_cleanup,
612 .readlock = srcu_torture_read_lock,
613 .read_delay = srcu_read_delay,
614 .readunlock = srcu_torture_read_unlock,
615 .completed = srcu_torture_completed,
616 .deferred_free = rcu_sync_torture_deferred_free,
617 .sync = srcu_torture_synchronize,
618 .cb_barrier = NULL,
619 .stats = srcu_torture_stats,
620 .name = "srcu"
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700621};
622
Paul E. McKenney804bb832009-10-25 19:03:52 -0700623static void srcu_torture_synchronize_expedited(void)
624{
625 synchronize_srcu_expedited(&srcu_ctl);
626}
627
628static struct rcu_torture_ops srcu_expedited_ops = {
629 .init = srcu_torture_init,
630 .cleanup = srcu_torture_cleanup,
631 .readlock = srcu_torture_read_lock,
632 .read_delay = srcu_read_delay,
633 .readunlock = srcu_torture_read_unlock,
634 .completed = srcu_torture_completed,
635 .deferred_free = rcu_sync_torture_deferred_free,
636 .sync = srcu_torture_synchronize_expedited,
637 .cb_barrier = NULL,
638 .stats = srcu_torture_stats,
639 .name = "srcu_expedited"
640};
641
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700642/*
643 * Definitions for sched torture testing.
644 */
645
646static int sched_torture_read_lock(void)
647{
648 preempt_disable();
649 return 0;
650}
651
652static void sched_torture_read_unlock(int idx)
653{
654 preempt_enable();
655}
656
Paul E. McKenney23269742008-05-12 21:21:05 +0200657static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
658{
659 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
660}
661
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700662static struct rcu_torture_ops sched_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700663 .init = rcu_sync_torture_init,
664 .cleanup = NULL,
665 .readlock = sched_torture_read_lock,
666 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
667 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800668 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700669 .deferred_free = rcu_sched_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700670 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700671 .cb_barrier = rcu_barrier_sched,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800672 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700673 .stats = NULL,
674 .irq_capable = 1,
675 .name = "sched"
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700676};
677
Paul E. McKenney804bb832009-10-25 19:03:52 -0700678static struct rcu_torture_ops sched_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700679 .init = rcu_sync_torture_init,
680 .cleanup = NULL,
681 .readlock = sched_torture_read_lock,
682 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
683 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800684 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700685 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700686 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700687 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800688 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700689 .stats = NULL,
690 .name = "sched_sync"
691};
692
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700693static struct rcu_torture_ops sched_expedited_ops = {
694 .init = rcu_sync_torture_init,
695 .cleanup = NULL,
696 .readlock = sched_torture_read_lock,
697 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
698 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800699 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700700 .deferred_free = rcu_sync_torture_deferred_free,
701 .sync = synchronize_sched_expedited,
702 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800703 .fqs = rcu_sched_force_quiescent_state,
Tejun Heo969c7922010-05-06 18:49:21 +0200704 .stats = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700705 .irq_capable = 1,
706 .name = "sched_expedited"
Paul E. McKenney23269742008-05-12 21:21:05 +0200707};
708
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700709/*
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700710 * RCU torture priority-boost testing. Runs one real-time thread per
711 * CPU for moderate bursts, repeatedly registering RCU callbacks and
712 * spinning waiting for them to be invoked. If a given callback takes
713 * too long to be invoked, we assume that priority inversion has occurred.
714 */
715
716struct rcu_boost_inflight {
717 struct rcu_head rcu;
718 int inflight;
719};
720
721static void rcu_torture_boost_cb(struct rcu_head *head)
722{
723 struct rcu_boost_inflight *rbip =
724 container_of(head, struct rcu_boost_inflight, rcu);
725
726 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
727 rbip->inflight = 0;
728}
729
730static int rcu_torture_boost(void *arg)
731{
732 unsigned long call_rcu_time;
733 unsigned long endtime;
734 unsigned long oldstarttime;
735 struct rcu_boost_inflight rbi = { .inflight = 0 };
736 struct sched_param sp;
737
738 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
739
740 /* Set real-time priority. */
741 sp.sched_priority = 1;
742 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
743 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
744 n_rcu_torture_boost_rterror++;
745 }
746
Paul E. McKenney561190e2011-03-30 09:10:44 -0700747 init_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700748 /* Each pass through the following loop does one boost-test cycle. */
749 do {
750 /* Wait for the next test interval. */
751 oldstarttime = boost_starttime;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700752 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700753 schedule_timeout_uninterruptible(1);
754 rcu_stutter_wait("rcu_torture_boost");
755 if (kthread_should_stop() ||
756 fullstop != FULLSTOP_DONTSTOP)
757 goto checkwait;
758 }
759
760 /* Do one boost-test interval. */
761 endtime = oldstarttime + test_boost_duration * HZ;
762 call_rcu_time = jiffies;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700763 while (ULONG_CMP_LT(jiffies, endtime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700764 /* If we don't have a callback in flight, post one. */
765 if (!rbi.inflight) {
766 smp_mb(); /* RCU core before ->inflight = 1. */
767 rbi.inflight = 1;
768 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
769 if (jiffies - call_rcu_time >
770 test_boost_duration * HZ - HZ / 2) {
771 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
772 n_rcu_torture_boost_failure++;
773 }
774 call_rcu_time = jiffies;
775 }
776 cond_resched();
777 rcu_stutter_wait("rcu_torture_boost");
778 if (kthread_should_stop() ||
779 fullstop != FULLSTOP_DONTSTOP)
780 goto checkwait;
781 }
782
783 /*
784 * Set the start time of the next test interval.
785 * Yes, this is vulnerable to long delays, but such
786 * delays simply cause a false negative for the next
787 * interval. Besides, we are running at RT priority,
788 * so delays should be relatively rare.
789 */
Paul E. McKenneyab8f11e2011-08-18 09:30:32 -0700790 while (oldstarttime == boost_starttime &&
791 !kthread_should_stop()) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700792 if (mutex_trylock(&boost_mutex)) {
793 boost_starttime = jiffies +
794 test_boost_interval * HZ;
795 n_rcu_torture_boosts++;
796 mutex_unlock(&boost_mutex);
797 break;
798 }
799 schedule_timeout_uninterruptible(1);
800 }
801
802 /* Go do the stutter. */
803checkwait: rcu_stutter_wait("rcu_torture_boost");
804 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
805
806 /* Clean up and exit. */
807 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
808 rcutorture_shutdown_absorb("rcu_torture_boost");
809 while (!kthread_should_stop() || rbi.inflight)
810 schedule_timeout_uninterruptible(1);
811 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
Paul E. McKenney9d681972011-06-21 01:48:03 -0700812 destroy_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700813 return 0;
814}
815
816/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800817 * RCU torture force-quiescent-state kthread. Repeatedly induces
818 * bursts of calls to force_quiescent_state(), increasing the probability
819 * of occurrence of some important types of race conditions.
820 */
821static int
822rcu_torture_fqs(void *arg)
823{
824 unsigned long fqs_resume_time;
825 int fqs_burst_remaining;
826
827 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
828 do {
829 fqs_resume_time = jiffies + fqs_stutter * HZ;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700830 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
831 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800832 schedule_timeout_interruptible(1);
833 }
834 fqs_burst_remaining = fqs_duration;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700835 while (fqs_burst_remaining > 0 &&
836 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800837 cur_ops->fqs();
838 udelay(fqs_holdoff);
839 fqs_burst_remaining -= fqs_holdoff;
840 }
841 rcu_stutter_wait("rcu_torture_fqs");
842 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
843 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
844 rcutorture_shutdown_absorb("rcu_torture_fqs");
845 while (!kthread_should_stop())
846 schedule_timeout_uninterruptible(1);
847 return 0;
848}
849
850/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800851 * RCU torture writer kthread. Repeatedly substitutes a new structure
852 * for that pointed to by rcu_torture_current, freeing the old structure
853 * after a series of grace periods (the "pipeline").
854 */
855static int
856rcu_torture_writer(void *arg)
857{
858 int i;
859 long oldbatch = rcu_batches_completed();
860 struct rcu_torture *rp;
861 struct rcu_torture *old_rp;
862 static DEFINE_RCU_RANDOM(rand);
863
864 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800865 set_user_nice(current, 19);
866
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800867 do {
868 schedule_timeout_uninterruptible(1);
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700869 rp = rcu_torture_alloc();
870 if (rp == NULL)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800871 continue;
872 rp->rtort_pipe_count = 0;
873 udelay(rcu_random(&rand) & 0x3ff);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700874 old_rp = rcu_dereference_check(rcu_torture_current,
875 current == writer_task);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800876 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800877 rcu_assign_pointer(rcu_torture_current, rp);
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700878 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
Josh Triplettc8e5b162007-05-08 00:33:20 -0700879 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800880 i = old_rp->rtort_pipe_count;
881 if (i > RCU_TORTURE_PIPE_LEN)
882 i = RCU_TORTURE_PIPE_LEN;
883 atomic_inc(&rcu_torture_wcount[i]);
884 old_rp->rtort_pipe_count++;
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700885 cur_ops->deferred_free(old_rp);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800886 }
Paul E. McKenney4a298652011-04-03 21:33:51 -0700887 rcutorture_record_progress(++rcu_torture_current_version);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700888 oldbatch = cur_ops->completed();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800889 rcu_stutter_wait("rcu_torture_writer");
890 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800891 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800892 rcutorture_shutdown_absorb("rcu_torture_writer");
893 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800894 schedule_timeout_uninterruptible(1);
895 return 0;
896}
897
898/*
Josh Triplettb772e1d2006-10-04 02:17:13 -0700899 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
900 * delay between calls.
901 */
902static int
903rcu_torture_fakewriter(void *arg)
904{
905 DEFINE_RCU_RANDOM(rand);
906
907 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
908 set_user_nice(current, 19);
909
910 do {
911 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
912 udelay(rcu_random(&rand) & 0x3ff);
913 cur_ops->sync();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800914 rcu_stutter_wait("rcu_torture_fakewriter");
915 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700916
917 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800918 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
919 while (!kthread_should_stop())
Josh Triplettb772e1d2006-10-04 02:17:13 -0700920 schedule_timeout_uninterruptible(1);
921 return 0;
922}
923
Paul E. McKenney91afaf32011-10-02 07:44:32 -0700924void rcutorture_trace_dump(void)
925{
926 static atomic_t beenhere = ATOMIC_INIT(0);
927
928 if (atomic_read(&beenhere))
929 return;
930 if (atomic_xchg(&beenhere, 1) != 0)
931 return;
932 do_trace_rcu_torture_read(cur_ops->name, (struct rcu_head *)~0UL);
933 ftrace_dump(DUMP_ALL);
934}
935
Josh Triplettb772e1d2006-10-04 02:17:13 -0700936/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700937 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
938 * incrementing the corresponding element of the pipeline array. The
939 * counter in the element should never be greater than 1, otherwise, the
940 * RCU implementation is broken.
941 */
942static void rcu_torture_timer(unsigned long unused)
943{
944 int idx;
945 int completed;
946 static DEFINE_RCU_RANDOM(rand);
947 static DEFINE_SPINLOCK(rand_lock);
948 struct rcu_torture *p;
949 int pipe_count;
950
951 idx = cur_ops->readlock();
952 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -0800953 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -0800954 rcu_read_lock_bh_held() ||
955 rcu_read_lock_sched_held() ||
956 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenney91afaf32011-10-02 07:44:32 -0700957 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700958 if (p == NULL) {
959 /* Leave because rcu_torture_writer is not yet underway */
960 cur_ops->readunlock(idx);
961 return;
962 }
963 if (p->rtort_mbtest == 0)
964 atomic_inc(&n_rcu_torture_mberror);
965 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700966 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700967 n_rcu_torture_timers++;
968 spin_unlock(&rand_lock);
969 preempt_disable();
970 pipe_count = p->rtort_pipe_count;
971 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
972 /* Should not happen, but... */
973 pipe_count = RCU_TORTURE_PIPE_LEN;
974 }
Paul E. McKenney91afaf32011-10-02 07:44:32 -0700975 if (pipe_count > 1)
976 rcutorture_trace_dump();
Rusty Russelldd17c8f2009-10-29 22:34:15 +0900977 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700978 completed = cur_ops->completed() - completed;
979 if (completed > RCU_TORTURE_PIPE_LEN) {
980 /* Should not happen, but... */
981 completed = RCU_TORTURE_PIPE_LEN;
982 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +0900983 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700984 preempt_enable();
985 cur_ops->readunlock(idx);
986}
987
988/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800989 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
990 * incrementing the corresponding element of the pipeline array. The
991 * counter in the element should never be greater than 1, otherwise, the
992 * RCU implementation is broken.
993 */
994static int
995rcu_torture_reader(void *arg)
996{
997 int completed;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700998 int idx;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800999 DEFINE_RCU_RANDOM(rand);
1000 struct rcu_torture *p;
1001 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001002 struct timer_list t;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001003
1004 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001005 set_user_nice(current, 19);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001006 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001007 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001008
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001009 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001010 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001011 if (!timer_pending(&t))
Paul E. McKenney6155fec2010-02-22 17:05:04 -08001012 mod_timer(&t, jiffies + 1);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001013 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001014 idx = cur_ops->readlock();
1015 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001016 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001017 rcu_read_lock_bh_held() ||
1018 rcu_read_lock_sched_held() ||
1019 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001020 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001021 if (p == NULL) {
1022 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001023 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001024 schedule_timeout_interruptible(HZ);
1025 continue;
1026 }
Paul E. McKenney996417d2005-11-18 01:10:50 -08001027 if (p->rtort_mbtest == 0)
1028 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001029 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001030 preempt_disable();
1031 pipe_count = p->rtort_pipe_count;
1032 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1033 /* Should not happen, but... */
1034 pipe_count = RCU_TORTURE_PIPE_LEN;
1035 }
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001036 if (pipe_count > 1)
1037 rcutorture_trace_dump();
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001038 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001039 completed = cur_ops->completed() - completed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001040 if (completed > RCU_TORTURE_PIPE_LEN) {
1041 /* Should not happen, but... */
1042 completed = RCU_TORTURE_PIPE_LEN;
1043 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001044 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001045 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001046 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001047 schedule();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001048 rcu_stutter_wait("rcu_torture_reader");
1049 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001050 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001051 rcutorture_shutdown_absorb("rcu_torture_reader");
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001052 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001053 del_timer_sync(&t);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001054 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001055 schedule_timeout_uninterruptible(1);
1056 return 0;
1057}
1058
1059/*
1060 * Create an RCU-torture statistics message in the specified buffer.
1061 */
1062static int
1063rcu_torture_printk(char *page)
1064{
1065 int cnt = 0;
1066 int cpu;
1067 int i;
1068 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1069 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1070
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001071 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001072 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1073 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1074 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1075 }
1076 }
1077 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1078 if (pipesummary[i] != 0)
1079 break;
1080 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001081 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001082 cnt += sprintf(&page[cnt],
Paul E. McKenney4a298652011-04-03 21:33:51 -07001083 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d "
Paul E. McKenney67b98db2011-02-21 13:31:55 -08001084 "rtmbe: %d rtbke: %ld rtbre: %ld "
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001085 "rtbf: %ld rtb: %ld nt: %ld",
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001086 rcu_torture_current,
1087 rcu_torture_current_version,
1088 list_empty(&rcu_torture_freelist),
1089 atomic_read(&n_rcu_torture_alloc),
1090 atomic_read(&n_rcu_torture_alloc_fail),
Paul E. McKenney996417d2005-11-18 01:10:50 -08001091 atomic_read(&n_rcu_torture_free),
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001092 atomic_read(&n_rcu_torture_mberror),
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001093 n_rcu_torture_boost_ktrerror,
1094 n_rcu_torture_boost_rterror,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001095 n_rcu_torture_boost_failure,
1096 n_rcu_torture_boosts,
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001097 n_rcu_torture_timers);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001098 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
1099 n_rcu_torture_boost_ktrerror != 0 ||
1100 n_rcu_torture_boost_rterror != 0 ||
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001101 n_rcu_torture_boost_failure != 0)
Paul E. McKenney996417d2005-11-18 01:10:50 -08001102 cnt += sprintf(&page[cnt], " !!!");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001103 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001104 if (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);
1142 printk(KERN_ALERT "%s", printk_buf);
1143}
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 }
1194
Josh Triplettc8e5b162007-05-08 00:33:20 -07001195 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001196 for (i = 0; i < nfakewriters; i++)
1197 if (fakewriter_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001198 set_cpus_allowed_ptr(fakewriter_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001199 shuffle_tmp_mask);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001200 }
1201
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001202 if (writer_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001203 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001204
1205 if (stats_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001206 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001207
1208 if (rcu_idle_cpu == -1)
1209 rcu_idle_cpu = num_online_cpus() - 1;
1210 else
1211 rcu_idle_cpu--;
1212
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001213 put_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001214}
1215
1216/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1217 * system to become idle at a time and cut off its timer ticks. This is meant
1218 * to test the support for such tickless idle CPU in RCU.
1219 */
1220static int
1221rcu_torture_shuffle(void *arg)
1222{
1223 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1224 do {
1225 schedule_timeout_interruptible(shuffle_interval * HZ);
1226 rcu_torture_shuffle_tasks();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001227 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1228 } while (!kthread_should_stop());
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001229 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1230 return 0;
1231}
1232
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001233/* Cause the rcutorture test to "stutter", starting and stopping all
1234 * threads periodically.
1235 */
1236static int
1237rcu_torture_stutter(void *arg)
1238{
1239 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1240 do {
1241 schedule_timeout_interruptible(stutter * HZ);
1242 stutter_pause_test = 1;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001243 if (!kthread_should_stop())
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001244 schedule_timeout_interruptible(stutter * HZ);
1245 stutter_pause_test = 0;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001246 rcutorture_shutdown_absorb("rcu_torture_stutter");
1247 } while (!kthread_should_stop());
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001248 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1249 return 0;
1250}
1251
Paul E. McKenney95c38322006-03-24 03:15:58 -08001252static inline void
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001253rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
Paul E. McKenney95c38322006-03-24 03:15:58 -08001254{
Josh Triplettb772e1d2006-10-04 02:17:13 -07001255 printk(KERN_ALERT "%s" TORTURE_FLAG
1256 "--- %s: nreaders=%d nfakewriters=%d "
Paul E. McKenney95c38322006-03-24 03:15:58 -08001257 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001258 "shuffle_interval=%d stutter=%d irqreader=%d "
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001259 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1260 "test_boost=%d/%d test_boost_interval=%d "
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001261 "test_boost_duration=%d shutdown_secs=%d\n",
Josh Triplettb772e1d2006-10-04 02:17:13 -07001262 torture_type, tag, nrealreaders, nfakewriters,
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001263 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001264 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1265 test_boost, cur_ops->can_boost,
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001266 test_boost_interval, test_boost_duration, shutdown_secs);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001267}
1268
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001269static struct notifier_block rcutorture_shutdown_nb = {
Paul E. McKenney343e9092008-12-15 16:13:07 -08001270 .notifier_call = rcutorture_shutdown_notify,
1271};
1272
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001273static void rcutorture_booster_cleanup(int cpu)
1274{
1275 struct task_struct *t;
1276
1277 if (boost_tasks[cpu] == NULL)
1278 return;
1279 mutex_lock(&boost_mutex);
1280 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1281 t = boost_tasks[cpu];
1282 boost_tasks[cpu] = NULL;
1283 mutex_unlock(&boost_mutex);
1284
1285 /* This must be outside of the mutex, otherwise deadlock! */
1286 kthread_stop(t);
1287}
1288
1289static int rcutorture_booster_init(int cpu)
1290{
1291 int retval;
1292
1293 if (boost_tasks[cpu] != NULL)
1294 return 0; /* Already created, nothing more to do. */
1295
1296 /* Don't allow time recalculation while creating a new task. */
1297 mutex_lock(&boost_mutex);
1298 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
Eric Dumazet1f288092011-06-16 15:53:18 -07001299 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1300 cpu_to_node(cpu),
1301 "rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001302 if (IS_ERR(boost_tasks[cpu])) {
1303 retval = PTR_ERR(boost_tasks[cpu]);
1304 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1305 n_rcu_torture_boost_ktrerror++;
1306 boost_tasks[cpu] = NULL;
1307 mutex_unlock(&boost_mutex);
1308 return retval;
1309 }
1310 kthread_bind(boost_tasks[cpu], cpu);
1311 wake_up_process(boost_tasks[cpu]);
1312 mutex_unlock(&boost_mutex);
1313 return 0;
1314}
1315
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001316/*
1317 * Cause the rcutorture test to shutdown the system after the test has
1318 * run for the time specified by the shutdown_secs module parameter.
1319 */
1320static int
1321rcu_torture_shutdown(void *arg)
1322{
1323 long delta;
1324 unsigned long jiffies_snap;
1325
1326 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1327 jiffies_snap = ACCESS_ONCE(jiffies);
1328 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
1329 !kthread_should_stop()) {
1330 delta = shutdown_time - jiffies_snap;
1331 if (verbose)
1332 printk(KERN_ALERT "%s" TORTURE_FLAG
1333 "rcu_torture_shutdown task: %lu "
1334 "jiffies remaining\n",
1335 torture_type, delta);
1336 schedule_timeout_interruptible(delta);
1337 jiffies_snap = ACCESS_ONCE(jiffies);
1338 }
1339 if (ULONG_CMP_LT(jiffies, shutdown_time)) {
1340 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1341 return 0;
1342 }
1343
1344 /* OK, shut down the system. */
1345
1346 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1347 shutdown_task = NULL; /* Avoid self-kill deadlock. */
1348 rcu_torture_cleanup(); /* Get the success/failure message. */
1349 kernel_power_off(); /* Shut down the system. */
1350 return 0;
1351}
1352
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001353static int rcutorture_cpu_notify(struct notifier_block *self,
1354 unsigned long action, void *hcpu)
1355{
1356 long cpu = (long)hcpu;
1357
1358 switch (action) {
1359 case CPU_ONLINE:
1360 case CPU_DOWN_FAILED:
1361 (void)rcutorture_booster_init(cpu);
1362 break;
1363 case CPU_DOWN_PREPARE:
1364 rcutorture_booster_cleanup(cpu);
1365 break;
1366 default:
1367 break;
1368 }
1369 return NOTIFY_OK;
1370}
1371
1372static struct notifier_block rcutorture_cpu_nb = {
1373 .notifier_call = rcutorture_cpu_notify,
1374};
1375
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001376static void
1377rcu_torture_cleanup(void)
1378{
1379 int i;
1380
Paul E. McKenney343e9092008-12-15 16:13:07 -08001381 mutex_lock(&fullstop_mutex);
Paul E. McKenney4a298652011-04-03 21:33:51 -07001382 rcutorture_record_test_transition();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001383 if (fullstop == FULLSTOP_SHUTDOWN) {
1384 printk(KERN_WARNING /* but going down anyway, so... */
1385 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001386 mutex_unlock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001387 schedule_timeout_uninterruptible(10);
Paul E. McKenney343e9092008-12-15 16:13:07 -08001388 if (cur_ops->cb_barrier != NULL)
1389 cur_ops->cb_barrier();
1390 return;
1391 }
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001392 fullstop = FULLSTOP_RMMOD;
Paul E. McKenney343e9092008-12-15 16:13:07 -08001393 mutex_unlock(&fullstop_mutex);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001394 unregister_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001395 if (stutter_task) {
1396 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1397 kthread_stop(stutter_task);
1398 }
1399 stutter_task = NULL;
Josh Triplettc8e5b162007-05-08 00:33:20 -07001400 if (shuffler_task) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001401 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1402 kthread_stop(shuffler_task);
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001403 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001404 }
1405 shuffler_task = NULL;
1406
Josh Triplettc8e5b162007-05-08 00:33:20 -07001407 if (writer_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001408 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1409 kthread_stop(writer_task);
1410 }
1411 writer_task = NULL;
1412
Josh Triplettc8e5b162007-05-08 00:33:20 -07001413 if (reader_tasks) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001414 for (i = 0; i < nrealreaders; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001415 if (reader_tasks[i]) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001416 VERBOSE_PRINTK_STRING(
1417 "Stopping rcu_torture_reader task");
1418 kthread_stop(reader_tasks[i]);
1419 }
1420 reader_tasks[i] = NULL;
1421 }
1422 kfree(reader_tasks);
1423 reader_tasks = NULL;
1424 }
1425 rcu_torture_current = NULL;
1426
Josh Triplettc8e5b162007-05-08 00:33:20 -07001427 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001428 for (i = 0; i < nfakewriters; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001429 if (fakewriter_tasks[i]) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001430 VERBOSE_PRINTK_STRING(
1431 "Stopping rcu_torture_fakewriter task");
1432 kthread_stop(fakewriter_tasks[i]);
1433 }
1434 fakewriter_tasks[i] = NULL;
1435 }
1436 kfree(fakewriter_tasks);
1437 fakewriter_tasks = NULL;
1438 }
1439
Josh Triplettc8e5b162007-05-08 00:33:20 -07001440 if (stats_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001441 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1442 kthread_stop(stats_task);
1443 }
1444 stats_task = NULL;
1445
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001446 if (fqs_task) {
1447 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1448 kthread_stop(fqs_task);
1449 }
1450 fqs_task = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001451 if ((test_boost == 1 && cur_ops->can_boost) ||
1452 test_boost == 2) {
1453 unregister_cpu_notifier(&rcutorture_cpu_nb);
1454 for_each_possible_cpu(i)
1455 rcutorture_booster_cleanup(i);
1456 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001457 if (shutdown_task != NULL) {
1458 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1459 kthread_stop(shutdown_task);
1460 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001461
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001462 /* Wait for all RCU callbacks to fire. */
Paul E. McKenney23269742008-05-12 21:21:05 +02001463
1464 if (cur_ops->cb_barrier != NULL)
1465 cur_ops->cb_barrier();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001466
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001467 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001468
Josh Triplettc8e5b162007-05-08 00:33:20 -07001469 if (cur_ops->cleanup)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001470 cur_ops->cleanup();
Paul E. McKenney95c38322006-03-24 03:15:58 -08001471 if (atomic_read(&n_rcu_torture_error))
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001472 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
Paul E. McKenney95c38322006-03-24 03:15:58 -08001473 else
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001474 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001475}
1476
Josh Triplett6f8bc502007-05-08 00:25:24 -07001477static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001478rcu_torture_init(void)
1479{
1480 int i;
1481 int cpu;
1482 int firsterr = 0;
Josh Triplettade5fb82007-05-08 00:33:22 -07001483 static struct rcu_torture_ops *torture_ops[] =
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -08001484 { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -07001485 &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops,
Paul E. McKenney804bb832009-10-25 19:03:52 -07001486 &srcu_ops, &srcu_expedited_ops,
1487 &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001488
Paul E. McKenney343e9092008-12-15 16:13:07 -08001489 mutex_lock(&fullstop_mutex);
1490
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001491 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001492 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001493 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001494 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001495 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001496 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001497 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001498 printk(KERN_ALERT "rcu-torture: invalid torture type: \"%s\"\n",
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001499 torture_type);
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001500 printk(KERN_ALERT "rcu-torture types:");
1501 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
1502 printk(KERN_ALERT " %s", torture_ops[i]->name);
1503 printk(KERN_ALERT "\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001504 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001505 return -EINVAL;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001506 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001507 if (cur_ops->fqs == NULL && fqs_duration != 0) {
1508 printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero "
1509 "fqs_duration, fqs disabled.\n");
1510 fqs_duration = 0;
1511 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001512 if (cur_ops->init)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001513 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1514
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001515 if (nreaders >= 0)
1516 nrealreaders = nreaders;
1517 else
1518 nrealreaders = 2 * num_online_cpus();
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001519 rcu_torture_print_module_parms(cur_ops, "Start of test");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001520 fullstop = FULLSTOP_DONTSTOP;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001521
1522 /* Set up the freelist. */
1523
1524 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07001525 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08001526 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001527 list_add_tail(&rcu_tortures[i].rtort_free,
1528 &rcu_torture_freelist);
1529 }
1530
1531 /* Initialize the statistics so that each run gets its own numbers. */
1532
1533 rcu_torture_current = NULL;
1534 rcu_torture_current_version = 0;
1535 atomic_set(&n_rcu_torture_alloc, 0);
1536 atomic_set(&n_rcu_torture_alloc_fail, 0);
1537 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001538 atomic_set(&n_rcu_torture_mberror, 0);
1539 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001540 n_rcu_torture_boost_ktrerror = 0;
1541 n_rcu_torture_boost_rterror = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001542 n_rcu_torture_boost_failure = 0;
1543 n_rcu_torture_boosts = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001544 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1545 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001546 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001547 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1548 per_cpu(rcu_torture_count, cpu)[i] = 0;
1549 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1550 }
1551 }
1552
1553 /* Start up the kthreads. */
1554
1555 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1556 writer_task = kthread_run(rcu_torture_writer, NULL,
1557 "rcu_torture_writer");
1558 if (IS_ERR(writer_task)) {
1559 firsterr = PTR_ERR(writer_task);
1560 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1561 writer_task = NULL;
1562 goto unwind;
1563 }
Josh Triplettb772e1d2006-10-04 02:17:13 -07001564 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001565 GFP_KERNEL);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001566 if (fakewriter_tasks == NULL) {
1567 VERBOSE_PRINTK_ERRSTRING("out of memory");
1568 firsterr = -ENOMEM;
1569 goto unwind;
1570 }
1571 for (i = 0; i < nfakewriters; i++) {
1572 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
1573 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001574 "rcu_torture_fakewriter");
Josh Triplettb772e1d2006-10-04 02:17:13 -07001575 if (IS_ERR(fakewriter_tasks[i])) {
1576 firsterr = PTR_ERR(fakewriter_tasks[i]);
1577 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
1578 fakewriter_tasks[i] = NULL;
1579 goto unwind;
1580 }
1581 }
Josh Triplett2860aab2006-10-04 02:17:11 -07001582 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001583 GFP_KERNEL);
1584 if (reader_tasks == NULL) {
1585 VERBOSE_PRINTK_ERRSTRING("out of memory");
1586 firsterr = -ENOMEM;
1587 goto unwind;
1588 }
1589 for (i = 0; i < nrealreaders; i++) {
1590 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
1591 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
1592 "rcu_torture_reader");
1593 if (IS_ERR(reader_tasks[i])) {
1594 firsterr = PTR_ERR(reader_tasks[i]);
1595 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
1596 reader_tasks[i] = NULL;
1597 goto unwind;
1598 }
1599 }
1600 if (stat_interval > 0) {
1601 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
1602 stats_task = kthread_run(rcu_torture_stats, NULL,
1603 "rcu_torture_stats");
1604 if (IS_ERR(stats_task)) {
1605 firsterr = PTR_ERR(stats_task);
1606 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
1607 stats_task = NULL;
1608 goto unwind;
1609 }
1610 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001611 if (test_no_idle_hz) {
1612 rcu_idle_cpu = num_online_cpus() - 1;
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001613
1614 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
1615 firsterr = -ENOMEM;
1616 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
1617 goto unwind;
1618 }
1619
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001620 /* Create the shuffler thread */
1621 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
1622 "rcu_torture_shuffle");
1623 if (IS_ERR(shuffler_task)) {
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001624 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001625 firsterr = PTR_ERR(shuffler_task);
1626 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
1627 shuffler_task = NULL;
1628 goto unwind;
1629 }
1630 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001631 if (stutter < 0)
1632 stutter = 0;
1633 if (stutter) {
1634 /* Create the stutter thread */
1635 stutter_task = kthread_run(rcu_torture_stutter, NULL,
1636 "rcu_torture_stutter");
1637 if (IS_ERR(stutter_task)) {
1638 firsterr = PTR_ERR(stutter_task);
1639 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
1640 stutter_task = NULL;
1641 goto unwind;
1642 }
1643 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001644 if (fqs_duration < 0)
1645 fqs_duration = 0;
1646 if (fqs_duration) {
1647 /* Create the stutter thread */
1648 fqs_task = kthread_run(rcu_torture_fqs, NULL,
1649 "rcu_torture_fqs");
1650 if (IS_ERR(fqs_task)) {
1651 firsterr = PTR_ERR(fqs_task);
1652 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
1653 fqs_task = NULL;
1654 goto unwind;
1655 }
1656 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001657 if (test_boost_interval < 1)
1658 test_boost_interval = 1;
1659 if (test_boost_duration < 2)
1660 test_boost_duration = 2;
1661 if ((test_boost == 1 && cur_ops->can_boost) ||
1662 test_boost == 2) {
1663 int retval;
1664
1665 boost_starttime = jiffies + test_boost_interval * HZ;
1666 register_cpu_notifier(&rcutorture_cpu_nb);
1667 for_each_possible_cpu(i) {
1668 if (cpu_is_offline(i))
1669 continue; /* Heuristic: CPU can go offline. */
1670 retval = rcutorture_booster_init(i);
1671 if (retval < 0) {
1672 firsterr = retval;
1673 goto unwind;
1674 }
1675 }
1676 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001677 if (shutdown_secs > 0) {
1678 shutdown_time = jiffies + shutdown_secs * HZ;
1679 shutdown_task = kthread_run(rcu_torture_shutdown, NULL,
1680 "rcu_torture_shutdown");
1681 if (IS_ERR(shutdown_task)) {
1682 firsterr = PTR_ERR(shutdown_task);
1683 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
1684 shutdown_task = NULL;
1685 goto unwind;
1686 }
1687 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001688 register_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenney4a298652011-04-03 21:33:51 -07001689 rcutorture_record_test_transition();
Paul E. McKenney343e9092008-12-15 16:13:07 -08001690 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001691 return 0;
1692
1693unwind:
Paul E. McKenney343e9092008-12-15 16:13:07 -08001694 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001695 rcu_torture_cleanup();
1696 return firsterr;
1697}
1698
1699module_init(rcu_torture_init);
1700module_exit(rcu_torture_cleanup);