2 * Read-Copy Update module-based torture test facility
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.
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.
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.
18 * Copyright (C) IBM Corporation, 2005
20 * Authors: Paul E. McKenney <paulmck@us.ibm.com>
22 * See also: Documentation/RCU/torture.txt
24 #include <linux/types.h>
25 #include <linux/kernel.h>
26 #include <linux/init.h>
27 #include <linux/module.h>
28 #include <linux/kthread.h>
29 #include <linux/err.h>
30 #include <linux/spinlock.h>
31 #include <linux/smp.h>
32 #include <linux/rcupdate.h>
33 #include <linux/interrupt.h>
34 #include <linux/sched.h>
35 #include <asm/atomic.h>
36 #include <linux/bitops.h>
37 #include <linux/module.h>
38 #include <linux/completion.h>
39 #include <linux/moduleparam.h>
40 #include <linux/percpu.h>
41 #include <linux/notifier.h>
42 #include <linux/cpu.h>
43 #include <linux/random.h>
44 #include <linux/delay.h>
45 #include <linux/byteorder/swabb.h>
46 #include <linux/stat.h>
47 #include <linux/srcu.h>
49 MODULE_LICENSE("GPL");
50 MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com>");
52 static int nreaders
= -1; /* # reader threads, defaults to 2*ncpus */
53 static int stat_interval
; /* Interval between stats, in seconds. */
54 /* Defaults to "only at end of test". */
55 static int verbose
; /* Print more debug info. */
56 static int test_no_idle_hz
; /* Test RCU's support for tickless idle CPUs. */
57 static int shuffle_interval
= 5; /* Interval between shuffles (in sec)*/
58 static char *torture_type
= "rcu"; /* What to torture: rcu, rcu_bh, srcu. */
60 module_param(nreaders
, int, 0);
61 MODULE_PARM_DESC(nreaders
, "Number of RCU reader threads");
62 module_param(stat_interval
, int, 0);
63 MODULE_PARM_DESC(stat_interval
, "Number of seconds between stats printk()s");
64 module_param(verbose
, bool, 0);
65 MODULE_PARM_DESC(verbose
, "Enable verbose debugging printk()s");
66 module_param(test_no_idle_hz
, bool, 0);
67 MODULE_PARM_DESC(test_no_idle_hz
, "Test support for tickless idle CPUs");
68 module_param(shuffle_interval
, int, 0);
69 MODULE_PARM_DESC(shuffle_interval
, "Number of seconds between shuffles");
70 module_param(torture_type
, charp
, 0);
71 MODULE_PARM_DESC(torture_type
, "Type of RCU to torture (rcu, rcu_bh, srcu)");
73 #define TORTURE_FLAG "-torture:"
74 #define PRINTK_STRING(s) \
75 do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
76 #define VERBOSE_PRINTK_STRING(s) \
77 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
78 #define VERBOSE_PRINTK_ERRSTRING(s) \
79 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
81 static char printk_buf
[4096];
83 static int nrealreaders
;
84 static struct task_struct
*writer_task
;
85 static struct task_struct
**reader_tasks
;
86 static struct task_struct
*stats_task
;
87 static struct task_struct
*shuffler_task
;
89 #define RCU_TORTURE_PIPE_LEN 10
92 struct rcu_head rtort_rcu
;
94 struct list_head rtort_free
;
98 static int fullstop
= 0; /* stop generating callbacks at test end. */
99 static LIST_HEAD(rcu_torture_freelist
);
100 static struct rcu_torture
*rcu_torture_current
= NULL
;
101 static long rcu_torture_current_version
= 0;
102 static struct rcu_torture rcu_tortures
[10 * RCU_TORTURE_PIPE_LEN
];
103 static DEFINE_SPINLOCK(rcu_torture_lock
);
104 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN
+ 1], rcu_torture_count
) =
106 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN
+ 1], rcu_torture_batch
) =
108 static atomic_t rcu_torture_wcount
[RCU_TORTURE_PIPE_LEN
+ 1];
109 static atomic_t n_rcu_torture_alloc
;
110 static atomic_t n_rcu_torture_alloc_fail
;
111 static atomic_t n_rcu_torture_free
;
112 static atomic_t n_rcu_torture_mberror
;
113 static atomic_t n_rcu_torture_error
;
116 * Allocate an element from the rcu_tortures pool.
118 static struct rcu_torture
*
119 rcu_torture_alloc(void)
123 spin_lock_bh(&rcu_torture_lock
);
124 if (list_empty(&rcu_torture_freelist
)) {
125 atomic_inc(&n_rcu_torture_alloc_fail
);
126 spin_unlock_bh(&rcu_torture_lock
);
129 atomic_inc(&n_rcu_torture_alloc
);
130 p
= rcu_torture_freelist
.next
;
132 spin_unlock_bh(&rcu_torture_lock
);
133 return container_of(p
, struct rcu_torture
, rtort_free
);
137 * Free an element to the rcu_tortures pool.
140 rcu_torture_free(struct rcu_torture
*p
)
142 atomic_inc(&n_rcu_torture_free
);
143 spin_lock_bh(&rcu_torture_lock
);
144 list_add_tail(&p
->rtort_free
, &rcu_torture_freelist
);
145 spin_unlock_bh(&rcu_torture_lock
);
148 struct rcu_random_state
{
149 unsigned long rrs_state
;
153 #define RCU_RANDOM_MULT 39916801 /* prime */
154 #define RCU_RANDOM_ADD 479001701 /* prime */
155 #define RCU_RANDOM_REFRESH 10000
157 #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
160 * Crude but fast random-number generator. Uses a linear congruential
161 * generator, with occasional help from get_random_bytes().
164 rcu_random(struct rcu_random_state
*rrsp
)
168 if (--rrsp
->rrs_count
< 0) {
169 get_random_bytes(&refresh
, sizeof(refresh
));
170 rrsp
->rrs_state
+= refresh
;
171 rrsp
->rrs_count
= RCU_RANDOM_REFRESH
;
173 rrsp
->rrs_state
= rrsp
->rrs_state
* RCU_RANDOM_MULT
+ RCU_RANDOM_ADD
;
174 return swahw32(rrsp
->rrs_state
);
178 * Operations vector for selecting different types of tests.
181 struct rcu_torture_ops
{
183 void (*cleanup
)(void);
184 int (*readlock
)(void);
185 void (*readdelay
)(struct rcu_random_state
*rrsp
);
186 void (*readunlock
)(int idx
);
187 int (*completed
)(void);
188 void (*deferredfree
)(struct rcu_torture
*p
);
189 int (*stats
)(char *page
);
192 static struct rcu_torture_ops
*cur_ops
= NULL
;
195 * Definitions for rcu torture testing.
198 static int rcu_torture_read_lock(void) __acquires(RCU
)
204 static void rcu_read_delay(struct rcu_random_state
*rrsp
)
207 const long longdelay
= 200;
209 /* We want there to be long-running readers, but not all the time. */
211 delay
= rcu_random(rrsp
) % (nrealreaders
* 2 * longdelay
);
216 static void rcu_torture_read_unlock(int idx
) __releases(RCU
)
221 static int rcu_torture_completed(void)
223 return rcu_batches_completed();
227 rcu_torture_cb(struct rcu_head
*p
)
230 struct rcu_torture
*rp
= container_of(p
, struct rcu_torture
, rtort_rcu
);
233 /* Test is ending, just drop callbacks on the floor. */
234 /* The next initialization will pick up the pieces. */
237 i
= rp
->rtort_pipe_count
;
238 if (i
> RCU_TORTURE_PIPE_LEN
)
239 i
= RCU_TORTURE_PIPE_LEN
;
240 atomic_inc(&rcu_torture_wcount
[i
]);
241 if (++rp
->rtort_pipe_count
>= RCU_TORTURE_PIPE_LEN
) {
242 rp
->rtort_mbtest
= 0;
243 rcu_torture_free(rp
);
245 cur_ops
->deferredfree(rp
);
248 static void rcu_torture_deferred_free(struct rcu_torture
*p
)
250 call_rcu(&p
->rtort_rcu
, rcu_torture_cb
);
253 static struct rcu_torture_ops rcu_ops
= {
256 .readlock
= rcu_torture_read_lock
,
257 .readdelay
= rcu_read_delay
,
258 .readunlock
= rcu_torture_read_unlock
,
259 .completed
= rcu_torture_completed
,
260 .deferredfree
= rcu_torture_deferred_free
,
266 * Definitions for rcu_bh torture testing.
269 static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH
)
275 static void rcu_bh_torture_read_unlock(int idx
) __releases(RCU_BH
)
277 rcu_read_unlock_bh();
280 static int rcu_bh_torture_completed(void)
282 return rcu_batches_completed_bh();
285 static void rcu_bh_torture_deferred_free(struct rcu_torture
*p
)
287 call_rcu_bh(&p
->rtort_rcu
, rcu_torture_cb
);
290 static struct rcu_torture_ops rcu_bh_ops
= {
293 .readlock
= rcu_bh_torture_read_lock
,
294 .readdelay
= rcu_read_delay
, /* just reuse rcu's version. */
295 .readunlock
= rcu_bh_torture_read_unlock
,
296 .completed
= rcu_bh_torture_completed
,
297 .deferredfree
= rcu_bh_torture_deferred_free
,
303 * Definitions for srcu torture testing.
306 static struct srcu_struct srcu_ctl
;
307 static struct list_head srcu_removed
;
309 static void srcu_torture_init(void)
311 init_srcu_struct(&srcu_ctl
);
312 INIT_LIST_HEAD(&srcu_removed
);
315 static void srcu_torture_cleanup(void)
317 synchronize_srcu(&srcu_ctl
);
318 cleanup_srcu_struct(&srcu_ctl
);
321 static int srcu_torture_read_lock(void)
323 return srcu_read_lock(&srcu_ctl
);
326 static void srcu_read_delay(struct rcu_random_state
*rrsp
)
329 const long uspertick
= 1000000 / HZ
;
330 const long longdelay
= 10;
332 /* We want there to be long-running readers, but not all the time. */
334 delay
= rcu_random(rrsp
) % (nrealreaders
* 2 * longdelay
* uspertick
);
336 schedule_timeout_interruptible(longdelay
);
339 static void srcu_torture_read_unlock(int idx
)
341 srcu_read_unlock(&srcu_ctl
, idx
);
344 static int srcu_torture_completed(void)
346 return srcu_batches_completed(&srcu_ctl
);
349 static void srcu_torture_deferred_free(struct rcu_torture
*p
)
352 struct rcu_torture
*rp
;
353 struct rcu_torture
*rp1
;
355 synchronize_srcu(&srcu_ctl
);
356 list_add(&p
->rtort_free
, &srcu_removed
);
357 list_for_each_entry_safe(rp
, rp1
, &srcu_removed
, rtort_free
) {
358 i
= rp
->rtort_pipe_count
;
359 if (i
> RCU_TORTURE_PIPE_LEN
)
360 i
= RCU_TORTURE_PIPE_LEN
;
361 atomic_inc(&rcu_torture_wcount
[i
]);
362 if (++rp
->rtort_pipe_count
>= RCU_TORTURE_PIPE_LEN
) {
363 rp
->rtort_mbtest
= 0;
364 list_del(&rp
->rtort_free
);
365 rcu_torture_free(rp
);
370 static int srcu_torture_stats(char *page
)
374 int idx
= srcu_ctl
.completed
& 0x1;
376 cnt
+= sprintf(&page
[cnt
], "%s%s per-CPU(idx=%d):",
377 torture_type
, TORTURE_FLAG
, idx
);
378 for_each_possible_cpu(cpu
) {
379 cnt
+= sprintf(&page
[cnt
], " %d(%d,%d)", cpu
,
380 per_cpu_ptr(srcu_ctl
.per_cpu_ref
, cpu
)->c
[!idx
],
381 per_cpu_ptr(srcu_ctl
.per_cpu_ref
, cpu
)->c
[idx
]);
383 cnt
+= sprintf(&page
[cnt
], "\n");
387 static struct rcu_torture_ops srcu_ops
= {
388 .init
= srcu_torture_init
,
389 .cleanup
= srcu_torture_cleanup
,
390 .readlock
= srcu_torture_read_lock
,
391 .readdelay
= srcu_read_delay
,
392 .readunlock
= srcu_torture_read_unlock
,
393 .completed
= srcu_torture_completed
,
394 .deferredfree
= srcu_torture_deferred_free
,
395 .stats
= srcu_torture_stats
,
399 static struct rcu_torture_ops
*torture_ops
[] =
400 { &rcu_ops
, &rcu_bh_ops
, &srcu_ops
, NULL
};
403 * RCU torture writer kthread. Repeatedly substitutes a new structure
404 * for that pointed to by rcu_torture_current, freeing the old structure
405 * after a series of grace periods (the "pipeline").
408 rcu_torture_writer(void *arg
)
411 long oldbatch
= rcu_batches_completed();
412 struct rcu_torture
*rp
;
413 struct rcu_torture
*old_rp
;
414 static DEFINE_RCU_RANDOM(rand
);
416 VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
417 set_user_nice(current
, 19);
420 schedule_timeout_uninterruptible(1);
421 if ((rp
= rcu_torture_alloc()) == NULL
)
423 rp
->rtort_pipe_count
= 0;
424 udelay(rcu_random(&rand
) & 0x3ff);
425 old_rp
= rcu_torture_current
;
426 rp
->rtort_mbtest
= 1;
427 rcu_assign_pointer(rcu_torture_current
, rp
);
429 if (old_rp
!= NULL
) {
430 i
= old_rp
->rtort_pipe_count
;
431 if (i
> RCU_TORTURE_PIPE_LEN
)
432 i
= RCU_TORTURE_PIPE_LEN
;
433 atomic_inc(&rcu_torture_wcount
[i
]);
434 old_rp
->rtort_pipe_count
++;
435 cur_ops
->deferredfree(old_rp
);
437 rcu_torture_current_version
++;
438 oldbatch
= cur_ops
->completed();
439 } while (!kthread_should_stop() && !fullstop
);
440 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
441 while (!kthread_should_stop())
442 schedule_timeout_uninterruptible(1);
447 * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
448 * incrementing the corresponding element of the pipeline array. The
449 * counter in the element should never be greater than 1, otherwise, the
450 * RCU implementation is broken.
453 rcu_torture_reader(void *arg
)
457 DEFINE_RCU_RANDOM(rand
);
458 struct rcu_torture
*p
;
461 VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
462 set_user_nice(current
, 19);
465 idx
= cur_ops
->readlock();
466 completed
= cur_ops
->completed();
467 p
= rcu_dereference(rcu_torture_current
);
469 /* Wait for rcu_torture_writer to get underway */
470 cur_ops
->readunlock(idx
);
471 schedule_timeout_interruptible(HZ
);
474 if (p
->rtort_mbtest
== 0)
475 atomic_inc(&n_rcu_torture_mberror
);
476 cur_ops
->readdelay(&rand
);
478 pipe_count
= p
->rtort_pipe_count
;
479 if (pipe_count
> RCU_TORTURE_PIPE_LEN
) {
480 /* Should not happen, but... */
481 pipe_count
= RCU_TORTURE_PIPE_LEN
;
483 ++__get_cpu_var(rcu_torture_count
)[pipe_count
];
484 completed
= cur_ops
->completed() - completed
;
485 if (completed
> RCU_TORTURE_PIPE_LEN
) {
486 /* Should not happen, but... */
487 completed
= RCU_TORTURE_PIPE_LEN
;
489 ++__get_cpu_var(rcu_torture_batch
)[completed
];
491 cur_ops
->readunlock(idx
);
493 } while (!kthread_should_stop() && !fullstop
);
494 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
495 while (!kthread_should_stop())
496 schedule_timeout_uninterruptible(1);
501 * Create an RCU-torture statistics message in the specified buffer.
504 rcu_torture_printk(char *page
)
509 long pipesummary
[RCU_TORTURE_PIPE_LEN
+ 1] = { 0 };
510 long batchsummary
[RCU_TORTURE_PIPE_LEN
+ 1] = { 0 };
512 for_each_possible_cpu(cpu
) {
513 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
514 pipesummary
[i
] += per_cpu(rcu_torture_count
, cpu
)[i
];
515 batchsummary
[i
] += per_cpu(rcu_torture_batch
, cpu
)[i
];
518 for (i
= RCU_TORTURE_PIPE_LEN
- 1; i
>= 0; i
--) {
519 if (pipesummary
[i
] != 0)
522 cnt
+= sprintf(&page
[cnt
], "%s%s ", torture_type
, TORTURE_FLAG
);
523 cnt
+= sprintf(&page
[cnt
],
524 "rtc: %p ver: %ld tfle: %d rta: %d rtaf: %d rtf: %d "
527 rcu_torture_current_version
,
528 list_empty(&rcu_torture_freelist
),
529 atomic_read(&n_rcu_torture_alloc
),
530 atomic_read(&n_rcu_torture_alloc_fail
),
531 atomic_read(&n_rcu_torture_free
),
532 atomic_read(&n_rcu_torture_mberror
));
533 if (atomic_read(&n_rcu_torture_mberror
) != 0)
534 cnt
+= sprintf(&page
[cnt
], " !!!");
535 cnt
+= sprintf(&page
[cnt
], "\n%s%s ", torture_type
, TORTURE_FLAG
);
537 cnt
+= sprintf(&page
[cnt
], "!!! ");
538 atomic_inc(&n_rcu_torture_error
);
540 cnt
+= sprintf(&page
[cnt
], "Reader Pipe: ");
541 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
542 cnt
+= sprintf(&page
[cnt
], " %ld", pipesummary
[i
]);
543 cnt
+= sprintf(&page
[cnt
], "\n%s%s ", torture_type
, TORTURE_FLAG
);
544 cnt
+= sprintf(&page
[cnt
], "Reader Batch: ");
545 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
546 cnt
+= sprintf(&page
[cnt
], " %ld", batchsummary
[i
]);
547 cnt
+= sprintf(&page
[cnt
], "\n%s%s ", torture_type
, TORTURE_FLAG
);
548 cnt
+= sprintf(&page
[cnt
], "Free-Block Circulation: ");
549 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
550 cnt
+= sprintf(&page
[cnt
], " %d",
551 atomic_read(&rcu_torture_wcount
[i
]));
553 cnt
+= sprintf(&page
[cnt
], "\n");
554 if (cur_ops
->stats
!= NULL
)
555 cnt
+= cur_ops
->stats(&page
[cnt
]);
560 * Print torture statistics. Caller must ensure that there is only
561 * one call to this function at a given time!!! This is normally
562 * accomplished by relying on the module system to only have one copy
563 * of the module loaded, and then by giving the rcu_torture_stats
564 * kthread full control (or the init/cleanup functions when rcu_torture_stats
565 * thread is not running).
568 rcu_torture_stats_print(void)
572 cnt
= rcu_torture_printk(printk_buf
);
573 printk(KERN_ALERT
"%s", printk_buf
);
577 * Periodically prints torture statistics, if periodic statistics printing
578 * was specified via the stat_interval module parameter.
580 * No need to worry about fullstop here, since this one doesn't reference
581 * volatile state or register callbacks.
584 rcu_torture_stats(void *arg
)
586 VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
588 schedule_timeout_interruptible(stat_interval
* HZ
);
589 rcu_torture_stats_print();
590 } while (!kthread_should_stop());
591 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
595 static int rcu_idle_cpu
; /* Force all torture tasks off this CPU */
597 /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
598 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
600 static void rcu_torture_shuffle_tasks(void)
602 cpumask_t tmp_mask
= CPU_MASK_ALL
;
607 /* No point in shuffling if there is only one online CPU (ex: UP) */
608 if (num_online_cpus() == 1) {
609 unlock_cpu_hotplug();
613 if (rcu_idle_cpu
!= -1)
614 cpu_clear(rcu_idle_cpu
, tmp_mask
);
616 set_cpus_allowed(current
, tmp_mask
);
618 if (reader_tasks
!= NULL
) {
619 for (i
= 0; i
< nrealreaders
; i
++)
621 set_cpus_allowed(reader_tasks
[i
], tmp_mask
);
625 set_cpus_allowed(writer_task
, tmp_mask
);
628 set_cpus_allowed(stats_task
, tmp_mask
);
630 if (rcu_idle_cpu
== -1)
631 rcu_idle_cpu
= num_online_cpus() - 1;
635 unlock_cpu_hotplug();
638 /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
639 * system to become idle at a time and cut off its timer ticks. This is meant
640 * to test the support for such tickless idle CPU in RCU.
643 rcu_torture_shuffle(void *arg
)
645 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
647 schedule_timeout_interruptible(shuffle_interval
* HZ
);
648 rcu_torture_shuffle_tasks();
649 } while (!kthread_should_stop());
650 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
655 rcu_torture_print_module_parms(char *tag
)
657 printk(KERN_ALERT
"%s" TORTURE_FLAG
"--- %s: nreaders=%d "
658 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
659 "shuffle_interval = %d\n",
660 torture_type
, tag
, nrealreaders
, stat_interval
, verbose
,
661 test_no_idle_hz
, shuffle_interval
);
665 rcu_torture_cleanup(void)
670 if (shuffler_task
!= NULL
) {
671 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
672 kthread_stop(shuffler_task
);
674 shuffler_task
= NULL
;
676 if (writer_task
!= NULL
) {
677 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
678 kthread_stop(writer_task
);
682 if (reader_tasks
!= NULL
) {
683 for (i
= 0; i
< nrealreaders
; i
++) {
684 if (reader_tasks
[i
] != NULL
) {
685 VERBOSE_PRINTK_STRING(
686 "Stopping rcu_torture_reader task");
687 kthread_stop(reader_tasks
[i
]);
689 reader_tasks
[i
] = NULL
;
694 rcu_torture_current
= NULL
;
696 if (stats_task
!= NULL
) {
697 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
698 kthread_stop(stats_task
);
702 /* Wait for all RCU callbacks to fire. */
705 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
707 if (cur_ops
->cleanup
!= NULL
)
709 if (atomic_read(&n_rcu_torture_error
))
710 rcu_torture_print_module_parms("End of test: FAILURE");
712 rcu_torture_print_module_parms("End of test: SUCCESS");
716 rcu_torture_init(void)
722 /* Process args and tell the world that the torturer is on the job. */
724 for (i
= 0; cur_ops
= torture_ops
[i
], cur_ops
!= NULL
; i
++) {
725 cur_ops
= torture_ops
[i
];
726 if (strcmp(torture_type
, cur_ops
->name
) == 0) {
730 if (cur_ops
== NULL
) {
731 printk(KERN_ALERT
"rcutorture: invalid torture type: \"%s\"\n",
735 if (cur_ops
->init
!= NULL
)
736 cur_ops
->init(); /* no "goto unwind" prior to this point!!! */
739 nrealreaders
= nreaders
;
741 nrealreaders
= 2 * num_online_cpus();
742 rcu_torture_print_module_parms("Start of test");
745 /* Set up the freelist. */
747 INIT_LIST_HEAD(&rcu_torture_freelist
);
748 for (i
= 0; i
< sizeof(rcu_tortures
) / sizeof(rcu_tortures
[0]); i
++) {
749 rcu_tortures
[i
].rtort_mbtest
= 0;
750 list_add_tail(&rcu_tortures
[i
].rtort_free
,
751 &rcu_torture_freelist
);
754 /* Initialize the statistics so that each run gets its own numbers. */
756 rcu_torture_current
= NULL
;
757 rcu_torture_current_version
= 0;
758 atomic_set(&n_rcu_torture_alloc
, 0);
759 atomic_set(&n_rcu_torture_alloc_fail
, 0);
760 atomic_set(&n_rcu_torture_free
, 0);
761 atomic_set(&n_rcu_torture_mberror
, 0);
762 atomic_set(&n_rcu_torture_error
, 0);
763 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++)
764 atomic_set(&rcu_torture_wcount
[i
], 0);
765 for_each_possible_cpu(cpu
) {
766 for (i
= 0; i
< RCU_TORTURE_PIPE_LEN
+ 1; i
++) {
767 per_cpu(rcu_torture_count
, cpu
)[i
] = 0;
768 per_cpu(rcu_torture_batch
, cpu
)[i
] = 0;
772 /* Start up the kthreads. */
774 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
775 writer_task
= kthread_run(rcu_torture_writer
, NULL
,
776 "rcu_torture_writer");
777 if (IS_ERR(writer_task
)) {
778 firsterr
= PTR_ERR(writer_task
);
779 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
783 reader_tasks
= kzalloc(nrealreaders
* sizeof(reader_tasks
[0]),
785 if (reader_tasks
== NULL
) {
786 VERBOSE_PRINTK_ERRSTRING("out of memory");
790 for (i
= 0; i
< nrealreaders
; i
++) {
791 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
792 reader_tasks
[i
] = kthread_run(rcu_torture_reader
, NULL
,
793 "rcu_torture_reader");
794 if (IS_ERR(reader_tasks
[i
])) {
795 firsterr
= PTR_ERR(reader_tasks
[i
]);
796 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
797 reader_tasks
[i
] = NULL
;
801 if (stat_interval
> 0) {
802 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
803 stats_task
= kthread_run(rcu_torture_stats
, NULL
,
804 "rcu_torture_stats");
805 if (IS_ERR(stats_task
)) {
806 firsterr
= PTR_ERR(stats_task
);
807 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
812 if (test_no_idle_hz
) {
813 rcu_idle_cpu
= num_online_cpus() - 1;
814 /* Create the shuffler thread */
815 shuffler_task
= kthread_run(rcu_torture_shuffle
, NULL
,
816 "rcu_torture_shuffle");
817 if (IS_ERR(shuffler_task
)) {
818 firsterr
= PTR_ERR(shuffler_task
);
819 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
820 shuffler_task
= NULL
;
827 rcu_torture_cleanup();
831 module_init(rcu_torture_init
);
832 module_exit(rcu_torture_cleanup
);