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