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> |
| 38 | #include <linux/module.h> |
| 39 | #include <linux/completion.h> |
| 40 | #include <linux/moduleparam.h> |
| 41 | #include <linux/percpu.h> |
| 42 | #include <linux/notifier.h> |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 43 | #include <linux/cpu.h> |
| 44 | #include <linux/random.h> |
| 45 | #include <linux/delay.h> |
| 46 | #include <linux/byteorder/swabb.h> |
| 47 | #include <linux/stat.h> |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 48 | #include <linux/srcu.h> |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 49 | |
| 50 | MODULE_LICENSE("GPL"); |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 51 | MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and " |
| 52 | "Josh Triplett <josh@freedesktop.org>"); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 53 | |
Josh Triplett | 4802211 | 2006-10-03 23:26:16 +0200 | [diff] [blame] | 54 | static int nreaders = -1; /* # reader threads, defaults to 2*ncpus */ |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 55 | static int nfakewriters = 4; /* # fake writer threads */ |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 56 | static int stat_interval; /* Interval between stats, in seconds. */ |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 57 | /* Defaults to "only at end of test". */ |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 58 | static int verbose; /* Print more debug info. */ |
| 59 | static int test_no_idle_hz; /* Test RCU's support for tickless idle CPUs. */ |
| 60 | static int shuffle_interval = 5; /* Interval between shuffles (in sec)*/ |
Josh Triplett | 3c29e03 | 2006-10-04 02:17:10 -0700 | [diff] [blame] | 61 | static char *torture_type = "rcu"; /* What to torture: rcu, rcu_bh, srcu. */ |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 62 | |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 63 | module_param(nreaders, int, 0); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 64 | MODULE_PARM_DESC(nreaders, "Number of RCU reader threads"); |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 65 | module_param(nfakewriters, int, 0); |
| 66 | MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads"); |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 67 | module_param(stat_interval, int, 0); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 68 | MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s"); |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 69 | module_param(verbose, bool, 0); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 70 | MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s"); |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 71 | module_param(test_no_idle_hz, bool, 0); |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 72 | MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs"); |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 73 | module_param(shuffle_interval, int, 0); |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 74 | MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles"); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 75 | module_param(torture_type, charp, 0); |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 76 | 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] | 77 | |
| 78 | #define TORTURE_FLAG "-torture:" |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 79 | #define PRINTK_STRING(s) \ |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 80 | 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] | 81 | #define VERBOSE_PRINTK_STRING(s) \ |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 82 | 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] | 83 | #define VERBOSE_PRINTK_ERRSTRING(s) \ |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 84 | 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] | 85 | |
| 86 | static char printk_buf[4096]; |
| 87 | |
| 88 | static int nrealreaders; |
| 89 | static struct task_struct *writer_task; |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 90 | static struct task_struct **fakewriter_tasks; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 91 | static struct task_struct **reader_tasks; |
| 92 | static struct task_struct *stats_task; |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 93 | static struct task_struct *shuffler_task; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 94 | |
| 95 | #define RCU_TORTURE_PIPE_LEN 10 |
| 96 | |
| 97 | struct rcu_torture { |
| 98 | struct rcu_head rtort_rcu; |
| 99 | int rtort_pipe_count; |
| 100 | struct list_head rtort_free; |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 101 | int rtort_mbtest; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | static int fullstop = 0; /* stop generating callbacks at test end. */ |
| 105 | static LIST_HEAD(rcu_torture_freelist); |
| 106 | static struct rcu_torture *rcu_torture_current = NULL; |
| 107 | static long rcu_torture_current_version = 0; |
| 108 | static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN]; |
| 109 | static DEFINE_SPINLOCK(rcu_torture_lock); |
| 110 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) = |
| 111 | { 0 }; |
| 112 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) = |
| 113 | { 0 }; |
| 114 | static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1]; |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 115 | static atomic_t n_rcu_torture_alloc; |
| 116 | static atomic_t n_rcu_torture_alloc_fail; |
| 117 | static atomic_t n_rcu_torture_free; |
| 118 | static atomic_t n_rcu_torture_mberror; |
| 119 | static atomic_t n_rcu_torture_error; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 120 | |
| 121 | /* |
| 122 | * Allocate an element from the rcu_tortures pool. |
| 123 | */ |
Adrian Bunk | 97a41e2 | 2006-01-08 01:02:17 -0800 | [diff] [blame] | 124 | static struct rcu_torture * |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 125 | rcu_torture_alloc(void) |
| 126 | { |
| 127 | struct list_head *p; |
| 128 | |
Ingo Molnar | adac166 | 2006-01-25 19:50:12 +0100 | [diff] [blame] | 129 | spin_lock_bh(&rcu_torture_lock); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 130 | if (list_empty(&rcu_torture_freelist)) { |
| 131 | atomic_inc(&n_rcu_torture_alloc_fail); |
Ingo Molnar | adac166 | 2006-01-25 19:50:12 +0100 | [diff] [blame] | 132 | spin_unlock_bh(&rcu_torture_lock); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 133 | return NULL; |
| 134 | } |
| 135 | atomic_inc(&n_rcu_torture_alloc); |
| 136 | p = rcu_torture_freelist.next; |
| 137 | list_del_init(p); |
Ingo Molnar | adac166 | 2006-01-25 19:50:12 +0100 | [diff] [blame] | 138 | spin_unlock_bh(&rcu_torture_lock); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 139 | return container_of(p, struct rcu_torture, rtort_free); |
| 140 | } |
| 141 | |
| 142 | /* |
| 143 | * Free an element to the rcu_tortures pool. |
| 144 | */ |
| 145 | static void |
| 146 | rcu_torture_free(struct rcu_torture *p) |
| 147 | { |
| 148 | atomic_inc(&n_rcu_torture_free); |
Ingo Molnar | adac166 | 2006-01-25 19:50:12 +0100 | [diff] [blame] | 149 | spin_lock_bh(&rcu_torture_lock); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 150 | list_add_tail(&p->rtort_free, &rcu_torture_freelist); |
Ingo Molnar | adac166 | 2006-01-25 19:50:12 +0100 | [diff] [blame] | 151 | spin_unlock_bh(&rcu_torture_lock); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 154 | struct rcu_random_state { |
| 155 | unsigned long rrs_state; |
Josh Triplett | 75cfef3 | 2006-10-04 02:17:12 -0700 | [diff] [blame] | 156 | long rrs_count; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | #define RCU_RANDOM_MULT 39916801 /* prime */ |
| 160 | #define RCU_RANDOM_ADD 479001701 /* prime */ |
| 161 | #define RCU_RANDOM_REFRESH 10000 |
| 162 | |
| 163 | #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 } |
| 164 | |
| 165 | /* |
| 166 | * Crude but fast random-number generator. Uses a linear congruential |
| 167 | * generator, with occasional help from get_random_bytes(). |
| 168 | */ |
Josh Triplett | 75cfef3 | 2006-10-04 02:17:12 -0700 | [diff] [blame] | 169 | static unsigned long |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 170 | rcu_random(struct rcu_random_state *rrsp) |
| 171 | { |
| 172 | long refresh; |
| 173 | |
| 174 | if (--rrsp->rrs_count < 0) { |
| 175 | get_random_bytes(&refresh, sizeof(refresh)); |
| 176 | rrsp->rrs_state += refresh; |
| 177 | rrsp->rrs_count = RCU_RANDOM_REFRESH; |
| 178 | } |
| 179 | rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD; |
| 180 | return swahw32(rrsp->rrs_state); |
| 181 | } |
| 182 | |
| 183 | /* |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 184 | * Operations vector for selecting different types of tests. |
| 185 | */ |
| 186 | |
| 187 | struct rcu_torture_ops { |
| 188 | void (*init)(void); |
| 189 | void (*cleanup)(void); |
| 190 | int (*readlock)(void); |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 191 | void (*readdelay)(struct rcu_random_state *rrsp); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 192 | void (*readunlock)(int idx); |
| 193 | int (*completed)(void); |
| 194 | void (*deferredfree)(struct rcu_torture *p); |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 195 | void (*sync)(void); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 196 | int (*stats)(char *page); |
| 197 | char *name; |
| 198 | }; |
| 199 | static struct rcu_torture_ops *cur_ops = NULL; |
| 200 | |
| 201 | /* |
| 202 | * Definitions for rcu torture testing. |
| 203 | */ |
| 204 | |
Josh Triplett | a49a4af | 2006-09-29 01:59:30 -0700 | [diff] [blame] | 205 | static int rcu_torture_read_lock(void) __acquires(RCU) |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 206 | { |
| 207 | rcu_read_lock(); |
| 208 | return 0; |
| 209 | } |
| 210 | |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 211 | static void rcu_read_delay(struct rcu_random_state *rrsp) |
| 212 | { |
| 213 | long delay; |
| 214 | const long longdelay = 200; |
| 215 | |
| 216 | /* We want there to be long-running readers, but not all the time. */ |
| 217 | |
| 218 | delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay); |
| 219 | if (!delay) |
| 220 | udelay(longdelay); |
| 221 | } |
| 222 | |
Josh Triplett | a49a4af | 2006-09-29 01:59:30 -0700 | [diff] [blame] | 223 | static void rcu_torture_read_unlock(int idx) __releases(RCU) |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 224 | { |
| 225 | rcu_read_unlock(); |
| 226 | } |
| 227 | |
| 228 | static int rcu_torture_completed(void) |
| 229 | { |
| 230 | return rcu_batches_completed(); |
| 231 | } |
| 232 | |
| 233 | static void |
| 234 | rcu_torture_cb(struct rcu_head *p) |
| 235 | { |
| 236 | int i; |
| 237 | struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu); |
| 238 | |
| 239 | if (fullstop) { |
| 240 | /* Test is ending, just drop callbacks on the floor. */ |
| 241 | /* The next initialization will pick up the pieces. */ |
| 242 | return; |
| 243 | } |
| 244 | i = rp->rtort_pipe_count; |
| 245 | if (i > RCU_TORTURE_PIPE_LEN) |
| 246 | i = RCU_TORTURE_PIPE_LEN; |
| 247 | atomic_inc(&rcu_torture_wcount[i]); |
| 248 | if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) { |
| 249 | rp->rtort_mbtest = 0; |
| 250 | rcu_torture_free(rp); |
| 251 | } else |
| 252 | cur_ops->deferredfree(rp); |
| 253 | } |
| 254 | |
| 255 | static void rcu_torture_deferred_free(struct rcu_torture *p) |
| 256 | { |
| 257 | call_rcu(&p->rtort_rcu, rcu_torture_cb); |
| 258 | } |
| 259 | |
| 260 | static struct rcu_torture_ops rcu_ops = { |
| 261 | .init = NULL, |
| 262 | .cleanup = NULL, |
| 263 | .readlock = rcu_torture_read_lock, |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 264 | .readdelay = rcu_read_delay, |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 265 | .readunlock = rcu_torture_read_unlock, |
| 266 | .completed = rcu_torture_completed, |
| 267 | .deferredfree = rcu_torture_deferred_free, |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 268 | .sync = synchronize_rcu, |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 269 | .stats = NULL, |
| 270 | .name = "rcu" |
| 271 | }; |
| 272 | |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 273 | /* |
| 274 | * Definitions for rcu_bh torture testing. |
| 275 | */ |
| 276 | |
Josh Triplett | a49a4af | 2006-09-29 01:59:30 -0700 | [diff] [blame] | 277 | static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH) |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 278 | { |
| 279 | rcu_read_lock_bh(); |
| 280 | return 0; |
| 281 | } |
| 282 | |
Josh Triplett | a49a4af | 2006-09-29 01:59:30 -0700 | [diff] [blame] | 283 | 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] | 284 | { |
| 285 | rcu_read_unlock_bh(); |
| 286 | } |
| 287 | |
| 288 | static int rcu_bh_torture_completed(void) |
| 289 | { |
| 290 | return rcu_batches_completed_bh(); |
| 291 | } |
| 292 | |
| 293 | static void rcu_bh_torture_deferred_free(struct rcu_torture *p) |
| 294 | { |
| 295 | call_rcu_bh(&p->rtort_rcu, rcu_torture_cb); |
| 296 | } |
| 297 | |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 298 | struct rcu_bh_torture_synchronize { |
| 299 | struct rcu_head head; |
| 300 | struct completion completion; |
| 301 | }; |
| 302 | |
| 303 | static void rcu_bh_torture_wakeme_after_cb(struct rcu_head *head) |
| 304 | { |
| 305 | struct rcu_bh_torture_synchronize *rcu; |
| 306 | |
| 307 | rcu = container_of(head, struct rcu_bh_torture_synchronize, head); |
| 308 | complete(&rcu->completion); |
| 309 | } |
| 310 | |
| 311 | static void rcu_bh_torture_synchronize(void) |
| 312 | { |
| 313 | struct rcu_bh_torture_synchronize rcu; |
| 314 | |
| 315 | init_completion(&rcu.completion); |
| 316 | call_rcu_bh(&rcu.head, rcu_bh_torture_wakeme_after_cb); |
| 317 | wait_for_completion(&rcu.completion); |
| 318 | } |
| 319 | |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 320 | static struct rcu_torture_ops rcu_bh_ops = { |
| 321 | .init = NULL, |
| 322 | .cleanup = NULL, |
| 323 | .readlock = rcu_bh_torture_read_lock, |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 324 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 325 | .readunlock = rcu_bh_torture_read_unlock, |
| 326 | .completed = rcu_bh_torture_completed, |
| 327 | .deferredfree = rcu_bh_torture_deferred_free, |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 328 | .sync = rcu_bh_torture_synchronize, |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 329 | .stats = NULL, |
| 330 | .name = "rcu_bh" |
| 331 | }; |
| 332 | |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 333 | /* |
| 334 | * Definitions for srcu torture testing. |
| 335 | */ |
| 336 | |
| 337 | static struct srcu_struct srcu_ctl; |
| 338 | static struct list_head srcu_removed; |
| 339 | |
| 340 | static void srcu_torture_init(void) |
| 341 | { |
| 342 | init_srcu_struct(&srcu_ctl); |
| 343 | INIT_LIST_HEAD(&srcu_removed); |
| 344 | } |
| 345 | |
| 346 | static void srcu_torture_cleanup(void) |
| 347 | { |
| 348 | synchronize_srcu(&srcu_ctl); |
| 349 | cleanup_srcu_struct(&srcu_ctl); |
| 350 | } |
| 351 | |
| 352 | static int srcu_torture_read_lock(void) |
| 353 | { |
| 354 | return srcu_read_lock(&srcu_ctl); |
| 355 | } |
| 356 | |
| 357 | static void srcu_read_delay(struct rcu_random_state *rrsp) |
| 358 | { |
| 359 | long delay; |
| 360 | const long uspertick = 1000000 / HZ; |
| 361 | const long longdelay = 10; |
| 362 | |
| 363 | /* We want there to be long-running readers, but not all the time. */ |
| 364 | |
| 365 | delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick); |
| 366 | if (!delay) |
| 367 | schedule_timeout_interruptible(longdelay); |
| 368 | } |
| 369 | |
| 370 | static void srcu_torture_read_unlock(int idx) |
| 371 | { |
| 372 | srcu_read_unlock(&srcu_ctl, idx); |
| 373 | } |
| 374 | |
| 375 | static int srcu_torture_completed(void) |
| 376 | { |
| 377 | return srcu_batches_completed(&srcu_ctl); |
| 378 | } |
| 379 | |
| 380 | static void srcu_torture_deferred_free(struct rcu_torture *p) |
| 381 | { |
| 382 | int i; |
| 383 | struct rcu_torture *rp; |
| 384 | struct rcu_torture *rp1; |
| 385 | |
| 386 | synchronize_srcu(&srcu_ctl); |
| 387 | list_add(&p->rtort_free, &srcu_removed); |
| 388 | list_for_each_entry_safe(rp, rp1, &srcu_removed, rtort_free) { |
| 389 | i = rp->rtort_pipe_count; |
| 390 | if (i > RCU_TORTURE_PIPE_LEN) |
| 391 | i = RCU_TORTURE_PIPE_LEN; |
| 392 | atomic_inc(&rcu_torture_wcount[i]); |
| 393 | if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) { |
| 394 | rp->rtort_mbtest = 0; |
| 395 | list_del(&rp->rtort_free); |
| 396 | rcu_torture_free(rp); |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 401 | static void srcu_torture_synchronize(void) |
| 402 | { |
| 403 | synchronize_srcu(&srcu_ctl); |
| 404 | } |
| 405 | |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 406 | static int srcu_torture_stats(char *page) |
| 407 | { |
| 408 | int cnt = 0; |
| 409 | int cpu; |
| 410 | int idx = srcu_ctl.completed & 0x1; |
| 411 | |
| 412 | cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):", |
| 413 | torture_type, TORTURE_FLAG, idx); |
| 414 | for_each_possible_cpu(cpu) { |
| 415 | cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu, |
| 416 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx], |
| 417 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]); |
| 418 | } |
| 419 | cnt += sprintf(&page[cnt], "\n"); |
| 420 | return cnt; |
| 421 | } |
| 422 | |
| 423 | static struct rcu_torture_ops srcu_ops = { |
| 424 | .init = srcu_torture_init, |
| 425 | .cleanup = srcu_torture_cleanup, |
| 426 | .readlock = srcu_torture_read_lock, |
| 427 | .readdelay = srcu_read_delay, |
| 428 | .readunlock = srcu_torture_read_unlock, |
| 429 | .completed = srcu_torture_completed, |
| 430 | .deferredfree = srcu_torture_deferred_free, |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 431 | .sync = srcu_torture_synchronize, |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 432 | .stats = srcu_torture_stats, |
| 433 | .name = "srcu" |
| 434 | }; |
| 435 | |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 436 | static struct rcu_torture_ops *torture_ops[] = |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 437 | { &rcu_ops, &rcu_bh_ops, &srcu_ops, NULL }; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 438 | |
| 439 | /* |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 440 | * RCU torture writer kthread. Repeatedly substitutes a new structure |
| 441 | * for that pointed to by rcu_torture_current, freeing the old structure |
| 442 | * after a series of grace periods (the "pipeline"). |
| 443 | */ |
| 444 | static int |
| 445 | rcu_torture_writer(void *arg) |
| 446 | { |
| 447 | int i; |
| 448 | long oldbatch = rcu_batches_completed(); |
| 449 | struct rcu_torture *rp; |
| 450 | struct rcu_torture *old_rp; |
| 451 | static DEFINE_RCU_RANDOM(rand); |
| 452 | |
| 453 | VERBOSE_PRINTK_STRING("rcu_torture_writer task started"); |
Ingo Molnar | dbdf65b | 2005-11-13 16:07:22 -0800 | [diff] [blame] | 454 | set_user_nice(current, 19); |
| 455 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 456 | do { |
| 457 | schedule_timeout_uninterruptible(1); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 458 | if ((rp = rcu_torture_alloc()) == NULL) |
| 459 | continue; |
| 460 | rp->rtort_pipe_count = 0; |
| 461 | udelay(rcu_random(&rand) & 0x3ff); |
| 462 | old_rp = rcu_torture_current; |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 463 | rp->rtort_mbtest = 1; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 464 | rcu_assign_pointer(rcu_torture_current, rp); |
| 465 | smp_wmb(); |
| 466 | if (old_rp != NULL) { |
| 467 | i = old_rp->rtort_pipe_count; |
| 468 | if (i > RCU_TORTURE_PIPE_LEN) |
| 469 | i = RCU_TORTURE_PIPE_LEN; |
| 470 | atomic_inc(&rcu_torture_wcount[i]); |
| 471 | old_rp->rtort_pipe_count++; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 472 | cur_ops->deferredfree(old_rp); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 473 | } |
| 474 | rcu_torture_current_version++; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 475 | oldbatch = cur_ops->completed(); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 476 | } while (!kthread_should_stop() && !fullstop); |
| 477 | VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping"); |
| 478 | while (!kthread_should_stop()) |
| 479 | schedule_timeout_uninterruptible(1); |
| 480 | return 0; |
| 481 | } |
| 482 | |
| 483 | /* |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 484 | * RCU torture fake writer kthread. Repeatedly calls sync, with a random |
| 485 | * delay between calls. |
| 486 | */ |
| 487 | static int |
| 488 | rcu_torture_fakewriter(void *arg) |
| 489 | { |
| 490 | DEFINE_RCU_RANDOM(rand); |
| 491 | |
| 492 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started"); |
| 493 | set_user_nice(current, 19); |
| 494 | |
| 495 | do { |
| 496 | schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10); |
| 497 | udelay(rcu_random(&rand) & 0x3ff); |
| 498 | cur_ops->sync(); |
| 499 | } while (!kthread_should_stop() && !fullstop); |
| 500 | |
| 501 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping"); |
| 502 | while (!kthread_should_stop()) |
| 503 | schedule_timeout_uninterruptible(1); |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | /* |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 508 | * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current, |
| 509 | * incrementing the corresponding element of the pipeline array. The |
| 510 | * counter in the element should never be greater than 1, otherwise, the |
| 511 | * RCU implementation is broken. |
| 512 | */ |
| 513 | static int |
| 514 | rcu_torture_reader(void *arg) |
| 515 | { |
| 516 | int completed; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 517 | int idx; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 518 | DEFINE_RCU_RANDOM(rand); |
| 519 | struct rcu_torture *p; |
| 520 | int pipe_count; |
| 521 | |
| 522 | VERBOSE_PRINTK_STRING("rcu_torture_reader task started"); |
Ingo Molnar | dbdf65b | 2005-11-13 16:07:22 -0800 | [diff] [blame] | 523 | set_user_nice(current, 19); |
| 524 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 525 | do { |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 526 | idx = cur_ops->readlock(); |
| 527 | completed = cur_ops->completed(); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 528 | p = rcu_dereference(rcu_torture_current); |
| 529 | if (p == NULL) { |
| 530 | /* Wait for rcu_torture_writer to get underway */ |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 531 | cur_ops->readunlock(idx); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 532 | schedule_timeout_interruptible(HZ); |
| 533 | continue; |
| 534 | } |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 535 | if (p->rtort_mbtest == 0) |
| 536 | atomic_inc(&n_rcu_torture_mberror); |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 537 | cur_ops->readdelay(&rand); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 538 | preempt_disable(); |
| 539 | pipe_count = p->rtort_pipe_count; |
| 540 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { |
| 541 | /* Should not happen, but... */ |
| 542 | pipe_count = RCU_TORTURE_PIPE_LEN; |
| 543 | } |
| 544 | ++__get_cpu_var(rcu_torture_count)[pipe_count]; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 545 | completed = cur_ops->completed() - completed; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 546 | if (completed > RCU_TORTURE_PIPE_LEN) { |
| 547 | /* Should not happen, but... */ |
| 548 | completed = RCU_TORTURE_PIPE_LEN; |
| 549 | } |
| 550 | ++__get_cpu_var(rcu_torture_batch)[completed]; |
| 551 | preempt_enable(); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 552 | cur_ops->readunlock(idx); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 553 | schedule(); |
| 554 | } while (!kthread_should_stop() && !fullstop); |
| 555 | VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping"); |
| 556 | while (!kthread_should_stop()) |
| 557 | schedule_timeout_uninterruptible(1); |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | /* |
| 562 | * Create an RCU-torture statistics message in the specified buffer. |
| 563 | */ |
| 564 | static int |
| 565 | rcu_torture_printk(char *page) |
| 566 | { |
| 567 | int cnt = 0; |
| 568 | int cpu; |
| 569 | int i; |
| 570 | long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; |
| 571 | long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; |
| 572 | |
KAMEZAWA Hiroyuki | 0a94502 | 2006-03-28 01:56:37 -0800 | [diff] [blame] | 573 | for_each_possible_cpu(cpu) { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 574 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
| 575 | pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i]; |
| 576 | batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i]; |
| 577 | } |
| 578 | } |
| 579 | for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) { |
| 580 | if (pipesummary[i] != 0) |
| 581 | break; |
| 582 | } |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 583 | cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 584 | cnt += sprintf(&page[cnt], |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 585 | "rtc: %p ver: %ld tfle: %d rta: %d rtaf: %d rtf: %d " |
| 586 | "rtmbe: %d", |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 587 | rcu_torture_current, |
| 588 | rcu_torture_current_version, |
| 589 | list_empty(&rcu_torture_freelist), |
| 590 | atomic_read(&n_rcu_torture_alloc), |
| 591 | atomic_read(&n_rcu_torture_alloc_fail), |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 592 | atomic_read(&n_rcu_torture_free), |
| 593 | atomic_read(&n_rcu_torture_mberror)); |
| 594 | if (atomic_read(&n_rcu_torture_mberror) != 0) |
| 595 | cnt += sprintf(&page[cnt], " !!!"); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 596 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 597 | if (i > 1) { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 598 | cnt += sprintf(&page[cnt], "!!! "); |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 599 | atomic_inc(&n_rcu_torture_error); |
| 600 | } |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 601 | cnt += sprintf(&page[cnt], "Reader Pipe: "); |
| 602 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
| 603 | cnt += sprintf(&page[cnt], " %ld", pipesummary[i]); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 604 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 605 | cnt += sprintf(&page[cnt], "Reader Batch: "); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 606 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 607 | cnt += sprintf(&page[cnt], " %ld", batchsummary[i]); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 608 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 609 | cnt += sprintf(&page[cnt], "Free-Block Circulation: "); |
| 610 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
| 611 | cnt += sprintf(&page[cnt], " %d", |
| 612 | atomic_read(&rcu_torture_wcount[i])); |
| 613 | } |
| 614 | cnt += sprintf(&page[cnt], "\n"); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 615 | if (cur_ops->stats != NULL) |
| 616 | cnt += cur_ops->stats(&page[cnt]); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 617 | return cnt; |
| 618 | } |
| 619 | |
| 620 | /* |
| 621 | * Print torture statistics. Caller must ensure that there is only |
| 622 | * one call to this function at a given time!!! This is normally |
| 623 | * accomplished by relying on the module system to only have one copy |
| 624 | * of the module loaded, and then by giving the rcu_torture_stats |
| 625 | * kthread full control (or the init/cleanup functions when rcu_torture_stats |
| 626 | * thread is not running). |
| 627 | */ |
| 628 | static void |
| 629 | rcu_torture_stats_print(void) |
| 630 | { |
| 631 | int cnt; |
| 632 | |
| 633 | cnt = rcu_torture_printk(printk_buf); |
| 634 | printk(KERN_ALERT "%s", printk_buf); |
| 635 | } |
| 636 | |
| 637 | /* |
| 638 | * Periodically prints torture statistics, if periodic statistics printing |
| 639 | * was specified via the stat_interval module parameter. |
| 640 | * |
| 641 | * No need to worry about fullstop here, since this one doesn't reference |
| 642 | * volatile state or register callbacks. |
| 643 | */ |
| 644 | static int |
| 645 | rcu_torture_stats(void *arg) |
| 646 | { |
| 647 | VERBOSE_PRINTK_STRING("rcu_torture_stats task started"); |
| 648 | do { |
| 649 | schedule_timeout_interruptible(stat_interval * HZ); |
| 650 | rcu_torture_stats_print(); |
| 651 | } while (!kthread_should_stop()); |
| 652 | VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping"); |
| 653 | return 0; |
| 654 | } |
| 655 | |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 656 | static int rcu_idle_cpu; /* Force all torture tasks off this CPU */ |
| 657 | |
| 658 | /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case |
| 659 | * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs. |
| 660 | */ |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 661 | static void rcu_torture_shuffle_tasks(void) |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 662 | { |
| 663 | cpumask_t tmp_mask = CPU_MASK_ALL; |
| 664 | int i; |
| 665 | |
| 666 | lock_cpu_hotplug(); |
| 667 | |
| 668 | /* No point in shuffling if there is only one online CPU (ex: UP) */ |
| 669 | if (num_online_cpus() == 1) { |
| 670 | unlock_cpu_hotplug(); |
| 671 | return; |
| 672 | } |
| 673 | |
| 674 | if (rcu_idle_cpu != -1) |
| 675 | cpu_clear(rcu_idle_cpu, tmp_mask); |
| 676 | |
| 677 | set_cpus_allowed(current, tmp_mask); |
| 678 | |
| 679 | if (reader_tasks != NULL) { |
| 680 | for (i = 0; i < nrealreaders; i++) |
| 681 | if (reader_tasks[i]) |
| 682 | set_cpus_allowed(reader_tasks[i], tmp_mask); |
| 683 | } |
| 684 | |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 685 | if (fakewriter_tasks != NULL) { |
| 686 | for (i = 0; i < nfakewriters; i++) |
| 687 | if (fakewriter_tasks[i]) |
| 688 | set_cpus_allowed(fakewriter_tasks[i], tmp_mask); |
| 689 | } |
| 690 | |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 691 | if (writer_task) |
| 692 | set_cpus_allowed(writer_task, tmp_mask); |
| 693 | |
| 694 | if (stats_task) |
| 695 | set_cpus_allowed(stats_task, tmp_mask); |
| 696 | |
| 697 | if (rcu_idle_cpu == -1) |
| 698 | rcu_idle_cpu = num_online_cpus() - 1; |
| 699 | else |
| 700 | rcu_idle_cpu--; |
| 701 | |
| 702 | unlock_cpu_hotplug(); |
| 703 | } |
| 704 | |
| 705 | /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the |
| 706 | * system to become idle at a time and cut off its timer ticks. This is meant |
| 707 | * to test the support for such tickless idle CPU in RCU. |
| 708 | */ |
| 709 | static int |
| 710 | rcu_torture_shuffle(void *arg) |
| 711 | { |
| 712 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started"); |
| 713 | do { |
| 714 | schedule_timeout_interruptible(shuffle_interval * HZ); |
| 715 | rcu_torture_shuffle_tasks(); |
| 716 | } while (!kthread_should_stop()); |
| 717 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping"); |
| 718 | return 0; |
| 719 | } |
| 720 | |
Paul E. McKenney | 95c3832 | 2006-03-24 03:15:58 -0800 | [diff] [blame] | 721 | static inline void |
| 722 | rcu_torture_print_module_parms(char *tag) |
| 723 | { |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 724 | printk(KERN_ALERT "%s" TORTURE_FLAG |
| 725 | "--- %s: nreaders=%d nfakewriters=%d " |
Paul E. McKenney | 95c3832 | 2006-03-24 03:15:58 -0800 | [diff] [blame] | 726 | "stat_interval=%d verbose=%d test_no_idle_hz=%d " |
| 727 | "shuffle_interval = %d\n", |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 728 | torture_type, tag, nrealreaders, nfakewriters, |
| 729 | stat_interval, verbose, test_no_idle_hz, shuffle_interval); |
Paul E. McKenney | 95c3832 | 2006-03-24 03:15:58 -0800 | [diff] [blame] | 730 | } |
| 731 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 732 | static void |
| 733 | rcu_torture_cleanup(void) |
| 734 | { |
| 735 | int i; |
| 736 | |
| 737 | fullstop = 1; |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 738 | if (shuffler_task != NULL) { |
| 739 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task"); |
| 740 | kthread_stop(shuffler_task); |
| 741 | } |
| 742 | shuffler_task = NULL; |
| 743 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 744 | if (writer_task != NULL) { |
| 745 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task"); |
| 746 | kthread_stop(writer_task); |
| 747 | } |
| 748 | writer_task = NULL; |
| 749 | |
| 750 | if (reader_tasks != NULL) { |
| 751 | for (i = 0; i < nrealreaders; i++) { |
| 752 | if (reader_tasks[i] != NULL) { |
| 753 | VERBOSE_PRINTK_STRING( |
| 754 | "Stopping rcu_torture_reader task"); |
| 755 | kthread_stop(reader_tasks[i]); |
| 756 | } |
| 757 | reader_tasks[i] = NULL; |
| 758 | } |
| 759 | kfree(reader_tasks); |
| 760 | reader_tasks = NULL; |
| 761 | } |
| 762 | rcu_torture_current = NULL; |
| 763 | |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 764 | if (fakewriter_tasks != NULL) { |
| 765 | for (i = 0; i < nfakewriters; i++) { |
| 766 | if (fakewriter_tasks[i] != NULL) { |
| 767 | VERBOSE_PRINTK_STRING( |
| 768 | "Stopping rcu_torture_fakewriter task"); |
| 769 | kthread_stop(fakewriter_tasks[i]); |
| 770 | } |
| 771 | fakewriter_tasks[i] = NULL; |
| 772 | } |
| 773 | kfree(fakewriter_tasks); |
| 774 | fakewriter_tasks = NULL; |
| 775 | } |
| 776 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 777 | if (stats_task != NULL) { |
| 778 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task"); |
| 779 | kthread_stop(stats_task); |
| 780 | } |
| 781 | stats_task = NULL; |
| 782 | |
| 783 | /* Wait for all RCU callbacks to fire. */ |
Srivatsa Vaddagiri | 89d46b8 | 2005-12-12 00:37:06 -0800 | [diff] [blame] | 784 | rcu_barrier(); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 785 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 786 | rcu_torture_stats_print(); /* -After- the stats thread is stopped! */ |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 787 | |
| 788 | if (cur_ops->cleanup != NULL) |
| 789 | cur_ops->cleanup(); |
Paul E. McKenney | 95c3832 | 2006-03-24 03:15:58 -0800 | [diff] [blame] | 790 | if (atomic_read(&n_rcu_torture_error)) |
| 791 | rcu_torture_print_module_parms("End of test: FAILURE"); |
| 792 | else |
| 793 | rcu_torture_print_module_parms("End of test: SUCCESS"); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | static int |
| 797 | rcu_torture_init(void) |
| 798 | { |
| 799 | int i; |
| 800 | int cpu; |
| 801 | int firsterr = 0; |
| 802 | |
| 803 | /* Process args and tell the world that the torturer is on the job. */ |
| 804 | |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 805 | for (i = 0; cur_ops = torture_ops[i], cur_ops != NULL; i++) { |
| 806 | cur_ops = torture_ops[i]; |
| 807 | if (strcmp(torture_type, cur_ops->name) == 0) { |
| 808 | break; |
| 809 | } |
| 810 | } |
| 811 | if (cur_ops == NULL) { |
| 812 | printk(KERN_ALERT "rcutorture: invalid torture type: \"%s\"\n", |
| 813 | torture_type); |
| 814 | return (-EINVAL); |
| 815 | } |
| 816 | if (cur_ops->init != NULL) |
| 817 | cur_ops->init(); /* no "goto unwind" prior to this point!!! */ |
| 818 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 819 | if (nreaders >= 0) |
| 820 | nrealreaders = nreaders; |
| 821 | else |
| 822 | nrealreaders = 2 * num_online_cpus(); |
Paul E. McKenney | 95c3832 | 2006-03-24 03:15:58 -0800 | [diff] [blame] | 823 | rcu_torture_print_module_parms("Start of test"); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 824 | fullstop = 0; |
| 825 | |
| 826 | /* Set up the freelist. */ |
| 827 | |
| 828 | INIT_LIST_HEAD(&rcu_torture_freelist); |
| 829 | for (i = 0; i < sizeof(rcu_tortures) / sizeof(rcu_tortures[0]); i++) { |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 830 | rcu_tortures[i].rtort_mbtest = 0; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 831 | list_add_tail(&rcu_tortures[i].rtort_free, |
| 832 | &rcu_torture_freelist); |
| 833 | } |
| 834 | |
| 835 | /* Initialize the statistics so that each run gets its own numbers. */ |
| 836 | |
| 837 | rcu_torture_current = NULL; |
| 838 | rcu_torture_current_version = 0; |
| 839 | atomic_set(&n_rcu_torture_alloc, 0); |
| 840 | atomic_set(&n_rcu_torture_alloc_fail, 0); |
| 841 | atomic_set(&n_rcu_torture_free, 0); |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 842 | atomic_set(&n_rcu_torture_mberror, 0); |
| 843 | atomic_set(&n_rcu_torture_error, 0); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 844 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
| 845 | atomic_set(&rcu_torture_wcount[i], 0); |
KAMEZAWA Hiroyuki | 0a94502 | 2006-03-28 01:56:37 -0800 | [diff] [blame] | 846 | for_each_possible_cpu(cpu) { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 847 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
| 848 | per_cpu(rcu_torture_count, cpu)[i] = 0; |
| 849 | per_cpu(rcu_torture_batch, cpu)[i] = 0; |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | /* Start up the kthreads. */ |
| 854 | |
| 855 | VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task"); |
| 856 | writer_task = kthread_run(rcu_torture_writer, NULL, |
| 857 | "rcu_torture_writer"); |
| 858 | if (IS_ERR(writer_task)) { |
| 859 | firsterr = PTR_ERR(writer_task); |
| 860 | VERBOSE_PRINTK_ERRSTRING("Failed to create writer"); |
| 861 | writer_task = NULL; |
| 862 | goto unwind; |
| 863 | } |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame^] | 864 | fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]), |
| 865 | GFP_KERNEL); |
| 866 | if (fakewriter_tasks == NULL) { |
| 867 | VERBOSE_PRINTK_ERRSTRING("out of memory"); |
| 868 | firsterr = -ENOMEM; |
| 869 | goto unwind; |
| 870 | } |
| 871 | for (i = 0; i < nfakewriters; i++) { |
| 872 | VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task"); |
| 873 | fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL, |
| 874 | "rcu_torture_fakewriter"); |
| 875 | if (IS_ERR(fakewriter_tasks[i])) { |
| 876 | firsterr = PTR_ERR(fakewriter_tasks[i]); |
| 877 | VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter"); |
| 878 | fakewriter_tasks[i] = NULL; |
| 879 | goto unwind; |
| 880 | } |
| 881 | } |
Josh Triplett | 2860aab | 2006-10-04 02:17:11 -0700 | [diff] [blame] | 882 | reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]), |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 883 | GFP_KERNEL); |
| 884 | if (reader_tasks == NULL) { |
| 885 | VERBOSE_PRINTK_ERRSTRING("out of memory"); |
| 886 | firsterr = -ENOMEM; |
| 887 | goto unwind; |
| 888 | } |
| 889 | for (i = 0; i < nrealreaders; i++) { |
| 890 | VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task"); |
| 891 | reader_tasks[i] = kthread_run(rcu_torture_reader, NULL, |
| 892 | "rcu_torture_reader"); |
| 893 | if (IS_ERR(reader_tasks[i])) { |
| 894 | firsterr = PTR_ERR(reader_tasks[i]); |
| 895 | VERBOSE_PRINTK_ERRSTRING("Failed to create reader"); |
| 896 | reader_tasks[i] = NULL; |
| 897 | goto unwind; |
| 898 | } |
| 899 | } |
| 900 | if (stat_interval > 0) { |
| 901 | VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task"); |
| 902 | stats_task = kthread_run(rcu_torture_stats, NULL, |
| 903 | "rcu_torture_stats"); |
| 904 | if (IS_ERR(stats_task)) { |
| 905 | firsterr = PTR_ERR(stats_task); |
| 906 | VERBOSE_PRINTK_ERRSTRING("Failed to create stats"); |
| 907 | stats_task = NULL; |
| 908 | goto unwind; |
| 909 | } |
| 910 | } |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 911 | if (test_no_idle_hz) { |
| 912 | rcu_idle_cpu = num_online_cpus() - 1; |
| 913 | /* Create the shuffler thread */ |
| 914 | shuffler_task = kthread_run(rcu_torture_shuffle, NULL, |
| 915 | "rcu_torture_shuffle"); |
| 916 | if (IS_ERR(shuffler_task)) { |
| 917 | firsterr = PTR_ERR(shuffler_task); |
| 918 | VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler"); |
| 919 | shuffler_task = NULL; |
| 920 | goto unwind; |
| 921 | } |
| 922 | } |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 923 | return 0; |
| 924 | |
| 925 | unwind: |
| 926 | rcu_torture_cleanup(); |
| 927 | return firsterr; |
| 928 | } |
| 929 | |
| 930 | module_init(rcu_torture_init); |
| 931 | module_exit(rcu_torture_cleanup); |