blob: f7fe73e59c9f2ddf938622e03df5eb287642061a [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". */
Rusty Russelld8e8ed92011-12-15 13:43:24 +103059static bool verbose; /* Print more debug info. */
60static bool 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. McKenneyfae4b542012-02-20 17:51:45 -080067static int n_barrier_cbs; /* Number of callbacks to test RCU barriers. */
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -080068static int onoff_interval; /* Wait time between CPU hotplugs, 0=disable. */
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -080069static int onoff_holdoff; /* Seconds after boot before CPU hotplugs. */
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -070070static int shutdown_secs; /* Shutdown time (s). <=0 for no shutdown. */
Paul E. McKenneyc13f3752012-01-20 15:36:33 -080071static int stall_cpu; /* CPU-stall duration (s). 0 for no stall. */
72static int stall_cpu_holdoff = 10; /* Time to wait until stall (s). */
Paul E. McKenney8e8be452010-09-02 16:16:14 -070073static int test_boost = 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */
74static int test_boost_interval = 7; /* Interval between boost tests, seconds. */
75static int test_boost_duration = 4; /* Duration of each boost test, seconds. */
Josh Triplett20d2e422006-10-04 02:17:15 -070076static char *torture_type = "rcu"; /* What RCU implementation to torture. */
Paul E. McKenneya241ec62005-10-30 15:03:12 -080077
Josh Triplettd6ad6712007-03-06 01:42:13 -080078module_param(nreaders, int, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080079MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
Josh Triplettd6ad6712007-03-06 01:42:13 -080080module_param(nfakewriters, int, 0444);
Josh Triplettb772e1d2006-10-04 02:17:13 -070081MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
Paul E. McKenney3721bc12011-07-21 16:00:17 -070082module_param(stat_interval, int, 0644);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080083MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
Josh Triplettd6ad6712007-03-06 01:42:13 -080084module_param(verbose, bool, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080085MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
Josh Triplettd6ad6712007-03-06 01:42:13 -080086module_param(test_no_idle_hz, bool, 0444);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080087MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
Josh Triplettd6ad6712007-03-06 01:42:13 -080088module_param(shuffle_interval, int, 0444);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080089MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
Paul E. McKenneyd120f652008-06-18 05:21:44 -070090module_param(stutter, int, 0444);
91MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
Paul E. McKenney0729fbf2008-06-25 12:24:52 -070092module_param(irqreader, int, 0444);
93MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
Paul E. McKenneybf66f182010-01-04 15:09:10 -080094module_param(fqs_duration, int, 0444);
95MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us)");
96module_param(fqs_holdoff, int, 0444);
97MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)");
98module_param(fqs_stutter, int, 0444);
99MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800100module_param(n_barrier_cbs, int, 0444);
101MODULE_PARM_DESC(n_barrier_cbs, "# of callbacks/kthreads for barrier testing");
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -0800102module_param(onoff_interval, int, 0444);
103MODULE_PARM_DESC(onoff_interval, "Time between CPU hotplugs (s), 0=disable");
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -0800104module_param(onoff_holdoff, int, 0444);
105MODULE_PARM_DESC(onoff_holdoff, "Time after boot before CPU hotplugs (s)");
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700106module_param(shutdown_secs, int, 0444);
107MODULE_PARM_DESC(shutdown_secs, "Shutdown time (s), zero to disable.");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -0800108module_param(stall_cpu, int, 0444);
109MODULE_PARM_DESC(stall_cpu, "Stall duration (s), zero to disable.");
110module_param(stall_cpu_holdoff, int, 0444);
111MODULE_PARM_DESC(stall_cpu_holdoff, "Time to wait before starting stall (s).");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700112module_param(test_boost, int, 0444);
113MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
114module_param(test_boost_interval, int, 0444);
115MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds.");
116module_param(test_boost_duration, int, 0444);
117MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds.");
Josh Triplettd6ad6712007-03-06 01:42:13 -0800118module_param(torture_type, charp, 0444);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700119MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700120
121#define TORTURE_FLAG "-torture:"
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800122#define PRINTK_STRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700123 do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800124#define VERBOSE_PRINTK_STRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700125 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800126#define VERBOSE_PRINTK_ERRSTRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700127 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800128
129static char printk_buf[4096];
130
131static int nrealreaders;
132static struct task_struct *writer_task;
Josh Triplettb772e1d2006-10-04 02:17:13 -0700133static struct task_struct **fakewriter_tasks;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800134static struct task_struct **reader_tasks;
135static struct task_struct *stats_task;
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800136static struct task_struct *shuffler_task;
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700137static struct task_struct *stutter_task;
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800138static struct task_struct *fqs_task;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700139static struct task_struct *boost_tasks[NR_CPUS];
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700140static struct task_struct *shutdown_task;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -0800141#ifdef CONFIG_HOTPLUG_CPU
142static struct task_struct *onoff_task;
143#endif /* #ifdef CONFIG_HOTPLUG_CPU */
Paul E. McKenneyc13f3752012-01-20 15:36:33 -0800144static struct task_struct *stall_task;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800145static struct task_struct **barrier_cbs_tasks;
146static struct task_struct *barrier_task;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800147
148#define RCU_TORTURE_PIPE_LEN 10
149
150struct rcu_torture {
151 struct rcu_head rtort_rcu;
152 int rtort_pipe_count;
153 struct list_head rtort_free;
Paul E. McKenney996417d2005-11-18 01:10:50 -0800154 int rtort_mbtest;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800155};
156
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800157static LIST_HEAD(rcu_torture_freelist);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700158static struct rcu_torture __rcu *rcu_torture_current;
Paul E. McKenney4a298652011-04-03 21:33:51 -0700159static unsigned long rcu_torture_current_version;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800160static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
161static DEFINE_SPINLOCK(rcu_torture_lock);
162static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
163 { 0 };
164static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
165 { 0 };
166static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700167static atomic_t n_rcu_torture_alloc;
168static atomic_t n_rcu_torture_alloc_fail;
169static atomic_t n_rcu_torture_free;
170static atomic_t n_rcu_torture_mberror;
171static atomic_t n_rcu_torture_error;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800172static long n_rcu_torture_barrier_error;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700173static long n_rcu_torture_boost_ktrerror;
174static long n_rcu_torture_boost_rterror;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700175static long n_rcu_torture_boost_failure;
176static long n_rcu_torture_boosts;
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700177static long n_rcu_torture_timers;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -0800178static long n_offline_attempts;
179static long n_offline_successes;
180static long n_online_attempts;
181static long n_online_successes;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800182static long n_barrier_attempts;
183static long n_barrier_successes;
Josh Triplette3033732006-10-04 02:17:14 -0700184static struct list_head rcu_torture_removed;
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600185static cpumask_var_t shuffle_tmp_mask;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800186
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700187static int stutter_pause_test;
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700188
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700189#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
190#define RCUTORTURE_RUNNABLE_INIT 1
191#else
192#define RCUTORTURE_RUNNABLE_INIT 0
193#endif
194int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
Paul E. McKenneybb3bf702011-11-04 13:24:07 -0700195module_param(rcutorture_runnable, int, 0444);
196MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot");
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700197
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700198#if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700199#define rcu_can_boost() 1
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700200#else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700201#define rcu_can_boost() 0
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700202#endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700203
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700204static unsigned long shutdown_time; /* jiffies to system shutdown. */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700205static unsigned long boost_starttime; /* jiffies of next boost test start. */
206DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
207 /* and boost task create/destroy. */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800208static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -0700209static bool barrier_phase; /* Test phase. */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800210static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */
211static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */
212static DECLARE_WAIT_QUEUE_HEAD(barrier_wq);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700213
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800214/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
215
216#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
217#define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
218#define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
219static int fullstop = FULLSTOP_RMMOD;
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700220/*
221 * Protect fullstop transitions and spawning of kthreads.
222 */
223static DEFINE_MUTEX(fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800224
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700225/* Forward reference. */
226static void rcu_torture_cleanup(void);
227
Paul E. McKenney343e9092008-12-15 16:13:07 -0800228/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800229 * Detect and respond to a system shutdown.
Paul E. McKenney343e9092008-12-15 16:13:07 -0800230 */
231static int
232rcutorture_shutdown_notify(struct notifier_block *unused1,
233 unsigned long unused2, void *unused3)
234{
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800235 mutex_lock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800236 if (fullstop == FULLSTOP_DONTSTOP)
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800237 fullstop = FULLSTOP_SHUTDOWN;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800238 else
239 printk(KERN_WARNING /* but going down anyway, so... */
240 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800241 mutex_unlock(&fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800242 return NOTIFY_DONE;
243}
244
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800245/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800246 * Absorb kthreads into a kernel function that won't return, so that
247 * they won't ever access module text or data again.
248 */
249static void rcutorture_shutdown_absorb(char *title)
250{
251 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
252 printk(KERN_NOTICE
253 "rcutorture thread %s parking due to system shutdown\n",
254 title);
255 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
256 }
257}
258
259/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800260 * Allocate an element from the rcu_tortures pool.
261 */
Adrian Bunk97a41e22006-01-08 01:02:17 -0800262static struct rcu_torture *
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800263rcu_torture_alloc(void)
264{
265 struct list_head *p;
266
Ingo Molnaradac1662006-01-25 19:50:12 +0100267 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800268 if (list_empty(&rcu_torture_freelist)) {
269 atomic_inc(&n_rcu_torture_alloc_fail);
Ingo Molnaradac1662006-01-25 19:50:12 +0100270 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800271 return NULL;
272 }
273 atomic_inc(&n_rcu_torture_alloc);
274 p = rcu_torture_freelist.next;
275 list_del_init(p);
Ingo Molnaradac1662006-01-25 19:50:12 +0100276 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800277 return container_of(p, struct rcu_torture, rtort_free);
278}
279
280/*
281 * Free an element to the rcu_tortures pool.
282 */
283static void
284rcu_torture_free(struct rcu_torture *p)
285{
286 atomic_inc(&n_rcu_torture_free);
Ingo Molnaradac1662006-01-25 19:50:12 +0100287 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800288 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
Ingo Molnaradac1662006-01-25 19:50:12 +0100289 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800290}
291
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800292struct rcu_random_state {
293 unsigned long rrs_state;
Josh Triplett75cfef32006-10-04 02:17:12 -0700294 long rrs_count;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800295};
296
297#define RCU_RANDOM_MULT 39916801 /* prime */
298#define RCU_RANDOM_ADD 479001701 /* prime */
299#define RCU_RANDOM_REFRESH 10000
300
301#define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
302
303/*
304 * Crude but fast random-number generator. Uses a linear congruential
Paul E. McKenneyc17ac852007-10-16 23:27:19 -0700305 * generator, with occasional help from cpu_clock().
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800306 */
Josh Triplett75cfef32006-10-04 02:17:12 -0700307static unsigned long
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800308rcu_random(struct rcu_random_state *rrsp)
309{
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800310 if (--rrsp->rrs_count < 0) {
Peter Zijlstrac6763292010-05-25 10:48:51 +0200311 rrsp->rrs_state += (unsigned long)local_clock();
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800312 rrsp->rrs_count = RCU_RANDOM_REFRESH;
313 }
314 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
315 return swahw32(rrsp->rrs_state);
316}
317
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700318static void
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800319rcu_stutter_wait(char *title)
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700320{
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800321 while (stutter_pause_test || !rcutorture_runnable) {
Paul E. McKenneye3d7be22008-06-22 13:06:38 -0700322 if (rcutorture_runnable)
323 schedule_timeout_interruptible(1);
324 else
Paul E. McKenney3ccf79f2008-06-22 14:02:55 -0700325 schedule_timeout_interruptible(round_jiffies_relative(HZ));
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800326 rcutorture_shutdown_absorb(title);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800327 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700328}
329
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800330/*
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700331 * Operations vector for selecting different types of tests.
332 */
333
334struct rcu_torture_ops {
335 void (*init)(void);
336 void (*cleanup)(void);
337 int (*readlock)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700338 void (*read_delay)(struct rcu_random_state *rrsp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700339 void (*readunlock)(int idx);
340 int (*completed)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700341 void (*deferred_free)(struct rcu_torture *p);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700342 void (*sync)(void);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800343 void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu));
Paul E. McKenney23269742008-05-12 21:21:05 +0200344 void (*cb_barrier)(void);
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800345 void (*fqs)(void);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700346 int (*stats)(char *page);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700347 int irq_capable;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700348 int can_boost;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700349 char *name;
350};
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700351
352static struct rcu_torture_ops *cur_ops;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700353
354/*
355 * Definitions for rcu torture testing.
356 */
357
Josh Tripletta49a4af2006-09-29 01:59:30 -0700358static int rcu_torture_read_lock(void) __acquires(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700359{
360 rcu_read_lock();
361 return 0;
362}
363
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700364static void rcu_read_delay(struct rcu_random_state *rrsp)
365{
Josh Triplettb8d57a72009-09-08 15:54:35 -0700366 const unsigned long shortdelay_us = 200;
367 const unsigned long longdelay_ms = 50;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700368
Josh Triplettb8d57a72009-09-08 15:54:35 -0700369 /* We want a short delay sometimes to make a reader delay the grace
370 * period, and we want a long delay occasionally to trigger
371 * force_quiescent_state. */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700372
Josh Triplettb8d57a72009-09-08 15:54:35 -0700373 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
374 mdelay(longdelay_ms);
375 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
376 udelay(shortdelay_us);
Lai Jiangshane546f482010-06-21 16:57:42 +0800377#ifdef CONFIG_PREEMPT
378 if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000)))
379 preempt_schedule(); /* No QS if preempt_disable() in effect */
380#endif
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700381}
382
Josh Tripletta49a4af2006-09-29 01:59:30 -0700383static void rcu_torture_read_unlock(int idx) __releases(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700384{
385 rcu_read_unlock();
386}
387
388static int rcu_torture_completed(void)
389{
390 return rcu_batches_completed();
391}
392
393static void
394rcu_torture_cb(struct rcu_head *p)
395{
396 int i;
397 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
398
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800399 if (fullstop != FULLSTOP_DONTSTOP) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700400 /* Test is ending, just drop callbacks on the floor. */
401 /* The next initialization will pick up the pieces. */
402 return;
403 }
404 i = rp->rtort_pipe_count;
405 if (i > RCU_TORTURE_PIPE_LEN)
406 i = RCU_TORTURE_PIPE_LEN;
407 atomic_inc(&rcu_torture_wcount[i]);
408 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
409 rp->rtort_mbtest = 0;
410 rcu_torture_free(rp);
411 } else
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700412 cur_ops->deferred_free(rp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700413}
414
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800415static int rcu_no_completed(void)
416{
417 return 0;
418}
419
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700420static void rcu_torture_deferred_free(struct rcu_torture *p)
421{
422 call_rcu(&p->rtort_rcu, rcu_torture_cb);
423}
424
425static struct rcu_torture_ops rcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700426 .init = NULL,
427 .cleanup = NULL,
428 .readlock = rcu_torture_read_lock,
429 .read_delay = rcu_read_delay,
430 .readunlock = rcu_torture_read_unlock,
431 .completed = rcu_torture_completed,
432 .deferred_free = rcu_torture_deferred_free,
433 .sync = synchronize_rcu,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800434 .call = call_rcu,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700435 .cb_barrier = rcu_barrier,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800436 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700437 .stats = NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700438 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700439 .can_boost = rcu_can_boost(),
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700440 .name = "rcu"
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700441};
442
Josh Triplette3033732006-10-04 02:17:14 -0700443static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
444{
445 int i;
446 struct rcu_torture *rp;
447 struct rcu_torture *rp1;
448
449 cur_ops->sync();
450 list_add(&p->rtort_free, &rcu_torture_removed);
451 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
452 i = rp->rtort_pipe_count;
453 if (i > RCU_TORTURE_PIPE_LEN)
454 i = RCU_TORTURE_PIPE_LEN;
455 atomic_inc(&rcu_torture_wcount[i]);
456 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
457 rp->rtort_mbtest = 0;
458 list_del(&rp->rtort_free);
459 rcu_torture_free(rp);
460 }
461 }
462}
463
464static void rcu_sync_torture_init(void)
465{
466 INIT_LIST_HEAD(&rcu_torture_removed);
467}
468
Josh Triplett20d2e422006-10-04 02:17:15 -0700469static struct rcu_torture_ops rcu_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700470 .init = rcu_sync_torture_init,
471 .cleanup = NULL,
472 .readlock = rcu_torture_read_lock,
473 .read_delay = rcu_read_delay,
474 .readunlock = rcu_torture_read_unlock,
475 .completed = rcu_torture_completed,
476 .deferred_free = rcu_sync_torture_deferred_free,
477 .sync = synchronize_rcu,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800478 .call = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700479 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800480 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700481 .stats = NULL,
482 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700483 .can_boost = rcu_can_boost(),
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700484 .name = "rcu_sync"
Josh Triplett20d2e422006-10-04 02:17:15 -0700485};
486
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800487static struct rcu_torture_ops rcu_expedited_ops = {
488 .init = rcu_sync_torture_init,
489 .cleanup = NULL,
490 .readlock = rcu_torture_read_lock,
491 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
492 .readunlock = rcu_torture_read_unlock,
493 .completed = rcu_no_completed,
494 .deferred_free = rcu_sync_torture_deferred_free,
495 .sync = synchronize_rcu_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800496 .call = NULL,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800497 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800498 .fqs = rcu_force_quiescent_state,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800499 .stats = NULL,
500 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700501 .can_boost = rcu_can_boost(),
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800502 .name = "rcu_expedited"
503};
504
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700505/*
506 * Definitions for rcu_bh torture testing.
507 */
508
Josh Tripletta49a4af2006-09-29 01:59:30 -0700509static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700510{
511 rcu_read_lock_bh();
512 return 0;
513}
514
Josh Tripletta49a4af2006-09-29 01:59:30 -0700515static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700516{
517 rcu_read_unlock_bh();
518}
519
520static int rcu_bh_torture_completed(void)
521{
522 return rcu_batches_completed_bh();
523}
524
525static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
526{
527 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
528}
529
530static struct rcu_torture_ops rcu_bh_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700531 .init = NULL,
532 .cleanup = NULL,
533 .readlock = rcu_bh_torture_read_lock,
534 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
535 .readunlock = rcu_bh_torture_read_unlock,
536 .completed = rcu_bh_torture_completed,
537 .deferred_free = rcu_bh_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700538 .sync = synchronize_rcu_bh,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800539 .call = call_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700540 .cb_barrier = rcu_barrier_bh,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800541 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700542 .stats = NULL,
543 .irq_capable = 1,
544 .name = "rcu_bh"
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700545};
546
Josh Triplett11a14702006-10-04 02:17:16 -0700547static struct rcu_torture_ops rcu_bh_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700548 .init = rcu_sync_torture_init,
549 .cleanup = NULL,
550 .readlock = rcu_bh_torture_read_lock,
551 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
552 .readunlock = rcu_bh_torture_read_unlock,
553 .completed = rcu_bh_torture_completed,
554 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700555 .sync = synchronize_rcu_bh,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800556 .call = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700557 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800558 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700559 .stats = NULL,
560 .irq_capable = 1,
561 .name = "rcu_bh_sync"
Josh Triplett11a14702006-10-04 02:17:16 -0700562};
563
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700564static struct rcu_torture_ops rcu_bh_expedited_ops = {
565 .init = rcu_sync_torture_init,
566 .cleanup = NULL,
567 .readlock = rcu_bh_torture_read_lock,
568 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
569 .readunlock = rcu_bh_torture_read_unlock,
570 .completed = rcu_bh_torture_completed,
571 .deferred_free = rcu_sync_torture_deferred_free,
572 .sync = synchronize_rcu_bh_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800573 .call = NULL,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700574 .cb_barrier = NULL,
575 .fqs = rcu_bh_force_quiescent_state,
576 .stats = NULL,
577 .irq_capable = 1,
578 .name = "rcu_bh_expedited"
579};
580
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700581/*
582 * Definitions for srcu torture testing.
583 */
584
585static struct srcu_struct srcu_ctl;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700586
587static void srcu_torture_init(void)
588{
589 init_srcu_struct(&srcu_ctl);
Josh Triplette3033732006-10-04 02:17:14 -0700590 rcu_sync_torture_init();
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700591}
592
593static void srcu_torture_cleanup(void)
594{
595 synchronize_srcu(&srcu_ctl);
596 cleanup_srcu_struct(&srcu_ctl);
597}
598
Josh Triplett012d3ca2006-12-06 20:40:19 -0800599static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700600{
601 return srcu_read_lock(&srcu_ctl);
602}
603
604static void srcu_read_delay(struct rcu_random_state *rrsp)
605{
606 long delay;
607 const long uspertick = 1000000 / HZ;
608 const long longdelay = 10;
609
610 /* We want there to be long-running readers, but not all the time. */
611
612 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
613 if (!delay)
614 schedule_timeout_interruptible(longdelay);
Lai Jiangshane546f482010-06-21 16:57:42 +0800615 else
616 rcu_read_delay(rrsp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700617}
618
Josh Triplett012d3ca2006-12-06 20:40:19 -0800619static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700620{
621 srcu_read_unlock(&srcu_ctl, idx);
622}
623
624static int srcu_torture_completed(void)
625{
626 return srcu_batches_completed(&srcu_ctl);
627}
628
Lai Jiangshan9059c942012-03-19 16:12:14 +0800629static void srcu_torture_deferred_free(struct rcu_torture *rp)
630{
631 call_srcu(&srcu_ctl, &rp->rtort_rcu, rcu_torture_cb);
632}
633
Josh Triplettb772e1d2006-10-04 02:17:13 -0700634static void srcu_torture_synchronize(void)
635{
636 synchronize_srcu(&srcu_ctl);
637}
638
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700639static void srcu_torture_call(struct rcu_head *head,
640 void (*func)(struct rcu_head *head))
641{
642 call_srcu(&srcu_ctl, head, func);
643}
644
645static void srcu_torture_barrier(void)
646{
647 srcu_barrier(&srcu_ctl);
648}
649
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700650static int srcu_torture_stats(char *page)
651{
652 int cnt = 0;
653 int cpu;
654 int idx = srcu_ctl.completed & 0x1;
655
656 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
657 torture_type, TORTURE_FLAG, idx);
658 for_each_possible_cpu(cpu) {
Paul E. McKenneycef50122012-02-05 07:42:44 -0800659 cnt += sprintf(&page[cnt], " %d(%lu,%lu)", cpu,
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700660 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
661 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
662 }
663 cnt += sprintf(&page[cnt], "\n");
664 return cnt;
665}
666
667static struct rcu_torture_ops srcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700668 .init = srcu_torture_init,
669 .cleanup = srcu_torture_cleanup,
670 .readlock = srcu_torture_read_lock,
671 .read_delay = srcu_read_delay,
672 .readunlock = srcu_torture_read_unlock,
673 .completed = srcu_torture_completed,
Lai Jiangshan9059c942012-03-19 16:12:14 +0800674 .deferred_free = srcu_torture_deferred_free,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700675 .sync = srcu_torture_synchronize,
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700676 .call = srcu_torture_call,
677 .cb_barrier = srcu_torture_barrier,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700678 .stats = srcu_torture_stats,
679 .name = "srcu"
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700680};
681
Lai Jiangshan9059c942012-03-19 16:12:14 +0800682static struct rcu_torture_ops srcu_sync_ops = {
683 .init = srcu_torture_init,
684 .cleanup = srcu_torture_cleanup,
685 .readlock = srcu_torture_read_lock,
686 .read_delay = srcu_read_delay,
687 .readunlock = srcu_torture_read_unlock,
688 .completed = srcu_torture_completed,
689 .deferred_free = rcu_sync_torture_deferred_free,
690 .sync = srcu_torture_synchronize,
691 .call = NULL,
692 .cb_barrier = NULL,
693 .stats = srcu_torture_stats,
694 .name = "srcu_sync"
695};
696
Paul E. McKenney101db7b2011-12-05 15:36:31 -0800697static int srcu_torture_read_lock_raw(void) __acquires(&srcu_ctl)
698{
699 return srcu_read_lock_raw(&srcu_ctl);
700}
701
702static void srcu_torture_read_unlock_raw(int idx) __releases(&srcu_ctl)
703{
704 srcu_read_unlock_raw(&srcu_ctl, idx);
705}
706
707static struct rcu_torture_ops srcu_raw_ops = {
708 .init = srcu_torture_init,
709 .cleanup = srcu_torture_cleanup,
710 .readlock = srcu_torture_read_lock_raw,
711 .read_delay = srcu_read_delay,
712 .readunlock = srcu_torture_read_unlock_raw,
713 .completed = srcu_torture_completed,
Lai Jiangshan9059c942012-03-19 16:12:14 +0800714 .deferred_free = srcu_torture_deferred_free,
Paul E. McKenney101db7b2011-12-05 15:36:31 -0800715 .sync = srcu_torture_synchronize,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800716 .call = NULL,
Paul E. McKenney101db7b2011-12-05 15:36:31 -0800717 .cb_barrier = NULL,
718 .stats = srcu_torture_stats,
719 .name = "srcu_raw"
720};
721
Lai Jiangshan9059c942012-03-19 16:12:14 +0800722static struct rcu_torture_ops srcu_raw_sync_ops = {
723 .init = srcu_torture_init,
724 .cleanup = srcu_torture_cleanup,
725 .readlock = srcu_torture_read_lock_raw,
726 .read_delay = srcu_read_delay,
727 .readunlock = srcu_torture_read_unlock_raw,
728 .completed = srcu_torture_completed,
729 .deferred_free = rcu_sync_torture_deferred_free,
730 .sync = srcu_torture_synchronize,
731 .call = NULL,
732 .cb_barrier = NULL,
733 .stats = srcu_torture_stats,
734 .name = "srcu_raw_sync"
735};
736
Paul E. McKenney804bb832009-10-25 19:03:52 -0700737static void srcu_torture_synchronize_expedited(void)
738{
739 synchronize_srcu_expedited(&srcu_ctl);
740}
741
742static struct rcu_torture_ops srcu_expedited_ops = {
743 .init = srcu_torture_init,
744 .cleanup = srcu_torture_cleanup,
745 .readlock = srcu_torture_read_lock,
746 .read_delay = srcu_read_delay,
747 .readunlock = srcu_torture_read_unlock,
748 .completed = srcu_torture_completed,
749 .deferred_free = rcu_sync_torture_deferred_free,
750 .sync = srcu_torture_synchronize_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800751 .call = NULL,
Paul E. McKenney804bb832009-10-25 19:03:52 -0700752 .cb_barrier = NULL,
753 .stats = srcu_torture_stats,
754 .name = "srcu_expedited"
755};
756
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700757/*
758 * Definitions for sched torture testing.
759 */
760
761static int sched_torture_read_lock(void)
762{
763 preempt_disable();
764 return 0;
765}
766
767static void sched_torture_read_unlock(int idx)
768{
769 preempt_enable();
770}
771
Paul E. McKenney23269742008-05-12 21:21:05 +0200772static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
773{
774 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
775}
776
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700777static struct rcu_torture_ops sched_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700778 .init = rcu_sync_torture_init,
779 .cleanup = NULL,
780 .readlock = sched_torture_read_lock,
781 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
782 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800783 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700784 .deferred_free = rcu_sched_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700785 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700786 .cb_barrier = rcu_barrier_sched,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800787 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700788 .stats = NULL,
789 .irq_capable = 1,
790 .name = "sched"
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700791};
792
Paul E. McKenney804bb832009-10-25 19:03:52 -0700793static struct rcu_torture_ops sched_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700794 .init = rcu_sync_torture_init,
795 .cleanup = NULL,
796 .readlock = sched_torture_read_lock,
797 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
798 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800799 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700800 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700801 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700802 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800803 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700804 .stats = NULL,
805 .name = "sched_sync"
806};
807
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700808static struct rcu_torture_ops sched_expedited_ops = {
809 .init = rcu_sync_torture_init,
810 .cleanup = NULL,
811 .readlock = sched_torture_read_lock,
812 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
813 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800814 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700815 .deferred_free = rcu_sync_torture_deferred_free,
816 .sync = synchronize_sched_expedited,
817 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800818 .fqs = rcu_sched_force_quiescent_state,
Tejun Heo969c7922010-05-06 18:49:21 +0200819 .stats = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700820 .irq_capable = 1,
821 .name = "sched_expedited"
Paul E. McKenney23269742008-05-12 21:21:05 +0200822};
823
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700824/*
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700825 * RCU torture priority-boost testing. Runs one real-time thread per
826 * CPU for moderate bursts, repeatedly registering RCU callbacks and
827 * spinning waiting for them to be invoked. If a given callback takes
828 * too long to be invoked, we assume that priority inversion has occurred.
829 */
830
831struct rcu_boost_inflight {
832 struct rcu_head rcu;
833 int inflight;
834};
835
836static void rcu_torture_boost_cb(struct rcu_head *head)
837{
838 struct rcu_boost_inflight *rbip =
839 container_of(head, struct rcu_boost_inflight, rcu);
840
841 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
842 rbip->inflight = 0;
843}
844
845static int rcu_torture_boost(void *arg)
846{
847 unsigned long call_rcu_time;
848 unsigned long endtime;
849 unsigned long oldstarttime;
850 struct rcu_boost_inflight rbi = { .inflight = 0 };
851 struct sched_param sp;
852
853 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
854
855 /* Set real-time priority. */
856 sp.sched_priority = 1;
857 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
858 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
859 n_rcu_torture_boost_rterror++;
860 }
861
Paul E. McKenney561190e2011-03-30 09:10:44 -0700862 init_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700863 /* Each pass through the following loop does one boost-test cycle. */
864 do {
865 /* Wait for the next test interval. */
866 oldstarttime = boost_starttime;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700867 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700868 schedule_timeout_uninterruptible(1);
869 rcu_stutter_wait("rcu_torture_boost");
870 if (kthread_should_stop() ||
871 fullstop != FULLSTOP_DONTSTOP)
872 goto checkwait;
873 }
874
875 /* Do one boost-test interval. */
876 endtime = oldstarttime + test_boost_duration * HZ;
877 call_rcu_time = jiffies;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700878 while (ULONG_CMP_LT(jiffies, endtime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700879 /* If we don't have a callback in flight, post one. */
880 if (!rbi.inflight) {
881 smp_mb(); /* RCU core before ->inflight = 1. */
882 rbi.inflight = 1;
883 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
884 if (jiffies - call_rcu_time >
885 test_boost_duration * HZ - HZ / 2) {
886 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
887 n_rcu_torture_boost_failure++;
888 }
889 call_rcu_time = jiffies;
890 }
891 cond_resched();
892 rcu_stutter_wait("rcu_torture_boost");
893 if (kthread_should_stop() ||
894 fullstop != FULLSTOP_DONTSTOP)
895 goto checkwait;
896 }
897
898 /*
899 * Set the start time of the next test interval.
900 * Yes, this is vulnerable to long delays, but such
901 * delays simply cause a false negative for the next
902 * interval. Besides, we are running at RT priority,
903 * so delays should be relatively rare.
904 */
Paul E. McKenneyab8f11e2011-08-18 09:30:32 -0700905 while (oldstarttime == boost_starttime &&
906 !kthread_should_stop()) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700907 if (mutex_trylock(&boost_mutex)) {
908 boost_starttime = jiffies +
909 test_boost_interval * HZ;
910 n_rcu_torture_boosts++;
911 mutex_unlock(&boost_mutex);
912 break;
913 }
914 schedule_timeout_uninterruptible(1);
915 }
916
917 /* Go do the stutter. */
918checkwait: rcu_stutter_wait("rcu_torture_boost");
919 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
920
921 /* Clean up and exit. */
922 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
923 rcutorture_shutdown_absorb("rcu_torture_boost");
924 while (!kthread_should_stop() || rbi.inflight)
925 schedule_timeout_uninterruptible(1);
926 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
Paul E. McKenney9d681972011-06-21 01:48:03 -0700927 destroy_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700928 return 0;
929}
930
931/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800932 * RCU torture force-quiescent-state kthread. Repeatedly induces
933 * bursts of calls to force_quiescent_state(), increasing the probability
934 * of occurrence of some important types of race conditions.
935 */
936static int
937rcu_torture_fqs(void *arg)
938{
939 unsigned long fqs_resume_time;
940 int fqs_burst_remaining;
941
942 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
943 do {
944 fqs_resume_time = jiffies + fqs_stutter * HZ;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700945 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
946 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800947 schedule_timeout_interruptible(1);
948 }
949 fqs_burst_remaining = fqs_duration;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700950 while (fqs_burst_remaining > 0 &&
951 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800952 cur_ops->fqs();
953 udelay(fqs_holdoff);
954 fqs_burst_remaining -= fqs_holdoff;
955 }
956 rcu_stutter_wait("rcu_torture_fqs");
957 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
958 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
959 rcutorture_shutdown_absorb("rcu_torture_fqs");
960 while (!kthread_should_stop())
961 schedule_timeout_uninterruptible(1);
962 return 0;
963}
964
965/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800966 * RCU torture writer kthread. Repeatedly substitutes a new structure
967 * for that pointed to by rcu_torture_current, freeing the old structure
968 * after a series of grace periods (the "pipeline").
969 */
970static int
971rcu_torture_writer(void *arg)
972{
973 int i;
974 long oldbatch = rcu_batches_completed();
975 struct rcu_torture *rp;
976 struct rcu_torture *old_rp;
977 static DEFINE_RCU_RANDOM(rand);
978
979 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800980 set_user_nice(current, 19);
981
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800982 do {
983 schedule_timeout_uninterruptible(1);
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700984 rp = rcu_torture_alloc();
985 if (rp == NULL)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800986 continue;
987 rp->rtort_pipe_count = 0;
988 udelay(rcu_random(&rand) & 0x3ff);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700989 old_rp = rcu_dereference_check(rcu_torture_current,
990 current == writer_task);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800991 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800992 rcu_assign_pointer(rcu_torture_current, rp);
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700993 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
Josh Triplettc8e5b162007-05-08 00:33:20 -0700994 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800995 i = old_rp->rtort_pipe_count;
996 if (i > RCU_TORTURE_PIPE_LEN)
997 i = RCU_TORTURE_PIPE_LEN;
998 atomic_inc(&rcu_torture_wcount[i]);
999 old_rp->rtort_pipe_count++;
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001000 cur_ops->deferred_free(old_rp);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001001 }
Paul E. McKenney4a298652011-04-03 21:33:51 -07001002 rcutorture_record_progress(++rcu_torture_current_version);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001003 oldbatch = cur_ops->completed();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001004 rcu_stutter_wait("rcu_torture_writer");
1005 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001006 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001007 rcutorture_shutdown_absorb("rcu_torture_writer");
1008 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001009 schedule_timeout_uninterruptible(1);
1010 return 0;
1011}
1012
1013/*
Josh Triplettb772e1d2006-10-04 02:17:13 -07001014 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
1015 * delay between calls.
1016 */
1017static int
1018rcu_torture_fakewriter(void *arg)
1019{
1020 DEFINE_RCU_RANDOM(rand);
1021
1022 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
1023 set_user_nice(current, 19);
1024
1025 do {
1026 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
1027 udelay(rcu_random(&rand) & 0x3ff);
1028 cur_ops->sync();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001029 rcu_stutter_wait("rcu_torture_fakewriter");
1030 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001031
1032 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001033 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
1034 while (!kthread_should_stop())
Josh Triplettb772e1d2006-10-04 02:17:13 -07001035 schedule_timeout_uninterruptible(1);
1036 return 0;
1037}
1038
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001039void rcutorture_trace_dump(void)
1040{
1041 static atomic_t beenhere = ATOMIC_INIT(0);
1042
1043 if (atomic_read(&beenhere))
1044 return;
1045 if (atomic_xchg(&beenhere, 1) != 0)
1046 return;
1047 do_trace_rcu_torture_read(cur_ops->name, (struct rcu_head *)~0UL);
1048 ftrace_dump(DUMP_ALL);
1049}
1050
Josh Triplettb772e1d2006-10-04 02:17:13 -07001051/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001052 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
1053 * incrementing the corresponding element of the pipeline array. The
1054 * counter in the element should never be greater than 1, otherwise, the
1055 * RCU implementation is broken.
1056 */
1057static void rcu_torture_timer(unsigned long unused)
1058{
1059 int idx;
1060 int completed;
1061 static DEFINE_RCU_RANDOM(rand);
1062 static DEFINE_SPINLOCK(rand_lock);
1063 struct rcu_torture *p;
1064 int pipe_count;
1065
1066 idx = cur_ops->readlock();
1067 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001068 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001069 rcu_read_lock_bh_held() ||
1070 rcu_read_lock_sched_held() ||
1071 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001072 if (p == NULL) {
1073 /* Leave because rcu_torture_writer is not yet underway */
1074 cur_ops->readunlock(idx);
1075 return;
1076 }
Paul E. McKenney7129d382012-01-31 16:46:34 -08001077 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001078 if (p->rtort_mbtest == 0)
1079 atomic_inc(&n_rcu_torture_mberror);
1080 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001081 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001082 n_rcu_torture_timers++;
1083 spin_unlock(&rand_lock);
1084 preempt_disable();
1085 pipe_count = p->rtort_pipe_count;
1086 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1087 /* Should not happen, but... */
1088 pipe_count = RCU_TORTURE_PIPE_LEN;
1089 }
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001090 if (pipe_count > 1)
1091 rcutorture_trace_dump();
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001092 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001093 completed = cur_ops->completed() - completed;
1094 if (completed > RCU_TORTURE_PIPE_LEN) {
1095 /* Should not happen, but... */
1096 completed = RCU_TORTURE_PIPE_LEN;
1097 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001098 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001099 preempt_enable();
1100 cur_ops->readunlock(idx);
1101}
1102
1103/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001104 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
1105 * incrementing the corresponding element of the pipeline array. The
1106 * counter in the element should never be greater than 1, otherwise, the
1107 * RCU implementation is broken.
1108 */
1109static int
1110rcu_torture_reader(void *arg)
1111{
1112 int completed;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001113 int idx;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001114 DEFINE_RCU_RANDOM(rand);
1115 struct rcu_torture *p;
1116 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001117 struct timer_list t;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001118
1119 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001120 set_user_nice(current, 19);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001121 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001122 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001123
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001124 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001125 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001126 if (!timer_pending(&t))
Paul E. McKenney6155fec2010-02-22 17:05:04 -08001127 mod_timer(&t, jiffies + 1);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001128 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001129 idx = cur_ops->readlock();
1130 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001131 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001132 rcu_read_lock_bh_held() ||
1133 rcu_read_lock_sched_held() ||
1134 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001135 if (p == NULL) {
1136 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001137 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001138 schedule_timeout_interruptible(HZ);
1139 continue;
1140 }
Paul E. McKenney7129d382012-01-31 16:46:34 -08001141 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001142 if (p->rtort_mbtest == 0)
1143 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001144 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001145 preempt_disable();
1146 pipe_count = p->rtort_pipe_count;
1147 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1148 /* Should not happen, but... */
1149 pipe_count = RCU_TORTURE_PIPE_LEN;
1150 }
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001151 if (pipe_count > 1)
1152 rcutorture_trace_dump();
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001153 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001154 completed = cur_ops->completed() - completed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001155 if (completed > RCU_TORTURE_PIPE_LEN) {
1156 /* Should not happen, but... */
1157 completed = RCU_TORTURE_PIPE_LEN;
1158 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001159 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001160 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001161 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001162 schedule();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001163 rcu_stutter_wait("rcu_torture_reader");
1164 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001165 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001166 rcutorture_shutdown_absorb("rcu_torture_reader");
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001167 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001168 del_timer_sync(&t);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001169 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001170 schedule_timeout_uninterruptible(1);
1171 return 0;
1172}
1173
1174/*
1175 * Create an RCU-torture statistics message in the specified buffer.
1176 */
1177static int
1178rcu_torture_printk(char *page)
1179{
1180 int cnt = 0;
1181 int cpu;
1182 int i;
1183 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1184 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1185
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001186 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001187 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1188 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1189 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1190 }
1191 }
1192 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1193 if (pipesummary[i] != 0)
1194 break;
1195 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001196 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001197 cnt += sprintf(&page[cnt],
Paul E. McKenney4a298652011-04-03 21:33:51 -07001198 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d "
Paul E. McKenney67b98db2011-02-21 13:31:55 -08001199 "rtmbe: %d rtbke: %ld rtbre: %ld "
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001200 "rtbf: %ld rtb: %ld nt: %ld "
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001201 "onoff: %ld/%ld:%ld/%ld "
1202 "barrier: %ld/%ld:%ld",
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001203 rcu_torture_current,
1204 rcu_torture_current_version,
1205 list_empty(&rcu_torture_freelist),
1206 atomic_read(&n_rcu_torture_alloc),
1207 atomic_read(&n_rcu_torture_alloc_fail),
Paul E. McKenney996417d2005-11-18 01:10:50 -08001208 atomic_read(&n_rcu_torture_free),
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001209 atomic_read(&n_rcu_torture_mberror),
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001210 n_rcu_torture_boost_ktrerror,
1211 n_rcu_torture_boost_rterror,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001212 n_rcu_torture_boost_failure,
1213 n_rcu_torture_boosts,
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001214 n_rcu_torture_timers,
1215 n_online_successes,
1216 n_online_attempts,
1217 n_offline_successes,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001218 n_offline_attempts,
1219 n_barrier_successes,
1220 n_barrier_attempts,
1221 n_rcu_torture_barrier_error);
1222 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001223 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001224 n_rcu_torture_barrier_error != 0 ||
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001225 n_rcu_torture_boost_ktrerror != 0 ||
1226 n_rcu_torture_boost_rterror != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001227 n_rcu_torture_boost_failure != 0 ||
1228 i > 1) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001229 cnt += sprintf(&page[cnt], "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -08001230 atomic_inc(&n_rcu_torture_error);
Ingo Molnar5af970a2008-06-18 10:09:48 +02001231 WARN_ON_ONCE(1);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001232 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001233 cnt += sprintf(&page[cnt], "Reader Pipe: ");
1234 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1235 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001236 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001237 cnt += sprintf(&page[cnt], "Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001238 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001239 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001240 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001241 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
1242 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1243 cnt += sprintf(&page[cnt], " %d",
1244 atomic_read(&rcu_torture_wcount[i]));
1245 }
1246 cnt += sprintf(&page[cnt], "\n");
Josh Triplettc8e5b162007-05-08 00:33:20 -07001247 if (cur_ops->stats)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001248 cnt += cur_ops->stats(&page[cnt]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001249 return cnt;
1250}
1251
1252/*
1253 * Print torture statistics. Caller must ensure that there is only
1254 * one call to this function at a given time!!! This is normally
1255 * accomplished by relying on the module system to only have one copy
1256 * of the module loaded, and then by giving the rcu_torture_stats
1257 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1258 * thread is not running).
1259 */
1260static void
1261rcu_torture_stats_print(void)
1262{
1263 int cnt;
1264
1265 cnt = rcu_torture_printk(printk_buf);
1266 printk(KERN_ALERT "%s", printk_buf);
1267}
1268
1269/*
1270 * Periodically prints torture statistics, if periodic statistics printing
1271 * was specified via the stat_interval module parameter.
1272 *
1273 * No need to worry about fullstop here, since this one doesn't reference
1274 * volatile state or register callbacks.
1275 */
1276static int
1277rcu_torture_stats(void *arg)
1278{
1279 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1280 do {
1281 schedule_timeout_interruptible(stat_interval * HZ);
1282 rcu_torture_stats_print();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001283 rcutorture_shutdown_absorb("rcu_torture_stats");
1284 } while (!kthread_should_stop());
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001285 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1286 return 0;
1287}
1288
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001289static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
1290
1291/* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1292 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1293 */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -07001294static void rcu_torture_shuffle_tasks(void)
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001295{
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001296 int i;
1297
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001298 cpumask_setall(shuffle_tmp_mask);
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001299 get_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001300
1301 /* No point in shuffling if there is only one online CPU (ex: UP) */
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001302 if (num_online_cpus() == 1) {
1303 put_online_cpus();
1304 return;
1305 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001306
1307 if (rcu_idle_cpu != -1)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001308 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001309
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001310 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001311
Josh Triplettc8e5b162007-05-08 00:33:20 -07001312 if (reader_tasks) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001313 for (i = 0; i < nrealreaders; i++)
1314 if (reader_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001315 set_cpus_allowed_ptr(reader_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001316 shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001317 }
1318
Josh Triplettc8e5b162007-05-08 00:33:20 -07001319 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001320 for (i = 0; i < nfakewriters; i++)
1321 if (fakewriter_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001322 set_cpus_allowed_ptr(fakewriter_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001323 shuffle_tmp_mask);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001324 }
1325
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001326 if (writer_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001327 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001328
1329 if (stats_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001330 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001331
1332 if (rcu_idle_cpu == -1)
1333 rcu_idle_cpu = num_online_cpus() - 1;
1334 else
1335 rcu_idle_cpu--;
1336
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001337 put_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001338}
1339
1340/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1341 * system to become idle at a time and cut off its timer ticks. This is meant
1342 * to test the support for such tickless idle CPU in RCU.
1343 */
1344static int
1345rcu_torture_shuffle(void *arg)
1346{
1347 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1348 do {
1349 schedule_timeout_interruptible(shuffle_interval * HZ);
1350 rcu_torture_shuffle_tasks();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001351 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1352 } while (!kthread_should_stop());
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001353 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1354 return 0;
1355}
1356
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001357/* Cause the rcutorture test to "stutter", starting and stopping all
1358 * threads periodically.
1359 */
1360static int
1361rcu_torture_stutter(void *arg)
1362{
1363 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1364 do {
1365 schedule_timeout_interruptible(stutter * HZ);
1366 stutter_pause_test = 1;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001367 if (!kthread_should_stop())
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001368 schedule_timeout_interruptible(stutter * HZ);
1369 stutter_pause_test = 0;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001370 rcutorture_shutdown_absorb("rcu_torture_stutter");
1371 } while (!kthread_should_stop());
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001372 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1373 return 0;
1374}
1375
Paul E. McKenney95c38322006-03-24 03:15:58 -08001376static inline void
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001377rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
Paul E. McKenney95c38322006-03-24 03:15:58 -08001378{
Josh Triplettb772e1d2006-10-04 02:17:13 -07001379 printk(KERN_ALERT "%s" TORTURE_FLAG
1380 "--- %s: nreaders=%d nfakewriters=%d "
Paul E. McKenney95c38322006-03-24 03:15:58 -08001381 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001382 "shuffle_interval=%d stutter=%d irqreader=%d "
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001383 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1384 "test_boost=%d/%d test_boost_interval=%d "
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001385 "test_boost_duration=%d shutdown_secs=%d "
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -08001386 "onoff_interval=%d onoff_holdoff=%d\n",
Josh Triplettb772e1d2006-10-04 02:17:13 -07001387 torture_type, tag, nrealreaders, nfakewriters,
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001388 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001389 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1390 test_boost, cur_ops->can_boost,
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001391 test_boost_interval, test_boost_duration, shutdown_secs,
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -08001392 onoff_interval, onoff_holdoff);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001393}
1394
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001395static struct notifier_block rcutorture_shutdown_nb = {
Paul E. McKenney343e9092008-12-15 16:13:07 -08001396 .notifier_call = rcutorture_shutdown_notify,
1397};
1398
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001399static void rcutorture_booster_cleanup(int cpu)
1400{
1401 struct task_struct *t;
1402
1403 if (boost_tasks[cpu] == NULL)
1404 return;
1405 mutex_lock(&boost_mutex);
1406 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1407 t = boost_tasks[cpu];
1408 boost_tasks[cpu] = NULL;
1409 mutex_unlock(&boost_mutex);
1410
1411 /* This must be outside of the mutex, otherwise deadlock! */
1412 kthread_stop(t);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001413 boost_tasks[cpu] = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001414}
1415
1416static int rcutorture_booster_init(int cpu)
1417{
1418 int retval;
1419
1420 if (boost_tasks[cpu] != NULL)
1421 return 0; /* Already created, nothing more to do. */
1422
1423 /* Don't allow time recalculation while creating a new task. */
1424 mutex_lock(&boost_mutex);
1425 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
Eric Dumazet1f288092011-06-16 15:53:18 -07001426 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1427 cpu_to_node(cpu),
1428 "rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001429 if (IS_ERR(boost_tasks[cpu])) {
1430 retval = PTR_ERR(boost_tasks[cpu]);
1431 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1432 n_rcu_torture_boost_ktrerror++;
1433 boost_tasks[cpu] = NULL;
1434 mutex_unlock(&boost_mutex);
1435 return retval;
1436 }
1437 kthread_bind(boost_tasks[cpu], cpu);
1438 wake_up_process(boost_tasks[cpu]);
1439 mutex_unlock(&boost_mutex);
1440 return 0;
1441}
1442
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001443/*
1444 * Cause the rcutorture test to shutdown the system after the test has
1445 * run for the time specified by the shutdown_secs module parameter.
1446 */
1447static int
1448rcu_torture_shutdown(void *arg)
1449{
1450 long delta;
1451 unsigned long jiffies_snap;
1452
1453 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1454 jiffies_snap = ACCESS_ONCE(jiffies);
1455 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
1456 !kthread_should_stop()) {
1457 delta = shutdown_time - jiffies_snap;
1458 if (verbose)
1459 printk(KERN_ALERT "%s" TORTURE_FLAG
1460 "rcu_torture_shutdown task: %lu "
1461 "jiffies remaining\n",
1462 torture_type, delta);
1463 schedule_timeout_interruptible(delta);
1464 jiffies_snap = ACCESS_ONCE(jiffies);
1465 }
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001466 if (kthread_should_stop()) {
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001467 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1468 return 0;
1469 }
1470
1471 /* OK, shut down the system. */
1472
1473 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1474 shutdown_task = NULL; /* Avoid self-kill deadlock. */
1475 rcu_torture_cleanup(); /* Get the success/failure message. */
1476 kernel_power_off(); /* Shut down the system. */
1477 return 0;
1478}
1479
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001480#ifdef CONFIG_HOTPLUG_CPU
1481
1482/*
1483 * Execute random CPU-hotplug operations at the interval specified
1484 * by the onoff_interval.
1485 */
Heiko Carstens44100302011-12-27 15:04:26 +01001486static int __cpuinit
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001487rcu_torture_onoff(void *arg)
1488{
1489 int cpu;
1490 int maxcpu = -1;
1491 DEFINE_RCU_RANDOM(rand);
1492
1493 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1494 for_each_online_cpu(cpu)
1495 maxcpu = cpu;
1496 WARN_ON(maxcpu < 0);
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -08001497 if (onoff_holdoff > 0) {
1498 VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff");
1499 schedule_timeout_interruptible(onoff_holdoff * HZ);
1500 VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff");
1501 }
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001502 while (!kthread_should_stop()) {
1503 cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
Paul E. McKenneyf2202422011-12-03 15:09:28 -08001504 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001505 if (verbose)
1506 printk(KERN_ALERT "%s" TORTURE_FLAG
1507 "rcu_torture_onoff task: offlining %d\n",
1508 torture_type, cpu);
1509 n_offline_attempts++;
1510 if (cpu_down(cpu) == 0) {
1511 if (verbose)
1512 printk(KERN_ALERT "%s" TORTURE_FLAG
1513 "rcu_torture_onoff task: "
1514 "offlined %d\n",
1515 torture_type, cpu);
1516 n_offline_successes++;
1517 }
Paul E. McKenneyf2202422011-12-03 15:09:28 -08001518 } else if (cpu_is_hotpluggable(cpu)) {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001519 if (verbose)
1520 printk(KERN_ALERT "%s" TORTURE_FLAG
1521 "rcu_torture_onoff task: onlining %d\n",
1522 torture_type, cpu);
1523 n_online_attempts++;
1524 if (cpu_up(cpu) == 0) {
1525 if (verbose)
1526 printk(KERN_ALERT "%s" TORTURE_FLAG
1527 "rcu_torture_onoff task: "
1528 "onlined %d\n",
1529 torture_type, cpu);
1530 n_online_successes++;
1531 }
1532 }
1533 schedule_timeout_interruptible(onoff_interval * HZ);
1534 }
1535 VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1536 return 0;
1537}
1538
Heiko Carstens44100302011-12-27 15:04:26 +01001539static int __cpuinit
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001540rcu_torture_onoff_init(void)
1541{
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001542 int ret;
1543
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001544 if (onoff_interval <= 0)
1545 return 0;
1546 onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff");
1547 if (IS_ERR(onoff_task)) {
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001548 ret = PTR_ERR(onoff_task);
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001549 onoff_task = NULL;
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001550 return ret;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001551 }
1552 return 0;
1553}
1554
1555static void rcu_torture_onoff_cleanup(void)
1556{
1557 if (onoff_task == NULL)
1558 return;
1559 VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1560 kthread_stop(onoff_task);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001561 onoff_task = NULL;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001562}
1563
1564#else /* #ifdef CONFIG_HOTPLUG_CPU */
1565
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001566static int
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001567rcu_torture_onoff_init(void)
1568{
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001569 return 0;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001570}
1571
1572static void rcu_torture_onoff_cleanup(void)
1573{
1574}
1575
1576#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1577
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001578/*
1579 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1580 * induces a CPU stall for the time specified by stall_cpu.
1581 */
1582static int __cpuinit rcu_torture_stall(void *args)
1583{
1584 unsigned long stop_at;
1585
1586 VERBOSE_PRINTK_STRING("rcu_torture_stall task started");
1587 if (stall_cpu_holdoff > 0) {
1588 VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff");
1589 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
1590 VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff");
1591 }
1592 if (!kthread_should_stop()) {
1593 stop_at = get_seconds() + stall_cpu;
1594 /* RCU CPU stall is expected behavior in following code. */
1595 printk(KERN_ALERT "rcu_torture_stall start.\n");
1596 rcu_read_lock();
1597 preempt_disable();
1598 while (ULONG_CMP_LT(get_seconds(), stop_at))
1599 continue; /* Induce RCU CPU stall warning. */
1600 preempt_enable();
1601 rcu_read_unlock();
1602 printk(KERN_ALERT "rcu_torture_stall end.\n");
1603 }
1604 rcutorture_shutdown_absorb("rcu_torture_stall");
1605 while (!kthread_should_stop())
1606 schedule_timeout_interruptible(10 * HZ);
1607 return 0;
1608}
1609
1610/* Spawn CPU-stall kthread, if stall_cpu specified. */
1611static int __init rcu_torture_stall_init(void)
1612{
1613 int ret;
1614
1615 if (stall_cpu <= 0)
1616 return 0;
1617 stall_task = kthread_run(rcu_torture_stall, NULL, "rcu_torture_stall");
1618 if (IS_ERR(stall_task)) {
1619 ret = PTR_ERR(stall_task);
1620 stall_task = NULL;
1621 return ret;
1622 }
1623 return 0;
1624}
1625
1626/* Clean up after the CPU-stall kthread, if one was spawned. */
1627static void rcu_torture_stall_cleanup(void)
1628{
1629 if (stall_task == NULL)
1630 return;
1631 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task.");
1632 kthread_stop(stall_task);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001633 stall_task = NULL;
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001634}
1635
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001636/* Callback function for RCU barrier testing. */
1637void rcu_torture_barrier_cbf(struct rcu_head *rcu)
1638{
1639 atomic_inc(&barrier_cbs_invoked);
1640}
1641
1642/* kthread function to register callbacks used to test RCU barriers. */
1643static int rcu_torture_barrier_cbs(void *arg)
1644{
1645 long myid = (long)arg;
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001646 bool lastphase = 0;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001647 struct rcu_head rcu;
1648
1649 init_rcu_head_on_stack(&rcu);
1650 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
1651 set_user_nice(current, 19);
1652 do {
1653 wait_event(barrier_cbs_wq[myid],
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001654 barrier_phase != lastphase ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001655 kthread_should_stop() ||
1656 fullstop != FULLSTOP_DONTSTOP);
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001657 lastphase = barrier_phase;
1658 smp_mb(); /* ensure barrier_phase load before ->call(). */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001659 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1660 break;
1661 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1662 if (atomic_dec_and_test(&barrier_cbs_count))
1663 wake_up(&barrier_wq);
1664 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1665 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task stopping");
1666 rcutorture_shutdown_absorb("rcu_torture_barrier_cbs");
1667 while (!kthread_should_stop())
1668 schedule_timeout_interruptible(1);
1669 cur_ops->cb_barrier();
1670 destroy_rcu_head_on_stack(&rcu);
1671 return 0;
1672}
1673
1674/* kthread function to drive and coordinate RCU barrier testing. */
1675static int rcu_torture_barrier(void *arg)
1676{
1677 int i;
1678
1679 VERBOSE_PRINTK_STRING("rcu_torture_barrier task starting");
1680 do {
1681 atomic_set(&barrier_cbs_invoked, 0);
1682 atomic_set(&barrier_cbs_count, n_barrier_cbs);
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001683 smp_mb(); /* Ensure barrier_phase after prior assignments. */
1684 barrier_phase = !barrier_phase;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001685 for (i = 0; i < n_barrier_cbs; i++)
1686 wake_up(&barrier_cbs_wq[i]);
1687 wait_event(barrier_wq,
1688 atomic_read(&barrier_cbs_count) == 0 ||
1689 kthread_should_stop() ||
1690 fullstop != FULLSTOP_DONTSTOP);
1691 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1692 break;
1693 n_barrier_attempts++;
1694 cur_ops->cb_barrier();
1695 if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
1696 n_rcu_torture_barrier_error++;
1697 WARN_ON_ONCE(1);
1698 }
1699 n_barrier_successes++;
1700 schedule_timeout_interruptible(HZ / 10);
1701 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1702 VERBOSE_PRINTK_STRING("rcu_torture_barrier task stopping");
1703 rcutorture_shutdown_absorb("rcu_torture_barrier_cbs");
1704 while (!kthread_should_stop())
1705 schedule_timeout_interruptible(1);
1706 return 0;
1707}
1708
1709/* Initialize RCU barrier testing. */
1710static int rcu_torture_barrier_init(void)
1711{
1712 int i;
1713 int ret;
1714
1715 if (n_barrier_cbs == 0)
1716 return 0;
1717 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
1718 printk(KERN_ALERT "%s" TORTURE_FLAG
1719 " Call or barrier ops missing for %s,\n",
1720 torture_type, cur_ops->name);
1721 printk(KERN_ALERT "%s" TORTURE_FLAG
1722 " RCU barrier testing omitted from run.\n",
1723 torture_type);
1724 return 0;
1725 }
1726 atomic_set(&barrier_cbs_count, 0);
1727 atomic_set(&barrier_cbs_invoked, 0);
1728 barrier_cbs_tasks =
1729 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
1730 GFP_KERNEL);
1731 barrier_cbs_wq =
1732 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
1733 GFP_KERNEL);
1734 if (barrier_cbs_tasks == NULL || barrier_cbs_wq == 0)
1735 return -ENOMEM;
1736 for (i = 0; i < n_barrier_cbs; i++) {
1737 init_waitqueue_head(&barrier_cbs_wq[i]);
1738 barrier_cbs_tasks[i] = kthread_run(rcu_torture_barrier_cbs,
Lai Jiangshan9059c942012-03-19 16:12:14 +08001739 (void *)(long)i,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001740 "rcu_torture_barrier_cbs");
1741 if (IS_ERR(barrier_cbs_tasks[i])) {
1742 ret = PTR_ERR(barrier_cbs_tasks[i]);
1743 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier_cbs");
1744 barrier_cbs_tasks[i] = NULL;
1745 return ret;
1746 }
1747 }
1748 barrier_task = kthread_run(rcu_torture_barrier, NULL,
1749 "rcu_torture_barrier");
1750 if (IS_ERR(barrier_task)) {
1751 ret = PTR_ERR(barrier_task);
1752 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier");
1753 barrier_task = NULL;
1754 }
1755 return 0;
1756}
1757
1758/* Clean up after RCU barrier testing. */
1759static void rcu_torture_barrier_cleanup(void)
1760{
1761 int i;
1762
1763 if (barrier_task != NULL) {
1764 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier task");
1765 kthread_stop(barrier_task);
1766 barrier_task = NULL;
1767 }
1768 if (barrier_cbs_tasks != NULL) {
1769 for (i = 0; i < n_barrier_cbs; i++) {
1770 if (barrier_cbs_tasks[i] != NULL) {
1771 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier_cbs task");
1772 kthread_stop(barrier_cbs_tasks[i]);
1773 barrier_cbs_tasks[i] = NULL;
1774 }
1775 }
1776 kfree(barrier_cbs_tasks);
1777 barrier_cbs_tasks = NULL;
1778 }
1779 if (barrier_cbs_wq != NULL) {
1780 kfree(barrier_cbs_wq);
1781 barrier_cbs_wq = NULL;
1782 }
1783}
1784
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001785static int rcutorture_cpu_notify(struct notifier_block *self,
1786 unsigned long action, void *hcpu)
1787{
1788 long cpu = (long)hcpu;
1789
1790 switch (action) {
1791 case CPU_ONLINE:
1792 case CPU_DOWN_FAILED:
1793 (void)rcutorture_booster_init(cpu);
1794 break;
1795 case CPU_DOWN_PREPARE:
1796 rcutorture_booster_cleanup(cpu);
1797 break;
1798 default:
1799 break;
1800 }
1801 return NOTIFY_OK;
1802}
1803
1804static struct notifier_block rcutorture_cpu_nb = {
1805 .notifier_call = rcutorture_cpu_notify,
1806};
1807
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001808static void
1809rcu_torture_cleanup(void)
1810{
1811 int i;
1812
Paul E. McKenney343e9092008-12-15 16:13:07 -08001813 mutex_lock(&fullstop_mutex);
Paul E. McKenney4a298652011-04-03 21:33:51 -07001814 rcutorture_record_test_transition();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001815 if (fullstop == FULLSTOP_SHUTDOWN) {
1816 printk(KERN_WARNING /* but going down anyway, so... */
1817 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001818 mutex_unlock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001819 schedule_timeout_uninterruptible(10);
Paul E. McKenney343e9092008-12-15 16:13:07 -08001820 if (cur_ops->cb_barrier != NULL)
1821 cur_ops->cb_barrier();
1822 return;
1823 }
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001824 fullstop = FULLSTOP_RMMOD;
Paul E. McKenney343e9092008-12-15 16:13:07 -08001825 mutex_unlock(&fullstop_mutex);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001826 unregister_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001827 rcu_torture_barrier_cleanup();
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001828 rcu_torture_stall_cleanup();
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001829 if (stutter_task) {
1830 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1831 kthread_stop(stutter_task);
1832 }
1833 stutter_task = NULL;
Josh Triplettc8e5b162007-05-08 00:33:20 -07001834 if (shuffler_task) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001835 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1836 kthread_stop(shuffler_task);
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001837 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001838 }
1839 shuffler_task = NULL;
1840
Josh Triplettc8e5b162007-05-08 00:33:20 -07001841 if (writer_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001842 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1843 kthread_stop(writer_task);
1844 }
1845 writer_task = NULL;
1846
Josh Triplettc8e5b162007-05-08 00:33:20 -07001847 if (reader_tasks) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001848 for (i = 0; i < nrealreaders; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001849 if (reader_tasks[i]) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001850 VERBOSE_PRINTK_STRING(
1851 "Stopping rcu_torture_reader task");
1852 kthread_stop(reader_tasks[i]);
1853 }
1854 reader_tasks[i] = NULL;
1855 }
1856 kfree(reader_tasks);
1857 reader_tasks = NULL;
1858 }
1859 rcu_torture_current = NULL;
1860
Josh Triplettc8e5b162007-05-08 00:33:20 -07001861 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001862 for (i = 0; i < nfakewriters; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001863 if (fakewriter_tasks[i]) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001864 VERBOSE_PRINTK_STRING(
1865 "Stopping rcu_torture_fakewriter task");
1866 kthread_stop(fakewriter_tasks[i]);
1867 }
1868 fakewriter_tasks[i] = NULL;
1869 }
1870 kfree(fakewriter_tasks);
1871 fakewriter_tasks = NULL;
1872 }
1873
Josh Triplettc8e5b162007-05-08 00:33:20 -07001874 if (stats_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001875 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1876 kthread_stop(stats_task);
1877 }
1878 stats_task = NULL;
1879
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001880 if (fqs_task) {
1881 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1882 kthread_stop(fqs_task);
1883 }
1884 fqs_task = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001885 if ((test_boost == 1 && cur_ops->can_boost) ||
1886 test_boost == 2) {
1887 unregister_cpu_notifier(&rcutorture_cpu_nb);
1888 for_each_possible_cpu(i)
1889 rcutorture_booster_cleanup(i);
1890 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001891 if (shutdown_task != NULL) {
1892 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1893 kthread_stop(shutdown_task);
1894 }
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001895 shutdown_task = NULL;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001896 rcu_torture_onoff_cleanup();
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001897
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001898 /* Wait for all RCU callbacks to fire. */
Paul E. McKenney23269742008-05-12 21:21:05 +02001899
1900 if (cur_ops->cb_barrier != NULL)
1901 cur_ops->cb_barrier();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001902
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001903 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001904
Josh Triplettc8e5b162007-05-08 00:33:20 -07001905 if (cur_ops->cleanup)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001906 cur_ops->cleanup();
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001907 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001908 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
Paul E. McKenney091541b2012-01-10 12:51:14 -08001909 else if (n_online_successes != n_online_attempts ||
1910 n_offline_successes != n_offline_attempts)
1911 rcu_torture_print_module_parms(cur_ops,
1912 "End of test: RCU_HOTPLUG");
Paul E. McKenney95c38322006-03-24 03:15:58 -08001913 else
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001914 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001915}
1916
Josh Triplett6f8bc502007-05-08 00:25:24 -07001917static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001918rcu_torture_init(void)
1919{
1920 int i;
1921 int cpu;
1922 int firsterr = 0;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001923 int retval;
Josh Triplettade5fb82007-05-08 00:33:22 -07001924 static struct rcu_torture_ops *torture_ops[] =
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -08001925 { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -07001926 &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops,
Paul E. McKenney751a68b2012-05-07 13:44:44 -07001927 &srcu_ops, &srcu_sync_ops, &srcu_expedited_ops,
1928 &srcu_raw_ops, &srcu_raw_sync_ops,
Paul E. McKenney804bb832009-10-25 19:03:52 -07001929 &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001930
Paul E. McKenney343e9092008-12-15 16:13:07 -08001931 mutex_lock(&fullstop_mutex);
1932
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001933 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001934 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001935 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001936 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001937 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001938 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001939 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001940 printk(KERN_ALERT "rcu-torture: invalid torture type: \"%s\"\n",
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001941 torture_type);
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001942 printk(KERN_ALERT "rcu-torture types:");
1943 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
1944 printk(KERN_ALERT " %s", torture_ops[i]->name);
1945 printk(KERN_ALERT "\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001946 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001947 return -EINVAL;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001948 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001949 if (cur_ops->fqs == NULL && fqs_duration != 0) {
1950 printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero "
1951 "fqs_duration, fqs disabled.\n");
1952 fqs_duration = 0;
1953 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001954 if (cur_ops->init)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001955 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1956
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001957 if (nreaders >= 0)
1958 nrealreaders = nreaders;
1959 else
1960 nrealreaders = 2 * num_online_cpus();
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001961 rcu_torture_print_module_parms(cur_ops, "Start of test");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001962 fullstop = FULLSTOP_DONTSTOP;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001963
1964 /* Set up the freelist. */
1965
1966 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07001967 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08001968 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001969 list_add_tail(&rcu_tortures[i].rtort_free,
1970 &rcu_torture_freelist);
1971 }
1972
1973 /* Initialize the statistics so that each run gets its own numbers. */
1974
1975 rcu_torture_current = NULL;
1976 rcu_torture_current_version = 0;
1977 atomic_set(&n_rcu_torture_alloc, 0);
1978 atomic_set(&n_rcu_torture_alloc_fail, 0);
1979 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001980 atomic_set(&n_rcu_torture_mberror, 0);
1981 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001982 n_rcu_torture_barrier_error = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001983 n_rcu_torture_boost_ktrerror = 0;
1984 n_rcu_torture_boost_rterror = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001985 n_rcu_torture_boost_failure = 0;
1986 n_rcu_torture_boosts = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001987 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1988 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001989 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001990 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1991 per_cpu(rcu_torture_count, cpu)[i] = 0;
1992 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1993 }
1994 }
1995
1996 /* Start up the kthreads. */
1997
1998 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1999 writer_task = kthread_run(rcu_torture_writer, NULL,
2000 "rcu_torture_writer");
2001 if (IS_ERR(writer_task)) {
2002 firsterr = PTR_ERR(writer_task);
2003 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
2004 writer_task = NULL;
2005 goto unwind;
2006 }
Josh Triplettb772e1d2006-10-04 02:17:13 -07002007 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
Paul E. McKenneya71fca52009-09-18 10:28:19 -07002008 GFP_KERNEL);
Josh Triplettb772e1d2006-10-04 02:17:13 -07002009 if (fakewriter_tasks == NULL) {
2010 VERBOSE_PRINTK_ERRSTRING("out of memory");
2011 firsterr = -ENOMEM;
2012 goto unwind;
2013 }
2014 for (i = 0; i < nfakewriters; i++) {
2015 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
2016 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -07002017 "rcu_torture_fakewriter");
Josh Triplettb772e1d2006-10-04 02:17:13 -07002018 if (IS_ERR(fakewriter_tasks[i])) {
2019 firsterr = PTR_ERR(fakewriter_tasks[i]);
2020 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
2021 fakewriter_tasks[i] = NULL;
2022 goto unwind;
2023 }
2024 }
Josh Triplett2860aab2006-10-04 02:17:11 -07002025 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002026 GFP_KERNEL);
2027 if (reader_tasks == NULL) {
2028 VERBOSE_PRINTK_ERRSTRING("out of memory");
2029 firsterr = -ENOMEM;
2030 goto unwind;
2031 }
2032 for (i = 0; i < nrealreaders; i++) {
2033 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
2034 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
2035 "rcu_torture_reader");
2036 if (IS_ERR(reader_tasks[i])) {
2037 firsterr = PTR_ERR(reader_tasks[i]);
2038 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
2039 reader_tasks[i] = NULL;
2040 goto unwind;
2041 }
2042 }
2043 if (stat_interval > 0) {
2044 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
2045 stats_task = kthread_run(rcu_torture_stats, NULL,
2046 "rcu_torture_stats");
2047 if (IS_ERR(stats_task)) {
2048 firsterr = PTR_ERR(stats_task);
2049 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
2050 stats_task = NULL;
2051 goto unwind;
2052 }
2053 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08002054 if (test_no_idle_hz) {
2055 rcu_idle_cpu = num_online_cpus() - 1;
Rusty Russell73d0a4b2009-03-30 22:05:16 -06002056
2057 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
2058 firsterr = -ENOMEM;
2059 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
2060 goto unwind;
2061 }
2062
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08002063 /* Create the shuffler thread */
2064 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
2065 "rcu_torture_shuffle");
2066 if (IS_ERR(shuffler_task)) {
Rusty Russell73d0a4b2009-03-30 22:05:16 -06002067 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08002068 firsterr = PTR_ERR(shuffler_task);
2069 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
2070 shuffler_task = NULL;
2071 goto unwind;
2072 }
2073 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07002074 if (stutter < 0)
2075 stutter = 0;
2076 if (stutter) {
2077 /* Create the stutter thread */
2078 stutter_task = kthread_run(rcu_torture_stutter, NULL,
2079 "rcu_torture_stutter");
2080 if (IS_ERR(stutter_task)) {
2081 firsterr = PTR_ERR(stutter_task);
2082 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
2083 stutter_task = NULL;
2084 goto unwind;
2085 }
2086 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08002087 if (fqs_duration < 0)
2088 fqs_duration = 0;
2089 if (fqs_duration) {
2090 /* Create the stutter thread */
2091 fqs_task = kthread_run(rcu_torture_fqs, NULL,
2092 "rcu_torture_fqs");
2093 if (IS_ERR(fqs_task)) {
2094 firsterr = PTR_ERR(fqs_task);
2095 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
2096 fqs_task = NULL;
2097 goto unwind;
2098 }
2099 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002100 if (test_boost_interval < 1)
2101 test_boost_interval = 1;
2102 if (test_boost_duration < 2)
2103 test_boost_duration = 2;
2104 if ((test_boost == 1 && cur_ops->can_boost) ||
2105 test_boost == 2) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002106
2107 boost_starttime = jiffies + test_boost_interval * HZ;
2108 register_cpu_notifier(&rcutorture_cpu_nb);
2109 for_each_possible_cpu(i) {
2110 if (cpu_is_offline(i))
2111 continue; /* Heuristic: CPU can go offline. */
2112 retval = rcutorture_booster_init(i);
2113 if (retval < 0) {
2114 firsterr = retval;
2115 goto unwind;
2116 }
2117 }
2118 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07002119 if (shutdown_secs > 0) {
2120 shutdown_time = jiffies + shutdown_secs * HZ;
2121 shutdown_task = kthread_run(rcu_torture_shutdown, NULL,
2122 "rcu_torture_shutdown");
2123 if (IS_ERR(shutdown_task)) {
2124 firsterr = PTR_ERR(shutdown_task);
2125 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
2126 shutdown_task = NULL;
2127 goto unwind;
2128 }
2129 }
Paul E. McKenney37e377d2012-02-17 22:12:18 -08002130 i = rcu_torture_onoff_init();
2131 if (i != 0) {
2132 firsterr = i;
2133 goto unwind;
2134 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002135 register_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08002136 i = rcu_torture_stall_init();
2137 if (i != 0) {
2138 firsterr = i;
2139 goto unwind;
2140 }
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08002141 retval = rcu_torture_barrier_init();
2142 if (retval != 0) {
2143 firsterr = retval;
2144 goto unwind;
2145 }
Paul E. McKenney4a298652011-04-03 21:33:51 -07002146 rcutorture_record_test_transition();
Paul E. McKenney343e9092008-12-15 16:13:07 -08002147 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002148 return 0;
2149
2150unwind:
Paul E. McKenney343e9092008-12-15 16:13:07 -08002151 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002152 rcu_torture_cleanup();
2153 return firsterr;
2154}
2155
2156module_init(rcu_torture_init);
2157module_exit(rcu_torture_cleanup);