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