Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1 | /* |
Paul E. McKenney | 29766f1 | 2006-06-27 02:54:02 -0700 | [diff] [blame] | 2 | * Read-Copy Update module-based torture test facility |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 3 | * |
| 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 Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 18 | * Copyright (C) IBM Corporation, 2005, 2006 |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 19 | * |
| 20 | * Authors: Paul E. McKenney <paulmck@us.ibm.com> |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 21 | * Josh Triplett <josh@freedesktop.org> |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 22 | * |
| 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. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 38 | #include <linux/completion.h> |
| 39 | #include <linux/moduleparam.h> |
| 40 | #include <linux/percpu.h> |
| 41 | #include <linux/notifier.h> |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 42 | #include <linux/reboot.h> |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 43 | #include <linux/freezer.h> |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 44 | #include <linux/cpu.h> |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 45 | #include <linux/delay.h> |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 46 | #include <linux/stat.h> |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 47 | #include <linux/srcu.h> |
Robert P. J. Day | 1aeb272 | 2008-04-29 00:59:25 -0700 | [diff] [blame] | 48 | #include <linux/slab.h> |
Harvey Harrison | f07767f | 2008-10-20 10:23:38 -0700 | [diff] [blame] | 49 | #include <asm/byteorder.h> |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 50 | |
| 51 | MODULE_LICENSE("GPL"); |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 52 | MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and " |
| 53 | "Josh Triplett <josh@freedesktop.org>"); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 54 | |
Josh Triplett | 4802211 | 2006-10-03 23:26:16 +0200 | [diff] [blame] | 55 | static int nreaders = -1; /* # reader threads, defaults to 2*ncpus */ |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 56 | static int nfakewriters = 4; /* # fake writer threads */ |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 57 | static int stat_interval; /* Interval between stats, in seconds. */ |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 58 | /* Defaults to "only at end of test". */ |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 59 | static int verbose; /* Print more debug info. */ |
| 60 | static int test_no_idle_hz; /* Test RCU's support for tickless idle CPUs. */ |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 61 | static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/ |
| 62 | static int stutter = 5; /* Start/stop testing interval (in sec) */ |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 63 | static int irqreader = 1; /* RCU readers from irq (timers). */ |
Josh Triplett | 20d2e42 | 2006-10-04 02:17:15 -0700 | [diff] [blame] | 64 | static char *torture_type = "rcu"; /* What RCU implementation to torture. */ |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 65 | |
Josh Triplett | d6ad671 | 2007-03-06 01:42:13 -0800 | [diff] [blame] | 66 | module_param(nreaders, int, 0444); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 67 | MODULE_PARM_DESC(nreaders, "Number of RCU reader threads"); |
Josh Triplett | d6ad671 | 2007-03-06 01:42:13 -0800 | [diff] [blame] | 68 | module_param(nfakewriters, int, 0444); |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 69 | MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads"); |
Josh Triplett | d6ad671 | 2007-03-06 01:42:13 -0800 | [diff] [blame] | 70 | module_param(stat_interval, int, 0444); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 71 | MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s"); |
Josh Triplett | d6ad671 | 2007-03-06 01:42:13 -0800 | [diff] [blame] | 72 | module_param(verbose, bool, 0444); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 73 | MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s"); |
Josh Triplett | d6ad671 | 2007-03-06 01:42:13 -0800 | [diff] [blame] | 74 | module_param(test_no_idle_hz, bool, 0444); |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 75 | MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs"); |
Josh Triplett | d6ad671 | 2007-03-06 01:42:13 -0800 | [diff] [blame] | 76 | module_param(shuffle_interval, int, 0444); |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 77 | MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles"); |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 78 | module_param(stutter, int, 0444); |
| 79 | MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test"); |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 80 | module_param(irqreader, int, 0444); |
| 81 | MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers"); |
Josh Triplett | d6ad671 | 2007-03-06 01:42:13 -0800 | [diff] [blame] | 82 | module_param(torture_type, charp, 0444); |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 83 | MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)"); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 84 | |
| 85 | #define TORTURE_FLAG "-torture:" |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 86 | #define PRINTK_STRING(s) \ |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 87 | do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0) |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 88 | #define VERBOSE_PRINTK_STRING(s) \ |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 89 | do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0) |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 90 | #define VERBOSE_PRINTK_ERRSTRING(s) \ |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 91 | do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0) |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 92 | |
| 93 | static char printk_buf[4096]; |
| 94 | |
| 95 | static int nrealreaders; |
| 96 | static struct task_struct *writer_task; |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 97 | static struct task_struct **fakewriter_tasks; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 98 | static struct task_struct **reader_tasks; |
| 99 | static struct task_struct *stats_task; |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 100 | static struct task_struct *shuffler_task; |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 101 | static struct task_struct *stutter_task; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 102 | |
| 103 | #define RCU_TORTURE_PIPE_LEN 10 |
| 104 | |
| 105 | struct rcu_torture { |
| 106 | struct rcu_head rtort_rcu; |
| 107 | int rtort_pipe_count; |
| 108 | struct list_head rtort_free; |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 109 | int rtort_mbtest; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 112 | static LIST_HEAD(rcu_torture_freelist); |
| 113 | static struct rcu_torture *rcu_torture_current = NULL; |
| 114 | static long rcu_torture_current_version = 0; |
| 115 | static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN]; |
| 116 | static DEFINE_SPINLOCK(rcu_torture_lock); |
| 117 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) = |
| 118 | { 0 }; |
| 119 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) = |
| 120 | { 0 }; |
| 121 | static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1]; |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 122 | static atomic_t n_rcu_torture_alloc; |
| 123 | static atomic_t n_rcu_torture_alloc_fail; |
| 124 | static atomic_t n_rcu_torture_free; |
| 125 | static atomic_t n_rcu_torture_mberror; |
| 126 | static atomic_t n_rcu_torture_error; |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 127 | static long n_rcu_torture_timers = 0; |
Josh Triplett | e303373 | 2006-10-04 02:17:14 -0700 | [diff] [blame] | 128 | static struct list_head rcu_torture_removed; |
Rusty Russell | 73d0a4b | 2009-03-30 22:05:16 -0600 | [diff] [blame] | 129 | static cpumask_var_t shuffle_tmp_mask; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 130 | |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 131 | static int stutter_pause_test = 0; |
| 132 | |
Paul E. McKenney | 31a72bc | 2008-06-18 09:26:49 -0700 | [diff] [blame] | 133 | #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE) |
| 134 | #define RCUTORTURE_RUNNABLE_INIT 1 |
| 135 | #else |
| 136 | #define RCUTORTURE_RUNNABLE_INIT 0 |
| 137 | #endif |
| 138 | int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT; |
| 139 | |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 140 | /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */ |
| 141 | |
| 142 | #define FULLSTOP_DONTSTOP 0 /* Normal operation. */ |
| 143 | #define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */ |
| 144 | #define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */ |
| 145 | static int fullstop = FULLSTOP_RMMOD; |
| 146 | DEFINE_MUTEX(fullstop_mutex); /* Protect fullstop transitions and spawning */ |
| 147 | /* of kthreads. */ |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 148 | |
| 149 | /* |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 150 | * Detect and respond to a system shutdown. |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 151 | */ |
| 152 | static int |
| 153 | rcutorture_shutdown_notify(struct notifier_block *unused1, |
| 154 | unsigned long unused2, void *unused3) |
| 155 | { |
Paul E. McKenney | c59ab97 | 2009-01-04 18:28:27 -0800 | [diff] [blame] | 156 | mutex_lock(&fullstop_mutex); |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 157 | if (fullstop == FULLSTOP_DONTSTOP) |
Paul E. McKenney | c59ab97 | 2009-01-04 18:28:27 -0800 | [diff] [blame] | 158 | fullstop = FULLSTOP_SHUTDOWN; |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 159 | else |
| 160 | printk(KERN_WARNING /* but going down anyway, so... */ |
| 161 | "Concurrent 'rmmod rcutorture' and shutdown illegal!\n"); |
Paul E. McKenney | c59ab97 | 2009-01-04 18:28:27 -0800 | [diff] [blame] | 162 | mutex_unlock(&fullstop_mutex); |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 163 | return NOTIFY_DONE; |
| 164 | } |
| 165 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 166 | /* |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 167 | * Absorb kthreads into a kernel function that won't return, so that |
| 168 | * they won't ever access module text or data again. |
| 169 | */ |
| 170 | static void rcutorture_shutdown_absorb(char *title) |
| 171 | { |
| 172 | if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) { |
| 173 | printk(KERN_NOTICE |
| 174 | "rcutorture thread %s parking due to system shutdown\n", |
| 175 | title); |
| 176 | schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | /* |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 181 | * Allocate an element from the rcu_tortures pool. |
| 182 | */ |
Adrian Bunk | 97a41e2 | 2006-01-08 01:02:17 -0800 | [diff] [blame] | 183 | static struct rcu_torture * |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 184 | rcu_torture_alloc(void) |
| 185 | { |
| 186 | struct list_head *p; |
| 187 | |
Ingo Molnar | adac166 | 2006-01-25 19:50:12 +0100 | [diff] [blame] | 188 | spin_lock_bh(&rcu_torture_lock); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 189 | if (list_empty(&rcu_torture_freelist)) { |
| 190 | atomic_inc(&n_rcu_torture_alloc_fail); |
Ingo Molnar | adac166 | 2006-01-25 19:50:12 +0100 | [diff] [blame] | 191 | spin_unlock_bh(&rcu_torture_lock); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 192 | return NULL; |
| 193 | } |
| 194 | atomic_inc(&n_rcu_torture_alloc); |
| 195 | p = rcu_torture_freelist.next; |
| 196 | list_del_init(p); |
Ingo Molnar | adac166 | 2006-01-25 19:50:12 +0100 | [diff] [blame] | 197 | spin_unlock_bh(&rcu_torture_lock); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 198 | return container_of(p, struct rcu_torture, rtort_free); |
| 199 | } |
| 200 | |
| 201 | /* |
| 202 | * Free an element to the rcu_tortures pool. |
| 203 | */ |
| 204 | static void |
| 205 | rcu_torture_free(struct rcu_torture *p) |
| 206 | { |
| 207 | atomic_inc(&n_rcu_torture_free); |
Ingo Molnar | adac166 | 2006-01-25 19:50:12 +0100 | [diff] [blame] | 208 | spin_lock_bh(&rcu_torture_lock); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 209 | list_add_tail(&p->rtort_free, &rcu_torture_freelist); |
Ingo Molnar | adac166 | 2006-01-25 19:50:12 +0100 | [diff] [blame] | 210 | spin_unlock_bh(&rcu_torture_lock); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 211 | } |
| 212 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 213 | struct rcu_random_state { |
| 214 | unsigned long rrs_state; |
Josh Triplett | 75cfef3 | 2006-10-04 02:17:12 -0700 | [diff] [blame] | 215 | long rrs_count; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 216 | }; |
| 217 | |
| 218 | #define RCU_RANDOM_MULT 39916801 /* prime */ |
| 219 | #define RCU_RANDOM_ADD 479001701 /* prime */ |
| 220 | #define RCU_RANDOM_REFRESH 10000 |
| 221 | |
| 222 | #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 } |
| 223 | |
| 224 | /* |
| 225 | * Crude but fast random-number generator. Uses a linear congruential |
Paul E. McKenney | c17ac85 | 2007-10-16 23:27:19 -0700 | [diff] [blame] | 226 | * generator, with occasional help from cpu_clock(). |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 227 | */ |
Josh Triplett | 75cfef3 | 2006-10-04 02:17:12 -0700 | [diff] [blame] | 228 | static unsigned long |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 229 | rcu_random(struct rcu_random_state *rrsp) |
| 230 | { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 231 | if (--rrsp->rrs_count < 0) { |
Paul E. McKenney | c17ac85 | 2007-10-16 23:27:19 -0700 | [diff] [blame] | 232 | rrsp->rrs_state += |
| 233 | (unsigned long)cpu_clock(raw_smp_processor_id()); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 234 | rrsp->rrs_count = RCU_RANDOM_REFRESH; |
| 235 | } |
| 236 | rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD; |
| 237 | return swahw32(rrsp->rrs_state); |
| 238 | } |
| 239 | |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 240 | static void |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 241 | rcu_stutter_wait(char *title) |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 242 | { |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 243 | while (stutter_pause_test || !rcutorture_runnable) { |
Paul E. McKenney | e3d7be2 | 2008-06-22 13:06:38 -0700 | [diff] [blame] | 244 | if (rcutorture_runnable) |
| 245 | schedule_timeout_interruptible(1); |
| 246 | else |
Paul E. McKenney | 3ccf79f | 2008-06-22 14:02:55 -0700 | [diff] [blame] | 247 | schedule_timeout_interruptible(round_jiffies_relative(HZ)); |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 248 | rcutorture_shutdown_absorb(title); |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 249 | } |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 252 | /* |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 253 | * Operations vector for selecting different types of tests. |
| 254 | */ |
| 255 | |
| 256 | struct rcu_torture_ops { |
| 257 | void (*init)(void); |
| 258 | void (*cleanup)(void); |
| 259 | int (*readlock)(void); |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 260 | void (*readdelay)(struct rcu_random_state *rrsp); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 261 | void (*readunlock)(int idx); |
| 262 | int (*completed)(void); |
| 263 | void (*deferredfree)(struct rcu_torture *p); |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 264 | void (*sync)(void); |
Paul E. McKenney | 2326974 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 265 | void (*cb_barrier)(void); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 266 | int (*stats)(char *page); |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 267 | int irqcapable; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 268 | char *name; |
| 269 | }; |
| 270 | static struct rcu_torture_ops *cur_ops = NULL; |
| 271 | |
| 272 | /* |
| 273 | * Definitions for rcu torture testing. |
| 274 | */ |
| 275 | |
Josh Triplett | a49a4af | 2006-09-29 01:59:30 -0700 | [diff] [blame] | 276 | static int rcu_torture_read_lock(void) __acquires(RCU) |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 277 | { |
| 278 | rcu_read_lock(); |
| 279 | return 0; |
| 280 | } |
| 281 | |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 282 | static void rcu_read_delay(struct rcu_random_state *rrsp) |
| 283 | { |
| 284 | long delay; |
| 285 | const long longdelay = 200; |
| 286 | |
| 287 | /* We want there to be long-running readers, but not all the time. */ |
| 288 | |
| 289 | delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay); |
| 290 | if (!delay) |
| 291 | udelay(longdelay); |
| 292 | } |
| 293 | |
Josh Triplett | a49a4af | 2006-09-29 01:59:30 -0700 | [diff] [blame] | 294 | static void rcu_torture_read_unlock(int idx) __releases(RCU) |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 295 | { |
| 296 | rcu_read_unlock(); |
| 297 | } |
| 298 | |
| 299 | static int rcu_torture_completed(void) |
| 300 | { |
| 301 | return rcu_batches_completed(); |
| 302 | } |
| 303 | |
| 304 | static void |
| 305 | rcu_torture_cb(struct rcu_head *p) |
| 306 | { |
| 307 | int i; |
| 308 | struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu); |
| 309 | |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 310 | if (fullstop != FULLSTOP_DONTSTOP) { |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 311 | /* Test is ending, just drop callbacks on the floor. */ |
| 312 | /* The next initialization will pick up the pieces. */ |
| 313 | return; |
| 314 | } |
| 315 | i = rp->rtort_pipe_count; |
| 316 | if (i > RCU_TORTURE_PIPE_LEN) |
| 317 | i = RCU_TORTURE_PIPE_LEN; |
| 318 | atomic_inc(&rcu_torture_wcount[i]); |
| 319 | if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) { |
| 320 | rp->rtort_mbtest = 0; |
| 321 | rcu_torture_free(rp); |
| 322 | } else |
| 323 | cur_ops->deferredfree(rp); |
| 324 | } |
| 325 | |
| 326 | static void rcu_torture_deferred_free(struct rcu_torture *p) |
| 327 | { |
| 328 | call_rcu(&p->rtort_rcu, rcu_torture_cb); |
| 329 | } |
| 330 | |
| 331 | static struct rcu_torture_ops rcu_ops = { |
| 332 | .init = NULL, |
| 333 | .cleanup = NULL, |
| 334 | .readlock = rcu_torture_read_lock, |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 335 | .readdelay = rcu_read_delay, |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 336 | .readunlock = rcu_torture_read_unlock, |
| 337 | .completed = rcu_torture_completed, |
| 338 | .deferredfree = rcu_torture_deferred_free, |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 339 | .sync = synchronize_rcu, |
Paul E. McKenney | 2326974 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 340 | .cb_barrier = rcu_barrier, |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 341 | .stats = NULL, |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 342 | .irqcapable = 1, |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 343 | .name = "rcu" |
| 344 | }; |
| 345 | |
Josh Triplett | e303373 | 2006-10-04 02:17:14 -0700 | [diff] [blame] | 346 | static void rcu_sync_torture_deferred_free(struct rcu_torture *p) |
| 347 | { |
| 348 | int i; |
| 349 | struct rcu_torture *rp; |
| 350 | struct rcu_torture *rp1; |
| 351 | |
| 352 | cur_ops->sync(); |
| 353 | list_add(&p->rtort_free, &rcu_torture_removed); |
| 354 | list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) { |
| 355 | i = rp->rtort_pipe_count; |
| 356 | if (i > RCU_TORTURE_PIPE_LEN) |
| 357 | i = RCU_TORTURE_PIPE_LEN; |
| 358 | atomic_inc(&rcu_torture_wcount[i]); |
| 359 | if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) { |
| 360 | rp->rtort_mbtest = 0; |
| 361 | list_del(&rp->rtort_free); |
| 362 | rcu_torture_free(rp); |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | static void rcu_sync_torture_init(void) |
| 368 | { |
| 369 | INIT_LIST_HEAD(&rcu_torture_removed); |
| 370 | } |
| 371 | |
Josh Triplett | 20d2e42 | 2006-10-04 02:17:15 -0700 | [diff] [blame] | 372 | static struct rcu_torture_ops rcu_sync_ops = { |
| 373 | .init = rcu_sync_torture_init, |
| 374 | .cleanup = NULL, |
| 375 | .readlock = rcu_torture_read_lock, |
| 376 | .readdelay = rcu_read_delay, |
| 377 | .readunlock = rcu_torture_read_unlock, |
| 378 | .completed = rcu_torture_completed, |
| 379 | .deferredfree = rcu_sync_torture_deferred_free, |
| 380 | .sync = synchronize_rcu, |
Paul E. McKenney | 2326974 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 381 | .cb_barrier = NULL, |
Josh Triplett | 20d2e42 | 2006-10-04 02:17:15 -0700 | [diff] [blame] | 382 | .stats = NULL, |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 383 | .irqcapable = 1, |
Josh Triplett | 20d2e42 | 2006-10-04 02:17:15 -0700 | [diff] [blame] | 384 | .name = "rcu_sync" |
| 385 | }; |
| 386 | |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 387 | /* |
| 388 | * Definitions for rcu_bh torture testing. |
| 389 | */ |
| 390 | |
Josh Triplett | a49a4af | 2006-09-29 01:59:30 -0700 | [diff] [blame] | 391 | static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH) |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 392 | { |
| 393 | rcu_read_lock_bh(); |
| 394 | return 0; |
| 395 | } |
| 396 | |
Josh Triplett | a49a4af | 2006-09-29 01:59:30 -0700 | [diff] [blame] | 397 | static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH) |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 398 | { |
| 399 | rcu_read_unlock_bh(); |
| 400 | } |
| 401 | |
| 402 | static int rcu_bh_torture_completed(void) |
| 403 | { |
| 404 | return rcu_batches_completed_bh(); |
| 405 | } |
| 406 | |
| 407 | static void rcu_bh_torture_deferred_free(struct rcu_torture *p) |
| 408 | { |
| 409 | call_rcu_bh(&p->rtort_rcu, rcu_torture_cb); |
| 410 | } |
| 411 | |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 412 | struct rcu_bh_torture_synchronize { |
| 413 | struct rcu_head head; |
| 414 | struct completion completion; |
| 415 | }; |
| 416 | |
| 417 | static void rcu_bh_torture_wakeme_after_cb(struct rcu_head *head) |
| 418 | { |
| 419 | struct rcu_bh_torture_synchronize *rcu; |
| 420 | |
| 421 | rcu = container_of(head, struct rcu_bh_torture_synchronize, head); |
| 422 | complete(&rcu->completion); |
| 423 | } |
| 424 | |
| 425 | static void rcu_bh_torture_synchronize(void) |
| 426 | { |
| 427 | struct rcu_bh_torture_synchronize rcu; |
| 428 | |
| 429 | init_completion(&rcu.completion); |
| 430 | call_rcu_bh(&rcu.head, rcu_bh_torture_wakeme_after_cb); |
| 431 | wait_for_completion(&rcu.completion); |
| 432 | } |
| 433 | |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 434 | static struct rcu_torture_ops rcu_bh_ops = { |
| 435 | .init = NULL, |
| 436 | .cleanup = NULL, |
| 437 | .readlock = rcu_bh_torture_read_lock, |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 438 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 439 | .readunlock = rcu_bh_torture_read_unlock, |
| 440 | .completed = rcu_bh_torture_completed, |
| 441 | .deferredfree = rcu_bh_torture_deferred_free, |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 442 | .sync = rcu_bh_torture_synchronize, |
Paul E. McKenney | 2326974 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 443 | .cb_barrier = rcu_barrier_bh, |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 444 | .stats = NULL, |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 445 | .irqcapable = 1, |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 446 | .name = "rcu_bh" |
| 447 | }; |
| 448 | |
Josh Triplett | 11a1470 | 2006-10-04 02:17:16 -0700 | [diff] [blame] | 449 | static struct rcu_torture_ops rcu_bh_sync_ops = { |
| 450 | .init = rcu_sync_torture_init, |
| 451 | .cleanup = NULL, |
| 452 | .readlock = rcu_bh_torture_read_lock, |
| 453 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ |
| 454 | .readunlock = rcu_bh_torture_read_unlock, |
| 455 | .completed = rcu_bh_torture_completed, |
| 456 | .deferredfree = rcu_sync_torture_deferred_free, |
| 457 | .sync = rcu_bh_torture_synchronize, |
Paul E. McKenney | 2326974 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 458 | .cb_barrier = NULL, |
Josh Triplett | 11a1470 | 2006-10-04 02:17:16 -0700 | [diff] [blame] | 459 | .stats = NULL, |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 460 | .irqcapable = 1, |
Josh Triplett | 11a1470 | 2006-10-04 02:17:16 -0700 | [diff] [blame] | 461 | .name = "rcu_bh_sync" |
| 462 | }; |
| 463 | |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 464 | /* |
| 465 | * Definitions for srcu torture testing. |
| 466 | */ |
| 467 | |
| 468 | static struct srcu_struct srcu_ctl; |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 469 | |
| 470 | static void srcu_torture_init(void) |
| 471 | { |
| 472 | init_srcu_struct(&srcu_ctl); |
Josh Triplett | e303373 | 2006-10-04 02:17:14 -0700 | [diff] [blame] | 473 | rcu_sync_torture_init(); |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | static void srcu_torture_cleanup(void) |
| 477 | { |
| 478 | synchronize_srcu(&srcu_ctl); |
| 479 | cleanup_srcu_struct(&srcu_ctl); |
| 480 | } |
| 481 | |
Josh Triplett | 012d3ca | 2006-12-06 20:40:19 -0800 | [diff] [blame] | 482 | static int srcu_torture_read_lock(void) __acquires(&srcu_ctl) |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 483 | { |
| 484 | return srcu_read_lock(&srcu_ctl); |
| 485 | } |
| 486 | |
| 487 | static void srcu_read_delay(struct rcu_random_state *rrsp) |
| 488 | { |
| 489 | long delay; |
| 490 | const long uspertick = 1000000 / HZ; |
| 491 | const long longdelay = 10; |
| 492 | |
| 493 | /* We want there to be long-running readers, but not all the time. */ |
| 494 | |
| 495 | delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick); |
| 496 | if (!delay) |
| 497 | schedule_timeout_interruptible(longdelay); |
| 498 | } |
| 499 | |
Josh Triplett | 012d3ca | 2006-12-06 20:40:19 -0800 | [diff] [blame] | 500 | static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl) |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 501 | { |
| 502 | srcu_read_unlock(&srcu_ctl, idx); |
| 503 | } |
| 504 | |
| 505 | static int srcu_torture_completed(void) |
| 506 | { |
| 507 | return srcu_batches_completed(&srcu_ctl); |
| 508 | } |
| 509 | |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 510 | static void srcu_torture_synchronize(void) |
| 511 | { |
| 512 | synchronize_srcu(&srcu_ctl); |
| 513 | } |
| 514 | |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 515 | static int srcu_torture_stats(char *page) |
| 516 | { |
| 517 | int cnt = 0; |
| 518 | int cpu; |
| 519 | int idx = srcu_ctl.completed & 0x1; |
| 520 | |
| 521 | cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):", |
| 522 | torture_type, TORTURE_FLAG, idx); |
| 523 | for_each_possible_cpu(cpu) { |
| 524 | cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu, |
| 525 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx], |
| 526 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]); |
| 527 | } |
| 528 | cnt += sprintf(&page[cnt], "\n"); |
| 529 | return cnt; |
| 530 | } |
| 531 | |
| 532 | static struct rcu_torture_ops srcu_ops = { |
| 533 | .init = srcu_torture_init, |
| 534 | .cleanup = srcu_torture_cleanup, |
| 535 | .readlock = srcu_torture_read_lock, |
| 536 | .readdelay = srcu_read_delay, |
| 537 | .readunlock = srcu_torture_read_unlock, |
| 538 | .completed = srcu_torture_completed, |
Josh Triplett | e303373 | 2006-10-04 02:17:14 -0700 | [diff] [blame] | 539 | .deferredfree = rcu_sync_torture_deferred_free, |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 540 | .sync = srcu_torture_synchronize, |
Paul E. McKenney | 2326974 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 541 | .cb_barrier = NULL, |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 542 | .stats = srcu_torture_stats, |
| 543 | .name = "srcu" |
| 544 | }; |
| 545 | |
Josh Triplett | 4b6c2cc | 2006-10-04 02:17:16 -0700 | [diff] [blame] | 546 | /* |
| 547 | * Definitions for sched torture testing. |
| 548 | */ |
| 549 | |
| 550 | static int sched_torture_read_lock(void) |
| 551 | { |
| 552 | preempt_disable(); |
| 553 | return 0; |
| 554 | } |
| 555 | |
| 556 | static void sched_torture_read_unlock(int idx) |
| 557 | { |
| 558 | preempt_enable(); |
| 559 | } |
| 560 | |
| 561 | static int sched_torture_completed(void) |
| 562 | { |
| 563 | return 0; |
| 564 | } |
| 565 | |
Paul E. McKenney | 2326974 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 566 | static void rcu_sched_torture_deferred_free(struct rcu_torture *p) |
| 567 | { |
| 568 | call_rcu_sched(&p->rtort_rcu, rcu_torture_cb); |
| 569 | } |
| 570 | |
Josh Triplett | 4b6c2cc | 2006-10-04 02:17:16 -0700 | [diff] [blame] | 571 | static void sched_torture_synchronize(void) |
| 572 | { |
| 573 | synchronize_sched(); |
| 574 | } |
| 575 | |
| 576 | static struct rcu_torture_ops sched_ops = { |
| 577 | .init = rcu_sync_torture_init, |
| 578 | .cleanup = NULL, |
| 579 | .readlock = sched_torture_read_lock, |
| 580 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ |
| 581 | .readunlock = sched_torture_read_unlock, |
| 582 | .completed = sched_torture_completed, |
Paul E. McKenney | 2326974 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 583 | .deferredfree = rcu_sched_torture_deferred_free, |
Josh Triplett | 4b6c2cc | 2006-10-04 02:17:16 -0700 | [diff] [blame] | 584 | .sync = sched_torture_synchronize, |
Paul E. McKenney | 2326974 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 585 | .cb_barrier = rcu_barrier_sched, |
Josh Triplett | 4b6c2cc | 2006-10-04 02:17:16 -0700 | [diff] [blame] | 586 | .stats = NULL, |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 587 | .irqcapable = 1, |
Josh Triplett | 4b6c2cc | 2006-10-04 02:17:16 -0700 | [diff] [blame] | 588 | .name = "sched" |
| 589 | }; |
| 590 | |
Paul E. McKenney | 2326974 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 591 | static struct rcu_torture_ops sched_ops_sync = { |
| 592 | .init = rcu_sync_torture_init, |
| 593 | .cleanup = NULL, |
| 594 | .readlock = sched_torture_read_lock, |
| 595 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ |
| 596 | .readunlock = sched_torture_read_unlock, |
| 597 | .completed = sched_torture_completed, |
| 598 | .deferredfree = rcu_sync_torture_deferred_free, |
| 599 | .sync = sched_torture_synchronize, |
| 600 | .cb_barrier = NULL, |
| 601 | .stats = NULL, |
| 602 | .name = "sched_sync" |
| 603 | }; |
| 604 | |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 605 | /* |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 606 | * RCU torture writer kthread. Repeatedly substitutes a new structure |
| 607 | * for that pointed to by rcu_torture_current, freeing the old structure |
| 608 | * after a series of grace periods (the "pipeline"). |
| 609 | */ |
| 610 | static int |
| 611 | rcu_torture_writer(void *arg) |
| 612 | { |
| 613 | int i; |
| 614 | long oldbatch = rcu_batches_completed(); |
| 615 | struct rcu_torture *rp; |
| 616 | struct rcu_torture *old_rp; |
| 617 | static DEFINE_RCU_RANDOM(rand); |
| 618 | |
| 619 | VERBOSE_PRINTK_STRING("rcu_torture_writer task started"); |
Ingo Molnar | dbdf65b | 2005-11-13 16:07:22 -0800 | [diff] [blame] | 620 | set_user_nice(current, 19); |
| 621 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 622 | do { |
| 623 | schedule_timeout_uninterruptible(1); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 624 | if ((rp = rcu_torture_alloc()) == NULL) |
| 625 | continue; |
| 626 | rp->rtort_pipe_count = 0; |
| 627 | udelay(rcu_random(&rand) & 0x3ff); |
| 628 | old_rp = rcu_torture_current; |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 629 | rp->rtort_mbtest = 1; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 630 | rcu_assign_pointer(rcu_torture_current, rp); |
| 631 | smp_wmb(); |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 632 | if (old_rp) { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 633 | i = old_rp->rtort_pipe_count; |
| 634 | if (i > RCU_TORTURE_PIPE_LEN) |
| 635 | i = RCU_TORTURE_PIPE_LEN; |
| 636 | atomic_inc(&rcu_torture_wcount[i]); |
| 637 | old_rp->rtort_pipe_count++; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 638 | cur_ops->deferredfree(old_rp); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 639 | } |
| 640 | rcu_torture_current_version++; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 641 | oldbatch = cur_ops->completed(); |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 642 | rcu_stutter_wait("rcu_torture_writer"); |
| 643 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 644 | VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping"); |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 645 | rcutorture_shutdown_absorb("rcu_torture_writer"); |
| 646 | while (!kthread_should_stop()) |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 647 | schedule_timeout_uninterruptible(1); |
| 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | /* |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 652 | * RCU torture fake writer kthread. Repeatedly calls sync, with a random |
| 653 | * delay between calls. |
| 654 | */ |
| 655 | static int |
| 656 | rcu_torture_fakewriter(void *arg) |
| 657 | { |
| 658 | DEFINE_RCU_RANDOM(rand); |
| 659 | |
| 660 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started"); |
| 661 | set_user_nice(current, 19); |
| 662 | |
| 663 | do { |
| 664 | schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10); |
| 665 | udelay(rcu_random(&rand) & 0x3ff); |
| 666 | cur_ops->sync(); |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 667 | rcu_stutter_wait("rcu_torture_fakewriter"); |
| 668 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 669 | |
| 670 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping"); |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 671 | rcutorture_shutdown_absorb("rcu_torture_fakewriter"); |
| 672 | while (!kthread_should_stop()) |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 673 | schedule_timeout_uninterruptible(1); |
| 674 | return 0; |
| 675 | } |
| 676 | |
| 677 | /* |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 678 | * RCU torture reader from timer handler. Dereferences rcu_torture_current, |
| 679 | * incrementing the corresponding element of the pipeline array. The |
| 680 | * counter in the element should never be greater than 1, otherwise, the |
| 681 | * RCU implementation is broken. |
| 682 | */ |
| 683 | static void rcu_torture_timer(unsigned long unused) |
| 684 | { |
| 685 | int idx; |
| 686 | int completed; |
| 687 | static DEFINE_RCU_RANDOM(rand); |
| 688 | static DEFINE_SPINLOCK(rand_lock); |
| 689 | struct rcu_torture *p; |
| 690 | int pipe_count; |
| 691 | |
| 692 | idx = cur_ops->readlock(); |
| 693 | completed = cur_ops->completed(); |
| 694 | p = rcu_dereference(rcu_torture_current); |
| 695 | if (p == NULL) { |
| 696 | /* Leave because rcu_torture_writer is not yet underway */ |
| 697 | cur_ops->readunlock(idx); |
| 698 | return; |
| 699 | } |
| 700 | if (p->rtort_mbtest == 0) |
| 701 | atomic_inc(&n_rcu_torture_mberror); |
| 702 | spin_lock(&rand_lock); |
| 703 | cur_ops->readdelay(&rand); |
| 704 | n_rcu_torture_timers++; |
| 705 | spin_unlock(&rand_lock); |
| 706 | preempt_disable(); |
| 707 | pipe_count = p->rtort_pipe_count; |
| 708 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { |
| 709 | /* Should not happen, but... */ |
| 710 | pipe_count = RCU_TORTURE_PIPE_LEN; |
| 711 | } |
| 712 | ++__get_cpu_var(rcu_torture_count)[pipe_count]; |
| 713 | completed = cur_ops->completed() - completed; |
| 714 | if (completed > RCU_TORTURE_PIPE_LEN) { |
| 715 | /* Should not happen, but... */ |
| 716 | completed = RCU_TORTURE_PIPE_LEN; |
| 717 | } |
| 718 | ++__get_cpu_var(rcu_torture_batch)[completed]; |
| 719 | preempt_enable(); |
| 720 | cur_ops->readunlock(idx); |
| 721 | } |
| 722 | |
| 723 | /* |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 724 | * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current, |
| 725 | * incrementing the corresponding element of the pipeline array. The |
| 726 | * counter in the element should never be greater than 1, otherwise, the |
| 727 | * RCU implementation is broken. |
| 728 | */ |
| 729 | static int |
| 730 | rcu_torture_reader(void *arg) |
| 731 | { |
| 732 | int completed; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 733 | int idx; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 734 | DEFINE_RCU_RANDOM(rand); |
| 735 | struct rcu_torture *p; |
| 736 | int pipe_count; |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 737 | struct timer_list t; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 738 | |
| 739 | VERBOSE_PRINTK_STRING("rcu_torture_reader task started"); |
Ingo Molnar | dbdf65b | 2005-11-13 16:07:22 -0800 | [diff] [blame] | 740 | set_user_nice(current, 19); |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 741 | if (irqreader && cur_ops->irqcapable) |
| 742 | setup_timer_on_stack(&t, rcu_torture_timer, 0); |
Ingo Molnar | dbdf65b | 2005-11-13 16:07:22 -0800 | [diff] [blame] | 743 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 744 | do { |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 745 | if (irqreader && cur_ops->irqcapable) { |
| 746 | if (!timer_pending(&t)) |
| 747 | mod_timer(&t, 1); |
| 748 | } |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 749 | idx = cur_ops->readlock(); |
| 750 | completed = cur_ops->completed(); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 751 | p = rcu_dereference(rcu_torture_current); |
| 752 | if (p == NULL) { |
| 753 | /* Wait for rcu_torture_writer to get underway */ |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 754 | cur_ops->readunlock(idx); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 755 | schedule_timeout_interruptible(HZ); |
| 756 | continue; |
| 757 | } |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 758 | if (p->rtort_mbtest == 0) |
| 759 | atomic_inc(&n_rcu_torture_mberror); |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 760 | cur_ops->readdelay(&rand); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 761 | preempt_disable(); |
| 762 | pipe_count = p->rtort_pipe_count; |
| 763 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { |
| 764 | /* Should not happen, but... */ |
| 765 | pipe_count = RCU_TORTURE_PIPE_LEN; |
| 766 | } |
| 767 | ++__get_cpu_var(rcu_torture_count)[pipe_count]; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 768 | completed = cur_ops->completed() - completed; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 769 | if (completed > RCU_TORTURE_PIPE_LEN) { |
| 770 | /* Should not happen, but... */ |
| 771 | completed = RCU_TORTURE_PIPE_LEN; |
| 772 | } |
| 773 | ++__get_cpu_var(rcu_torture_batch)[completed]; |
| 774 | preempt_enable(); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 775 | cur_ops->readunlock(idx); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 776 | schedule(); |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 777 | rcu_stutter_wait("rcu_torture_reader"); |
| 778 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 779 | VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping"); |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 780 | rcutorture_shutdown_absorb("rcu_torture_reader"); |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 781 | if (irqreader && cur_ops->irqcapable) |
| 782 | del_timer_sync(&t); |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 783 | while (!kthread_should_stop()) |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 784 | schedule_timeout_uninterruptible(1); |
| 785 | return 0; |
| 786 | } |
| 787 | |
| 788 | /* |
| 789 | * Create an RCU-torture statistics message in the specified buffer. |
| 790 | */ |
| 791 | static int |
| 792 | rcu_torture_printk(char *page) |
| 793 | { |
| 794 | int cnt = 0; |
| 795 | int cpu; |
| 796 | int i; |
| 797 | long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; |
| 798 | long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; |
| 799 | |
KAMEZAWA Hiroyuki | 0a94502 | 2006-03-28 01:56:37 -0800 | [diff] [blame] | 800 | for_each_possible_cpu(cpu) { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 801 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
| 802 | pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i]; |
| 803 | batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i]; |
| 804 | } |
| 805 | } |
| 806 | for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) { |
| 807 | if (pipesummary[i] != 0) |
| 808 | break; |
| 809 | } |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 810 | cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 811 | cnt += sprintf(&page[cnt], |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 812 | "rtc: %p ver: %ld tfle: %d rta: %d rtaf: %d rtf: %d " |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 813 | "rtmbe: %d nt: %ld", |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 814 | rcu_torture_current, |
| 815 | rcu_torture_current_version, |
| 816 | list_empty(&rcu_torture_freelist), |
| 817 | atomic_read(&n_rcu_torture_alloc), |
| 818 | atomic_read(&n_rcu_torture_alloc_fail), |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 819 | atomic_read(&n_rcu_torture_free), |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 820 | atomic_read(&n_rcu_torture_mberror), |
| 821 | n_rcu_torture_timers); |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 822 | if (atomic_read(&n_rcu_torture_mberror) != 0) |
| 823 | cnt += sprintf(&page[cnt], " !!!"); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 824 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 825 | if (i > 1) { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 826 | cnt += sprintf(&page[cnt], "!!! "); |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 827 | atomic_inc(&n_rcu_torture_error); |
Ingo Molnar | 5af970a | 2008-06-18 10:09:48 +0200 | [diff] [blame] | 828 | WARN_ON_ONCE(1); |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 829 | } |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 830 | cnt += sprintf(&page[cnt], "Reader Pipe: "); |
| 831 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
| 832 | cnt += sprintf(&page[cnt], " %ld", pipesummary[i]); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 833 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 834 | cnt += sprintf(&page[cnt], "Reader Batch: "); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 835 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 836 | cnt += sprintf(&page[cnt], " %ld", batchsummary[i]); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 837 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 838 | cnt += sprintf(&page[cnt], "Free-Block Circulation: "); |
| 839 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
| 840 | cnt += sprintf(&page[cnt], " %d", |
| 841 | atomic_read(&rcu_torture_wcount[i])); |
| 842 | } |
| 843 | cnt += sprintf(&page[cnt], "\n"); |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 844 | if (cur_ops->stats) |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 845 | cnt += cur_ops->stats(&page[cnt]); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 846 | return cnt; |
| 847 | } |
| 848 | |
| 849 | /* |
| 850 | * Print torture statistics. Caller must ensure that there is only |
| 851 | * one call to this function at a given time!!! This is normally |
| 852 | * accomplished by relying on the module system to only have one copy |
| 853 | * of the module loaded, and then by giving the rcu_torture_stats |
| 854 | * kthread full control (or the init/cleanup functions when rcu_torture_stats |
| 855 | * thread is not running). |
| 856 | */ |
| 857 | static void |
| 858 | rcu_torture_stats_print(void) |
| 859 | { |
| 860 | int cnt; |
| 861 | |
| 862 | cnt = rcu_torture_printk(printk_buf); |
| 863 | printk(KERN_ALERT "%s", printk_buf); |
| 864 | } |
| 865 | |
| 866 | /* |
| 867 | * Periodically prints torture statistics, if periodic statistics printing |
| 868 | * was specified via the stat_interval module parameter. |
| 869 | * |
| 870 | * No need to worry about fullstop here, since this one doesn't reference |
| 871 | * volatile state or register callbacks. |
| 872 | */ |
| 873 | static int |
| 874 | rcu_torture_stats(void *arg) |
| 875 | { |
| 876 | VERBOSE_PRINTK_STRING("rcu_torture_stats task started"); |
| 877 | do { |
| 878 | schedule_timeout_interruptible(stat_interval * HZ); |
| 879 | rcu_torture_stats_print(); |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 880 | rcutorture_shutdown_absorb("rcu_torture_stats"); |
| 881 | } while (!kthread_should_stop()); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 882 | VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping"); |
| 883 | return 0; |
| 884 | } |
| 885 | |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 886 | static int rcu_idle_cpu; /* Force all torture tasks off this CPU */ |
| 887 | |
| 888 | /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case |
| 889 | * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs. |
| 890 | */ |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 891 | static void rcu_torture_shuffle_tasks(void) |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 892 | { |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 893 | int i; |
| 894 | |
Rusty Russell | 73d0a4b | 2009-03-30 22:05:16 -0600 | [diff] [blame] | 895 | cpumask_setall(shuffle_tmp_mask); |
Gautham R Shenoy | 86ef5c9 | 2008-01-25 21:08:02 +0100 | [diff] [blame] | 896 | get_online_cpus(); |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 897 | |
| 898 | /* No point in shuffling if there is only one online CPU (ex: UP) */ |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 899 | if (num_online_cpus() == 1) { |
| 900 | put_online_cpus(); |
| 901 | return; |
| 902 | } |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 903 | |
| 904 | if (rcu_idle_cpu != -1) |
Rusty Russell | 73d0a4b | 2009-03-30 22:05:16 -0600 | [diff] [blame] | 905 | cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask); |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 906 | |
Rusty Russell | 73d0a4b | 2009-03-30 22:05:16 -0600 | [diff] [blame] | 907 | set_cpus_allowed_ptr(current, shuffle_tmp_mask); |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 908 | |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 909 | if (reader_tasks) { |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 910 | for (i = 0; i < nrealreaders; i++) |
| 911 | if (reader_tasks[i]) |
Mike Travis | f70316d | 2008-04-04 18:11:06 -0700 | [diff] [blame] | 912 | set_cpus_allowed_ptr(reader_tasks[i], |
Rusty Russell | 73d0a4b | 2009-03-30 22:05:16 -0600 | [diff] [blame] | 913 | shuffle_tmp_mask); |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 914 | } |
| 915 | |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 916 | if (fakewriter_tasks) { |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 917 | for (i = 0; i < nfakewriters; i++) |
| 918 | if (fakewriter_tasks[i]) |
Mike Travis | f70316d | 2008-04-04 18:11:06 -0700 | [diff] [blame] | 919 | set_cpus_allowed_ptr(fakewriter_tasks[i], |
Rusty Russell | 73d0a4b | 2009-03-30 22:05:16 -0600 | [diff] [blame] | 920 | shuffle_tmp_mask); |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 923 | if (writer_task) |
Rusty Russell | 73d0a4b | 2009-03-30 22:05:16 -0600 | [diff] [blame] | 924 | set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask); |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 925 | |
| 926 | if (stats_task) |
Rusty Russell | 73d0a4b | 2009-03-30 22:05:16 -0600 | [diff] [blame] | 927 | set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask); |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 928 | |
| 929 | if (rcu_idle_cpu == -1) |
| 930 | rcu_idle_cpu = num_online_cpus() - 1; |
| 931 | else |
| 932 | rcu_idle_cpu--; |
| 933 | |
Gautham R Shenoy | 86ef5c9 | 2008-01-25 21:08:02 +0100 | [diff] [blame] | 934 | put_online_cpus(); |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the |
| 938 | * system to become idle at a time and cut off its timer ticks. This is meant |
| 939 | * to test the support for such tickless idle CPU in RCU. |
| 940 | */ |
| 941 | static int |
| 942 | rcu_torture_shuffle(void *arg) |
| 943 | { |
| 944 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started"); |
| 945 | do { |
| 946 | schedule_timeout_interruptible(shuffle_interval * HZ); |
| 947 | rcu_torture_shuffle_tasks(); |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 948 | rcutorture_shutdown_absorb("rcu_torture_shuffle"); |
| 949 | } while (!kthread_should_stop()); |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 950 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping"); |
| 951 | return 0; |
| 952 | } |
| 953 | |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 954 | /* Cause the rcutorture test to "stutter", starting and stopping all |
| 955 | * threads periodically. |
| 956 | */ |
| 957 | static int |
| 958 | rcu_torture_stutter(void *arg) |
| 959 | { |
| 960 | VERBOSE_PRINTK_STRING("rcu_torture_stutter task started"); |
| 961 | do { |
| 962 | schedule_timeout_interruptible(stutter * HZ); |
| 963 | stutter_pause_test = 1; |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 964 | if (!kthread_should_stop()) |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 965 | schedule_timeout_interruptible(stutter * HZ); |
| 966 | stutter_pause_test = 0; |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 967 | rcutorture_shutdown_absorb("rcu_torture_stutter"); |
| 968 | } while (!kthread_should_stop()); |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 969 | VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping"); |
| 970 | return 0; |
| 971 | } |
| 972 | |
Paul E. McKenney | 95c3832 | 2006-03-24 03:15:58 -0800 | [diff] [blame] | 973 | static inline void |
| 974 | rcu_torture_print_module_parms(char *tag) |
| 975 | { |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 976 | printk(KERN_ALERT "%s" TORTURE_FLAG |
| 977 | "--- %s: nreaders=%d nfakewriters=%d " |
Paul E. McKenney | 95c3832 | 2006-03-24 03:15:58 -0800 | [diff] [blame] | 978 | "stat_interval=%d verbose=%d test_no_idle_hz=%d " |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 979 | "shuffle_interval=%d stutter=%d irqreader=%d\n", |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 980 | torture_type, tag, nrealreaders, nfakewriters, |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 981 | stat_interval, verbose, test_no_idle_hz, shuffle_interval, |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 982 | stutter, irqreader); |
Paul E. McKenney | 95c3832 | 2006-03-24 03:15:58 -0800 | [diff] [blame] | 983 | } |
| 984 | |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 985 | static struct notifier_block rcutorture_nb = { |
| 986 | .notifier_call = rcutorture_shutdown_notify, |
| 987 | }; |
| 988 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 989 | static void |
| 990 | rcu_torture_cleanup(void) |
| 991 | { |
| 992 | int i; |
| 993 | |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 994 | mutex_lock(&fullstop_mutex); |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 995 | if (fullstop == FULLSTOP_SHUTDOWN) { |
| 996 | printk(KERN_WARNING /* but going down anyway, so... */ |
| 997 | "Concurrent 'rmmod rcutorture' and shutdown illegal!\n"); |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 998 | mutex_unlock(&fullstop_mutex); |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 999 | schedule_timeout_uninterruptible(10); |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 1000 | if (cur_ops->cb_barrier != NULL) |
| 1001 | cur_ops->cb_barrier(); |
| 1002 | return; |
| 1003 | } |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 1004 | fullstop = FULLSTOP_RMMOD; |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 1005 | mutex_unlock(&fullstop_mutex); |
| 1006 | unregister_reboot_notifier(&rcutorture_nb); |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 1007 | if (stutter_task) { |
| 1008 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task"); |
| 1009 | kthread_stop(stutter_task); |
| 1010 | } |
| 1011 | stutter_task = NULL; |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 1012 | if (shuffler_task) { |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 1013 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task"); |
| 1014 | kthread_stop(shuffler_task); |
Rusty Russell | 73d0a4b | 2009-03-30 22:05:16 -0600 | [diff] [blame] | 1015 | free_cpumask_var(shuffle_tmp_mask); |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 1016 | } |
| 1017 | shuffler_task = NULL; |
| 1018 | |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 1019 | if (writer_task) { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1020 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task"); |
| 1021 | kthread_stop(writer_task); |
| 1022 | } |
| 1023 | writer_task = NULL; |
| 1024 | |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 1025 | if (reader_tasks) { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1026 | for (i = 0; i < nrealreaders; i++) { |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 1027 | if (reader_tasks[i]) { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1028 | VERBOSE_PRINTK_STRING( |
| 1029 | "Stopping rcu_torture_reader task"); |
| 1030 | kthread_stop(reader_tasks[i]); |
| 1031 | } |
| 1032 | reader_tasks[i] = NULL; |
| 1033 | } |
| 1034 | kfree(reader_tasks); |
| 1035 | reader_tasks = NULL; |
| 1036 | } |
| 1037 | rcu_torture_current = NULL; |
| 1038 | |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 1039 | if (fakewriter_tasks) { |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 1040 | for (i = 0; i < nfakewriters; i++) { |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 1041 | if (fakewriter_tasks[i]) { |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 1042 | VERBOSE_PRINTK_STRING( |
| 1043 | "Stopping rcu_torture_fakewriter task"); |
| 1044 | kthread_stop(fakewriter_tasks[i]); |
| 1045 | } |
| 1046 | fakewriter_tasks[i] = NULL; |
| 1047 | } |
| 1048 | kfree(fakewriter_tasks); |
| 1049 | fakewriter_tasks = NULL; |
| 1050 | } |
| 1051 | |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 1052 | if (stats_task) { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1053 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task"); |
| 1054 | kthread_stop(stats_task); |
| 1055 | } |
| 1056 | stats_task = NULL; |
| 1057 | |
| 1058 | /* Wait for all RCU callbacks to fire. */ |
Paul E. McKenney | 2326974 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 1059 | |
| 1060 | if (cur_ops->cb_barrier != NULL) |
| 1061 | cur_ops->cb_barrier(); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1062 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1063 | rcu_torture_stats_print(); /* -After- the stats thread is stopped! */ |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 1064 | |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 1065 | if (cur_ops->cleanup) |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 1066 | cur_ops->cleanup(); |
Paul E. McKenney | 95c3832 | 2006-03-24 03:15:58 -0800 | [diff] [blame] | 1067 | if (atomic_read(&n_rcu_torture_error)) |
| 1068 | rcu_torture_print_module_parms("End of test: FAILURE"); |
| 1069 | else |
| 1070 | rcu_torture_print_module_parms("End of test: SUCCESS"); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1071 | } |
| 1072 | |
Josh Triplett | 6f8bc500 | 2007-05-08 00:25:24 -0700 | [diff] [blame] | 1073 | static int __init |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1074 | rcu_torture_init(void) |
| 1075 | { |
| 1076 | int i; |
| 1077 | int cpu; |
| 1078 | int firsterr = 0; |
Josh Triplett | ade5fb8 | 2007-05-08 00:33:22 -0700 | [diff] [blame] | 1079 | static struct rcu_torture_ops *torture_ops[] = |
| 1080 | { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops, |
Paul E. McKenney | 2326974 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 1081 | &srcu_ops, &sched_ops, &sched_ops_sync, }; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1082 | |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 1083 | mutex_lock(&fullstop_mutex); |
| 1084 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1085 | /* Process args and tell the world that the torturer is on the job. */ |
Josh Triplett | ade5fb8 | 2007-05-08 00:33:22 -0700 | [diff] [blame] | 1086 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) { |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 1087 | cur_ops = torture_ops[i]; |
Josh Triplett | ade5fb8 | 2007-05-08 00:33:22 -0700 | [diff] [blame] | 1088 | if (strcmp(torture_type, cur_ops->name) == 0) |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 1089 | break; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 1090 | } |
Josh Triplett | ade5fb8 | 2007-05-08 00:33:22 -0700 | [diff] [blame] | 1091 | if (i == ARRAY_SIZE(torture_ops)) { |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 1092 | printk(KERN_ALERT "rcutorture: invalid torture type: \"%s\"\n", |
| 1093 | torture_type); |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 1094 | mutex_unlock(&fullstop_mutex); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 1095 | return (-EINVAL); |
| 1096 | } |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 1097 | if (cur_ops->init) |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 1098 | cur_ops->init(); /* no "goto unwind" prior to this point!!! */ |
| 1099 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1100 | if (nreaders >= 0) |
| 1101 | nrealreaders = nreaders; |
| 1102 | else |
| 1103 | nrealreaders = 2 * num_online_cpus(); |
Paul E. McKenney | 95c3832 | 2006-03-24 03:15:58 -0800 | [diff] [blame] | 1104 | rcu_torture_print_module_parms("Start of test"); |
Paul E. McKenney | c9d557c | 2009-01-07 14:33:30 -0800 | [diff] [blame] | 1105 | fullstop = FULLSTOP_DONTSTOP; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1106 | |
| 1107 | /* Set up the freelist. */ |
| 1108 | |
| 1109 | INIT_LIST_HEAD(&rcu_torture_freelist); |
Ahmed S. Darwish | 788e770 | 2007-05-08 00:33:14 -0700 | [diff] [blame] | 1110 | for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) { |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 1111 | rcu_tortures[i].rtort_mbtest = 0; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1112 | list_add_tail(&rcu_tortures[i].rtort_free, |
| 1113 | &rcu_torture_freelist); |
| 1114 | } |
| 1115 | |
| 1116 | /* Initialize the statistics so that each run gets its own numbers. */ |
| 1117 | |
| 1118 | rcu_torture_current = NULL; |
| 1119 | rcu_torture_current_version = 0; |
| 1120 | atomic_set(&n_rcu_torture_alloc, 0); |
| 1121 | atomic_set(&n_rcu_torture_alloc_fail, 0); |
| 1122 | atomic_set(&n_rcu_torture_free, 0); |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 1123 | atomic_set(&n_rcu_torture_mberror, 0); |
| 1124 | atomic_set(&n_rcu_torture_error, 0); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1125 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
| 1126 | atomic_set(&rcu_torture_wcount[i], 0); |
KAMEZAWA Hiroyuki | 0a94502 | 2006-03-28 01:56:37 -0800 | [diff] [blame] | 1127 | for_each_possible_cpu(cpu) { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1128 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
| 1129 | per_cpu(rcu_torture_count, cpu)[i] = 0; |
| 1130 | per_cpu(rcu_torture_batch, cpu)[i] = 0; |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | /* Start up the kthreads. */ |
| 1135 | |
| 1136 | VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task"); |
| 1137 | writer_task = kthread_run(rcu_torture_writer, NULL, |
| 1138 | "rcu_torture_writer"); |
| 1139 | if (IS_ERR(writer_task)) { |
| 1140 | firsterr = PTR_ERR(writer_task); |
| 1141 | VERBOSE_PRINTK_ERRSTRING("Failed to create writer"); |
| 1142 | writer_task = NULL; |
| 1143 | goto unwind; |
| 1144 | } |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 1145 | fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]), |
| 1146 | GFP_KERNEL); |
| 1147 | if (fakewriter_tasks == NULL) { |
| 1148 | VERBOSE_PRINTK_ERRSTRING("out of memory"); |
| 1149 | firsterr = -ENOMEM; |
| 1150 | goto unwind; |
| 1151 | } |
| 1152 | for (i = 0; i < nfakewriters; i++) { |
| 1153 | VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task"); |
| 1154 | fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL, |
| 1155 | "rcu_torture_fakewriter"); |
| 1156 | if (IS_ERR(fakewriter_tasks[i])) { |
| 1157 | firsterr = PTR_ERR(fakewriter_tasks[i]); |
| 1158 | VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter"); |
| 1159 | fakewriter_tasks[i] = NULL; |
| 1160 | goto unwind; |
| 1161 | } |
| 1162 | } |
Josh Triplett | 2860aab | 2006-10-04 02:17:11 -0700 | [diff] [blame] | 1163 | reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]), |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1164 | GFP_KERNEL); |
| 1165 | if (reader_tasks == NULL) { |
| 1166 | VERBOSE_PRINTK_ERRSTRING("out of memory"); |
| 1167 | firsterr = -ENOMEM; |
| 1168 | goto unwind; |
| 1169 | } |
| 1170 | for (i = 0; i < nrealreaders; i++) { |
| 1171 | VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task"); |
| 1172 | reader_tasks[i] = kthread_run(rcu_torture_reader, NULL, |
| 1173 | "rcu_torture_reader"); |
| 1174 | if (IS_ERR(reader_tasks[i])) { |
| 1175 | firsterr = PTR_ERR(reader_tasks[i]); |
| 1176 | VERBOSE_PRINTK_ERRSTRING("Failed to create reader"); |
| 1177 | reader_tasks[i] = NULL; |
| 1178 | goto unwind; |
| 1179 | } |
| 1180 | } |
| 1181 | if (stat_interval > 0) { |
| 1182 | VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task"); |
| 1183 | stats_task = kthread_run(rcu_torture_stats, NULL, |
| 1184 | "rcu_torture_stats"); |
| 1185 | if (IS_ERR(stats_task)) { |
| 1186 | firsterr = PTR_ERR(stats_task); |
| 1187 | VERBOSE_PRINTK_ERRSTRING("Failed to create stats"); |
| 1188 | stats_task = NULL; |
| 1189 | goto unwind; |
| 1190 | } |
| 1191 | } |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 1192 | if (test_no_idle_hz) { |
| 1193 | rcu_idle_cpu = num_online_cpus() - 1; |
Rusty Russell | 73d0a4b | 2009-03-30 22:05:16 -0600 | [diff] [blame] | 1194 | |
| 1195 | if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) { |
| 1196 | firsterr = -ENOMEM; |
| 1197 | VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask"); |
| 1198 | goto unwind; |
| 1199 | } |
| 1200 | |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 1201 | /* Create the shuffler thread */ |
| 1202 | shuffler_task = kthread_run(rcu_torture_shuffle, NULL, |
| 1203 | "rcu_torture_shuffle"); |
| 1204 | if (IS_ERR(shuffler_task)) { |
Rusty Russell | 73d0a4b | 2009-03-30 22:05:16 -0600 | [diff] [blame] | 1205 | free_cpumask_var(shuffle_tmp_mask); |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 1206 | firsterr = PTR_ERR(shuffler_task); |
| 1207 | VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler"); |
| 1208 | shuffler_task = NULL; |
| 1209 | goto unwind; |
| 1210 | } |
| 1211 | } |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 1212 | if (stutter < 0) |
| 1213 | stutter = 0; |
| 1214 | if (stutter) { |
| 1215 | /* Create the stutter thread */ |
| 1216 | stutter_task = kthread_run(rcu_torture_stutter, NULL, |
| 1217 | "rcu_torture_stutter"); |
| 1218 | if (IS_ERR(stutter_task)) { |
| 1219 | firsterr = PTR_ERR(stutter_task); |
| 1220 | VERBOSE_PRINTK_ERRSTRING("Failed to create stutter"); |
| 1221 | stutter_task = NULL; |
| 1222 | goto unwind; |
| 1223 | } |
| 1224 | } |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 1225 | register_reboot_notifier(&rcutorture_nb); |
| 1226 | mutex_unlock(&fullstop_mutex); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1227 | return 0; |
| 1228 | |
| 1229 | unwind: |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 1230 | mutex_unlock(&fullstop_mutex); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1231 | rcu_torture_cleanup(); |
| 1232 | return firsterr; |
| 1233 | } |
| 1234 | |
| 1235 | module_init(rcu_torture_init); |
| 1236 | module_exit(rcu_torture_cleanup); |