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