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