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