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