blob: 155fb129b64123c40ceb4d21dd4af6c12f0ed903 [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);
Paul E. McKenneyc701d5d2012-06-28 08:08:25 -0700411 } else {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700412 cur_ops->deferred_free(rp);
Paul E. McKenneyc701d5d2012-06-28 08:08:25 -0700413 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700414}
415
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800416static int rcu_no_completed(void)
417{
418 return 0;
419}
420
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700421static void rcu_torture_deferred_free(struct rcu_torture *p)
422{
423 call_rcu(&p->rtort_rcu, rcu_torture_cb);
424}
425
426static struct rcu_torture_ops rcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700427 .init = NULL,
428 .cleanup = NULL,
429 .readlock = rcu_torture_read_lock,
430 .read_delay = rcu_read_delay,
431 .readunlock = rcu_torture_read_unlock,
432 .completed = rcu_torture_completed,
433 .deferred_free = rcu_torture_deferred_free,
434 .sync = synchronize_rcu,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800435 .call = call_rcu,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700436 .cb_barrier = rcu_barrier,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800437 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700438 .stats = NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700439 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700440 .can_boost = rcu_can_boost(),
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700441 .name = "rcu"
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700442};
443
Josh Triplette3033732006-10-04 02:17:14 -0700444static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
445{
446 int i;
447 struct rcu_torture *rp;
448 struct rcu_torture *rp1;
449
450 cur_ops->sync();
451 list_add(&p->rtort_free, &rcu_torture_removed);
452 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
453 i = rp->rtort_pipe_count;
454 if (i > RCU_TORTURE_PIPE_LEN)
455 i = RCU_TORTURE_PIPE_LEN;
456 atomic_inc(&rcu_torture_wcount[i]);
457 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
458 rp->rtort_mbtest = 0;
459 list_del(&rp->rtort_free);
460 rcu_torture_free(rp);
461 }
462 }
463}
464
465static void rcu_sync_torture_init(void)
466{
467 INIT_LIST_HEAD(&rcu_torture_removed);
468}
469
Josh Triplett20d2e422006-10-04 02:17:15 -0700470static struct rcu_torture_ops rcu_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700471 .init = rcu_sync_torture_init,
472 .cleanup = NULL,
473 .readlock = rcu_torture_read_lock,
474 .read_delay = rcu_read_delay,
475 .readunlock = rcu_torture_read_unlock,
476 .completed = rcu_torture_completed,
477 .deferred_free = rcu_sync_torture_deferred_free,
478 .sync = synchronize_rcu,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800479 .call = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700480 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800481 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700482 .stats = NULL,
483 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700484 .can_boost = rcu_can_boost(),
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700485 .name = "rcu_sync"
Josh Triplett20d2e422006-10-04 02:17:15 -0700486};
487
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800488static struct rcu_torture_ops rcu_expedited_ops = {
489 .init = rcu_sync_torture_init,
490 .cleanup = NULL,
491 .readlock = rcu_torture_read_lock,
492 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
493 .readunlock = rcu_torture_read_unlock,
494 .completed = rcu_no_completed,
495 .deferred_free = rcu_sync_torture_deferred_free,
496 .sync = synchronize_rcu_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800497 .call = NULL,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800498 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800499 .fqs = rcu_force_quiescent_state,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800500 .stats = NULL,
501 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700502 .can_boost = rcu_can_boost(),
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800503 .name = "rcu_expedited"
504};
505
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700506/*
507 * Definitions for rcu_bh torture testing.
508 */
509
Josh Tripletta49a4af2006-09-29 01:59:30 -0700510static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700511{
512 rcu_read_lock_bh();
513 return 0;
514}
515
Josh Tripletta49a4af2006-09-29 01:59:30 -0700516static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700517{
518 rcu_read_unlock_bh();
519}
520
521static int rcu_bh_torture_completed(void)
522{
523 return rcu_batches_completed_bh();
524}
525
526static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
527{
528 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
529}
530
531static struct rcu_torture_ops rcu_bh_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700532 .init = NULL,
533 .cleanup = NULL,
534 .readlock = rcu_bh_torture_read_lock,
535 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
536 .readunlock = rcu_bh_torture_read_unlock,
537 .completed = rcu_bh_torture_completed,
538 .deferred_free = rcu_bh_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700539 .sync = synchronize_rcu_bh,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800540 .call = call_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700541 .cb_barrier = rcu_barrier_bh,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800542 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700543 .stats = NULL,
544 .irq_capable = 1,
545 .name = "rcu_bh"
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700546};
547
Josh Triplett11a14702006-10-04 02:17:16 -0700548static struct rcu_torture_ops rcu_bh_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700549 .init = rcu_sync_torture_init,
550 .cleanup = NULL,
551 .readlock = rcu_bh_torture_read_lock,
552 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
553 .readunlock = rcu_bh_torture_read_unlock,
554 .completed = rcu_bh_torture_completed,
555 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700556 .sync = synchronize_rcu_bh,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800557 .call = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700558 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800559 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700560 .stats = NULL,
561 .irq_capable = 1,
562 .name = "rcu_bh_sync"
Josh Triplett11a14702006-10-04 02:17:16 -0700563};
564
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700565static struct rcu_torture_ops rcu_bh_expedited_ops = {
566 .init = rcu_sync_torture_init,
567 .cleanup = NULL,
568 .readlock = rcu_bh_torture_read_lock,
569 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
570 .readunlock = rcu_bh_torture_read_unlock,
571 .completed = rcu_bh_torture_completed,
572 .deferred_free = rcu_sync_torture_deferred_free,
573 .sync = synchronize_rcu_bh_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800574 .call = NULL,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700575 .cb_barrier = NULL,
576 .fqs = rcu_bh_force_quiescent_state,
577 .stats = NULL,
578 .irq_capable = 1,
579 .name = "rcu_bh_expedited"
580};
581
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700582/*
583 * Definitions for srcu torture testing.
584 */
585
586static struct srcu_struct srcu_ctl;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700587
588static void srcu_torture_init(void)
589{
590 init_srcu_struct(&srcu_ctl);
Josh Triplette3033732006-10-04 02:17:14 -0700591 rcu_sync_torture_init();
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700592}
593
594static void srcu_torture_cleanup(void)
595{
596 synchronize_srcu(&srcu_ctl);
597 cleanup_srcu_struct(&srcu_ctl);
598}
599
Josh Triplett012d3ca2006-12-06 20:40:19 -0800600static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700601{
602 return srcu_read_lock(&srcu_ctl);
603}
604
605static void srcu_read_delay(struct rcu_random_state *rrsp)
606{
607 long delay;
608 const long uspertick = 1000000 / HZ;
609 const long longdelay = 10;
610
611 /* We want there to be long-running readers, but not all the time. */
612
613 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
614 if (!delay)
615 schedule_timeout_interruptible(longdelay);
Lai Jiangshane546f482010-06-21 16:57:42 +0800616 else
617 rcu_read_delay(rrsp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700618}
619
Josh Triplett012d3ca2006-12-06 20:40:19 -0800620static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700621{
622 srcu_read_unlock(&srcu_ctl, idx);
623}
624
625static int srcu_torture_completed(void)
626{
627 return srcu_batches_completed(&srcu_ctl);
628}
629
Lai Jiangshan9059c942012-03-19 16:12:14 +0800630static void srcu_torture_deferred_free(struct rcu_torture *rp)
631{
632 call_srcu(&srcu_ctl, &rp->rtort_rcu, rcu_torture_cb);
633}
634
Josh Triplettb772e1d2006-10-04 02:17:13 -0700635static void srcu_torture_synchronize(void)
636{
637 synchronize_srcu(&srcu_ctl);
638}
639
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700640static void srcu_torture_call(struct rcu_head *head,
641 void (*func)(struct rcu_head *head))
642{
643 call_srcu(&srcu_ctl, head, func);
644}
645
646static void srcu_torture_barrier(void)
647{
648 srcu_barrier(&srcu_ctl);
649}
650
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700651static int srcu_torture_stats(char *page)
652{
653 int cnt = 0;
654 int cpu;
655 int idx = srcu_ctl.completed & 0x1;
656
657 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
658 torture_type, TORTURE_FLAG, idx);
659 for_each_possible_cpu(cpu) {
Paul E. McKenneycef50122012-02-05 07:42:44 -0800660 cnt += sprintf(&page[cnt], " %d(%lu,%lu)", cpu,
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700661 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
662 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
663 }
664 cnt += sprintf(&page[cnt], "\n");
665 return cnt;
666}
667
668static struct rcu_torture_ops srcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700669 .init = srcu_torture_init,
670 .cleanup = srcu_torture_cleanup,
671 .readlock = srcu_torture_read_lock,
672 .read_delay = srcu_read_delay,
673 .readunlock = srcu_torture_read_unlock,
674 .completed = srcu_torture_completed,
Lai Jiangshan9059c942012-03-19 16:12:14 +0800675 .deferred_free = srcu_torture_deferred_free,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700676 .sync = srcu_torture_synchronize,
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700677 .call = srcu_torture_call,
678 .cb_barrier = srcu_torture_barrier,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700679 .stats = srcu_torture_stats,
680 .name = "srcu"
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700681};
682
Lai Jiangshan9059c942012-03-19 16:12:14 +0800683static struct rcu_torture_ops srcu_sync_ops = {
684 .init = srcu_torture_init,
685 .cleanup = srcu_torture_cleanup,
686 .readlock = srcu_torture_read_lock,
687 .read_delay = srcu_read_delay,
688 .readunlock = srcu_torture_read_unlock,
689 .completed = srcu_torture_completed,
690 .deferred_free = rcu_sync_torture_deferred_free,
691 .sync = srcu_torture_synchronize,
692 .call = NULL,
693 .cb_barrier = NULL,
694 .stats = srcu_torture_stats,
695 .name = "srcu_sync"
696};
697
Paul E. McKenney101db7b2011-12-05 15:36:31 -0800698static int srcu_torture_read_lock_raw(void) __acquires(&srcu_ctl)
699{
700 return srcu_read_lock_raw(&srcu_ctl);
701}
702
703static void srcu_torture_read_unlock_raw(int idx) __releases(&srcu_ctl)
704{
705 srcu_read_unlock_raw(&srcu_ctl, idx);
706}
707
708static struct rcu_torture_ops srcu_raw_ops = {
709 .init = srcu_torture_init,
710 .cleanup = srcu_torture_cleanup,
711 .readlock = srcu_torture_read_lock_raw,
712 .read_delay = srcu_read_delay,
713 .readunlock = srcu_torture_read_unlock_raw,
714 .completed = srcu_torture_completed,
Lai Jiangshan9059c942012-03-19 16:12:14 +0800715 .deferred_free = srcu_torture_deferred_free,
Paul E. McKenney101db7b2011-12-05 15:36:31 -0800716 .sync = srcu_torture_synchronize,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800717 .call = NULL,
Paul E. McKenney101db7b2011-12-05 15:36:31 -0800718 .cb_barrier = NULL,
719 .stats = srcu_torture_stats,
720 .name = "srcu_raw"
721};
722
Lai Jiangshan9059c942012-03-19 16:12:14 +0800723static struct rcu_torture_ops srcu_raw_sync_ops = {
724 .init = srcu_torture_init,
725 .cleanup = srcu_torture_cleanup,
726 .readlock = srcu_torture_read_lock_raw,
727 .read_delay = srcu_read_delay,
728 .readunlock = srcu_torture_read_unlock_raw,
729 .completed = srcu_torture_completed,
730 .deferred_free = rcu_sync_torture_deferred_free,
731 .sync = srcu_torture_synchronize,
732 .call = NULL,
733 .cb_barrier = NULL,
734 .stats = srcu_torture_stats,
735 .name = "srcu_raw_sync"
736};
737
Paul E. McKenney804bb832009-10-25 19:03:52 -0700738static void srcu_torture_synchronize_expedited(void)
739{
740 synchronize_srcu_expedited(&srcu_ctl);
741}
742
743static struct rcu_torture_ops srcu_expedited_ops = {
744 .init = srcu_torture_init,
745 .cleanup = srcu_torture_cleanup,
746 .readlock = srcu_torture_read_lock,
747 .read_delay = srcu_read_delay,
748 .readunlock = srcu_torture_read_unlock,
749 .completed = srcu_torture_completed,
750 .deferred_free = rcu_sync_torture_deferred_free,
751 .sync = srcu_torture_synchronize_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800752 .call = NULL,
Paul E. McKenney804bb832009-10-25 19:03:52 -0700753 .cb_barrier = NULL,
754 .stats = srcu_torture_stats,
755 .name = "srcu_expedited"
756};
757
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700758/*
759 * Definitions for sched torture testing.
760 */
761
762static int sched_torture_read_lock(void)
763{
764 preempt_disable();
765 return 0;
766}
767
768static void sched_torture_read_unlock(int idx)
769{
770 preempt_enable();
771}
772
Paul E. McKenney23269742008-05-12 21:21:05 +0200773static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
774{
775 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
776}
777
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700778static struct rcu_torture_ops sched_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700779 .init = rcu_sync_torture_init,
780 .cleanup = NULL,
781 .readlock = sched_torture_read_lock,
782 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
783 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800784 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700785 .deferred_free = rcu_sched_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700786 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700787 .cb_barrier = rcu_barrier_sched,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800788 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700789 .stats = NULL,
790 .irq_capable = 1,
791 .name = "sched"
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700792};
793
Paul E. McKenney804bb832009-10-25 19:03:52 -0700794static struct rcu_torture_ops sched_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700795 .init = rcu_sync_torture_init,
796 .cleanup = NULL,
797 .readlock = sched_torture_read_lock,
798 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
799 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800800 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700801 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700802 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700803 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800804 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700805 .stats = NULL,
806 .name = "sched_sync"
807};
808
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700809static struct rcu_torture_ops sched_expedited_ops = {
810 .init = rcu_sync_torture_init,
811 .cleanup = NULL,
812 .readlock = sched_torture_read_lock,
813 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
814 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800815 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700816 .deferred_free = rcu_sync_torture_deferred_free,
817 .sync = synchronize_sched_expedited,
818 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800819 .fqs = rcu_sched_force_quiescent_state,
Tejun Heo969c7922010-05-06 18:49:21 +0200820 .stats = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700821 .irq_capable = 1,
822 .name = "sched_expedited"
Paul E. McKenney23269742008-05-12 21:21:05 +0200823};
824
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700825/*
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700826 * RCU torture priority-boost testing. Runs one real-time thread per
827 * CPU for moderate bursts, repeatedly registering RCU callbacks and
828 * spinning waiting for them to be invoked. If a given callback takes
829 * too long to be invoked, we assume that priority inversion has occurred.
830 */
831
832struct rcu_boost_inflight {
833 struct rcu_head rcu;
834 int inflight;
835};
836
837static void rcu_torture_boost_cb(struct rcu_head *head)
838{
839 struct rcu_boost_inflight *rbip =
840 container_of(head, struct rcu_boost_inflight, rcu);
841
842 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
843 rbip->inflight = 0;
844}
845
846static int rcu_torture_boost(void *arg)
847{
848 unsigned long call_rcu_time;
849 unsigned long endtime;
850 unsigned long oldstarttime;
851 struct rcu_boost_inflight rbi = { .inflight = 0 };
852 struct sched_param sp;
853
854 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
855
856 /* Set real-time priority. */
857 sp.sched_priority = 1;
858 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
859 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
860 n_rcu_torture_boost_rterror++;
861 }
862
Paul E. McKenney561190e2011-03-30 09:10:44 -0700863 init_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700864 /* Each pass through the following loop does one boost-test cycle. */
865 do {
866 /* Wait for the next test interval. */
867 oldstarttime = boost_starttime;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700868 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700869 schedule_timeout_uninterruptible(1);
870 rcu_stutter_wait("rcu_torture_boost");
871 if (kthread_should_stop() ||
872 fullstop != FULLSTOP_DONTSTOP)
873 goto checkwait;
874 }
875
876 /* Do one boost-test interval. */
877 endtime = oldstarttime + test_boost_duration * HZ;
878 call_rcu_time = jiffies;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700879 while (ULONG_CMP_LT(jiffies, endtime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700880 /* If we don't have a callback in flight, post one. */
881 if (!rbi.inflight) {
882 smp_mb(); /* RCU core before ->inflight = 1. */
883 rbi.inflight = 1;
884 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
885 if (jiffies - call_rcu_time >
886 test_boost_duration * HZ - HZ / 2) {
887 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
888 n_rcu_torture_boost_failure++;
889 }
890 call_rcu_time = jiffies;
891 }
892 cond_resched();
893 rcu_stutter_wait("rcu_torture_boost");
894 if (kthread_should_stop() ||
895 fullstop != FULLSTOP_DONTSTOP)
896 goto checkwait;
897 }
898
899 /*
900 * Set the start time of the next test interval.
901 * Yes, this is vulnerable to long delays, but such
902 * delays simply cause a false negative for the next
903 * interval. Besides, we are running at RT priority,
904 * so delays should be relatively rare.
905 */
Paul E. McKenneyab8f11e2011-08-18 09:30:32 -0700906 while (oldstarttime == boost_starttime &&
907 !kthread_should_stop()) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700908 if (mutex_trylock(&boost_mutex)) {
909 boost_starttime = jiffies +
910 test_boost_interval * HZ;
911 n_rcu_torture_boosts++;
912 mutex_unlock(&boost_mutex);
913 break;
914 }
915 schedule_timeout_uninterruptible(1);
916 }
917
918 /* Go do the stutter. */
919checkwait: rcu_stutter_wait("rcu_torture_boost");
920 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
921
922 /* Clean up and exit. */
923 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
924 rcutorture_shutdown_absorb("rcu_torture_boost");
925 while (!kthread_should_stop() || rbi.inflight)
926 schedule_timeout_uninterruptible(1);
927 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
Paul E. McKenney9d681972011-06-21 01:48:03 -0700928 destroy_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700929 return 0;
930}
931
932/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800933 * RCU torture force-quiescent-state kthread. Repeatedly induces
934 * bursts of calls to force_quiescent_state(), increasing the probability
935 * of occurrence of some important types of race conditions.
936 */
937static int
938rcu_torture_fqs(void *arg)
939{
940 unsigned long fqs_resume_time;
941 int fqs_burst_remaining;
942
943 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
944 do {
945 fqs_resume_time = jiffies + fqs_stutter * HZ;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700946 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
947 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800948 schedule_timeout_interruptible(1);
949 }
950 fqs_burst_remaining = fqs_duration;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700951 while (fqs_burst_remaining > 0 &&
952 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800953 cur_ops->fqs();
954 udelay(fqs_holdoff);
955 fqs_burst_remaining -= fqs_holdoff;
956 }
957 rcu_stutter_wait("rcu_torture_fqs");
958 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
959 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
960 rcutorture_shutdown_absorb("rcu_torture_fqs");
961 while (!kthread_should_stop())
962 schedule_timeout_uninterruptible(1);
963 return 0;
964}
965
966/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800967 * RCU torture writer kthread. Repeatedly substitutes a new structure
968 * for that pointed to by rcu_torture_current, freeing the old structure
969 * after a series of grace periods (the "pipeline").
970 */
971static int
972rcu_torture_writer(void *arg)
973{
974 int i;
975 long oldbatch = rcu_batches_completed();
976 struct rcu_torture *rp;
977 struct rcu_torture *old_rp;
978 static DEFINE_RCU_RANDOM(rand);
979
980 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800981 set_user_nice(current, 19);
982
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800983 do {
984 schedule_timeout_uninterruptible(1);
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700985 rp = rcu_torture_alloc();
986 if (rp == NULL)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800987 continue;
988 rp->rtort_pipe_count = 0;
989 udelay(rcu_random(&rand) & 0x3ff);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700990 old_rp = rcu_dereference_check(rcu_torture_current,
991 current == writer_task);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800992 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800993 rcu_assign_pointer(rcu_torture_current, rp);
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700994 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
Josh Triplettc8e5b162007-05-08 00:33:20 -0700995 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800996 i = old_rp->rtort_pipe_count;
997 if (i > RCU_TORTURE_PIPE_LEN)
998 i = RCU_TORTURE_PIPE_LEN;
999 atomic_inc(&rcu_torture_wcount[i]);
1000 old_rp->rtort_pipe_count++;
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001001 cur_ops->deferred_free(old_rp);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001002 }
Paul E. McKenney4a298652011-04-03 21:33:51 -07001003 rcutorture_record_progress(++rcu_torture_current_version);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001004 oldbatch = cur_ops->completed();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001005 rcu_stutter_wait("rcu_torture_writer");
1006 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001007 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001008 rcutorture_shutdown_absorb("rcu_torture_writer");
1009 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001010 schedule_timeout_uninterruptible(1);
1011 return 0;
1012}
1013
1014/*
Josh Triplettb772e1d2006-10-04 02:17:13 -07001015 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
1016 * delay between calls.
1017 */
1018static int
1019rcu_torture_fakewriter(void *arg)
1020{
1021 DEFINE_RCU_RANDOM(rand);
1022
1023 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
1024 set_user_nice(current, 19);
1025
1026 do {
1027 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
1028 udelay(rcu_random(&rand) & 0x3ff);
Paul E. McKenney72472a02012-05-29 17:50:51 -07001029 if (cur_ops->cb_barrier != NULL &&
1030 rcu_random(&rand) % (nfakewriters * 8) == 0)
1031 cur_ops->cb_barrier();
1032 else
1033 cur_ops->sync();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001034 rcu_stutter_wait("rcu_torture_fakewriter");
1035 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001036
1037 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001038 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
1039 while (!kthread_should_stop())
Josh Triplettb772e1d2006-10-04 02:17:13 -07001040 schedule_timeout_uninterruptible(1);
1041 return 0;
1042}
1043
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001044void rcutorture_trace_dump(void)
1045{
1046 static atomic_t beenhere = ATOMIC_INIT(0);
1047
1048 if (atomic_read(&beenhere))
1049 return;
1050 if (atomic_xchg(&beenhere, 1) != 0)
1051 return;
1052 do_trace_rcu_torture_read(cur_ops->name, (struct rcu_head *)~0UL);
1053 ftrace_dump(DUMP_ALL);
1054}
1055
Josh Triplettb772e1d2006-10-04 02:17:13 -07001056/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001057 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
1058 * incrementing the corresponding element of the pipeline array. The
1059 * counter in the element should never be greater than 1, otherwise, the
1060 * RCU implementation is broken.
1061 */
1062static void rcu_torture_timer(unsigned long unused)
1063{
1064 int idx;
1065 int completed;
1066 static DEFINE_RCU_RANDOM(rand);
1067 static DEFINE_SPINLOCK(rand_lock);
1068 struct rcu_torture *p;
1069 int pipe_count;
1070
1071 idx = cur_ops->readlock();
1072 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001073 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001074 rcu_read_lock_bh_held() ||
1075 rcu_read_lock_sched_held() ||
1076 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001077 if (p == NULL) {
1078 /* Leave because rcu_torture_writer is not yet underway */
1079 cur_ops->readunlock(idx);
1080 return;
1081 }
Paul E. McKenney7129d382012-01-31 16:46:34 -08001082 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001083 if (p->rtort_mbtest == 0)
1084 atomic_inc(&n_rcu_torture_mberror);
1085 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001086 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001087 n_rcu_torture_timers++;
1088 spin_unlock(&rand_lock);
1089 preempt_disable();
1090 pipe_count = p->rtort_pipe_count;
1091 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1092 /* Should not happen, but... */
1093 pipe_count = RCU_TORTURE_PIPE_LEN;
1094 }
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001095 if (pipe_count > 1)
1096 rcutorture_trace_dump();
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001097 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001098 completed = cur_ops->completed() - completed;
1099 if (completed > RCU_TORTURE_PIPE_LEN) {
1100 /* Should not happen, but... */
1101 completed = RCU_TORTURE_PIPE_LEN;
1102 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001103 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001104 preempt_enable();
1105 cur_ops->readunlock(idx);
1106}
1107
1108/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001109 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
1110 * incrementing the corresponding element of the pipeline array. The
1111 * counter in the element should never be greater than 1, otherwise, the
1112 * RCU implementation is broken.
1113 */
1114static int
1115rcu_torture_reader(void *arg)
1116{
1117 int completed;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001118 int idx;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001119 DEFINE_RCU_RANDOM(rand);
1120 struct rcu_torture *p;
1121 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001122 struct timer_list t;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001123
1124 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001125 set_user_nice(current, 19);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001126 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001127 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001128
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001129 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001130 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001131 if (!timer_pending(&t))
Paul E. McKenney6155fec2010-02-22 17:05:04 -08001132 mod_timer(&t, jiffies + 1);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001133 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001134 idx = cur_ops->readlock();
1135 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001136 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001137 rcu_read_lock_bh_held() ||
1138 rcu_read_lock_sched_held() ||
1139 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001140 if (p == NULL) {
1141 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001142 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001143 schedule_timeout_interruptible(HZ);
1144 continue;
1145 }
Paul E. McKenney7129d382012-01-31 16:46:34 -08001146 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001147 if (p->rtort_mbtest == 0)
1148 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001149 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001150 preempt_disable();
1151 pipe_count = p->rtort_pipe_count;
1152 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1153 /* Should not happen, but... */
1154 pipe_count = RCU_TORTURE_PIPE_LEN;
1155 }
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001156 if (pipe_count > 1)
1157 rcutorture_trace_dump();
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001158 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001159 completed = cur_ops->completed() - completed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001160 if (completed > RCU_TORTURE_PIPE_LEN) {
1161 /* Should not happen, but... */
1162 completed = RCU_TORTURE_PIPE_LEN;
1163 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001164 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001165 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001166 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001167 schedule();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001168 rcu_stutter_wait("rcu_torture_reader");
1169 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001170 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001171 rcutorture_shutdown_absorb("rcu_torture_reader");
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001172 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001173 del_timer_sync(&t);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001174 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001175 schedule_timeout_uninterruptible(1);
1176 return 0;
1177}
1178
1179/*
1180 * Create an RCU-torture statistics message in the specified buffer.
1181 */
1182static int
1183rcu_torture_printk(char *page)
1184{
1185 int cnt = 0;
1186 int cpu;
1187 int i;
1188 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1189 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1190
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001191 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001192 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1193 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1194 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1195 }
1196 }
1197 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1198 if (pipesummary[i] != 0)
1199 break;
1200 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001201 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001202 cnt += sprintf(&page[cnt],
Paul E. McKenney4a298652011-04-03 21:33:51 -07001203 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d "
Paul E. McKenney67b98db2011-02-21 13:31:55 -08001204 "rtmbe: %d rtbke: %ld rtbre: %ld "
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001205 "rtbf: %ld rtb: %ld nt: %ld "
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001206 "onoff: %ld/%ld:%ld/%ld "
1207 "barrier: %ld/%ld:%ld",
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001208 rcu_torture_current,
1209 rcu_torture_current_version,
1210 list_empty(&rcu_torture_freelist),
1211 atomic_read(&n_rcu_torture_alloc),
1212 atomic_read(&n_rcu_torture_alloc_fail),
Paul E. McKenney996417d2005-11-18 01:10:50 -08001213 atomic_read(&n_rcu_torture_free),
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001214 atomic_read(&n_rcu_torture_mberror),
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001215 n_rcu_torture_boost_ktrerror,
1216 n_rcu_torture_boost_rterror,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001217 n_rcu_torture_boost_failure,
1218 n_rcu_torture_boosts,
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001219 n_rcu_torture_timers,
1220 n_online_successes,
1221 n_online_attempts,
1222 n_offline_successes,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001223 n_offline_attempts,
1224 n_barrier_successes,
1225 n_barrier_attempts,
1226 n_rcu_torture_barrier_error);
1227 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001228 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001229 n_rcu_torture_barrier_error != 0 ||
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001230 n_rcu_torture_boost_ktrerror != 0 ||
1231 n_rcu_torture_boost_rterror != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001232 n_rcu_torture_boost_failure != 0 ||
1233 i > 1) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001234 cnt += sprintf(&page[cnt], "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -08001235 atomic_inc(&n_rcu_torture_error);
Ingo Molnar5af970a2008-06-18 10:09:48 +02001236 WARN_ON_ONCE(1);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001237 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001238 cnt += sprintf(&page[cnt], "Reader Pipe: ");
1239 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1240 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001241 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001242 cnt += sprintf(&page[cnt], "Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001243 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001244 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001245 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001246 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
1247 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1248 cnt += sprintf(&page[cnt], " %d",
1249 atomic_read(&rcu_torture_wcount[i]));
1250 }
1251 cnt += sprintf(&page[cnt], "\n");
Josh Triplettc8e5b162007-05-08 00:33:20 -07001252 if (cur_ops->stats)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001253 cnt += cur_ops->stats(&page[cnt]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001254 return cnt;
1255}
1256
1257/*
1258 * Print torture statistics. Caller must ensure that there is only
1259 * one call to this function at a given time!!! This is normally
1260 * accomplished by relying on the module system to only have one copy
1261 * of the module loaded, and then by giving the rcu_torture_stats
1262 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1263 * thread is not running).
1264 */
1265static void
1266rcu_torture_stats_print(void)
1267{
1268 int cnt;
1269
1270 cnt = rcu_torture_printk(printk_buf);
1271 printk(KERN_ALERT "%s", printk_buf);
1272}
1273
1274/*
1275 * Periodically prints torture statistics, if periodic statistics printing
1276 * was specified via the stat_interval module parameter.
1277 *
1278 * No need to worry about fullstop here, since this one doesn't reference
1279 * volatile state or register callbacks.
1280 */
1281static int
1282rcu_torture_stats(void *arg)
1283{
1284 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1285 do {
1286 schedule_timeout_interruptible(stat_interval * HZ);
1287 rcu_torture_stats_print();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001288 rcutorture_shutdown_absorb("rcu_torture_stats");
1289 } while (!kthread_should_stop());
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001290 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1291 return 0;
1292}
1293
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001294static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
1295
1296/* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1297 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1298 */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -07001299static void rcu_torture_shuffle_tasks(void)
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001300{
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001301 int i;
1302
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001303 cpumask_setall(shuffle_tmp_mask);
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001304 get_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001305
1306 /* No point in shuffling if there is only one online CPU (ex: UP) */
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001307 if (num_online_cpus() == 1) {
1308 put_online_cpus();
1309 return;
1310 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001311
1312 if (rcu_idle_cpu != -1)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001313 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001314
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001315 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001316
Josh Triplettc8e5b162007-05-08 00:33:20 -07001317 if (reader_tasks) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001318 for (i = 0; i < nrealreaders; i++)
1319 if (reader_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001320 set_cpus_allowed_ptr(reader_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001321 shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001322 }
1323
Josh Triplettc8e5b162007-05-08 00:33:20 -07001324 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001325 for (i = 0; i < nfakewriters; i++)
1326 if (fakewriter_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001327 set_cpus_allowed_ptr(fakewriter_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001328 shuffle_tmp_mask);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001329 }
1330
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001331 if (writer_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001332 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001333
1334 if (stats_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001335 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001336
1337 if (rcu_idle_cpu == -1)
1338 rcu_idle_cpu = num_online_cpus() - 1;
1339 else
1340 rcu_idle_cpu--;
1341
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001342 put_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001343}
1344
1345/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1346 * system to become idle at a time and cut off its timer ticks. This is meant
1347 * to test the support for such tickless idle CPU in RCU.
1348 */
1349static int
1350rcu_torture_shuffle(void *arg)
1351{
1352 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1353 do {
1354 schedule_timeout_interruptible(shuffle_interval * HZ);
1355 rcu_torture_shuffle_tasks();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001356 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1357 } while (!kthread_should_stop());
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001358 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1359 return 0;
1360}
1361
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001362/* Cause the rcutorture test to "stutter", starting and stopping all
1363 * threads periodically.
1364 */
1365static int
1366rcu_torture_stutter(void *arg)
1367{
1368 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1369 do {
1370 schedule_timeout_interruptible(stutter * HZ);
1371 stutter_pause_test = 1;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001372 if (!kthread_should_stop())
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001373 schedule_timeout_interruptible(stutter * HZ);
1374 stutter_pause_test = 0;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001375 rcutorture_shutdown_absorb("rcu_torture_stutter");
1376 } while (!kthread_should_stop());
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001377 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1378 return 0;
1379}
1380
Paul E. McKenney95c38322006-03-24 03:15:58 -08001381static inline void
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001382rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
Paul E. McKenney95c38322006-03-24 03:15:58 -08001383{
Josh Triplettb772e1d2006-10-04 02:17:13 -07001384 printk(KERN_ALERT "%s" TORTURE_FLAG
1385 "--- %s: nreaders=%d nfakewriters=%d "
Paul E. McKenney95c38322006-03-24 03:15:58 -08001386 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001387 "shuffle_interval=%d stutter=%d irqreader=%d "
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001388 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1389 "test_boost=%d/%d test_boost_interval=%d "
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001390 "test_boost_duration=%d shutdown_secs=%d "
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -08001391 "onoff_interval=%d onoff_holdoff=%d\n",
Josh Triplettb772e1d2006-10-04 02:17:13 -07001392 torture_type, tag, nrealreaders, nfakewriters,
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001393 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001394 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1395 test_boost, cur_ops->can_boost,
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001396 test_boost_interval, test_boost_duration, shutdown_secs,
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -08001397 onoff_interval, onoff_holdoff);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001398}
1399
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001400static struct notifier_block rcutorture_shutdown_nb = {
Paul E. McKenney343e9092008-12-15 16:13:07 -08001401 .notifier_call = rcutorture_shutdown_notify,
1402};
1403
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001404static void rcutorture_booster_cleanup(int cpu)
1405{
1406 struct task_struct *t;
1407
1408 if (boost_tasks[cpu] == NULL)
1409 return;
1410 mutex_lock(&boost_mutex);
1411 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1412 t = boost_tasks[cpu];
1413 boost_tasks[cpu] = NULL;
1414 mutex_unlock(&boost_mutex);
1415
1416 /* This must be outside of the mutex, otherwise deadlock! */
1417 kthread_stop(t);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001418 boost_tasks[cpu] = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001419}
1420
1421static int rcutorture_booster_init(int cpu)
1422{
1423 int retval;
1424
1425 if (boost_tasks[cpu] != NULL)
1426 return 0; /* Already created, nothing more to do. */
1427
1428 /* Don't allow time recalculation while creating a new task. */
1429 mutex_lock(&boost_mutex);
1430 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
Eric Dumazet1f288092011-06-16 15:53:18 -07001431 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1432 cpu_to_node(cpu),
1433 "rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001434 if (IS_ERR(boost_tasks[cpu])) {
1435 retval = PTR_ERR(boost_tasks[cpu]);
1436 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1437 n_rcu_torture_boost_ktrerror++;
1438 boost_tasks[cpu] = NULL;
1439 mutex_unlock(&boost_mutex);
1440 return retval;
1441 }
1442 kthread_bind(boost_tasks[cpu], cpu);
1443 wake_up_process(boost_tasks[cpu]);
1444 mutex_unlock(&boost_mutex);
1445 return 0;
1446}
1447
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001448/*
1449 * Cause the rcutorture test to shutdown the system after the test has
1450 * run for the time specified by the shutdown_secs module parameter.
1451 */
1452static int
1453rcu_torture_shutdown(void *arg)
1454{
1455 long delta;
1456 unsigned long jiffies_snap;
1457
1458 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1459 jiffies_snap = ACCESS_ONCE(jiffies);
1460 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
1461 !kthread_should_stop()) {
1462 delta = shutdown_time - jiffies_snap;
1463 if (verbose)
1464 printk(KERN_ALERT "%s" TORTURE_FLAG
1465 "rcu_torture_shutdown task: %lu "
1466 "jiffies remaining\n",
1467 torture_type, delta);
1468 schedule_timeout_interruptible(delta);
1469 jiffies_snap = ACCESS_ONCE(jiffies);
1470 }
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001471 if (kthread_should_stop()) {
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001472 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1473 return 0;
1474 }
1475
1476 /* OK, shut down the system. */
1477
1478 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1479 shutdown_task = NULL; /* Avoid self-kill deadlock. */
1480 rcu_torture_cleanup(); /* Get the success/failure message. */
1481 kernel_power_off(); /* Shut down the system. */
1482 return 0;
1483}
1484
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001485#ifdef CONFIG_HOTPLUG_CPU
1486
1487/*
1488 * Execute random CPU-hotplug operations at the interval specified
1489 * by the onoff_interval.
1490 */
Heiko Carstens44100302011-12-27 15:04:26 +01001491static int __cpuinit
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001492rcu_torture_onoff(void *arg)
1493{
1494 int cpu;
1495 int maxcpu = -1;
1496 DEFINE_RCU_RANDOM(rand);
1497
1498 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1499 for_each_online_cpu(cpu)
1500 maxcpu = cpu;
1501 WARN_ON(maxcpu < 0);
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -08001502 if (onoff_holdoff > 0) {
1503 VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff");
1504 schedule_timeout_interruptible(onoff_holdoff * HZ);
1505 VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff");
1506 }
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001507 while (!kthread_should_stop()) {
1508 cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
Paul E. McKenneyf2202422011-12-03 15:09:28 -08001509 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001510 if (verbose)
1511 printk(KERN_ALERT "%s" TORTURE_FLAG
1512 "rcu_torture_onoff task: offlining %d\n",
1513 torture_type, cpu);
1514 n_offline_attempts++;
1515 if (cpu_down(cpu) == 0) {
1516 if (verbose)
1517 printk(KERN_ALERT "%s" TORTURE_FLAG
1518 "rcu_torture_onoff task: "
1519 "offlined %d\n",
1520 torture_type, cpu);
1521 n_offline_successes++;
1522 }
Paul E. McKenneyf2202422011-12-03 15:09:28 -08001523 } else if (cpu_is_hotpluggable(cpu)) {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001524 if (verbose)
1525 printk(KERN_ALERT "%s" TORTURE_FLAG
1526 "rcu_torture_onoff task: onlining %d\n",
1527 torture_type, cpu);
1528 n_online_attempts++;
1529 if (cpu_up(cpu) == 0) {
1530 if (verbose)
1531 printk(KERN_ALERT "%s" TORTURE_FLAG
1532 "rcu_torture_onoff task: "
1533 "onlined %d\n",
1534 torture_type, cpu);
1535 n_online_successes++;
1536 }
1537 }
1538 schedule_timeout_interruptible(onoff_interval * HZ);
1539 }
1540 VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1541 return 0;
1542}
1543
Heiko Carstens44100302011-12-27 15:04:26 +01001544static int __cpuinit
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001545rcu_torture_onoff_init(void)
1546{
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001547 int ret;
1548
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001549 if (onoff_interval <= 0)
1550 return 0;
1551 onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff");
1552 if (IS_ERR(onoff_task)) {
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001553 ret = PTR_ERR(onoff_task);
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001554 onoff_task = NULL;
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001555 return ret;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001556 }
1557 return 0;
1558}
1559
1560static void rcu_torture_onoff_cleanup(void)
1561{
1562 if (onoff_task == NULL)
1563 return;
1564 VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1565 kthread_stop(onoff_task);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001566 onoff_task = NULL;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001567}
1568
1569#else /* #ifdef CONFIG_HOTPLUG_CPU */
1570
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001571static int
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001572rcu_torture_onoff_init(void)
1573{
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001574 return 0;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001575}
1576
1577static void rcu_torture_onoff_cleanup(void)
1578{
1579}
1580
1581#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1582
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001583/*
1584 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1585 * induces a CPU stall for the time specified by stall_cpu.
1586 */
1587static int __cpuinit rcu_torture_stall(void *args)
1588{
1589 unsigned long stop_at;
1590
1591 VERBOSE_PRINTK_STRING("rcu_torture_stall task started");
1592 if (stall_cpu_holdoff > 0) {
1593 VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff");
1594 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
1595 VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff");
1596 }
1597 if (!kthread_should_stop()) {
1598 stop_at = get_seconds() + stall_cpu;
1599 /* RCU CPU stall is expected behavior in following code. */
1600 printk(KERN_ALERT "rcu_torture_stall start.\n");
1601 rcu_read_lock();
1602 preempt_disable();
1603 while (ULONG_CMP_LT(get_seconds(), stop_at))
1604 continue; /* Induce RCU CPU stall warning. */
1605 preempt_enable();
1606 rcu_read_unlock();
1607 printk(KERN_ALERT "rcu_torture_stall end.\n");
1608 }
1609 rcutorture_shutdown_absorb("rcu_torture_stall");
1610 while (!kthread_should_stop())
1611 schedule_timeout_interruptible(10 * HZ);
1612 return 0;
1613}
1614
1615/* Spawn CPU-stall kthread, if stall_cpu specified. */
1616static int __init rcu_torture_stall_init(void)
1617{
1618 int ret;
1619
1620 if (stall_cpu <= 0)
1621 return 0;
1622 stall_task = kthread_run(rcu_torture_stall, NULL, "rcu_torture_stall");
1623 if (IS_ERR(stall_task)) {
1624 ret = PTR_ERR(stall_task);
1625 stall_task = NULL;
1626 return ret;
1627 }
1628 return 0;
1629}
1630
1631/* Clean up after the CPU-stall kthread, if one was spawned. */
1632static void rcu_torture_stall_cleanup(void)
1633{
1634 if (stall_task == NULL)
1635 return;
1636 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task.");
1637 kthread_stop(stall_task);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001638 stall_task = NULL;
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001639}
1640
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001641/* Callback function for RCU barrier testing. */
1642void rcu_torture_barrier_cbf(struct rcu_head *rcu)
1643{
1644 atomic_inc(&barrier_cbs_invoked);
1645}
1646
1647/* kthread function to register callbacks used to test RCU barriers. */
1648static int rcu_torture_barrier_cbs(void *arg)
1649{
1650 long myid = (long)arg;
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001651 bool lastphase = 0;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001652 struct rcu_head rcu;
1653
1654 init_rcu_head_on_stack(&rcu);
1655 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
1656 set_user_nice(current, 19);
1657 do {
1658 wait_event(barrier_cbs_wq[myid],
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001659 barrier_phase != lastphase ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001660 kthread_should_stop() ||
1661 fullstop != FULLSTOP_DONTSTOP);
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001662 lastphase = barrier_phase;
1663 smp_mb(); /* ensure barrier_phase load before ->call(). */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001664 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1665 break;
1666 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1667 if (atomic_dec_and_test(&barrier_cbs_count))
1668 wake_up(&barrier_wq);
1669 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1670 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task stopping");
1671 rcutorture_shutdown_absorb("rcu_torture_barrier_cbs");
1672 while (!kthread_should_stop())
1673 schedule_timeout_interruptible(1);
1674 cur_ops->cb_barrier();
1675 destroy_rcu_head_on_stack(&rcu);
1676 return 0;
1677}
1678
1679/* kthread function to drive and coordinate RCU barrier testing. */
1680static int rcu_torture_barrier(void *arg)
1681{
1682 int i;
1683
1684 VERBOSE_PRINTK_STRING("rcu_torture_barrier task starting");
1685 do {
1686 atomic_set(&barrier_cbs_invoked, 0);
1687 atomic_set(&barrier_cbs_count, n_barrier_cbs);
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001688 smp_mb(); /* Ensure barrier_phase after prior assignments. */
1689 barrier_phase = !barrier_phase;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001690 for (i = 0; i < n_barrier_cbs; i++)
1691 wake_up(&barrier_cbs_wq[i]);
1692 wait_event(barrier_wq,
1693 atomic_read(&barrier_cbs_count) == 0 ||
1694 kthread_should_stop() ||
1695 fullstop != FULLSTOP_DONTSTOP);
1696 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1697 break;
1698 n_barrier_attempts++;
1699 cur_ops->cb_barrier();
1700 if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
1701 n_rcu_torture_barrier_error++;
1702 WARN_ON_ONCE(1);
1703 }
1704 n_barrier_successes++;
1705 schedule_timeout_interruptible(HZ / 10);
1706 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1707 VERBOSE_PRINTK_STRING("rcu_torture_barrier task stopping");
Paul E. McKenney143aa672012-05-24 18:17:48 -07001708 rcutorture_shutdown_absorb("rcu_torture_barrier");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001709 while (!kthread_should_stop())
1710 schedule_timeout_interruptible(1);
1711 return 0;
1712}
1713
1714/* Initialize RCU barrier testing. */
1715static int rcu_torture_barrier_init(void)
1716{
1717 int i;
1718 int ret;
1719
1720 if (n_barrier_cbs == 0)
1721 return 0;
1722 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
1723 printk(KERN_ALERT "%s" TORTURE_FLAG
1724 " Call or barrier ops missing for %s,\n",
1725 torture_type, cur_ops->name);
1726 printk(KERN_ALERT "%s" TORTURE_FLAG
1727 " RCU barrier testing omitted from run.\n",
1728 torture_type);
1729 return 0;
1730 }
1731 atomic_set(&barrier_cbs_count, 0);
1732 atomic_set(&barrier_cbs_invoked, 0);
1733 barrier_cbs_tasks =
1734 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
1735 GFP_KERNEL);
1736 barrier_cbs_wq =
1737 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
1738 GFP_KERNEL);
1739 if (barrier_cbs_tasks == NULL || barrier_cbs_wq == 0)
1740 return -ENOMEM;
1741 for (i = 0; i < n_barrier_cbs; i++) {
1742 init_waitqueue_head(&barrier_cbs_wq[i]);
1743 barrier_cbs_tasks[i] = kthread_run(rcu_torture_barrier_cbs,
Lai Jiangshan9059c942012-03-19 16:12:14 +08001744 (void *)(long)i,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001745 "rcu_torture_barrier_cbs");
1746 if (IS_ERR(barrier_cbs_tasks[i])) {
1747 ret = PTR_ERR(barrier_cbs_tasks[i]);
1748 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier_cbs");
1749 barrier_cbs_tasks[i] = NULL;
1750 return ret;
1751 }
1752 }
1753 barrier_task = kthread_run(rcu_torture_barrier, NULL,
1754 "rcu_torture_barrier");
1755 if (IS_ERR(barrier_task)) {
1756 ret = PTR_ERR(barrier_task);
1757 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier");
1758 barrier_task = NULL;
1759 }
1760 return 0;
1761}
1762
1763/* Clean up after RCU barrier testing. */
1764static void rcu_torture_barrier_cleanup(void)
1765{
1766 int i;
1767
1768 if (barrier_task != NULL) {
1769 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier task");
1770 kthread_stop(barrier_task);
1771 barrier_task = NULL;
1772 }
1773 if (barrier_cbs_tasks != NULL) {
1774 for (i = 0; i < n_barrier_cbs; i++) {
1775 if (barrier_cbs_tasks[i] != NULL) {
1776 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier_cbs task");
1777 kthread_stop(barrier_cbs_tasks[i]);
1778 barrier_cbs_tasks[i] = NULL;
1779 }
1780 }
1781 kfree(barrier_cbs_tasks);
1782 barrier_cbs_tasks = NULL;
1783 }
1784 if (barrier_cbs_wq != NULL) {
1785 kfree(barrier_cbs_wq);
1786 barrier_cbs_wq = NULL;
1787 }
1788}
1789
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001790static int rcutorture_cpu_notify(struct notifier_block *self,
1791 unsigned long action, void *hcpu)
1792{
1793 long cpu = (long)hcpu;
1794
1795 switch (action) {
1796 case CPU_ONLINE:
1797 case CPU_DOWN_FAILED:
1798 (void)rcutorture_booster_init(cpu);
1799 break;
1800 case CPU_DOWN_PREPARE:
1801 rcutorture_booster_cleanup(cpu);
1802 break;
1803 default:
1804 break;
1805 }
1806 return NOTIFY_OK;
1807}
1808
1809static struct notifier_block rcutorture_cpu_nb = {
1810 .notifier_call = rcutorture_cpu_notify,
1811};
1812
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001813static void
1814rcu_torture_cleanup(void)
1815{
1816 int i;
1817
Paul E. McKenney343e9092008-12-15 16:13:07 -08001818 mutex_lock(&fullstop_mutex);
Paul E. McKenney4a298652011-04-03 21:33:51 -07001819 rcutorture_record_test_transition();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001820 if (fullstop == FULLSTOP_SHUTDOWN) {
1821 printk(KERN_WARNING /* but going down anyway, so... */
1822 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001823 mutex_unlock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001824 schedule_timeout_uninterruptible(10);
Paul E. McKenney343e9092008-12-15 16:13:07 -08001825 if (cur_ops->cb_barrier != NULL)
1826 cur_ops->cb_barrier();
1827 return;
1828 }
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001829 fullstop = FULLSTOP_RMMOD;
Paul E. McKenney343e9092008-12-15 16:13:07 -08001830 mutex_unlock(&fullstop_mutex);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001831 unregister_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001832 rcu_torture_barrier_cleanup();
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001833 rcu_torture_stall_cleanup();
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001834 if (stutter_task) {
1835 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1836 kthread_stop(stutter_task);
1837 }
1838 stutter_task = NULL;
Josh Triplettc8e5b162007-05-08 00:33:20 -07001839 if (shuffler_task) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001840 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1841 kthread_stop(shuffler_task);
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001842 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001843 }
1844 shuffler_task = NULL;
1845
Josh Triplettc8e5b162007-05-08 00:33:20 -07001846 if (writer_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001847 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1848 kthread_stop(writer_task);
1849 }
1850 writer_task = NULL;
1851
Josh Triplettc8e5b162007-05-08 00:33:20 -07001852 if (reader_tasks) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001853 for (i = 0; i < nrealreaders; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001854 if (reader_tasks[i]) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001855 VERBOSE_PRINTK_STRING(
1856 "Stopping rcu_torture_reader task");
1857 kthread_stop(reader_tasks[i]);
1858 }
1859 reader_tasks[i] = NULL;
1860 }
1861 kfree(reader_tasks);
1862 reader_tasks = NULL;
1863 }
1864 rcu_torture_current = NULL;
1865
Josh Triplettc8e5b162007-05-08 00:33:20 -07001866 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001867 for (i = 0; i < nfakewriters; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001868 if (fakewriter_tasks[i]) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001869 VERBOSE_PRINTK_STRING(
1870 "Stopping rcu_torture_fakewriter task");
1871 kthread_stop(fakewriter_tasks[i]);
1872 }
1873 fakewriter_tasks[i] = NULL;
1874 }
1875 kfree(fakewriter_tasks);
1876 fakewriter_tasks = NULL;
1877 }
1878
Josh Triplettc8e5b162007-05-08 00:33:20 -07001879 if (stats_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001880 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1881 kthread_stop(stats_task);
1882 }
1883 stats_task = NULL;
1884
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001885 if (fqs_task) {
1886 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1887 kthread_stop(fqs_task);
1888 }
1889 fqs_task = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001890 if ((test_boost == 1 && cur_ops->can_boost) ||
1891 test_boost == 2) {
1892 unregister_cpu_notifier(&rcutorture_cpu_nb);
1893 for_each_possible_cpu(i)
1894 rcutorture_booster_cleanup(i);
1895 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001896 if (shutdown_task != NULL) {
1897 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1898 kthread_stop(shutdown_task);
1899 }
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001900 shutdown_task = NULL;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001901 rcu_torture_onoff_cleanup();
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001902
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001903 /* Wait for all RCU callbacks to fire. */
Paul E. McKenney23269742008-05-12 21:21:05 +02001904
1905 if (cur_ops->cb_barrier != NULL)
1906 cur_ops->cb_barrier();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001907
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001908 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001909
Josh Triplettc8e5b162007-05-08 00:33:20 -07001910 if (cur_ops->cleanup)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001911 cur_ops->cleanup();
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001912 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001913 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
Paul E. McKenney091541b2012-01-10 12:51:14 -08001914 else if (n_online_successes != n_online_attempts ||
1915 n_offline_successes != n_offline_attempts)
1916 rcu_torture_print_module_parms(cur_ops,
1917 "End of test: RCU_HOTPLUG");
Paul E. McKenney95c38322006-03-24 03:15:58 -08001918 else
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001919 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001920}
1921
Josh Triplett6f8bc502007-05-08 00:25:24 -07001922static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001923rcu_torture_init(void)
1924{
1925 int i;
1926 int cpu;
1927 int firsterr = 0;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001928 int retval;
Josh Triplettade5fb82007-05-08 00:33:22 -07001929 static struct rcu_torture_ops *torture_ops[] =
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -08001930 { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -07001931 &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops,
Paul E. McKenney751a68b2012-05-07 13:44:44 -07001932 &srcu_ops, &srcu_sync_ops, &srcu_expedited_ops,
1933 &srcu_raw_ops, &srcu_raw_sync_ops,
Paul E. McKenney804bb832009-10-25 19:03:52 -07001934 &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001935
Paul E. McKenney343e9092008-12-15 16:13:07 -08001936 mutex_lock(&fullstop_mutex);
1937
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001938 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001939 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001940 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001941 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001942 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001943 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001944 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001945 printk(KERN_ALERT "rcu-torture: invalid torture type: \"%s\"\n",
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001946 torture_type);
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001947 printk(KERN_ALERT "rcu-torture types:");
1948 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
1949 printk(KERN_ALERT " %s", torture_ops[i]->name);
1950 printk(KERN_ALERT "\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001951 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001952 return -EINVAL;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001953 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001954 if (cur_ops->fqs == NULL && fqs_duration != 0) {
1955 printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero "
1956 "fqs_duration, fqs disabled.\n");
1957 fqs_duration = 0;
1958 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001959 if (cur_ops->init)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001960 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1961
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001962 if (nreaders >= 0)
1963 nrealreaders = nreaders;
1964 else
1965 nrealreaders = 2 * num_online_cpus();
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001966 rcu_torture_print_module_parms(cur_ops, "Start of test");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001967 fullstop = FULLSTOP_DONTSTOP;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001968
1969 /* Set up the freelist. */
1970
1971 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07001972 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08001973 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001974 list_add_tail(&rcu_tortures[i].rtort_free,
1975 &rcu_torture_freelist);
1976 }
1977
1978 /* Initialize the statistics so that each run gets its own numbers. */
1979
1980 rcu_torture_current = NULL;
1981 rcu_torture_current_version = 0;
1982 atomic_set(&n_rcu_torture_alloc, 0);
1983 atomic_set(&n_rcu_torture_alloc_fail, 0);
1984 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001985 atomic_set(&n_rcu_torture_mberror, 0);
1986 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001987 n_rcu_torture_barrier_error = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001988 n_rcu_torture_boost_ktrerror = 0;
1989 n_rcu_torture_boost_rterror = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001990 n_rcu_torture_boost_failure = 0;
1991 n_rcu_torture_boosts = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001992 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1993 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001994 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001995 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1996 per_cpu(rcu_torture_count, cpu)[i] = 0;
1997 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1998 }
1999 }
2000
2001 /* Start up the kthreads. */
2002
2003 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
2004 writer_task = kthread_run(rcu_torture_writer, NULL,
2005 "rcu_torture_writer");
2006 if (IS_ERR(writer_task)) {
2007 firsterr = PTR_ERR(writer_task);
2008 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
2009 writer_task = NULL;
2010 goto unwind;
2011 }
Josh Triplettb772e1d2006-10-04 02:17:13 -07002012 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
Paul E. McKenneya71fca52009-09-18 10:28:19 -07002013 GFP_KERNEL);
Josh Triplettb772e1d2006-10-04 02:17:13 -07002014 if (fakewriter_tasks == NULL) {
2015 VERBOSE_PRINTK_ERRSTRING("out of memory");
2016 firsterr = -ENOMEM;
2017 goto unwind;
2018 }
2019 for (i = 0; i < nfakewriters; i++) {
2020 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
2021 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -07002022 "rcu_torture_fakewriter");
Josh Triplettb772e1d2006-10-04 02:17:13 -07002023 if (IS_ERR(fakewriter_tasks[i])) {
2024 firsterr = PTR_ERR(fakewriter_tasks[i]);
2025 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
2026 fakewriter_tasks[i] = NULL;
2027 goto unwind;
2028 }
2029 }
Josh Triplett2860aab2006-10-04 02:17:11 -07002030 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002031 GFP_KERNEL);
2032 if (reader_tasks == NULL) {
2033 VERBOSE_PRINTK_ERRSTRING("out of memory");
2034 firsterr = -ENOMEM;
2035 goto unwind;
2036 }
2037 for (i = 0; i < nrealreaders; i++) {
2038 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
2039 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
2040 "rcu_torture_reader");
2041 if (IS_ERR(reader_tasks[i])) {
2042 firsterr = PTR_ERR(reader_tasks[i]);
2043 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
2044 reader_tasks[i] = NULL;
2045 goto unwind;
2046 }
2047 }
2048 if (stat_interval > 0) {
2049 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
2050 stats_task = kthread_run(rcu_torture_stats, NULL,
2051 "rcu_torture_stats");
2052 if (IS_ERR(stats_task)) {
2053 firsterr = PTR_ERR(stats_task);
2054 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
2055 stats_task = NULL;
2056 goto unwind;
2057 }
2058 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08002059 if (test_no_idle_hz) {
2060 rcu_idle_cpu = num_online_cpus() - 1;
Rusty Russell73d0a4b2009-03-30 22:05:16 -06002061
2062 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
2063 firsterr = -ENOMEM;
2064 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
2065 goto unwind;
2066 }
2067
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08002068 /* Create the shuffler thread */
2069 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
2070 "rcu_torture_shuffle");
2071 if (IS_ERR(shuffler_task)) {
Rusty Russell73d0a4b2009-03-30 22:05:16 -06002072 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08002073 firsterr = PTR_ERR(shuffler_task);
2074 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
2075 shuffler_task = NULL;
2076 goto unwind;
2077 }
2078 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07002079 if (stutter < 0)
2080 stutter = 0;
2081 if (stutter) {
2082 /* Create the stutter thread */
2083 stutter_task = kthread_run(rcu_torture_stutter, NULL,
2084 "rcu_torture_stutter");
2085 if (IS_ERR(stutter_task)) {
2086 firsterr = PTR_ERR(stutter_task);
2087 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
2088 stutter_task = NULL;
2089 goto unwind;
2090 }
2091 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08002092 if (fqs_duration < 0)
2093 fqs_duration = 0;
2094 if (fqs_duration) {
2095 /* Create the stutter thread */
2096 fqs_task = kthread_run(rcu_torture_fqs, NULL,
2097 "rcu_torture_fqs");
2098 if (IS_ERR(fqs_task)) {
2099 firsterr = PTR_ERR(fqs_task);
2100 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
2101 fqs_task = NULL;
2102 goto unwind;
2103 }
2104 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002105 if (test_boost_interval < 1)
2106 test_boost_interval = 1;
2107 if (test_boost_duration < 2)
2108 test_boost_duration = 2;
2109 if ((test_boost == 1 && cur_ops->can_boost) ||
2110 test_boost == 2) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002111
2112 boost_starttime = jiffies + test_boost_interval * HZ;
2113 register_cpu_notifier(&rcutorture_cpu_nb);
2114 for_each_possible_cpu(i) {
2115 if (cpu_is_offline(i))
2116 continue; /* Heuristic: CPU can go offline. */
2117 retval = rcutorture_booster_init(i);
2118 if (retval < 0) {
2119 firsterr = retval;
2120 goto unwind;
2121 }
2122 }
2123 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07002124 if (shutdown_secs > 0) {
2125 shutdown_time = jiffies + shutdown_secs * HZ;
2126 shutdown_task = kthread_run(rcu_torture_shutdown, NULL,
2127 "rcu_torture_shutdown");
2128 if (IS_ERR(shutdown_task)) {
2129 firsterr = PTR_ERR(shutdown_task);
2130 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
2131 shutdown_task = NULL;
2132 goto unwind;
2133 }
2134 }
Paul E. McKenney37e377d2012-02-17 22:12:18 -08002135 i = rcu_torture_onoff_init();
2136 if (i != 0) {
2137 firsterr = i;
2138 goto unwind;
2139 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002140 register_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08002141 i = rcu_torture_stall_init();
2142 if (i != 0) {
2143 firsterr = i;
2144 goto unwind;
2145 }
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08002146 retval = rcu_torture_barrier_init();
2147 if (retval != 0) {
2148 firsterr = retval;
2149 goto unwind;
2150 }
Paul E. McKenney4a298652011-04-03 21:33:51 -07002151 rcutorture_record_test_transition();
Paul E. McKenney343e9092008-12-15 16:13:07 -08002152 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002153 return 0;
2154
2155unwind:
Paul E. McKenney343e9092008-12-15 16:13:07 -08002156 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002157 rcu_torture_cleanup();
2158 return firsterr;
2159}
2160
2161module_init(rcu_torture_init);
2162module_exit(rcu_torture_cleanup);