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