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