blob: 7b6935e0cee32512bdb8c831c234f8143661e862 [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. */
209static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */
210static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */
211static DECLARE_WAIT_QUEUE_HEAD(barrier_wq);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700212
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800213/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
214
215#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
216#define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
217#define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
218static int fullstop = FULLSTOP_RMMOD;
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700219/*
220 * Protect fullstop transitions and spawning of kthreads.
221 */
222static DEFINE_MUTEX(fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800223
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700224/* Forward reference. */
225static void rcu_torture_cleanup(void);
226
Paul E. McKenney343e9092008-12-15 16:13:07 -0800227/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800228 * Detect and respond to a system shutdown.
Paul E. McKenney343e9092008-12-15 16:13:07 -0800229 */
230static int
231rcutorture_shutdown_notify(struct notifier_block *unused1,
232 unsigned long unused2, void *unused3)
233{
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800234 mutex_lock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800235 if (fullstop == FULLSTOP_DONTSTOP)
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800236 fullstop = FULLSTOP_SHUTDOWN;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800237 else
238 printk(KERN_WARNING /* but going down anyway, so... */
239 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800240 mutex_unlock(&fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800241 return NOTIFY_DONE;
242}
243
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800244/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800245 * Absorb kthreads into a kernel function that won't return, so that
246 * they won't ever access module text or data again.
247 */
248static void rcutorture_shutdown_absorb(char *title)
249{
250 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
251 printk(KERN_NOTICE
252 "rcutorture thread %s parking due to system shutdown\n",
253 title);
254 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
255 }
256}
257
258/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800259 * Allocate an element from the rcu_tortures pool.
260 */
Adrian Bunk97a41e22006-01-08 01:02:17 -0800261static struct rcu_torture *
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800262rcu_torture_alloc(void)
263{
264 struct list_head *p;
265
Ingo Molnaradac1662006-01-25 19:50:12 +0100266 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800267 if (list_empty(&rcu_torture_freelist)) {
268 atomic_inc(&n_rcu_torture_alloc_fail);
Ingo Molnaradac1662006-01-25 19:50:12 +0100269 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800270 return NULL;
271 }
272 atomic_inc(&n_rcu_torture_alloc);
273 p = rcu_torture_freelist.next;
274 list_del_init(p);
Ingo Molnaradac1662006-01-25 19:50:12 +0100275 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800276 return container_of(p, struct rcu_torture, rtort_free);
277}
278
279/*
280 * Free an element to the rcu_tortures pool.
281 */
282static void
283rcu_torture_free(struct rcu_torture *p)
284{
285 atomic_inc(&n_rcu_torture_free);
Ingo Molnaradac1662006-01-25 19:50:12 +0100286 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800287 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
Ingo Molnaradac1662006-01-25 19:50:12 +0100288 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800289}
290
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800291struct rcu_random_state {
292 unsigned long rrs_state;
Josh Triplett75cfef32006-10-04 02:17:12 -0700293 long rrs_count;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800294};
295
296#define RCU_RANDOM_MULT 39916801 /* prime */
297#define RCU_RANDOM_ADD 479001701 /* prime */
298#define RCU_RANDOM_REFRESH 10000
299
300#define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
301
302/*
303 * Crude but fast random-number generator. Uses a linear congruential
Paul E. McKenneyc17ac852007-10-16 23:27:19 -0700304 * generator, with occasional help from cpu_clock().
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800305 */
Josh Triplett75cfef32006-10-04 02:17:12 -0700306static unsigned long
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800307rcu_random(struct rcu_random_state *rrsp)
308{
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800309 if (--rrsp->rrs_count < 0) {
Peter Zijlstrac6763292010-05-25 10:48:51 +0200310 rrsp->rrs_state += (unsigned long)local_clock();
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800311 rrsp->rrs_count = RCU_RANDOM_REFRESH;
312 }
313 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
314 return swahw32(rrsp->rrs_state);
315}
316
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700317static void
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800318rcu_stutter_wait(char *title)
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700319{
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800320 while (stutter_pause_test || !rcutorture_runnable) {
Paul E. McKenneye3d7be22008-06-22 13:06:38 -0700321 if (rcutorture_runnable)
322 schedule_timeout_interruptible(1);
323 else
Paul E. McKenney3ccf79f2008-06-22 14:02:55 -0700324 schedule_timeout_interruptible(round_jiffies_relative(HZ));
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800325 rcutorture_shutdown_absorb(title);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800326 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700327}
328
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800329/*
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700330 * Operations vector for selecting different types of tests.
331 */
332
333struct rcu_torture_ops {
334 void (*init)(void);
335 void (*cleanup)(void);
336 int (*readlock)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700337 void (*read_delay)(struct rcu_random_state *rrsp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700338 void (*readunlock)(int idx);
339 int (*completed)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700340 void (*deferred_free)(struct rcu_torture *p);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700341 void (*sync)(void);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800342 void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu));
Paul E. McKenney23269742008-05-12 21:21:05 +0200343 void (*cb_barrier)(void);
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800344 void (*fqs)(void);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700345 int (*stats)(char *page);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700346 int irq_capable;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700347 int can_boost;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700348 char *name;
349};
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700350
351static struct rcu_torture_ops *cur_ops;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700352
353/*
354 * Definitions for rcu torture testing.
355 */
356
Josh Tripletta49a4af2006-09-29 01:59:30 -0700357static int rcu_torture_read_lock(void) __acquires(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700358{
359 rcu_read_lock();
360 return 0;
361}
362
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700363static void rcu_read_delay(struct rcu_random_state *rrsp)
364{
Josh Triplettb8d57a72009-09-08 15:54:35 -0700365 const unsigned long shortdelay_us = 200;
366 const unsigned long longdelay_ms = 50;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700367
Josh Triplettb8d57a72009-09-08 15:54:35 -0700368 /* We want a short delay sometimes to make a reader delay the grace
369 * period, and we want a long delay occasionally to trigger
370 * force_quiescent_state. */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700371
Josh Triplettb8d57a72009-09-08 15:54:35 -0700372 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
373 mdelay(longdelay_ms);
374 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
375 udelay(shortdelay_us);
Lai Jiangshane546f482010-06-21 16:57:42 +0800376#ifdef CONFIG_PREEMPT
377 if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000)))
378 preempt_schedule(); /* No QS if preempt_disable() in effect */
379#endif
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700380}
381
Josh Tripletta49a4af2006-09-29 01:59:30 -0700382static void rcu_torture_read_unlock(int idx) __releases(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700383{
384 rcu_read_unlock();
385}
386
387static int rcu_torture_completed(void)
388{
389 return rcu_batches_completed();
390}
391
392static void
393rcu_torture_cb(struct rcu_head *p)
394{
395 int i;
396 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
397
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800398 if (fullstop != FULLSTOP_DONTSTOP) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700399 /* Test is ending, just drop callbacks on the floor. */
400 /* The next initialization will pick up the pieces. */
401 return;
402 }
403 i = rp->rtort_pipe_count;
404 if (i > RCU_TORTURE_PIPE_LEN)
405 i = RCU_TORTURE_PIPE_LEN;
406 atomic_inc(&rcu_torture_wcount[i]);
407 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
408 rp->rtort_mbtest = 0;
409 rcu_torture_free(rp);
410 } else
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700411 cur_ops->deferred_free(rp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700412}
413
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800414static int rcu_no_completed(void)
415{
416 return 0;
417}
418
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700419static void rcu_torture_deferred_free(struct rcu_torture *p)
420{
421 call_rcu(&p->rtort_rcu, rcu_torture_cb);
422}
423
424static struct rcu_torture_ops rcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700425 .init = NULL,
426 .cleanup = NULL,
427 .readlock = rcu_torture_read_lock,
428 .read_delay = rcu_read_delay,
429 .readunlock = rcu_torture_read_unlock,
430 .completed = rcu_torture_completed,
431 .deferred_free = rcu_torture_deferred_free,
432 .sync = synchronize_rcu,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800433 .call = call_rcu,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700434 .cb_barrier = rcu_barrier,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800435 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700436 .stats = NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700437 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700438 .can_boost = rcu_can_boost(),
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700439 .name = "rcu"
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700440};
441
Josh Triplette3033732006-10-04 02:17:14 -0700442static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
443{
444 int i;
445 struct rcu_torture *rp;
446 struct rcu_torture *rp1;
447
448 cur_ops->sync();
449 list_add(&p->rtort_free, &rcu_torture_removed);
450 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
451 i = rp->rtort_pipe_count;
452 if (i > RCU_TORTURE_PIPE_LEN)
453 i = RCU_TORTURE_PIPE_LEN;
454 atomic_inc(&rcu_torture_wcount[i]);
455 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
456 rp->rtort_mbtest = 0;
457 list_del(&rp->rtort_free);
458 rcu_torture_free(rp);
459 }
460 }
461}
462
463static void rcu_sync_torture_init(void)
464{
465 INIT_LIST_HEAD(&rcu_torture_removed);
466}
467
Josh Triplett20d2e422006-10-04 02:17:15 -0700468static struct rcu_torture_ops rcu_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700469 .init = rcu_sync_torture_init,
470 .cleanup = NULL,
471 .readlock = rcu_torture_read_lock,
472 .read_delay = rcu_read_delay,
473 .readunlock = rcu_torture_read_unlock,
474 .completed = rcu_torture_completed,
475 .deferred_free = rcu_sync_torture_deferred_free,
476 .sync = synchronize_rcu,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800477 .call = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700478 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800479 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700480 .stats = NULL,
481 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700482 .can_boost = rcu_can_boost(),
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700483 .name = "rcu_sync"
Josh Triplett20d2e422006-10-04 02:17:15 -0700484};
485
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800486static struct rcu_torture_ops rcu_expedited_ops = {
487 .init = rcu_sync_torture_init,
488 .cleanup = NULL,
489 .readlock = rcu_torture_read_lock,
490 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
491 .readunlock = rcu_torture_read_unlock,
492 .completed = rcu_no_completed,
493 .deferred_free = rcu_sync_torture_deferred_free,
494 .sync = synchronize_rcu_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800495 .call = NULL,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800496 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800497 .fqs = rcu_force_quiescent_state,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800498 .stats = NULL,
499 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700500 .can_boost = rcu_can_boost(),
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800501 .name = "rcu_expedited"
502};
503
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700504/*
505 * Definitions for rcu_bh torture testing.
506 */
507
Josh Tripletta49a4af2006-09-29 01:59:30 -0700508static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700509{
510 rcu_read_lock_bh();
511 return 0;
512}
513
Josh Tripletta49a4af2006-09-29 01:59:30 -0700514static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700515{
516 rcu_read_unlock_bh();
517}
518
519static int rcu_bh_torture_completed(void)
520{
521 return rcu_batches_completed_bh();
522}
523
524static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
525{
526 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
527}
528
529static struct rcu_torture_ops rcu_bh_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700530 .init = NULL,
531 .cleanup = NULL,
532 .readlock = rcu_bh_torture_read_lock,
533 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
534 .readunlock = rcu_bh_torture_read_unlock,
535 .completed = rcu_bh_torture_completed,
536 .deferred_free = rcu_bh_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700537 .sync = synchronize_rcu_bh,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800538 .call = call_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700539 .cb_barrier = rcu_barrier_bh,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800540 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700541 .stats = NULL,
542 .irq_capable = 1,
543 .name = "rcu_bh"
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700544};
545
Josh Triplett11a14702006-10-04 02:17:16 -0700546static struct rcu_torture_ops rcu_bh_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700547 .init = rcu_sync_torture_init,
548 .cleanup = NULL,
549 .readlock = rcu_bh_torture_read_lock,
550 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
551 .readunlock = rcu_bh_torture_read_unlock,
552 .completed = rcu_bh_torture_completed,
553 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700554 .sync = synchronize_rcu_bh,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800555 .call = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700556 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800557 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700558 .stats = NULL,
559 .irq_capable = 1,
560 .name = "rcu_bh_sync"
Josh Triplett11a14702006-10-04 02:17:16 -0700561};
562
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700563static struct rcu_torture_ops rcu_bh_expedited_ops = {
564 .init = rcu_sync_torture_init,
565 .cleanup = NULL,
566 .readlock = rcu_bh_torture_read_lock,
567 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
568 .readunlock = rcu_bh_torture_read_unlock,
569 .completed = rcu_bh_torture_completed,
570 .deferred_free = rcu_sync_torture_deferred_free,
571 .sync = synchronize_rcu_bh_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800572 .call = NULL,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700573 .cb_barrier = NULL,
574 .fqs = rcu_bh_force_quiescent_state,
575 .stats = NULL,
576 .irq_capable = 1,
577 .name = "rcu_bh_expedited"
578};
579
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700580/*
581 * Definitions for srcu torture testing.
582 */
583
584static struct srcu_struct srcu_ctl;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700585
586static void srcu_torture_init(void)
587{
588 init_srcu_struct(&srcu_ctl);
Josh Triplette3033732006-10-04 02:17:14 -0700589 rcu_sync_torture_init();
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700590}
591
592static void srcu_torture_cleanup(void)
593{
594 synchronize_srcu(&srcu_ctl);
595 cleanup_srcu_struct(&srcu_ctl);
596}
597
Josh Triplett012d3ca2006-12-06 20:40:19 -0800598static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700599{
600 return srcu_read_lock(&srcu_ctl);
601}
602
603static void srcu_read_delay(struct rcu_random_state *rrsp)
604{
605 long delay;
606 const long uspertick = 1000000 / HZ;
607 const long longdelay = 10;
608
609 /* We want there to be long-running readers, but not all the time. */
610
611 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
612 if (!delay)
613 schedule_timeout_interruptible(longdelay);
Lai Jiangshane546f482010-06-21 16:57:42 +0800614 else
615 rcu_read_delay(rrsp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700616}
617
Josh Triplett012d3ca2006-12-06 20:40:19 -0800618static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700619{
620 srcu_read_unlock(&srcu_ctl, idx);
621}
622
623static int srcu_torture_completed(void)
624{
625 return srcu_batches_completed(&srcu_ctl);
626}
627
Lai Jiangshan9059c942012-03-19 16:12:14 +0800628static void srcu_torture_deferred_free(struct rcu_torture *rp)
629{
630 call_srcu(&srcu_ctl, &rp->rtort_rcu, rcu_torture_cb);
631}
632
Josh Triplettb772e1d2006-10-04 02:17:13 -0700633static void srcu_torture_synchronize(void)
634{
635 synchronize_srcu(&srcu_ctl);
636}
637
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700638static void srcu_torture_call(struct rcu_head *head,
639 void (*func)(struct rcu_head *head))
640{
641 call_srcu(&srcu_ctl, head, func);
642}
643
644static void srcu_torture_barrier(void)
645{
646 srcu_barrier(&srcu_ctl);
647}
648
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700649static int srcu_torture_stats(char *page)
650{
651 int cnt = 0;
652 int cpu;
653 int idx = srcu_ctl.completed & 0x1;
654
655 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
656 torture_type, TORTURE_FLAG, idx);
657 for_each_possible_cpu(cpu) {
Paul E. McKenneycef50122012-02-05 07:42:44 -0800658 cnt += sprintf(&page[cnt], " %d(%lu,%lu)", cpu,
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700659 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
660 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
661 }
662 cnt += sprintf(&page[cnt], "\n");
663 return cnt;
664}
665
666static struct rcu_torture_ops srcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700667 .init = srcu_torture_init,
668 .cleanup = srcu_torture_cleanup,
669 .readlock = srcu_torture_read_lock,
670 .read_delay = srcu_read_delay,
671 .readunlock = srcu_torture_read_unlock,
672 .completed = srcu_torture_completed,
Lai Jiangshan9059c942012-03-19 16:12:14 +0800673 .deferred_free = srcu_torture_deferred_free,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700674 .sync = srcu_torture_synchronize,
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700675 .call = srcu_torture_call,
676 .cb_barrier = srcu_torture_barrier,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700677 .stats = srcu_torture_stats,
678 .name = "srcu"
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700679};
680
Lai Jiangshan9059c942012-03-19 16:12:14 +0800681static struct rcu_torture_ops srcu_sync_ops = {
682 .init = srcu_torture_init,
683 .cleanup = srcu_torture_cleanup,
684 .readlock = srcu_torture_read_lock,
685 .read_delay = srcu_read_delay,
686 .readunlock = srcu_torture_read_unlock,
687 .completed = srcu_torture_completed,
688 .deferred_free = rcu_sync_torture_deferred_free,
689 .sync = srcu_torture_synchronize,
690 .call = NULL,
691 .cb_barrier = NULL,
692 .stats = srcu_torture_stats,
693 .name = "srcu_sync"
694};
695
Paul E. McKenney101db7b2011-12-05 15:36:31 -0800696static int srcu_torture_read_lock_raw(void) __acquires(&srcu_ctl)
697{
698 return srcu_read_lock_raw(&srcu_ctl);
699}
700
701static void srcu_torture_read_unlock_raw(int idx) __releases(&srcu_ctl)
702{
703 srcu_read_unlock_raw(&srcu_ctl, idx);
704}
705
706static struct rcu_torture_ops srcu_raw_ops = {
707 .init = srcu_torture_init,
708 .cleanup = srcu_torture_cleanup,
709 .readlock = srcu_torture_read_lock_raw,
710 .read_delay = srcu_read_delay,
711 .readunlock = srcu_torture_read_unlock_raw,
712 .completed = srcu_torture_completed,
Lai Jiangshan9059c942012-03-19 16:12:14 +0800713 .deferred_free = srcu_torture_deferred_free,
Paul E. McKenney101db7b2011-12-05 15:36:31 -0800714 .sync = srcu_torture_synchronize,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800715 .call = NULL,
Paul E. McKenney101db7b2011-12-05 15:36:31 -0800716 .cb_barrier = NULL,
717 .stats = srcu_torture_stats,
718 .name = "srcu_raw"
719};
720
Lai Jiangshan9059c942012-03-19 16:12:14 +0800721static struct rcu_torture_ops srcu_raw_sync_ops = {
722 .init = srcu_torture_init,
723 .cleanup = srcu_torture_cleanup,
724 .readlock = srcu_torture_read_lock_raw,
725 .read_delay = srcu_read_delay,
726 .readunlock = srcu_torture_read_unlock_raw,
727 .completed = srcu_torture_completed,
728 .deferred_free = rcu_sync_torture_deferred_free,
729 .sync = srcu_torture_synchronize,
730 .call = NULL,
731 .cb_barrier = NULL,
732 .stats = srcu_torture_stats,
733 .name = "srcu_raw_sync"
734};
735
Paul E. McKenney804bb832009-10-25 19:03:52 -0700736static void srcu_torture_synchronize_expedited(void)
737{
738 synchronize_srcu_expedited(&srcu_ctl);
739}
740
741static struct rcu_torture_ops srcu_expedited_ops = {
742 .init = srcu_torture_init,
743 .cleanup = srcu_torture_cleanup,
744 .readlock = srcu_torture_read_lock,
745 .read_delay = srcu_read_delay,
746 .readunlock = srcu_torture_read_unlock,
747 .completed = srcu_torture_completed,
748 .deferred_free = rcu_sync_torture_deferred_free,
749 .sync = srcu_torture_synchronize_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800750 .call = NULL,
Paul E. McKenney804bb832009-10-25 19:03:52 -0700751 .cb_barrier = NULL,
752 .stats = srcu_torture_stats,
753 .name = "srcu_expedited"
754};
755
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700756/*
757 * Definitions for sched torture testing.
758 */
759
760static int sched_torture_read_lock(void)
761{
762 preempt_disable();
763 return 0;
764}
765
766static void sched_torture_read_unlock(int idx)
767{
768 preempt_enable();
769}
770
Paul E. McKenney23269742008-05-12 21:21:05 +0200771static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
772{
773 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
774}
775
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700776static struct rcu_torture_ops sched_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700777 .init = rcu_sync_torture_init,
778 .cleanup = NULL,
779 .readlock = sched_torture_read_lock,
780 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
781 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800782 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700783 .deferred_free = rcu_sched_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700784 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700785 .cb_barrier = rcu_barrier_sched,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800786 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700787 .stats = NULL,
788 .irq_capable = 1,
789 .name = "sched"
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700790};
791
Paul E. McKenney804bb832009-10-25 19:03:52 -0700792static struct rcu_torture_ops sched_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700793 .init = rcu_sync_torture_init,
794 .cleanup = NULL,
795 .readlock = sched_torture_read_lock,
796 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
797 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800798 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700799 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700800 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700801 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800802 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700803 .stats = NULL,
804 .name = "sched_sync"
805};
806
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700807static struct rcu_torture_ops sched_expedited_ops = {
808 .init = rcu_sync_torture_init,
809 .cleanup = NULL,
810 .readlock = sched_torture_read_lock,
811 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
812 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800813 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700814 .deferred_free = rcu_sync_torture_deferred_free,
815 .sync = synchronize_sched_expedited,
816 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800817 .fqs = rcu_sched_force_quiescent_state,
Tejun Heo969c7922010-05-06 18:49:21 +0200818 .stats = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700819 .irq_capable = 1,
820 .name = "sched_expedited"
Paul E. McKenney23269742008-05-12 21:21:05 +0200821};
822
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700823/*
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700824 * RCU torture priority-boost testing. Runs one real-time thread per
825 * CPU for moderate bursts, repeatedly registering RCU callbacks and
826 * spinning waiting for them to be invoked. If a given callback takes
827 * too long to be invoked, we assume that priority inversion has occurred.
828 */
829
830struct rcu_boost_inflight {
831 struct rcu_head rcu;
832 int inflight;
833};
834
835static void rcu_torture_boost_cb(struct rcu_head *head)
836{
837 struct rcu_boost_inflight *rbip =
838 container_of(head, struct rcu_boost_inflight, rcu);
839
840 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
841 rbip->inflight = 0;
842}
843
844static int rcu_torture_boost(void *arg)
845{
846 unsigned long call_rcu_time;
847 unsigned long endtime;
848 unsigned long oldstarttime;
849 struct rcu_boost_inflight rbi = { .inflight = 0 };
850 struct sched_param sp;
851
852 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
853
854 /* Set real-time priority. */
855 sp.sched_priority = 1;
856 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
857 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
858 n_rcu_torture_boost_rterror++;
859 }
860
Paul E. McKenney561190e2011-03-30 09:10:44 -0700861 init_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700862 /* Each pass through the following loop does one boost-test cycle. */
863 do {
864 /* Wait for the next test interval. */
865 oldstarttime = boost_starttime;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700866 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700867 schedule_timeout_uninterruptible(1);
868 rcu_stutter_wait("rcu_torture_boost");
869 if (kthread_should_stop() ||
870 fullstop != FULLSTOP_DONTSTOP)
871 goto checkwait;
872 }
873
874 /* Do one boost-test interval. */
875 endtime = oldstarttime + test_boost_duration * HZ;
876 call_rcu_time = jiffies;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700877 while (ULONG_CMP_LT(jiffies, endtime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700878 /* If we don't have a callback in flight, post one. */
879 if (!rbi.inflight) {
880 smp_mb(); /* RCU core before ->inflight = 1. */
881 rbi.inflight = 1;
882 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
883 if (jiffies - call_rcu_time >
884 test_boost_duration * HZ - HZ / 2) {
885 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
886 n_rcu_torture_boost_failure++;
887 }
888 call_rcu_time = jiffies;
889 }
890 cond_resched();
891 rcu_stutter_wait("rcu_torture_boost");
892 if (kthread_should_stop() ||
893 fullstop != FULLSTOP_DONTSTOP)
894 goto checkwait;
895 }
896
897 /*
898 * Set the start time of the next test interval.
899 * Yes, this is vulnerable to long delays, but such
900 * delays simply cause a false negative for the next
901 * interval. Besides, we are running at RT priority,
902 * so delays should be relatively rare.
903 */
Paul E. McKenneyab8f11e2011-08-18 09:30:32 -0700904 while (oldstarttime == boost_starttime &&
905 !kthread_should_stop()) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700906 if (mutex_trylock(&boost_mutex)) {
907 boost_starttime = jiffies +
908 test_boost_interval * HZ;
909 n_rcu_torture_boosts++;
910 mutex_unlock(&boost_mutex);
911 break;
912 }
913 schedule_timeout_uninterruptible(1);
914 }
915
916 /* Go do the stutter. */
917checkwait: rcu_stutter_wait("rcu_torture_boost");
918 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
919
920 /* Clean up and exit. */
921 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
922 rcutorture_shutdown_absorb("rcu_torture_boost");
923 while (!kthread_should_stop() || rbi.inflight)
924 schedule_timeout_uninterruptible(1);
925 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
Paul E. McKenney9d681972011-06-21 01:48:03 -0700926 destroy_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700927 return 0;
928}
929
930/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800931 * RCU torture force-quiescent-state kthread. Repeatedly induces
932 * bursts of calls to force_quiescent_state(), increasing the probability
933 * of occurrence of some important types of race conditions.
934 */
935static int
936rcu_torture_fqs(void *arg)
937{
938 unsigned long fqs_resume_time;
939 int fqs_burst_remaining;
940
941 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
942 do {
943 fqs_resume_time = jiffies + fqs_stutter * HZ;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700944 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
945 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800946 schedule_timeout_interruptible(1);
947 }
948 fqs_burst_remaining = fqs_duration;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700949 while (fqs_burst_remaining > 0 &&
950 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800951 cur_ops->fqs();
952 udelay(fqs_holdoff);
953 fqs_burst_remaining -= fqs_holdoff;
954 }
955 rcu_stutter_wait("rcu_torture_fqs");
956 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
957 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
958 rcutorture_shutdown_absorb("rcu_torture_fqs");
959 while (!kthread_should_stop())
960 schedule_timeout_uninterruptible(1);
961 return 0;
962}
963
964/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800965 * RCU torture writer kthread. Repeatedly substitutes a new structure
966 * for that pointed to by rcu_torture_current, freeing the old structure
967 * after a series of grace periods (the "pipeline").
968 */
969static int
970rcu_torture_writer(void *arg)
971{
972 int i;
973 long oldbatch = rcu_batches_completed();
974 struct rcu_torture *rp;
975 struct rcu_torture *old_rp;
976 static DEFINE_RCU_RANDOM(rand);
977
978 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800979 set_user_nice(current, 19);
980
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800981 do {
982 schedule_timeout_uninterruptible(1);
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700983 rp = rcu_torture_alloc();
984 if (rp == NULL)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800985 continue;
986 rp->rtort_pipe_count = 0;
987 udelay(rcu_random(&rand) & 0x3ff);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700988 old_rp = rcu_dereference_check(rcu_torture_current,
989 current == writer_task);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800990 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800991 rcu_assign_pointer(rcu_torture_current, rp);
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700992 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
Josh Triplettc8e5b162007-05-08 00:33:20 -0700993 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800994 i = old_rp->rtort_pipe_count;
995 if (i > RCU_TORTURE_PIPE_LEN)
996 i = RCU_TORTURE_PIPE_LEN;
997 atomic_inc(&rcu_torture_wcount[i]);
998 old_rp->rtort_pipe_count++;
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700999 cur_ops->deferred_free(old_rp);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001000 }
Paul E. McKenney4a298652011-04-03 21:33:51 -07001001 rcutorture_record_progress(++rcu_torture_current_version);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001002 oldbatch = cur_ops->completed();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001003 rcu_stutter_wait("rcu_torture_writer");
1004 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001005 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001006 rcutorture_shutdown_absorb("rcu_torture_writer");
1007 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001008 schedule_timeout_uninterruptible(1);
1009 return 0;
1010}
1011
1012/*
Josh Triplettb772e1d2006-10-04 02:17:13 -07001013 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
1014 * delay between calls.
1015 */
1016static int
1017rcu_torture_fakewriter(void *arg)
1018{
1019 DEFINE_RCU_RANDOM(rand);
1020
1021 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
1022 set_user_nice(current, 19);
1023
1024 do {
1025 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
1026 udelay(rcu_random(&rand) & 0x3ff);
1027 cur_ops->sync();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001028 rcu_stutter_wait("rcu_torture_fakewriter");
1029 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001030
1031 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001032 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
1033 while (!kthread_should_stop())
Josh Triplettb772e1d2006-10-04 02:17:13 -07001034 schedule_timeout_uninterruptible(1);
1035 return 0;
1036}
1037
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001038void rcutorture_trace_dump(void)
1039{
1040 static atomic_t beenhere = ATOMIC_INIT(0);
1041
1042 if (atomic_read(&beenhere))
1043 return;
1044 if (atomic_xchg(&beenhere, 1) != 0)
1045 return;
1046 do_trace_rcu_torture_read(cur_ops->name, (struct rcu_head *)~0UL);
1047 ftrace_dump(DUMP_ALL);
1048}
1049
Josh Triplettb772e1d2006-10-04 02:17:13 -07001050/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001051 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
1052 * incrementing the corresponding element of the pipeline array. The
1053 * counter in the element should never be greater than 1, otherwise, the
1054 * RCU implementation is broken.
1055 */
1056static void rcu_torture_timer(unsigned long unused)
1057{
1058 int idx;
1059 int completed;
1060 static DEFINE_RCU_RANDOM(rand);
1061 static DEFINE_SPINLOCK(rand_lock);
1062 struct rcu_torture *p;
1063 int pipe_count;
1064
1065 idx = cur_ops->readlock();
1066 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001067 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001068 rcu_read_lock_bh_held() ||
1069 rcu_read_lock_sched_held() ||
1070 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001071 if (p == NULL) {
1072 /* Leave because rcu_torture_writer is not yet underway */
1073 cur_ops->readunlock(idx);
1074 return;
1075 }
Paul E. McKenney7129d382012-01-31 16:46:34 -08001076 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001077 if (p->rtort_mbtest == 0)
1078 atomic_inc(&n_rcu_torture_mberror);
1079 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001080 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001081 n_rcu_torture_timers++;
1082 spin_unlock(&rand_lock);
1083 preempt_disable();
1084 pipe_count = p->rtort_pipe_count;
1085 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1086 /* Should not happen, but... */
1087 pipe_count = RCU_TORTURE_PIPE_LEN;
1088 }
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001089 if (pipe_count > 1)
1090 rcutorture_trace_dump();
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001091 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001092 completed = cur_ops->completed() - completed;
1093 if (completed > RCU_TORTURE_PIPE_LEN) {
1094 /* Should not happen, but... */
1095 completed = RCU_TORTURE_PIPE_LEN;
1096 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001097 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001098 preempt_enable();
1099 cur_ops->readunlock(idx);
1100}
1101
1102/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001103 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
1104 * incrementing the corresponding element of the pipeline array. The
1105 * counter in the element should never be greater than 1, otherwise, the
1106 * RCU implementation is broken.
1107 */
1108static int
1109rcu_torture_reader(void *arg)
1110{
1111 int completed;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001112 int idx;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001113 DEFINE_RCU_RANDOM(rand);
1114 struct rcu_torture *p;
1115 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001116 struct timer_list t;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001117
1118 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001119 set_user_nice(current, 19);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001120 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001121 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001122
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001123 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001124 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001125 if (!timer_pending(&t))
Paul E. McKenney6155fec2010-02-22 17:05:04 -08001126 mod_timer(&t, jiffies + 1);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001127 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001128 idx = cur_ops->readlock();
1129 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001130 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001131 rcu_read_lock_bh_held() ||
1132 rcu_read_lock_sched_held() ||
1133 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001134 if (p == NULL) {
1135 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001136 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001137 schedule_timeout_interruptible(HZ);
1138 continue;
1139 }
Paul E. McKenney7129d382012-01-31 16:46:34 -08001140 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001141 if (p->rtort_mbtest == 0)
1142 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001143 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001144 preempt_disable();
1145 pipe_count = p->rtort_pipe_count;
1146 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1147 /* Should not happen, but... */
1148 pipe_count = RCU_TORTURE_PIPE_LEN;
1149 }
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001150 if (pipe_count > 1)
1151 rcutorture_trace_dump();
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001152 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001153 completed = cur_ops->completed() - completed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001154 if (completed > RCU_TORTURE_PIPE_LEN) {
1155 /* Should not happen, but... */
1156 completed = RCU_TORTURE_PIPE_LEN;
1157 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001158 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001159 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001160 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001161 schedule();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001162 rcu_stutter_wait("rcu_torture_reader");
1163 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001164 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001165 rcutorture_shutdown_absorb("rcu_torture_reader");
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001166 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001167 del_timer_sync(&t);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001168 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001169 schedule_timeout_uninterruptible(1);
1170 return 0;
1171}
1172
1173/*
1174 * Create an RCU-torture statistics message in the specified buffer.
1175 */
1176static int
1177rcu_torture_printk(char *page)
1178{
1179 int cnt = 0;
1180 int cpu;
1181 int i;
1182 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1183 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1184
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001185 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001186 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1187 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1188 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1189 }
1190 }
1191 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1192 if (pipesummary[i] != 0)
1193 break;
1194 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001195 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001196 cnt += sprintf(&page[cnt],
Paul E. McKenney4a298652011-04-03 21:33:51 -07001197 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d "
Paul E. McKenney67b98db2011-02-21 13:31:55 -08001198 "rtmbe: %d rtbke: %ld rtbre: %ld "
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001199 "rtbf: %ld rtb: %ld nt: %ld "
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001200 "onoff: %ld/%ld:%ld/%ld "
1201 "barrier: %ld/%ld:%ld",
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001202 rcu_torture_current,
1203 rcu_torture_current_version,
1204 list_empty(&rcu_torture_freelist),
1205 atomic_read(&n_rcu_torture_alloc),
1206 atomic_read(&n_rcu_torture_alloc_fail),
Paul E. McKenney996417d2005-11-18 01:10:50 -08001207 atomic_read(&n_rcu_torture_free),
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001208 atomic_read(&n_rcu_torture_mberror),
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001209 n_rcu_torture_boost_ktrerror,
1210 n_rcu_torture_boost_rterror,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001211 n_rcu_torture_boost_failure,
1212 n_rcu_torture_boosts,
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001213 n_rcu_torture_timers,
1214 n_online_successes,
1215 n_online_attempts,
1216 n_offline_successes,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001217 n_offline_attempts,
1218 n_barrier_successes,
1219 n_barrier_attempts,
1220 n_rcu_torture_barrier_error);
1221 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001222 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001223 n_rcu_torture_barrier_error != 0 ||
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001224 n_rcu_torture_boost_ktrerror != 0 ||
1225 n_rcu_torture_boost_rterror != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001226 n_rcu_torture_boost_failure != 0 ||
1227 i > 1) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001228 cnt += sprintf(&page[cnt], "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -08001229 atomic_inc(&n_rcu_torture_error);
Ingo Molnar5af970a2008-06-18 10:09:48 +02001230 WARN_ON_ONCE(1);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001231 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001232 cnt += sprintf(&page[cnt], "Reader Pipe: ");
1233 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1234 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001235 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001236 cnt += sprintf(&page[cnt], "Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001237 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001238 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001239 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001240 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
1241 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1242 cnt += sprintf(&page[cnt], " %d",
1243 atomic_read(&rcu_torture_wcount[i]));
1244 }
1245 cnt += sprintf(&page[cnt], "\n");
Josh Triplettc8e5b162007-05-08 00:33:20 -07001246 if (cur_ops->stats)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001247 cnt += cur_ops->stats(&page[cnt]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001248 return cnt;
1249}
1250
1251/*
1252 * Print torture statistics. Caller must ensure that there is only
1253 * one call to this function at a given time!!! This is normally
1254 * accomplished by relying on the module system to only have one copy
1255 * of the module loaded, and then by giving the rcu_torture_stats
1256 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1257 * thread is not running).
1258 */
1259static void
1260rcu_torture_stats_print(void)
1261{
1262 int cnt;
1263
1264 cnt = rcu_torture_printk(printk_buf);
1265 printk(KERN_ALERT "%s", printk_buf);
1266}
1267
1268/*
1269 * Periodically prints torture statistics, if periodic statistics printing
1270 * was specified via the stat_interval module parameter.
1271 *
1272 * No need to worry about fullstop here, since this one doesn't reference
1273 * volatile state or register callbacks.
1274 */
1275static int
1276rcu_torture_stats(void *arg)
1277{
1278 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1279 do {
1280 schedule_timeout_interruptible(stat_interval * HZ);
1281 rcu_torture_stats_print();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001282 rcutorture_shutdown_absorb("rcu_torture_stats");
1283 } while (!kthread_should_stop());
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001284 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1285 return 0;
1286}
1287
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001288static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
1289
1290/* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1291 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1292 */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -07001293static void rcu_torture_shuffle_tasks(void)
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001294{
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001295 int i;
1296
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001297 cpumask_setall(shuffle_tmp_mask);
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001298 get_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001299
1300 /* No point in shuffling if there is only one online CPU (ex: UP) */
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001301 if (num_online_cpus() == 1) {
1302 put_online_cpus();
1303 return;
1304 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001305
1306 if (rcu_idle_cpu != -1)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001307 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001308
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001309 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001310
Josh Triplettc8e5b162007-05-08 00:33:20 -07001311 if (reader_tasks) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001312 for (i = 0; i < nrealreaders; i++)
1313 if (reader_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001314 set_cpus_allowed_ptr(reader_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001315 shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001316 }
1317
Josh Triplettc8e5b162007-05-08 00:33:20 -07001318 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001319 for (i = 0; i < nfakewriters; i++)
1320 if (fakewriter_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001321 set_cpus_allowed_ptr(fakewriter_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001322 shuffle_tmp_mask);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001323 }
1324
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001325 if (writer_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001326 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001327
1328 if (stats_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001329 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001330
1331 if (rcu_idle_cpu == -1)
1332 rcu_idle_cpu = num_online_cpus() - 1;
1333 else
1334 rcu_idle_cpu--;
1335
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001336 put_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001337}
1338
1339/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1340 * system to become idle at a time and cut off its timer ticks. This is meant
1341 * to test the support for such tickless idle CPU in RCU.
1342 */
1343static int
1344rcu_torture_shuffle(void *arg)
1345{
1346 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1347 do {
1348 schedule_timeout_interruptible(shuffle_interval * HZ);
1349 rcu_torture_shuffle_tasks();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001350 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1351 } while (!kthread_should_stop());
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001352 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1353 return 0;
1354}
1355
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001356/* Cause the rcutorture test to "stutter", starting and stopping all
1357 * threads periodically.
1358 */
1359static int
1360rcu_torture_stutter(void *arg)
1361{
1362 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1363 do {
1364 schedule_timeout_interruptible(stutter * HZ);
1365 stutter_pause_test = 1;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001366 if (!kthread_should_stop())
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001367 schedule_timeout_interruptible(stutter * HZ);
1368 stutter_pause_test = 0;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001369 rcutorture_shutdown_absorb("rcu_torture_stutter");
1370 } while (!kthread_should_stop());
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001371 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1372 return 0;
1373}
1374
Paul E. McKenney95c38322006-03-24 03:15:58 -08001375static inline void
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001376rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
Paul E. McKenney95c38322006-03-24 03:15:58 -08001377{
Josh Triplettb772e1d2006-10-04 02:17:13 -07001378 printk(KERN_ALERT "%s" TORTURE_FLAG
1379 "--- %s: nreaders=%d nfakewriters=%d "
Paul E. McKenney95c38322006-03-24 03:15:58 -08001380 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001381 "shuffle_interval=%d stutter=%d irqreader=%d "
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001382 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1383 "test_boost=%d/%d test_boost_interval=%d "
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001384 "test_boost_duration=%d shutdown_secs=%d "
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -08001385 "onoff_interval=%d onoff_holdoff=%d\n",
Josh Triplettb772e1d2006-10-04 02:17:13 -07001386 torture_type, tag, nrealreaders, nfakewriters,
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001387 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001388 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1389 test_boost, cur_ops->can_boost,
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001390 test_boost_interval, test_boost_duration, shutdown_secs,
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -08001391 onoff_interval, onoff_holdoff);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001392}
1393
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001394static struct notifier_block rcutorture_shutdown_nb = {
Paul E. McKenney343e9092008-12-15 16:13:07 -08001395 .notifier_call = rcutorture_shutdown_notify,
1396};
1397
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001398static void rcutorture_booster_cleanup(int cpu)
1399{
1400 struct task_struct *t;
1401
1402 if (boost_tasks[cpu] == NULL)
1403 return;
1404 mutex_lock(&boost_mutex);
1405 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1406 t = boost_tasks[cpu];
1407 boost_tasks[cpu] = NULL;
1408 mutex_unlock(&boost_mutex);
1409
1410 /* This must be outside of the mutex, otherwise deadlock! */
1411 kthread_stop(t);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001412 boost_tasks[cpu] = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001413}
1414
1415static int rcutorture_booster_init(int cpu)
1416{
1417 int retval;
1418
1419 if (boost_tasks[cpu] != NULL)
1420 return 0; /* Already created, nothing more to do. */
1421
1422 /* Don't allow time recalculation while creating a new task. */
1423 mutex_lock(&boost_mutex);
1424 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
Eric Dumazet1f288092011-06-16 15:53:18 -07001425 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1426 cpu_to_node(cpu),
1427 "rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001428 if (IS_ERR(boost_tasks[cpu])) {
1429 retval = PTR_ERR(boost_tasks[cpu]);
1430 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1431 n_rcu_torture_boost_ktrerror++;
1432 boost_tasks[cpu] = NULL;
1433 mutex_unlock(&boost_mutex);
1434 return retval;
1435 }
1436 kthread_bind(boost_tasks[cpu], cpu);
1437 wake_up_process(boost_tasks[cpu]);
1438 mutex_unlock(&boost_mutex);
1439 return 0;
1440}
1441
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001442/*
1443 * Cause the rcutorture test to shutdown the system after the test has
1444 * run for the time specified by the shutdown_secs module parameter.
1445 */
1446static int
1447rcu_torture_shutdown(void *arg)
1448{
1449 long delta;
1450 unsigned long jiffies_snap;
1451
1452 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1453 jiffies_snap = ACCESS_ONCE(jiffies);
1454 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
1455 !kthread_should_stop()) {
1456 delta = shutdown_time - jiffies_snap;
1457 if (verbose)
1458 printk(KERN_ALERT "%s" TORTURE_FLAG
1459 "rcu_torture_shutdown task: %lu "
1460 "jiffies remaining\n",
1461 torture_type, delta);
1462 schedule_timeout_interruptible(delta);
1463 jiffies_snap = ACCESS_ONCE(jiffies);
1464 }
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001465 if (kthread_should_stop()) {
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001466 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1467 return 0;
1468 }
1469
1470 /* OK, shut down the system. */
1471
1472 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1473 shutdown_task = NULL; /* Avoid self-kill deadlock. */
1474 rcu_torture_cleanup(); /* Get the success/failure message. */
1475 kernel_power_off(); /* Shut down the system. */
1476 return 0;
1477}
1478
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001479#ifdef CONFIG_HOTPLUG_CPU
1480
1481/*
1482 * Execute random CPU-hotplug operations at the interval specified
1483 * by the onoff_interval.
1484 */
Heiko Carstens44100302011-12-27 15:04:26 +01001485static int __cpuinit
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001486rcu_torture_onoff(void *arg)
1487{
1488 int cpu;
1489 int maxcpu = -1;
1490 DEFINE_RCU_RANDOM(rand);
1491
1492 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1493 for_each_online_cpu(cpu)
1494 maxcpu = cpu;
1495 WARN_ON(maxcpu < 0);
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -08001496 if (onoff_holdoff > 0) {
1497 VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff");
1498 schedule_timeout_interruptible(onoff_holdoff * HZ);
1499 VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff");
1500 }
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001501 while (!kthread_should_stop()) {
1502 cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
Paul E. McKenneyf2202422011-12-03 15:09:28 -08001503 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001504 if (verbose)
1505 printk(KERN_ALERT "%s" TORTURE_FLAG
1506 "rcu_torture_onoff task: offlining %d\n",
1507 torture_type, cpu);
1508 n_offline_attempts++;
1509 if (cpu_down(cpu) == 0) {
1510 if (verbose)
1511 printk(KERN_ALERT "%s" TORTURE_FLAG
1512 "rcu_torture_onoff task: "
1513 "offlined %d\n",
1514 torture_type, cpu);
1515 n_offline_successes++;
1516 }
Paul E. McKenneyf2202422011-12-03 15:09:28 -08001517 } else if (cpu_is_hotpluggable(cpu)) {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001518 if (verbose)
1519 printk(KERN_ALERT "%s" TORTURE_FLAG
1520 "rcu_torture_onoff task: onlining %d\n",
1521 torture_type, cpu);
1522 n_online_attempts++;
1523 if (cpu_up(cpu) == 0) {
1524 if (verbose)
1525 printk(KERN_ALERT "%s" TORTURE_FLAG
1526 "rcu_torture_onoff task: "
1527 "onlined %d\n",
1528 torture_type, cpu);
1529 n_online_successes++;
1530 }
1531 }
1532 schedule_timeout_interruptible(onoff_interval * HZ);
1533 }
1534 VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1535 return 0;
1536}
1537
Heiko Carstens44100302011-12-27 15:04:26 +01001538static int __cpuinit
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001539rcu_torture_onoff_init(void)
1540{
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001541 int ret;
1542
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001543 if (onoff_interval <= 0)
1544 return 0;
1545 onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff");
1546 if (IS_ERR(onoff_task)) {
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001547 ret = PTR_ERR(onoff_task);
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001548 onoff_task = NULL;
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001549 return ret;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001550 }
1551 return 0;
1552}
1553
1554static void rcu_torture_onoff_cleanup(void)
1555{
1556 if (onoff_task == NULL)
1557 return;
1558 VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1559 kthread_stop(onoff_task);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001560 onoff_task = NULL;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001561}
1562
1563#else /* #ifdef CONFIG_HOTPLUG_CPU */
1564
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001565static int
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001566rcu_torture_onoff_init(void)
1567{
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001568 return 0;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001569}
1570
1571static void rcu_torture_onoff_cleanup(void)
1572{
1573}
1574
1575#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1576
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001577/*
1578 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1579 * induces a CPU stall for the time specified by stall_cpu.
1580 */
1581static int __cpuinit rcu_torture_stall(void *args)
1582{
1583 unsigned long stop_at;
1584
1585 VERBOSE_PRINTK_STRING("rcu_torture_stall task started");
1586 if (stall_cpu_holdoff > 0) {
1587 VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff");
1588 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
1589 VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff");
1590 }
1591 if (!kthread_should_stop()) {
1592 stop_at = get_seconds() + stall_cpu;
1593 /* RCU CPU stall is expected behavior in following code. */
1594 printk(KERN_ALERT "rcu_torture_stall start.\n");
1595 rcu_read_lock();
1596 preempt_disable();
1597 while (ULONG_CMP_LT(get_seconds(), stop_at))
1598 continue; /* Induce RCU CPU stall warning. */
1599 preempt_enable();
1600 rcu_read_unlock();
1601 printk(KERN_ALERT "rcu_torture_stall end.\n");
1602 }
1603 rcutorture_shutdown_absorb("rcu_torture_stall");
1604 while (!kthread_should_stop())
1605 schedule_timeout_interruptible(10 * HZ);
1606 return 0;
1607}
1608
1609/* Spawn CPU-stall kthread, if stall_cpu specified. */
1610static int __init rcu_torture_stall_init(void)
1611{
1612 int ret;
1613
1614 if (stall_cpu <= 0)
1615 return 0;
1616 stall_task = kthread_run(rcu_torture_stall, NULL, "rcu_torture_stall");
1617 if (IS_ERR(stall_task)) {
1618 ret = PTR_ERR(stall_task);
1619 stall_task = NULL;
1620 return ret;
1621 }
1622 return 0;
1623}
1624
1625/* Clean up after the CPU-stall kthread, if one was spawned. */
1626static void rcu_torture_stall_cleanup(void)
1627{
1628 if (stall_task == NULL)
1629 return;
1630 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task.");
1631 kthread_stop(stall_task);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001632 stall_task = NULL;
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001633}
1634
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001635/* Callback function for RCU barrier testing. */
1636void rcu_torture_barrier_cbf(struct rcu_head *rcu)
1637{
1638 atomic_inc(&barrier_cbs_invoked);
1639}
1640
1641/* kthread function to register callbacks used to test RCU barriers. */
1642static int rcu_torture_barrier_cbs(void *arg)
1643{
1644 long myid = (long)arg;
1645 struct rcu_head rcu;
1646
1647 init_rcu_head_on_stack(&rcu);
1648 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
1649 set_user_nice(current, 19);
1650 do {
1651 wait_event(barrier_cbs_wq[myid],
1652 atomic_read(&barrier_cbs_count) == n_barrier_cbs ||
1653 kthread_should_stop() ||
1654 fullstop != FULLSTOP_DONTSTOP);
1655 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1656 break;
1657 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1658 if (atomic_dec_and_test(&barrier_cbs_count))
1659 wake_up(&barrier_wq);
1660 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1661 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task stopping");
1662 rcutorture_shutdown_absorb("rcu_torture_barrier_cbs");
1663 while (!kthread_should_stop())
1664 schedule_timeout_interruptible(1);
1665 cur_ops->cb_barrier();
1666 destroy_rcu_head_on_stack(&rcu);
1667 return 0;
1668}
1669
1670/* kthread function to drive and coordinate RCU barrier testing. */
1671static int rcu_torture_barrier(void *arg)
1672{
1673 int i;
1674
1675 VERBOSE_PRINTK_STRING("rcu_torture_barrier task starting");
1676 do {
1677 atomic_set(&barrier_cbs_invoked, 0);
1678 atomic_set(&barrier_cbs_count, n_barrier_cbs);
1679 /* wake_up() path contains the required barriers. */
1680 for (i = 0; i < n_barrier_cbs; i++)
1681 wake_up(&barrier_cbs_wq[i]);
1682 wait_event(barrier_wq,
1683 atomic_read(&barrier_cbs_count) == 0 ||
1684 kthread_should_stop() ||
1685 fullstop != FULLSTOP_DONTSTOP);
1686 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1687 break;
1688 n_barrier_attempts++;
1689 cur_ops->cb_barrier();
1690 if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
1691 n_rcu_torture_barrier_error++;
1692 WARN_ON_ONCE(1);
1693 }
1694 n_barrier_successes++;
1695 schedule_timeout_interruptible(HZ / 10);
1696 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1697 VERBOSE_PRINTK_STRING("rcu_torture_barrier task stopping");
1698 rcutorture_shutdown_absorb("rcu_torture_barrier_cbs");
1699 while (!kthread_should_stop())
1700 schedule_timeout_interruptible(1);
1701 return 0;
1702}
1703
1704/* Initialize RCU barrier testing. */
1705static int rcu_torture_barrier_init(void)
1706{
1707 int i;
1708 int ret;
1709
1710 if (n_barrier_cbs == 0)
1711 return 0;
1712 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
1713 printk(KERN_ALERT "%s" TORTURE_FLAG
1714 " Call or barrier ops missing for %s,\n",
1715 torture_type, cur_ops->name);
1716 printk(KERN_ALERT "%s" TORTURE_FLAG
1717 " RCU barrier testing omitted from run.\n",
1718 torture_type);
1719 return 0;
1720 }
1721 atomic_set(&barrier_cbs_count, 0);
1722 atomic_set(&barrier_cbs_invoked, 0);
1723 barrier_cbs_tasks =
1724 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
1725 GFP_KERNEL);
1726 barrier_cbs_wq =
1727 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
1728 GFP_KERNEL);
1729 if (barrier_cbs_tasks == NULL || barrier_cbs_wq == 0)
1730 return -ENOMEM;
1731 for (i = 0; i < n_barrier_cbs; i++) {
1732 init_waitqueue_head(&barrier_cbs_wq[i]);
1733 barrier_cbs_tasks[i] = kthread_run(rcu_torture_barrier_cbs,
Lai Jiangshan9059c942012-03-19 16:12:14 +08001734 (void *)(long)i,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001735 "rcu_torture_barrier_cbs");
1736 if (IS_ERR(barrier_cbs_tasks[i])) {
1737 ret = PTR_ERR(barrier_cbs_tasks[i]);
1738 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier_cbs");
1739 barrier_cbs_tasks[i] = NULL;
1740 return ret;
1741 }
1742 }
1743 barrier_task = kthread_run(rcu_torture_barrier, NULL,
1744 "rcu_torture_barrier");
1745 if (IS_ERR(barrier_task)) {
1746 ret = PTR_ERR(barrier_task);
1747 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier");
1748 barrier_task = NULL;
1749 }
1750 return 0;
1751}
1752
1753/* Clean up after RCU barrier testing. */
1754static void rcu_torture_barrier_cleanup(void)
1755{
1756 int i;
1757
1758 if (barrier_task != NULL) {
1759 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier task");
1760 kthread_stop(barrier_task);
1761 barrier_task = NULL;
1762 }
1763 if (barrier_cbs_tasks != NULL) {
1764 for (i = 0; i < n_barrier_cbs; i++) {
1765 if (barrier_cbs_tasks[i] != NULL) {
1766 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier_cbs task");
1767 kthread_stop(barrier_cbs_tasks[i]);
1768 barrier_cbs_tasks[i] = NULL;
1769 }
1770 }
1771 kfree(barrier_cbs_tasks);
1772 barrier_cbs_tasks = NULL;
1773 }
1774 if (barrier_cbs_wq != NULL) {
1775 kfree(barrier_cbs_wq);
1776 barrier_cbs_wq = NULL;
1777 }
1778}
1779
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001780static int rcutorture_cpu_notify(struct notifier_block *self,
1781 unsigned long action, void *hcpu)
1782{
1783 long cpu = (long)hcpu;
1784
1785 switch (action) {
1786 case CPU_ONLINE:
1787 case CPU_DOWN_FAILED:
1788 (void)rcutorture_booster_init(cpu);
1789 break;
1790 case CPU_DOWN_PREPARE:
1791 rcutorture_booster_cleanup(cpu);
1792 break;
1793 default:
1794 break;
1795 }
1796 return NOTIFY_OK;
1797}
1798
1799static struct notifier_block rcutorture_cpu_nb = {
1800 .notifier_call = rcutorture_cpu_notify,
1801};
1802
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001803static void
1804rcu_torture_cleanup(void)
1805{
1806 int i;
1807
Paul E. McKenney343e9092008-12-15 16:13:07 -08001808 mutex_lock(&fullstop_mutex);
Paul E. McKenney4a298652011-04-03 21:33:51 -07001809 rcutorture_record_test_transition();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001810 if (fullstop == FULLSTOP_SHUTDOWN) {
1811 printk(KERN_WARNING /* but going down anyway, so... */
1812 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001813 mutex_unlock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001814 schedule_timeout_uninterruptible(10);
Paul E. McKenney343e9092008-12-15 16:13:07 -08001815 if (cur_ops->cb_barrier != NULL)
1816 cur_ops->cb_barrier();
1817 return;
1818 }
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001819 fullstop = FULLSTOP_RMMOD;
Paul E. McKenney343e9092008-12-15 16:13:07 -08001820 mutex_unlock(&fullstop_mutex);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001821 unregister_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001822 rcu_torture_barrier_cleanup();
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001823 rcu_torture_stall_cleanup();
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001824 if (stutter_task) {
1825 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1826 kthread_stop(stutter_task);
1827 }
1828 stutter_task = NULL;
Josh Triplettc8e5b162007-05-08 00:33:20 -07001829 if (shuffler_task) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001830 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1831 kthread_stop(shuffler_task);
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001832 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001833 }
1834 shuffler_task = NULL;
1835
Josh Triplettc8e5b162007-05-08 00:33:20 -07001836 if (writer_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001837 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1838 kthread_stop(writer_task);
1839 }
1840 writer_task = NULL;
1841
Josh Triplettc8e5b162007-05-08 00:33:20 -07001842 if (reader_tasks) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001843 for (i = 0; i < nrealreaders; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001844 if (reader_tasks[i]) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001845 VERBOSE_PRINTK_STRING(
1846 "Stopping rcu_torture_reader task");
1847 kthread_stop(reader_tasks[i]);
1848 }
1849 reader_tasks[i] = NULL;
1850 }
1851 kfree(reader_tasks);
1852 reader_tasks = NULL;
1853 }
1854 rcu_torture_current = NULL;
1855
Josh Triplettc8e5b162007-05-08 00:33:20 -07001856 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001857 for (i = 0; i < nfakewriters; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001858 if (fakewriter_tasks[i]) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001859 VERBOSE_PRINTK_STRING(
1860 "Stopping rcu_torture_fakewriter task");
1861 kthread_stop(fakewriter_tasks[i]);
1862 }
1863 fakewriter_tasks[i] = NULL;
1864 }
1865 kfree(fakewriter_tasks);
1866 fakewriter_tasks = NULL;
1867 }
1868
Josh Triplettc8e5b162007-05-08 00:33:20 -07001869 if (stats_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001870 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1871 kthread_stop(stats_task);
1872 }
1873 stats_task = NULL;
1874
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001875 if (fqs_task) {
1876 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1877 kthread_stop(fqs_task);
1878 }
1879 fqs_task = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001880 if ((test_boost == 1 && cur_ops->can_boost) ||
1881 test_boost == 2) {
1882 unregister_cpu_notifier(&rcutorture_cpu_nb);
1883 for_each_possible_cpu(i)
1884 rcutorture_booster_cleanup(i);
1885 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001886 if (shutdown_task != NULL) {
1887 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1888 kthread_stop(shutdown_task);
1889 }
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001890 shutdown_task = NULL;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001891 rcu_torture_onoff_cleanup();
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001892
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001893 /* Wait for all RCU callbacks to fire. */
Paul E. McKenney23269742008-05-12 21:21:05 +02001894
1895 if (cur_ops->cb_barrier != NULL)
1896 cur_ops->cb_barrier();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001897
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001898 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001899
Josh Triplettc8e5b162007-05-08 00:33:20 -07001900 if (cur_ops->cleanup)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001901 cur_ops->cleanup();
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001902 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001903 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
Paul E. McKenney091541b2012-01-10 12:51:14 -08001904 else if (n_online_successes != n_online_attempts ||
1905 n_offline_successes != n_offline_attempts)
1906 rcu_torture_print_module_parms(cur_ops,
1907 "End of test: RCU_HOTPLUG");
Paul E. McKenney95c38322006-03-24 03:15:58 -08001908 else
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001909 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001910}
1911
Josh Triplett6f8bc502007-05-08 00:25:24 -07001912static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001913rcu_torture_init(void)
1914{
1915 int i;
1916 int cpu;
1917 int firsterr = 0;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001918 int retval;
Josh Triplettade5fb82007-05-08 00:33:22 -07001919 static struct rcu_torture_ops *torture_ops[] =
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -08001920 { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -07001921 &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops,
Paul E. McKenney751a68b2012-05-07 13:44:44 -07001922 &srcu_ops, &srcu_sync_ops, &srcu_expedited_ops,
1923 &srcu_raw_ops, &srcu_raw_sync_ops,
Paul E. McKenney804bb832009-10-25 19:03:52 -07001924 &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001925
Paul E. McKenney343e9092008-12-15 16:13:07 -08001926 mutex_lock(&fullstop_mutex);
1927
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001928 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001929 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001930 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001931 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001932 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001933 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001934 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001935 printk(KERN_ALERT "rcu-torture: invalid torture type: \"%s\"\n",
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001936 torture_type);
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001937 printk(KERN_ALERT "rcu-torture types:");
1938 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
1939 printk(KERN_ALERT " %s", torture_ops[i]->name);
1940 printk(KERN_ALERT "\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001941 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001942 return -EINVAL;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001943 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001944 if (cur_ops->fqs == NULL && fqs_duration != 0) {
1945 printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero "
1946 "fqs_duration, fqs disabled.\n");
1947 fqs_duration = 0;
1948 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001949 if (cur_ops->init)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001950 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1951
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001952 if (nreaders >= 0)
1953 nrealreaders = nreaders;
1954 else
1955 nrealreaders = 2 * num_online_cpus();
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001956 rcu_torture_print_module_parms(cur_ops, "Start of test");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001957 fullstop = FULLSTOP_DONTSTOP;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001958
1959 /* Set up the freelist. */
1960
1961 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07001962 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08001963 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001964 list_add_tail(&rcu_tortures[i].rtort_free,
1965 &rcu_torture_freelist);
1966 }
1967
1968 /* Initialize the statistics so that each run gets its own numbers. */
1969
1970 rcu_torture_current = NULL;
1971 rcu_torture_current_version = 0;
1972 atomic_set(&n_rcu_torture_alloc, 0);
1973 atomic_set(&n_rcu_torture_alloc_fail, 0);
1974 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001975 atomic_set(&n_rcu_torture_mberror, 0);
1976 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001977 n_rcu_torture_barrier_error = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001978 n_rcu_torture_boost_ktrerror = 0;
1979 n_rcu_torture_boost_rterror = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001980 n_rcu_torture_boost_failure = 0;
1981 n_rcu_torture_boosts = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001982 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1983 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001984 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001985 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1986 per_cpu(rcu_torture_count, cpu)[i] = 0;
1987 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1988 }
1989 }
1990
1991 /* Start up the kthreads. */
1992
1993 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1994 writer_task = kthread_run(rcu_torture_writer, NULL,
1995 "rcu_torture_writer");
1996 if (IS_ERR(writer_task)) {
1997 firsterr = PTR_ERR(writer_task);
1998 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1999 writer_task = NULL;
2000 goto unwind;
2001 }
Josh Triplettb772e1d2006-10-04 02:17:13 -07002002 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
Paul E. McKenneya71fca52009-09-18 10:28:19 -07002003 GFP_KERNEL);
Josh Triplettb772e1d2006-10-04 02:17:13 -07002004 if (fakewriter_tasks == NULL) {
2005 VERBOSE_PRINTK_ERRSTRING("out of memory");
2006 firsterr = -ENOMEM;
2007 goto unwind;
2008 }
2009 for (i = 0; i < nfakewriters; i++) {
2010 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
2011 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -07002012 "rcu_torture_fakewriter");
Josh Triplettb772e1d2006-10-04 02:17:13 -07002013 if (IS_ERR(fakewriter_tasks[i])) {
2014 firsterr = PTR_ERR(fakewriter_tasks[i]);
2015 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
2016 fakewriter_tasks[i] = NULL;
2017 goto unwind;
2018 }
2019 }
Josh Triplett2860aab2006-10-04 02:17:11 -07002020 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002021 GFP_KERNEL);
2022 if (reader_tasks == NULL) {
2023 VERBOSE_PRINTK_ERRSTRING("out of memory");
2024 firsterr = -ENOMEM;
2025 goto unwind;
2026 }
2027 for (i = 0; i < nrealreaders; i++) {
2028 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
2029 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
2030 "rcu_torture_reader");
2031 if (IS_ERR(reader_tasks[i])) {
2032 firsterr = PTR_ERR(reader_tasks[i]);
2033 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
2034 reader_tasks[i] = NULL;
2035 goto unwind;
2036 }
2037 }
2038 if (stat_interval > 0) {
2039 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
2040 stats_task = kthread_run(rcu_torture_stats, NULL,
2041 "rcu_torture_stats");
2042 if (IS_ERR(stats_task)) {
2043 firsterr = PTR_ERR(stats_task);
2044 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
2045 stats_task = NULL;
2046 goto unwind;
2047 }
2048 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08002049 if (test_no_idle_hz) {
2050 rcu_idle_cpu = num_online_cpus() - 1;
Rusty Russell73d0a4b2009-03-30 22:05:16 -06002051
2052 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
2053 firsterr = -ENOMEM;
2054 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
2055 goto unwind;
2056 }
2057
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08002058 /* Create the shuffler thread */
2059 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
2060 "rcu_torture_shuffle");
2061 if (IS_ERR(shuffler_task)) {
Rusty Russell73d0a4b2009-03-30 22:05:16 -06002062 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08002063 firsterr = PTR_ERR(shuffler_task);
2064 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
2065 shuffler_task = NULL;
2066 goto unwind;
2067 }
2068 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07002069 if (stutter < 0)
2070 stutter = 0;
2071 if (stutter) {
2072 /* Create the stutter thread */
2073 stutter_task = kthread_run(rcu_torture_stutter, NULL,
2074 "rcu_torture_stutter");
2075 if (IS_ERR(stutter_task)) {
2076 firsterr = PTR_ERR(stutter_task);
2077 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
2078 stutter_task = NULL;
2079 goto unwind;
2080 }
2081 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08002082 if (fqs_duration < 0)
2083 fqs_duration = 0;
2084 if (fqs_duration) {
2085 /* Create the stutter thread */
2086 fqs_task = kthread_run(rcu_torture_fqs, NULL,
2087 "rcu_torture_fqs");
2088 if (IS_ERR(fqs_task)) {
2089 firsterr = PTR_ERR(fqs_task);
2090 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
2091 fqs_task = NULL;
2092 goto unwind;
2093 }
2094 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002095 if (test_boost_interval < 1)
2096 test_boost_interval = 1;
2097 if (test_boost_duration < 2)
2098 test_boost_duration = 2;
2099 if ((test_boost == 1 && cur_ops->can_boost) ||
2100 test_boost == 2) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002101
2102 boost_starttime = jiffies + test_boost_interval * HZ;
2103 register_cpu_notifier(&rcutorture_cpu_nb);
2104 for_each_possible_cpu(i) {
2105 if (cpu_is_offline(i))
2106 continue; /* Heuristic: CPU can go offline. */
2107 retval = rcutorture_booster_init(i);
2108 if (retval < 0) {
2109 firsterr = retval;
2110 goto unwind;
2111 }
2112 }
2113 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07002114 if (shutdown_secs > 0) {
2115 shutdown_time = jiffies + shutdown_secs * HZ;
2116 shutdown_task = kthread_run(rcu_torture_shutdown, NULL,
2117 "rcu_torture_shutdown");
2118 if (IS_ERR(shutdown_task)) {
2119 firsterr = PTR_ERR(shutdown_task);
2120 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
2121 shutdown_task = NULL;
2122 goto unwind;
2123 }
2124 }
Paul E. McKenney37e377d2012-02-17 22:12:18 -08002125 i = rcu_torture_onoff_init();
2126 if (i != 0) {
2127 firsterr = i;
2128 goto unwind;
2129 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002130 register_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08002131 i = rcu_torture_stall_init();
2132 if (i != 0) {
2133 firsterr = i;
2134 goto unwind;
2135 }
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08002136 retval = rcu_torture_barrier_init();
2137 if (retval != 0) {
2138 firsterr = retval;
2139 goto unwind;
2140 }
Paul E. McKenney4a298652011-04-03 21:33:51 -07002141 rcutorture_record_test_transition();
Paul E. McKenney343e9092008-12-15 16:13:07 -08002142 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002143 return 0;
2144
2145unwind:
Paul E. McKenney343e9092008-12-15 16:13:07 -08002146 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002147 rcu_torture_cleanup();
2148 return firsterr;
2149}
2150
2151module_init(rcu_torture_init);
2152module_exit(rcu_torture_cleanup);