blob: 1463a06364431ed58c0267b0f381025deed281eb [file] [log] [blame]
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001/*
Paul E. McKenney29766f12006-06-27 02:54:02 -07002 * Read-Copy Update module-based torture test facility
Paul E. McKenneya241ec62005-10-30 15:03:12 -08003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
Josh Triplettb772e1d2006-10-04 02:17:13 -070018 * Copyright (C) IBM Corporation, 2005, 2006
Paul E. McKenneya241ec62005-10-30 15:03:12 -080019 *
20 * Authors: Paul E. McKenney <paulmck@us.ibm.com>
Paul E. McKenneya71fca52009-09-18 10:28:19 -070021 * Josh Triplett <josh@freedesktop.org>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080022 *
23 * See also: Documentation/RCU/torture.txt
24 */
25#include <linux/types.h>
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/module.h>
29#include <linux/kthread.h>
30#include <linux/err.h>
31#include <linux/spinlock.h>
32#include <linux/smp.h>
33#include <linux/rcupdate.h>
34#include <linux/interrupt.h>
35#include <linux/sched.h>
Arun Sharma600634972011-07-26 16:09:06 -070036#include <linux/atomic.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080037#include <linux/bitops.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080038#include <linux/completion.h>
39#include <linux/moduleparam.h>
40#include <linux/percpu.h>
41#include <linux/notifier.h>
Paul E. McKenney343e9092008-12-15 16:13:07 -080042#include <linux/reboot.h>
Rafael J. Wysocki83144182007-07-17 04:03:35 -070043#include <linux/freezer.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080044#include <linux/cpu.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080045#include <linux/delay.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080046#include <linux/stat.h>
Paul E. McKenneyb2896d22006-10-04 02:17:03 -070047#include <linux/srcu.h>
Robert P. J. Day1aeb2722008-04-29 00:59:25 -070048#include <linux/slab.h>
Harvey Harrisonf07767f2008-10-20 10:23:38 -070049#include <asm/byteorder.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080050
51MODULE_LICENSE("GPL");
Josh Triplettb772e1d2006-10-04 02:17:13 -070052MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and "
Paul E. McKenneya71fca52009-09-18 10:28:19 -070053 "Josh Triplett <josh@freedesktop.org>");
Paul E. McKenneya241ec62005-10-30 15:03:12 -080054
Josh Triplett48022112006-10-03 23:26:16 +020055static int nreaders = -1; /* # reader threads, defaults to 2*ncpus */
Josh Triplettb772e1d2006-10-04 02:17:13 -070056static int nfakewriters = 4; /* # fake writer threads */
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080057static int stat_interval; /* Interval between stats, in seconds. */
Paul E. McKenneya241ec62005-10-30 15:03:12 -080058 /* Defaults to "only at end of test". */
Rusty Russelld8e8ed92011-12-15 13:43:24 +103059static bool verbose; /* Print more debug info. */
60static bool test_no_idle_hz; /* Test RCU's support for tickless idle CPUs. */
Paul E. McKenneyd120f652008-06-18 05:21:44 -070061static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/
62static int stutter = 5; /* Start/stop testing interval (in sec) */
Paul E. McKenney0729fbf2008-06-25 12:24:52 -070063static int irqreader = 1; /* RCU readers from irq (timers). */
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -070064static int fqs_duration; /* Duration of bursts (us), 0 to disable. */
65static int fqs_holdoff; /* Hold time within burst (us). */
Paul E. McKenneybf66f182010-01-04 15:09:10 -080066static int fqs_stutter = 3; /* Wait time between bursts (s). */
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -080067static int onoff_interval; /* Wait time between CPU hotplugs, 0=disable. */
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -080068static int onoff_holdoff; /* Seconds after boot before CPU hotplugs. */
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -070069static int shutdown_secs; /* Shutdown time (s). <=0 for no shutdown. */
Paul E. McKenneyc13f3752012-01-20 15:36:33 -080070static int stall_cpu; /* CPU-stall duration (s). 0 for no stall. */
71static int stall_cpu_holdoff = 10; /* Time to wait until stall (s). */
Paul E. McKenney8e8be452010-09-02 16:16:14 -070072static int test_boost = 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */
73static int test_boost_interval = 7; /* Interval between boost tests, seconds. */
74static int test_boost_duration = 4; /* Duration of each boost test, seconds. */
Josh Triplett20d2e422006-10-04 02:17:15 -070075static char *torture_type = "rcu"; /* What RCU implementation to torture. */
Paul E. McKenneya241ec62005-10-30 15:03:12 -080076
Josh Triplettd6ad6712007-03-06 01:42:13 -080077module_param(nreaders, int, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080078MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
Josh Triplettd6ad6712007-03-06 01:42:13 -080079module_param(nfakewriters, int, 0444);
Josh Triplettb772e1d2006-10-04 02:17:13 -070080MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
Paul E. McKenney3721bc12011-07-21 16:00:17 -070081module_param(stat_interval, int, 0644);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080082MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
Josh Triplettd6ad6712007-03-06 01:42:13 -080083module_param(verbose, bool, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080084MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
Josh Triplettd6ad6712007-03-06 01:42:13 -080085module_param(test_no_idle_hz, bool, 0444);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080086MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
Josh Triplettd6ad6712007-03-06 01:42:13 -080087module_param(shuffle_interval, int, 0444);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080088MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
Paul E. McKenneyd120f652008-06-18 05:21:44 -070089module_param(stutter, int, 0444);
90MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
Paul E. McKenney0729fbf2008-06-25 12:24:52 -070091module_param(irqreader, int, 0444);
92MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
Paul E. McKenneybf66f182010-01-04 15:09:10 -080093module_param(fqs_duration, int, 0444);
94MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us)");
95module_param(fqs_holdoff, int, 0444);
96MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)");
97module_param(fqs_stutter, int, 0444);
98MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)");
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -080099module_param(onoff_interval, int, 0444);
100MODULE_PARM_DESC(onoff_interval, "Time between CPU hotplugs (s), 0=disable");
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -0800101module_param(onoff_holdoff, int, 0444);
102MODULE_PARM_DESC(onoff_holdoff, "Time after boot before CPU hotplugs (s)");
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700103module_param(shutdown_secs, int, 0444);
104MODULE_PARM_DESC(shutdown_secs, "Shutdown time (s), zero to disable.");
Paul E. McKenneyc13f3752012-01-20 15:36:33 -0800105module_param(stall_cpu, int, 0444);
106MODULE_PARM_DESC(stall_cpu, "Stall duration (s), zero to disable.");
107module_param(stall_cpu_holdoff, int, 0444);
108MODULE_PARM_DESC(stall_cpu_holdoff, "Time to wait before starting stall (s).");
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700109module_param(test_boost, int, 0444);
110MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
111module_param(test_boost_interval, int, 0444);
112MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds.");
113module_param(test_boost_duration, int, 0444);
114MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds.");
Josh Triplettd6ad6712007-03-06 01:42:13 -0800115module_param(torture_type, charp, 0444);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700116MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700117
118#define TORTURE_FLAG "-torture:"
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800119#define PRINTK_STRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700120 do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800121#define VERBOSE_PRINTK_STRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700122 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800123#define VERBOSE_PRINTK_ERRSTRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700124 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800125
126static char printk_buf[4096];
127
128static int nrealreaders;
129static struct task_struct *writer_task;
Josh Triplettb772e1d2006-10-04 02:17:13 -0700130static struct task_struct **fakewriter_tasks;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800131static struct task_struct **reader_tasks;
132static struct task_struct *stats_task;
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800133static struct task_struct *shuffler_task;
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700134static struct task_struct *stutter_task;
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800135static struct task_struct *fqs_task;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700136static struct task_struct *boost_tasks[NR_CPUS];
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700137static struct task_struct *shutdown_task;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -0800138#ifdef CONFIG_HOTPLUG_CPU
139static struct task_struct *onoff_task;
140#endif /* #ifdef CONFIG_HOTPLUG_CPU */
Paul E. McKenneyc13f3752012-01-20 15:36:33 -0800141static struct task_struct *stall_task;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800142
143#define RCU_TORTURE_PIPE_LEN 10
144
145struct rcu_torture {
146 struct rcu_head rtort_rcu;
147 int rtort_pipe_count;
148 struct list_head rtort_free;
Paul E. McKenney996417d2005-11-18 01:10:50 -0800149 int rtort_mbtest;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800150};
151
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800152static LIST_HEAD(rcu_torture_freelist);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700153static struct rcu_torture __rcu *rcu_torture_current;
Paul E. McKenney4a298652011-04-03 21:33:51 -0700154static unsigned long rcu_torture_current_version;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800155static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
156static DEFINE_SPINLOCK(rcu_torture_lock);
157static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
158 { 0 };
159static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
160 { 0 };
161static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700162static atomic_t n_rcu_torture_alloc;
163static atomic_t n_rcu_torture_alloc_fail;
164static atomic_t n_rcu_torture_free;
165static atomic_t n_rcu_torture_mberror;
166static atomic_t n_rcu_torture_error;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700167static long n_rcu_torture_boost_ktrerror;
168static long n_rcu_torture_boost_rterror;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700169static long n_rcu_torture_boost_failure;
170static long n_rcu_torture_boosts;
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700171static long n_rcu_torture_timers;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -0800172static long n_offline_attempts;
173static long n_offline_successes;
174static long n_online_attempts;
175static long n_online_successes;
Josh Triplette3033732006-10-04 02:17:14 -0700176static struct list_head rcu_torture_removed;
Rusty Russell73d0a4b2009-03-30 22:05:16 -0600177static cpumask_var_t shuffle_tmp_mask;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800178
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700179static int stutter_pause_test;
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700180
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700181#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
182#define RCUTORTURE_RUNNABLE_INIT 1
183#else
184#define RCUTORTURE_RUNNABLE_INIT 0
185#endif
186int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
Paul E. McKenneybb3bf702011-11-04 13:24:07 -0700187module_param(rcutorture_runnable, int, 0444);
188MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot");
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700189
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700190#if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700191#define rcu_can_boost() 1
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700192#else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700193#define rcu_can_boost() 0
Paul E. McKenney3acf4a92011-04-17 23:45:23 -0700194#endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700195
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700196static unsigned long shutdown_time; /* jiffies to system shutdown. */
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700197static unsigned long boost_starttime; /* jiffies of next boost test start. */
198DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
199 /* and boost task create/destroy. */
200
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800201/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
202
203#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
204#define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
205#define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
206static int fullstop = FULLSTOP_RMMOD;
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700207/*
208 * Protect fullstop transitions and spawning of kthreads.
209 */
210static DEFINE_MUTEX(fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800211
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -0700212/* Forward reference. */
213static void rcu_torture_cleanup(void);
214
Paul E. McKenney343e9092008-12-15 16:13:07 -0800215/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800216 * Detect and respond to a system shutdown.
Paul E. McKenney343e9092008-12-15 16:13:07 -0800217 */
218static int
219rcutorture_shutdown_notify(struct notifier_block *unused1,
220 unsigned long unused2, void *unused3)
221{
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800222 mutex_lock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800223 if (fullstop == FULLSTOP_DONTSTOP)
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800224 fullstop = FULLSTOP_SHUTDOWN;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800225 else
226 printk(KERN_WARNING /* but going down anyway, so... */
227 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenneyc59ab972009-01-04 18:28:27 -0800228 mutex_unlock(&fullstop_mutex);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800229 return NOTIFY_DONE;
230}
231
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800232/*
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800233 * Absorb kthreads into a kernel function that won't return, so that
234 * they won't ever access module text or data again.
235 */
236static void rcutorture_shutdown_absorb(char *title)
237{
238 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
239 printk(KERN_NOTICE
240 "rcutorture thread %s parking due to system shutdown\n",
241 title);
242 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
243 }
244}
245
246/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800247 * Allocate an element from the rcu_tortures pool.
248 */
Adrian Bunk97a41e22006-01-08 01:02:17 -0800249static struct rcu_torture *
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800250rcu_torture_alloc(void)
251{
252 struct list_head *p;
253
Ingo Molnaradac1662006-01-25 19:50:12 +0100254 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800255 if (list_empty(&rcu_torture_freelist)) {
256 atomic_inc(&n_rcu_torture_alloc_fail);
Ingo Molnaradac1662006-01-25 19:50:12 +0100257 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800258 return NULL;
259 }
260 atomic_inc(&n_rcu_torture_alloc);
261 p = rcu_torture_freelist.next;
262 list_del_init(p);
Ingo Molnaradac1662006-01-25 19:50:12 +0100263 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800264 return container_of(p, struct rcu_torture, rtort_free);
265}
266
267/*
268 * Free an element to the rcu_tortures pool.
269 */
270static void
271rcu_torture_free(struct rcu_torture *p)
272{
273 atomic_inc(&n_rcu_torture_free);
Ingo Molnaradac1662006-01-25 19:50:12 +0100274 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800275 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
Ingo Molnaradac1662006-01-25 19:50:12 +0100276 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800277}
278
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800279struct rcu_random_state {
280 unsigned long rrs_state;
Josh Triplett75cfef32006-10-04 02:17:12 -0700281 long rrs_count;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800282};
283
284#define RCU_RANDOM_MULT 39916801 /* prime */
285#define RCU_RANDOM_ADD 479001701 /* prime */
286#define RCU_RANDOM_REFRESH 10000
287
288#define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
289
290/*
291 * Crude but fast random-number generator. Uses a linear congruential
Paul E. McKenneyc17ac852007-10-16 23:27:19 -0700292 * generator, with occasional help from cpu_clock().
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800293 */
Josh Triplett75cfef32006-10-04 02:17:12 -0700294static unsigned long
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800295rcu_random(struct rcu_random_state *rrsp)
296{
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800297 if (--rrsp->rrs_count < 0) {
Peter Zijlstrac6763292010-05-25 10:48:51 +0200298 rrsp->rrs_state += (unsigned long)local_clock();
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800299 rrsp->rrs_count = RCU_RANDOM_REFRESH;
300 }
301 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
302 return swahw32(rrsp->rrs_state);
303}
304
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700305static void
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800306rcu_stutter_wait(char *title)
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700307{
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800308 while (stutter_pause_test || !rcutorture_runnable) {
Paul E. McKenneye3d7be22008-06-22 13:06:38 -0700309 if (rcutorture_runnable)
310 schedule_timeout_interruptible(1);
311 else
Paul E. McKenney3ccf79f2008-06-22 14:02:55 -0700312 schedule_timeout_interruptible(round_jiffies_relative(HZ));
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800313 rcutorture_shutdown_absorb(title);
Paul E. McKenney343e9092008-12-15 16:13:07 -0800314 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -0700315}
316
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800317/*
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700318 * Operations vector for selecting different types of tests.
319 */
320
321struct rcu_torture_ops {
322 void (*init)(void);
323 void (*cleanup)(void);
324 int (*readlock)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700325 void (*read_delay)(struct rcu_random_state *rrsp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700326 void (*readunlock)(int idx);
327 int (*completed)(void);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700328 void (*deferred_free)(struct rcu_torture *p);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700329 void (*sync)(void);
Paul E. McKenney23269742008-05-12 21:21:05 +0200330 void (*cb_barrier)(void);
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800331 void (*fqs)(void);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700332 int (*stats)(char *page);
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700333 int irq_capable;
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700334 int can_boost;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700335 char *name;
336};
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700337
338static struct rcu_torture_ops *cur_ops;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700339
340/*
341 * Definitions for rcu torture testing.
342 */
343
Josh Tripletta49a4af2006-09-29 01:59:30 -0700344static int rcu_torture_read_lock(void) __acquires(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700345{
346 rcu_read_lock();
347 return 0;
348}
349
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700350static void rcu_read_delay(struct rcu_random_state *rrsp)
351{
Josh Triplettb8d57a72009-09-08 15:54:35 -0700352 const unsigned long shortdelay_us = 200;
353 const unsigned long longdelay_ms = 50;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700354
Josh Triplettb8d57a72009-09-08 15:54:35 -0700355 /* We want a short delay sometimes to make a reader delay the grace
356 * period, and we want a long delay occasionally to trigger
357 * force_quiescent_state. */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700358
Josh Triplettb8d57a72009-09-08 15:54:35 -0700359 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
360 mdelay(longdelay_ms);
361 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
362 udelay(shortdelay_us);
Lai Jiangshane546f482010-06-21 16:57:42 +0800363#ifdef CONFIG_PREEMPT
364 if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000)))
365 preempt_schedule(); /* No QS if preempt_disable() in effect */
366#endif
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700367}
368
Josh Tripletta49a4af2006-09-29 01:59:30 -0700369static void rcu_torture_read_unlock(int idx) __releases(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700370{
371 rcu_read_unlock();
372}
373
374static int rcu_torture_completed(void)
375{
376 return rcu_batches_completed();
377}
378
379static void
380rcu_torture_cb(struct rcu_head *p)
381{
382 int i;
383 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
384
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800385 if (fullstop != FULLSTOP_DONTSTOP) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700386 /* Test is ending, just drop callbacks on the floor. */
387 /* The next initialization will pick up the pieces. */
388 return;
389 }
390 i = rp->rtort_pipe_count;
391 if (i > RCU_TORTURE_PIPE_LEN)
392 i = RCU_TORTURE_PIPE_LEN;
393 atomic_inc(&rcu_torture_wcount[i]);
394 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
395 rp->rtort_mbtest = 0;
396 rcu_torture_free(rp);
397 } else
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700398 cur_ops->deferred_free(rp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700399}
400
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800401static int rcu_no_completed(void)
402{
403 return 0;
404}
405
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700406static void rcu_torture_deferred_free(struct rcu_torture *p)
407{
408 call_rcu(&p->rtort_rcu, rcu_torture_cb);
409}
410
411static struct rcu_torture_ops rcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700412 .init = NULL,
413 .cleanup = NULL,
414 .readlock = rcu_torture_read_lock,
415 .read_delay = rcu_read_delay,
416 .readunlock = rcu_torture_read_unlock,
417 .completed = rcu_torture_completed,
418 .deferred_free = rcu_torture_deferred_free,
419 .sync = synchronize_rcu,
420 .cb_barrier = rcu_barrier,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800421 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700422 .stats = NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700423 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700424 .can_boost = rcu_can_boost(),
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700425 .name = "rcu"
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700426};
427
Josh Triplette3033732006-10-04 02:17:14 -0700428static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
429{
430 int i;
431 struct rcu_torture *rp;
432 struct rcu_torture *rp1;
433
434 cur_ops->sync();
435 list_add(&p->rtort_free, &rcu_torture_removed);
436 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
437 i = rp->rtort_pipe_count;
438 if (i > RCU_TORTURE_PIPE_LEN)
439 i = RCU_TORTURE_PIPE_LEN;
440 atomic_inc(&rcu_torture_wcount[i]);
441 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
442 rp->rtort_mbtest = 0;
443 list_del(&rp->rtort_free);
444 rcu_torture_free(rp);
445 }
446 }
447}
448
449static void rcu_sync_torture_init(void)
450{
451 INIT_LIST_HEAD(&rcu_torture_removed);
452}
453
Josh Triplett20d2e422006-10-04 02:17:15 -0700454static struct rcu_torture_ops rcu_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700455 .init = rcu_sync_torture_init,
456 .cleanup = NULL,
457 .readlock = rcu_torture_read_lock,
458 .read_delay = rcu_read_delay,
459 .readunlock = rcu_torture_read_unlock,
460 .completed = rcu_torture_completed,
461 .deferred_free = rcu_sync_torture_deferred_free,
462 .sync = synchronize_rcu,
463 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800464 .fqs = rcu_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700465 .stats = NULL,
466 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700467 .can_boost = rcu_can_boost(),
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700468 .name = "rcu_sync"
Josh Triplett20d2e422006-10-04 02:17:15 -0700469};
470
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800471static struct rcu_torture_ops rcu_expedited_ops = {
472 .init = rcu_sync_torture_init,
473 .cleanup = NULL,
474 .readlock = rcu_torture_read_lock,
475 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
476 .readunlock = rcu_torture_read_unlock,
477 .completed = rcu_no_completed,
478 .deferred_free = rcu_sync_torture_deferred_free,
479 .sync = synchronize_rcu_expedited,
480 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800481 .fqs = rcu_force_quiescent_state,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800482 .stats = NULL,
483 .irq_capable = 1,
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700484 .can_boost = rcu_can_boost(),
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800485 .name = "rcu_expedited"
486};
487
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700488/*
489 * Definitions for rcu_bh torture testing.
490 */
491
Josh Tripletta49a4af2006-09-29 01:59:30 -0700492static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700493{
494 rcu_read_lock_bh();
495 return 0;
496}
497
Josh Tripletta49a4af2006-09-29 01:59:30 -0700498static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700499{
500 rcu_read_unlock_bh();
501}
502
503static int rcu_bh_torture_completed(void)
504{
505 return rcu_batches_completed_bh();
506}
507
508static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
509{
510 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
511}
512
513static struct rcu_torture_ops rcu_bh_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700514 .init = NULL,
515 .cleanup = NULL,
516 .readlock = rcu_bh_torture_read_lock,
517 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
518 .readunlock = rcu_bh_torture_read_unlock,
519 .completed = rcu_bh_torture_completed,
520 .deferred_free = rcu_bh_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700521 .sync = synchronize_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700522 .cb_barrier = rcu_barrier_bh,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800523 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700524 .stats = NULL,
525 .irq_capable = 1,
526 .name = "rcu_bh"
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700527};
528
Josh Triplett11a14702006-10-04 02:17:16 -0700529static struct rcu_torture_ops rcu_bh_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700530 .init = rcu_sync_torture_init,
531 .cleanup = NULL,
532 .readlock = rcu_bh_torture_read_lock,
533 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
534 .readunlock = rcu_bh_torture_read_unlock,
535 .completed = rcu_bh_torture_completed,
536 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700537 .sync = synchronize_rcu_bh,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700538 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800539 .fqs = rcu_bh_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700540 .stats = NULL,
541 .irq_capable = 1,
542 .name = "rcu_bh_sync"
Josh Triplett11a14702006-10-04 02:17:16 -0700543};
544
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700545static struct rcu_torture_ops rcu_bh_expedited_ops = {
546 .init = rcu_sync_torture_init,
547 .cleanup = NULL,
548 .readlock = rcu_bh_torture_read_lock,
549 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
550 .readunlock = rcu_bh_torture_read_unlock,
551 .completed = rcu_bh_torture_completed,
552 .deferred_free = rcu_sync_torture_deferred_free,
553 .sync = synchronize_rcu_bh_expedited,
554 .cb_barrier = NULL,
555 .fqs = rcu_bh_force_quiescent_state,
556 .stats = NULL,
557 .irq_capable = 1,
558 .name = "rcu_bh_expedited"
559};
560
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700561/*
562 * Definitions for srcu torture testing.
563 */
564
565static struct srcu_struct srcu_ctl;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700566
567static void srcu_torture_init(void)
568{
569 init_srcu_struct(&srcu_ctl);
Josh Triplette3033732006-10-04 02:17:14 -0700570 rcu_sync_torture_init();
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700571}
572
573static void srcu_torture_cleanup(void)
574{
575 synchronize_srcu(&srcu_ctl);
576 cleanup_srcu_struct(&srcu_ctl);
577}
578
Josh Triplett012d3ca2006-12-06 20:40:19 -0800579static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700580{
581 return srcu_read_lock(&srcu_ctl);
582}
583
584static void srcu_read_delay(struct rcu_random_state *rrsp)
585{
586 long delay;
587 const long uspertick = 1000000 / HZ;
588 const long longdelay = 10;
589
590 /* We want there to be long-running readers, but not all the time. */
591
592 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
593 if (!delay)
594 schedule_timeout_interruptible(longdelay);
Lai Jiangshane546f482010-06-21 16:57:42 +0800595 else
596 rcu_read_delay(rrsp);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700597}
598
Josh Triplett012d3ca2006-12-06 20:40:19 -0800599static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700600{
601 srcu_read_unlock(&srcu_ctl, idx);
602}
603
604static int srcu_torture_completed(void)
605{
606 return srcu_batches_completed(&srcu_ctl);
607}
608
Josh Triplettb772e1d2006-10-04 02:17:13 -0700609static void srcu_torture_synchronize(void)
610{
611 synchronize_srcu(&srcu_ctl);
612}
613
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700614static int srcu_torture_stats(char *page)
615{
616 int cnt = 0;
617 int cpu;
618 int idx = srcu_ctl.completed & 0x1;
619
620 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
621 torture_type, TORTURE_FLAG, idx);
622 for_each_possible_cpu(cpu) {
623 cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu,
624 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
625 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
626 }
627 cnt += sprintf(&page[cnt], "\n");
628 return cnt;
629}
630
631static struct rcu_torture_ops srcu_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700632 .init = srcu_torture_init,
633 .cleanup = srcu_torture_cleanup,
634 .readlock = srcu_torture_read_lock,
635 .read_delay = srcu_read_delay,
636 .readunlock = srcu_torture_read_unlock,
637 .completed = srcu_torture_completed,
638 .deferred_free = rcu_sync_torture_deferred_free,
639 .sync = srcu_torture_synchronize,
640 .cb_barrier = NULL,
641 .stats = srcu_torture_stats,
642 .name = "srcu"
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700643};
644
Paul E. McKenney101db7b2011-12-05 15:36:31 -0800645static int srcu_torture_read_lock_raw(void) __acquires(&srcu_ctl)
646{
647 return srcu_read_lock_raw(&srcu_ctl);
648}
649
650static void srcu_torture_read_unlock_raw(int idx) __releases(&srcu_ctl)
651{
652 srcu_read_unlock_raw(&srcu_ctl, idx);
653}
654
655static struct rcu_torture_ops srcu_raw_ops = {
656 .init = srcu_torture_init,
657 .cleanup = srcu_torture_cleanup,
658 .readlock = srcu_torture_read_lock_raw,
659 .read_delay = srcu_read_delay,
660 .readunlock = srcu_torture_read_unlock_raw,
661 .completed = srcu_torture_completed,
662 .deferred_free = rcu_sync_torture_deferred_free,
663 .sync = srcu_torture_synchronize,
664 .cb_barrier = NULL,
665 .stats = srcu_torture_stats,
666 .name = "srcu_raw"
667};
668
Paul E. McKenney804bb832009-10-25 19:03:52 -0700669static void srcu_torture_synchronize_expedited(void)
670{
671 synchronize_srcu_expedited(&srcu_ctl);
672}
673
674static struct rcu_torture_ops srcu_expedited_ops = {
675 .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,
681 .deferred_free = rcu_sync_torture_deferred_free,
682 .sync = srcu_torture_synchronize_expedited,
683 .cb_barrier = NULL,
684 .stats = srcu_torture_stats,
685 .name = "srcu_expedited"
686};
687
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700688/*
689 * Definitions for sched torture testing.
690 */
691
692static int sched_torture_read_lock(void)
693{
694 preempt_disable();
695 return 0;
696}
697
698static void sched_torture_read_unlock(int idx)
699{
700 preempt_enable();
701}
702
Paul E. McKenney23269742008-05-12 21:21:05 +0200703static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
704{
705 call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
706}
707
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700708static struct rcu_torture_ops sched_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700709 .init = rcu_sync_torture_init,
710 .cleanup = NULL,
711 .readlock = sched_torture_read_lock,
712 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
713 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800714 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700715 .deferred_free = rcu_sched_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700716 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700717 .cb_barrier = rcu_barrier_sched,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800718 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700719 .stats = NULL,
720 .irq_capable = 1,
721 .name = "sched"
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700722};
723
Paul E. McKenney804bb832009-10-25 19:03:52 -0700724static struct rcu_torture_ops sched_sync_ops = {
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700725 .init = rcu_sync_torture_init,
726 .cleanup = NULL,
727 .readlock = sched_torture_read_lock,
728 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
729 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800730 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700731 .deferred_free = rcu_sync_torture_deferred_free,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -0700732 .sync = synchronize_sched,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700733 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800734 .fqs = rcu_sched_force_quiescent_state,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700735 .stats = NULL,
736 .name = "sched_sync"
737};
738
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700739static struct rcu_torture_ops sched_expedited_ops = {
740 .init = rcu_sync_torture_init,
741 .cleanup = NULL,
742 .readlock = sched_torture_read_lock,
743 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
744 .readunlock = sched_torture_read_unlock,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800745 .completed = rcu_no_completed,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700746 .deferred_free = rcu_sync_torture_deferred_free,
747 .sync = synchronize_sched_expedited,
748 .cb_barrier = NULL,
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800749 .fqs = rcu_sched_force_quiescent_state,
Tejun Heo969c7922010-05-06 18:49:21 +0200750 .stats = NULL,
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700751 .irq_capable = 1,
752 .name = "sched_expedited"
Paul E. McKenney23269742008-05-12 21:21:05 +0200753};
754
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700755/*
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700756 * RCU torture priority-boost testing. Runs one real-time thread per
757 * CPU for moderate bursts, repeatedly registering RCU callbacks and
758 * spinning waiting for them to be invoked. If a given callback takes
759 * too long to be invoked, we assume that priority inversion has occurred.
760 */
761
762struct rcu_boost_inflight {
763 struct rcu_head rcu;
764 int inflight;
765};
766
767static void rcu_torture_boost_cb(struct rcu_head *head)
768{
769 struct rcu_boost_inflight *rbip =
770 container_of(head, struct rcu_boost_inflight, rcu);
771
772 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
773 rbip->inflight = 0;
774}
775
776static int rcu_torture_boost(void *arg)
777{
778 unsigned long call_rcu_time;
779 unsigned long endtime;
780 unsigned long oldstarttime;
781 struct rcu_boost_inflight rbi = { .inflight = 0 };
782 struct sched_param sp;
783
784 VERBOSE_PRINTK_STRING("rcu_torture_boost started");
785
786 /* Set real-time priority. */
787 sp.sched_priority = 1;
788 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
789 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
790 n_rcu_torture_boost_rterror++;
791 }
792
Paul E. McKenney561190e2011-03-30 09:10:44 -0700793 init_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700794 /* Each pass through the following loop does one boost-test cycle. */
795 do {
796 /* Wait for the next test interval. */
797 oldstarttime = boost_starttime;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700798 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700799 schedule_timeout_uninterruptible(1);
800 rcu_stutter_wait("rcu_torture_boost");
801 if (kthread_should_stop() ||
802 fullstop != FULLSTOP_DONTSTOP)
803 goto checkwait;
804 }
805
806 /* Do one boost-test interval. */
807 endtime = oldstarttime + test_boost_duration * HZ;
808 call_rcu_time = jiffies;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700809 while (ULONG_CMP_LT(jiffies, endtime)) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700810 /* If we don't have a callback in flight, post one. */
811 if (!rbi.inflight) {
812 smp_mb(); /* RCU core before ->inflight = 1. */
813 rbi.inflight = 1;
814 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
815 if (jiffies - call_rcu_time >
816 test_boost_duration * HZ - HZ / 2) {
817 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
818 n_rcu_torture_boost_failure++;
819 }
820 call_rcu_time = jiffies;
821 }
822 cond_resched();
823 rcu_stutter_wait("rcu_torture_boost");
824 if (kthread_should_stop() ||
825 fullstop != FULLSTOP_DONTSTOP)
826 goto checkwait;
827 }
828
829 /*
830 * Set the start time of the next test interval.
831 * Yes, this is vulnerable to long delays, but such
832 * delays simply cause a false negative for the next
833 * interval. Besides, we are running at RT priority,
834 * so delays should be relatively rare.
835 */
Paul E. McKenneyab8f11e2011-08-18 09:30:32 -0700836 while (oldstarttime == boost_starttime &&
837 !kthread_should_stop()) {
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700838 if (mutex_trylock(&boost_mutex)) {
839 boost_starttime = jiffies +
840 test_boost_interval * HZ;
841 n_rcu_torture_boosts++;
842 mutex_unlock(&boost_mutex);
843 break;
844 }
845 schedule_timeout_uninterruptible(1);
846 }
847
848 /* Go do the stutter. */
849checkwait: rcu_stutter_wait("rcu_torture_boost");
850 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
851
852 /* Clean up and exit. */
853 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
854 rcutorture_shutdown_absorb("rcu_torture_boost");
855 while (!kthread_should_stop() || rbi.inflight)
856 schedule_timeout_uninterruptible(1);
857 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
Paul E. McKenney9d681972011-06-21 01:48:03 -0700858 destroy_rcu_head_on_stack(&rbi.rcu);
Paul E. McKenney8e8be452010-09-02 16:16:14 -0700859 return 0;
860}
861
862/*
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800863 * RCU torture force-quiescent-state kthread. Repeatedly induces
864 * bursts of calls to force_quiescent_state(), increasing the probability
865 * of occurrence of some important types of race conditions.
866 */
867static int
868rcu_torture_fqs(void *arg)
869{
870 unsigned long fqs_resume_time;
871 int fqs_burst_remaining;
872
873 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
874 do {
875 fqs_resume_time = jiffies + fqs_stutter * HZ;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700876 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
877 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800878 schedule_timeout_interruptible(1);
879 }
880 fqs_burst_remaining = fqs_duration;
Paul E. McKenney93898fb2011-08-17 12:39:34 -0700881 while (fqs_burst_remaining > 0 &&
882 !kthread_should_stop()) {
Paul E. McKenneybf66f182010-01-04 15:09:10 -0800883 cur_ops->fqs();
884 udelay(fqs_holdoff);
885 fqs_burst_remaining -= fqs_holdoff;
886 }
887 rcu_stutter_wait("rcu_torture_fqs");
888 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
889 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
890 rcutorture_shutdown_absorb("rcu_torture_fqs");
891 while (!kthread_should_stop())
892 schedule_timeout_uninterruptible(1);
893 return 0;
894}
895
896/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800897 * RCU torture writer kthread. Repeatedly substitutes a new structure
898 * for that pointed to by rcu_torture_current, freeing the old structure
899 * after a series of grace periods (the "pipeline").
900 */
901static int
902rcu_torture_writer(void *arg)
903{
904 int i;
905 long oldbatch = rcu_batches_completed();
906 struct rcu_torture *rp;
907 struct rcu_torture *old_rp;
908 static DEFINE_RCU_RANDOM(rand);
909
910 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800911 set_user_nice(current, 19);
912
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800913 do {
914 schedule_timeout_uninterruptible(1);
Paul E. McKenneya71fca52009-09-18 10:28:19 -0700915 rp = rcu_torture_alloc();
916 if (rp == NULL)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800917 continue;
918 rp->rtort_pipe_count = 0;
919 udelay(rcu_random(&rand) & 0x3ff);
Paul E. McKenney0ddea0e2010-09-19 21:06:14 -0700920 old_rp = rcu_dereference_check(rcu_torture_current,
921 current == writer_task);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800922 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800923 rcu_assign_pointer(rcu_torture_current, rp);
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700924 smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
Josh Triplettc8e5b162007-05-08 00:33:20 -0700925 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800926 i = old_rp->rtort_pipe_count;
927 if (i > RCU_TORTURE_PIPE_LEN)
928 i = RCU_TORTURE_PIPE_LEN;
929 atomic_inc(&rcu_torture_wcount[i]);
930 old_rp->rtort_pipe_count++;
Paul E. McKenney0acc5122009-06-25 09:08:17 -0700931 cur_ops->deferred_free(old_rp);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800932 }
Paul E. McKenney4a298652011-04-03 21:33:51 -0700933 rcutorture_record_progress(++rcu_torture_current_version);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700934 oldbatch = cur_ops->completed();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800935 rcu_stutter_wait("rcu_torture_writer");
936 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800937 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800938 rcutorture_shutdown_absorb("rcu_torture_writer");
939 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800940 schedule_timeout_uninterruptible(1);
941 return 0;
942}
943
944/*
Josh Triplettb772e1d2006-10-04 02:17:13 -0700945 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
946 * delay between calls.
947 */
948static int
949rcu_torture_fakewriter(void *arg)
950{
951 DEFINE_RCU_RANDOM(rand);
952
953 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
954 set_user_nice(current, 19);
955
956 do {
957 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
958 udelay(rcu_random(&rand) & 0x3ff);
959 cur_ops->sync();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800960 rcu_stutter_wait("rcu_torture_fakewriter");
961 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700962
963 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -0800964 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
965 while (!kthread_should_stop())
Josh Triplettb772e1d2006-10-04 02:17:13 -0700966 schedule_timeout_uninterruptible(1);
967 return 0;
968}
969
Paul E. McKenney91afaf32011-10-02 07:44:32 -0700970void rcutorture_trace_dump(void)
971{
972 static atomic_t beenhere = ATOMIC_INIT(0);
973
974 if (atomic_read(&beenhere))
975 return;
976 if (atomic_xchg(&beenhere, 1) != 0)
977 return;
978 do_trace_rcu_torture_read(cur_ops->name, (struct rcu_head *)~0UL);
979 ftrace_dump(DUMP_ALL);
980}
981
Josh Triplettb772e1d2006-10-04 02:17:13 -0700982/*
Paul E. McKenney0729fbf2008-06-25 12:24:52 -0700983 * RCU torture reader from timer handler. Dereferences rcu_torture_current,
984 * incrementing the corresponding element of the pipeline array. The
985 * counter in the element should never be greater than 1, otherwise, the
986 * RCU implementation is broken.
987 */
988static void rcu_torture_timer(unsigned long unused)
989{
990 int idx;
991 int completed;
992 static DEFINE_RCU_RANDOM(rand);
993 static DEFINE_SPINLOCK(rand_lock);
994 struct rcu_torture *p;
995 int pipe_count;
996
997 idx = cur_ops->readlock();
998 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -0800999 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001000 rcu_read_lock_bh_held() ||
1001 rcu_read_lock_sched_held() ||
1002 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001003 if (p == NULL) {
1004 /* Leave because rcu_torture_writer is not yet underway */
1005 cur_ops->readunlock(idx);
1006 return;
1007 }
Paul E. McKenney7129d382012-01-31 16:46:34 -08001008 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001009 if (p->rtort_mbtest == 0)
1010 atomic_inc(&n_rcu_torture_mberror);
1011 spin_lock(&rand_lock);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001012 cur_ops->read_delay(&rand);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001013 n_rcu_torture_timers++;
1014 spin_unlock(&rand_lock);
1015 preempt_disable();
1016 pipe_count = p->rtort_pipe_count;
1017 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1018 /* Should not happen, but... */
1019 pipe_count = RCU_TORTURE_PIPE_LEN;
1020 }
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001021 if (pipe_count > 1)
1022 rcutorture_trace_dump();
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001023 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001024 completed = cur_ops->completed() - completed;
1025 if (completed > RCU_TORTURE_PIPE_LEN) {
1026 /* Should not happen, but... */
1027 completed = RCU_TORTURE_PIPE_LEN;
1028 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001029 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001030 preempt_enable();
1031 cur_ops->readunlock(idx);
1032}
1033
1034/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001035 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
1036 * incrementing the corresponding element of the pipeline array. The
1037 * counter in the element should never be greater than 1, otherwise, the
1038 * RCU implementation is broken.
1039 */
1040static int
1041rcu_torture_reader(void *arg)
1042{
1043 int completed;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001044 int idx;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001045 DEFINE_RCU_RANDOM(rand);
1046 struct rcu_torture *p;
1047 int pipe_count;
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001048 struct timer_list t;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001049
1050 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001051 set_user_nice(current, 19);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001052 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001053 setup_timer_on_stack(&t, rcu_torture_timer, 0);
Ingo Molnardbdf65b2005-11-13 16:07:22 -08001054
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001055 do {
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001056 if (irqreader && cur_ops->irq_capable) {
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001057 if (!timer_pending(&t))
Paul E. McKenney6155fec2010-02-22 17:05:04 -08001058 mod_timer(&t, jiffies + 1);
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001059 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001060 idx = cur_ops->readlock();
1061 completed = cur_ops->completed();
Paul E. McKenney632ee202010-02-22 17:04:45 -08001062 p = rcu_dereference_check(rcu_torture_current,
Paul E. McKenney632ee202010-02-22 17:04:45 -08001063 rcu_read_lock_bh_held() ||
1064 rcu_read_lock_sched_held() ||
1065 srcu_read_lock_held(&srcu_ctl));
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001066 if (p == NULL) {
1067 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001068 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001069 schedule_timeout_interruptible(HZ);
1070 continue;
1071 }
Paul E. McKenney7129d382012-01-31 16:46:34 -08001072 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001073 if (p->rtort_mbtest == 0)
1074 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001075 cur_ops->read_delay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001076 preempt_disable();
1077 pipe_count = p->rtort_pipe_count;
1078 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
1079 /* Should not happen, but... */
1080 pipe_count = RCU_TORTURE_PIPE_LEN;
1081 }
Paul E. McKenney91afaf32011-10-02 07:44:32 -07001082 if (pipe_count > 1)
1083 rcutorture_trace_dump();
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001084 __this_cpu_inc(rcu_torture_count[pipe_count]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001085 completed = cur_ops->completed() - completed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001086 if (completed > RCU_TORTURE_PIPE_LEN) {
1087 /* Should not happen, but... */
1088 completed = RCU_TORTURE_PIPE_LEN;
1089 }
Rusty Russelldd17c8f2009-10-29 22:34:15 +09001090 __this_cpu_inc(rcu_torture_batch[completed]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001091 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001092 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001093 schedule();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001094 rcu_stutter_wait("rcu_torture_reader");
1095 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001096 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001097 rcutorture_shutdown_absorb("rcu_torture_reader");
Paul E. McKenney0acc5122009-06-25 09:08:17 -07001098 if (irqreader && cur_ops->irq_capable)
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001099 del_timer_sync(&t);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001100 while (!kthread_should_stop())
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001101 schedule_timeout_uninterruptible(1);
1102 return 0;
1103}
1104
1105/*
1106 * Create an RCU-torture statistics message in the specified buffer.
1107 */
1108static int
1109rcu_torture_printk(char *page)
1110{
1111 int cnt = 0;
1112 int cpu;
1113 int i;
1114 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1115 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1116
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001117 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001118 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1119 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1120 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1121 }
1122 }
1123 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
1124 if (pipesummary[i] != 0)
1125 break;
1126 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001127 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001128 cnt += sprintf(&page[cnt],
Paul E. McKenney4a298652011-04-03 21:33:51 -07001129 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d "
Paul E. McKenney67b98db2011-02-21 13:31:55 -08001130 "rtmbe: %d rtbke: %ld rtbre: %ld "
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001131 "rtbf: %ld rtb: %ld nt: %ld "
1132 "onoff: %ld/%ld:%ld/%ld",
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001133 rcu_torture_current,
1134 rcu_torture_current_version,
1135 list_empty(&rcu_torture_freelist),
1136 atomic_read(&n_rcu_torture_alloc),
1137 atomic_read(&n_rcu_torture_alloc_fail),
Paul E. McKenney996417d2005-11-18 01:10:50 -08001138 atomic_read(&n_rcu_torture_free),
Paul E. McKenney0729fbf2008-06-25 12:24:52 -07001139 atomic_read(&n_rcu_torture_mberror),
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001140 n_rcu_torture_boost_ktrerror,
1141 n_rcu_torture_boost_rterror,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001142 n_rcu_torture_boost_failure,
1143 n_rcu_torture_boosts,
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001144 n_rcu_torture_timers,
1145 n_online_successes,
1146 n_online_attempts,
1147 n_offline_successes,
1148 n_offline_attempts);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001149 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
1150 n_rcu_torture_boost_ktrerror != 0 ||
1151 n_rcu_torture_boost_rterror != 0 ||
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001152 n_rcu_torture_boost_failure != 0)
Paul E. McKenney996417d2005-11-18 01:10:50 -08001153 cnt += sprintf(&page[cnt], " !!!");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001154 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001155 if (i > 1) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001156 cnt += sprintf(&page[cnt], "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -08001157 atomic_inc(&n_rcu_torture_error);
Ingo Molnar5af970a2008-06-18 10:09:48 +02001158 WARN_ON_ONCE(1);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001159 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001160 cnt += sprintf(&page[cnt], "Reader Pipe: ");
1161 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1162 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001163 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001164 cnt += sprintf(&page[cnt], "Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001165 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001166 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001167 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001168 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
1169 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1170 cnt += sprintf(&page[cnt], " %d",
1171 atomic_read(&rcu_torture_wcount[i]));
1172 }
1173 cnt += sprintf(&page[cnt], "\n");
Josh Triplettc8e5b162007-05-08 00:33:20 -07001174 if (cur_ops->stats)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001175 cnt += cur_ops->stats(&page[cnt]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001176 return cnt;
1177}
1178
1179/*
1180 * Print torture statistics. Caller must ensure that there is only
1181 * one call to this function at a given time!!! This is normally
1182 * accomplished by relying on the module system to only have one copy
1183 * of the module loaded, and then by giving the rcu_torture_stats
1184 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1185 * thread is not running).
1186 */
1187static void
1188rcu_torture_stats_print(void)
1189{
1190 int cnt;
1191
1192 cnt = rcu_torture_printk(printk_buf);
1193 printk(KERN_ALERT "%s", printk_buf);
1194}
1195
1196/*
1197 * Periodically prints torture statistics, if periodic statistics printing
1198 * was specified via the stat_interval module parameter.
1199 *
1200 * No need to worry about fullstop here, since this one doesn't reference
1201 * volatile state or register callbacks.
1202 */
1203static int
1204rcu_torture_stats(void *arg)
1205{
1206 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
1207 do {
1208 schedule_timeout_interruptible(stat_interval * HZ);
1209 rcu_torture_stats_print();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001210 rcutorture_shutdown_absorb("rcu_torture_stats");
1211 } while (!kthread_should_stop());
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001212 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
1213 return 0;
1214}
1215
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001216static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
1217
1218/* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1219 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1220 */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -07001221static void rcu_torture_shuffle_tasks(void)
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001222{
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001223 int i;
1224
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001225 cpumask_setall(shuffle_tmp_mask);
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001226 get_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001227
1228 /* No point in shuffling if there is only one online CPU (ex: UP) */
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001229 if (num_online_cpus() == 1) {
1230 put_online_cpus();
1231 return;
1232 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001233
1234 if (rcu_idle_cpu != -1)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001235 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001236
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001237 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001238
Josh Triplettc8e5b162007-05-08 00:33:20 -07001239 if (reader_tasks) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001240 for (i = 0; i < nrealreaders; i++)
1241 if (reader_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001242 set_cpus_allowed_ptr(reader_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001243 shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001244 }
1245
Josh Triplettc8e5b162007-05-08 00:33:20 -07001246 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001247 for (i = 0; i < nfakewriters; i++)
1248 if (fakewriter_tasks[i])
Mike Travisf70316d2008-04-04 18:11:06 -07001249 set_cpus_allowed_ptr(fakewriter_tasks[i],
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001250 shuffle_tmp_mask);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001251 }
1252
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001253 if (writer_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001254 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001255
1256 if (stats_task)
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001257 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001258
1259 if (rcu_idle_cpu == -1)
1260 rcu_idle_cpu = num_online_cpus() - 1;
1261 else
1262 rcu_idle_cpu--;
1263
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +01001264 put_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001265}
1266
1267/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1268 * system to become idle at a time and cut off its timer ticks. This is meant
1269 * to test the support for such tickless idle CPU in RCU.
1270 */
1271static int
1272rcu_torture_shuffle(void *arg)
1273{
1274 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1275 do {
1276 schedule_timeout_interruptible(shuffle_interval * HZ);
1277 rcu_torture_shuffle_tasks();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001278 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1279 } while (!kthread_should_stop());
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001280 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1281 return 0;
1282}
1283
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001284/* Cause the rcutorture test to "stutter", starting and stopping all
1285 * threads periodically.
1286 */
1287static int
1288rcu_torture_stutter(void *arg)
1289{
1290 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1291 do {
1292 schedule_timeout_interruptible(stutter * HZ);
1293 stutter_pause_test = 1;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001294 if (!kthread_should_stop())
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001295 schedule_timeout_interruptible(stutter * HZ);
1296 stutter_pause_test = 0;
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001297 rcutorture_shutdown_absorb("rcu_torture_stutter");
1298 } while (!kthread_should_stop());
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001299 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1300 return 0;
1301}
1302
Paul E. McKenney95c38322006-03-24 03:15:58 -08001303static inline void
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001304rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
Paul E. McKenney95c38322006-03-24 03:15:58 -08001305{
Josh Triplettb772e1d2006-10-04 02:17:13 -07001306 printk(KERN_ALERT "%s" TORTURE_FLAG
1307 "--- %s: nreaders=%d nfakewriters=%d "
Paul E. McKenney95c38322006-03-24 03:15:58 -08001308 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001309 "shuffle_interval=%d stutter=%d irqreader=%d "
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001310 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1311 "test_boost=%d/%d test_boost_interval=%d "
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001312 "test_boost_duration=%d shutdown_secs=%d "
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -08001313 "onoff_interval=%d onoff_holdoff=%d\n",
Josh Triplettb772e1d2006-10-04 02:17:13 -07001314 torture_type, tag, nrealreaders, nfakewriters,
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001315 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001316 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1317 test_boost, cur_ops->can_boost,
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001318 test_boost_interval, test_boost_duration, shutdown_secs,
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -08001319 onoff_interval, onoff_holdoff);
Paul E. McKenney95c38322006-03-24 03:15:58 -08001320}
1321
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001322static struct notifier_block rcutorture_shutdown_nb = {
Paul E. McKenney343e9092008-12-15 16:13:07 -08001323 .notifier_call = rcutorture_shutdown_notify,
1324};
1325
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001326static void rcutorture_booster_cleanup(int cpu)
1327{
1328 struct task_struct *t;
1329
1330 if (boost_tasks[cpu] == NULL)
1331 return;
1332 mutex_lock(&boost_mutex);
1333 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1334 t = boost_tasks[cpu];
1335 boost_tasks[cpu] = NULL;
1336 mutex_unlock(&boost_mutex);
1337
1338 /* This must be outside of the mutex, otherwise deadlock! */
1339 kthread_stop(t);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001340 boost_tasks[cpu] = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001341}
1342
1343static int rcutorture_booster_init(int cpu)
1344{
1345 int retval;
1346
1347 if (boost_tasks[cpu] != NULL)
1348 return 0; /* Already created, nothing more to do. */
1349
1350 /* Don't allow time recalculation while creating a new task. */
1351 mutex_lock(&boost_mutex);
1352 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
Eric Dumazet1f288092011-06-16 15:53:18 -07001353 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1354 cpu_to_node(cpu),
1355 "rcu_torture_boost");
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001356 if (IS_ERR(boost_tasks[cpu])) {
1357 retval = PTR_ERR(boost_tasks[cpu]);
1358 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
1359 n_rcu_torture_boost_ktrerror++;
1360 boost_tasks[cpu] = NULL;
1361 mutex_unlock(&boost_mutex);
1362 return retval;
1363 }
1364 kthread_bind(boost_tasks[cpu], cpu);
1365 wake_up_process(boost_tasks[cpu]);
1366 mutex_unlock(&boost_mutex);
1367 return 0;
1368}
1369
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001370/*
1371 * Cause the rcutorture test to shutdown the system after the test has
1372 * run for the time specified by the shutdown_secs module parameter.
1373 */
1374static int
1375rcu_torture_shutdown(void *arg)
1376{
1377 long delta;
1378 unsigned long jiffies_snap;
1379
1380 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1381 jiffies_snap = ACCESS_ONCE(jiffies);
1382 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
1383 !kthread_should_stop()) {
1384 delta = shutdown_time - jiffies_snap;
1385 if (verbose)
1386 printk(KERN_ALERT "%s" TORTURE_FLAG
1387 "rcu_torture_shutdown task: %lu "
1388 "jiffies remaining\n",
1389 torture_type, delta);
1390 schedule_timeout_interruptible(delta);
1391 jiffies_snap = ACCESS_ONCE(jiffies);
1392 }
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001393 if (kthread_should_stop()) {
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001394 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1395 return 0;
1396 }
1397
1398 /* OK, shut down the system. */
1399
1400 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1401 shutdown_task = NULL; /* Avoid self-kill deadlock. */
1402 rcu_torture_cleanup(); /* Get the success/failure message. */
1403 kernel_power_off(); /* Shut down the system. */
1404 return 0;
1405}
1406
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001407#ifdef CONFIG_HOTPLUG_CPU
1408
1409/*
1410 * Execute random CPU-hotplug operations at the interval specified
1411 * by the onoff_interval.
1412 */
Heiko Carstens44100302011-12-27 15:04:26 +01001413static int __cpuinit
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001414rcu_torture_onoff(void *arg)
1415{
1416 int cpu;
1417 int maxcpu = -1;
1418 DEFINE_RCU_RANDOM(rand);
1419
1420 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1421 for_each_online_cpu(cpu)
1422 maxcpu = cpu;
1423 WARN_ON(maxcpu < 0);
Paul E. McKenney9b9ec9b2012-01-17 14:36:51 -08001424 if (onoff_holdoff > 0) {
1425 VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff");
1426 schedule_timeout_interruptible(onoff_holdoff * HZ);
1427 VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff");
1428 }
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001429 while (!kthread_should_stop()) {
1430 cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
Paul E. McKenneyf2202422011-12-03 15:09:28 -08001431 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001432 if (verbose)
1433 printk(KERN_ALERT "%s" TORTURE_FLAG
1434 "rcu_torture_onoff task: offlining %d\n",
1435 torture_type, cpu);
1436 n_offline_attempts++;
1437 if (cpu_down(cpu) == 0) {
1438 if (verbose)
1439 printk(KERN_ALERT "%s" TORTURE_FLAG
1440 "rcu_torture_onoff task: "
1441 "offlined %d\n",
1442 torture_type, cpu);
1443 n_offline_successes++;
1444 }
Paul E. McKenneyf2202422011-12-03 15:09:28 -08001445 } else if (cpu_is_hotpluggable(cpu)) {
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001446 if (verbose)
1447 printk(KERN_ALERT "%s" TORTURE_FLAG
1448 "rcu_torture_onoff task: onlining %d\n",
1449 torture_type, cpu);
1450 n_online_attempts++;
1451 if (cpu_up(cpu) == 0) {
1452 if (verbose)
1453 printk(KERN_ALERT "%s" TORTURE_FLAG
1454 "rcu_torture_onoff task: "
1455 "onlined %d\n",
1456 torture_type, cpu);
1457 n_online_successes++;
1458 }
1459 }
1460 schedule_timeout_interruptible(onoff_interval * HZ);
1461 }
1462 VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1463 return 0;
1464}
1465
Heiko Carstens44100302011-12-27 15:04:26 +01001466static int __cpuinit
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001467rcu_torture_onoff_init(void)
1468{
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001469 int ret;
1470
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001471 if (onoff_interval <= 0)
1472 return 0;
1473 onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff");
1474 if (IS_ERR(onoff_task)) {
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001475 ret = PTR_ERR(onoff_task);
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001476 onoff_task = NULL;
Julia Lawall3c1b1ce2012-02-02 07:52:54 -08001477 return ret;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001478 }
1479 return 0;
1480}
1481
1482static void rcu_torture_onoff_cleanup(void)
1483{
1484 if (onoff_task == NULL)
1485 return;
1486 VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1487 kthread_stop(onoff_task);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001488 onoff_task = NULL;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001489}
1490
1491#else /* #ifdef CONFIG_HOTPLUG_CPU */
1492
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001493static int
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001494rcu_torture_onoff_init(void)
1495{
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001496 return 0;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001497}
1498
1499static void rcu_torture_onoff_cleanup(void)
1500{
1501}
1502
1503#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1504
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001505/*
1506 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1507 * induces a CPU stall for the time specified by stall_cpu.
1508 */
1509static int __cpuinit rcu_torture_stall(void *args)
1510{
1511 unsigned long stop_at;
1512
1513 VERBOSE_PRINTK_STRING("rcu_torture_stall task started");
1514 if (stall_cpu_holdoff > 0) {
1515 VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff");
1516 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
1517 VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff");
1518 }
1519 if (!kthread_should_stop()) {
1520 stop_at = get_seconds() + stall_cpu;
1521 /* RCU CPU stall is expected behavior in following code. */
1522 printk(KERN_ALERT "rcu_torture_stall start.\n");
1523 rcu_read_lock();
1524 preempt_disable();
1525 while (ULONG_CMP_LT(get_seconds(), stop_at))
1526 continue; /* Induce RCU CPU stall warning. */
1527 preempt_enable();
1528 rcu_read_unlock();
1529 printk(KERN_ALERT "rcu_torture_stall end.\n");
1530 }
1531 rcutorture_shutdown_absorb("rcu_torture_stall");
1532 while (!kthread_should_stop())
1533 schedule_timeout_interruptible(10 * HZ);
1534 return 0;
1535}
1536
1537/* Spawn CPU-stall kthread, if stall_cpu specified. */
1538static int __init rcu_torture_stall_init(void)
1539{
1540 int ret;
1541
1542 if (stall_cpu <= 0)
1543 return 0;
1544 stall_task = kthread_run(rcu_torture_stall, NULL, "rcu_torture_stall");
1545 if (IS_ERR(stall_task)) {
1546 ret = PTR_ERR(stall_task);
1547 stall_task = NULL;
1548 return ret;
1549 }
1550 return 0;
1551}
1552
1553/* Clean up after the CPU-stall kthread, if one was spawned. */
1554static void rcu_torture_stall_cleanup(void)
1555{
1556 if (stall_task == NULL)
1557 return;
1558 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task.");
1559 kthread_stop(stall_task);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001560 stall_task = NULL;
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001561}
1562
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001563static int rcutorture_cpu_notify(struct notifier_block *self,
1564 unsigned long action, void *hcpu)
1565{
1566 long cpu = (long)hcpu;
1567
1568 switch (action) {
1569 case CPU_ONLINE:
1570 case CPU_DOWN_FAILED:
1571 (void)rcutorture_booster_init(cpu);
1572 break;
1573 case CPU_DOWN_PREPARE:
1574 rcutorture_booster_cleanup(cpu);
1575 break;
1576 default:
1577 break;
1578 }
1579 return NOTIFY_OK;
1580}
1581
1582static struct notifier_block rcutorture_cpu_nb = {
1583 .notifier_call = rcutorture_cpu_notify,
1584};
1585
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001586static void
1587rcu_torture_cleanup(void)
1588{
1589 int i;
1590
Paul E. McKenney343e9092008-12-15 16:13:07 -08001591 mutex_lock(&fullstop_mutex);
Paul E. McKenney4a298652011-04-03 21:33:51 -07001592 rcutorture_record_test_transition();
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001593 if (fullstop == FULLSTOP_SHUTDOWN) {
1594 printk(KERN_WARNING /* but going down anyway, so... */
1595 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001596 mutex_unlock(&fullstop_mutex);
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001597 schedule_timeout_uninterruptible(10);
Paul E. McKenney343e9092008-12-15 16:13:07 -08001598 if (cur_ops->cb_barrier != NULL)
1599 cur_ops->cb_barrier();
1600 return;
1601 }
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001602 fullstop = FULLSTOP_RMMOD;
Paul E. McKenney343e9092008-12-15 16:13:07 -08001603 mutex_unlock(&fullstop_mutex);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001604 unregister_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenneyc13f3752012-01-20 15:36:33 -08001605 rcu_torture_stall_cleanup();
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001606 if (stutter_task) {
1607 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1608 kthread_stop(stutter_task);
1609 }
1610 stutter_task = NULL;
Josh Triplettc8e5b162007-05-08 00:33:20 -07001611 if (shuffler_task) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001612 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1613 kthread_stop(shuffler_task);
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001614 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001615 }
1616 shuffler_task = NULL;
1617
Josh Triplettc8e5b162007-05-08 00:33:20 -07001618 if (writer_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001619 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
1620 kthread_stop(writer_task);
1621 }
1622 writer_task = NULL;
1623
Josh Triplettc8e5b162007-05-08 00:33:20 -07001624 if (reader_tasks) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001625 for (i = 0; i < nrealreaders; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001626 if (reader_tasks[i]) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001627 VERBOSE_PRINTK_STRING(
1628 "Stopping rcu_torture_reader task");
1629 kthread_stop(reader_tasks[i]);
1630 }
1631 reader_tasks[i] = NULL;
1632 }
1633 kfree(reader_tasks);
1634 reader_tasks = NULL;
1635 }
1636 rcu_torture_current = NULL;
1637
Josh Triplettc8e5b162007-05-08 00:33:20 -07001638 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001639 for (i = 0; i < nfakewriters; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -07001640 if (fakewriter_tasks[i]) {
Josh Triplettb772e1d2006-10-04 02:17:13 -07001641 VERBOSE_PRINTK_STRING(
1642 "Stopping rcu_torture_fakewriter task");
1643 kthread_stop(fakewriter_tasks[i]);
1644 }
1645 fakewriter_tasks[i] = NULL;
1646 }
1647 kfree(fakewriter_tasks);
1648 fakewriter_tasks = NULL;
1649 }
1650
Josh Triplettc8e5b162007-05-08 00:33:20 -07001651 if (stats_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001652 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
1653 kthread_stop(stats_task);
1654 }
1655 stats_task = NULL;
1656
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001657 if (fqs_task) {
1658 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1659 kthread_stop(fqs_task);
1660 }
1661 fqs_task = NULL;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001662 if ((test_boost == 1 && cur_ops->can_boost) ||
1663 test_boost == 2) {
1664 unregister_cpu_notifier(&rcutorture_cpu_nb);
1665 for_each_possible_cpu(i)
1666 rcutorture_booster_cleanup(i);
1667 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001668 if (shutdown_task != NULL) {
1669 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1670 kthread_stop(shutdown_task);
1671 }
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001672 shutdown_task = NULL;
Paul E. McKenneyb58bdcc2011-11-16 17:48:21 -08001673 rcu_torture_onoff_cleanup();
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001674
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001675 /* Wait for all RCU callbacks to fire. */
Paul E. McKenney23269742008-05-12 21:21:05 +02001676
1677 if (cur_ops->cb_barrier != NULL)
1678 cur_ops->cb_barrier();
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001679
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001680 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001681
Josh Triplettc8e5b162007-05-08 00:33:20 -07001682 if (cur_ops->cleanup)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001683 cur_ops->cleanup();
Paul E. McKenney95c38322006-03-24 03:15:58 -08001684 if (atomic_read(&n_rcu_torture_error))
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001685 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
Paul E. McKenney091541b2012-01-10 12:51:14 -08001686 else if (n_online_successes != n_online_attempts ||
1687 n_offline_successes != n_offline_attempts)
1688 rcu_torture_print_module_parms(cur_ops,
1689 "End of test: RCU_HOTPLUG");
Paul E. McKenney95c38322006-03-24 03:15:58 -08001690 else
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001691 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001692}
1693
Josh Triplett6f8bc502007-05-08 00:25:24 -07001694static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001695rcu_torture_init(void)
1696{
1697 int i;
1698 int cpu;
1699 int firsterr = 0;
Josh Triplettade5fb82007-05-08 00:33:22 -07001700 static struct rcu_torture_ops *torture_ops[] =
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -08001701 { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
Paul E. McKenneybdf2a432011-06-07 16:59:35 -07001702 &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops,
Paul E. McKenney101db7b2011-12-05 15:36:31 -08001703 &srcu_ops, &srcu_raw_ops, &srcu_expedited_ops,
Paul E. McKenney804bb832009-10-25 19:03:52 -07001704 &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001705
Paul E. McKenney343e9092008-12-15 16:13:07 -08001706 mutex_lock(&fullstop_mutex);
1707
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001708 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -07001709 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001710 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -07001711 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001712 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001713 }
Josh Triplettade5fb82007-05-08 00:33:22 -07001714 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001715 printk(KERN_ALERT "rcu-torture: invalid torture type: \"%s\"\n",
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001716 torture_type);
Paul E. McKenneycf886c42009-10-25 19:03:54 -07001717 printk(KERN_ALERT "rcu-torture types:");
1718 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
1719 printk(KERN_ALERT " %s", torture_ops[i]->name);
1720 printk(KERN_ALERT "\n");
Paul E. McKenney343e9092008-12-15 16:13:07 -08001721 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001722 return -EINVAL;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001723 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001724 if (cur_ops->fqs == NULL && fqs_duration != 0) {
1725 printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero "
1726 "fqs_duration, fqs disabled.\n");
1727 fqs_duration = 0;
1728 }
Josh Triplettc8e5b162007-05-08 00:33:20 -07001729 if (cur_ops->init)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -07001730 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
1731
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001732 if (nreaders >= 0)
1733 nrealreaders = nreaders;
1734 else
1735 nrealreaders = 2 * num_online_cpus();
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001736 rcu_torture_print_module_parms(cur_ops, "Start of test");
Paul E. McKenneyc9d557c2009-01-07 14:33:30 -08001737 fullstop = FULLSTOP_DONTSTOP;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001738
1739 /* Set up the freelist. */
1740
1741 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -07001742 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -08001743 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001744 list_add_tail(&rcu_tortures[i].rtort_free,
1745 &rcu_torture_freelist);
1746 }
1747
1748 /* Initialize the statistics so that each run gets its own numbers. */
1749
1750 rcu_torture_current = NULL;
1751 rcu_torture_current_version = 0;
1752 atomic_set(&n_rcu_torture_alloc, 0);
1753 atomic_set(&n_rcu_torture_alloc_fail, 0);
1754 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -08001755 atomic_set(&n_rcu_torture_mberror, 0);
1756 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001757 n_rcu_torture_boost_ktrerror = 0;
1758 n_rcu_torture_boost_rterror = 0;
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001759 n_rcu_torture_boost_failure = 0;
1760 n_rcu_torture_boosts = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001761 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1762 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -08001763 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001764 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1765 per_cpu(rcu_torture_count, cpu)[i] = 0;
1766 per_cpu(rcu_torture_batch, cpu)[i] = 0;
1767 }
1768 }
1769
1770 /* Start up the kthreads. */
1771
1772 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1773 writer_task = kthread_run(rcu_torture_writer, NULL,
1774 "rcu_torture_writer");
1775 if (IS_ERR(writer_task)) {
1776 firsterr = PTR_ERR(writer_task);
1777 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1778 writer_task = NULL;
1779 goto unwind;
1780 }
Josh Triplettb772e1d2006-10-04 02:17:13 -07001781 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001782 GFP_KERNEL);
Josh Triplettb772e1d2006-10-04 02:17:13 -07001783 if (fakewriter_tasks == NULL) {
1784 VERBOSE_PRINTK_ERRSTRING("out of memory");
1785 firsterr = -ENOMEM;
1786 goto unwind;
1787 }
1788 for (i = 0; i < nfakewriters; i++) {
1789 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
1790 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
Paul E. McKenneya71fca52009-09-18 10:28:19 -07001791 "rcu_torture_fakewriter");
Josh Triplettb772e1d2006-10-04 02:17:13 -07001792 if (IS_ERR(fakewriter_tasks[i])) {
1793 firsterr = PTR_ERR(fakewriter_tasks[i]);
1794 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
1795 fakewriter_tasks[i] = NULL;
1796 goto unwind;
1797 }
1798 }
Josh Triplett2860aab2006-10-04 02:17:11 -07001799 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001800 GFP_KERNEL);
1801 if (reader_tasks == NULL) {
1802 VERBOSE_PRINTK_ERRSTRING("out of memory");
1803 firsterr = -ENOMEM;
1804 goto unwind;
1805 }
1806 for (i = 0; i < nrealreaders; i++) {
1807 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
1808 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
1809 "rcu_torture_reader");
1810 if (IS_ERR(reader_tasks[i])) {
1811 firsterr = PTR_ERR(reader_tasks[i]);
1812 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
1813 reader_tasks[i] = NULL;
1814 goto unwind;
1815 }
1816 }
1817 if (stat_interval > 0) {
1818 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
1819 stats_task = kthread_run(rcu_torture_stats, NULL,
1820 "rcu_torture_stats");
1821 if (IS_ERR(stats_task)) {
1822 firsterr = PTR_ERR(stats_task);
1823 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
1824 stats_task = NULL;
1825 goto unwind;
1826 }
1827 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001828 if (test_no_idle_hz) {
1829 rcu_idle_cpu = num_online_cpus() - 1;
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001830
1831 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
1832 firsterr = -ENOMEM;
1833 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
1834 goto unwind;
1835 }
1836
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001837 /* Create the shuffler thread */
1838 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
1839 "rcu_torture_shuffle");
1840 if (IS_ERR(shuffler_task)) {
Rusty Russell73d0a4b2009-03-30 22:05:16 -06001841 free_cpumask_var(shuffle_tmp_mask);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -08001842 firsterr = PTR_ERR(shuffler_task);
1843 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
1844 shuffler_task = NULL;
1845 goto unwind;
1846 }
1847 }
Paul E. McKenneyd120f652008-06-18 05:21:44 -07001848 if (stutter < 0)
1849 stutter = 0;
1850 if (stutter) {
1851 /* Create the stutter thread */
1852 stutter_task = kthread_run(rcu_torture_stutter, NULL,
1853 "rcu_torture_stutter");
1854 if (IS_ERR(stutter_task)) {
1855 firsterr = PTR_ERR(stutter_task);
1856 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
1857 stutter_task = NULL;
1858 goto unwind;
1859 }
1860 }
Paul E. McKenneybf66f182010-01-04 15:09:10 -08001861 if (fqs_duration < 0)
1862 fqs_duration = 0;
1863 if (fqs_duration) {
1864 /* Create the stutter thread */
1865 fqs_task = kthread_run(rcu_torture_fqs, NULL,
1866 "rcu_torture_fqs");
1867 if (IS_ERR(fqs_task)) {
1868 firsterr = PTR_ERR(fqs_task);
1869 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
1870 fqs_task = NULL;
1871 goto unwind;
1872 }
1873 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001874 if (test_boost_interval < 1)
1875 test_boost_interval = 1;
1876 if (test_boost_duration < 2)
1877 test_boost_duration = 2;
1878 if ((test_boost == 1 && cur_ops->can_boost) ||
1879 test_boost == 2) {
1880 int retval;
1881
1882 boost_starttime = jiffies + test_boost_interval * HZ;
1883 register_cpu_notifier(&rcutorture_cpu_nb);
1884 for_each_possible_cpu(i) {
1885 if (cpu_is_offline(i))
1886 continue; /* Heuristic: CPU can go offline. */
1887 retval = rcutorture_booster_init(i);
1888 if (retval < 0) {
1889 firsterr = retval;
1890 goto unwind;
1891 }
1892 }
1893 }
Paul E. McKenneyd5f546d2011-11-04 11:44:12 -07001894 if (shutdown_secs > 0) {
1895 shutdown_time = jiffies + shutdown_secs * HZ;
1896 shutdown_task = kthread_run(rcu_torture_shutdown, NULL,
1897 "rcu_torture_shutdown");
1898 if (IS_ERR(shutdown_task)) {
1899 firsterr = PTR_ERR(shutdown_task);
1900 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
1901 shutdown_task = NULL;
1902 goto unwind;
1903 }
1904 }
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001905 i = rcu_torture_onoff_init();
1906 if (i != 0) {
1907 firsterr = i;
1908 goto unwind;
1909 }
Paul E. McKenney8e8be452010-09-02 16:16:14 -07001910 register_reboot_notifier(&rcutorture_shutdown_nb);
Paul E. McKenney37e377d2012-02-17 22:12:18 -08001911 i = rcu_torture_stall_init();
1912 if (i != 0) {
1913 firsterr = i;
1914 goto unwind;
1915 }
Paul E. McKenney4a298652011-04-03 21:33:51 -07001916 rcutorture_record_test_transition();
Paul E. McKenney343e9092008-12-15 16:13:07 -08001917 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001918 return 0;
1919
1920unwind:
Paul E. McKenney343e9092008-12-15 16:13:07 -08001921 mutex_unlock(&fullstop_mutex);
Paul E. McKenneya241ec62005-10-30 15:03:12 -08001922 rcu_torture_cleanup();
1923 return firsterr;
1924}
1925
1926module_init(rcu_torture_init);
1927module_exit(rcu_torture_cleanup);