blob: 2431d576e9cabbd436d0b1a29c2cae04ffc245b0 [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. McKenneybf66f182010-01-04 15:09:10 -080064static int fqs_duration = 0; /* Duration of bursts (us), 0 to disable. */
65static int fqs_holdoff = 0; /* Hold time within burst (us). */
66static int fqs_stutter = 3; /* Wait time between bursts (s). */
Paul E. McKenney8e8be452010-09-02 16:16:14 -070067static int test_boost = 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */
68static int test_boost_interval = 7; /* Interval between boost tests, seconds. */
69static int test_boost_duration = 4; /* Duration of each boost test, seconds. */
Josh Triplett20d2e422006-10-04 02:17:15 -070070static char *torture_type = "rcu"; /* What RCU implementation to torture. */
Paul E. McKenneya241ec62005-10-30 15:03:12 -080071
Josh Triplettd6ad6712007-03-06 01:42:13 -080072module_param(nreaders, int, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080073MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
Josh Triplettd6ad6712007-03-06 01:42:13 -080074module_param(nfakewriters, int, 0444);
Josh Triplettb772e1d2006-10-04 02:17:13 -070075MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
Paul E. McKenney3721bc12011-07-21 16:00:17 -070076module_param(stat_interval, int, 0644);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080077MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
Josh Triplettd6ad6712007-03-06 01:42:13 -080078module_param(verbose, bool, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080079MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
Josh Triplettd6ad6712007-03-06 01:42:13 -080080module_param(test_no_idle_hz, bool, 0444);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080081MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
Josh Triplettd6ad6712007-03-06 01:42:13 -080082module_param(shuffle_interval, int, 0444);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080083MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
Paul E. McKenneyd120f652008-06-18 05:21:44 -070084module_param(stutter, int, 0444);
85MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
Paul E. McKenney0729fbf2008-06-25 12:24:52 -070086module_param(irqreader, int, 0444);
87MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
Paul E. McKenneybf66f182010-01-04 15:09:10 -080088module_param(fqs_duration, int, 0444);
89MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us)");
90module_param(fqs_holdoff, int, 0444);
91MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)");
92module_param(fqs_stutter, int, 0444);
93MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)");
Paul E. McKenney8e8be452010-09-02 16:16:14 -070094module_param(test_boost, int, 0444);
95MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
96module_param(test_boost_interval, int, 0444);
97MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds.");
98module_param(test_boost_duration, int, 0444);
99MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds.");
Josh Triplettd6ad6712007-03-06 01:42:13 -0800100module_param(torture_type, charp, 0444);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700101MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700102
103#define TORTURE_FLAG "-torture:"
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800104#define PRINTK_STRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700105 do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800106#define VERBOSE_PRINTK_STRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700107 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800108#define VERBOSE_PRINTK_ERRSTRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700109 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800110
111static char printk_buf[4096];
112
113static int nrealreaders;
114static struct task_struct *writer_task;
Josh Triplettb772e1d2006-10-04 02:17:13 -0700115static struct task_struct **fakewriter_tasks;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800116static struct task_struct **reader_tasks;
117static struct task_struct *stats_task;
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800118static struct task_struct *shuffler_task;
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700119static struct task_struct *stutter_task;
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800120static struct task_struct *fqs_task;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700121static struct task_struct *boost_tasks[NR_CPUS];
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800122
123#define RCU_TORTURE_PIPE_LEN 10
124
125struct rcu_torture {
126 struct rcu_head rtort_rcu;
127 int rtort_pipe_count;
128 struct list_head rtort_free;
Paul E. McKenney996417d2005-11-18 01:10:50 -0800129 int rtort_mbtest;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800130};
131
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800132static LIST_HEAD(rcu_torture_freelist);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700133static struct rcu_torture __rcu *rcu_torture_current;
Paul E. McKenney4a298652011-04-03 21:33:51 -0700134static unsigned long rcu_torture_current_version;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800135static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
136static DEFINE_SPINLOCK(rcu_torture_lock);
137static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
138 { 0 };
139static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
140 { 0 };
141static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700142static atomic_t n_rcu_torture_alloc;
143static atomic_t n_rcu_torture_alloc_fail;
144static atomic_t n_rcu_torture_free;
145static atomic_t n_rcu_torture_mberror;
146static atomic_t n_rcu_torture_error;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700147static long n_rcu_torture_boost_ktrerror;
148static long n_rcu_torture_boost_rterror;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700149static long n_rcu_torture_boost_failure;
150static long n_rcu_torture_boosts;
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700151static long n_rcu_torture_timers;
Josh Triplette3033732006-10-04 02:17:14 -0700152static struct list_head rcu_torture_removed;
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600153static cpumask_var_t shuffle_tmp_mask;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800154
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700155static int stutter_pause_test;
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700156
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700157#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
158#define RCUTORTURE_RUNNABLE_INIT 1
159#else
160#define RCUTORTURE_RUNNABLE_INIT 0
161#endif
162int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
163
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700164#if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700165#define rcu_can_boost() 1
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700166#else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700167#define rcu_can_boost() 0
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700168#endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700169
170static unsigned long boost_starttime; /* jiffies of next boost test start. */
171DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
172 /* and boost task create/destroy. */
173
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800174/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
175
176#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
177#define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
178#define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
179static int fullstop = FULLSTOP_RMMOD;
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700180/*
181 * Protect fullstop transitions and spawning of kthreads.
182 */
183static DEFINE_MUTEX(fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800184
185/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800186 * Detect and respond to a system shutdown.
Paul E. McKenney343e9092008-12-15 16:13:07 -0800187 */
188static int
189rcutorture_shutdown_notify(struct notifier_block *unused1,
190 unsigned long unused2, void *unused3)
191{
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800192 mutex_lock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800193 if (fullstop == FULLSTOP_DONTSTOP)
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800194 fullstop = FULLSTOP_SHUTDOWN;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800195 else
196 printk(KERN_WARNING /* but going down anyway, so... */
197 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800198 mutex_unlock(&fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800199 return NOTIFY_DONE;
200}
201
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800202/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800203 * Absorb kthreads into a kernel function that won't return, so that
204 * they won't ever access module text or data again.
205 */
206static void rcutorture_shutdown_absorb(char *title)
207{
208 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
209 printk(KERN_NOTICE
210 "rcutorture thread %s parking due to system shutdown\n",
211 title);
212 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
213 }
214}
215
216/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800217 * Allocate an element from the rcu_tortures pool.
218 */
Adrian Bunk97a41e22006-01-08 01:02:17 -0800219static struct rcu_torture *
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800220rcu_torture_alloc(void)
221{
222 struct list_head *p;
223
Ingo Molnaradac1662006-01-25 19:50:12 +0100224 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800225 if (list_empty(&rcu_torture_freelist)) {
226 atomic_inc(&n_rcu_torture_alloc_fail);
Ingo Molnaradac1662006-01-25 19:50:12 +0100227 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800228 return NULL;
229 }
230 atomic_inc(&n_rcu_torture_alloc);
231 p = rcu_torture_freelist.next;
232 list_del_init(p);
Ingo Molnaradac1662006-01-25 19:50:12 +0100233 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800234 return container_of(p, struct rcu_torture, rtort_free);
235}
236
237/*
238 * Free an element to the rcu_tortures pool.
239 */
240static void
241rcu_torture_free(struct rcu_torture *p)
242{
243 atomic_inc(&n_rcu_torture_free);
Ingo Molnaradac1662006-01-25 19:50:12 +0100244 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800245 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
Ingo Molnaradac1662006-01-25 19:50:12 +0100246 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800247}
248
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800249struct rcu_random_state {
250 unsigned long rrs_state;
Josh Triplett75cfef32006-10-04 02:17:12 -0700251 long rrs_count;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800252};
253
254#define RCU_RANDOM_MULT 39916801 /* prime */
255#define RCU_RANDOM_ADD 479001701 /* prime */
256#define RCU_RANDOM_REFRESH 10000
257
258#define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
259
260/*
261 * Crude but fast random-number generator. Uses a linear congruential
Paul E. McKenneyc17ac852007-10-16 23:27:19 -0700262 * generator, with occasional help from cpu_clock().
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800263 */
Josh Triplett75cfef32006-10-04 02:17:12 -0700264static unsigned long
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800265rcu_random(struct rcu_random_state *rrsp)
266{
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800267 if (--rrsp->rrs_count < 0) {
Peter Zijlstrac6763292010-05-25 10:48:51 +0200268 rrsp->rrs_state += (unsigned long)local_clock();
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800269 rrsp->rrs_count = RCU_RANDOM_REFRESH;
270 }
271 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
272 return swahw32(rrsp->rrs_state);
273}
274
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700275static void
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800276rcu_stutter_wait(char *title)
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700277{
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800278 while (stutter_pause_test || !rcutorture_runnable) {
Paul E. McKenneye3d7be22008-06-22 13:06:38 -0700279 if (rcutorture_runnable)
280 schedule_timeout_interruptible(1);
281 else
Paul E. McKenney3ccf79f2008-06-22 14:02:55 -0700282 schedule_timeout_interruptible(round_jiffies_relative(HZ));
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800283 rcutorture_shutdown_absorb(title);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800284 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700285}
286
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800287/*
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700288 * Operations vector for selecting different types of tests.
289 */
290
291struct rcu_torture_ops {
292 void (*init)(void);
293 void (*cleanup)(void);
294 int (*readlock)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700295 void (*read_delay)(struct rcu_random_state *rrsp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700296 void (*readunlock)(int idx);
297 int (*completed)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700298 void (*deferred_free)(struct rcu_torture *p);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700299 void (*sync)(void);
Paul E. McKenney23269742008-05-12 21:21:05 +0200300 void (*cb_barrier)(void);
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800301 void (*fqs)(void);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700302 int (*stats)(char *page);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700303 int irq_capable;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700304 int can_boost;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700305 char *name;
306};
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700307
308static struct rcu_torture_ops *cur_ops;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700309
310/*
311 * Definitions for rcu torture testing.
312 */
313
Josh Tripletta49a4af2006-09-29 01:59:30 -0700314static int rcu_torture_read_lock(void) __acquires(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700315{
316 rcu_read_lock();
317 return 0;
318}
319
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700320static void rcu_read_delay(struct rcu_random_state *rrsp)
321{
Josh Triplettb8d57a72009-09-08 15:54:35 -0700322 const unsigned long shortdelay_us = 200;
323 const unsigned long longdelay_ms = 50;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700324
Josh Triplettb8d57a72009-09-08 15:54:35 -0700325 /* We want a short delay sometimes to make a reader delay the grace
326 * period, and we want a long delay occasionally to trigger
327 * force_quiescent_state. */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700328
Josh Triplettb8d57a72009-09-08 15:54:35 -0700329 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
330 mdelay(longdelay_ms);
331 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
332 udelay(shortdelay_us);
Lai Jiangshane546f482010-06-21 16:57:42 +0800333#ifdef CONFIG_PREEMPT
334 if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000)))
335 preempt_schedule(); /* No QS if preempt_disable() in effect */
336#endif
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700337}
338
Josh Tripletta49a4af2006-09-29 01:59:30 -0700339static void rcu_torture_read_unlock(int idx) __releases(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700340{
341 rcu_read_unlock();
342}
343
344static int rcu_torture_completed(void)
345{
346 return rcu_batches_completed();
347}
348
349static void
350rcu_torture_cb(struct rcu_head *p)
351{
352 int i;
353 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
354
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800355 if (fullstop != FULLSTOP_DONTSTOP) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700356 /* Test is ending, just drop callbacks on the floor. */
357 /* The next initialization will pick up the pieces. */
358 return;
359 }
360 i = rp->rtort_pipe_count;
361 if (i > RCU_TORTURE_PIPE_LEN)
362 i = RCU_TORTURE_PIPE_LEN;
363 atomic_inc(&rcu_torture_wcount[i]);
364 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
365 rp->rtort_mbtest = 0;
366 rcu_torture_free(rp);
367 } else
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700368 cur_ops->deferred_free(rp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700369}
370
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800371static int rcu_no_completed(void)
372{
373 return 0;
374}
375
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700376static void rcu_torture_deferred_free(struct rcu_torture *p)
377{
378 call_rcu(&p->rtort_rcu, rcu_torture_cb);
379}
380
381static struct rcu_torture_ops rcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700382 .init = NULL,
383 .cleanup = NULL,
384 .readlock = rcu_torture_read_lock,
385 .read_delay = rcu_read_delay,
386 .readunlock = rcu_torture_read_unlock,
387 .completed = rcu_torture_completed,
388 .deferred_free = rcu_torture_deferred_free,
389 .sync = synchronize_rcu,
390 .cb_barrier = rcu_barrier,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800391 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700392 .stats = NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700393 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700394 .can_boost = rcu_can_boost(),
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700395 .name = "rcu"
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700396};
397
Josh Triplette3033732006-10-04 02:17:14 -0700398static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
399{
400 int i;
401 struct rcu_torture *rp;
402 struct rcu_torture *rp1;
403
404 cur_ops->sync();
405 list_add(&p->rtort_free, &rcu_torture_removed);
406 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
407 i = rp->rtort_pipe_count;
408 if (i > RCU_TORTURE_PIPE_LEN)
409 i = RCU_TORTURE_PIPE_LEN;
410 atomic_inc(&rcu_torture_wcount[i]);
411 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
412 rp->rtort_mbtest = 0;
413 list_del(&rp->rtort_free);
414 rcu_torture_free(rp);
415 }
416 }
417}
418
419static void rcu_sync_torture_init(void)
420{
421 INIT_LIST_HEAD(&rcu_torture_removed);
422}
423
Josh Triplett20d2e422006-10-04 02:17:15 -0700424static struct rcu_torture_ops rcu_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700425 .init = rcu_sync_torture_init,
426 .cleanup = NULL,
427 .readlock = rcu_torture_read_lock,
428 .read_delay = rcu_read_delay,
429 .readunlock = rcu_torture_read_unlock,
430 .completed = rcu_torture_completed,
431 .deferred_free = rcu_sync_torture_deferred_free,
432 .sync = synchronize_rcu,
433 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800434 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700435 .stats = NULL,
436 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700437 .can_boost = rcu_can_boost(),
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700438 .name = "rcu_sync"
Josh Triplett20d2e422006-10-04 02:17:15 -0700439};
440
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800441static struct rcu_torture_ops rcu_expedited_ops = {
442 .init = rcu_sync_torture_init,
443 .cleanup = NULL,
444 .readlock = rcu_torture_read_lock,
445 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
446 .readunlock = rcu_torture_read_unlock,
447 .completed = rcu_no_completed,
448 .deferred_free = rcu_sync_torture_deferred_free,
449 .sync = synchronize_rcu_expedited,
450 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800451 .fqs = rcu_force_quiescent_state,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800452 .stats = NULL,
453 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700454 .can_boost = rcu_can_boost(),
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800455 .name = "rcu_expedited"
456};
457
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700458/*
459 * Definitions for rcu_bh torture testing.
460 */
461
Josh Tripletta49a4af2006-09-29 01:59:30 -0700462static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700463{
464 rcu_read_lock_bh();
465 return 0;
466}
467
Josh Tripletta49a4af2006-09-29 01:59:30 -0700468static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700469{
470 rcu_read_unlock_bh();
471}
472
473static int rcu_bh_torture_completed(void)
474{
475 return rcu_batches_completed_bh();
476}
477
478static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
479{
480 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
481}
482
483static struct rcu_torture_ops rcu_bh_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700484 .init = NULL,
485 .cleanup = NULL,
486 .readlock = rcu_bh_torture_read_lock,
487 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
488 .readunlock = rcu_bh_torture_read_unlock,
489 .completed = rcu_bh_torture_completed,
490 .deferred_free = rcu_bh_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700491 .sync = synchronize_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700492 .cb_barrier = rcu_barrier_bh,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800493 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700494 .stats = NULL,
495 .irq_capable = 1,
496 .name = "rcu_bh"
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700497};
498
Josh Triplett11a14702006-10-04 02:17:16 -0700499static struct rcu_torture_ops rcu_bh_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700500 .init = rcu_sync_torture_init,
501 .cleanup = NULL,
502 .readlock = rcu_bh_torture_read_lock,
503 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
504 .readunlock = rcu_bh_torture_read_unlock,
505 .completed = rcu_bh_torture_completed,
506 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700507 .sync = synchronize_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700508 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800509 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700510 .stats = NULL,
511 .irq_capable = 1,
512 .name = "rcu_bh_sync"
Josh Triplett11a14702006-10-04 02:17:16 -0700513};
514
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700515static struct rcu_torture_ops rcu_bh_expedited_ops = {
516 .init = rcu_sync_torture_init,
517 .cleanup = NULL,
518 .readlock = rcu_bh_torture_read_lock,
519 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
520 .readunlock = rcu_bh_torture_read_unlock,
521 .completed = rcu_bh_torture_completed,
522 .deferred_free = rcu_sync_torture_deferred_free,
523 .sync = synchronize_rcu_bh_expedited,
524 .cb_barrier = NULL,
525 .fqs = rcu_bh_force_quiescent_state,
526 .stats = NULL,
527 .irq_capable = 1,
528 .name = "rcu_bh_expedited"
529};
530
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700531/*
532 * Definitions for srcu torture testing.
533 */
534
535static struct srcu_struct srcu_ctl;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700536
537static void srcu_torture_init(void)
538{
539 init_srcu_struct(&srcu_ctl);
Josh Triplette3033732006-10-04 02:17:14 -0700540 rcu_sync_torture_init();
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700541}
542
543static void srcu_torture_cleanup(void)
544{
545 synchronize_srcu(&srcu_ctl);
546 cleanup_srcu_struct(&srcu_ctl);
547}
548
Josh Triplett012d3ca2006-12-06 20:40:19 -0800549static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700550{
551 return srcu_read_lock(&srcu_ctl);
552}
553
554static void srcu_read_delay(struct rcu_random_state *rrsp)
555{
556 long delay;
557 const long uspertick = 1000000 / HZ;
558 const long longdelay = 10;
559
560 /* We want there to be long-running readers, but not all the time. */
561
562 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
563 if (!delay)
564 schedule_timeout_interruptible(longdelay);
Lai Jiangshane546f482010-06-21 16:57:42 +0800565 else
566 rcu_read_delay(rrsp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700567}
568
Josh Triplett012d3ca2006-12-06 20:40:19 -0800569static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700570{
571 srcu_read_unlock(&srcu_ctl, idx);
572}
573
574static int srcu_torture_completed(void)
575{
576 return srcu_batches_completed(&srcu_ctl);
577}
578
Josh Triplettb772e1d2006-10-04 02:17:13 -0700579static void srcu_torture_synchronize(void)
580{
581 synchronize_srcu(&srcu_ctl);
582}
583
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700584static int srcu_torture_stats(char *page)
585{
586 int cnt = 0;
587 int cpu;
588 int idx = srcu_ctl.completed & 0x1;
589
590 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
591 torture_type, TORTURE_FLAG, idx);
592 for_each_possible_cpu(cpu) {
593 cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu,
594 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
595 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
596 }
597 cnt += sprintf(&page[cnt], "\n");
598 return cnt;
599}
600
601static struct rcu_torture_ops srcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700602 .init = srcu_torture_init,
603 .cleanup = srcu_torture_cleanup,
604 .readlock = srcu_torture_read_lock,
605 .read_delay = srcu_read_delay,
606 .readunlock = srcu_torture_read_unlock,
607 .completed = srcu_torture_completed,
608 .deferred_free = rcu_sync_torture_deferred_free,
609 .sync = srcu_torture_synchronize,
610 .cb_barrier = NULL,
611 .stats = srcu_torture_stats,
612 .name = "srcu"
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700613};
614
Paul E. McKenney804bb832009-10-25 19:03:52 -0700615static void srcu_torture_synchronize_expedited(void)
616{
617 synchronize_srcu_expedited(&srcu_ctl);
618}
619
620static struct rcu_torture_ops srcu_expedited_ops = {
621 .init = srcu_torture_init,
622 .cleanup = srcu_torture_cleanup,
623 .readlock = srcu_torture_read_lock,
624 .read_delay = srcu_read_delay,
625 .readunlock = srcu_torture_read_unlock,
626 .completed = srcu_torture_completed,
627 .deferred_free = rcu_sync_torture_deferred_free,
628 .sync = srcu_torture_synchronize_expedited,
629 .cb_barrier = NULL,
630 .stats = srcu_torture_stats,
631 .name = "srcu_expedited"
632};
633
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700634/*
635 * Definitions for sched torture testing.
636 */
637
638static int sched_torture_read_lock(void)
639{
640 preempt_disable();
641 return 0;
642}
643
644static void sched_torture_read_unlock(int idx)
645{
646 preempt_enable();
647}
648
Paul E. McKenney23269742008-05-12 21:21:05 +0200649static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
650{
651 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
652}
653
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700654static struct rcu_torture_ops sched_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700655 .init = rcu_sync_torture_init,
656 .cleanup = NULL,
657 .readlock = sched_torture_read_lock,
658 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
659 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800660 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700661 .deferred_free = rcu_sched_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700662 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700663 .cb_barrier = rcu_barrier_sched,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800664 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700665 .stats = NULL,
666 .irq_capable = 1,
667 .name = "sched"
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700668};
669
Paul E. McKenney804bb832009-10-25 19:03:52 -0700670static struct rcu_torture_ops sched_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700671 .init = rcu_sync_torture_init,
672 .cleanup = NULL,
673 .readlock = sched_torture_read_lock,
674 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
675 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800676 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700677 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700678 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700679 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800680 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700681 .stats = NULL,
682 .name = "sched_sync"
683};
684
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700685static struct rcu_torture_ops sched_expedited_ops = {
686 .init = rcu_sync_torture_init,
687 .cleanup = NULL,
688 .readlock = sched_torture_read_lock,
689 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
690 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800691 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700692 .deferred_free = rcu_sync_torture_deferred_free,
693 .sync = synchronize_sched_expedited,
694 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800695 .fqs = rcu_sched_force_quiescent_state,
Tejun Heo969c7922010-05-06 18:49:21 +0200696 .stats = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700697 .irq_capable = 1,
698 .name = "sched_expedited"
Paul E. McKenney23269742008-05-12 21:21:05 +0200699};
700
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700701/*
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700702 * RCU torture priority-boost testing. Runs one real-time thread per
703 * CPU for moderate bursts, repeatedly registering RCU callbacks and
704 * spinning waiting for them to be invoked. If a given callback takes
705 * too long to be invoked, we assume that priority inversion has occurred.
706 */
707
708struct rcu_boost_inflight {
709 struct rcu_head rcu;
710 int inflight;
711};
712
713static void rcu_torture_boost_cb(struct rcu_head *head)
714{
715 struct rcu_boost_inflight *rbip =
716 container_of(head, struct rcu_boost_inflight, rcu);
717
718 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
719 rbip->inflight = 0;
720}
721
722static int rcu_torture_boost(void *arg)
723{
724 unsigned long call_rcu_time;
725 unsigned long endtime;
726 unsigned long oldstarttime;
727 struct rcu_boost_inflight rbi = { .inflight = 0 };
728 struct sched_param sp;
729
730 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
731
732 /* Set real-time priority. */
733 sp.sched_priority = 1;
734 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
735 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
736 n_rcu_torture_boost_rterror++;
737 }
738
Paul E. McKenney561190e2011-03-30 09:10:44 -0700739 init_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700740 /* Each pass through the following loop does one boost-test cycle. */
741 do {
742 /* Wait for the next test interval. */
743 oldstarttime = boost_starttime;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700744 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700745 schedule_timeout_uninterruptible(1);
746 rcu_stutter_wait("rcu_torture_boost");
747 if (kthread_should_stop() ||
748 fullstop != FULLSTOP_DONTSTOP)
749 goto checkwait;
750 }
751
752 /* Do one boost-test interval. */
753 endtime = oldstarttime + test_boost_duration * HZ;
754 call_rcu_time = jiffies;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700755 while (ULONG_CMP_LT(jiffies, endtime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700756 /* If we don't have a callback in flight, post one. */
757 if (!rbi.inflight) {
758 smp_mb(); /* RCU core before ->inflight = 1. */
759 rbi.inflight = 1;
760 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
761 if (jiffies - call_rcu_time >
762 test_boost_duration * HZ - HZ / 2) {
763 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
764 n_rcu_torture_boost_failure++;
765 }
766 call_rcu_time = jiffies;
767 }
768 cond_resched();
769 rcu_stutter_wait("rcu_torture_boost");
770 if (kthread_should_stop() ||
771 fullstop != FULLSTOP_DONTSTOP)
772 goto checkwait;
773 }
774
775 /*
776 * Set the start time of the next test interval.
777 * Yes, this is vulnerable to long delays, but such
778 * delays simply cause a false negative for the next
779 * interval. Besides, we are running at RT priority,
780 * so delays should be relatively rare.
781 */
782 while (oldstarttime == boost_starttime) {
783 if (mutex_trylock(&boost_mutex)) {
784 boost_starttime = jiffies +
785 test_boost_interval * HZ;
786 n_rcu_torture_boosts++;
787 mutex_unlock(&boost_mutex);
788 break;
789 }
790 schedule_timeout_uninterruptible(1);
791 }
792
793 /* Go do the stutter. */
794checkwait: rcu_stutter_wait("rcu_torture_boost");
795 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
796
797 /* Clean up and exit. */
798 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
799 rcutorture_shutdown_absorb("rcu_torture_boost");
800 while (!kthread_should_stop() || rbi.inflight)
801 schedule_timeout_uninterruptible(1);
802 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
Paul E. McKenney9d681972011-06-21 01:48:03 -0700803 destroy_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700804 return 0;
805}
806
807/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800808 * RCU torture force-quiescent-state kthread. Repeatedly induces
809 * bursts of calls to force_quiescent_state(), increasing the probability
810 * of occurrence of some important types of race conditions.
811 */
812static int
813rcu_torture_fqs(void *arg)
814{
815 unsigned long fqs_resume_time;
816 int fqs_burst_remaining;
817
818 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
819 do {
820 fqs_resume_time = jiffies + fqs_stutter * HZ;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700821 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
822 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800823 schedule_timeout_interruptible(1);
824 }
825 fqs_burst_remaining = fqs_duration;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700826 while (fqs_burst_remaining > 0 &&
827 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800828 cur_ops->fqs();
829 udelay(fqs_holdoff);
830 fqs_burst_remaining -= fqs_holdoff;
831 }
832 rcu_stutter_wait("rcu_torture_fqs");
833 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
834 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
835 rcutorture_shutdown_absorb("rcu_torture_fqs");
836 while (!kthread_should_stop())
837 schedule_timeout_uninterruptible(1);
838 return 0;
839}
840
841/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800842 * RCU torture writer kthread. Repeatedly substitutes a new structure
843 * for that pointed to by rcu_torture_current, freeing the old structure
844 * after a series of grace periods (the "pipeline").
845 */
846static int
847rcu_torture_writer(void *arg)
848{
849 int i;
850 long oldbatch = rcu_batches_completed();
851 struct rcu_torture *rp;
852 struct rcu_torture *old_rp;
853 static DEFINE_RCU_RANDOM(rand);
854
855 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800856 set_user_nice(current, 19);
857
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800858 do {
859 schedule_timeout_uninterruptible(1);
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700860 rp = rcu_torture_alloc();
861 if (rp == NULL)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800862 continue;
863 rp->rtort_pipe_count = 0;
864 udelay(rcu_random(&rand) & 0x3ff);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700865 old_rp = rcu_dereference_check(rcu_torture_current,
866 current == writer_task);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800867 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800868 rcu_assign_pointer(rcu_torture_current, rp);
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700869 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
Josh Triplettc8e5b162007-05-08 00:33:20 -0700870 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800871 i = old_rp->rtort_pipe_count;
872 if (i > RCU_TORTURE_PIPE_LEN)
873 i = RCU_TORTURE_PIPE_LEN;
874 atomic_inc(&rcu_torture_wcount[i]);
875 old_rp->rtort_pipe_count++;
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700876 cur_ops->deferred_free(old_rp);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800877 }
Paul E. McKenney4a298652011-04-03 21:33:51 -0700878 rcutorture_record_progress(++rcu_torture_current_version);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700879 oldbatch = cur_ops->completed();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800880 rcu_stutter_wait("rcu_torture_writer");
881 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800882 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800883 rcutorture_shutdown_absorb("rcu_torture_writer");
884 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800885 schedule_timeout_uninterruptible(1);
886 return 0;
887}
888
889/*
Josh Triplettb772e1d2006-10-04 02:17:13 -0700890 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
891 * delay between calls.
892 */
893static int
894rcu_torture_fakewriter(void *arg)
895{
896 DEFINE_RCU_RANDOM(rand);
897
898 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
899 set_user_nice(current, 19);
900
901 do {
902 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
903 udelay(rcu_random(&rand) & 0x3ff);
904 cur_ops->sync();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800905 rcu_stutter_wait("rcu_torture_fakewriter");
906 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700907
908 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800909 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
910 while (!kthread_should_stop())
Josh Triplettb772e1d2006-10-04 02:17:13 -0700911 schedule_timeout_uninterruptible(1);
912 return 0;
913}
914
915/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700916 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
917 * incrementing the corresponding element of the pipeline array. The
918 * counter in the element should never be greater than 1, otherwise, the
919 * RCU implementation is broken.
920 */
921static void rcu_torture_timer(unsigned long unused)
922{
923 int idx;
924 int completed;
925 static DEFINE_RCU_RANDOM(rand);
926 static DEFINE_SPINLOCK(rand_lock);
927 struct rcu_torture *p;
928 int pipe_count;
929
930 idx = cur_ops->readlock();
931 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -0800932 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -0800933 rcu_read_lock_bh_held() ||
934 rcu_read_lock_sched_held() ||
935 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700936 if (p == NULL) {
937 /* Leave because rcu_torture_writer is not yet underway */
938 cur_ops->readunlock(idx);
939 return;
940 }
941 if (p->rtort_mbtest == 0)
942 atomic_inc(&n_rcu_torture_mberror);
943 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700944 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700945 n_rcu_torture_timers++;
946 spin_unlock(&rand_lock);
947 preempt_disable();
948 pipe_count = p->rtort_pipe_count;
949 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
950 /* Should not happen, but... */
951 pipe_count = RCU_TORTURE_PIPE_LEN;
952 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +0900953 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700954 completed = cur_ops->completed() - completed;
955 if (completed > RCU_TORTURE_PIPE_LEN) {
956 /* Should not happen, but... */
957 completed = RCU_TORTURE_PIPE_LEN;
958 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +0900959 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700960 preempt_enable();
961 cur_ops->readunlock(idx);
962}
963
964/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800965 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
966 * incrementing the corresponding element of the pipeline array. The
967 * counter in the element should never be greater than 1, otherwise, the
968 * RCU implementation is broken.
969 */
970static int
971rcu_torture_reader(void *arg)
972{
973 int completed;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700974 int idx;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800975 DEFINE_RCU_RANDOM(rand);
976 struct rcu_torture *p;
977 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700978 struct timer_list t;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800979
980 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800981 set_user_nice(current, 19);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700982 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700983 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800984
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800985 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700986 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700987 if (!timer_pending(&t))
Paul E. McKenney6155fec2010-02-22 17:05:04 -0800988 mod_timer(&t, jiffies + 1);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700989 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700990 idx = cur_ops->readlock();
991 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -0800992 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -0800993 rcu_read_lock_bh_held() ||
994 rcu_read_lock_sched_held() ||
995 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800996 if (p == NULL) {
997 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700998 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800999 schedule_timeout_interruptible(HZ);
1000 continue;
1001 }
Paul E. McKenney996417d2005-11-18 01:10:50 -08001002 if (p->rtort_mbtest == 0)
1003 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001004 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001005 preempt_disable();
1006 pipe_count = p->rtort_pipe_count;
1007 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1008 /* Should not happen, but... */
1009 pipe_count = RCU_TORTURE_PIPE_LEN;
1010 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001011 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001012 completed = cur_ops->completed() - completed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001013 if (completed > RCU_TORTURE_PIPE_LEN) {
1014 /* Should not happen, but... */
1015 completed = RCU_TORTURE_PIPE_LEN;
1016 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001017 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001018 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001019 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001020 schedule();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001021 rcu_stutter_wait("rcu_torture_reader");
1022 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001023 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001024 rcutorture_shutdown_absorb("rcu_torture_reader");
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001025 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001026 del_timer_sync(&t);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001027 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001028 schedule_timeout_uninterruptible(1);
1029 return 0;
1030}
1031
1032/*
1033 * Create an RCU-torture statistics message in the specified buffer.
1034 */
1035static int
1036rcu_torture_printk(char *page)
1037{
1038 int cnt = 0;
1039 int cpu;
1040 int i;
1041 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1042 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1043
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001044 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001045 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1046 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1047 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1048 }
1049 }
1050 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1051 if (pipesummary[i] != 0)
1052 break;
1053 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001054 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001055 cnt += sprintf(&page[cnt],
Paul E. McKenney4a298652011-04-03 21:33:51 -07001056 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d "
Paul E. McKenney67b98db2011-02-21 13:31:55 -08001057 "rtmbe: %d rtbke: %ld rtbre: %ld "
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001058 "rtbf: %ld rtb: %ld nt: %ld",
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001059 rcu_torture_current,
1060 rcu_torture_current_version,
1061 list_empty(&rcu_torture_freelist),
1062 atomic_read(&n_rcu_torture_alloc),
1063 atomic_read(&n_rcu_torture_alloc_fail),
Paul E. McKenney996417d2005-11-18 01:10:50 -08001064 atomic_read(&n_rcu_torture_free),
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001065 atomic_read(&n_rcu_torture_mberror),
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001066 n_rcu_torture_boost_ktrerror,
1067 n_rcu_torture_boost_rterror,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001068 n_rcu_torture_boost_failure,
1069 n_rcu_torture_boosts,
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001070 n_rcu_torture_timers);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001071 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
1072 n_rcu_torture_boost_ktrerror != 0 ||
1073 n_rcu_torture_boost_rterror != 0 ||
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001074 n_rcu_torture_boost_failure != 0)
Paul E. McKenney996417d2005-11-18 01:10:50 -08001075 cnt += sprintf(&page[cnt], " !!!");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001076 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001077 if (i > 1) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001078 cnt += sprintf(&page[cnt], "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -08001079 atomic_inc(&n_rcu_torture_error);
Ingo Molnar5af970a2008-06-18 10:09:48 +02001080 WARN_ON_ONCE(1);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001081 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001082 cnt += sprintf(&page[cnt], "Reader Pipe: ");
1083 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1084 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001085 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001086 cnt += sprintf(&page[cnt], "Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001087 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001088 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001089 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001090 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
1091 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1092 cnt += sprintf(&page[cnt], " %d",
1093 atomic_read(&rcu_torture_wcount[i]));
1094 }
1095 cnt += sprintf(&page[cnt], "\n");
Josh Triplettc8e5b162007-05-08 00:33:20 -07001096 if (cur_ops->stats)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001097 cnt += cur_ops->stats(&page[cnt]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001098 return cnt;
1099}
1100
1101/*
1102 * Print torture statistics. Caller must ensure that there is only
1103 * one call to this function at a given time!!! This is normally
1104 * accomplished by relying on the module system to only have one copy
1105 * of the module loaded, and then by giving the rcu_torture_stats
1106 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1107 * thread is not running).
1108 */
1109static void
1110rcu_torture_stats_print(void)
1111{
1112 int cnt;
1113
1114 cnt = rcu_torture_printk(printk_buf);
1115 printk(KERN_ALERT "%s", printk_buf);
1116}
1117
1118/*
1119 * Periodically prints torture statistics, if periodic statistics printing
1120 * was specified via the stat_interval module parameter.
1121 *
1122 * No need to worry about fullstop here, since this one doesn't reference
1123 * volatile state or register callbacks.
1124 */
1125static int
1126rcu_torture_stats(void *arg)
1127{
1128 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1129 do {
1130 schedule_timeout_interruptible(stat_interval * HZ);
1131 rcu_torture_stats_print();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001132 rcutorture_shutdown_absorb("rcu_torture_stats");
1133 } while (!kthread_should_stop());
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001134 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1135 return 0;
1136}
1137
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001138static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
1139
1140/* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1141 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1142 */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -07001143static void rcu_torture_shuffle_tasks(void)
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001144{
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001145 int i;
1146
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001147 cpumask_setall(shuffle_tmp_mask);
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001148 get_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001149
1150 /* No point in shuffling if there is only one online CPU (ex: UP) */
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001151 if (num_online_cpus() == 1) {
1152 put_online_cpus();
1153 return;
1154 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001155
1156 if (rcu_idle_cpu != -1)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001157 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001158
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001159 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001160
Josh Triplettc8e5b162007-05-08 00:33:20 -07001161 if (reader_tasks) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001162 for (i = 0; i < nrealreaders; i++)
1163 if (reader_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001164 set_cpus_allowed_ptr(reader_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001165 shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001166 }
1167
Josh Triplettc8e5b162007-05-08 00:33:20 -07001168 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001169 for (i = 0; i < nfakewriters; i++)
1170 if (fakewriter_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001171 set_cpus_allowed_ptr(fakewriter_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001172 shuffle_tmp_mask);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001173 }
1174
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001175 if (writer_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001176 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001177
1178 if (stats_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001179 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001180
1181 if (rcu_idle_cpu == -1)
1182 rcu_idle_cpu = num_online_cpus() - 1;
1183 else
1184 rcu_idle_cpu--;
1185
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001186 put_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001187}
1188
1189/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1190 * system to become idle at a time and cut off its timer ticks. This is meant
1191 * to test the support for such tickless idle CPU in RCU.
1192 */
1193static int
1194rcu_torture_shuffle(void *arg)
1195{
1196 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1197 do {
1198 schedule_timeout_interruptible(shuffle_interval * HZ);
1199 rcu_torture_shuffle_tasks();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001200 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1201 } while (!kthread_should_stop());
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001202 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1203 return 0;
1204}
1205
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001206/* Cause the rcutorture test to "stutter", starting and stopping all
1207 * threads periodically.
1208 */
1209static int
1210rcu_torture_stutter(void *arg)
1211{
1212 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1213 do {
1214 schedule_timeout_interruptible(stutter * HZ);
1215 stutter_pause_test = 1;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001216 if (!kthread_should_stop())
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001217 schedule_timeout_interruptible(stutter * HZ);
1218 stutter_pause_test = 0;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001219 rcutorture_shutdown_absorb("rcu_torture_stutter");
1220 } while (!kthread_should_stop());
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001221 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1222 return 0;
1223}
1224
Paul E. McKenney95c38322006-03-24 03:15:58 -08001225static inline void
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001226rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
Paul E. McKenney95c38322006-03-24 03:15:58 -08001227{
Josh Triplettb772e1d2006-10-04 02:17:13 -07001228 printk(KERN_ALERT "%s" TORTURE_FLAG
1229 "--- %s: nreaders=%d nfakewriters=%d "
Paul E. McKenney95c38322006-03-24 03:15:58 -08001230 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001231 "shuffle_interval=%d stutter=%d irqreader=%d "
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001232 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1233 "test_boost=%d/%d test_boost_interval=%d "
1234 "test_boost_duration=%d\n",
Josh Triplettb772e1d2006-10-04 02:17:13 -07001235 torture_type, tag, nrealreaders, nfakewriters,
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001236 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001237 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1238 test_boost, cur_ops->can_boost,
1239 test_boost_interval, test_boost_duration);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001240}
1241
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001242static struct notifier_block rcutorture_shutdown_nb = {
Paul E. McKenney343e9092008-12-15 16:13:07 -08001243 .notifier_call = rcutorture_shutdown_notify,
1244};
1245
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001246static void rcutorture_booster_cleanup(int cpu)
1247{
1248 struct task_struct *t;
1249
1250 if (boost_tasks[cpu] == NULL)
1251 return;
1252 mutex_lock(&boost_mutex);
1253 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1254 t = boost_tasks[cpu];
1255 boost_tasks[cpu] = NULL;
1256 mutex_unlock(&boost_mutex);
1257
1258 /* This must be outside of the mutex, otherwise deadlock! */
1259 kthread_stop(t);
1260}
1261
1262static int rcutorture_booster_init(int cpu)
1263{
1264 int retval;
1265
1266 if (boost_tasks[cpu] != NULL)
1267 return 0; /* Already created, nothing more to do. */
1268
1269 /* Don't allow time recalculation while creating a new task. */
1270 mutex_lock(&boost_mutex);
1271 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
Eric Dumazet1f288092011-06-16 15:53:18 -07001272 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1273 cpu_to_node(cpu),
1274 "rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001275 if (IS_ERR(boost_tasks[cpu])) {
1276 retval = PTR_ERR(boost_tasks[cpu]);
1277 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1278 n_rcu_torture_boost_ktrerror++;
1279 boost_tasks[cpu] = NULL;
1280 mutex_unlock(&boost_mutex);
1281 return retval;
1282 }
1283 kthread_bind(boost_tasks[cpu], cpu);
1284 wake_up_process(boost_tasks[cpu]);
1285 mutex_unlock(&boost_mutex);
1286 return 0;
1287}
1288
1289static int rcutorture_cpu_notify(struct notifier_block *self,
1290 unsigned long action, void *hcpu)
1291{
1292 long cpu = (long)hcpu;
1293
1294 switch (action) {
1295 case CPU_ONLINE:
1296 case CPU_DOWN_FAILED:
1297 (void)rcutorture_booster_init(cpu);
1298 break;
1299 case CPU_DOWN_PREPARE:
1300 rcutorture_booster_cleanup(cpu);
1301 break;
1302 default:
1303 break;
1304 }
1305 return NOTIFY_OK;
1306}
1307
1308static struct notifier_block rcutorture_cpu_nb = {
1309 .notifier_call = rcutorture_cpu_notify,
1310};
1311
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001312static void
1313rcu_torture_cleanup(void)
1314{
1315 int i;
1316
Paul E. McKenney343e9092008-12-15 16:13:07 -08001317 mutex_lock(&fullstop_mutex);
Paul E. McKenney4a298652011-04-03 21:33:51 -07001318 rcutorture_record_test_transition();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001319 if (fullstop == FULLSTOP_SHUTDOWN) {
1320 printk(KERN_WARNING /* but going down anyway, so... */
1321 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001322 mutex_unlock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001323 schedule_timeout_uninterruptible(10);
Paul E. McKenney343e9092008-12-15 16:13:07 -08001324 if (cur_ops->cb_barrier != NULL)
1325 cur_ops->cb_barrier();
1326 return;
1327 }
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001328 fullstop = FULLSTOP_RMMOD;
Paul E. McKenney343e9092008-12-15 16:13:07 -08001329 mutex_unlock(&fullstop_mutex);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001330 unregister_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001331 if (stutter_task) {
1332 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1333 kthread_stop(stutter_task);
1334 }
1335 stutter_task = NULL;
Josh Triplettc8e5b162007-05-08 00:33:20 -07001336 if (shuffler_task) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001337 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1338 kthread_stop(shuffler_task);
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001339 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001340 }
1341 shuffler_task = NULL;
1342
Josh Triplettc8e5b162007-05-08 00:33:20 -07001343 if (writer_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001344 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1345 kthread_stop(writer_task);
1346 }
1347 writer_task = NULL;
1348
Josh Triplettc8e5b162007-05-08 00:33:20 -07001349 if (reader_tasks) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001350 for (i = 0; i < nrealreaders; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001351 if (reader_tasks[i]) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001352 VERBOSE_PRINTK_STRING(
1353 "Stopping rcu_torture_reader task");
1354 kthread_stop(reader_tasks[i]);
1355 }
1356 reader_tasks[i] = NULL;
1357 }
1358 kfree(reader_tasks);
1359 reader_tasks = NULL;
1360 }
1361 rcu_torture_current = NULL;
1362
Josh Triplettc8e5b162007-05-08 00:33:20 -07001363 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001364 for (i = 0; i < nfakewriters; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001365 if (fakewriter_tasks[i]) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001366 VERBOSE_PRINTK_STRING(
1367 "Stopping rcu_torture_fakewriter task");
1368 kthread_stop(fakewriter_tasks[i]);
1369 }
1370 fakewriter_tasks[i] = NULL;
1371 }
1372 kfree(fakewriter_tasks);
1373 fakewriter_tasks = NULL;
1374 }
1375
Josh Triplettc8e5b162007-05-08 00:33:20 -07001376 if (stats_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001377 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1378 kthread_stop(stats_task);
1379 }
1380 stats_task = NULL;
1381
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001382 if (fqs_task) {
1383 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1384 kthread_stop(fqs_task);
1385 }
1386 fqs_task = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001387 if ((test_boost == 1 && cur_ops->can_boost) ||
1388 test_boost == 2) {
1389 unregister_cpu_notifier(&rcutorture_cpu_nb);
1390 for_each_possible_cpu(i)
1391 rcutorture_booster_cleanup(i);
1392 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001393
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001394 /* Wait for all RCU callbacks to fire. */
Paul E. McKenney23269742008-05-12 21:21:05 +02001395
1396 if (cur_ops->cb_barrier != NULL)
1397 cur_ops->cb_barrier();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001398
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001399 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001400
Josh Triplettc8e5b162007-05-08 00:33:20 -07001401 if (cur_ops->cleanup)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001402 cur_ops->cleanup();
Paul E. McKenney95c38322006-03-24 03:15:58 -08001403 if (atomic_read(&n_rcu_torture_error))
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001404 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
Paul E. McKenney95c38322006-03-24 03:15:58 -08001405 else
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001406 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001407}
1408
Josh Triplett6f8bc502007-05-08 00:25:24 -07001409static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001410rcu_torture_init(void)
1411{
1412 int i;
1413 int cpu;
1414 int firsterr = 0;
Josh Triplettade5fb82007-05-08 00:33:22 -07001415 static struct rcu_torture_ops *torture_ops[] =
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -08001416 { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -07001417 &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops,
Paul E. McKenney804bb832009-10-25 19:03:52 -07001418 &srcu_ops, &srcu_expedited_ops,
1419 &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001420
Paul E. McKenney343e9092008-12-15 16:13:07 -08001421 mutex_lock(&fullstop_mutex);
1422
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001423 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001424 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001425 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001426 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001427 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001428 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001429 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001430 printk(KERN_ALERT "rcu-torture: invalid torture type: \"%s\"\n",
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001431 torture_type);
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001432 printk(KERN_ALERT "rcu-torture types:");
1433 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
1434 printk(KERN_ALERT " %s", torture_ops[i]->name);
1435 printk(KERN_ALERT "\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001436 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001437 return -EINVAL;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001438 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001439 if (cur_ops->fqs == NULL && fqs_duration != 0) {
1440 printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero "
1441 "fqs_duration, fqs disabled.\n");
1442 fqs_duration = 0;
1443 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001444 if (cur_ops->init)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001445 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1446
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001447 if (nreaders >= 0)
1448 nrealreaders = nreaders;
1449 else
1450 nrealreaders = 2 * num_online_cpus();
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001451 rcu_torture_print_module_parms(cur_ops, "Start of test");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001452 fullstop = FULLSTOP_DONTSTOP;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001453
1454 /* Set up the freelist. */
1455
1456 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07001457 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08001458 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001459 list_add_tail(&rcu_tortures[i].rtort_free,
1460 &rcu_torture_freelist);
1461 }
1462
1463 /* Initialize the statistics so that each run gets its own numbers. */
1464
1465 rcu_torture_current = NULL;
1466 rcu_torture_current_version = 0;
1467 atomic_set(&n_rcu_torture_alloc, 0);
1468 atomic_set(&n_rcu_torture_alloc_fail, 0);
1469 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001470 atomic_set(&n_rcu_torture_mberror, 0);
1471 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001472 n_rcu_torture_boost_ktrerror = 0;
1473 n_rcu_torture_boost_rterror = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001474 n_rcu_torture_boost_failure = 0;
1475 n_rcu_torture_boosts = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001476 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1477 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001478 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001479 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1480 per_cpu(rcu_torture_count, cpu)[i] = 0;
1481 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1482 }
1483 }
1484
1485 /* Start up the kthreads. */
1486
1487 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1488 writer_task = kthread_run(rcu_torture_writer, NULL,
1489 "rcu_torture_writer");
1490 if (IS_ERR(writer_task)) {
1491 firsterr = PTR_ERR(writer_task);
1492 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1493 writer_task = NULL;
1494 goto unwind;
1495 }
Josh Triplettb772e1d2006-10-04 02:17:13 -07001496 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001497 GFP_KERNEL);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001498 if (fakewriter_tasks == NULL) {
1499 VERBOSE_PRINTK_ERRSTRING("out of memory");
1500 firsterr = -ENOMEM;
1501 goto unwind;
1502 }
1503 for (i = 0; i < nfakewriters; i++) {
1504 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
1505 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001506 "rcu_torture_fakewriter");
Josh Triplettb772e1d2006-10-04 02:17:13 -07001507 if (IS_ERR(fakewriter_tasks[i])) {
1508 firsterr = PTR_ERR(fakewriter_tasks[i]);
1509 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
1510 fakewriter_tasks[i] = NULL;
1511 goto unwind;
1512 }
1513 }
Josh Triplett2860aab2006-10-04 02:17:11 -07001514 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001515 GFP_KERNEL);
1516 if (reader_tasks == NULL) {
1517 VERBOSE_PRINTK_ERRSTRING("out of memory");
1518 firsterr = -ENOMEM;
1519 goto unwind;
1520 }
1521 for (i = 0; i < nrealreaders; i++) {
1522 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
1523 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
1524 "rcu_torture_reader");
1525 if (IS_ERR(reader_tasks[i])) {
1526 firsterr = PTR_ERR(reader_tasks[i]);
1527 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
1528 reader_tasks[i] = NULL;
1529 goto unwind;
1530 }
1531 }
1532 if (stat_interval > 0) {
1533 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
1534 stats_task = kthread_run(rcu_torture_stats, NULL,
1535 "rcu_torture_stats");
1536 if (IS_ERR(stats_task)) {
1537 firsterr = PTR_ERR(stats_task);
1538 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
1539 stats_task = NULL;
1540 goto unwind;
1541 }
1542 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001543 if (test_no_idle_hz) {
1544 rcu_idle_cpu = num_online_cpus() - 1;
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001545
1546 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
1547 firsterr = -ENOMEM;
1548 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
1549 goto unwind;
1550 }
1551
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001552 /* Create the shuffler thread */
1553 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
1554 "rcu_torture_shuffle");
1555 if (IS_ERR(shuffler_task)) {
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001556 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001557 firsterr = PTR_ERR(shuffler_task);
1558 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
1559 shuffler_task = NULL;
1560 goto unwind;
1561 }
1562 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001563 if (stutter < 0)
1564 stutter = 0;
1565 if (stutter) {
1566 /* Create the stutter thread */
1567 stutter_task = kthread_run(rcu_torture_stutter, NULL,
1568 "rcu_torture_stutter");
1569 if (IS_ERR(stutter_task)) {
1570 firsterr = PTR_ERR(stutter_task);
1571 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
1572 stutter_task = NULL;
1573 goto unwind;
1574 }
1575 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001576 if (fqs_duration < 0)
1577 fqs_duration = 0;
1578 if (fqs_duration) {
1579 /* Create the stutter thread */
1580 fqs_task = kthread_run(rcu_torture_fqs, NULL,
1581 "rcu_torture_fqs");
1582 if (IS_ERR(fqs_task)) {
1583 firsterr = PTR_ERR(fqs_task);
1584 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
1585 fqs_task = NULL;
1586 goto unwind;
1587 }
1588 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001589 if (test_boost_interval < 1)
1590 test_boost_interval = 1;
1591 if (test_boost_duration < 2)
1592 test_boost_duration = 2;
1593 if ((test_boost == 1 && cur_ops->can_boost) ||
1594 test_boost == 2) {
1595 int retval;
1596
1597 boost_starttime = jiffies + test_boost_interval * HZ;
1598 register_cpu_notifier(&rcutorture_cpu_nb);
1599 for_each_possible_cpu(i) {
1600 if (cpu_is_offline(i))
1601 continue; /* Heuristic: CPU can go offline. */
1602 retval = rcutorture_booster_init(i);
1603 if (retval < 0) {
1604 firsterr = retval;
1605 goto unwind;
1606 }
1607 }
1608 }
1609 register_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenney4a298652011-04-03 21:33:51 -07001610 rcutorture_record_test_transition();
Paul E. McKenney343e9092008-12-15 16:13:07 -08001611 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001612 return 0;
1613
1614unwind:
Paul E. McKenney343e9092008-12-15 16:13:07 -08001615 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001616 rcu_torture_cleanup();
1617 return firsterr;
1618}
1619
1620module_init(rcu_torture_init);
1621module_exit(rcu_torture_cleanup);