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