blob: c2f58ec2475121d574ed66d96a53a7db16792be2 [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>
36#include <asm/atomic.h>
37#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");
Josh Triplettd6ad6712007-03-06 01:42:13 -080076module_param(stat_interval, int, 0444);
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
Josh Triplettb772e1d2006-10-04 02:17:13 -0700483struct rcu_bh_torture_synchronize {
484 struct rcu_head head;
485 struct completion completion;
486};
487
488static void rcu_bh_torture_wakeme_after_cb(struct rcu_head *head)
489{
490 struct rcu_bh_torture_synchronize *rcu;
491
492 rcu = container_of(head, struct rcu_bh_torture_synchronize, head);
493 complete(&rcu->completion);
494}
495
496static void rcu_bh_torture_synchronize(void)
497{
498 struct rcu_bh_torture_synchronize rcu;
499
Paul E. McKenney72d5a9f2010-05-10 17:12:17 -0700500 init_rcu_head_on_stack(&rcu.head);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700501 init_completion(&rcu.completion);
502 call_rcu_bh(&rcu.head, rcu_bh_torture_wakeme_after_cb);
503 wait_for_completion(&rcu.completion);
Paul E. McKenney72d5a9f2010-05-10 17:12:17 -0700504 destroy_rcu_head_on_stack(&rcu.head);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700505}
506
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700507static struct rcu_torture_ops rcu_bh_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700508 .init = NULL,
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_bh_torture_deferred_free,
515 .sync = rcu_bh_torture_synchronize,
516 .cb_barrier = rcu_barrier_bh,
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"
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700521};
522
Josh Triplett11a14702006-10-04 02:17:16 -0700523static struct rcu_torture_ops rcu_bh_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700524 .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 = rcu_bh_torture_synchronize,
532 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800533 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700534 .stats = NULL,
535 .irq_capable = 1,
536 .name = "rcu_bh_sync"
Josh Triplett11a14702006-10-04 02:17:16 -0700537};
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 void sched_torture_synchronize(void)
663{
664 synchronize_sched();
665}
666
667static struct rcu_torture_ops sched_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700668 .init = rcu_sync_torture_init,
669 .cleanup = NULL,
670 .readlock = sched_torture_read_lock,
671 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
672 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800673 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700674 .deferred_free = rcu_sched_torture_deferred_free,
675 .sync = sched_torture_synchronize,
676 .cb_barrier = rcu_barrier_sched,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800677 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700678 .stats = NULL,
679 .irq_capable = 1,
680 .name = "sched"
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700681};
682
Paul E. McKenney804bb832009-10-25 19:03:52 -0700683static struct rcu_torture_ops sched_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700684 .init = rcu_sync_torture_init,
685 .cleanup = NULL,
686 .readlock = sched_torture_read_lock,
687 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
688 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800689 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700690 .deferred_free = rcu_sync_torture_deferred_free,
691 .sync = sched_torture_synchronize,
692 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800693 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700694 .stats = NULL,
695 .name = "sched_sync"
696};
697
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700698static struct rcu_torture_ops sched_expedited_ops = {
699 .init = rcu_sync_torture_init,
700 .cleanup = NULL,
701 .readlock = sched_torture_read_lock,
702 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
703 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800704 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700705 .deferred_free = rcu_sync_torture_deferred_free,
706 .sync = synchronize_sched_expedited,
707 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800708 .fqs = rcu_sched_force_quiescent_state,
Tejun Heo969c7922010-05-06 18:49:21 +0200709 .stats = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700710 .irq_capable = 1,
711 .name = "sched_expedited"
Paul E. McKenney23269742008-05-12 21:21:05 +0200712};
713
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700714/*
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700715 * RCU torture priority-boost testing. Runs one real-time thread per
716 * CPU for moderate bursts, repeatedly registering RCU callbacks and
717 * spinning waiting for them to be invoked. If a given callback takes
718 * too long to be invoked, we assume that priority inversion has occurred.
719 */
720
721struct rcu_boost_inflight {
722 struct rcu_head rcu;
723 int inflight;
724};
725
726static void rcu_torture_boost_cb(struct rcu_head *head)
727{
728 struct rcu_boost_inflight *rbip =
729 container_of(head, struct rcu_boost_inflight, rcu);
730
731 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
732 rbip->inflight = 0;
733}
734
735static int rcu_torture_boost(void *arg)
736{
737 unsigned long call_rcu_time;
738 unsigned long endtime;
739 unsigned long oldstarttime;
740 struct rcu_boost_inflight rbi = { .inflight = 0 };
741 struct sched_param sp;
742
743 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
744
745 /* Set real-time priority. */
746 sp.sched_priority = 1;
747 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
748 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
749 n_rcu_torture_boost_rterror++;
750 }
751
752 /* Each pass through the following loop does one boost-test cycle. */
753 do {
754 /* Wait for the next test interval. */
755 oldstarttime = boost_starttime;
756 while (jiffies - oldstarttime > ULONG_MAX / 2) {
757 schedule_timeout_uninterruptible(1);
758 rcu_stutter_wait("rcu_torture_boost");
759 if (kthread_should_stop() ||
760 fullstop != FULLSTOP_DONTSTOP)
761 goto checkwait;
762 }
763
764 /* Do one boost-test interval. */
765 endtime = oldstarttime + test_boost_duration * HZ;
766 call_rcu_time = jiffies;
767 while (jiffies - endtime > ULONG_MAX / 2) {
768 /* If we don't have a callback in flight, post one. */
769 if (!rbi.inflight) {
770 smp_mb(); /* RCU core before ->inflight = 1. */
771 rbi.inflight = 1;
772 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
773 if (jiffies - call_rcu_time >
774 test_boost_duration * HZ - HZ / 2) {
775 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
776 n_rcu_torture_boost_failure++;
777 }
778 call_rcu_time = jiffies;
779 }
780 cond_resched();
781 rcu_stutter_wait("rcu_torture_boost");
782 if (kthread_should_stop() ||
783 fullstop != FULLSTOP_DONTSTOP)
784 goto checkwait;
785 }
786
787 /*
788 * Set the start time of the next test interval.
789 * Yes, this is vulnerable to long delays, but such
790 * delays simply cause a false negative for the next
791 * interval. Besides, we are running at RT priority,
792 * so delays should be relatively rare.
793 */
794 while (oldstarttime == boost_starttime) {
795 if (mutex_trylock(&boost_mutex)) {
796 boost_starttime = jiffies +
797 test_boost_interval * HZ;
798 n_rcu_torture_boosts++;
799 mutex_unlock(&boost_mutex);
800 break;
801 }
802 schedule_timeout_uninterruptible(1);
803 }
804
805 /* Go do the stutter. */
806checkwait: rcu_stutter_wait("rcu_torture_boost");
807 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
808
809 /* Clean up and exit. */
810 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
811 rcutorture_shutdown_absorb("rcu_torture_boost");
812 while (!kthread_should_stop() || rbi.inflight)
813 schedule_timeout_uninterruptible(1);
814 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
815 return 0;
816}
817
818/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800819 * RCU torture force-quiescent-state kthread. Repeatedly induces
820 * bursts of calls to force_quiescent_state(), increasing the probability
821 * of occurrence of some important types of race conditions.
822 */
823static int
824rcu_torture_fqs(void *arg)
825{
826 unsigned long fqs_resume_time;
827 int fqs_burst_remaining;
828
829 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
830 do {
831 fqs_resume_time = jiffies + fqs_stutter * HZ;
832 while (jiffies - fqs_resume_time > LONG_MAX) {
833 schedule_timeout_interruptible(1);
834 }
835 fqs_burst_remaining = fqs_duration;
836 while (fqs_burst_remaining > 0) {
837 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
924/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700925 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
926 * incrementing the corresponding element of the pipeline array. The
927 * counter in the element should never be greater than 1, otherwise, the
928 * RCU implementation is broken.
929 */
930static void rcu_torture_timer(unsigned long unused)
931{
932 int idx;
933 int completed;
934 static DEFINE_RCU_RANDOM(rand);
935 static DEFINE_SPINLOCK(rand_lock);
936 struct rcu_torture *p;
937 int pipe_count;
938
939 idx = cur_ops->readlock();
940 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -0800941 p = rcu_dereference_check(rcu_torture_current,
942 rcu_read_lock_held() ||
943 rcu_read_lock_bh_held() ||
944 rcu_read_lock_sched_held() ||
945 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700946 if (p == NULL) {
947 /* Leave because rcu_torture_writer is not yet underway */
948 cur_ops->readunlock(idx);
949 return;
950 }
951 if (p->rtort_mbtest == 0)
952 atomic_inc(&n_rcu_torture_mberror);
953 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700954 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700955 n_rcu_torture_timers++;
956 spin_unlock(&rand_lock);
957 preempt_disable();
958 pipe_count = p->rtort_pipe_count;
959 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
960 /* Should not happen, but... */
961 pipe_count = RCU_TORTURE_PIPE_LEN;
962 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +0900963 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700964 completed = cur_ops->completed() - completed;
965 if (completed > RCU_TORTURE_PIPE_LEN) {
966 /* Should not happen, but... */
967 completed = RCU_TORTURE_PIPE_LEN;
968 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +0900969 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700970 preempt_enable();
971 cur_ops->readunlock(idx);
972}
973
974/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800975 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
976 * incrementing the corresponding element of the pipeline array. The
977 * counter in the element should never be greater than 1, otherwise, the
978 * RCU implementation is broken.
979 */
980static int
981rcu_torture_reader(void *arg)
982{
983 int completed;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700984 int idx;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800985 DEFINE_RCU_RANDOM(rand);
986 struct rcu_torture *p;
987 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700988 struct timer_list t;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800989
990 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800991 set_user_nice(current, 19);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700992 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700993 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800994
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800995 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700996 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700997 if (!timer_pending(&t))
Paul E. McKenney6155fec2010-02-22 17:05:04 -0800998 mod_timer(&t, jiffies + 1);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700999 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001000 idx = cur_ops->readlock();
1001 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001002 p = rcu_dereference_check(rcu_torture_current,
1003 rcu_read_lock_held() ||
1004 rcu_read_lock_bh_held() ||
1005 rcu_read_lock_sched_held() ||
1006 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001007 if (p == NULL) {
1008 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001009 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001010 schedule_timeout_interruptible(HZ);
1011 continue;
1012 }
Paul E. McKenney996417d2005-11-18 01:10:50 -08001013 if (p->rtort_mbtest == 0)
1014 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001015 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001016 preempt_disable();
1017 pipe_count = p->rtort_pipe_count;
1018 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1019 /* Should not happen, but... */
1020 pipe_count = RCU_TORTURE_PIPE_LEN;
1021 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001022 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001023 completed = cur_ops->completed() - completed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001024 if (completed > RCU_TORTURE_PIPE_LEN) {
1025 /* Should not happen, but... */
1026 completed = RCU_TORTURE_PIPE_LEN;
1027 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001028 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001029 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001030 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001031 schedule();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001032 rcu_stutter_wait("rcu_torture_reader");
1033 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001034 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001035 rcutorture_shutdown_absorb("rcu_torture_reader");
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001036 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001037 del_timer_sync(&t);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001038 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001039 schedule_timeout_uninterruptible(1);
1040 return 0;
1041}
1042
1043/*
1044 * Create an RCU-torture statistics message in the specified buffer.
1045 */
1046static int
1047rcu_torture_printk(char *page)
1048{
1049 int cnt = 0;
1050 int cpu;
1051 int i;
1052 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1053 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1054
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001055 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001056 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1057 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1058 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1059 }
1060 }
1061 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1062 if (pipesummary[i] != 0)
1063 break;
1064 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001065 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001066 cnt += sprintf(&page[cnt],
Paul E. McKenney4a298652011-04-03 21:33:51 -07001067 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d "
Paul E. McKenney67b98db2011-02-21 13:31:55 -08001068 "rtmbe: %d rtbke: %ld rtbre: %ld "
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001069 "rtbf: %ld rtb: %ld nt: %ld",
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001070 rcu_torture_current,
1071 rcu_torture_current_version,
1072 list_empty(&rcu_torture_freelist),
1073 atomic_read(&n_rcu_torture_alloc),
1074 atomic_read(&n_rcu_torture_alloc_fail),
Paul E. McKenney996417d2005-11-18 01:10:50 -08001075 atomic_read(&n_rcu_torture_free),
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001076 atomic_read(&n_rcu_torture_mberror),
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001077 n_rcu_torture_boost_ktrerror,
1078 n_rcu_torture_boost_rterror,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001079 n_rcu_torture_boost_failure,
1080 n_rcu_torture_boosts,
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001081 n_rcu_torture_timers);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001082 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
1083 n_rcu_torture_boost_ktrerror != 0 ||
1084 n_rcu_torture_boost_rterror != 0 ||
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001085 n_rcu_torture_boost_failure != 0)
Paul E. McKenney996417d2005-11-18 01:10:50 -08001086 cnt += sprintf(&page[cnt], " !!!");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001087 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001088 if (i > 1) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001089 cnt += sprintf(&page[cnt], "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -08001090 atomic_inc(&n_rcu_torture_error);
Ingo Molnar5af970a2008-06-18 10:09:48 +02001091 WARN_ON_ONCE(1);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001092 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001093 cnt += sprintf(&page[cnt], "Reader Pipe: ");
1094 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1095 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001096 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001097 cnt += sprintf(&page[cnt], "Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001098 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001099 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001100 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001101 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
1102 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1103 cnt += sprintf(&page[cnt], " %d",
1104 atomic_read(&rcu_torture_wcount[i]));
1105 }
1106 cnt += sprintf(&page[cnt], "\n");
Josh Triplettc8e5b162007-05-08 00:33:20 -07001107 if (cur_ops->stats)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001108 cnt += cur_ops->stats(&page[cnt]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001109 return cnt;
1110}
1111
1112/*
1113 * Print torture statistics. Caller must ensure that there is only
1114 * one call to this function at a given time!!! This is normally
1115 * accomplished by relying on the module system to only have one copy
1116 * of the module loaded, and then by giving the rcu_torture_stats
1117 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1118 * thread is not running).
1119 */
1120static void
1121rcu_torture_stats_print(void)
1122{
1123 int cnt;
1124
1125 cnt = rcu_torture_printk(printk_buf);
1126 printk(KERN_ALERT "%s", printk_buf);
1127}
1128
1129/*
1130 * Periodically prints torture statistics, if periodic statistics printing
1131 * was specified via the stat_interval module parameter.
1132 *
1133 * No need to worry about fullstop here, since this one doesn't reference
1134 * volatile state or register callbacks.
1135 */
1136static int
1137rcu_torture_stats(void *arg)
1138{
1139 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1140 do {
1141 schedule_timeout_interruptible(stat_interval * HZ);
1142 rcu_torture_stats_print();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001143 rcutorture_shutdown_absorb("rcu_torture_stats");
1144 } while (!kthread_should_stop());
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001145 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1146 return 0;
1147}
1148
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001149static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
1150
1151/* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1152 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1153 */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -07001154static void rcu_torture_shuffle_tasks(void)
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001155{
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001156 int i;
1157
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001158 cpumask_setall(shuffle_tmp_mask);
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001159 get_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001160
1161 /* No point in shuffling if there is only one online CPU (ex: UP) */
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001162 if (num_online_cpus() == 1) {
1163 put_online_cpus();
1164 return;
1165 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001166
1167 if (rcu_idle_cpu != -1)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001168 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001169
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001170 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001171
Josh Triplettc8e5b162007-05-08 00:33:20 -07001172 if (reader_tasks) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001173 for (i = 0; i < nrealreaders; i++)
1174 if (reader_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001175 set_cpus_allowed_ptr(reader_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001176 shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001177 }
1178
Josh Triplettc8e5b162007-05-08 00:33:20 -07001179 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001180 for (i = 0; i < nfakewriters; i++)
1181 if (fakewriter_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001182 set_cpus_allowed_ptr(fakewriter_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001183 shuffle_tmp_mask);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001184 }
1185
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001186 if (writer_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001187 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001188
1189 if (stats_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001190 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001191
1192 if (rcu_idle_cpu == -1)
1193 rcu_idle_cpu = num_online_cpus() - 1;
1194 else
1195 rcu_idle_cpu--;
1196
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001197 put_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001198}
1199
1200/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1201 * system to become idle at a time and cut off its timer ticks. This is meant
1202 * to test the support for such tickless idle CPU in RCU.
1203 */
1204static int
1205rcu_torture_shuffle(void *arg)
1206{
1207 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1208 do {
1209 schedule_timeout_interruptible(shuffle_interval * HZ);
1210 rcu_torture_shuffle_tasks();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001211 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1212 } while (!kthread_should_stop());
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001213 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1214 return 0;
1215}
1216
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001217/* Cause the rcutorture test to "stutter", starting and stopping all
1218 * threads periodically.
1219 */
1220static int
1221rcu_torture_stutter(void *arg)
1222{
1223 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1224 do {
1225 schedule_timeout_interruptible(stutter * HZ);
1226 stutter_pause_test = 1;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001227 if (!kthread_should_stop())
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001228 schedule_timeout_interruptible(stutter * HZ);
1229 stutter_pause_test = 0;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001230 rcutorture_shutdown_absorb("rcu_torture_stutter");
1231 } while (!kthread_should_stop());
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001232 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1233 return 0;
1234}
1235
Paul E. McKenney95c38322006-03-24 03:15:58 -08001236static inline void
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001237rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
Paul E. McKenney95c38322006-03-24 03:15:58 -08001238{
Josh Triplettb772e1d2006-10-04 02:17:13 -07001239 printk(KERN_ALERT "%s" TORTURE_FLAG
1240 "--- %s: nreaders=%d nfakewriters=%d "
Paul E. McKenney95c38322006-03-24 03:15:58 -08001241 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001242 "shuffle_interval=%d stutter=%d irqreader=%d "
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001243 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1244 "test_boost=%d/%d test_boost_interval=%d "
1245 "test_boost_duration=%d\n",
Josh Triplettb772e1d2006-10-04 02:17:13 -07001246 torture_type, tag, nrealreaders, nfakewriters,
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001247 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001248 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1249 test_boost, cur_ops->can_boost,
1250 test_boost_interval, test_boost_duration);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001251}
1252
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001253static struct notifier_block rcutorture_shutdown_nb = {
Paul E. McKenney343e9092008-12-15 16:13:07 -08001254 .notifier_call = rcutorture_shutdown_notify,
1255};
1256
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001257static void rcutorture_booster_cleanup(int cpu)
1258{
1259 struct task_struct *t;
1260
1261 if (boost_tasks[cpu] == NULL)
1262 return;
1263 mutex_lock(&boost_mutex);
1264 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1265 t = boost_tasks[cpu];
1266 boost_tasks[cpu] = NULL;
1267 mutex_unlock(&boost_mutex);
1268
1269 /* This must be outside of the mutex, otherwise deadlock! */
1270 kthread_stop(t);
1271}
1272
1273static int rcutorture_booster_init(int cpu)
1274{
1275 int retval;
1276
1277 if (boost_tasks[cpu] != NULL)
1278 return 0; /* Already created, nothing more to do. */
1279
1280 /* Don't allow time recalculation while creating a new task. */
1281 mutex_lock(&boost_mutex);
1282 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
1283 boost_tasks[cpu] = kthread_create(rcu_torture_boost, NULL,
1284 "rcu_torture_boost");
1285 if (IS_ERR(boost_tasks[cpu])) {
1286 retval = PTR_ERR(boost_tasks[cpu]);
1287 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1288 n_rcu_torture_boost_ktrerror++;
1289 boost_tasks[cpu] = NULL;
1290 mutex_unlock(&boost_mutex);
1291 return retval;
1292 }
1293 kthread_bind(boost_tasks[cpu], cpu);
1294 wake_up_process(boost_tasks[cpu]);
1295 mutex_unlock(&boost_mutex);
1296 return 0;
1297}
1298
1299static int rcutorture_cpu_notify(struct notifier_block *self,
1300 unsigned long action, void *hcpu)
1301{
1302 long cpu = (long)hcpu;
1303
1304 switch (action) {
1305 case CPU_ONLINE:
1306 case CPU_DOWN_FAILED:
1307 (void)rcutorture_booster_init(cpu);
1308 break;
1309 case CPU_DOWN_PREPARE:
1310 rcutorture_booster_cleanup(cpu);
1311 break;
1312 default:
1313 break;
1314 }
1315 return NOTIFY_OK;
1316}
1317
1318static struct notifier_block rcutorture_cpu_nb = {
1319 .notifier_call = rcutorture_cpu_notify,
1320};
1321
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001322static void
1323rcu_torture_cleanup(void)
1324{
1325 int i;
1326
Paul E. McKenney343e9092008-12-15 16:13:07 -08001327 mutex_lock(&fullstop_mutex);
Paul E. McKenney4a298652011-04-03 21:33:51 -07001328 rcutorture_record_test_transition();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001329 if (fullstop == FULLSTOP_SHUTDOWN) {
1330 printk(KERN_WARNING /* but going down anyway, so... */
1331 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001332 mutex_unlock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001333 schedule_timeout_uninterruptible(10);
Paul E. McKenney343e9092008-12-15 16:13:07 -08001334 if (cur_ops->cb_barrier != NULL)
1335 cur_ops->cb_barrier();
1336 return;
1337 }
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001338 fullstop = FULLSTOP_RMMOD;
Paul E. McKenney343e9092008-12-15 16:13:07 -08001339 mutex_unlock(&fullstop_mutex);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001340 unregister_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001341 if (stutter_task) {
1342 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1343 kthread_stop(stutter_task);
1344 }
1345 stutter_task = NULL;
Josh Triplettc8e5b162007-05-08 00:33:20 -07001346 if (shuffler_task) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001347 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1348 kthread_stop(shuffler_task);
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001349 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001350 }
1351 shuffler_task = NULL;
1352
Josh Triplettc8e5b162007-05-08 00:33:20 -07001353 if (writer_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001354 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1355 kthread_stop(writer_task);
1356 }
1357 writer_task = NULL;
1358
Josh Triplettc8e5b162007-05-08 00:33:20 -07001359 if (reader_tasks) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001360 for (i = 0; i < nrealreaders; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001361 if (reader_tasks[i]) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001362 VERBOSE_PRINTK_STRING(
1363 "Stopping rcu_torture_reader task");
1364 kthread_stop(reader_tasks[i]);
1365 }
1366 reader_tasks[i] = NULL;
1367 }
1368 kfree(reader_tasks);
1369 reader_tasks = NULL;
1370 }
1371 rcu_torture_current = NULL;
1372
Josh Triplettc8e5b162007-05-08 00:33:20 -07001373 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001374 for (i = 0; i < nfakewriters; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001375 if (fakewriter_tasks[i]) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001376 VERBOSE_PRINTK_STRING(
1377 "Stopping rcu_torture_fakewriter task");
1378 kthread_stop(fakewriter_tasks[i]);
1379 }
1380 fakewriter_tasks[i] = NULL;
1381 }
1382 kfree(fakewriter_tasks);
1383 fakewriter_tasks = NULL;
1384 }
1385
Josh Triplettc8e5b162007-05-08 00:33:20 -07001386 if (stats_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001387 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1388 kthread_stop(stats_task);
1389 }
1390 stats_task = NULL;
1391
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001392 if (fqs_task) {
1393 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1394 kthread_stop(fqs_task);
1395 }
1396 fqs_task = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001397 if ((test_boost == 1 && cur_ops->can_boost) ||
1398 test_boost == 2) {
1399 unregister_cpu_notifier(&rcutorture_cpu_nb);
1400 for_each_possible_cpu(i)
1401 rcutorture_booster_cleanup(i);
1402 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001403
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001404 /* Wait for all RCU callbacks to fire. */
Paul E. McKenney23269742008-05-12 21:21:05 +02001405
1406 if (cur_ops->cb_barrier != NULL)
1407 cur_ops->cb_barrier();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001408
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001409 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001410
Josh Triplettc8e5b162007-05-08 00:33:20 -07001411 if (cur_ops->cleanup)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001412 cur_ops->cleanup();
Paul E. McKenney95c38322006-03-24 03:15:58 -08001413 if (atomic_read(&n_rcu_torture_error))
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001414 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
Paul E. McKenney95c38322006-03-24 03:15:58 -08001415 else
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001416 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001417}
1418
Josh Triplett6f8bc5002007-05-08 00:25:24 -07001419static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001420rcu_torture_init(void)
1421{
1422 int i;
1423 int cpu;
1424 int firsterr = 0;
Josh Triplettade5fb82007-05-08 00:33:22 -07001425 static struct rcu_torture_ops *torture_ops[] =
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -08001426 { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
1427 &rcu_bh_ops, &rcu_bh_sync_ops,
Paul E. McKenney804bb832009-10-25 19:03:52 -07001428 &srcu_ops, &srcu_expedited_ops,
1429 &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001430
Paul E. McKenney343e9092008-12-15 16:13:07 -08001431 mutex_lock(&fullstop_mutex);
1432
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001433 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001434 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001435 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001436 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001437 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001438 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001439 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001440 printk(KERN_ALERT "rcu-torture: invalid torture type: \"%s\"\n",
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001441 torture_type);
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001442 printk(KERN_ALERT "rcu-torture types:");
1443 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
1444 printk(KERN_ALERT " %s", torture_ops[i]->name);
1445 printk(KERN_ALERT "\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001446 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001447 return -EINVAL;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001448 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001449 if (cur_ops->fqs == NULL && fqs_duration != 0) {
1450 printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero "
1451 "fqs_duration, fqs disabled.\n");
1452 fqs_duration = 0;
1453 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001454 if (cur_ops->init)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001455 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1456
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001457 if (nreaders >= 0)
1458 nrealreaders = nreaders;
1459 else
1460 nrealreaders = 2 * num_online_cpus();
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001461 rcu_torture_print_module_parms(cur_ops, "Start of test");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001462 fullstop = FULLSTOP_DONTSTOP;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001463
1464 /* Set up the freelist. */
1465
1466 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07001467 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08001468 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001469 list_add_tail(&rcu_tortures[i].rtort_free,
1470 &rcu_torture_freelist);
1471 }
1472
1473 /* Initialize the statistics so that each run gets its own numbers. */
1474
1475 rcu_torture_current = NULL;
1476 rcu_torture_current_version = 0;
1477 atomic_set(&n_rcu_torture_alloc, 0);
1478 atomic_set(&n_rcu_torture_alloc_fail, 0);
1479 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001480 atomic_set(&n_rcu_torture_mberror, 0);
1481 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001482 n_rcu_torture_boost_ktrerror = 0;
1483 n_rcu_torture_boost_rterror = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001484 n_rcu_torture_boost_failure = 0;
1485 n_rcu_torture_boosts = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001486 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1487 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001488 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001489 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1490 per_cpu(rcu_torture_count, cpu)[i] = 0;
1491 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1492 }
1493 }
1494
1495 /* Start up the kthreads. */
1496
1497 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1498 writer_task = kthread_run(rcu_torture_writer, NULL,
1499 "rcu_torture_writer");
1500 if (IS_ERR(writer_task)) {
1501 firsterr = PTR_ERR(writer_task);
1502 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1503 writer_task = NULL;
1504 goto unwind;
1505 }
Josh Triplettb772e1d2006-10-04 02:17:13 -07001506 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001507 GFP_KERNEL);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001508 if (fakewriter_tasks == NULL) {
1509 VERBOSE_PRINTK_ERRSTRING("out of memory");
1510 firsterr = -ENOMEM;
1511 goto unwind;
1512 }
1513 for (i = 0; i < nfakewriters; i++) {
1514 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
1515 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001516 "rcu_torture_fakewriter");
Josh Triplettb772e1d2006-10-04 02:17:13 -07001517 if (IS_ERR(fakewriter_tasks[i])) {
1518 firsterr = PTR_ERR(fakewriter_tasks[i]);
1519 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
1520 fakewriter_tasks[i] = NULL;
1521 goto unwind;
1522 }
1523 }
Josh Triplett2860aab2006-10-04 02:17:11 -07001524 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001525 GFP_KERNEL);
1526 if (reader_tasks == NULL) {
1527 VERBOSE_PRINTK_ERRSTRING("out of memory");
1528 firsterr = -ENOMEM;
1529 goto unwind;
1530 }
1531 for (i = 0; i < nrealreaders; i++) {
1532 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
1533 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
1534 "rcu_torture_reader");
1535 if (IS_ERR(reader_tasks[i])) {
1536 firsterr = PTR_ERR(reader_tasks[i]);
1537 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
1538 reader_tasks[i] = NULL;
1539 goto unwind;
1540 }
1541 }
1542 if (stat_interval > 0) {
1543 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
1544 stats_task = kthread_run(rcu_torture_stats, NULL,
1545 "rcu_torture_stats");
1546 if (IS_ERR(stats_task)) {
1547 firsterr = PTR_ERR(stats_task);
1548 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
1549 stats_task = NULL;
1550 goto unwind;
1551 }
1552 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001553 if (test_no_idle_hz) {
1554 rcu_idle_cpu = num_online_cpus() - 1;
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001555
1556 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
1557 firsterr = -ENOMEM;
1558 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
1559 goto unwind;
1560 }
1561
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001562 /* Create the shuffler thread */
1563 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
1564 "rcu_torture_shuffle");
1565 if (IS_ERR(shuffler_task)) {
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001566 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001567 firsterr = PTR_ERR(shuffler_task);
1568 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
1569 shuffler_task = NULL;
1570 goto unwind;
1571 }
1572 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001573 if (stutter < 0)
1574 stutter = 0;
1575 if (stutter) {
1576 /* Create the stutter thread */
1577 stutter_task = kthread_run(rcu_torture_stutter, NULL,
1578 "rcu_torture_stutter");
1579 if (IS_ERR(stutter_task)) {
1580 firsterr = PTR_ERR(stutter_task);
1581 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
1582 stutter_task = NULL;
1583 goto unwind;
1584 }
1585 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001586 if (fqs_duration < 0)
1587 fqs_duration = 0;
1588 if (fqs_duration) {
1589 /* Create the stutter thread */
1590 fqs_task = kthread_run(rcu_torture_fqs, NULL,
1591 "rcu_torture_fqs");
1592 if (IS_ERR(fqs_task)) {
1593 firsterr = PTR_ERR(fqs_task);
1594 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
1595 fqs_task = NULL;
1596 goto unwind;
1597 }
1598 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001599 if (test_boost_interval < 1)
1600 test_boost_interval = 1;
1601 if (test_boost_duration < 2)
1602 test_boost_duration = 2;
1603 if ((test_boost == 1 && cur_ops->can_boost) ||
1604 test_boost == 2) {
1605 int retval;
1606
1607 boost_starttime = jiffies + test_boost_interval * HZ;
1608 register_cpu_notifier(&rcutorture_cpu_nb);
1609 for_each_possible_cpu(i) {
1610 if (cpu_is_offline(i))
1611 continue; /* Heuristic: CPU can go offline. */
1612 retval = rcutorture_booster_init(i);
1613 if (retval < 0) {
1614 firsterr = retval;
1615 goto unwind;
1616 }
1617 }
1618 }
1619 register_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenney4a298652011-04-03 21:33:51 -07001620 rcutorture_record_test_transition();
Paul E. McKenney343e9092008-12-15 16:13:07 -08001621 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001622 return 0;
1623
1624unwind:
Paul E. McKenney343e9092008-12-15 16:13:07 -08001625 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001626 rcu_torture_cleanup();
1627 return firsterr;
1628}
1629
1630module_init(rcu_torture_init);
1631module_exit(rcu_torture_cleanup);