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