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