blob: 186ead9fa34883b930efbf69e672881bcacd99c2 [file] [log] [blame]
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001/*
Paul E. McKenney29766f12006-06-27 02:54:02 -07002 * Read-Copy Update module-based torture test facility
Paul E. McKenneya241ec62005-10-30 15:03:12 -08003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
Josh Triplettb772e1d2006-10-04 02:17:13 -070018 * Copyright (C) IBM Corporation, 2005, 2006
Paul E. McKenneya241ec62005-10-30 15:03:12 -080019 *
20 * Authors: Paul E. McKenney <paulmck@us.ibm.com>
Paul E. McKenneya71fca52009-09-18 10:28:19 -070021 * Josh Triplett <josh@freedesktop.org>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080022 *
23 * See also: Documentation/RCU/torture.txt
24 */
25#include <linux/types.h>
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/module.h>
29#include <linux/kthread.h>
30#include <linux/err.h>
31#include <linux/spinlock.h>
32#include <linux/smp.h>
33#include <linux/rcupdate.h>
34#include <linux/interrupt.h>
35#include <linux/sched.h>
Arun Sharma600634972011-07-26 16:09:06 -070036#include <linux/atomic.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080037#include <linux/bitops.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080038#include <linux/completion.h>
39#include <linux/moduleparam.h>
40#include <linux/percpu.h>
41#include <linux/notifier.h>
Paul E. McKenney343e9092008-12-15 16:13:07 -080042#include <linux/reboot.h>
Rafael J. Wysocki83144182007-07-17 04:03:35 -070043#include <linux/freezer.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080044#include <linux/cpu.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080045#include <linux/delay.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080046#include <linux/stat.h>
Paul E. McKenneyb2896d22006-10-04 02:17:03 -070047#include <linux/srcu.h>
Robert P. J. Day1aeb2722008-04-29 00:59:25 -070048#include <linux/slab.h>
Harvey Harrisonf07767f2008-10-20 10:23:38 -070049#include <asm/byteorder.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080050
51MODULE_LICENSE("GPL");
Josh Triplettb772e1d2006-10-04 02:17:13 -070052MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and "
Paul E. McKenneya71fca52009-09-18 10:28:19 -070053 "Josh Triplett <josh@freedesktop.org>");
Paul E. McKenneya241ec62005-10-30 15:03:12 -080054
Josh Triplett48022112006-10-03 23:26:16 +020055static int nreaders = -1; /* # reader threads, defaults to 2*ncpus */
Josh Triplettb772e1d2006-10-04 02:17:13 -070056static int nfakewriters = 4; /* # fake writer threads */
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080057static int stat_interval; /* Interval between stats, in seconds. */
Paul E. McKenneya241ec62005-10-30 15:03:12 -080058 /* Defaults to "only at end of test". */
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080059static int verbose; /* Print more debug info. */
60static int test_no_idle_hz; /* Test RCU's support for tickless idle CPUs. */
Paul E. McKenneyd120f652008-06-18 05:21:44 -070061static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/
62static int stutter = 5; /* Start/stop testing interval (in sec) */
Paul E. McKenney0729fbf2008-06-25 12:24:52 -070063static int irqreader = 1; /* RCU readers from irq (timers). */
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -070064static int fqs_duration; /* Duration of bursts (us), 0 to disable. */
65static int fqs_holdoff; /* Hold time within burst (us). */
Paul E. McKenneybf66f182010-01-04 15:09:10 -080066static int fqs_stutter = 3; /* Wait time between bursts (s). */
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -080067static int onoff_interval; /* Wait time between CPU hotplugs, 0=disable. */
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -070068static int shutdown_secs; /* Shutdown time (s). <=0 for no shutdown. */
Paul E. McKenney8e8be452010-09-02 16:16:14 -070069static int test_boost = 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */
70static int test_boost_interval = 7; /* Interval between boost tests, seconds. */
71static int test_boost_duration = 4; /* Duration of each boost test, seconds. */
Josh Triplett20d2e422006-10-04 02:17:15 -070072static char *torture_type = "rcu"; /* What RCU implementation to torture. */
Paul E. McKenneya241ec62005-10-30 15:03:12 -080073
Josh Triplettd6ad6712007-03-06 01:42:13 -080074module_param(nreaders, int, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080075MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
Josh Triplettd6ad6712007-03-06 01:42:13 -080076module_param(nfakewriters, int, 0444);
Josh Triplettb772e1d2006-10-04 02:17:13 -070077MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
Paul E. McKenney3721bc12011-07-21 16:00:17 -070078module_param(stat_interval, int, 0644);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080079MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
Josh Triplettd6ad6712007-03-06 01:42:13 -080080module_param(verbose, bool, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080081MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
Josh Triplettd6ad6712007-03-06 01:42:13 -080082module_param(test_no_idle_hz, bool, 0444);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080083MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
Josh Triplettd6ad6712007-03-06 01:42:13 -080084module_param(shuffle_interval, int, 0444);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080085MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
Paul E. McKenneyd120f652008-06-18 05:21:44 -070086module_param(stutter, int, 0444);
87MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
Paul E. McKenney0729fbf2008-06-25 12:24:52 -070088module_param(irqreader, int, 0444);
89MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
Paul E. McKenneybf66f182010-01-04 15:09:10 -080090module_param(fqs_duration, int, 0444);
91MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us)");
92module_param(fqs_holdoff, int, 0444);
93MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)");
94module_param(fqs_stutter, int, 0444);
95MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)");
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -080096module_param(onoff_interval, int, 0444);
97MODULE_PARM_DESC(onoff_interval, "Time between CPU hotplugs (s), 0=disable");
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -070098module_param(shutdown_secs, int, 0444);
99MODULE_PARM_DESC(shutdown_secs, "Shutdown time (s), zero to disable.");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700100module_param(test_boost, int, 0444);
101MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
102module_param(test_boost_interval, int, 0444);
103MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds.");
104module_param(test_boost_duration, int, 0444);
105MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds.");
Josh Triplettd6ad6712007-03-06 01:42:13 -0800106module_param(torture_type, charp, 0444);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700107MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700108
109#define TORTURE_FLAG "-torture:"
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800110#define PRINTK_STRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700111 do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800112#define VERBOSE_PRINTK_STRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700113 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800114#define VERBOSE_PRINTK_ERRSTRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700115 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800116
117static char printk_buf[4096];
118
119static int nrealreaders;
120static struct task_struct *writer_task;
Josh Triplettb772e1d2006-10-04 02:17:13 -0700121static struct task_struct **fakewriter_tasks;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800122static struct task_struct **reader_tasks;
123static struct task_struct *stats_task;
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800124static struct task_struct *shuffler_task;
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700125static struct task_struct *stutter_task;
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800126static struct task_struct *fqs_task;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700127static struct task_struct *boost_tasks[NR_CPUS];
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700128static struct task_struct *shutdown_task;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -0800129#ifdef CONFIG_HOTPLUG_CPU
130static struct task_struct *onoff_task;
131#endif /* #ifdef CONFIG_HOTPLUG_CPU */
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800132
133#define RCU_TORTURE_PIPE_LEN 10
134
135struct rcu_torture {
136 struct rcu_head rtort_rcu;
137 int rtort_pipe_count;
138 struct list_head rtort_free;
Paul E. McKenney996417d2005-11-18 01:10:50 -0800139 int rtort_mbtest;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800140};
141
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800142static LIST_HEAD(rcu_torture_freelist);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700143static struct rcu_torture __rcu *rcu_torture_current;
Paul E. McKenney4a298652011-04-03 21:33:51 -0700144static unsigned long rcu_torture_current_version;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800145static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
146static DEFINE_SPINLOCK(rcu_torture_lock);
147static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
148 { 0 };
149static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
150 { 0 };
151static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700152static atomic_t n_rcu_torture_alloc;
153static atomic_t n_rcu_torture_alloc_fail;
154static atomic_t n_rcu_torture_free;
155static atomic_t n_rcu_torture_mberror;
156static atomic_t n_rcu_torture_error;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700157static long n_rcu_torture_boost_ktrerror;
158static long n_rcu_torture_boost_rterror;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700159static long n_rcu_torture_boost_failure;
160static long n_rcu_torture_boosts;
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700161static long n_rcu_torture_timers;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -0800162static long n_offline_attempts;
163static long n_offline_successes;
164static long n_online_attempts;
165static long n_online_successes;
Josh Triplette3033732006-10-04 02:17:14 -0700166static struct list_head rcu_torture_removed;
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600167static cpumask_var_t shuffle_tmp_mask;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800168
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700169static int stutter_pause_test;
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700170
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700171#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
172#define RCUTORTURE_RUNNABLE_INIT 1
173#else
174#define RCUTORTURE_RUNNABLE_INIT 0
175#endif
176int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
Paul E. McKenneybb3bf702011-11-04 13:24:07 -0700177module_param(rcutorture_runnable, int, 0444);
178MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot");
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700179
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700180#if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700181#define rcu_can_boost() 1
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700182#else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700183#define rcu_can_boost() 0
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700184#endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700185
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700186static unsigned long shutdown_time; /* jiffies to system shutdown. */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700187static unsigned long boost_starttime; /* jiffies of next boost test start. */
188DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
189 /* and boost task create/destroy. */
190
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800191/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
192
193#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
194#define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
195#define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
196static int fullstop = FULLSTOP_RMMOD;
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700197/*
198 * Protect fullstop transitions and spawning of kthreads.
199 */
200static DEFINE_MUTEX(fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800201
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700202/* Forward reference. */
203static void rcu_torture_cleanup(void);
204
Paul E. McKenney343e9092008-12-15 16:13:07 -0800205/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800206 * Detect and respond to a system shutdown.
Paul E. McKenney343e9092008-12-15 16:13:07 -0800207 */
208static int
209rcutorture_shutdown_notify(struct notifier_block *unused1,
210 unsigned long unused2, void *unused3)
211{
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800212 mutex_lock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800213 if (fullstop == FULLSTOP_DONTSTOP)
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800214 fullstop = FULLSTOP_SHUTDOWN;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800215 else
216 printk(KERN_WARNING /* but going down anyway, so... */
217 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800218 mutex_unlock(&fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800219 return NOTIFY_DONE;
220}
221
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800222/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800223 * Absorb kthreads into a kernel function that won't return, so that
224 * they won't ever access module text or data again.
225 */
226static void rcutorture_shutdown_absorb(char *title)
227{
228 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
229 printk(KERN_NOTICE
230 "rcutorture thread %s parking due to system shutdown\n",
231 title);
232 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
233 }
234}
235
236/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800237 * Allocate an element from the rcu_tortures pool.
238 */
Adrian Bunk97a41e22006-01-08 01:02:17 -0800239static struct rcu_torture *
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800240rcu_torture_alloc(void)
241{
242 struct list_head *p;
243
Ingo Molnaradac1662006-01-25 19:50:12 +0100244 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800245 if (list_empty(&rcu_torture_freelist)) {
246 atomic_inc(&n_rcu_torture_alloc_fail);
Ingo Molnaradac1662006-01-25 19:50:12 +0100247 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800248 return NULL;
249 }
250 atomic_inc(&n_rcu_torture_alloc);
251 p = rcu_torture_freelist.next;
252 list_del_init(p);
Ingo Molnaradac1662006-01-25 19:50:12 +0100253 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800254 return container_of(p, struct rcu_torture, rtort_free);
255}
256
257/*
258 * Free an element to the rcu_tortures pool.
259 */
260static void
261rcu_torture_free(struct rcu_torture *p)
262{
263 atomic_inc(&n_rcu_torture_free);
Ingo Molnaradac1662006-01-25 19:50:12 +0100264 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800265 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
Ingo Molnaradac1662006-01-25 19:50:12 +0100266 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800267}
268
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800269struct rcu_random_state {
270 unsigned long rrs_state;
Josh Triplett75cfef32006-10-04 02:17:12 -0700271 long rrs_count;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800272};
273
274#define RCU_RANDOM_MULT 39916801 /* prime */
275#define RCU_RANDOM_ADD 479001701 /* prime */
276#define RCU_RANDOM_REFRESH 10000
277
278#define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
279
280/*
281 * Crude but fast random-number generator. Uses a linear congruential
Paul E. McKenneyc17ac852007-10-16 23:27:19 -0700282 * generator, with occasional help from cpu_clock().
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800283 */
Josh Triplett75cfef32006-10-04 02:17:12 -0700284static unsigned long
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800285rcu_random(struct rcu_random_state *rrsp)
286{
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800287 if (--rrsp->rrs_count < 0) {
Peter Zijlstrac6763292010-05-25 10:48:51 +0200288 rrsp->rrs_state += (unsigned long)local_clock();
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800289 rrsp->rrs_count = RCU_RANDOM_REFRESH;
290 }
291 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
292 return swahw32(rrsp->rrs_state);
293}
294
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700295static void
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800296rcu_stutter_wait(char *title)
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700297{
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800298 while (stutter_pause_test || !rcutorture_runnable) {
Paul E. McKenneye3d7be22008-06-22 13:06:38 -0700299 if (rcutorture_runnable)
300 schedule_timeout_interruptible(1);
301 else
Paul E. McKenney3ccf79f2008-06-22 14:02:55 -0700302 schedule_timeout_interruptible(round_jiffies_relative(HZ));
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800303 rcutorture_shutdown_absorb(title);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800304 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700305}
306
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800307/*
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700308 * Operations vector for selecting different types of tests.
309 */
310
311struct rcu_torture_ops {
312 void (*init)(void);
313 void (*cleanup)(void);
314 int (*readlock)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700315 void (*read_delay)(struct rcu_random_state *rrsp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700316 void (*readunlock)(int idx);
317 int (*completed)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700318 void (*deferred_free)(struct rcu_torture *p);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700319 void (*sync)(void);
Paul E. McKenney23269742008-05-12 21:21:05 +0200320 void (*cb_barrier)(void);
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800321 void (*fqs)(void);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700322 int (*stats)(char *page);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700323 int irq_capable;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700324 int can_boost;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700325 char *name;
326};
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700327
328static struct rcu_torture_ops *cur_ops;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700329
330/*
331 * Definitions for rcu torture testing.
332 */
333
Josh Tripletta49a4af2006-09-29 01:59:30 -0700334static int rcu_torture_read_lock(void) __acquires(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700335{
336 rcu_read_lock();
337 return 0;
338}
339
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700340static void rcu_read_delay(struct rcu_random_state *rrsp)
341{
Josh Triplettb8d57a72009-09-08 15:54:35 -0700342 const unsigned long shortdelay_us = 200;
343 const unsigned long longdelay_ms = 50;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700344
Josh Triplettb8d57a72009-09-08 15:54:35 -0700345 /* We want a short delay sometimes to make a reader delay the grace
346 * period, and we want a long delay occasionally to trigger
347 * force_quiescent_state. */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700348
Josh Triplettb8d57a72009-09-08 15:54:35 -0700349 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
350 mdelay(longdelay_ms);
351 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
352 udelay(shortdelay_us);
Lai Jiangshane546f482010-06-21 16:57:42 +0800353#ifdef CONFIG_PREEMPT
354 if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000)))
355 preempt_schedule(); /* No QS if preempt_disable() in effect */
356#endif
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700357}
358
Josh Tripletta49a4af2006-09-29 01:59:30 -0700359static void rcu_torture_read_unlock(int idx) __releases(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700360{
361 rcu_read_unlock();
362}
363
364static int rcu_torture_completed(void)
365{
366 return rcu_batches_completed();
367}
368
369static void
370rcu_torture_cb(struct rcu_head *p)
371{
372 int i;
373 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
374
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800375 if (fullstop != FULLSTOP_DONTSTOP) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700376 /* Test is ending, just drop callbacks on the floor. */
377 /* The next initialization will pick up the pieces. */
378 return;
379 }
380 i = rp->rtort_pipe_count;
381 if (i > RCU_TORTURE_PIPE_LEN)
382 i = RCU_TORTURE_PIPE_LEN;
383 atomic_inc(&rcu_torture_wcount[i]);
384 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
385 rp->rtort_mbtest = 0;
386 rcu_torture_free(rp);
387 } else
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700388 cur_ops->deferred_free(rp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700389}
390
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800391static int rcu_no_completed(void)
392{
393 return 0;
394}
395
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700396static void rcu_torture_deferred_free(struct rcu_torture *p)
397{
398 call_rcu(&p->rtort_rcu, rcu_torture_cb);
399}
400
401static struct rcu_torture_ops rcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700402 .init = NULL,
403 .cleanup = NULL,
404 .readlock = rcu_torture_read_lock,
405 .read_delay = rcu_read_delay,
406 .readunlock = rcu_torture_read_unlock,
407 .completed = rcu_torture_completed,
408 .deferred_free = rcu_torture_deferred_free,
409 .sync = synchronize_rcu,
410 .cb_barrier = rcu_barrier,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800411 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700412 .stats = NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700413 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700414 .can_boost = rcu_can_boost(),
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700415 .name = "rcu"
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700416};
417
Josh Triplette3033732006-10-04 02:17:14 -0700418static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
419{
420 int i;
421 struct rcu_torture *rp;
422 struct rcu_torture *rp1;
423
424 cur_ops->sync();
425 list_add(&p->rtort_free, &rcu_torture_removed);
426 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
427 i = rp->rtort_pipe_count;
428 if (i > RCU_TORTURE_PIPE_LEN)
429 i = RCU_TORTURE_PIPE_LEN;
430 atomic_inc(&rcu_torture_wcount[i]);
431 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
432 rp->rtort_mbtest = 0;
433 list_del(&rp->rtort_free);
434 rcu_torture_free(rp);
435 }
436 }
437}
438
439static void rcu_sync_torture_init(void)
440{
441 INIT_LIST_HEAD(&rcu_torture_removed);
442}
443
Josh Triplett20d2e422006-10-04 02:17:15 -0700444static struct rcu_torture_ops rcu_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700445 .init = rcu_sync_torture_init,
446 .cleanup = NULL,
447 .readlock = rcu_torture_read_lock,
448 .read_delay = rcu_read_delay,
449 .readunlock = rcu_torture_read_unlock,
450 .completed = rcu_torture_completed,
451 .deferred_free = rcu_sync_torture_deferred_free,
452 .sync = synchronize_rcu,
453 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800454 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700455 .stats = NULL,
456 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700457 .can_boost = rcu_can_boost(),
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700458 .name = "rcu_sync"
Josh Triplett20d2e422006-10-04 02:17:15 -0700459};
460
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800461static struct rcu_torture_ops rcu_expedited_ops = {
462 .init = rcu_sync_torture_init,
463 .cleanup = NULL,
464 .readlock = rcu_torture_read_lock,
465 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
466 .readunlock = rcu_torture_read_unlock,
467 .completed = rcu_no_completed,
468 .deferred_free = rcu_sync_torture_deferred_free,
469 .sync = synchronize_rcu_expedited,
470 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800471 .fqs = rcu_force_quiescent_state,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800472 .stats = NULL,
473 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700474 .can_boost = rcu_can_boost(),
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800475 .name = "rcu_expedited"
476};
477
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700478/*
479 * Definitions for rcu_bh torture testing.
480 */
481
Josh Tripletta49a4af2006-09-29 01:59:30 -0700482static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700483{
484 rcu_read_lock_bh();
485 return 0;
486}
487
Josh Tripletta49a4af2006-09-29 01:59:30 -0700488static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700489{
490 rcu_read_unlock_bh();
491}
492
493static int rcu_bh_torture_completed(void)
494{
495 return rcu_batches_completed_bh();
496}
497
498static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
499{
500 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
501}
502
503static struct rcu_torture_ops rcu_bh_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700504 .init = NULL,
505 .cleanup = NULL,
506 .readlock = rcu_bh_torture_read_lock,
507 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
508 .readunlock = rcu_bh_torture_read_unlock,
509 .completed = rcu_bh_torture_completed,
510 .deferred_free = rcu_bh_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700511 .sync = synchronize_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700512 .cb_barrier = rcu_barrier_bh,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800513 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700514 .stats = NULL,
515 .irq_capable = 1,
516 .name = "rcu_bh"
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700517};
518
Josh Triplett11a14702006-10-04 02:17:16 -0700519static struct rcu_torture_ops rcu_bh_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700520 .init = rcu_sync_torture_init,
521 .cleanup = NULL,
522 .readlock = rcu_bh_torture_read_lock,
523 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
524 .readunlock = rcu_bh_torture_read_unlock,
525 .completed = rcu_bh_torture_completed,
526 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700527 .sync = synchronize_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700528 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800529 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700530 .stats = NULL,
531 .irq_capable = 1,
532 .name = "rcu_bh_sync"
Josh Triplett11a14702006-10-04 02:17:16 -0700533};
534
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700535static struct rcu_torture_ops rcu_bh_expedited_ops = {
536 .init = rcu_sync_torture_init,
537 .cleanup = NULL,
538 .readlock = rcu_bh_torture_read_lock,
539 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
540 .readunlock = rcu_bh_torture_read_unlock,
541 .completed = rcu_bh_torture_completed,
542 .deferred_free = rcu_sync_torture_deferred_free,
543 .sync = synchronize_rcu_bh_expedited,
544 .cb_barrier = NULL,
545 .fqs = rcu_bh_force_quiescent_state,
546 .stats = NULL,
547 .irq_capable = 1,
548 .name = "rcu_bh_expedited"
549};
550
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700551/*
552 * Definitions for srcu torture testing.
553 */
554
555static struct srcu_struct srcu_ctl;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700556
557static void srcu_torture_init(void)
558{
559 init_srcu_struct(&srcu_ctl);
Josh Triplette3033732006-10-04 02:17:14 -0700560 rcu_sync_torture_init();
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700561}
562
563static void srcu_torture_cleanup(void)
564{
565 synchronize_srcu(&srcu_ctl);
566 cleanup_srcu_struct(&srcu_ctl);
567}
568
Josh Triplett012d3ca2006-12-06 20:40:19 -0800569static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700570{
571 return srcu_read_lock(&srcu_ctl);
572}
573
574static void srcu_read_delay(struct rcu_random_state *rrsp)
575{
576 long delay;
577 const long uspertick = 1000000 / HZ;
578 const long longdelay = 10;
579
580 /* We want there to be long-running readers, but not all the time. */
581
582 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
583 if (!delay)
584 schedule_timeout_interruptible(longdelay);
Lai Jiangshane546f482010-06-21 16:57:42 +0800585 else
586 rcu_read_delay(rrsp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700587}
588
Josh Triplett012d3ca2006-12-06 20:40:19 -0800589static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700590{
591 srcu_read_unlock(&srcu_ctl, idx);
592}
593
594static int srcu_torture_completed(void)
595{
596 return srcu_batches_completed(&srcu_ctl);
597}
598
Josh Triplettb772e1d2006-10-04 02:17:13 -0700599static void srcu_torture_synchronize(void)
600{
601 synchronize_srcu(&srcu_ctl);
602}
603
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700604static int srcu_torture_stats(char *page)
605{
606 int cnt = 0;
607 int cpu;
608 int idx = srcu_ctl.completed & 0x1;
609
610 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
611 torture_type, TORTURE_FLAG, idx);
612 for_each_possible_cpu(cpu) {
613 cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu,
614 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
615 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
616 }
617 cnt += sprintf(&page[cnt], "\n");
618 return cnt;
619}
620
621static struct rcu_torture_ops srcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700622 .init = srcu_torture_init,
623 .cleanup = srcu_torture_cleanup,
624 .readlock = srcu_torture_read_lock,
625 .read_delay = srcu_read_delay,
626 .readunlock = srcu_torture_read_unlock,
627 .completed = srcu_torture_completed,
628 .deferred_free = rcu_sync_torture_deferred_free,
629 .sync = srcu_torture_synchronize,
630 .cb_barrier = NULL,
631 .stats = srcu_torture_stats,
632 .name = "srcu"
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700633};
634
Paul E. McKenney804bb832009-10-25 19:03:52 -0700635static void srcu_torture_synchronize_expedited(void)
636{
637 synchronize_srcu_expedited(&srcu_ctl);
638}
639
640static struct rcu_torture_ops srcu_expedited_ops = {
641 .init = srcu_torture_init,
642 .cleanup = srcu_torture_cleanup,
643 .readlock = srcu_torture_read_lock,
644 .read_delay = srcu_read_delay,
645 .readunlock = srcu_torture_read_unlock,
646 .completed = srcu_torture_completed,
647 .deferred_free = rcu_sync_torture_deferred_free,
648 .sync = srcu_torture_synchronize_expedited,
649 .cb_barrier = NULL,
650 .stats = srcu_torture_stats,
651 .name = "srcu_expedited"
652};
653
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700654/*
655 * Definitions for sched torture testing.
656 */
657
658static int sched_torture_read_lock(void)
659{
660 preempt_disable();
661 return 0;
662}
663
664static void sched_torture_read_unlock(int idx)
665{
666 preempt_enable();
667}
668
Paul E. McKenney23269742008-05-12 21:21:05 +0200669static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
670{
671 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
672}
673
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700674static struct rcu_torture_ops sched_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700675 .init = rcu_sync_torture_init,
676 .cleanup = NULL,
677 .readlock = sched_torture_read_lock,
678 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
679 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800680 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700681 .deferred_free = rcu_sched_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700682 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700683 .cb_barrier = rcu_barrier_sched,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800684 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700685 .stats = NULL,
686 .irq_capable = 1,
687 .name = "sched"
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700688};
689
Paul E. McKenney804bb832009-10-25 19:03:52 -0700690static struct rcu_torture_ops sched_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700691 .init = rcu_sync_torture_init,
692 .cleanup = NULL,
693 .readlock = sched_torture_read_lock,
694 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
695 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800696 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700697 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700698 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700699 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800700 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700701 .stats = NULL,
702 .name = "sched_sync"
703};
704
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700705static struct rcu_torture_ops sched_expedited_ops = {
706 .init = rcu_sync_torture_init,
707 .cleanup = NULL,
708 .readlock = sched_torture_read_lock,
709 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
710 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800711 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700712 .deferred_free = rcu_sync_torture_deferred_free,
713 .sync = synchronize_sched_expedited,
714 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800715 .fqs = rcu_sched_force_quiescent_state,
Tejun Heo969c7922010-05-06 18:49:21 +0200716 .stats = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700717 .irq_capable = 1,
718 .name = "sched_expedited"
Paul E. McKenney23269742008-05-12 21:21:05 +0200719};
720
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700721/*
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700722 * RCU torture priority-boost testing. Runs one real-time thread per
723 * CPU for moderate bursts, repeatedly registering RCU callbacks and
724 * spinning waiting for them to be invoked. If a given callback takes
725 * too long to be invoked, we assume that priority inversion has occurred.
726 */
727
728struct rcu_boost_inflight {
729 struct rcu_head rcu;
730 int inflight;
731};
732
733static void rcu_torture_boost_cb(struct rcu_head *head)
734{
735 struct rcu_boost_inflight *rbip =
736 container_of(head, struct rcu_boost_inflight, rcu);
737
738 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
739 rbip->inflight = 0;
740}
741
742static int rcu_torture_boost(void *arg)
743{
744 unsigned long call_rcu_time;
745 unsigned long endtime;
746 unsigned long oldstarttime;
747 struct rcu_boost_inflight rbi = { .inflight = 0 };
748 struct sched_param sp;
749
750 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
751
752 /* Set real-time priority. */
753 sp.sched_priority = 1;
754 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
755 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
756 n_rcu_torture_boost_rterror++;
757 }
758
Paul E. McKenney561190e2011-03-30 09:10:44 -0700759 init_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700760 /* Each pass through the following loop does one boost-test cycle. */
761 do {
762 /* Wait for the next test interval. */
763 oldstarttime = boost_starttime;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700764 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700765 schedule_timeout_uninterruptible(1);
766 rcu_stutter_wait("rcu_torture_boost");
767 if (kthread_should_stop() ||
768 fullstop != FULLSTOP_DONTSTOP)
769 goto checkwait;
770 }
771
772 /* Do one boost-test interval. */
773 endtime = oldstarttime + test_boost_duration * HZ;
774 call_rcu_time = jiffies;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700775 while (ULONG_CMP_LT(jiffies, endtime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700776 /* If we don't have a callback in flight, post one. */
777 if (!rbi.inflight) {
778 smp_mb(); /* RCU core before ->inflight = 1. */
779 rbi.inflight = 1;
780 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
781 if (jiffies - call_rcu_time >
782 test_boost_duration * HZ - HZ / 2) {
783 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
784 n_rcu_torture_boost_failure++;
785 }
786 call_rcu_time = jiffies;
787 }
788 cond_resched();
789 rcu_stutter_wait("rcu_torture_boost");
790 if (kthread_should_stop() ||
791 fullstop != FULLSTOP_DONTSTOP)
792 goto checkwait;
793 }
794
795 /*
796 * Set the start time of the next test interval.
797 * Yes, this is vulnerable to long delays, but such
798 * delays simply cause a false negative for the next
799 * interval. Besides, we are running at RT priority,
800 * so delays should be relatively rare.
801 */
Paul E. McKenneyab8f11e2011-08-18 09:30:32 -0700802 while (oldstarttime == boost_starttime &&
803 !kthread_should_stop()) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700804 if (mutex_trylock(&boost_mutex)) {
805 boost_starttime = jiffies +
806 test_boost_interval * HZ;
807 n_rcu_torture_boosts++;
808 mutex_unlock(&boost_mutex);
809 break;
810 }
811 schedule_timeout_uninterruptible(1);
812 }
813
814 /* Go do the stutter. */
815checkwait: rcu_stutter_wait("rcu_torture_boost");
816 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
817
818 /* Clean up and exit. */
819 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
820 rcutorture_shutdown_absorb("rcu_torture_boost");
821 while (!kthread_should_stop() || rbi.inflight)
822 schedule_timeout_uninterruptible(1);
823 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
Paul E. McKenney9d681972011-06-21 01:48:03 -0700824 destroy_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700825 return 0;
826}
827
828/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800829 * RCU torture force-quiescent-state kthread. Repeatedly induces
830 * bursts of calls to force_quiescent_state(), increasing the probability
831 * of occurrence of some important types of race conditions.
832 */
833static int
834rcu_torture_fqs(void *arg)
835{
836 unsigned long fqs_resume_time;
837 int fqs_burst_remaining;
838
839 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
840 do {
841 fqs_resume_time = jiffies + fqs_stutter * HZ;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700842 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
843 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800844 schedule_timeout_interruptible(1);
845 }
846 fqs_burst_remaining = fqs_duration;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700847 while (fqs_burst_remaining > 0 &&
848 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800849 cur_ops->fqs();
850 udelay(fqs_holdoff);
851 fqs_burst_remaining -= fqs_holdoff;
852 }
853 rcu_stutter_wait("rcu_torture_fqs");
854 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
855 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
856 rcutorture_shutdown_absorb("rcu_torture_fqs");
857 while (!kthread_should_stop())
858 schedule_timeout_uninterruptible(1);
859 return 0;
860}
861
862/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800863 * RCU torture writer kthread. Repeatedly substitutes a new structure
864 * for that pointed to by rcu_torture_current, freeing the old structure
865 * after a series of grace periods (the "pipeline").
866 */
867static int
868rcu_torture_writer(void *arg)
869{
870 int i;
871 long oldbatch = rcu_batches_completed();
872 struct rcu_torture *rp;
873 struct rcu_torture *old_rp;
874 static DEFINE_RCU_RANDOM(rand);
875
876 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800877 set_user_nice(current, 19);
878
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800879 do {
880 schedule_timeout_uninterruptible(1);
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700881 rp = rcu_torture_alloc();
882 if (rp == NULL)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800883 continue;
884 rp->rtort_pipe_count = 0;
885 udelay(rcu_random(&rand) & 0x3ff);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700886 old_rp = rcu_dereference_check(rcu_torture_current,
887 current == writer_task);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800888 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800889 rcu_assign_pointer(rcu_torture_current, rp);
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700890 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
Josh Triplettc8e5b162007-05-08 00:33:20 -0700891 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800892 i = old_rp->rtort_pipe_count;
893 if (i > RCU_TORTURE_PIPE_LEN)
894 i = RCU_TORTURE_PIPE_LEN;
895 atomic_inc(&rcu_torture_wcount[i]);
896 old_rp->rtort_pipe_count++;
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700897 cur_ops->deferred_free(old_rp);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800898 }
Paul E. McKenney4a298652011-04-03 21:33:51 -0700899 rcutorture_record_progress(++rcu_torture_current_version);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700900 oldbatch = cur_ops->completed();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800901 rcu_stutter_wait("rcu_torture_writer");
902 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800903 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800904 rcutorture_shutdown_absorb("rcu_torture_writer");
905 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800906 schedule_timeout_uninterruptible(1);
907 return 0;
908}
909
910/*
Josh Triplettb772e1d2006-10-04 02:17:13 -0700911 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
912 * delay between calls.
913 */
914static int
915rcu_torture_fakewriter(void *arg)
916{
917 DEFINE_RCU_RANDOM(rand);
918
919 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
920 set_user_nice(current, 19);
921
922 do {
923 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
924 udelay(rcu_random(&rand) & 0x3ff);
925 cur_ops->sync();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800926 rcu_stutter_wait("rcu_torture_fakewriter");
927 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700928
929 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800930 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
931 while (!kthread_should_stop())
Josh Triplettb772e1d2006-10-04 02:17:13 -0700932 schedule_timeout_uninterruptible(1);
933 return 0;
934}
935
Paul E. McKenney91afaf32011-10-02 07:44:32 -0700936void rcutorture_trace_dump(void)
937{
938 static atomic_t beenhere = ATOMIC_INIT(0);
939
940 if (atomic_read(&beenhere))
941 return;
942 if (atomic_xchg(&beenhere, 1) != 0)
943 return;
944 do_trace_rcu_torture_read(cur_ops->name, (struct rcu_head *)~0UL);
945 ftrace_dump(DUMP_ALL);
946}
947
Josh Triplettb772e1d2006-10-04 02:17:13 -0700948/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700949 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
950 * incrementing the corresponding element of the pipeline array. The
951 * counter in the element should never be greater than 1, otherwise, the
952 * RCU implementation is broken.
953 */
954static void rcu_torture_timer(unsigned long unused)
955{
956 int idx;
957 int completed;
958 static DEFINE_RCU_RANDOM(rand);
959 static DEFINE_SPINLOCK(rand_lock);
960 struct rcu_torture *p;
961 int pipe_count;
962
963 idx = cur_ops->readlock();
964 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -0800965 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -0800966 rcu_read_lock_bh_held() ||
967 rcu_read_lock_sched_held() ||
968 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenney91afaf32011-10-02 07:44:32 -0700969 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700970 if (p == NULL) {
971 /* Leave because rcu_torture_writer is not yet underway */
972 cur_ops->readunlock(idx);
973 return;
974 }
975 if (p->rtort_mbtest == 0)
976 atomic_inc(&n_rcu_torture_mberror);
977 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700978 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700979 n_rcu_torture_timers++;
980 spin_unlock(&rand_lock);
981 preempt_disable();
982 pipe_count = p->rtort_pipe_count;
983 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
984 /* Should not happen, but... */
985 pipe_count = RCU_TORTURE_PIPE_LEN;
986 }
Paul E. McKenney91afaf32011-10-02 07:44:32 -0700987 if (pipe_count > 1)
988 rcutorture_trace_dump();
Rusty Russelldd17c8f2009-10-29 22:34:15 +0900989 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700990 completed = cur_ops->completed() - completed;
991 if (completed > RCU_TORTURE_PIPE_LEN) {
992 /* Should not happen, but... */
993 completed = RCU_TORTURE_PIPE_LEN;
994 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +0900995 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700996 preempt_enable();
997 cur_ops->readunlock(idx);
998}
999
1000/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001001 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
1002 * incrementing the corresponding element of the pipeline array. The
1003 * counter in the element should never be greater than 1, otherwise, the
1004 * RCU implementation is broken.
1005 */
1006static int
1007rcu_torture_reader(void *arg)
1008{
1009 int completed;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001010 int idx;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001011 DEFINE_RCU_RANDOM(rand);
1012 struct rcu_torture *p;
1013 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001014 struct timer_list t;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001015
1016 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001017 set_user_nice(current, 19);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001018 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001019 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001020
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001021 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001022 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001023 if (!timer_pending(&t))
Paul E. McKenney6155fec2010-02-22 17:05:04 -08001024 mod_timer(&t, jiffies + 1);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001025 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001026 idx = cur_ops->readlock();
1027 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001028 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001029 rcu_read_lock_bh_held() ||
1030 rcu_read_lock_sched_held() ||
1031 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001032 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001033 if (p == NULL) {
1034 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001035 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001036 schedule_timeout_interruptible(HZ);
1037 continue;
1038 }
Paul E. McKenney996417d2005-11-18 01:10:50 -08001039 if (p->rtort_mbtest == 0)
1040 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001041 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001042 preempt_disable();
1043 pipe_count = p->rtort_pipe_count;
1044 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1045 /* Should not happen, but... */
1046 pipe_count = RCU_TORTURE_PIPE_LEN;
1047 }
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001048 if (pipe_count > 1)
1049 rcutorture_trace_dump();
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001050 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001051 completed = cur_ops->completed() - completed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001052 if (completed > RCU_TORTURE_PIPE_LEN) {
1053 /* Should not happen, but... */
1054 completed = RCU_TORTURE_PIPE_LEN;
1055 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001056 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001057 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001058 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001059 schedule();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001060 rcu_stutter_wait("rcu_torture_reader");
1061 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001062 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001063 rcutorture_shutdown_absorb("rcu_torture_reader");
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001064 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001065 del_timer_sync(&t);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001066 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001067 schedule_timeout_uninterruptible(1);
1068 return 0;
1069}
1070
1071/*
1072 * Create an RCU-torture statistics message in the specified buffer.
1073 */
1074static int
1075rcu_torture_printk(char *page)
1076{
1077 int cnt = 0;
1078 int cpu;
1079 int i;
1080 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1081 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1082
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001083 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001084 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1085 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1086 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1087 }
1088 }
1089 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1090 if (pipesummary[i] != 0)
1091 break;
1092 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001093 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001094 cnt += sprintf(&page[cnt],
Paul E. McKenney4a298652011-04-03 21:33:51 -07001095 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d "
Paul E. McKenney67b98db2011-02-21 13:31:55 -08001096 "rtmbe: %d rtbke: %ld rtbre: %ld "
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001097 "rtbf: %ld rtb: %ld nt: %ld "
1098 "onoff: %ld/%ld:%ld/%ld",
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001099 rcu_torture_current,
1100 rcu_torture_current_version,
1101 list_empty(&rcu_torture_freelist),
1102 atomic_read(&n_rcu_torture_alloc),
1103 atomic_read(&n_rcu_torture_alloc_fail),
Paul E. McKenney996417d2005-11-18 01:10:50 -08001104 atomic_read(&n_rcu_torture_free),
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001105 atomic_read(&n_rcu_torture_mberror),
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001106 n_rcu_torture_boost_ktrerror,
1107 n_rcu_torture_boost_rterror,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001108 n_rcu_torture_boost_failure,
1109 n_rcu_torture_boosts,
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001110 n_rcu_torture_timers,
1111 n_online_successes,
1112 n_online_attempts,
1113 n_offline_successes,
1114 n_offline_attempts);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001115 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
1116 n_rcu_torture_boost_ktrerror != 0 ||
1117 n_rcu_torture_boost_rterror != 0 ||
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001118 n_rcu_torture_boost_failure != 0)
Paul E. McKenney996417d2005-11-18 01:10:50 -08001119 cnt += sprintf(&page[cnt], " !!!");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001120 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001121 if (i > 1) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001122 cnt += sprintf(&page[cnt], "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -08001123 atomic_inc(&n_rcu_torture_error);
Ingo Molnar5af970a2008-06-18 10:09:48 +02001124 WARN_ON_ONCE(1);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001125 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001126 cnt += sprintf(&page[cnt], "Reader Pipe: ");
1127 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1128 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001129 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001130 cnt += sprintf(&page[cnt], "Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001131 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001132 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001133 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001134 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
1135 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1136 cnt += sprintf(&page[cnt], " %d",
1137 atomic_read(&rcu_torture_wcount[i]));
1138 }
1139 cnt += sprintf(&page[cnt], "\n");
Josh Triplettc8e5b162007-05-08 00:33:20 -07001140 if (cur_ops->stats)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001141 cnt += cur_ops->stats(&page[cnt]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001142 return cnt;
1143}
1144
1145/*
1146 * Print torture statistics. Caller must ensure that there is only
1147 * one call to this function at a given time!!! This is normally
1148 * accomplished by relying on the module system to only have one copy
1149 * of the module loaded, and then by giving the rcu_torture_stats
1150 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1151 * thread is not running).
1152 */
1153static void
1154rcu_torture_stats_print(void)
1155{
1156 int cnt;
1157
1158 cnt = rcu_torture_printk(printk_buf);
1159 printk(KERN_ALERT "%s", printk_buf);
1160}
1161
1162/*
1163 * Periodically prints torture statistics, if periodic statistics printing
1164 * was specified via the stat_interval module parameter.
1165 *
1166 * No need to worry about fullstop here, since this one doesn't reference
1167 * volatile state or register callbacks.
1168 */
1169static int
1170rcu_torture_stats(void *arg)
1171{
1172 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1173 do {
1174 schedule_timeout_interruptible(stat_interval * HZ);
1175 rcu_torture_stats_print();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001176 rcutorture_shutdown_absorb("rcu_torture_stats");
1177 } while (!kthread_should_stop());
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001178 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1179 return 0;
1180}
1181
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001182static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
1183
1184/* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1185 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1186 */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -07001187static void rcu_torture_shuffle_tasks(void)
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001188{
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001189 int i;
1190
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001191 cpumask_setall(shuffle_tmp_mask);
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001192 get_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001193
1194 /* No point in shuffling if there is only one online CPU (ex: UP) */
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001195 if (num_online_cpus() == 1) {
1196 put_online_cpus();
1197 return;
1198 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001199
1200 if (rcu_idle_cpu != -1)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001201 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001202
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001203 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001204
Josh Triplettc8e5b162007-05-08 00:33:20 -07001205 if (reader_tasks) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001206 for (i = 0; i < nrealreaders; i++)
1207 if (reader_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001208 set_cpus_allowed_ptr(reader_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001209 shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001210 }
1211
Josh Triplettc8e5b162007-05-08 00:33:20 -07001212 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001213 for (i = 0; i < nfakewriters; i++)
1214 if (fakewriter_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001215 set_cpus_allowed_ptr(fakewriter_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001216 shuffle_tmp_mask);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001217 }
1218
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001219 if (writer_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001220 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001221
1222 if (stats_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001223 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001224
1225 if (rcu_idle_cpu == -1)
1226 rcu_idle_cpu = num_online_cpus() - 1;
1227 else
1228 rcu_idle_cpu--;
1229
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001230 put_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001231}
1232
1233/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1234 * system to become idle at a time and cut off its timer ticks. This is meant
1235 * to test the support for such tickless idle CPU in RCU.
1236 */
1237static int
1238rcu_torture_shuffle(void *arg)
1239{
1240 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1241 do {
1242 schedule_timeout_interruptible(shuffle_interval * HZ);
1243 rcu_torture_shuffle_tasks();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001244 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1245 } while (!kthread_should_stop());
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001246 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1247 return 0;
1248}
1249
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001250/* Cause the rcutorture test to "stutter", starting and stopping all
1251 * threads periodically.
1252 */
1253static int
1254rcu_torture_stutter(void *arg)
1255{
1256 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1257 do {
1258 schedule_timeout_interruptible(stutter * HZ);
1259 stutter_pause_test = 1;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001260 if (!kthread_should_stop())
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001261 schedule_timeout_interruptible(stutter * HZ);
1262 stutter_pause_test = 0;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001263 rcutorture_shutdown_absorb("rcu_torture_stutter");
1264 } while (!kthread_should_stop());
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001265 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1266 return 0;
1267}
1268
Paul E. McKenney95c38322006-03-24 03:15:58 -08001269static inline void
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001270rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
Paul E. McKenney95c38322006-03-24 03:15:58 -08001271{
Josh Triplettb772e1d2006-10-04 02:17:13 -07001272 printk(KERN_ALERT "%s" TORTURE_FLAG
1273 "--- %s: nreaders=%d nfakewriters=%d "
Paul E. McKenney95c38322006-03-24 03:15:58 -08001274 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001275 "shuffle_interval=%d stutter=%d irqreader=%d "
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001276 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1277 "test_boost=%d/%d test_boost_interval=%d "
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001278 "test_boost_duration=%d shutdown_secs=%d "
1279 "onoff_interval=%d\n",
Josh Triplettb772e1d2006-10-04 02:17:13 -07001280 torture_type, tag, nrealreaders, nfakewriters,
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001281 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001282 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1283 test_boost, cur_ops->can_boost,
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001284 test_boost_interval, test_boost_duration, shutdown_secs,
1285 onoff_interval);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001286}
1287
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001288static struct notifier_block rcutorture_shutdown_nb = {
Paul E. McKenney343e9092008-12-15 16:13:07 -08001289 .notifier_call = rcutorture_shutdown_notify,
1290};
1291
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001292static void rcutorture_booster_cleanup(int cpu)
1293{
1294 struct task_struct *t;
1295
1296 if (boost_tasks[cpu] == NULL)
1297 return;
1298 mutex_lock(&boost_mutex);
1299 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1300 t = boost_tasks[cpu];
1301 boost_tasks[cpu] = NULL;
1302 mutex_unlock(&boost_mutex);
1303
1304 /* This must be outside of the mutex, otherwise deadlock! */
1305 kthread_stop(t);
1306}
1307
1308static int rcutorture_booster_init(int cpu)
1309{
1310 int retval;
1311
1312 if (boost_tasks[cpu] != NULL)
1313 return 0; /* Already created, nothing more to do. */
1314
1315 /* Don't allow time recalculation while creating a new task. */
1316 mutex_lock(&boost_mutex);
1317 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
Eric Dumazet1f288092011-06-16 15:53:18 -07001318 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1319 cpu_to_node(cpu),
1320 "rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001321 if (IS_ERR(boost_tasks[cpu])) {
1322 retval = PTR_ERR(boost_tasks[cpu]);
1323 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1324 n_rcu_torture_boost_ktrerror++;
1325 boost_tasks[cpu] = NULL;
1326 mutex_unlock(&boost_mutex);
1327 return retval;
1328 }
1329 kthread_bind(boost_tasks[cpu], cpu);
1330 wake_up_process(boost_tasks[cpu]);
1331 mutex_unlock(&boost_mutex);
1332 return 0;
1333}
1334
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001335/*
1336 * Cause the rcutorture test to shutdown the system after the test has
1337 * run for the time specified by the shutdown_secs module parameter.
1338 */
1339static int
1340rcu_torture_shutdown(void *arg)
1341{
1342 long delta;
1343 unsigned long jiffies_snap;
1344
1345 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1346 jiffies_snap = ACCESS_ONCE(jiffies);
1347 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
1348 !kthread_should_stop()) {
1349 delta = shutdown_time - jiffies_snap;
1350 if (verbose)
1351 printk(KERN_ALERT "%s" TORTURE_FLAG
1352 "rcu_torture_shutdown task: %lu "
1353 "jiffies remaining\n",
1354 torture_type, delta);
1355 schedule_timeout_interruptible(delta);
1356 jiffies_snap = ACCESS_ONCE(jiffies);
1357 }
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001358 if (kthread_should_stop()) {
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001359 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1360 return 0;
1361 }
1362
1363 /* OK, shut down the system. */
1364
1365 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1366 shutdown_task = NULL; /* Avoid self-kill deadlock. */
1367 rcu_torture_cleanup(); /* Get the success/failure message. */
1368 kernel_power_off(); /* Shut down the system. */
1369 return 0;
1370}
1371
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001372#ifdef CONFIG_HOTPLUG_CPU
1373
1374/*
1375 * Execute random CPU-hotplug operations at the interval specified
1376 * by the onoff_interval.
1377 */
1378static int
1379rcu_torture_onoff(void *arg)
1380{
1381 int cpu;
1382 int maxcpu = -1;
1383 DEFINE_RCU_RANDOM(rand);
1384
1385 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1386 for_each_online_cpu(cpu)
1387 maxcpu = cpu;
1388 WARN_ON(maxcpu < 0);
1389 while (!kthread_should_stop()) {
1390 cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
Paul E. McKenneyf2202422011-12-03 15:09:28 -08001391 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001392 if (verbose)
1393 printk(KERN_ALERT "%s" TORTURE_FLAG
1394 "rcu_torture_onoff task: offlining %d\n",
1395 torture_type, cpu);
1396 n_offline_attempts++;
1397 if (cpu_down(cpu) == 0) {
1398 if (verbose)
1399 printk(KERN_ALERT "%s" TORTURE_FLAG
1400 "rcu_torture_onoff task: "
1401 "offlined %d\n",
1402 torture_type, cpu);
1403 n_offline_successes++;
1404 }
Paul E. McKenneyf2202422011-12-03 15:09:28 -08001405 } else if (cpu_is_hotpluggable(cpu)) {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001406 if (verbose)
1407 printk(KERN_ALERT "%s" TORTURE_FLAG
1408 "rcu_torture_onoff task: onlining %d\n",
1409 torture_type, cpu);
1410 n_online_attempts++;
1411 if (cpu_up(cpu) == 0) {
1412 if (verbose)
1413 printk(KERN_ALERT "%s" TORTURE_FLAG
1414 "rcu_torture_onoff task: "
1415 "onlined %d\n",
1416 torture_type, cpu);
1417 n_online_successes++;
1418 }
1419 }
1420 schedule_timeout_interruptible(onoff_interval * HZ);
1421 }
1422 VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1423 return 0;
1424}
1425
1426static int
1427rcu_torture_onoff_init(void)
1428{
1429 if (onoff_interval <= 0)
1430 return 0;
1431 onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff");
1432 if (IS_ERR(onoff_task)) {
1433 onoff_task = NULL;
1434 return PTR_ERR(onoff_task);
1435 }
1436 return 0;
1437}
1438
1439static void rcu_torture_onoff_cleanup(void)
1440{
1441 if (onoff_task == NULL)
1442 return;
1443 VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1444 kthread_stop(onoff_task);
1445}
1446
1447#else /* #ifdef CONFIG_HOTPLUG_CPU */
1448
1449static void
1450rcu_torture_onoff_init(void)
1451{
1452}
1453
1454static void rcu_torture_onoff_cleanup(void)
1455{
1456}
1457
1458#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1459
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001460static int rcutorture_cpu_notify(struct notifier_block *self,
1461 unsigned long action, void *hcpu)
1462{
1463 long cpu = (long)hcpu;
1464
1465 switch (action) {
1466 case CPU_ONLINE:
1467 case CPU_DOWN_FAILED:
1468 (void)rcutorture_booster_init(cpu);
1469 break;
1470 case CPU_DOWN_PREPARE:
1471 rcutorture_booster_cleanup(cpu);
1472 break;
1473 default:
1474 break;
1475 }
1476 return NOTIFY_OK;
1477}
1478
1479static struct notifier_block rcutorture_cpu_nb = {
1480 .notifier_call = rcutorture_cpu_notify,
1481};
1482
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001483static void
1484rcu_torture_cleanup(void)
1485{
1486 int i;
1487
Paul E. McKenney343e9092008-12-15 16:13:07 -08001488 mutex_lock(&fullstop_mutex);
Paul E. McKenney4a298652011-04-03 21:33:51 -07001489 rcutorture_record_test_transition();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001490 if (fullstop == FULLSTOP_SHUTDOWN) {
1491 printk(KERN_WARNING /* but going down anyway, so... */
1492 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001493 mutex_unlock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001494 schedule_timeout_uninterruptible(10);
Paul E. McKenney343e9092008-12-15 16:13:07 -08001495 if (cur_ops->cb_barrier != NULL)
1496 cur_ops->cb_barrier();
1497 return;
1498 }
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001499 fullstop = FULLSTOP_RMMOD;
Paul E. McKenney343e9092008-12-15 16:13:07 -08001500 mutex_unlock(&fullstop_mutex);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001501 unregister_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001502 if (stutter_task) {
1503 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1504 kthread_stop(stutter_task);
1505 }
1506 stutter_task = NULL;
Josh Triplettc8e5b162007-05-08 00:33:20 -07001507 if (shuffler_task) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001508 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1509 kthread_stop(shuffler_task);
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001510 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001511 }
1512 shuffler_task = NULL;
1513
Josh Triplettc8e5b162007-05-08 00:33:20 -07001514 if (writer_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001515 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1516 kthread_stop(writer_task);
1517 }
1518 writer_task = NULL;
1519
Josh Triplettc8e5b162007-05-08 00:33:20 -07001520 if (reader_tasks) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001521 for (i = 0; i < nrealreaders; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001522 if (reader_tasks[i]) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001523 VERBOSE_PRINTK_STRING(
1524 "Stopping rcu_torture_reader task");
1525 kthread_stop(reader_tasks[i]);
1526 }
1527 reader_tasks[i] = NULL;
1528 }
1529 kfree(reader_tasks);
1530 reader_tasks = NULL;
1531 }
1532 rcu_torture_current = NULL;
1533
Josh Triplettc8e5b162007-05-08 00:33:20 -07001534 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001535 for (i = 0; i < nfakewriters; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001536 if (fakewriter_tasks[i]) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001537 VERBOSE_PRINTK_STRING(
1538 "Stopping rcu_torture_fakewriter task");
1539 kthread_stop(fakewriter_tasks[i]);
1540 }
1541 fakewriter_tasks[i] = NULL;
1542 }
1543 kfree(fakewriter_tasks);
1544 fakewriter_tasks = NULL;
1545 }
1546
Josh Triplettc8e5b162007-05-08 00:33:20 -07001547 if (stats_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001548 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1549 kthread_stop(stats_task);
1550 }
1551 stats_task = NULL;
1552
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001553 if (fqs_task) {
1554 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1555 kthread_stop(fqs_task);
1556 }
1557 fqs_task = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001558 if ((test_boost == 1 && cur_ops->can_boost) ||
1559 test_boost == 2) {
1560 unregister_cpu_notifier(&rcutorture_cpu_nb);
1561 for_each_possible_cpu(i)
1562 rcutorture_booster_cleanup(i);
1563 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001564 if (shutdown_task != NULL) {
1565 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1566 kthread_stop(shutdown_task);
1567 }
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001568 rcu_torture_onoff_cleanup();
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001569
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001570 /* Wait for all RCU callbacks to fire. */
Paul E. McKenney23269742008-05-12 21:21:05 +02001571
1572 if (cur_ops->cb_barrier != NULL)
1573 cur_ops->cb_barrier();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001574
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001575 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001576
Josh Triplettc8e5b162007-05-08 00:33:20 -07001577 if (cur_ops->cleanup)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001578 cur_ops->cleanup();
Paul E. McKenney95c38322006-03-24 03:15:58 -08001579 if (atomic_read(&n_rcu_torture_error))
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001580 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
Paul E. McKenney95c38322006-03-24 03:15:58 -08001581 else
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001582 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001583}
1584
Josh Triplett6f8bc502007-05-08 00:25:24 -07001585static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001586rcu_torture_init(void)
1587{
1588 int i;
1589 int cpu;
1590 int firsterr = 0;
Josh Triplettade5fb82007-05-08 00:33:22 -07001591 static struct rcu_torture_ops *torture_ops[] =
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -08001592 { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -07001593 &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops,
Paul E. McKenney804bb832009-10-25 19:03:52 -07001594 &srcu_ops, &srcu_expedited_ops,
1595 &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001596
Paul E. McKenney343e9092008-12-15 16:13:07 -08001597 mutex_lock(&fullstop_mutex);
1598
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001599 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001600 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001601 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001602 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001603 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001604 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001605 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001606 printk(KERN_ALERT "rcu-torture: invalid torture type: \"%s\"\n",
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001607 torture_type);
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001608 printk(KERN_ALERT "rcu-torture types:");
1609 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
1610 printk(KERN_ALERT " %s", torture_ops[i]->name);
1611 printk(KERN_ALERT "\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001612 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001613 return -EINVAL;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001614 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001615 if (cur_ops->fqs == NULL && fqs_duration != 0) {
1616 printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero "
1617 "fqs_duration, fqs disabled.\n");
1618 fqs_duration = 0;
1619 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001620 if (cur_ops->init)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001621 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1622
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001623 if (nreaders >= 0)
1624 nrealreaders = nreaders;
1625 else
1626 nrealreaders = 2 * num_online_cpus();
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001627 rcu_torture_print_module_parms(cur_ops, "Start of test");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001628 fullstop = FULLSTOP_DONTSTOP;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001629
1630 /* Set up the freelist. */
1631
1632 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07001633 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08001634 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001635 list_add_tail(&rcu_tortures[i].rtort_free,
1636 &rcu_torture_freelist);
1637 }
1638
1639 /* Initialize the statistics so that each run gets its own numbers. */
1640
1641 rcu_torture_current = NULL;
1642 rcu_torture_current_version = 0;
1643 atomic_set(&n_rcu_torture_alloc, 0);
1644 atomic_set(&n_rcu_torture_alloc_fail, 0);
1645 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001646 atomic_set(&n_rcu_torture_mberror, 0);
1647 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001648 n_rcu_torture_boost_ktrerror = 0;
1649 n_rcu_torture_boost_rterror = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001650 n_rcu_torture_boost_failure = 0;
1651 n_rcu_torture_boosts = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001652 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1653 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001654 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001655 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1656 per_cpu(rcu_torture_count, cpu)[i] = 0;
1657 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1658 }
1659 }
1660
1661 /* Start up the kthreads. */
1662
1663 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1664 writer_task = kthread_run(rcu_torture_writer, NULL,
1665 "rcu_torture_writer");
1666 if (IS_ERR(writer_task)) {
1667 firsterr = PTR_ERR(writer_task);
1668 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1669 writer_task = NULL;
1670 goto unwind;
1671 }
Josh Triplettb772e1d2006-10-04 02:17:13 -07001672 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001673 GFP_KERNEL);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001674 if (fakewriter_tasks == NULL) {
1675 VERBOSE_PRINTK_ERRSTRING("out of memory");
1676 firsterr = -ENOMEM;
1677 goto unwind;
1678 }
1679 for (i = 0; i < nfakewriters; i++) {
1680 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
1681 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001682 "rcu_torture_fakewriter");
Josh Triplettb772e1d2006-10-04 02:17:13 -07001683 if (IS_ERR(fakewriter_tasks[i])) {
1684 firsterr = PTR_ERR(fakewriter_tasks[i]);
1685 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
1686 fakewriter_tasks[i] = NULL;
1687 goto unwind;
1688 }
1689 }
Josh Triplett2860aab2006-10-04 02:17:11 -07001690 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001691 GFP_KERNEL);
1692 if (reader_tasks == NULL) {
1693 VERBOSE_PRINTK_ERRSTRING("out of memory");
1694 firsterr = -ENOMEM;
1695 goto unwind;
1696 }
1697 for (i = 0; i < nrealreaders; i++) {
1698 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
1699 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
1700 "rcu_torture_reader");
1701 if (IS_ERR(reader_tasks[i])) {
1702 firsterr = PTR_ERR(reader_tasks[i]);
1703 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
1704 reader_tasks[i] = NULL;
1705 goto unwind;
1706 }
1707 }
1708 if (stat_interval > 0) {
1709 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
1710 stats_task = kthread_run(rcu_torture_stats, NULL,
1711 "rcu_torture_stats");
1712 if (IS_ERR(stats_task)) {
1713 firsterr = PTR_ERR(stats_task);
1714 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
1715 stats_task = NULL;
1716 goto unwind;
1717 }
1718 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001719 if (test_no_idle_hz) {
1720 rcu_idle_cpu = num_online_cpus() - 1;
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001721
1722 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
1723 firsterr = -ENOMEM;
1724 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
1725 goto unwind;
1726 }
1727
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001728 /* Create the shuffler thread */
1729 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
1730 "rcu_torture_shuffle");
1731 if (IS_ERR(shuffler_task)) {
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001732 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001733 firsterr = PTR_ERR(shuffler_task);
1734 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
1735 shuffler_task = NULL;
1736 goto unwind;
1737 }
1738 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001739 if (stutter < 0)
1740 stutter = 0;
1741 if (stutter) {
1742 /* Create the stutter thread */
1743 stutter_task = kthread_run(rcu_torture_stutter, NULL,
1744 "rcu_torture_stutter");
1745 if (IS_ERR(stutter_task)) {
1746 firsterr = PTR_ERR(stutter_task);
1747 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
1748 stutter_task = NULL;
1749 goto unwind;
1750 }
1751 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001752 if (fqs_duration < 0)
1753 fqs_duration = 0;
1754 if (fqs_duration) {
1755 /* Create the stutter thread */
1756 fqs_task = kthread_run(rcu_torture_fqs, NULL,
1757 "rcu_torture_fqs");
1758 if (IS_ERR(fqs_task)) {
1759 firsterr = PTR_ERR(fqs_task);
1760 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
1761 fqs_task = NULL;
1762 goto unwind;
1763 }
1764 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001765 if (test_boost_interval < 1)
1766 test_boost_interval = 1;
1767 if (test_boost_duration < 2)
1768 test_boost_duration = 2;
1769 if ((test_boost == 1 && cur_ops->can_boost) ||
1770 test_boost == 2) {
1771 int retval;
1772
1773 boost_starttime = jiffies + test_boost_interval * HZ;
1774 register_cpu_notifier(&rcutorture_cpu_nb);
1775 for_each_possible_cpu(i) {
1776 if (cpu_is_offline(i))
1777 continue; /* Heuristic: CPU can go offline. */
1778 retval = rcutorture_booster_init(i);
1779 if (retval < 0) {
1780 firsterr = retval;
1781 goto unwind;
1782 }
1783 }
1784 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001785 if (shutdown_secs > 0) {
1786 shutdown_time = jiffies + shutdown_secs * HZ;
1787 shutdown_task = kthread_run(rcu_torture_shutdown, NULL,
1788 "rcu_torture_shutdown");
1789 if (IS_ERR(shutdown_task)) {
1790 firsterr = PTR_ERR(shutdown_task);
1791 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
1792 shutdown_task = NULL;
1793 goto unwind;
1794 }
1795 }
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001796 rcu_torture_onoff_init();
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001797 register_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenney4a298652011-04-03 21:33:51 -07001798 rcutorture_record_test_transition();
Paul E. McKenney343e9092008-12-15 16:13:07 -08001799 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001800 return 0;
1801
1802unwind:
Paul E. McKenney343e9092008-12-15 16:13:07 -08001803 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001804 rcu_torture_cleanup();
1805 return firsterr;
1806}
1807
1808module_init(rcu_torture_init);
1809module_exit(rcu_torture_cleanup);