blob: fd599829e72a5d49a5852272ba234be8c38accaf [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>
Josh Triplettb772e1d2006-10-04 02:17:13 -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>
36#include <asm/atomic.h>
37#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>
Rafael J. Wysocki83144182007-07-17 04:03:35 -070042#include <linux/freezer.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080043#include <linux/cpu.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080044#include <linux/delay.h>
45#include <linux/byteorder/swabb.h>
46#include <linux/stat.h>
Paul E. McKenneyb2896d22006-10-04 02:17:03 -070047#include <linux/srcu.h>
Paul E. McKenneya241ec62005-10-30 15:03:12 -080048
49MODULE_LICENSE("GPL");
Josh Triplettb772e1d2006-10-04 02:17:13 -070050MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and "
51 "Josh Triplett <josh@freedesktop.org>");
Paul E. McKenneya241ec62005-10-30 15:03:12 -080052
Josh Triplett48022112006-10-03 23:26:16 +020053static int nreaders = -1; /* # reader threads, defaults to 2*ncpus */
Josh Triplettb772e1d2006-10-04 02:17:13 -070054static int nfakewriters = 4; /* # fake writer threads */
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080055static int stat_interval; /* Interval between stats, in seconds. */
Paul E. McKenneya241ec62005-10-30 15:03:12 -080056 /* Defaults to "only at end of test". */
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080057static int verbose; /* Print more debug info. */
58static int test_no_idle_hz; /* Test RCU's support for tickless idle CPUs. */
59static int shuffle_interval = 5; /* Interval between shuffles (in sec)*/
Josh Triplett20d2e422006-10-04 02:17:15 -070060static char *torture_type = "rcu"; /* What RCU implementation to torture. */
Paul E. McKenneya241ec62005-10-30 15:03:12 -080061
Josh Triplettd6ad6712007-03-06 01:42:13 -080062module_param(nreaders, int, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080063MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
Josh Triplettd6ad6712007-03-06 01:42:13 -080064module_param(nfakewriters, int, 0444);
Josh Triplettb772e1d2006-10-04 02:17:13 -070065MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
Josh Triplettd6ad6712007-03-06 01:42:13 -080066module_param(stat_interval, int, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080067MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
Josh Triplettd6ad6712007-03-06 01:42:13 -080068module_param(verbose, bool, 0444);
Paul E. McKenneya241ec62005-10-30 15:03:12 -080069MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
Josh Triplettd6ad6712007-03-06 01:42:13 -080070module_param(test_no_idle_hz, bool, 0444);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080071MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
Josh Triplettd6ad6712007-03-06 01:42:13 -080072module_param(shuffle_interval, int, 0444);
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080073MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
Josh Triplettd6ad6712007-03-06 01:42:13 -080074module_param(torture_type, charp, 0444);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -070075MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -070076
77#define TORTURE_FLAG "-torture:"
Paul E. McKenneya241ec62005-10-30 15:03:12 -080078#define PRINTK_STRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -070079 do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -080080#define VERBOSE_PRINTK_STRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -070081 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -080082#define VERBOSE_PRINTK_ERRSTRING(s) \
Paul E. McKenney72e9bb52006-06-27 02:54:03 -070083 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
Paul E. McKenneya241ec62005-10-30 15:03:12 -080084
85static char printk_buf[4096];
86
87static int nrealreaders;
88static struct task_struct *writer_task;
Josh Triplettb772e1d2006-10-04 02:17:13 -070089static struct task_struct **fakewriter_tasks;
Paul E. McKenneya241ec62005-10-30 15:03:12 -080090static struct task_struct **reader_tasks;
91static struct task_struct *stats_task;
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -080092static struct task_struct *shuffler_task;
Paul E. McKenneya241ec62005-10-30 15:03:12 -080093
94#define RCU_TORTURE_PIPE_LEN 10
95
96struct rcu_torture {
97 struct rcu_head rtort_rcu;
98 int rtort_pipe_count;
99 struct list_head rtort_free;
Paul E. McKenney996417d2005-11-18 01:10:50 -0800100 int rtort_mbtest;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800101};
102
103static int fullstop = 0; /* stop generating callbacks at test end. */
104static LIST_HEAD(rcu_torture_freelist);
105static struct rcu_torture *rcu_torture_current = NULL;
106static long rcu_torture_current_version = 0;
107static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
108static DEFINE_SPINLOCK(rcu_torture_lock);
109static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
110 { 0 };
111static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
112 { 0 };
113static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700114static atomic_t n_rcu_torture_alloc;
115static atomic_t n_rcu_torture_alloc_fail;
116static atomic_t n_rcu_torture_free;
117static atomic_t n_rcu_torture_mberror;
118static atomic_t n_rcu_torture_error;
Josh Triplette3033732006-10-04 02:17:14 -0700119static struct list_head rcu_torture_removed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800120
121/*
122 * Allocate an element from the rcu_tortures pool.
123 */
Adrian Bunk97a41e22006-01-08 01:02:17 -0800124static struct rcu_torture *
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800125rcu_torture_alloc(void)
126{
127 struct list_head *p;
128
Ingo Molnaradac1662006-01-25 19:50:12 +0100129 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800130 if (list_empty(&rcu_torture_freelist)) {
131 atomic_inc(&n_rcu_torture_alloc_fail);
Ingo Molnaradac1662006-01-25 19:50:12 +0100132 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800133 return NULL;
134 }
135 atomic_inc(&n_rcu_torture_alloc);
136 p = rcu_torture_freelist.next;
137 list_del_init(p);
Ingo Molnaradac1662006-01-25 19:50:12 +0100138 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800139 return container_of(p, struct rcu_torture, rtort_free);
140}
141
142/*
143 * Free an element to the rcu_tortures pool.
144 */
145static void
146rcu_torture_free(struct rcu_torture *p)
147{
148 atomic_inc(&n_rcu_torture_free);
Ingo Molnaradac1662006-01-25 19:50:12 +0100149 spin_lock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800150 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
Ingo Molnaradac1662006-01-25 19:50:12 +0100151 spin_unlock_bh(&rcu_torture_lock);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800152}
153
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800154struct rcu_random_state {
155 unsigned long rrs_state;
Josh Triplett75cfef32006-10-04 02:17:12 -0700156 long rrs_count;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800157};
158
159#define RCU_RANDOM_MULT 39916801 /* prime */
160#define RCU_RANDOM_ADD 479001701 /* prime */
161#define RCU_RANDOM_REFRESH 10000
162
163#define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
164
165/*
166 * Crude but fast random-number generator. Uses a linear congruential
Paul E. McKenneyc17ac852007-10-16 23:27:19 -0700167 * generator, with occasional help from cpu_clock().
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800168 */
Josh Triplett75cfef32006-10-04 02:17:12 -0700169static unsigned long
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800170rcu_random(struct rcu_random_state *rrsp)
171{
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800172 if (--rrsp->rrs_count < 0) {
Paul E. McKenneyc17ac852007-10-16 23:27:19 -0700173 rrsp->rrs_state +=
174 (unsigned long)cpu_clock(raw_smp_processor_id());
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800175 rrsp->rrs_count = RCU_RANDOM_REFRESH;
176 }
177 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
178 return swahw32(rrsp->rrs_state);
179}
180
181/*
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700182 * Operations vector for selecting different types of tests.
183 */
184
185struct rcu_torture_ops {
186 void (*init)(void);
187 void (*cleanup)(void);
188 int (*readlock)(void);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700189 void (*readdelay)(struct rcu_random_state *rrsp);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700190 void (*readunlock)(int idx);
191 int (*completed)(void);
192 void (*deferredfree)(struct rcu_torture *p);
Josh Triplettb772e1d2006-10-04 02:17:13 -0700193 void (*sync)(void);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700194 int (*stats)(char *page);
195 char *name;
196};
197static struct rcu_torture_ops *cur_ops = NULL;
198
199/*
200 * Definitions for rcu torture testing.
201 */
202
Josh Tripletta49a4af2006-09-29 01:59:30 -0700203static int rcu_torture_read_lock(void) __acquires(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700204{
205 rcu_read_lock();
206 return 0;
207}
208
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700209static void rcu_read_delay(struct rcu_random_state *rrsp)
210{
211 long delay;
212 const long longdelay = 200;
213
214 /* We want there to be long-running readers, but not all the time. */
215
216 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay);
217 if (!delay)
218 udelay(longdelay);
219}
220
Josh Tripletta49a4af2006-09-29 01:59:30 -0700221static void rcu_torture_read_unlock(int idx) __releases(RCU)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700222{
223 rcu_read_unlock();
224}
225
226static int rcu_torture_completed(void)
227{
228 return rcu_batches_completed();
229}
230
231static void
232rcu_torture_cb(struct rcu_head *p)
233{
234 int i;
235 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
236
237 if (fullstop) {
238 /* Test is ending, just drop callbacks on the floor. */
239 /* The next initialization will pick up the pieces. */
240 return;
241 }
242 i = rp->rtort_pipe_count;
243 if (i > RCU_TORTURE_PIPE_LEN)
244 i = RCU_TORTURE_PIPE_LEN;
245 atomic_inc(&rcu_torture_wcount[i]);
246 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
247 rp->rtort_mbtest = 0;
248 rcu_torture_free(rp);
249 } else
250 cur_ops->deferredfree(rp);
251}
252
253static void rcu_torture_deferred_free(struct rcu_torture *p)
254{
255 call_rcu(&p->rtort_rcu, rcu_torture_cb);
256}
257
258static struct rcu_torture_ops rcu_ops = {
259 .init = NULL,
260 .cleanup = NULL,
261 .readlock = rcu_torture_read_lock,
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700262 .readdelay = rcu_read_delay,
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700263 .readunlock = rcu_torture_read_unlock,
264 .completed = rcu_torture_completed,
265 .deferredfree = rcu_torture_deferred_free,
Josh Triplettb772e1d2006-10-04 02:17:13 -0700266 .sync = synchronize_rcu,
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700267 .stats = NULL,
268 .name = "rcu"
269};
270
Josh Triplette3033732006-10-04 02:17:14 -0700271static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
272{
273 int i;
274 struct rcu_torture *rp;
275 struct rcu_torture *rp1;
276
277 cur_ops->sync();
278 list_add(&p->rtort_free, &rcu_torture_removed);
279 list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
280 i = rp->rtort_pipe_count;
281 if (i > RCU_TORTURE_PIPE_LEN)
282 i = RCU_TORTURE_PIPE_LEN;
283 atomic_inc(&rcu_torture_wcount[i]);
284 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
285 rp->rtort_mbtest = 0;
286 list_del(&rp->rtort_free);
287 rcu_torture_free(rp);
288 }
289 }
290}
291
292static void rcu_sync_torture_init(void)
293{
294 INIT_LIST_HEAD(&rcu_torture_removed);
295}
296
Josh Triplett20d2e422006-10-04 02:17:15 -0700297static struct rcu_torture_ops rcu_sync_ops = {
298 .init = rcu_sync_torture_init,
299 .cleanup = NULL,
300 .readlock = rcu_torture_read_lock,
301 .readdelay = rcu_read_delay,
302 .readunlock = rcu_torture_read_unlock,
303 .completed = rcu_torture_completed,
304 .deferredfree = rcu_sync_torture_deferred_free,
305 .sync = synchronize_rcu,
306 .stats = NULL,
307 .name = "rcu_sync"
308};
309
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700310/*
311 * Definitions for rcu_bh torture testing.
312 */
313
Josh Tripletta49a4af2006-09-29 01:59:30 -0700314static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700315{
316 rcu_read_lock_bh();
317 return 0;
318}
319
Josh Tripletta49a4af2006-09-29 01:59:30 -0700320static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700321{
322 rcu_read_unlock_bh();
323}
324
325static int rcu_bh_torture_completed(void)
326{
327 return rcu_batches_completed_bh();
328}
329
330static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
331{
332 call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
333}
334
Josh Triplettb772e1d2006-10-04 02:17:13 -0700335struct rcu_bh_torture_synchronize {
336 struct rcu_head head;
337 struct completion completion;
338};
339
340static void rcu_bh_torture_wakeme_after_cb(struct rcu_head *head)
341{
342 struct rcu_bh_torture_synchronize *rcu;
343
344 rcu = container_of(head, struct rcu_bh_torture_synchronize, head);
345 complete(&rcu->completion);
346}
347
348static void rcu_bh_torture_synchronize(void)
349{
350 struct rcu_bh_torture_synchronize rcu;
351
352 init_completion(&rcu.completion);
353 call_rcu_bh(&rcu.head, rcu_bh_torture_wakeme_after_cb);
354 wait_for_completion(&rcu.completion);
355}
356
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700357static struct rcu_torture_ops rcu_bh_ops = {
358 .init = NULL,
359 .cleanup = NULL,
360 .readlock = rcu_bh_torture_read_lock,
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700361 .readdelay = rcu_read_delay, /* just reuse rcu's version. */
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700362 .readunlock = rcu_bh_torture_read_unlock,
363 .completed = rcu_bh_torture_completed,
364 .deferredfree = rcu_bh_torture_deferred_free,
Josh Triplettb772e1d2006-10-04 02:17:13 -0700365 .sync = rcu_bh_torture_synchronize,
Paul E. McKenneyc32e0662006-06-27 02:54:04 -0700366 .stats = NULL,
367 .name = "rcu_bh"
368};
369
Josh Triplett11a14702006-10-04 02:17:16 -0700370static struct rcu_torture_ops rcu_bh_sync_ops = {
371 .init = rcu_sync_torture_init,
372 .cleanup = NULL,
373 .readlock = rcu_bh_torture_read_lock,
374 .readdelay = rcu_read_delay, /* just reuse rcu's version. */
375 .readunlock = rcu_bh_torture_read_unlock,
376 .completed = rcu_bh_torture_completed,
377 .deferredfree = rcu_sync_torture_deferred_free,
378 .sync = rcu_bh_torture_synchronize,
379 .stats = NULL,
380 .name = "rcu_bh_sync"
381};
382
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700383/*
384 * Definitions for srcu torture testing.
385 */
386
387static struct srcu_struct srcu_ctl;
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700388
389static void srcu_torture_init(void)
390{
391 init_srcu_struct(&srcu_ctl);
Josh Triplette3033732006-10-04 02:17:14 -0700392 rcu_sync_torture_init();
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700393}
394
395static void srcu_torture_cleanup(void)
396{
397 synchronize_srcu(&srcu_ctl);
398 cleanup_srcu_struct(&srcu_ctl);
399}
400
Josh Triplett012d3ca2006-12-06 20:40:19 -0800401static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700402{
403 return srcu_read_lock(&srcu_ctl);
404}
405
406static void srcu_read_delay(struct rcu_random_state *rrsp)
407{
408 long delay;
409 const long uspertick = 1000000 / HZ;
410 const long longdelay = 10;
411
412 /* We want there to be long-running readers, but not all the time. */
413
414 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
415 if (!delay)
416 schedule_timeout_interruptible(longdelay);
417}
418
Josh Triplett012d3ca2006-12-06 20:40:19 -0800419static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700420{
421 srcu_read_unlock(&srcu_ctl, idx);
422}
423
424static int srcu_torture_completed(void)
425{
426 return srcu_batches_completed(&srcu_ctl);
427}
428
Josh Triplettb772e1d2006-10-04 02:17:13 -0700429static void srcu_torture_synchronize(void)
430{
431 synchronize_srcu(&srcu_ctl);
432}
433
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700434static int srcu_torture_stats(char *page)
435{
436 int cnt = 0;
437 int cpu;
438 int idx = srcu_ctl.completed & 0x1;
439
440 cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
441 torture_type, TORTURE_FLAG, idx);
442 for_each_possible_cpu(cpu) {
443 cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu,
444 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
445 per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
446 }
447 cnt += sprintf(&page[cnt], "\n");
448 return cnt;
449}
450
451static struct rcu_torture_ops srcu_ops = {
452 .init = srcu_torture_init,
453 .cleanup = srcu_torture_cleanup,
454 .readlock = srcu_torture_read_lock,
455 .readdelay = srcu_read_delay,
456 .readunlock = srcu_torture_read_unlock,
457 .completed = srcu_torture_completed,
Josh Triplette3033732006-10-04 02:17:14 -0700458 .deferredfree = rcu_sync_torture_deferred_free,
Josh Triplettb772e1d2006-10-04 02:17:13 -0700459 .sync = srcu_torture_synchronize,
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700460 .stats = srcu_torture_stats,
461 .name = "srcu"
462};
463
Josh Triplett4b6c2cc2006-10-04 02:17:16 -0700464/*
465 * Definitions for sched torture testing.
466 */
467
468static int sched_torture_read_lock(void)
469{
470 preempt_disable();
471 return 0;
472}
473
474static void sched_torture_read_unlock(int idx)
475{
476 preempt_enable();
477}
478
479static int sched_torture_completed(void)
480{
481 return 0;
482}
483
484static void sched_torture_synchronize(void)
485{
486 synchronize_sched();
487}
488
489static struct rcu_torture_ops sched_ops = {
490 .init = rcu_sync_torture_init,
491 .cleanup = NULL,
492 .readlock = sched_torture_read_lock,
493 .readdelay = rcu_read_delay, /* just reuse rcu's version. */
494 .readunlock = sched_torture_read_unlock,
495 .completed = sched_torture_completed,
496 .deferredfree = rcu_sync_torture_deferred_free,
497 .sync = sched_torture_synchronize,
498 .stats = NULL,
499 .name = "sched"
500};
501
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700502/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800503 * RCU torture writer kthread. Repeatedly substitutes a new structure
504 * for that pointed to by rcu_torture_current, freeing the old structure
505 * after a series of grace periods (the "pipeline").
506 */
507static int
508rcu_torture_writer(void *arg)
509{
510 int i;
511 long oldbatch = rcu_batches_completed();
512 struct rcu_torture *rp;
513 struct rcu_torture *old_rp;
514 static DEFINE_RCU_RANDOM(rand);
515
516 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800517 set_user_nice(current, 19);
518
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800519 do {
520 schedule_timeout_uninterruptible(1);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800521 if ((rp = rcu_torture_alloc()) == NULL)
522 continue;
523 rp->rtort_pipe_count = 0;
524 udelay(rcu_random(&rand) & 0x3ff);
525 old_rp = rcu_torture_current;
Paul E. McKenney996417d2005-11-18 01:10:50 -0800526 rp->rtort_mbtest = 1;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800527 rcu_assign_pointer(rcu_torture_current, rp);
528 smp_wmb();
Josh Triplettc8e5b162007-05-08 00:33:20 -0700529 if (old_rp) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800530 i = old_rp->rtort_pipe_count;
531 if (i > RCU_TORTURE_PIPE_LEN)
532 i = RCU_TORTURE_PIPE_LEN;
533 atomic_inc(&rcu_torture_wcount[i]);
534 old_rp->rtort_pipe_count++;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700535 cur_ops->deferredfree(old_rp);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800536 }
537 rcu_torture_current_version++;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700538 oldbatch = cur_ops->completed();
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800539 } while (!kthread_should_stop() && !fullstop);
540 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
541 while (!kthread_should_stop())
542 schedule_timeout_uninterruptible(1);
543 return 0;
544}
545
546/*
Josh Triplettb772e1d2006-10-04 02:17:13 -0700547 * RCU torture fake writer kthread. Repeatedly calls sync, with a random
548 * delay between calls.
549 */
550static int
551rcu_torture_fakewriter(void *arg)
552{
553 DEFINE_RCU_RANDOM(rand);
554
555 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
556 set_user_nice(current, 19);
557
558 do {
559 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
560 udelay(rcu_random(&rand) & 0x3ff);
561 cur_ops->sync();
562 } while (!kthread_should_stop() && !fullstop);
563
564 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
565 while (!kthread_should_stop())
566 schedule_timeout_uninterruptible(1);
567 return 0;
568}
569
570/*
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800571 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
572 * incrementing the corresponding element of the pipeline array. The
573 * counter in the element should never be greater than 1, otherwise, the
574 * RCU implementation is broken.
575 */
576static int
577rcu_torture_reader(void *arg)
578{
579 int completed;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700580 int idx;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800581 DEFINE_RCU_RANDOM(rand);
582 struct rcu_torture *p;
583 int pipe_count;
584
585 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
Ingo Molnardbdf65b2005-11-13 16:07:22 -0800586 set_user_nice(current, 19);
587
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800588 do {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700589 idx = cur_ops->readlock();
590 completed = cur_ops->completed();
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800591 p = rcu_dereference(rcu_torture_current);
592 if (p == NULL) {
593 /* Wait for rcu_torture_writer to get underway */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700594 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800595 schedule_timeout_interruptible(HZ);
596 continue;
597 }
Paul E. McKenney996417d2005-11-18 01:10:50 -0800598 if (p->rtort_mbtest == 0)
599 atomic_inc(&n_rcu_torture_mberror);
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700600 cur_ops->readdelay(&rand);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800601 preempt_disable();
602 pipe_count = p->rtort_pipe_count;
603 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
604 /* Should not happen, but... */
605 pipe_count = RCU_TORTURE_PIPE_LEN;
606 }
607 ++__get_cpu_var(rcu_torture_count)[pipe_count];
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700608 completed = cur_ops->completed() - completed;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800609 if (completed > RCU_TORTURE_PIPE_LEN) {
610 /* Should not happen, but... */
611 completed = RCU_TORTURE_PIPE_LEN;
612 }
613 ++__get_cpu_var(rcu_torture_batch)[completed];
614 preempt_enable();
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700615 cur_ops->readunlock(idx);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800616 schedule();
617 } while (!kthread_should_stop() && !fullstop);
618 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
619 while (!kthread_should_stop())
620 schedule_timeout_uninterruptible(1);
621 return 0;
622}
623
624/*
625 * Create an RCU-torture statistics message in the specified buffer.
626 */
627static int
628rcu_torture_printk(char *page)
629{
630 int cnt = 0;
631 int cpu;
632 int i;
633 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
634 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
635
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -0800636 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800637 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
638 pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
639 batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
640 }
641 }
642 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
643 if (pipesummary[i] != 0)
644 break;
645 }
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700646 cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800647 cnt += sprintf(&page[cnt],
Paul E. McKenney996417d2005-11-18 01:10:50 -0800648 "rtc: %p ver: %ld tfle: %d rta: %d rtaf: %d rtf: %d "
649 "rtmbe: %d",
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800650 rcu_torture_current,
651 rcu_torture_current_version,
652 list_empty(&rcu_torture_freelist),
653 atomic_read(&n_rcu_torture_alloc),
654 atomic_read(&n_rcu_torture_alloc_fail),
Paul E. McKenney996417d2005-11-18 01:10:50 -0800655 atomic_read(&n_rcu_torture_free),
656 atomic_read(&n_rcu_torture_mberror));
657 if (atomic_read(&n_rcu_torture_mberror) != 0)
658 cnt += sprintf(&page[cnt], " !!!");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700659 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800660 if (i > 1) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800661 cnt += sprintf(&page[cnt], "!!! ");
Paul E. McKenney996417d2005-11-18 01:10:50 -0800662 atomic_inc(&n_rcu_torture_error);
663 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800664 cnt += sprintf(&page[cnt], "Reader Pipe: ");
665 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
666 cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700667 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800668 cnt += sprintf(&page[cnt], "Reader Batch: ");
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700669 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800670 cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700671 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800672 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
673 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
674 cnt += sprintf(&page[cnt], " %d",
675 atomic_read(&rcu_torture_wcount[i]));
676 }
677 cnt += sprintf(&page[cnt], "\n");
Josh Triplettc8e5b162007-05-08 00:33:20 -0700678 if (cur_ops->stats)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700679 cnt += cur_ops->stats(&page[cnt]);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800680 return cnt;
681}
682
683/*
684 * Print torture statistics. Caller must ensure that there is only
685 * one call to this function at a given time!!! This is normally
686 * accomplished by relying on the module system to only have one copy
687 * of the module loaded, and then by giving the rcu_torture_stats
688 * kthread full control (or the init/cleanup functions when rcu_torture_stats
689 * thread is not running).
690 */
691static void
692rcu_torture_stats_print(void)
693{
694 int cnt;
695
696 cnt = rcu_torture_printk(printk_buf);
697 printk(KERN_ALERT "%s", printk_buf);
698}
699
700/*
701 * Periodically prints torture statistics, if periodic statistics printing
702 * was specified via the stat_interval module parameter.
703 *
704 * No need to worry about fullstop here, since this one doesn't reference
705 * volatile state or register callbacks.
706 */
707static int
708rcu_torture_stats(void *arg)
709{
710 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
711 do {
712 schedule_timeout_interruptible(stat_interval * HZ);
713 rcu_torture_stats_print();
714 } while (!kthread_should_stop());
715 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
716 return 0;
717}
718
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800719static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
720
721/* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
722 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
723 */
Paul E. McKenneyb2896d22006-10-04 02:17:03 -0700724static void rcu_torture_shuffle_tasks(void)
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800725{
726 cpumask_t tmp_mask = CPU_MASK_ALL;
727 int i;
728
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +0100729 get_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800730
731 /* No point in shuffling if there is only one online CPU (ex: UP) */
732 if (num_online_cpus() == 1) {
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +0100733 put_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800734 return;
735 }
736
737 if (rcu_idle_cpu != -1)
738 cpu_clear(rcu_idle_cpu, tmp_mask);
739
740 set_cpus_allowed(current, tmp_mask);
741
Josh Triplettc8e5b162007-05-08 00:33:20 -0700742 if (reader_tasks) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800743 for (i = 0; i < nrealreaders; i++)
744 if (reader_tasks[i])
745 set_cpus_allowed(reader_tasks[i], tmp_mask);
746 }
747
Josh Triplettc8e5b162007-05-08 00:33:20 -0700748 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -0700749 for (i = 0; i < nfakewriters; i++)
750 if (fakewriter_tasks[i])
751 set_cpus_allowed(fakewriter_tasks[i], tmp_mask);
752 }
753
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800754 if (writer_task)
755 set_cpus_allowed(writer_task, tmp_mask);
756
757 if (stats_task)
758 set_cpus_allowed(stats_task, tmp_mask);
759
760 if (rcu_idle_cpu == -1)
761 rcu_idle_cpu = num_online_cpus() - 1;
762 else
763 rcu_idle_cpu--;
764
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +0100765 put_online_cpus();
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800766}
767
768/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
769 * system to become idle at a time and cut off its timer ticks. This is meant
770 * to test the support for such tickless idle CPU in RCU.
771 */
772static int
773rcu_torture_shuffle(void *arg)
774{
775 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
776 do {
777 schedule_timeout_interruptible(shuffle_interval * HZ);
778 rcu_torture_shuffle_tasks();
779 } while (!kthread_should_stop());
780 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
781 return 0;
782}
783
Paul E. McKenney95c38322006-03-24 03:15:58 -0800784static inline void
785rcu_torture_print_module_parms(char *tag)
786{
Josh Triplettb772e1d2006-10-04 02:17:13 -0700787 printk(KERN_ALERT "%s" TORTURE_FLAG
788 "--- %s: nreaders=%d nfakewriters=%d "
Paul E. McKenney95c38322006-03-24 03:15:58 -0800789 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
790 "shuffle_interval = %d\n",
Josh Triplettb772e1d2006-10-04 02:17:13 -0700791 torture_type, tag, nrealreaders, nfakewriters,
792 stat_interval, verbose, test_no_idle_hz, shuffle_interval);
Paul E. McKenney95c38322006-03-24 03:15:58 -0800793}
794
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800795static void
796rcu_torture_cleanup(void)
797{
798 int i;
799
800 fullstop = 1;
Josh Triplettc8e5b162007-05-08 00:33:20 -0700801 if (shuffler_task) {
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800802 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
803 kthread_stop(shuffler_task);
804 }
805 shuffler_task = NULL;
806
Josh Triplettc8e5b162007-05-08 00:33:20 -0700807 if (writer_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800808 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
809 kthread_stop(writer_task);
810 }
811 writer_task = NULL;
812
Josh Triplettc8e5b162007-05-08 00:33:20 -0700813 if (reader_tasks) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800814 for (i = 0; i < nrealreaders; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -0700815 if (reader_tasks[i]) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800816 VERBOSE_PRINTK_STRING(
817 "Stopping rcu_torture_reader task");
818 kthread_stop(reader_tasks[i]);
819 }
820 reader_tasks[i] = NULL;
821 }
822 kfree(reader_tasks);
823 reader_tasks = NULL;
824 }
825 rcu_torture_current = NULL;
826
Josh Triplettc8e5b162007-05-08 00:33:20 -0700827 if (fakewriter_tasks) {
Josh Triplettb772e1d2006-10-04 02:17:13 -0700828 for (i = 0; i < nfakewriters; i++) {
Josh Triplettc8e5b162007-05-08 00:33:20 -0700829 if (fakewriter_tasks[i]) {
Josh Triplettb772e1d2006-10-04 02:17:13 -0700830 VERBOSE_PRINTK_STRING(
831 "Stopping rcu_torture_fakewriter task");
832 kthread_stop(fakewriter_tasks[i]);
833 }
834 fakewriter_tasks[i] = NULL;
835 }
836 kfree(fakewriter_tasks);
837 fakewriter_tasks = NULL;
838 }
839
Josh Triplettc8e5b162007-05-08 00:33:20 -0700840 if (stats_task) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800841 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
842 kthread_stop(stats_task);
843 }
844 stats_task = NULL;
845
846 /* Wait for all RCU callbacks to fire. */
Srivatsa Vaddagiri89d46b82005-12-12 00:37:06 -0800847 rcu_barrier();
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800848
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800849 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700850
Josh Triplettc8e5b162007-05-08 00:33:20 -0700851 if (cur_ops->cleanup)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700852 cur_ops->cleanup();
Paul E. McKenney95c38322006-03-24 03:15:58 -0800853 if (atomic_read(&n_rcu_torture_error))
854 rcu_torture_print_module_parms("End of test: FAILURE");
855 else
856 rcu_torture_print_module_parms("End of test: SUCCESS");
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800857}
858
Josh Triplett6f8bc5002007-05-08 00:25:24 -0700859static int __init
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800860rcu_torture_init(void)
861{
862 int i;
863 int cpu;
864 int firsterr = 0;
Josh Triplettade5fb82007-05-08 00:33:22 -0700865 static struct rcu_torture_ops *torture_ops[] =
866 { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops,
867 &srcu_ops, &sched_ops, };
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800868
869 /* Process args and tell the world that the torturer is on the job. */
Josh Triplettade5fb82007-05-08 00:33:22 -0700870 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700871 cur_ops = torture_ops[i];
Josh Triplettade5fb82007-05-08 00:33:22 -0700872 if (strcmp(torture_type, cur_ops->name) == 0)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700873 break;
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700874 }
Josh Triplettade5fb82007-05-08 00:33:22 -0700875 if (i == ARRAY_SIZE(torture_ops)) {
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700876 printk(KERN_ALERT "rcutorture: invalid torture type: \"%s\"\n",
877 torture_type);
878 return (-EINVAL);
879 }
Josh Triplettc8e5b162007-05-08 00:33:20 -0700880 if (cur_ops->init)
Paul E. McKenney72e9bb52006-06-27 02:54:03 -0700881 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
882
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800883 if (nreaders >= 0)
884 nrealreaders = nreaders;
885 else
886 nrealreaders = 2 * num_online_cpus();
Paul E. McKenney95c38322006-03-24 03:15:58 -0800887 rcu_torture_print_module_parms("Start of test");
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800888 fullstop = 0;
889
890 /* Set up the freelist. */
891
892 INIT_LIST_HEAD(&rcu_torture_freelist);
Ahmed S. Darwish788e7702007-05-08 00:33:14 -0700893 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
Paul E. McKenney996417d2005-11-18 01:10:50 -0800894 rcu_tortures[i].rtort_mbtest = 0;
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800895 list_add_tail(&rcu_tortures[i].rtort_free,
896 &rcu_torture_freelist);
897 }
898
899 /* Initialize the statistics so that each run gets its own numbers. */
900
901 rcu_torture_current = NULL;
902 rcu_torture_current_version = 0;
903 atomic_set(&n_rcu_torture_alloc, 0);
904 atomic_set(&n_rcu_torture_alloc_fail, 0);
905 atomic_set(&n_rcu_torture_free, 0);
Paul E. McKenney996417d2005-11-18 01:10:50 -0800906 atomic_set(&n_rcu_torture_mberror, 0);
907 atomic_set(&n_rcu_torture_error, 0);
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800908 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
909 atomic_set(&rcu_torture_wcount[i], 0);
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -0800910 for_each_possible_cpu(cpu) {
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800911 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
912 per_cpu(rcu_torture_count, cpu)[i] = 0;
913 per_cpu(rcu_torture_batch, cpu)[i] = 0;
914 }
915 }
916
917 /* Start up the kthreads. */
918
919 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
920 writer_task = kthread_run(rcu_torture_writer, NULL,
921 "rcu_torture_writer");
922 if (IS_ERR(writer_task)) {
923 firsterr = PTR_ERR(writer_task);
924 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
925 writer_task = NULL;
926 goto unwind;
927 }
Josh Triplettb772e1d2006-10-04 02:17:13 -0700928 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
929 GFP_KERNEL);
930 if (fakewriter_tasks == NULL) {
931 VERBOSE_PRINTK_ERRSTRING("out of memory");
932 firsterr = -ENOMEM;
933 goto unwind;
934 }
935 for (i = 0; i < nfakewriters; i++) {
936 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
937 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
938 "rcu_torture_fakewriter");
939 if (IS_ERR(fakewriter_tasks[i])) {
940 firsterr = PTR_ERR(fakewriter_tasks[i]);
941 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
942 fakewriter_tasks[i] = NULL;
943 goto unwind;
944 }
945 }
Josh Triplett2860aab2006-10-04 02:17:11 -0700946 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800947 GFP_KERNEL);
948 if (reader_tasks == NULL) {
949 VERBOSE_PRINTK_ERRSTRING("out of memory");
950 firsterr = -ENOMEM;
951 goto unwind;
952 }
953 for (i = 0; i < nrealreaders; i++) {
954 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
955 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
956 "rcu_torture_reader");
957 if (IS_ERR(reader_tasks[i])) {
958 firsterr = PTR_ERR(reader_tasks[i]);
959 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
960 reader_tasks[i] = NULL;
961 goto unwind;
962 }
963 }
964 if (stat_interval > 0) {
965 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
966 stats_task = kthread_run(rcu_torture_stats, NULL,
967 "rcu_torture_stats");
968 if (IS_ERR(stats_task)) {
969 firsterr = PTR_ERR(stats_task);
970 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
971 stats_task = NULL;
972 goto unwind;
973 }
974 }
Srivatsa Vaddagirid84f5202006-01-08 01:03:42 -0800975 if (test_no_idle_hz) {
976 rcu_idle_cpu = num_online_cpus() - 1;
977 /* Create the shuffler thread */
978 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
979 "rcu_torture_shuffle");
980 if (IS_ERR(shuffler_task)) {
981 firsterr = PTR_ERR(shuffler_task);
982 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
983 shuffler_task = NULL;
984 goto unwind;
985 }
986 }
Paul E. McKenneya241ec62005-10-30 15:03:12 -0800987 return 0;
988
989unwind:
990 rcu_torture_cleanup();
991 return firsterr;
992}
993
994module_init(rcu_torture_init);
995module_exit(rcu_torture_cleanup);