blob: 9900f560f1bdaf5adfe78262dc918b8869cbb6f9 [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");
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -070052MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@freedesktop.org>");
Paul E. McKenneya241ec62005-10-30 15:03:12 -080053
Josh Triplett48022112006-10-03 23:26:16 +020054static int nreaders = -1; /* # reader threads, defaults to 2*ncpus */
Josh Triplettb772e1d2006-10-04 02:17:13 -070055static int nfakewriters = 4; /* # fake writer threads */
Paul E. McKenneyab840f72012-07-23 12:30:22 -070056static int stat_interval = 60; /* Interval between stats, in seconds. */
57 /* Zero means "only at end of test". */
Rusty Russelld8e8ed92011-12-15 13:43:24 +103058static bool verbose; /* Print more debug info. */
Paul E. McKenneyab840f72012-07-23 12:30:22 -070059static bool test_no_idle_hz = true;
60 /* Test RCU 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. McKenney2caa1e42012-08-09 16:30:45 -0700123 do { pr_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. McKenney2caa1e42012-08-09 16:30:45 -0700125 do { if (verbose) pr_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. McKenney2caa1e42012-08-09 16:30:45 -0700127 do { if (verbose) pr_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;
Paul E. McKenney13dbf912012-07-23 12:05:55 -0700180static unsigned long sum_offline;
181static int min_offline = -1;
182static int max_offline;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -0800183static long n_online_attempts;
184static long n_online_successes;
Paul E. McKenney13dbf912012-07-23 12:05:55 -0700185static unsigned long sum_online;
186static int min_online = -1;
187static int max_online;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800188static long n_barrier_attempts;
189static long n_barrier_successes;
Josh Triplette3033732006-10-04 02:17:14 -0700190static struct list_head rcu_torture_removed;
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600191static cpumask_var_t shuffle_tmp_mask;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800192
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700193static int stutter_pause_test;
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700194
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700195#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
196#define RCUTORTURE_RUNNABLE_INIT 1
197#else
198#define RCUTORTURE_RUNNABLE_INIT 0
199#endif
200int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
Paul E. McKenneybb3bf702011-11-04 13:24:07 -0700201module_param(rcutorture_runnable, int, 0444);
202MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot");
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700203
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700204#if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700205#define rcu_can_boost() 1
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700206#else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700207#define rcu_can_boost() 0
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700208#endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700209
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700210static unsigned long shutdown_time; /* jiffies to system shutdown. */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700211static unsigned long boost_starttime; /* jiffies of next boost test start. */
212DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
213 /* and boost task create/destroy. */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800214static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -0700215static bool barrier_phase; /* Test phase. */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800216static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */
217static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */
218static DECLARE_WAIT_QUEUE_HEAD(barrier_wq);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700219
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800220/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
221
222#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
223#define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
224#define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
225static int fullstop = FULLSTOP_RMMOD;
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700226/*
227 * Protect fullstop transitions and spawning of kthreads.
228 */
229static DEFINE_MUTEX(fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800230
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700231/* Forward reference. */
232static void rcu_torture_cleanup(void);
233
Paul E. McKenney343e9092008-12-15 16:13:07 -0800234/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800235 * Detect and respond to a system shutdown.
Paul E. McKenney343e9092008-12-15 16:13:07 -0800236 */
237static int
238rcutorture_shutdown_notify(struct notifier_block *unused1,
239 unsigned long unused2, void *unused3)
240{
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800241 mutex_lock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800242 if (fullstop == FULLSTOP_DONTSTOP)
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800243 fullstop = FULLSTOP_SHUTDOWN;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800244 else
Paul E. McKenney2caa1e42012-08-09 16:30:45 -0700245 pr_warn(/* but going down anyway, so... */
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800246 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800247 mutex_unlock(&fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800248 return NOTIFY_DONE;
249}
250
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800251/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800252 * Absorb kthreads into a kernel function that won't return, so that
253 * they won't ever access module text or data again.
254 */
255static void rcutorture_shutdown_absorb(char *title)
256{
257 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -0700258 pr_notice(
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800259 "rcutorture thread %s parking due to system shutdown\n",
260 title);
261 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
262 }
263}
264
265/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800266 * Allocate an element from the rcu_tortures pool.
267 */
Adrian Bunk97a41e22006-01-08 01:02:17 -0800268static struct rcu_torture *
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800269rcu_torture_alloc(void)
270{
271 struct list_head *p;
272
Ingo Molnaradac1662006-01-25 19:50:12 +0100273 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800274 if (list_empty(&rcu_torture_freelist)) {
275 atomic_inc(&n_rcu_torture_alloc_fail);
Ingo Molnaradac1662006-01-25 19:50:12 +0100276 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800277 return NULL;
278 }
279 atomic_inc(&n_rcu_torture_alloc);
280 p = rcu_torture_freelist.next;
281 list_del_init(p);
Ingo Molnaradac1662006-01-25 19:50:12 +0100282 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800283 return container_of(p, struct rcu_torture, rtort_free);
284}
285
286/*
287 * Free an element to the rcu_tortures pool.
288 */
289static void
290rcu_torture_free(struct rcu_torture *p)
291{
292 atomic_inc(&n_rcu_torture_free);
Ingo Molnaradac1662006-01-25 19:50:12 +0100293 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800294 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
Ingo Molnaradac1662006-01-25 19:50:12 +0100295 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800296}
297
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800298struct rcu_random_state {
299 unsigned long rrs_state;
Josh Triplett75cfef32006-10-04 02:17:12 -0700300 long rrs_count;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800301};
302
303#define RCU_RANDOM_MULT 39916801 /* prime */
304#define RCU_RANDOM_ADD 479001701 /* prime */
305#define RCU_RANDOM_REFRESH 10000
306
307#define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
308
309/*
310 * Crude but fast random-number generator. Uses a linear congruential
Paul E. McKenneyc17ac852007-10-16 23:27:19 -0700311 * generator, with occasional help from cpu_clock().
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800312 */
Josh Triplett75cfef32006-10-04 02:17:12 -0700313static unsigned long
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800314rcu_random(struct rcu_random_state *rrsp)
315{
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800316 if (--rrsp->rrs_count < 0) {
Peter Zijlstrac6763292010-05-25 10:48:51 +0200317 rrsp->rrs_state += (unsigned long)local_clock();
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800318 rrsp->rrs_count = RCU_RANDOM_REFRESH;
319 }
320 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
321 return swahw32(rrsp->rrs_state);
322}
323
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700324static void
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800325rcu_stutter_wait(char *title)
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700326{
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800327 while (stutter_pause_test || !rcutorture_runnable) {
Paul E. McKenneye3d7be22008-06-22 13:06:38 -0700328 if (rcutorture_runnable)
329 schedule_timeout_interruptible(1);
330 else
Paul E. McKenney3ccf79f2008-06-22 14:02:55 -0700331 schedule_timeout_interruptible(round_jiffies_relative(HZ));
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800332 rcutorture_shutdown_absorb(title);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800333 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700334}
335
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800336/*
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700337 * Operations vector for selecting different types of tests.
338 */
339
340struct rcu_torture_ops {
341 void (*init)(void);
342 void (*cleanup)(void);
343 int (*readlock)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700344 void (*read_delay)(struct rcu_random_state *rrsp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700345 void (*readunlock)(int idx);
346 int (*completed)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700347 void (*deferred_free)(struct rcu_torture *p);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700348 void (*sync)(void);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800349 void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu));
Paul E. McKenney23269742008-05-12 21:21:05 +0200350 void (*cb_barrier)(void);
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800351 void (*fqs)(void);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700352 int (*stats)(char *page);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700353 int irq_capable;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700354 int can_boost;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700355 char *name;
356};
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700357
358static struct rcu_torture_ops *cur_ops;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700359
360/*
361 * Definitions for rcu torture testing.
362 */
363
Josh Tripletta49a4af2006-09-29 01:59:30 -0700364static int rcu_torture_read_lock(void) __acquires(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700365{
366 rcu_read_lock();
367 return 0;
368}
369
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700370static void rcu_read_delay(struct rcu_random_state *rrsp)
371{
Josh Triplettb8d57a72009-09-08 15:54:35 -0700372 const unsigned long shortdelay_us = 200;
373 const unsigned long longdelay_ms = 50;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700374
Josh Triplettb8d57a72009-09-08 15:54:35 -0700375 /* We want a short delay sometimes to make a reader delay the grace
376 * period, and we want a long delay occasionally to trigger
377 * force_quiescent_state. */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700378
Josh Triplettb8d57a72009-09-08 15:54:35 -0700379 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
380 mdelay(longdelay_ms);
381 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
382 udelay(shortdelay_us);
Lai Jiangshane546f482010-06-21 16:57:42 +0800383#ifdef CONFIG_PREEMPT
384 if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000)))
385 preempt_schedule(); /* No QS if preempt_disable() in effect */
386#endif
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700387}
388
Josh Tripletta49a4af2006-09-29 01:59:30 -0700389static void rcu_torture_read_unlock(int idx) __releases(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700390{
391 rcu_read_unlock();
392}
393
394static int rcu_torture_completed(void)
395{
396 return rcu_batches_completed();
397}
398
399static void
400rcu_torture_cb(struct rcu_head *p)
401{
402 int i;
403 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
404
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800405 if (fullstop != FULLSTOP_DONTSTOP) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700406 /* Test is ending, just drop callbacks on the floor. */
407 /* The next initialization will pick up the pieces. */
408 return;
409 }
410 i = rp->rtort_pipe_count;
411 if (i > RCU_TORTURE_PIPE_LEN)
412 i = RCU_TORTURE_PIPE_LEN;
413 atomic_inc(&rcu_torture_wcount[i]);
414 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
415 rp->rtort_mbtest = 0;
416 rcu_torture_free(rp);
Paul E. McKenneyc701d5d2012-06-28 08:08:25 -0700417 } else {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700418 cur_ops->deferred_free(rp);
Paul E. McKenneyc701d5d2012-06-28 08:08:25 -0700419 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700420}
421
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800422static int rcu_no_completed(void)
423{
424 return 0;
425}
426
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700427static void rcu_torture_deferred_free(struct rcu_torture *p)
428{
429 call_rcu(&p->rtort_rcu, rcu_torture_cb);
430}
431
432static struct rcu_torture_ops rcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700433 .init = NULL,
434 .cleanup = NULL,
435 .readlock = rcu_torture_read_lock,
436 .read_delay = rcu_read_delay,
437 .readunlock = rcu_torture_read_unlock,
438 .completed = rcu_torture_completed,
439 .deferred_free = rcu_torture_deferred_free,
440 .sync = synchronize_rcu,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800441 .call = call_rcu,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700442 .cb_barrier = rcu_barrier,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800443 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700444 .stats = NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700445 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700446 .can_boost = rcu_can_boost(),
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700447 .name = "rcu"
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700448};
449
Josh Triplette3033732006-10-04 02:17:14 -0700450static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
451{
452 int i;
453 struct rcu_torture *rp;
454 struct rcu_torture *rp1;
455
456 cur_ops->sync();
457 list_add(&p->rtort_free, &rcu_torture_removed);
458 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
459 i = rp->rtort_pipe_count;
460 if (i > RCU_TORTURE_PIPE_LEN)
461 i = RCU_TORTURE_PIPE_LEN;
462 atomic_inc(&rcu_torture_wcount[i]);
463 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
464 rp->rtort_mbtest = 0;
465 list_del(&rp->rtort_free);
466 rcu_torture_free(rp);
467 }
468 }
469}
470
471static void rcu_sync_torture_init(void)
472{
473 INIT_LIST_HEAD(&rcu_torture_removed);
474}
475
Josh Triplett20d2e422006-10-04 02:17:15 -0700476static struct rcu_torture_ops rcu_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700477 .init = rcu_sync_torture_init,
478 .cleanup = NULL,
479 .readlock = rcu_torture_read_lock,
480 .read_delay = rcu_read_delay,
481 .readunlock = rcu_torture_read_unlock,
482 .completed = rcu_torture_completed,
483 .deferred_free = rcu_sync_torture_deferred_free,
484 .sync = synchronize_rcu,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800485 .call = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700486 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800487 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700488 .stats = NULL,
489 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700490 .can_boost = rcu_can_boost(),
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700491 .name = "rcu_sync"
Josh Triplett20d2e422006-10-04 02:17:15 -0700492};
493
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800494static struct rcu_torture_ops rcu_expedited_ops = {
495 .init = rcu_sync_torture_init,
496 .cleanup = NULL,
497 .readlock = rcu_torture_read_lock,
498 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
499 .readunlock = rcu_torture_read_unlock,
500 .completed = rcu_no_completed,
501 .deferred_free = rcu_sync_torture_deferred_free,
502 .sync = synchronize_rcu_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800503 .call = NULL,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800504 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800505 .fqs = rcu_force_quiescent_state,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800506 .stats = NULL,
507 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700508 .can_boost = rcu_can_boost(),
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800509 .name = "rcu_expedited"
510};
511
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700512/*
513 * Definitions for rcu_bh torture testing.
514 */
515
Josh Tripletta49a4af2006-09-29 01:59:30 -0700516static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700517{
518 rcu_read_lock_bh();
519 return 0;
520}
521
Josh Tripletta49a4af2006-09-29 01:59:30 -0700522static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700523{
524 rcu_read_unlock_bh();
525}
526
527static int rcu_bh_torture_completed(void)
528{
529 return rcu_batches_completed_bh();
530}
531
532static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
533{
534 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
535}
536
537static struct rcu_torture_ops rcu_bh_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700538 .init = NULL,
539 .cleanup = NULL,
540 .readlock = rcu_bh_torture_read_lock,
541 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
542 .readunlock = rcu_bh_torture_read_unlock,
543 .completed = rcu_bh_torture_completed,
544 .deferred_free = rcu_bh_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700545 .sync = synchronize_rcu_bh,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800546 .call = call_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700547 .cb_barrier = rcu_barrier_bh,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800548 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700549 .stats = NULL,
550 .irq_capable = 1,
551 .name = "rcu_bh"
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700552};
553
Josh Triplett11a14702006-10-04 02:17:16 -0700554static struct rcu_torture_ops rcu_bh_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700555 .init = rcu_sync_torture_init,
556 .cleanup = NULL,
557 .readlock = rcu_bh_torture_read_lock,
558 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
559 .readunlock = rcu_bh_torture_read_unlock,
560 .completed = rcu_bh_torture_completed,
561 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700562 .sync = synchronize_rcu_bh,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800563 .call = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700564 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800565 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700566 .stats = NULL,
567 .irq_capable = 1,
568 .name = "rcu_bh_sync"
Josh Triplett11a14702006-10-04 02:17:16 -0700569};
570
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700571static struct rcu_torture_ops rcu_bh_expedited_ops = {
572 .init = rcu_sync_torture_init,
573 .cleanup = NULL,
574 .readlock = rcu_bh_torture_read_lock,
575 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
576 .readunlock = rcu_bh_torture_read_unlock,
577 .completed = rcu_bh_torture_completed,
578 .deferred_free = rcu_sync_torture_deferred_free,
579 .sync = synchronize_rcu_bh_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800580 .call = NULL,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700581 .cb_barrier = NULL,
582 .fqs = rcu_bh_force_quiescent_state,
583 .stats = NULL,
584 .irq_capable = 1,
585 .name = "rcu_bh_expedited"
586};
587
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700588/*
589 * Definitions for srcu torture testing.
590 */
591
592static struct srcu_struct srcu_ctl;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700593
594static void srcu_torture_init(void)
595{
596 init_srcu_struct(&srcu_ctl);
Josh Triplette3033732006-10-04 02:17:14 -0700597 rcu_sync_torture_init();
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700598}
599
600static void srcu_torture_cleanup(void)
601{
602 synchronize_srcu(&srcu_ctl);
603 cleanup_srcu_struct(&srcu_ctl);
604}
605
Josh Triplett012d3ca2006-12-06 20:40:19 -0800606static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700607{
608 return srcu_read_lock(&srcu_ctl);
609}
610
611static void srcu_read_delay(struct rcu_random_state *rrsp)
612{
613 long delay;
614 const long uspertick = 1000000 / HZ;
615 const long longdelay = 10;
616
617 /* We want there to be long-running readers, but not all the time. */
618
619 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
620 if (!delay)
621 schedule_timeout_interruptible(longdelay);
Lai Jiangshane546f482010-06-21 16:57:42 +0800622 else
623 rcu_read_delay(rrsp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700624}
625
Josh Triplett012d3ca2006-12-06 20:40:19 -0800626static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700627{
628 srcu_read_unlock(&srcu_ctl, idx);
629}
630
631static int srcu_torture_completed(void)
632{
633 return srcu_batches_completed(&srcu_ctl);
634}
635
Lai Jiangshan9059c942012-03-19 16:12:14 +0800636static void srcu_torture_deferred_free(struct rcu_torture *rp)
637{
638 call_srcu(&srcu_ctl, &rp->rtort_rcu, rcu_torture_cb);
639}
640
Josh Triplettb772e1d2006-10-04 02:17:13 -0700641static void srcu_torture_synchronize(void)
642{
643 synchronize_srcu(&srcu_ctl);
644}
645
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700646static void srcu_torture_call(struct rcu_head *head,
647 void (*func)(struct rcu_head *head))
648{
649 call_srcu(&srcu_ctl, head, func);
650}
651
652static void srcu_torture_barrier(void)
653{
654 srcu_barrier(&srcu_ctl);
655}
656
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700657static int srcu_torture_stats(char *page)
658{
659 int cnt = 0;
660 int cpu;
661 int idx = srcu_ctl.completed & 0x1;
662
663 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
664 torture_type, TORTURE_FLAG, idx);
665 for_each_possible_cpu(cpu) {
Paul E. McKenneycef50122012-02-05 07:42:44 -0800666 cnt += sprintf(&page[cnt], " %d(%lu,%lu)", cpu,
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700667 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
668 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
669 }
670 cnt += sprintf(&page[cnt], "\n");
671 return cnt;
672}
673
674static struct rcu_torture_ops srcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700675 .init = srcu_torture_init,
676 .cleanup = srcu_torture_cleanup,
677 .readlock = srcu_torture_read_lock,
678 .read_delay = srcu_read_delay,
679 .readunlock = srcu_torture_read_unlock,
680 .completed = srcu_torture_completed,
Lai Jiangshan9059c942012-03-19 16:12:14 +0800681 .deferred_free = srcu_torture_deferred_free,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700682 .sync = srcu_torture_synchronize,
Paul E. McKenneye3f8d372012-05-08 10:21:50 -0700683 .call = srcu_torture_call,
684 .cb_barrier = srcu_torture_barrier,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700685 .stats = srcu_torture_stats,
686 .name = "srcu"
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700687};
688
Lai Jiangshan9059c942012-03-19 16:12:14 +0800689static struct rcu_torture_ops srcu_sync_ops = {
690 .init = srcu_torture_init,
691 .cleanup = srcu_torture_cleanup,
692 .readlock = srcu_torture_read_lock,
693 .read_delay = srcu_read_delay,
694 .readunlock = srcu_torture_read_unlock,
695 .completed = srcu_torture_completed,
696 .deferred_free = rcu_sync_torture_deferred_free,
697 .sync = srcu_torture_synchronize,
698 .call = NULL,
699 .cb_barrier = NULL,
700 .stats = srcu_torture_stats,
701 .name = "srcu_sync"
702};
703
Paul E. McKenney101db7b2011-12-05 15:36:31 -0800704static int srcu_torture_read_lock_raw(void) __acquires(&srcu_ctl)
705{
706 return srcu_read_lock_raw(&srcu_ctl);
707}
708
709static void srcu_torture_read_unlock_raw(int idx) __releases(&srcu_ctl)
710{
711 srcu_read_unlock_raw(&srcu_ctl, idx);
712}
713
714static struct rcu_torture_ops srcu_raw_ops = {
715 .init = srcu_torture_init,
716 .cleanup = srcu_torture_cleanup,
717 .readlock = srcu_torture_read_lock_raw,
718 .read_delay = srcu_read_delay,
719 .readunlock = srcu_torture_read_unlock_raw,
720 .completed = srcu_torture_completed,
Lai Jiangshan9059c942012-03-19 16:12:14 +0800721 .deferred_free = srcu_torture_deferred_free,
Paul E. McKenney101db7b2011-12-05 15:36:31 -0800722 .sync = srcu_torture_synchronize,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800723 .call = NULL,
Paul E. McKenney101db7b2011-12-05 15:36:31 -0800724 .cb_barrier = NULL,
725 .stats = srcu_torture_stats,
726 .name = "srcu_raw"
727};
728
Lai Jiangshan9059c942012-03-19 16:12:14 +0800729static struct rcu_torture_ops srcu_raw_sync_ops = {
730 .init = srcu_torture_init,
731 .cleanup = srcu_torture_cleanup,
732 .readlock = srcu_torture_read_lock_raw,
733 .read_delay = srcu_read_delay,
734 .readunlock = srcu_torture_read_unlock_raw,
735 .completed = srcu_torture_completed,
736 .deferred_free = rcu_sync_torture_deferred_free,
737 .sync = srcu_torture_synchronize,
738 .call = NULL,
739 .cb_barrier = NULL,
740 .stats = srcu_torture_stats,
741 .name = "srcu_raw_sync"
742};
743
Paul E. McKenney804bb832009-10-25 19:03:52 -0700744static void srcu_torture_synchronize_expedited(void)
745{
746 synchronize_srcu_expedited(&srcu_ctl);
747}
748
749static struct rcu_torture_ops srcu_expedited_ops = {
750 .init = srcu_torture_init,
751 .cleanup = srcu_torture_cleanup,
752 .readlock = srcu_torture_read_lock,
753 .read_delay = srcu_read_delay,
754 .readunlock = srcu_torture_read_unlock,
755 .completed = srcu_torture_completed,
756 .deferred_free = rcu_sync_torture_deferred_free,
757 .sync = srcu_torture_synchronize_expedited,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -0800758 .call = NULL,
Paul E. McKenney804bb832009-10-25 19:03:52 -0700759 .cb_barrier = NULL,
760 .stats = srcu_torture_stats,
761 .name = "srcu_expedited"
762};
763
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700764/*
765 * Definitions for sched torture testing.
766 */
767
768static int sched_torture_read_lock(void)
769{
770 preempt_disable();
771 return 0;
772}
773
774static void sched_torture_read_unlock(int idx)
775{
776 preempt_enable();
777}
778
Paul E. McKenney23269742008-05-12 21:21:05 +0200779static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
780{
781 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
782}
783
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700784static struct rcu_torture_ops sched_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700785 .init = rcu_sync_torture_init,
786 .cleanup = NULL,
787 .readlock = sched_torture_read_lock,
788 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
789 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800790 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700791 .deferred_free = rcu_sched_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700792 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700793 .cb_barrier = rcu_barrier_sched,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800794 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700795 .stats = NULL,
796 .irq_capable = 1,
797 .name = "sched"
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700798};
799
Paul E. McKenney804bb832009-10-25 19:03:52 -0700800static struct rcu_torture_ops sched_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700801 .init = rcu_sync_torture_init,
802 .cleanup = NULL,
803 .readlock = sched_torture_read_lock,
804 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
805 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800806 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700807 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700808 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700809 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800810 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700811 .stats = NULL,
812 .name = "sched_sync"
813};
814
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700815static struct rcu_torture_ops sched_expedited_ops = {
816 .init = rcu_sync_torture_init,
817 .cleanup = NULL,
818 .readlock = sched_torture_read_lock,
819 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
820 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800821 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700822 .deferred_free = rcu_sync_torture_deferred_free,
823 .sync = synchronize_sched_expedited,
824 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800825 .fqs = rcu_sched_force_quiescent_state,
Tejun Heo969c7922010-05-06 18:49:21 +0200826 .stats = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700827 .irq_capable = 1,
828 .name = "sched_expedited"
Paul E. McKenney23269742008-05-12 21:21:05 +0200829};
830
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700831/*
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700832 * RCU torture priority-boost testing. Runs one real-time thread per
833 * CPU for moderate bursts, repeatedly registering RCU callbacks and
834 * spinning waiting for them to be invoked. If a given callback takes
835 * too long to be invoked, we assume that priority inversion has occurred.
836 */
837
838struct rcu_boost_inflight {
839 struct rcu_head rcu;
840 int inflight;
841};
842
843static void rcu_torture_boost_cb(struct rcu_head *head)
844{
845 struct rcu_boost_inflight *rbip =
846 container_of(head, struct rcu_boost_inflight, rcu);
847
848 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
849 rbip->inflight = 0;
850}
851
852static int rcu_torture_boost(void *arg)
853{
854 unsigned long call_rcu_time;
855 unsigned long endtime;
856 unsigned long oldstarttime;
857 struct rcu_boost_inflight rbi = { .inflight = 0 };
858 struct sched_param sp;
859
860 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
861
862 /* Set real-time priority. */
863 sp.sched_priority = 1;
864 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
865 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
866 n_rcu_torture_boost_rterror++;
867 }
868
Paul E. McKenney561190e2011-03-30 09:10:44 -0700869 init_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700870 /* Each pass through the following loop does one boost-test cycle. */
871 do {
872 /* Wait for the next test interval. */
873 oldstarttime = boost_starttime;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700874 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700875 schedule_timeout_uninterruptible(1);
876 rcu_stutter_wait("rcu_torture_boost");
877 if (kthread_should_stop() ||
878 fullstop != FULLSTOP_DONTSTOP)
879 goto checkwait;
880 }
881
882 /* Do one boost-test interval. */
883 endtime = oldstarttime + test_boost_duration * HZ;
884 call_rcu_time = jiffies;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700885 while (ULONG_CMP_LT(jiffies, endtime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700886 /* If we don't have a callback in flight, post one. */
887 if (!rbi.inflight) {
888 smp_mb(); /* RCU core before ->inflight = 1. */
889 rbi.inflight = 1;
890 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
891 if (jiffies - call_rcu_time >
892 test_boost_duration * HZ - HZ / 2) {
893 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
894 n_rcu_torture_boost_failure++;
895 }
896 call_rcu_time = jiffies;
897 }
898 cond_resched();
899 rcu_stutter_wait("rcu_torture_boost");
900 if (kthread_should_stop() ||
901 fullstop != FULLSTOP_DONTSTOP)
902 goto checkwait;
903 }
904
905 /*
906 * Set the start time of the next test interval.
907 * Yes, this is vulnerable to long delays, but such
908 * delays simply cause a false negative for the next
909 * interval. Besides, we are running at RT priority,
910 * so delays should be relatively rare.
911 */
Paul E. McKenneyab8f11e2011-08-18 09:30:32 -0700912 while (oldstarttime == boost_starttime &&
913 !kthread_should_stop()) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700914 if (mutex_trylock(&boost_mutex)) {
915 boost_starttime = jiffies +
916 test_boost_interval * HZ;
917 n_rcu_torture_boosts++;
918 mutex_unlock(&boost_mutex);
919 break;
920 }
921 schedule_timeout_uninterruptible(1);
922 }
923
924 /* Go do the stutter. */
925checkwait: rcu_stutter_wait("rcu_torture_boost");
926 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
927
928 /* Clean up and exit. */
929 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
930 rcutorture_shutdown_absorb("rcu_torture_boost");
931 while (!kthread_should_stop() || rbi.inflight)
932 schedule_timeout_uninterruptible(1);
933 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
Paul E. McKenney9d681972011-06-21 01:48:03 -0700934 destroy_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700935 return 0;
936}
937
938/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800939 * RCU torture force-quiescent-state kthread. Repeatedly induces
940 * bursts of calls to force_quiescent_state(), increasing the probability
941 * of occurrence of some important types of race conditions.
942 */
943static int
944rcu_torture_fqs(void *arg)
945{
946 unsigned long fqs_resume_time;
947 int fqs_burst_remaining;
948
949 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
950 do {
951 fqs_resume_time = jiffies + fqs_stutter * HZ;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700952 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
953 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800954 schedule_timeout_interruptible(1);
955 }
956 fqs_burst_remaining = fqs_duration;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700957 while (fqs_burst_remaining > 0 &&
958 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800959 cur_ops->fqs();
960 udelay(fqs_holdoff);
961 fqs_burst_remaining -= fqs_holdoff;
962 }
963 rcu_stutter_wait("rcu_torture_fqs");
964 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
965 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
966 rcutorture_shutdown_absorb("rcu_torture_fqs");
967 while (!kthread_should_stop())
968 schedule_timeout_uninterruptible(1);
969 return 0;
970}
971
972/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800973 * RCU torture writer kthread. Repeatedly substitutes a new structure
974 * for that pointed to by rcu_torture_current, freeing the old structure
975 * after a series of grace periods (the "pipeline").
976 */
977static int
978rcu_torture_writer(void *arg)
979{
980 int i;
981 long oldbatch = rcu_batches_completed();
982 struct rcu_torture *rp;
983 struct rcu_torture *old_rp;
984 static DEFINE_RCU_RANDOM(rand);
985
986 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800987 set_user_nice(current, 19);
988
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800989 do {
990 schedule_timeout_uninterruptible(1);
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700991 rp = rcu_torture_alloc();
992 if (rp == NULL)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800993 continue;
994 rp->rtort_pipe_count = 0;
995 udelay(rcu_random(&rand) & 0x3ff);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700996 old_rp = rcu_dereference_check(rcu_torture_current,
997 current == writer_task);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800998 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800999 rcu_assign_pointer(rcu_torture_current, rp);
Paul E. McKenney9b2619a2009-09-23 09:50:43 -07001000 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
Josh Triplettc8e5b162007-05-08 00:33:20 -07001001 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001002 i = old_rp->rtort_pipe_count;
1003 if (i > RCU_TORTURE_PIPE_LEN)
1004 i = RCU_TORTURE_PIPE_LEN;
1005 atomic_inc(&rcu_torture_wcount[i]);
1006 old_rp->rtort_pipe_count++;
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001007 cur_ops->deferred_free(old_rp);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001008 }
Paul E. McKenney4a298652011-04-03 21:33:51 -07001009 rcutorture_record_progress(++rcu_torture_current_version);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001010 oldbatch = cur_ops->completed();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001011 rcu_stutter_wait("rcu_torture_writer");
1012 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001013 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001014 rcutorture_shutdown_absorb("rcu_torture_writer");
1015 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001016 schedule_timeout_uninterruptible(1);
1017 return 0;
1018}
1019
1020/*
Josh Triplettb772e1d2006-10-04 02:17:13 -07001021 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
1022 * delay between calls.
1023 */
1024static int
1025rcu_torture_fakewriter(void *arg)
1026{
1027 DEFINE_RCU_RANDOM(rand);
1028
1029 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
1030 set_user_nice(current, 19);
1031
1032 do {
1033 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
1034 udelay(rcu_random(&rand) & 0x3ff);
Paul E. McKenney72472a02012-05-29 17:50:51 -07001035 if (cur_ops->cb_barrier != NULL &&
1036 rcu_random(&rand) % (nfakewriters * 8) == 0)
1037 cur_ops->cb_barrier();
1038 else
1039 cur_ops->sync();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001040 rcu_stutter_wait("rcu_torture_fakewriter");
1041 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001042
1043 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001044 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
1045 while (!kthread_should_stop())
Josh Triplettb772e1d2006-10-04 02:17:13 -07001046 schedule_timeout_uninterruptible(1);
1047 return 0;
1048}
1049
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001050void rcutorture_trace_dump(void)
1051{
1052 static atomic_t beenhere = ATOMIC_INIT(0);
1053
1054 if (atomic_read(&beenhere))
1055 return;
1056 if (atomic_xchg(&beenhere, 1) != 0)
1057 return;
1058 do_trace_rcu_torture_read(cur_ops->name, (struct rcu_head *)~0UL);
1059 ftrace_dump(DUMP_ALL);
1060}
1061
Josh Triplettb772e1d2006-10-04 02:17:13 -07001062/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001063 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
1064 * incrementing the corresponding element of the pipeline array. The
1065 * counter in the element should never be greater than 1, otherwise, the
1066 * RCU implementation is broken.
1067 */
1068static void rcu_torture_timer(unsigned long unused)
1069{
1070 int idx;
1071 int completed;
1072 static DEFINE_RCU_RANDOM(rand);
1073 static DEFINE_SPINLOCK(rand_lock);
1074 struct rcu_torture *p;
1075 int pipe_count;
1076
1077 idx = cur_ops->readlock();
1078 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001079 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001080 rcu_read_lock_bh_held() ||
1081 rcu_read_lock_sched_held() ||
1082 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001083 if (p == NULL) {
1084 /* Leave because rcu_torture_writer is not yet underway */
1085 cur_ops->readunlock(idx);
1086 return;
1087 }
Paul E. McKenney7129d382012-01-31 16:46:34 -08001088 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001089 if (p->rtort_mbtest == 0)
1090 atomic_inc(&n_rcu_torture_mberror);
1091 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001092 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001093 n_rcu_torture_timers++;
1094 spin_unlock(&rand_lock);
1095 preempt_disable();
1096 pipe_count = p->rtort_pipe_count;
1097 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1098 /* Should not happen, but... */
1099 pipe_count = RCU_TORTURE_PIPE_LEN;
1100 }
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001101 if (pipe_count > 1)
1102 rcutorture_trace_dump();
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001103 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001104 completed = cur_ops->completed() - completed;
1105 if (completed > RCU_TORTURE_PIPE_LEN) {
1106 /* Should not happen, but... */
1107 completed = RCU_TORTURE_PIPE_LEN;
1108 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001109 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001110 preempt_enable();
1111 cur_ops->readunlock(idx);
1112}
1113
1114/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001115 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
1116 * incrementing the corresponding element of the pipeline array. The
1117 * counter in the element should never be greater than 1, otherwise, the
1118 * RCU implementation is broken.
1119 */
1120static int
1121rcu_torture_reader(void *arg)
1122{
1123 int completed;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001124 int idx;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001125 DEFINE_RCU_RANDOM(rand);
1126 struct rcu_torture *p;
1127 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001128 struct timer_list t;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001129
1130 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001131 set_user_nice(current, 19);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001132 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001133 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001134
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001135 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001136 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001137 if (!timer_pending(&t))
Paul E. McKenney6155fec2010-02-22 17:05:04 -08001138 mod_timer(&t, jiffies + 1);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001139 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001140 idx = cur_ops->readlock();
1141 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001142 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001143 rcu_read_lock_bh_held() ||
1144 rcu_read_lock_sched_held() ||
1145 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001146 if (p == NULL) {
1147 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001148 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001149 schedule_timeout_interruptible(HZ);
1150 continue;
1151 }
Paul E. McKenney7129d382012-01-31 16:46:34 -08001152 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001153 if (p->rtort_mbtest == 0)
1154 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001155 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001156 preempt_disable();
1157 pipe_count = p->rtort_pipe_count;
1158 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1159 /* Should not happen, but... */
1160 pipe_count = RCU_TORTURE_PIPE_LEN;
1161 }
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001162 if (pipe_count > 1)
1163 rcutorture_trace_dump();
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001164 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001165 completed = cur_ops->completed() - completed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001166 if (completed > RCU_TORTURE_PIPE_LEN) {
1167 /* Should not happen, but... */
1168 completed = RCU_TORTURE_PIPE_LEN;
1169 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001170 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001171 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001172 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001173 schedule();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001174 rcu_stutter_wait("rcu_torture_reader");
1175 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001176 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001177 rcutorture_shutdown_absorb("rcu_torture_reader");
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001178 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001179 del_timer_sync(&t);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001180 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001181 schedule_timeout_uninterruptible(1);
1182 return 0;
1183}
1184
1185/*
1186 * Create an RCU-torture statistics message in the specified buffer.
1187 */
1188static int
1189rcu_torture_printk(char *page)
1190{
1191 int cnt = 0;
1192 int cpu;
1193 int i;
1194 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1195 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1196
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001197 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001198 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1199 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1200 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1201 }
1202 }
1203 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1204 if (pipesummary[i] != 0)
1205 break;
1206 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001207 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001208 cnt += sprintf(&page[cnt],
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -07001209 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001210 rcu_torture_current,
1211 rcu_torture_current_version,
1212 list_empty(&rcu_torture_freelist),
1213 atomic_read(&n_rcu_torture_alloc),
1214 atomic_read(&n_rcu_torture_alloc_fail),
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -07001215 atomic_read(&n_rcu_torture_free));
1216 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001217 atomic_read(&n_rcu_torture_mberror),
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001218 n_rcu_torture_boost_ktrerror,
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -07001219 n_rcu_torture_boost_rterror);
1220 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001221 n_rcu_torture_boost_failure,
1222 n_rcu_torture_boosts,
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -07001223 n_rcu_torture_timers);
Paul E. McKenney13dbf912012-07-23 12:05:55 -07001224 cnt += sprintf(&page[cnt],
1225 "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ",
1226 n_online_successes, n_online_attempts,
1227 n_offline_successes, n_offline_attempts,
1228 min_online, max_online,
1229 min_offline, max_offline,
1230 sum_online, sum_offline, HZ);
Paul E. McKenney5cf05ad2012-05-17 15:12:45 -07001231 cnt += sprintf(&page[cnt], "barrier: %ld/%ld:%ld",
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001232 n_barrier_successes,
1233 n_barrier_attempts,
1234 n_rcu_torture_barrier_error);
1235 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001236 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001237 n_rcu_torture_barrier_error != 0 ||
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001238 n_rcu_torture_boost_ktrerror != 0 ||
1239 n_rcu_torture_boost_rterror != 0 ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001240 n_rcu_torture_boost_failure != 0 ||
1241 i > 1) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001242 cnt += sprintf(&page[cnt], "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -08001243 atomic_inc(&n_rcu_torture_error);
Ingo Molnar5af970a2008-06-18 10:09:48 +02001244 WARN_ON_ONCE(1);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001245 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001246 cnt += sprintf(&page[cnt], "Reader Pipe: ");
1247 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1248 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001249 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001250 cnt += sprintf(&page[cnt], "Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001251 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001252 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001253 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001254 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
1255 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1256 cnt += sprintf(&page[cnt], " %d",
1257 atomic_read(&rcu_torture_wcount[i]));
1258 }
1259 cnt += sprintf(&page[cnt], "\n");
Josh Triplettc8e5b162007-05-08 00:33:20 -07001260 if (cur_ops->stats)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001261 cnt += cur_ops->stats(&page[cnt]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001262 return cnt;
1263}
1264
1265/*
1266 * Print torture statistics. Caller must ensure that there is only
1267 * one call to this function at a given time!!! This is normally
1268 * accomplished by relying on the module system to only have one copy
1269 * of the module loaded, and then by giving the rcu_torture_stats
1270 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1271 * thread is not running).
1272 */
1273static void
1274rcu_torture_stats_print(void)
1275{
1276 int cnt;
1277
1278 cnt = rcu_torture_printk(printk_buf);
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001279 pr_alert("%s", printk_buf);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001280}
1281
1282/*
1283 * Periodically prints torture statistics, if periodic statistics printing
1284 * was specified via the stat_interval module parameter.
1285 *
1286 * No need to worry about fullstop here, since this one doesn't reference
1287 * volatile state or register callbacks.
1288 */
1289static int
1290rcu_torture_stats(void *arg)
1291{
1292 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1293 do {
1294 schedule_timeout_interruptible(stat_interval * HZ);
1295 rcu_torture_stats_print();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001296 rcutorture_shutdown_absorb("rcu_torture_stats");
1297 } while (!kthread_should_stop());
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001298 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1299 return 0;
1300}
1301
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001302static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
1303
1304/* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1305 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1306 */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -07001307static void rcu_torture_shuffle_tasks(void)
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001308{
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001309 int i;
1310
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001311 cpumask_setall(shuffle_tmp_mask);
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001312 get_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001313
1314 /* No point in shuffling if there is only one online CPU (ex: UP) */
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001315 if (num_online_cpus() == 1) {
1316 put_online_cpus();
1317 return;
1318 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001319
1320 if (rcu_idle_cpu != -1)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001321 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001322
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001323 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001324
Josh Triplettc8e5b162007-05-08 00:33:20 -07001325 if (reader_tasks) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001326 for (i = 0; i < nrealreaders; i++)
1327 if (reader_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001328 set_cpus_allowed_ptr(reader_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001329 shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001330 }
1331
Josh Triplettc8e5b162007-05-08 00:33:20 -07001332 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001333 for (i = 0; i < nfakewriters; i++)
1334 if (fakewriter_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001335 set_cpus_allowed_ptr(fakewriter_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001336 shuffle_tmp_mask);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001337 }
1338
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001339 if (writer_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001340 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001341
1342 if (stats_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001343 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001344
1345 if (rcu_idle_cpu == -1)
1346 rcu_idle_cpu = num_online_cpus() - 1;
1347 else
1348 rcu_idle_cpu--;
1349
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001350 put_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001351}
1352
1353/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1354 * system to become idle at a time and cut off its timer ticks. This is meant
1355 * to test the support for such tickless idle CPU in RCU.
1356 */
1357static int
1358rcu_torture_shuffle(void *arg)
1359{
1360 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1361 do {
1362 schedule_timeout_interruptible(shuffle_interval * HZ);
1363 rcu_torture_shuffle_tasks();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001364 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1365 } while (!kthread_should_stop());
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001366 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1367 return 0;
1368}
1369
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001370/* Cause the rcutorture test to "stutter", starting and stopping all
1371 * threads periodically.
1372 */
1373static int
1374rcu_torture_stutter(void *arg)
1375{
1376 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1377 do {
1378 schedule_timeout_interruptible(stutter * HZ);
1379 stutter_pause_test = 1;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001380 if (!kthread_should_stop())
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001381 schedule_timeout_interruptible(stutter * HZ);
1382 stutter_pause_test = 0;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001383 rcutorture_shutdown_absorb("rcu_torture_stutter");
1384 } while (!kthread_should_stop());
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001385 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1386 return 0;
1387}
1388
Paul E. McKenney95c38322006-03-24 03:15:58 -08001389static inline void
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001390rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
Paul E. McKenney95c38322006-03-24 03:15:58 -08001391{
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001392 pr_alert("%s" TORTURE_FLAG
1393 "--- %s: nreaders=%d nfakewriters=%d "
1394 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1395 "shuffle_interval=%d stutter=%d irqreader=%d "
1396 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1397 "test_boost=%d/%d test_boost_interval=%d "
1398 "test_boost_duration=%d shutdown_secs=%d "
1399 "onoff_interval=%d onoff_holdoff=%d\n",
1400 torture_type, tag, nrealreaders, nfakewriters,
1401 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
1402 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1403 test_boost, cur_ops->can_boost,
1404 test_boost_interval, test_boost_duration, shutdown_secs,
1405 onoff_interval, onoff_holdoff);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001406}
1407
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001408static struct notifier_block rcutorture_shutdown_nb = {
Paul E. McKenney343e9092008-12-15 16:13:07 -08001409 .notifier_call = rcutorture_shutdown_notify,
1410};
1411
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001412static void rcutorture_booster_cleanup(int cpu)
1413{
1414 struct task_struct *t;
1415
1416 if (boost_tasks[cpu] == NULL)
1417 return;
1418 mutex_lock(&boost_mutex);
1419 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1420 t = boost_tasks[cpu];
1421 boost_tasks[cpu] = NULL;
1422 mutex_unlock(&boost_mutex);
1423
1424 /* This must be outside of the mutex, otherwise deadlock! */
1425 kthread_stop(t);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001426 boost_tasks[cpu] = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001427}
1428
1429static int rcutorture_booster_init(int cpu)
1430{
1431 int retval;
1432
1433 if (boost_tasks[cpu] != NULL)
1434 return 0; /* Already created, nothing more to do. */
1435
1436 /* Don't allow time recalculation while creating a new task. */
1437 mutex_lock(&boost_mutex);
1438 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
Eric Dumazet1f288092011-06-16 15:53:18 -07001439 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1440 cpu_to_node(cpu),
1441 "rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001442 if (IS_ERR(boost_tasks[cpu])) {
1443 retval = PTR_ERR(boost_tasks[cpu]);
1444 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1445 n_rcu_torture_boost_ktrerror++;
1446 boost_tasks[cpu] = NULL;
1447 mutex_unlock(&boost_mutex);
1448 return retval;
1449 }
1450 kthread_bind(boost_tasks[cpu], cpu);
1451 wake_up_process(boost_tasks[cpu]);
1452 mutex_unlock(&boost_mutex);
1453 return 0;
1454}
1455
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001456/*
1457 * Cause the rcutorture test to shutdown the system after the test has
1458 * run for the time specified by the shutdown_secs module parameter.
1459 */
1460static int
1461rcu_torture_shutdown(void *arg)
1462{
1463 long delta;
1464 unsigned long jiffies_snap;
1465
1466 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1467 jiffies_snap = ACCESS_ONCE(jiffies);
1468 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
1469 !kthread_should_stop()) {
1470 delta = shutdown_time - jiffies_snap;
1471 if (verbose)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001472 pr_alert("%s" TORTURE_FLAG
1473 "rcu_torture_shutdown task: %lu jiffies remaining\n",
1474 torture_type, delta);
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001475 schedule_timeout_interruptible(delta);
1476 jiffies_snap = ACCESS_ONCE(jiffies);
1477 }
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001478 if (kthread_should_stop()) {
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001479 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1480 return 0;
1481 }
1482
1483 /* OK, shut down the system. */
1484
1485 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1486 shutdown_task = NULL; /* Avoid self-kill deadlock. */
1487 rcu_torture_cleanup(); /* Get the success/failure message. */
1488 kernel_power_off(); /* Shut down the system. */
1489 return 0;
1490}
1491
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001492#ifdef CONFIG_HOTPLUG_CPU
1493
1494/*
1495 * Execute random CPU-hotplug operations at the interval specified
1496 * by the onoff_interval.
1497 */
Heiko Carstens44100302011-12-27 15:04:26 +01001498static int __cpuinit
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001499rcu_torture_onoff(void *arg)
1500{
1501 int cpu;
Paul E. McKenney13dbf912012-07-23 12:05:55 -07001502 unsigned long delta;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001503 int maxcpu = -1;
1504 DEFINE_RCU_RANDOM(rand);
Paul E. McKenney48983262012-09-24 16:08:31 -07001505 int ret;
Paul E. McKenney13dbf912012-07-23 12:05:55 -07001506 unsigned long starttime;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001507
1508 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1509 for_each_online_cpu(cpu)
1510 maxcpu = cpu;
1511 WARN_ON(maxcpu < 0);
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -08001512 if (onoff_holdoff > 0) {
1513 VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff");
1514 schedule_timeout_interruptible(onoff_holdoff * HZ);
1515 VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff");
1516 }
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001517 while (!kthread_should_stop()) {
1518 cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
Paul E. McKenneyf2202422011-12-03 15:09:28 -08001519 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001520 if (verbose)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001521 pr_alert("%s" TORTURE_FLAG
1522 "rcu_torture_onoff task: offlining %d\n",
1523 torture_type, cpu);
Paul E. McKenney13dbf912012-07-23 12:05:55 -07001524 starttime = jiffies;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001525 n_offline_attempts++;
Paul E. McKenney48983262012-09-24 16:08:31 -07001526 ret = cpu_down(cpu);
1527 if (ret) {
1528 if (verbose)
1529 pr_alert("%s" TORTURE_FLAG
1530 "rcu_torture_onoff task: offline %d failed: errno %d\n",
1531 torture_type, cpu, ret);
1532 } else {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001533 if (verbose)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001534 pr_alert("%s" TORTURE_FLAG
1535 "rcu_torture_onoff task: offlined %d\n",
1536 torture_type, cpu);
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001537 n_offline_successes++;
Paul E. McKenney13dbf912012-07-23 12:05:55 -07001538 delta = jiffies - starttime;
1539 sum_offline += delta;
1540 if (min_offline < 0) {
1541 min_offline = delta;
1542 max_offline = delta;
1543 }
1544 if (min_offline > delta)
1545 min_offline = delta;
1546 if (max_offline < delta)
1547 max_offline = delta;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001548 }
Paul E. McKenneyf2202422011-12-03 15:09:28 -08001549 } else if (cpu_is_hotpluggable(cpu)) {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001550 if (verbose)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001551 pr_alert("%s" TORTURE_FLAG
1552 "rcu_torture_onoff task: onlining %d\n",
1553 torture_type, cpu);
Paul E. McKenney13dbf912012-07-23 12:05:55 -07001554 starttime = jiffies;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001555 n_online_attempts++;
1556 if (cpu_up(cpu) == 0) {
1557 if (verbose)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001558 pr_alert("%s" TORTURE_FLAG
1559 "rcu_torture_onoff task: onlined %d\n",
1560 torture_type, cpu);
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001561 n_online_successes++;
Paul E. McKenney13dbf912012-07-23 12:05:55 -07001562 delta = jiffies - starttime;
1563 sum_online += delta;
1564 if (min_online < 0) {
1565 min_online = delta;
1566 max_online = delta;
1567 }
1568 if (min_online > delta)
1569 min_online = delta;
1570 if (max_online < delta)
1571 max_online = delta;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001572 }
1573 }
1574 schedule_timeout_interruptible(onoff_interval * HZ);
1575 }
1576 VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1577 return 0;
1578}
1579
Heiko Carstens44100302011-12-27 15:04:26 +01001580static int __cpuinit
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001581rcu_torture_onoff_init(void)
1582{
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001583 int ret;
1584
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001585 if (onoff_interval <= 0)
1586 return 0;
1587 onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff");
1588 if (IS_ERR(onoff_task)) {
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001589 ret = PTR_ERR(onoff_task);
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001590 onoff_task = NULL;
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001591 return ret;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001592 }
1593 return 0;
1594}
1595
1596static void rcu_torture_onoff_cleanup(void)
1597{
1598 if (onoff_task == NULL)
1599 return;
1600 VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1601 kthread_stop(onoff_task);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001602 onoff_task = NULL;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001603}
1604
1605#else /* #ifdef CONFIG_HOTPLUG_CPU */
1606
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001607static int
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001608rcu_torture_onoff_init(void)
1609{
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001610 return 0;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001611}
1612
1613static void rcu_torture_onoff_cleanup(void)
1614{
1615}
1616
1617#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1618
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001619/*
1620 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1621 * induces a CPU stall for the time specified by stall_cpu.
1622 */
1623static int __cpuinit rcu_torture_stall(void *args)
1624{
1625 unsigned long stop_at;
1626
1627 VERBOSE_PRINTK_STRING("rcu_torture_stall task started");
1628 if (stall_cpu_holdoff > 0) {
1629 VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff");
1630 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
1631 VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff");
1632 }
1633 if (!kthread_should_stop()) {
1634 stop_at = get_seconds() + stall_cpu;
1635 /* RCU CPU stall is expected behavior in following code. */
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001636 pr_alert("rcu_torture_stall start.\n");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001637 rcu_read_lock();
1638 preempt_disable();
1639 while (ULONG_CMP_LT(get_seconds(), stop_at))
1640 continue; /* Induce RCU CPU stall warning. */
1641 preempt_enable();
1642 rcu_read_unlock();
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001643 pr_alert("rcu_torture_stall end.\n");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001644 }
1645 rcutorture_shutdown_absorb("rcu_torture_stall");
1646 while (!kthread_should_stop())
1647 schedule_timeout_interruptible(10 * HZ);
1648 return 0;
1649}
1650
1651/* Spawn CPU-stall kthread, if stall_cpu specified. */
1652static int __init rcu_torture_stall_init(void)
1653{
1654 int ret;
1655
1656 if (stall_cpu <= 0)
1657 return 0;
1658 stall_task = kthread_run(rcu_torture_stall, NULL, "rcu_torture_stall");
1659 if (IS_ERR(stall_task)) {
1660 ret = PTR_ERR(stall_task);
1661 stall_task = NULL;
1662 return ret;
1663 }
1664 return 0;
1665}
1666
1667/* Clean up after the CPU-stall kthread, if one was spawned. */
1668static void rcu_torture_stall_cleanup(void)
1669{
1670 if (stall_task == NULL)
1671 return;
1672 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task.");
1673 kthread_stop(stall_task);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001674 stall_task = NULL;
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001675}
1676
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001677/* Callback function for RCU barrier testing. */
1678void rcu_torture_barrier_cbf(struct rcu_head *rcu)
1679{
1680 atomic_inc(&barrier_cbs_invoked);
1681}
1682
1683/* kthread function to register callbacks used to test RCU barriers. */
1684static int rcu_torture_barrier_cbs(void *arg)
1685{
1686 long myid = (long)arg;
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001687 bool lastphase = 0;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001688 struct rcu_head rcu;
1689
1690 init_rcu_head_on_stack(&rcu);
1691 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
1692 set_user_nice(current, 19);
1693 do {
1694 wait_event(barrier_cbs_wq[myid],
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001695 barrier_phase != lastphase ||
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001696 kthread_should_stop() ||
1697 fullstop != FULLSTOP_DONTSTOP);
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001698 lastphase = barrier_phase;
1699 smp_mb(); /* ensure barrier_phase load before ->call(). */
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001700 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1701 break;
1702 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1703 if (atomic_dec_and_test(&barrier_cbs_count))
1704 wake_up(&barrier_wq);
1705 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1706 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task stopping");
1707 rcutorture_shutdown_absorb("rcu_torture_barrier_cbs");
1708 while (!kthread_should_stop())
1709 schedule_timeout_interruptible(1);
1710 cur_ops->cb_barrier();
1711 destroy_rcu_head_on_stack(&rcu);
1712 return 0;
1713}
1714
1715/* kthread function to drive and coordinate RCU barrier testing. */
1716static int rcu_torture_barrier(void *arg)
1717{
1718 int i;
1719
1720 VERBOSE_PRINTK_STRING("rcu_torture_barrier task starting");
1721 do {
1722 atomic_set(&barrier_cbs_invoked, 0);
1723 atomic_set(&barrier_cbs_count, n_barrier_cbs);
Paul E. McKenneyc6ebcbb2012-05-28 19:21:41 -07001724 smp_mb(); /* Ensure barrier_phase after prior assignments. */
1725 barrier_phase = !barrier_phase;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001726 for (i = 0; i < n_barrier_cbs; i++)
1727 wake_up(&barrier_cbs_wq[i]);
1728 wait_event(barrier_wq,
1729 atomic_read(&barrier_cbs_count) == 0 ||
1730 kthread_should_stop() ||
1731 fullstop != FULLSTOP_DONTSTOP);
1732 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1733 break;
1734 n_barrier_attempts++;
1735 cur_ops->cb_barrier();
1736 if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
1737 n_rcu_torture_barrier_error++;
1738 WARN_ON_ONCE(1);
1739 }
1740 n_barrier_successes++;
1741 schedule_timeout_interruptible(HZ / 10);
1742 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
1743 VERBOSE_PRINTK_STRING("rcu_torture_barrier task stopping");
Paul E. McKenney143aa672012-05-24 18:17:48 -07001744 rcutorture_shutdown_absorb("rcu_torture_barrier");
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001745 while (!kthread_should_stop())
1746 schedule_timeout_interruptible(1);
1747 return 0;
1748}
1749
1750/* Initialize RCU barrier testing. */
1751static int rcu_torture_barrier_init(void)
1752{
1753 int i;
1754 int ret;
1755
1756 if (n_barrier_cbs == 0)
1757 return 0;
1758 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001759 pr_alert("%s" TORTURE_FLAG
1760 " Call or barrier ops missing for %s,\n",
1761 torture_type, cur_ops->name);
1762 pr_alert("%s" TORTURE_FLAG
1763 " RCU barrier testing omitted from run.\n",
1764 torture_type);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001765 return 0;
1766 }
1767 atomic_set(&barrier_cbs_count, 0);
1768 atomic_set(&barrier_cbs_invoked, 0);
1769 barrier_cbs_tasks =
1770 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
1771 GFP_KERNEL);
1772 barrier_cbs_wq =
1773 kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
1774 GFP_KERNEL);
1775 if (barrier_cbs_tasks == NULL || barrier_cbs_wq == 0)
1776 return -ENOMEM;
1777 for (i = 0; i < n_barrier_cbs; i++) {
1778 init_waitqueue_head(&barrier_cbs_wq[i]);
1779 barrier_cbs_tasks[i] = kthread_run(rcu_torture_barrier_cbs,
Lai Jiangshan9059c942012-03-19 16:12:14 +08001780 (void *)(long)i,
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001781 "rcu_torture_barrier_cbs");
1782 if (IS_ERR(barrier_cbs_tasks[i])) {
1783 ret = PTR_ERR(barrier_cbs_tasks[i]);
1784 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier_cbs");
1785 barrier_cbs_tasks[i] = NULL;
1786 return ret;
1787 }
1788 }
1789 barrier_task = kthread_run(rcu_torture_barrier, NULL,
1790 "rcu_torture_barrier");
1791 if (IS_ERR(barrier_task)) {
1792 ret = PTR_ERR(barrier_task);
1793 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier");
1794 barrier_task = NULL;
1795 }
1796 return 0;
1797}
1798
1799/* Clean up after RCU barrier testing. */
1800static void rcu_torture_barrier_cleanup(void)
1801{
1802 int i;
1803
1804 if (barrier_task != NULL) {
1805 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier task");
1806 kthread_stop(barrier_task);
1807 barrier_task = NULL;
1808 }
1809 if (barrier_cbs_tasks != NULL) {
1810 for (i = 0; i < n_barrier_cbs; i++) {
1811 if (barrier_cbs_tasks[i] != NULL) {
1812 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier_cbs task");
1813 kthread_stop(barrier_cbs_tasks[i]);
1814 barrier_cbs_tasks[i] = NULL;
1815 }
1816 }
1817 kfree(barrier_cbs_tasks);
1818 barrier_cbs_tasks = NULL;
1819 }
1820 if (barrier_cbs_wq != NULL) {
1821 kfree(barrier_cbs_wq);
1822 barrier_cbs_wq = NULL;
1823 }
1824}
1825
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001826static int rcutorture_cpu_notify(struct notifier_block *self,
1827 unsigned long action, void *hcpu)
1828{
1829 long cpu = (long)hcpu;
1830
1831 switch (action) {
1832 case CPU_ONLINE:
1833 case CPU_DOWN_FAILED:
1834 (void)rcutorture_booster_init(cpu);
1835 break;
1836 case CPU_DOWN_PREPARE:
1837 rcutorture_booster_cleanup(cpu);
1838 break;
1839 default:
1840 break;
1841 }
1842 return NOTIFY_OK;
1843}
1844
1845static struct notifier_block rcutorture_cpu_nb = {
1846 .notifier_call = rcutorture_cpu_notify,
1847};
1848
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001849static void
1850rcu_torture_cleanup(void)
1851{
1852 int i;
1853
Paul E. McKenney343e9092008-12-15 16:13:07 -08001854 mutex_lock(&fullstop_mutex);
Paul E. McKenney4a298652011-04-03 21:33:51 -07001855 rcutorture_record_test_transition();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001856 if (fullstop == FULLSTOP_SHUTDOWN) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001857 pr_warn(/* but going down anyway, so... */
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001858 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001859 mutex_unlock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001860 schedule_timeout_uninterruptible(10);
Paul E. McKenney343e9092008-12-15 16:13:07 -08001861 if (cur_ops->cb_barrier != NULL)
1862 cur_ops->cb_barrier();
1863 return;
1864 }
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001865 fullstop = FULLSTOP_RMMOD;
Paul E. McKenney343e9092008-12-15 16:13:07 -08001866 mutex_unlock(&fullstop_mutex);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001867 unregister_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001868 rcu_torture_barrier_cleanup();
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001869 rcu_torture_stall_cleanup();
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001870 if (stutter_task) {
1871 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1872 kthread_stop(stutter_task);
1873 }
1874 stutter_task = NULL;
Josh Triplettc8e5b162007-05-08 00:33:20 -07001875 if (shuffler_task) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001876 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1877 kthread_stop(shuffler_task);
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001878 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001879 }
1880 shuffler_task = NULL;
1881
Josh Triplettc8e5b162007-05-08 00:33:20 -07001882 if (writer_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001883 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1884 kthread_stop(writer_task);
1885 }
1886 writer_task = NULL;
1887
Josh Triplettc8e5b162007-05-08 00:33:20 -07001888 if (reader_tasks) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001889 for (i = 0; i < nrealreaders; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001890 if (reader_tasks[i]) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001891 VERBOSE_PRINTK_STRING(
1892 "Stopping rcu_torture_reader task");
1893 kthread_stop(reader_tasks[i]);
1894 }
1895 reader_tasks[i] = NULL;
1896 }
1897 kfree(reader_tasks);
1898 reader_tasks = NULL;
1899 }
1900 rcu_torture_current = NULL;
1901
Josh Triplettc8e5b162007-05-08 00:33:20 -07001902 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001903 for (i = 0; i < nfakewriters; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001904 if (fakewriter_tasks[i]) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001905 VERBOSE_PRINTK_STRING(
1906 "Stopping rcu_torture_fakewriter task");
1907 kthread_stop(fakewriter_tasks[i]);
1908 }
1909 fakewriter_tasks[i] = NULL;
1910 }
1911 kfree(fakewriter_tasks);
1912 fakewriter_tasks = NULL;
1913 }
1914
Josh Triplettc8e5b162007-05-08 00:33:20 -07001915 if (stats_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001916 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1917 kthread_stop(stats_task);
1918 }
1919 stats_task = NULL;
1920
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001921 if (fqs_task) {
1922 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1923 kthread_stop(fqs_task);
1924 }
1925 fqs_task = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001926 if ((test_boost == 1 && cur_ops->can_boost) ||
1927 test_boost == 2) {
1928 unregister_cpu_notifier(&rcutorture_cpu_nb);
1929 for_each_possible_cpu(i)
1930 rcutorture_booster_cleanup(i);
1931 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001932 if (shutdown_task != NULL) {
1933 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1934 kthread_stop(shutdown_task);
1935 }
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001936 shutdown_task = NULL;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001937 rcu_torture_onoff_cleanup();
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001938
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001939 /* Wait for all RCU callbacks to fire. */
Paul E. McKenney23269742008-05-12 21:21:05 +02001940
1941 if (cur_ops->cb_barrier != NULL)
1942 cur_ops->cb_barrier();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001943
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001944 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001945
Josh Triplettc8e5b162007-05-08 00:33:20 -07001946 if (cur_ops->cleanup)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001947 cur_ops->cleanup();
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001948 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001949 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
Paul E. McKenney091541b2012-01-10 12:51:14 -08001950 else if (n_online_successes != n_online_attempts ||
1951 n_offline_successes != n_offline_attempts)
1952 rcu_torture_print_module_parms(cur_ops,
1953 "End of test: RCU_HOTPLUG");
Paul E. McKenney95c38322006-03-24 03:15:58 -08001954 else
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001955 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001956}
1957
Josh Triplett6f8bc502007-05-08 00:25:24 -07001958static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001959rcu_torture_init(void)
1960{
1961 int i;
1962 int cpu;
1963 int firsterr = 0;
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08001964 int retval;
Josh Triplettade5fb82007-05-08 00:33:22 -07001965 static struct rcu_torture_ops *torture_ops[] =
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -08001966 { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -07001967 &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops,
Paul E. McKenney751a68b2012-05-07 13:44:44 -07001968 &srcu_ops, &srcu_sync_ops, &srcu_expedited_ops,
1969 &srcu_raw_ops, &srcu_raw_sync_ops,
Paul E. McKenney804bb832009-10-25 19:03:52 -07001970 &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001971
Paul E. McKenney343e9092008-12-15 16:13:07 -08001972 mutex_lock(&fullstop_mutex);
1973
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001974 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001975 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001976 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001977 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001978 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001979 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001980 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001981 pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
1982 torture_type);
1983 pr_alert("rcu-torture types:");
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001984 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001985 pr_alert(" %s", torture_ops[i]->name);
1986 pr_alert("\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001987 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001988 return -EINVAL;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001989 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001990 if (cur_ops->fqs == NULL && fqs_duration != 0) {
Paul E. McKenney2caa1e42012-08-09 16:30:45 -07001991 pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001992 fqs_duration = 0;
1993 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001994 if (cur_ops->init)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001995 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1996
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001997 if (nreaders >= 0)
1998 nrealreaders = nreaders;
1999 else
2000 nrealreaders = 2 * num_online_cpus();
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002001 rcu_torture_print_module_parms(cur_ops, "Start of test");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08002002 fullstop = FULLSTOP_DONTSTOP;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002003
2004 /* Set up the freelist. */
2005
2006 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07002007 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08002008 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002009 list_add_tail(&rcu_tortures[i].rtort_free,
2010 &rcu_torture_freelist);
2011 }
2012
2013 /* Initialize the statistics so that each run gets its own numbers. */
2014
2015 rcu_torture_current = NULL;
2016 rcu_torture_current_version = 0;
2017 atomic_set(&n_rcu_torture_alloc, 0);
2018 atomic_set(&n_rcu_torture_alloc_fail, 0);
2019 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08002020 atomic_set(&n_rcu_torture_mberror, 0);
2021 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08002022 n_rcu_torture_barrier_error = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002023 n_rcu_torture_boost_ktrerror = 0;
2024 n_rcu_torture_boost_rterror = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002025 n_rcu_torture_boost_failure = 0;
2026 n_rcu_torture_boosts = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002027 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
2028 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08002029 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002030 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
2031 per_cpu(rcu_torture_count, cpu)[i] = 0;
2032 per_cpu(rcu_torture_batch, cpu)[i] = 0;
2033 }
2034 }
2035
2036 /* Start up the kthreads. */
2037
2038 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
Paul E. McKenney60f53782012-08-25 15:27:40 -07002039 writer_task = kthread_create(rcu_torture_writer, NULL,
2040 "rcu_torture_writer");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002041 if (IS_ERR(writer_task)) {
2042 firsterr = PTR_ERR(writer_task);
2043 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
2044 writer_task = NULL;
2045 goto unwind;
2046 }
Paul E. McKenney60f53782012-08-25 15:27:40 -07002047 wake_up_process(writer_task);
Josh Triplettb772e1d2006-10-04 02:17:13 -07002048 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
Paul E. McKenneya71fca52009-09-18 10:28:19 -07002049 GFP_KERNEL);
Josh Triplettb772e1d2006-10-04 02:17:13 -07002050 if (fakewriter_tasks == NULL) {
2051 VERBOSE_PRINTK_ERRSTRING("out of memory");
2052 firsterr = -ENOMEM;
2053 goto unwind;
2054 }
2055 for (i = 0; i < nfakewriters; i++) {
2056 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
2057 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -07002058 "rcu_torture_fakewriter");
Josh Triplettb772e1d2006-10-04 02:17:13 -07002059 if (IS_ERR(fakewriter_tasks[i])) {
2060 firsterr = PTR_ERR(fakewriter_tasks[i]);
2061 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
2062 fakewriter_tasks[i] = NULL;
2063 goto unwind;
2064 }
2065 }
Josh Triplett2860aab2006-10-04 02:17:11 -07002066 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002067 GFP_KERNEL);
2068 if (reader_tasks == NULL) {
2069 VERBOSE_PRINTK_ERRSTRING("out of memory");
2070 firsterr = -ENOMEM;
2071 goto unwind;
2072 }
2073 for (i = 0; i < nrealreaders; i++) {
2074 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
2075 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
2076 "rcu_torture_reader");
2077 if (IS_ERR(reader_tasks[i])) {
2078 firsterr = PTR_ERR(reader_tasks[i]);
2079 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
2080 reader_tasks[i] = NULL;
2081 goto unwind;
2082 }
2083 }
2084 if (stat_interval > 0) {
2085 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
2086 stats_task = kthread_run(rcu_torture_stats, NULL,
2087 "rcu_torture_stats");
2088 if (IS_ERR(stats_task)) {
2089 firsterr = PTR_ERR(stats_task);
2090 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
2091 stats_task = NULL;
2092 goto unwind;
2093 }
2094 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08002095 if (test_no_idle_hz) {
2096 rcu_idle_cpu = num_online_cpus() - 1;
Rusty Russell73d0a4b2009-03-30 22:05:16 -06002097
2098 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
2099 firsterr = -ENOMEM;
2100 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
2101 goto unwind;
2102 }
2103
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08002104 /* Create the shuffler thread */
2105 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
2106 "rcu_torture_shuffle");
2107 if (IS_ERR(shuffler_task)) {
Rusty Russell73d0a4b2009-03-30 22:05:16 -06002108 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08002109 firsterr = PTR_ERR(shuffler_task);
2110 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
2111 shuffler_task = NULL;
2112 goto unwind;
2113 }
2114 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07002115 if (stutter < 0)
2116 stutter = 0;
2117 if (stutter) {
2118 /* Create the stutter thread */
2119 stutter_task = kthread_run(rcu_torture_stutter, NULL,
2120 "rcu_torture_stutter");
2121 if (IS_ERR(stutter_task)) {
2122 firsterr = PTR_ERR(stutter_task);
2123 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
2124 stutter_task = NULL;
2125 goto unwind;
2126 }
2127 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08002128 if (fqs_duration < 0)
2129 fqs_duration = 0;
2130 if (fqs_duration) {
2131 /* Create the stutter thread */
2132 fqs_task = kthread_run(rcu_torture_fqs, NULL,
2133 "rcu_torture_fqs");
2134 if (IS_ERR(fqs_task)) {
2135 firsterr = PTR_ERR(fqs_task);
2136 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
2137 fqs_task = NULL;
2138 goto unwind;
2139 }
2140 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002141 if (test_boost_interval < 1)
2142 test_boost_interval = 1;
2143 if (test_boost_duration < 2)
2144 test_boost_duration = 2;
2145 if ((test_boost == 1 && cur_ops->can_boost) ||
2146 test_boost == 2) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002147
2148 boost_starttime = jiffies + test_boost_interval * HZ;
2149 register_cpu_notifier(&rcutorture_cpu_nb);
2150 for_each_possible_cpu(i) {
2151 if (cpu_is_offline(i))
2152 continue; /* Heuristic: CPU can go offline. */
2153 retval = rcutorture_booster_init(i);
2154 if (retval < 0) {
2155 firsterr = retval;
2156 goto unwind;
2157 }
2158 }
2159 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07002160 if (shutdown_secs > 0) {
2161 shutdown_time = jiffies + shutdown_secs * HZ;
Paul E. McKenney60f53782012-08-25 15:27:40 -07002162 shutdown_task = kthread_create(rcu_torture_shutdown, NULL,
2163 "rcu_torture_shutdown");
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07002164 if (IS_ERR(shutdown_task)) {
2165 firsterr = PTR_ERR(shutdown_task);
2166 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
2167 shutdown_task = NULL;
2168 goto unwind;
2169 }
Paul E. McKenney60f53782012-08-25 15:27:40 -07002170 wake_up_process(shutdown_task);
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07002171 }
Paul E. McKenney37e377d2012-02-17 22:12:18 -08002172 i = rcu_torture_onoff_init();
2173 if (i != 0) {
2174 firsterr = i;
2175 goto unwind;
2176 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07002177 register_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08002178 i = rcu_torture_stall_init();
2179 if (i != 0) {
2180 firsterr = i;
2181 goto unwind;
2182 }
Paul E. McKenneyfae4b542012-02-20 17:51:45 -08002183 retval = rcu_torture_barrier_init();
2184 if (retval != 0) {
2185 firsterr = retval;
2186 goto unwind;
2187 }
Paul E. McKenney4a298652011-04-03 21:33:51 -07002188 rcutorture_record_test_transition();
Paul E. McKenney343e9092008-12-15 16:13:07 -08002189 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002190 return 0;
2191
2192unwind:
Paul E. McKenney343e9092008-12-15 16:13:07 -08002193 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08002194 rcu_torture_cleanup();
2195 return firsterr;
2196}
2197
2198module_init(rcu_torture_init);
2199module_exit(rcu_torture_cleanup);