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 |
Paul E. McKenney | f5604f6 | 2014-02-26 06:38:59 -0800 | [diff] [blame] | 15 | * along with this program; if not, you can access it online at |
| 16 | * http://www.gnu.org/licenses/gpl-2.0.html. |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 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> |
Josh Triplett | e0198b29 | 2014-07-30 16:08:42 -0700 | [diff] [blame] | 21 | * Josh Triplett <josh@joshtriplett.org> |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 22 | * |
| 23 | * See also: Documentation/RCU/torture.txt |
| 24 | */ |
Paul E. McKenney | 6050003 | 2018-05-15 12:25:05 -0700 | [diff] [blame] | 25 | |
| 26 | #define pr_fmt(fmt) fmt |
| 27 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 28 | #include <linux/types.h> |
| 29 | #include <linux/kernel.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/kthread.h> |
| 33 | #include <linux/err.h> |
| 34 | #include <linux/spinlock.h> |
| 35 | #include <linux/smp.h> |
| 36 | #include <linux/rcupdate.h> |
| 37 | #include <linux/interrupt.h> |
Ingo Molnar | 174cd4b | 2017-02-02 19:15:33 +0100 | [diff] [blame] | 38 | #include <linux/sched/signal.h> |
Ingo Molnar | ae7e81c | 2017-02-01 18:07:51 +0100 | [diff] [blame] | 39 | #include <uapi/linux/sched/types.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 40 | #include <linux/atomic.h> |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 41 | #include <linux/bitops.h> |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 42 | #include <linux/completion.h> |
| 43 | #include <linux/moduleparam.h> |
| 44 | #include <linux/percpu.h> |
| 45 | #include <linux/notifier.h> |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 46 | #include <linux/reboot.h> |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 47 | #include <linux/freezer.h> |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 48 | #include <linux/cpu.h> |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 49 | #include <linux/delay.h> |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 50 | #include <linux/stat.h> |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 51 | #include <linux/srcu.h> |
Robert P. J. Day | 1aeb272 | 2008-04-29 00:59:25 -0700 | [diff] [blame] | 52 | #include <linux/slab.h> |
Paul E. McKenney | 5249453 | 2012-11-14 16:26:40 -0800 | [diff] [blame] | 53 | #include <linux/trace_clock.h> |
Harvey Harrison | f07767f | 2008-10-20 10:23:38 -0700 | [diff] [blame] | 54 | #include <asm/byteorder.h> |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 55 | #include <linux/torture.h> |
Paul E. McKenney | 38706bc | 2014-08-18 21:12:17 -0700 | [diff] [blame] | 56 | #include <linux/vmalloc.h> |
Paul E. McKenney | 0032f4e | 2017-08-30 10:40:17 -0700 | [diff] [blame] | 57 | #include <linux/sched/debug.h> |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 58 | |
Paul E. McKenney | 25c3632 | 2017-05-03 09:51:55 -0700 | [diff] [blame] | 59 | #include "rcu.h" |
| 60 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 61 | MODULE_LICENSE("GPL"); |
Josh Triplett | e0198b29 | 2014-07-30 16:08:42 -0700 | [diff] [blame] | 62 | MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@joshtriplett.org>"); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 63 | |
Paul E. McKenney | 4102ada | 2013-10-08 20:23:47 -0700 | [diff] [blame] | 64 | |
Paul E. McKenney | 38706bc | 2014-08-18 21:12:17 -0700 | [diff] [blame] | 65 | torture_param(int, cbflood_inter_holdoff, HZ, |
| 66 | "Holdoff between floods (jiffies)"); |
| 67 | torture_param(int, cbflood_intra_holdoff, 1, |
| 68 | "Holdoff between bursts (jiffies)"); |
| 69 | torture_param(int, cbflood_n_burst, 3, "# bursts in flood, zero to disable"); |
| 70 | torture_param(int, cbflood_n_per_burst, 20000, |
| 71 | "# callbacks per burst in flood"); |
Paul E. McKenney | 9e25022 | 2014-01-27 16:27:00 -0800 | [diff] [blame] | 72 | torture_param(int, fqs_duration, 0, |
| 73 | "Duration of fqs bursts (us), 0 to disable"); |
| 74 | torture_param(int, fqs_holdoff, 0, "Holdoff time within fqs bursts (us)"); |
| 75 | torture_param(int, fqs_stutter, 3, "Wait time between fqs bursts (s)"); |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 76 | torture_param(bool, gp_cond, false, "Use conditional/async GP wait primitives"); |
Paul E. McKenney | 9e25022 | 2014-01-27 16:27:00 -0800 | [diff] [blame] | 77 | torture_param(bool, gp_exp, false, "Use expedited GP wait primitives"); |
| 78 | torture_param(bool, gp_normal, false, |
| 79 | "Use normal (non-expedited) GP wait primitives"); |
Paul E. McKenney | f0bf8fa | 2014-03-21 16:17:56 -0700 | [diff] [blame] | 80 | torture_param(bool, gp_sync, false, "Use synchronous GP wait primitives"); |
Paul E. McKenney | 9e25022 | 2014-01-27 16:27:00 -0800 | [diff] [blame] | 81 | torture_param(int, irqreader, 1, "Allow RCU readers from irq handlers"); |
| 82 | torture_param(int, n_barrier_cbs, 0, |
| 83 | "# of callbacks/kthreads for barrier testing"); |
| 84 | torture_param(int, nfakewriters, 4, "Number of RCU fake writer threads"); |
| 85 | torture_param(int, nreaders, -1, "Number of RCU reader threads"); |
| 86 | torture_param(int, object_debug, 0, |
| 87 | "Enable debug-object double call_rcu() testing"); |
| 88 | torture_param(int, onoff_holdoff, 0, "Time after boot before CPU hotplugs (s)"); |
| 89 | torture_param(int, onoff_interval, 0, |
Paul E. McKenney | 028be12 | 2018-05-08 09:20:34 -0700 | [diff] [blame] | 90 | "Time between CPU hotplugs (jiffies), 0=disable"); |
Paul E. McKenney | 9e25022 | 2014-01-27 16:27:00 -0800 | [diff] [blame] | 91 | torture_param(int, shuffle_interval, 3, "Number of seconds between shuffles"); |
| 92 | torture_param(int, shutdown_secs, 0, "Shutdown time (s), <= zero to disable."); |
| 93 | torture_param(int, stall_cpu, 0, "Stall duration (s), zero to disable."); |
| 94 | torture_param(int, stall_cpu_holdoff, 10, |
| 95 | "Time to wait before starting stall (s)."); |
Paul E. McKenney | 2b1516e | 2017-08-18 16:11:37 -0700 | [diff] [blame] | 96 | torture_param(int, stall_cpu_irqsoff, 0, "Disable interrupts while stalling."); |
Paul E. McKenney | 9e25022 | 2014-01-27 16:27:00 -0800 | [diff] [blame] | 97 | torture_param(int, stat_interval, 60, |
| 98 | "Number of seconds between stats printk()s"); |
| 99 | torture_param(int, stutter, 5, "Number of seconds to run/halt test"); |
| 100 | torture_param(int, test_boost, 1, "Test RCU prio boost: 0=no, 1=maybe, 2=yes."); |
| 101 | torture_param(int, test_boost_duration, 4, |
| 102 | "Duration of each boost test, seconds."); |
| 103 | torture_param(int, test_boost_interval, 7, |
| 104 | "Interval between boost tests, seconds."); |
| 105 | torture_param(bool, test_no_idle_hz, true, |
| 106 | "Test support for tickless idle CPUs"); |
Paul E. McKenney | 90127d6 | 2018-05-09 10:29:18 -0700 | [diff] [blame] | 107 | torture_param(int, verbose, 1, |
Paul E. McKenney | b5daa8f | 2014-01-30 13:38:09 -0800 | [diff] [blame] | 108 | "Enable verbose debugging printk()s"); |
Paul E. McKenney | 9e25022 | 2014-01-27 16:27:00 -0800 | [diff] [blame] | 109 | |
Paul E. McKenney | b5daa8f | 2014-01-30 13:38:09 -0800 | [diff] [blame] | 110 | static char *torture_type = "rcu"; |
Josh Triplett | d6ad671 | 2007-03-06 01:42:13 -0800 | [diff] [blame] | 111 | module_param(torture_type, charp, 0444); |
Paul E. McKenney | d10453e | 2013-06-13 15:12:24 -0700 | [diff] [blame] | 112 | MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)"); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 113 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 114 | static int nrealreaders; |
Paul E. McKenney | 38706bc | 2014-08-18 21:12:17 -0700 | [diff] [blame] | 115 | static int ncbflooders; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 116 | static struct task_struct *writer_task; |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 117 | static struct task_struct **fakewriter_tasks; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 118 | static struct task_struct **reader_tasks; |
| 119 | static struct task_struct *stats_task; |
Paul E. McKenney | 38706bc | 2014-08-18 21:12:17 -0700 | [diff] [blame] | 120 | static struct task_struct **cbflood_task; |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 121 | static struct task_struct *fqs_task; |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 122 | static struct task_struct *boost_tasks[NR_CPUS]; |
Paul E. McKenney | c13f375 | 2012-01-20 15:36:33 -0800 | [diff] [blame] | 123 | static struct task_struct *stall_task; |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 124 | static struct task_struct **barrier_cbs_tasks; |
| 125 | static struct task_struct *barrier_task; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 126 | |
| 127 | #define RCU_TORTURE_PIPE_LEN 10 |
| 128 | |
| 129 | struct rcu_torture { |
| 130 | struct rcu_head rtort_rcu; |
| 131 | int rtort_pipe_count; |
| 132 | struct list_head rtort_free; |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 133 | int rtort_mbtest; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 134 | }; |
| 135 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 136 | static LIST_HEAD(rcu_torture_freelist); |
Paul E. McKenney | 0ddea0e | 2010-09-19 21:06:14 -0700 | [diff] [blame] | 137 | static struct rcu_torture __rcu *rcu_torture_current; |
Paul E. McKenney | 4a29865 | 2011-04-03 21:33:51 -0700 | [diff] [blame] | 138 | static unsigned long rcu_torture_current_version; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 139 | static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN]; |
| 140 | static DEFINE_SPINLOCK(rcu_torture_lock); |
Paul E. McKenney | 67522be | 2016-03-01 08:52:19 -0800 | [diff] [blame] | 141 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count); |
| 142 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 143 | static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1]; |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 144 | static atomic_t n_rcu_torture_alloc; |
| 145 | static atomic_t n_rcu_torture_alloc_fail; |
| 146 | static atomic_t n_rcu_torture_free; |
| 147 | static atomic_t n_rcu_torture_mberror; |
| 148 | static atomic_t n_rcu_torture_error; |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 149 | static long n_rcu_torture_barrier_error; |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 150 | static long n_rcu_torture_boost_ktrerror; |
| 151 | static long n_rcu_torture_boost_rterror; |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 152 | static long n_rcu_torture_boost_failure; |
| 153 | static long n_rcu_torture_boosts; |
Paul E. McKenney | 8da9a59 | 2018-05-22 11:17:51 -0700 | [diff] [blame] | 154 | static atomic_long_t n_rcu_torture_timers; |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 155 | static long n_barrier_attempts; |
| 156 | static long n_barrier_successes; |
Paul E. McKenney | 38706bc | 2014-08-18 21:12:17 -0700 | [diff] [blame] | 157 | static atomic_long_t n_cbfloods; |
Josh Triplett | e303373 | 2006-10-04 02:17:14 -0700 | [diff] [blame] | 158 | static struct list_head rcu_torture_removed; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 159 | |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 160 | static int rcu_torture_writer_state; |
| 161 | #define RTWS_FIXED_DELAY 0 |
| 162 | #define RTWS_DELAY 1 |
| 163 | #define RTWS_REPLACE 2 |
| 164 | #define RTWS_DEF_FREE 3 |
| 165 | #define RTWS_EXP_SYNC 4 |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 166 | #define RTWS_COND_GET 5 |
| 167 | #define RTWS_COND_SYNC 6 |
Paul E. McKenney | f0bf8fa | 2014-03-21 16:17:56 -0700 | [diff] [blame] | 168 | #define RTWS_SYNC 7 |
| 169 | #define RTWS_STUTTER 8 |
| 170 | #define RTWS_STOPPING 9 |
Paul E. McKenney | 18aff33 | 2015-11-17 13:35:28 -0800 | [diff] [blame] | 171 | static const char * const rcu_torture_writer_state_names[] = { |
| 172 | "RTWS_FIXED_DELAY", |
| 173 | "RTWS_DELAY", |
| 174 | "RTWS_REPLACE", |
| 175 | "RTWS_DEF_FREE", |
| 176 | "RTWS_EXP_SYNC", |
| 177 | "RTWS_COND_GET", |
| 178 | "RTWS_COND_SYNC", |
| 179 | "RTWS_SYNC", |
| 180 | "RTWS_STUTTER", |
| 181 | "RTWS_STOPPING", |
| 182 | }; |
| 183 | |
| 184 | static const char *rcu_torture_writer_state_getname(void) |
| 185 | { |
| 186 | unsigned int i = READ_ONCE(rcu_torture_writer_state); |
| 187 | |
| 188 | if (i >= ARRAY_SIZE(rcu_torture_writer_state_names)) |
| 189 | return "???"; |
| 190 | return rcu_torture_writer_state_names[i]; |
| 191 | } |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 192 | |
Paul E. McKenney | 3acf4a9 | 2011-04-17 23:45:23 -0700 | [diff] [blame] | 193 | #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 194 | #define rcu_can_boost() 1 |
Paul E. McKenney | 3acf4a9 | 2011-04-17 23:45:23 -0700 | [diff] [blame] | 195 | #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */ |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 196 | #define rcu_can_boost() 0 |
Paul E. McKenney | 3acf4a9 | 2011-04-17 23:45:23 -0700 | [diff] [blame] | 197 | #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */ |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 198 | |
Steven Rostedt | e4aa0da | 2013-02-04 13:36:13 -0500 | [diff] [blame] | 199 | #ifdef CONFIG_RCU_TRACE |
| 200 | static u64 notrace rcu_trace_clock_local(void) |
| 201 | { |
| 202 | u64 ts = trace_clock_local(); |
Paul E. McKenney | a3b7b6c | 2017-06-23 16:07:17 -0700 | [diff] [blame] | 203 | |
| 204 | (void)do_div(ts, NSEC_PER_USEC); |
Steven Rostedt | e4aa0da | 2013-02-04 13:36:13 -0500 | [diff] [blame] | 205 | return ts; |
| 206 | } |
| 207 | #else /* #ifdef CONFIG_RCU_TRACE */ |
| 208 | static u64 notrace rcu_trace_clock_local(void) |
| 209 | { |
| 210 | return 0ULL; |
| 211 | } |
| 212 | #endif /* #else #ifdef CONFIG_RCU_TRACE */ |
| 213 | |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 214 | static unsigned long boost_starttime; /* jiffies of next boost test start. */ |
Pranith Kumar | 58ade2d | 2014-06-11 16:39:43 -0400 | [diff] [blame] | 215 | static DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */ |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 216 | /* and boost task create/destroy. */ |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 217 | static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */ |
Paul E. McKenney | c6ebcbb | 2012-05-28 19:21:41 -0700 | [diff] [blame] | 218 | static bool barrier_phase; /* Test phase. */ |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 219 | static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */ |
| 220 | static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */ |
| 221 | static DECLARE_WAIT_QUEUE_HEAD(barrier_wq); |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 222 | |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 223 | /* |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 224 | * Allocate an element from the rcu_tortures pool. |
| 225 | */ |
Adrian Bunk | 97a41e2 | 2006-01-08 01:02:17 -0800 | [diff] [blame] | 226 | static struct rcu_torture * |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 227 | rcu_torture_alloc(void) |
| 228 | { |
| 229 | struct list_head *p; |
| 230 | |
Ingo Molnar | adac166 | 2006-01-25 19:50:12 +0100 | [diff] [blame] | 231 | spin_lock_bh(&rcu_torture_lock); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 232 | if (list_empty(&rcu_torture_freelist)) { |
| 233 | atomic_inc(&n_rcu_torture_alloc_fail); |
Ingo Molnar | adac166 | 2006-01-25 19:50:12 +0100 | [diff] [blame] | 234 | spin_unlock_bh(&rcu_torture_lock); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 235 | return NULL; |
| 236 | } |
| 237 | atomic_inc(&n_rcu_torture_alloc); |
| 238 | p = rcu_torture_freelist.next; |
| 239 | list_del_init(p); |
Ingo Molnar | adac166 | 2006-01-25 19:50:12 +0100 | [diff] [blame] | 240 | spin_unlock_bh(&rcu_torture_lock); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 241 | return container_of(p, struct rcu_torture, rtort_free); |
| 242 | } |
| 243 | |
| 244 | /* |
| 245 | * Free an element to the rcu_tortures pool. |
| 246 | */ |
| 247 | static void |
| 248 | rcu_torture_free(struct rcu_torture *p) |
| 249 | { |
| 250 | atomic_inc(&n_rcu_torture_free); |
Ingo Molnar | adac166 | 2006-01-25 19:50:12 +0100 | [diff] [blame] | 251 | spin_lock_bh(&rcu_torture_lock); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 252 | list_add_tail(&p->rtort_free, &rcu_torture_freelist); |
Ingo Molnar | adac166 | 2006-01-25 19:50:12 +0100 | [diff] [blame] | 253 | spin_unlock_bh(&rcu_torture_lock); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 254 | } |
| 255 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 256 | /* |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 257 | * Operations vector for selecting different types of tests. |
| 258 | */ |
| 259 | |
| 260 | struct rcu_torture_ops { |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 261 | int ttype; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 262 | void (*init)(void); |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 263 | void (*cleanup)(void); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 264 | int (*readlock)(void); |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 265 | void (*read_delay)(struct torture_random_state *rrsp); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 266 | void (*readunlock)(int idx); |
Paul E. McKenney | 17ef2fe | 2018-04-27 11:39:34 -0700 | [diff] [blame] | 267 | unsigned long (*get_gp_seq)(void); |
Paul E. McKenney | d7219312 | 2018-05-15 15:24:41 -0700 | [diff] [blame] | 268 | unsigned long (*gp_diff)(unsigned long new, unsigned long old); |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 269 | void (*deferred_free)(struct rcu_torture *p); |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 270 | void (*sync)(void); |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 271 | void (*exp_sync)(void); |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 272 | unsigned long (*get_state)(void); |
| 273 | void (*cond_sync)(unsigned long oldstate); |
Boqun Feng | db3e8db | 2015-07-29 13:29:39 +0800 | [diff] [blame] | 274 | call_rcu_func_t call; |
Paul E. McKenney | 2326974 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 275 | void (*cb_barrier)(void); |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 276 | void (*fqs)(void); |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 277 | void (*stats)(void); |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 278 | int irq_capable; |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 279 | int can_boost; |
Steven Rostedt (Red Hat) | e66c33d | 2013-07-12 16:50:28 -0400 | [diff] [blame] | 280 | const char *name; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 281 | }; |
Paul E. McKenney | a71fca5 | 2009-09-18 10:28:19 -0700 | [diff] [blame] | 282 | |
| 283 | static struct rcu_torture_ops *cur_ops; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 284 | |
| 285 | /* |
| 286 | * Definitions for rcu torture testing. |
| 287 | */ |
| 288 | |
Josh Triplett | a49a4af | 2006-09-29 01:59:30 -0700 | [diff] [blame] | 289 | static int rcu_torture_read_lock(void) __acquires(RCU) |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 290 | { |
| 291 | rcu_read_lock(); |
| 292 | return 0; |
| 293 | } |
| 294 | |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 295 | static void rcu_read_delay(struct torture_random_state *rrsp) |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 296 | { |
Paul E. McKenney | d0af39e | 2016-10-10 18:26:04 -0700 | [diff] [blame] | 297 | unsigned long started; |
| 298 | unsigned long completed; |
Josh Triplett | b8d57a7 | 2009-09-08 15:54:35 -0700 | [diff] [blame] | 299 | const unsigned long shortdelay_us = 200; |
| 300 | const unsigned long longdelay_ms = 50; |
Paul E. McKenney | d0af39e | 2016-10-10 18:26:04 -0700 | [diff] [blame] | 301 | unsigned long long ts; |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 302 | |
Josh Triplett | b8d57a7 | 2009-09-08 15:54:35 -0700 | [diff] [blame] | 303 | /* We want a short delay sometimes to make a reader delay the grace |
| 304 | * period, and we want a long delay occasionally to trigger |
| 305 | * force_quiescent_state. */ |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 306 | |
Paul E. McKenney | d0af39e | 2016-10-10 18:26:04 -0700 | [diff] [blame] | 307 | if (!(torture_random(rrsp) % (nrealreaders * 2000 * longdelay_ms))) { |
Paul E. McKenney | 17ef2fe | 2018-04-27 11:39:34 -0700 | [diff] [blame] | 308 | started = cur_ops->get_gp_seq(); |
Paul E. McKenney | d0af39e | 2016-10-10 18:26:04 -0700 | [diff] [blame] | 309 | ts = rcu_trace_clock_local(); |
Josh Triplett | b8d57a7 | 2009-09-08 15:54:35 -0700 | [diff] [blame] | 310 | mdelay(longdelay_ms); |
Paul E. McKenney | 17ef2fe | 2018-04-27 11:39:34 -0700 | [diff] [blame] | 311 | completed = cur_ops->get_gp_seq(); |
Paul E. McKenney | d0af39e | 2016-10-10 18:26:04 -0700 | [diff] [blame] | 312 | do_trace_rcu_torture_read(cur_ops->name, NULL, ts, |
| 313 | started, completed); |
| 314 | } |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 315 | if (!(torture_random(rrsp) % (nrealreaders * 2 * shortdelay_us))) |
Josh Triplett | b8d57a7 | 2009-09-08 15:54:35 -0700 | [diff] [blame] | 316 | udelay(shortdelay_us); |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 317 | if (!preempt_count() && |
Paul E. McKenney | e830273 | 2017-10-16 11:23:42 -0700 | [diff] [blame] | 318 | !(torture_random(rrsp) % (nrealreaders * 500))) |
Paul E. McKenney | cc1321c | 2017-10-16 11:05:03 -0700 | [diff] [blame] | 319 | torture_preempt_schedule(); /* QS only if preemptible. */ |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Josh Triplett | a49a4af | 2006-09-29 01:59:30 -0700 | [diff] [blame] | 322 | static void rcu_torture_read_unlock(int idx) __releases(RCU) |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 323 | { |
| 324 | rcu_read_unlock(); |
| 325 | } |
| 326 | |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 327 | /* |
| 328 | * Update callback in the pipe. This should be invoked after a grace period. |
| 329 | */ |
| 330 | static bool |
| 331 | rcu_torture_pipe_update_one(struct rcu_torture *rp) |
| 332 | { |
| 333 | int i; |
| 334 | |
| 335 | i = rp->rtort_pipe_count; |
| 336 | if (i > RCU_TORTURE_PIPE_LEN) |
| 337 | i = RCU_TORTURE_PIPE_LEN; |
| 338 | atomic_inc(&rcu_torture_wcount[i]); |
| 339 | if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) { |
| 340 | rp->rtort_mbtest = 0; |
| 341 | return true; |
| 342 | } |
| 343 | return false; |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Update all callbacks in the pipe. Suitable for synchronous grace-period |
| 348 | * primitives. |
| 349 | */ |
| 350 | static void |
| 351 | rcu_torture_pipe_update(struct rcu_torture *old_rp) |
| 352 | { |
| 353 | struct rcu_torture *rp; |
| 354 | struct rcu_torture *rp1; |
| 355 | |
| 356 | if (old_rp) |
| 357 | list_add(&old_rp->rtort_free, &rcu_torture_removed); |
| 358 | list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) { |
| 359 | if (rcu_torture_pipe_update_one(rp)) { |
| 360 | list_del(&rp->rtort_free); |
| 361 | rcu_torture_free(rp); |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 366 | static void |
| 367 | rcu_torture_cb(struct rcu_head *p) |
| 368 | { |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 369 | struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu); |
| 370 | |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 371 | if (torture_must_stop_irq()) { |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 372 | /* Test is ending, just drop callbacks on the floor. */ |
| 373 | /* The next initialization will pick up the pieces. */ |
| 374 | return; |
| 375 | } |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 376 | if (rcu_torture_pipe_update_one(rp)) |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 377 | rcu_torture_free(rp); |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 378 | else |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 379 | cur_ops->deferred_free(rp); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Paul E. McKenney | 6b80da4 | 2014-11-21 14:19:26 -0800 | [diff] [blame] | 382 | static unsigned long rcu_no_completed(void) |
Paul E. McKenney | d9a3da0 | 2009-12-02 12:10:15 -0800 | [diff] [blame] | 383 | { |
| 384 | return 0; |
| 385 | } |
| 386 | |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 387 | static void rcu_torture_deferred_free(struct rcu_torture *p) |
| 388 | { |
| 389 | call_rcu(&p->rtort_rcu, rcu_torture_cb); |
| 390 | } |
| 391 | |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 392 | static void rcu_sync_torture_init(void) |
| 393 | { |
| 394 | INIT_LIST_HEAD(&rcu_torture_removed); |
| 395 | } |
| 396 | |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 397 | static struct rcu_torture_ops rcu_ops = { |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 398 | .ttype = RCU_FLAVOR, |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 399 | .init = rcu_sync_torture_init, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 400 | .readlock = rcu_torture_read_lock, |
| 401 | .read_delay = rcu_read_delay, |
| 402 | .readunlock = rcu_torture_read_unlock, |
Paul E. McKenney | 17ef2fe | 2018-04-27 11:39:34 -0700 | [diff] [blame] | 403 | .get_gp_seq = rcu_get_gp_seq, |
Paul E. McKenney | d7219312 | 2018-05-15 15:24:41 -0700 | [diff] [blame] | 404 | .gp_diff = rcu_seq_diff, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 405 | .deferred_free = rcu_torture_deferred_free, |
| 406 | .sync = synchronize_rcu, |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 407 | .exp_sync = synchronize_rcu_expedited, |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 408 | .get_state = get_state_synchronize_rcu, |
| 409 | .cond_sync = cond_synchronize_rcu, |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 410 | .call = call_rcu, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 411 | .cb_barrier = rcu_barrier, |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 412 | .fqs = rcu_force_quiescent_state, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 413 | .stats = NULL, |
Paul E. McKenney | a71fca5 | 2009-09-18 10:28:19 -0700 | [diff] [blame] | 414 | .irq_capable = 1, |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 415 | .can_boost = rcu_can_boost(), |
Paul E. McKenney | a71fca5 | 2009-09-18 10:28:19 -0700 | [diff] [blame] | 416 | .name = "rcu" |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 417 | }; |
| 418 | |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 419 | /* |
| 420 | * Definitions for rcu_bh torture testing. |
| 421 | */ |
| 422 | |
Josh Triplett | a49a4af | 2006-09-29 01:59:30 -0700 | [diff] [blame] | 423 | static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH) |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 424 | { |
| 425 | rcu_read_lock_bh(); |
| 426 | return 0; |
| 427 | } |
| 428 | |
Josh Triplett | a49a4af | 2006-09-29 01:59:30 -0700 | [diff] [blame] | 429 | 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] | 430 | { |
| 431 | rcu_read_unlock_bh(); |
| 432 | } |
| 433 | |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 434 | static void rcu_bh_torture_deferred_free(struct rcu_torture *p) |
| 435 | { |
| 436 | call_rcu_bh(&p->rtort_rcu, rcu_torture_cb); |
| 437 | } |
| 438 | |
| 439 | static struct rcu_torture_ops rcu_bh_ops = { |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 440 | .ttype = RCU_BH_FLAVOR, |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 441 | .init = rcu_sync_torture_init, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 442 | .readlock = rcu_bh_torture_read_lock, |
| 443 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ |
| 444 | .readunlock = rcu_bh_torture_read_unlock, |
Paul E. McKenney | 17ef2fe | 2018-04-27 11:39:34 -0700 | [diff] [blame] | 445 | .get_gp_seq = rcu_bh_get_gp_seq, |
Paul E. McKenney | d7219312 | 2018-05-15 15:24:41 -0700 | [diff] [blame] | 446 | .gp_diff = rcu_seq_diff, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 447 | .deferred_free = rcu_bh_torture_deferred_free, |
Paul E. McKenney | bdf2a43 | 2011-06-07 16:59:35 -0700 | [diff] [blame] | 448 | .sync = synchronize_rcu_bh, |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 449 | .exp_sync = synchronize_rcu_bh_expedited, |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 450 | .call = call_rcu_bh, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 451 | .cb_barrier = rcu_barrier_bh, |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 452 | .fqs = rcu_bh_force_quiescent_state, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 453 | .stats = NULL, |
| 454 | .irq_capable = 1, |
| 455 | .name = "rcu_bh" |
Paul E. McKenney | c32e066 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 456 | }; |
| 457 | |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 458 | /* |
Paul E. McKenney | ff20e25 | 2014-02-06 08:45:56 -0800 | [diff] [blame] | 459 | * Don't even think about trying any of these in real life!!! |
| 460 | * The names includes "busted", and they really means it! |
| 461 | * The only purpose of these functions is to provide a buggy RCU |
| 462 | * implementation to make sure that rcutorture correctly emits |
| 463 | * buggy-RCU error messages. |
| 464 | */ |
| 465 | static void rcu_busted_torture_deferred_free(struct rcu_torture *p) |
| 466 | { |
| 467 | /* This is a deliberate bug for testing purposes only! */ |
| 468 | rcu_torture_cb(&p->rtort_rcu); |
| 469 | } |
| 470 | |
| 471 | static void synchronize_rcu_busted(void) |
| 472 | { |
| 473 | /* This is a deliberate bug for testing purposes only! */ |
| 474 | } |
| 475 | |
| 476 | static void |
Boqun Feng | b6a4ae7 | 2015-07-29 13:29:38 +0800 | [diff] [blame] | 477 | call_rcu_busted(struct rcu_head *head, rcu_callback_t func) |
Paul E. McKenney | ff20e25 | 2014-02-06 08:45:56 -0800 | [diff] [blame] | 478 | { |
| 479 | /* This is a deliberate bug for testing purposes only! */ |
| 480 | func(head); |
| 481 | } |
| 482 | |
| 483 | static struct rcu_torture_ops rcu_busted_ops = { |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 484 | .ttype = INVALID_RCU_FLAVOR, |
Paul E. McKenney | ff20e25 | 2014-02-06 08:45:56 -0800 | [diff] [blame] | 485 | .init = rcu_sync_torture_init, |
| 486 | .readlock = rcu_torture_read_lock, |
| 487 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ |
| 488 | .readunlock = rcu_torture_read_unlock, |
Paul E. McKenney | 17ef2fe | 2018-04-27 11:39:34 -0700 | [diff] [blame] | 489 | .get_gp_seq = rcu_no_completed, |
Paul E. McKenney | ff20e25 | 2014-02-06 08:45:56 -0800 | [diff] [blame] | 490 | .deferred_free = rcu_busted_torture_deferred_free, |
| 491 | .sync = synchronize_rcu_busted, |
| 492 | .exp_sync = synchronize_rcu_busted, |
| 493 | .call = call_rcu_busted, |
| 494 | .cb_barrier = NULL, |
| 495 | .fqs = NULL, |
| 496 | .stats = NULL, |
| 497 | .irq_capable = 1, |
Paul E. McKenney | b3c9831 | 2017-06-06 16:39:00 -0700 | [diff] [blame] | 498 | .name = "busted" |
Paul E. McKenney | ff20e25 | 2014-02-06 08:45:56 -0800 | [diff] [blame] | 499 | }; |
| 500 | |
| 501 | /* |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 502 | * Definitions for srcu torture testing. |
| 503 | */ |
| 504 | |
Lai Jiangshan | cda4dc8 | 2012-10-13 01:14:17 +0800 | [diff] [blame] | 505 | DEFINE_STATIC_SRCU(srcu_ctl); |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 506 | static struct srcu_struct srcu_ctld; |
| 507 | static struct srcu_struct *srcu_ctlp = &srcu_ctl; |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 508 | |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 509 | static int srcu_torture_read_lock(void) __acquires(srcu_ctlp) |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 510 | { |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 511 | return srcu_read_lock(srcu_ctlp); |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 514 | static void srcu_read_delay(struct torture_random_state *rrsp) |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 515 | { |
| 516 | long delay; |
| 517 | const long uspertick = 1000000 / HZ; |
| 518 | const long longdelay = 10; |
| 519 | |
| 520 | /* We want there to be long-running readers, but not all the time. */ |
| 521 | |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 522 | delay = torture_random(rrsp) % |
| 523 | (nrealreaders * 2 * longdelay * uspertick); |
Paul E. McKenney | 5e741fa | 2017-06-06 12:52:44 -0700 | [diff] [blame] | 524 | if (!delay && in_task()) |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 525 | schedule_timeout_interruptible(longdelay); |
Lai Jiangshan | e546f48 | 2010-06-21 16:57:42 +0800 | [diff] [blame] | 526 | else |
| 527 | rcu_read_delay(rrsp); |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 530 | static void srcu_torture_read_unlock(int idx) __releases(srcu_ctlp) |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 531 | { |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 532 | srcu_read_unlock(srcu_ctlp, idx); |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 533 | } |
| 534 | |
Paul E. McKenney | 6b80da4 | 2014-11-21 14:19:26 -0800 | [diff] [blame] | 535 | static unsigned long srcu_torture_completed(void) |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 536 | { |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 537 | return srcu_batches_completed(srcu_ctlp); |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Lai Jiangshan | 9059c94 | 2012-03-19 16:12:14 +0800 | [diff] [blame] | 540 | static void srcu_torture_deferred_free(struct rcu_torture *rp) |
| 541 | { |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 542 | call_srcu(srcu_ctlp, &rp->rtort_rcu, rcu_torture_cb); |
Lai Jiangshan | 9059c94 | 2012-03-19 16:12:14 +0800 | [diff] [blame] | 543 | } |
| 544 | |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 545 | static void srcu_torture_synchronize(void) |
| 546 | { |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 547 | synchronize_srcu(srcu_ctlp); |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Paul E. McKenney | e3f8d37 | 2012-05-08 10:21:50 -0700 | [diff] [blame] | 550 | static void srcu_torture_call(struct rcu_head *head, |
Boqun Feng | b6a4ae7 | 2015-07-29 13:29:38 +0800 | [diff] [blame] | 551 | rcu_callback_t func) |
Paul E. McKenney | e3f8d37 | 2012-05-08 10:21:50 -0700 | [diff] [blame] | 552 | { |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 553 | call_srcu(srcu_ctlp, head, func); |
Paul E. McKenney | e3f8d37 | 2012-05-08 10:21:50 -0700 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | static void srcu_torture_barrier(void) |
| 557 | { |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 558 | srcu_barrier(srcu_ctlp); |
Paul E. McKenney | e3f8d37 | 2012-05-08 10:21:50 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 561 | static void srcu_torture_stats(void) |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 562 | { |
Paul E. McKenney | 115a1a5 | 2017-05-22 13:31:03 -0700 | [diff] [blame] | 563 | srcu_torture_stats_print(srcu_ctlp, torture_type, TORTURE_FLAG); |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 566 | static void srcu_torture_synchronize_expedited(void) |
| 567 | { |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 568 | synchronize_srcu_expedited(srcu_ctlp); |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 571 | static struct rcu_torture_ops srcu_ops = { |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 572 | .ttype = SRCU_FLAVOR, |
Lai Jiangshan | cda4dc8 | 2012-10-13 01:14:17 +0800 | [diff] [blame] | 573 | .init = rcu_sync_torture_init, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 574 | .readlock = srcu_torture_read_lock, |
| 575 | .read_delay = srcu_read_delay, |
| 576 | .readunlock = srcu_torture_read_unlock, |
Paul E. McKenney | 17ef2fe | 2018-04-27 11:39:34 -0700 | [diff] [blame] | 577 | .get_gp_seq = srcu_torture_completed, |
Lai Jiangshan | 9059c94 | 2012-03-19 16:12:14 +0800 | [diff] [blame] | 578 | .deferred_free = srcu_torture_deferred_free, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 579 | .sync = srcu_torture_synchronize, |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 580 | .exp_sync = srcu_torture_synchronize_expedited, |
Paul E. McKenney | e3f8d37 | 2012-05-08 10:21:50 -0700 | [diff] [blame] | 581 | .call = srcu_torture_call, |
| 582 | .cb_barrier = srcu_torture_barrier, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 583 | .stats = srcu_torture_stats, |
Paul E. McKenney | 5e741fa | 2017-06-06 12:52:44 -0700 | [diff] [blame] | 584 | .irq_capable = 1, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 585 | .name = "srcu" |
Paul E. McKenney | b2896d2 | 2006-10-04 02:17:03 -0700 | [diff] [blame] | 586 | }; |
| 587 | |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 588 | static void srcu_torture_init(void) |
| 589 | { |
| 590 | rcu_sync_torture_init(); |
| 591 | WARN_ON(init_srcu_struct(&srcu_ctld)); |
| 592 | srcu_ctlp = &srcu_ctld; |
| 593 | } |
| 594 | |
| 595 | static void srcu_torture_cleanup(void) |
| 596 | { |
Paul E. McKenney | f7194ac | 2018-04-05 17:19:17 -0700 | [diff] [blame] | 597 | static DEFINE_TORTURE_RANDOM(rand); |
| 598 | |
| 599 | if (torture_random(&rand) & 0x800) |
| 600 | cleanup_srcu_struct(&srcu_ctld); |
| 601 | else |
| 602 | cleanup_srcu_struct_quiesced(&srcu_ctld); |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 603 | srcu_ctlp = &srcu_ctl; /* In case of a later rcutorture run. */ |
| 604 | } |
| 605 | |
| 606 | /* As above, but dynamically allocated. */ |
| 607 | static struct rcu_torture_ops srcud_ops = { |
| 608 | .ttype = SRCU_FLAVOR, |
| 609 | .init = srcu_torture_init, |
| 610 | .cleanup = srcu_torture_cleanup, |
| 611 | .readlock = srcu_torture_read_lock, |
| 612 | .read_delay = srcu_read_delay, |
| 613 | .readunlock = srcu_torture_read_unlock, |
Paul E. McKenney | 17ef2fe | 2018-04-27 11:39:34 -0700 | [diff] [blame] | 614 | .get_gp_seq = srcu_torture_completed, |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 615 | .deferred_free = srcu_torture_deferred_free, |
| 616 | .sync = srcu_torture_synchronize, |
| 617 | .exp_sync = srcu_torture_synchronize_expedited, |
| 618 | .call = srcu_torture_call, |
| 619 | .cb_barrier = srcu_torture_barrier, |
| 620 | .stats = srcu_torture_stats, |
Paul E. McKenney | 5e741fa | 2017-06-06 12:52:44 -0700 | [diff] [blame] | 621 | .irq_capable = 1, |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 622 | .name = "srcud" |
| 623 | }; |
| 624 | |
Josh Triplett | 4b6c2cc | 2006-10-04 02:17:16 -0700 | [diff] [blame] | 625 | /* |
| 626 | * Definitions for sched torture testing. |
| 627 | */ |
| 628 | |
| 629 | static int sched_torture_read_lock(void) |
| 630 | { |
| 631 | preempt_disable(); |
| 632 | return 0; |
| 633 | } |
| 634 | |
| 635 | static void sched_torture_read_unlock(int idx) |
| 636 | { |
| 637 | preempt_enable(); |
| 638 | } |
| 639 | |
Paul E. McKenney | 2326974 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 640 | static void rcu_sched_torture_deferred_free(struct rcu_torture *p) |
| 641 | { |
| 642 | call_rcu_sched(&p->rtort_rcu, rcu_torture_cb); |
| 643 | } |
| 644 | |
Josh Triplett | 4b6c2cc | 2006-10-04 02:17:16 -0700 | [diff] [blame] | 645 | static struct rcu_torture_ops sched_ops = { |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 646 | .ttype = RCU_SCHED_FLAVOR, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 647 | .init = rcu_sync_torture_init, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 648 | .readlock = sched_torture_read_lock, |
| 649 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ |
| 650 | .readunlock = sched_torture_read_unlock, |
Paul E. McKenney | 17ef2fe | 2018-04-27 11:39:34 -0700 | [diff] [blame] | 651 | .get_gp_seq = rcu_sched_get_gp_seq, |
Paul E. McKenney | d7219312 | 2018-05-15 15:24:41 -0700 | [diff] [blame] | 652 | .gp_diff = rcu_seq_diff, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 653 | .deferred_free = rcu_sched_torture_deferred_free, |
Paul E. McKenney | bdf2a43 | 2011-06-07 16:59:35 -0700 | [diff] [blame] | 654 | .sync = synchronize_sched, |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 655 | .exp_sync = synchronize_sched_expedited, |
Paul E. McKenney | 2456005 | 2015-05-30 10:11:24 -0700 | [diff] [blame] | 656 | .get_state = get_state_synchronize_sched, |
| 657 | .cond_sync = cond_synchronize_sched, |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 658 | .call = call_rcu_sched, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 659 | .cb_barrier = rcu_barrier_sched, |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 660 | .fqs = rcu_sched_force_quiescent_state, |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 661 | .stats = NULL, |
| 662 | .irq_capable = 1, |
| 663 | .name = "sched" |
Josh Triplett | 4b6c2cc | 2006-10-04 02:17:16 -0700 | [diff] [blame] | 664 | }; |
| 665 | |
Paul E. McKenney | 69c6045 | 2014-07-01 11:59:36 -0700 | [diff] [blame] | 666 | /* |
| 667 | * Definitions for RCU-tasks torture testing. |
| 668 | */ |
| 669 | |
| 670 | static int tasks_torture_read_lock(void) |
| 671 | { |
| 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | static void tasks_torture_read_unlock(int idx) |
| 676 | { |
| 677 | } |
| 678 | |
| 679 | static void rcu_tasks_torture_deferred_free(struct rcu_torture *p) |
| 680 | { |
| 681 | call_rcu_tasks(&p->rtort_rcu, rcu_torture_cb); |
| 682 | } |
| 683 | |
| 684 | static struct rcu_torture_ops tasks_ops = { |
| 685 | .ttype = RCU_TASKS_FLAVOR, |
| 686 | .init = rcu_sync_torture_init, |
| 687 | .readlock = tasks_torture_read_lock, |
| 688 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ |
| 689 | .readunlock = tasks_torture_read_unlock, |
Paul E. McKenney | 17ef2fe | 2018-04-27 11:39:34 -0700 | [diff] [blame] | 690 | .get_gp_seq = rcu_no_completed, |
Paul E. McKenney | 69c6045 | 2014-07-01 11:59:36 -0700 | [diff] [blame] | 691 | .deferred_free = rcu_tasks_torture_deferred_free, |
| 692 | .sync = synchronize_rcu_tasks, |
| 693 | .exp_sync = synchronize_rcu_tasks, |
| 694 | .call = call_rcu_tasks, |
| 695 | .cb_barrier = rcu_barrier_tasks, |
| 696 | .fqs = NULL, |
| 697 | .stats = NULL, |
| 698 | .irq_capable = 1, |
| 699 | .name = "tasks" |
| 700 | }; |
| 701 | |
Paul E. McKenney | d7219312 | 2018-05-15 15:24:41 -0700 | [diff] [blame] | 702 | static unsigned long rcutorture_seq_diff(unsigned long new, unsigned long old) |
| 703 | { |
| 704 | if (!cur_ops->gp_diff) |
| 705 | return new - old; |
| 706 | return cur_ops->gp_diff(new, old); |
| 707 | } |
| 708 | |
Paul E. McKenney | 5be5d1a | 2015-06-30 08:57:57 -0700 | [diff] [blame] | 709 | static bool __maybe_unused torturing_tasks(void) |
| 710 | { |
| 711 | return cur_ops == &tasks_ops; |
| 712 | } |
| 713 | |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 714 | /* |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 715 | * RCU torture priority-boost testing. Runs one real-time thread per |
| 716 | * CPU for moderate bursts, repeatedly registering RCU callbacks and |
| 717 | * spinning waiting for them to be invoked. If a given callback takes |
| 718 | * too long to be invoked, we assume that priority inversion has occurred. |
| 719 | */ |
| 720 | |
| 721 | struct rcu_boost_inflight { |
| 722 | struct rcu_head rcu; |
| 723 | int inflight; |
| 724 | }; |
| 725 | |
| 726 | static void rcu_torture_boost_cb(struct rcu_head *head) |
| 727 | { |
| 728 | struct rcu_boost_inflight *rbip = |
| 729 | container_of(head, struct rcu_boost_inflight, rcu); |
| 730 | |
Paul E. McKenney | 6c7ed42 | 2015-04-13 11:58:08 -0700 | [diff] [blame] | 731 | /* Ensure RCU-core accesses precede clearing ->inflight */ |
| 732 | smp_store_release(&rbip->inflight, 0); |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | static int rcu_torture_boost(void *arg) |
| 736 | { |
| 737 | unsigned long call_rcu_time; |
| 738 | unsigned long endtime; |
| 739 | unsigned long oldstarttime; |
| 740 | struct rcu_boost_inflight rbi = { .inflight = 0 }; |
| 741 | struct sched_param sp; |
| 742 | |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 743 | VERBOSE_TOROUT_STRING("rcu_torture_boost started"); |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 744 | |
| 745 | /* Set real-time priority. */ |
| 746 | sp.sched_priority = 1; |
| 747 | if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) { |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 748 | VERBOSE_TOROUT_STRING("rcu_torture_boost RT prio failed!"); |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 749 | n_rcu_torture_boost_rterror++; |
| 750 | } |
| 751 | |
Paul E. McKenney | 561190e | 2011-03-30 09:10:44 -0700 | [diff] [blame] | 752 | init_rcu_head_on_stack(&rbi.rcu); |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 753 | /* Each pass through the following loop does one boost-test cycle. */ |
| 754 | do { |
| 755 | /* Wait for the next test interval. */ |
| 756 | oldstarttime = boost_starttime; |
Paul E. McKenney | 93898fb | 2011-08-17 12:39:34 -0700 | [diff] [blame] | 757 | while (ULONG_CMP_LT(jiffies, oldstarttime)) { |
Paul E. McKenney | 0e11c8e | 2013-01-10 16:21:07 -0800 | [diff] [blame] | 758 | schedule_timeout_interruptible(oldstarttime - jiffies); |
Paul E. McKenney | 628edaa | 2014-01-31 11:57:43 -0800 | [diff] [blame] | 759 | stutter_wait("rcu_torture_boost"); |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 760 | if (torture_must_stop()) |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 761 | goto checkwait; |
| 762 | } |
| 763 | |
| 764 | /* Do one boost-test interval. */ |
| 765 | endtime = oldstarttime + test_boost_duration * HZ; |
| 766 | call_rcu_time = jiffies; |
Paul E. McKenney | 93898fb | 2011-08-17 12:39:34 -0700 | [diff] [blame] | 767 | while (ULONG_CMP_LT(jiffies, endtime)) { |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 768 | /* If we don't have a callback in flight, post one. */ |
Paul E. McKenney | 6c7ed42 | 2015-04-13 11:58:08 -0700 | [diff] [blame] | 769 | if (!smp_load_acquire(&rbi.inflight)) { |
| 770 | /* RCU core before ->inflight = 1. */ |
| 771 | smp_store_release(&rbi.inflight, 1); |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 772 | call_rcu(&rbi.rcu, rcu_torture_boost_cb); |
| 773 | if (jiffies - call_rcu_time > |
| 774 | test_boost_duration * HZ - HZ / 2) { |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 775 | VERBOSE_TOROUT_STRING("rcu_torture_boost boosting failed"); |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 776 | n_rcu_torture_boost_failure++; |
| 777 | } |
| 778 | call_rcu_time = jiffies; |
| 779 | } |
Paul E. McKenney | 628edaa | 2014-01-31 11:57:43 -0800 | [diff] [blame] | 780 | stutter_wait("rcu_torture_boost"); |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 781 | if (torture_must_stop()) |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 782 | goto checkwait; |
| 783 | } |
| 784 | |
| 785 | /* |
| 786 | * Set the start time of the next test interval. |
| 787 | * Yes, this is vulnerable to long delays, but such |
| 788 | * delays simply cause a false negative for the next |
| 789 | * interval. Besides, we are running at RT priority, |
| 790 | * so delays should be relatively rare. |
| 791 | */ |
Paul E. McKenney | ab8f11e | 2011-08-18 09:30:32 -0700 | [diff] [blame] | 792 | while (oldstarttime == boost_starttime && |
| 793 | !kthread_should_stop()) { |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 794 | if (mutex_trylock(&boost_mutex)) { |
| 795 | boost_starttime = jiffies + |
| 796 | test_boost_interval * HZ; |
| 797 | n_rcu_torture_boosts++; |
| 798 | mutex_unlock(&boost_mutex); |
| 799 | break; |
| 800 | } |
| 801 | schedule_timeout_uninterruptible(1); |
| 802 | } |
| 803 | |
| 804 | /* Go do the stutter. */ |
Paul E. McKenney | 628edaa | 2014-01-31 11:57:43 -0800 | [diff] [blame] | 805 | checkwait: stutter_wait("rcu_torture_boost"); |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 806 | } while (!torture_must_stop()); |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 807 | |
| 808 | /* Clean up and exit. */ |
Paul E. McKenney | 6c7ed42 | 2015-04-13 11:58:08 -0700 | [diff] [blame] | 809 | while (!kthread_should_stop() || smp_load_acquire(&rbi.inflight)) { |
Paul E. McKenney | 7fafaac | 2014-01-31 17:37:28 -0800 | [diff] [blame] | 810 | torture_shutdown_absorb("rcu_torture_boost"); |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 811 | schedule_timeout_uninterruptible(1); |
Paul E. McKenney | 7fafaac | 2014-01-31 17:37:28 -0800 | [diff] [blame] | 812 | } |
Paul E. McKenney | 9d68197 | 2011-06-21 01:48:03 -0700 | [diff] [blame] | 813 | destroy_rcu_head_on_stack(&rbi.rcu); |
Paul E. McKenney | 7fafaac | 2014-01-31 17:37:28 -0800 | [diff] [blame] | 814 | torture_kthread_stopping("rcu_torture_boost"); |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 815 | return 0; |
| 816 | } |
| 817 | |
Paul E. McKenney | 38706bc | 2014-08-18 21:12:17 -0700 | [diff] [blame] | 818 | static void rcu_torture_cbflood_cb(struct rcu_head *rhp) |
| 819 | { |
| 820 | } |
| 821 | |
| 822 | /* |
| 823 | * RCU torture callback-flood kthread. Repeatedly induces bursts of calls |
| 824 | * to call_rcu() or analogous, increasing the probability of occurrence |
| 825 | * of callback-overflow corner cases. |
| 826 | */ |
| 827 | static int |
| 828 | rcu_torture_cbflood(void *arg) |
| 829 | { |
| 830 | int err = 1; |
| 831 | int i; |
| 832 | int j; |
| 833 | struct rcu_head *rhp; |
| 834 | |
| 835 | if (cbflood_n_per_burst > 0 && |
| 836 | cbflood_inter_holdoff > 0 && |
| 837 | cbflood_intra_holdoff > 0 && |
| 838 | cur_ops->call && |
| 839 | cur_ops->cb_barrier) { |
Kees Cook | 42bc47b | 2018-06-12 14:27:11 -0700 | [diff] [blame] | 840 | rhp = vmalloc(array3_size(cbflood_n_burst, |
| 841 | cbflood_n_per_burst, |
| 842 | sizeof(*rhp))); |
Paul E. McKenney | 38706bc | 2014-08-18 21:12:17 -0700 | [diff] [blame] | 843 | err = !rhp; |
| 844 | } |
| 845 | if (err) { |
| 846 | VERBOSE_TOROUT_STRING("rcu_torture_cbflood disabled: Bad args or OOM"); |
Paul E. McKenney | 3a0af33 | 2015-06-22 18:11:31 -0700 | [diff] [blame] | 847 | goto wait_for_stop; |
Paul E. McKenney | 38706bc | 2014-08-18 21:12:17 -0700 | [diff] [blame] | 848 | } |
| 849 | VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started"); |
| 850 | do { |
| 851 | schedule_timeout_interruptible(cbflood_inter_holdoff); |
| 852 | atomic_long_inc(&n_cbfloods); |
| 853 | WARN_ON(signal_pending(current)); |
| 854 | for (i = 0; i < cbflood_n_burst; i++) { |
| 855 | for (j = 0; j < cbflood_n_per_burst; j++) { |
| 856 | cur_ops->call(&rhp[i * cbflood_n_per_burst + j], |
| 857 | rcu_torture_cbflood_cb); |
| 858 | } |
| 859 | schedule_timeout_interruptible(cbflood_intra_holdoff); |
| 860 | WARN_ON(signal_pending(current)); |
| 861 | } |
| 862 | cur_ops->cb_barrier(); |
| 863 | stutter_wait("rcu_torture_cbflood"); |
| 864 | } while (!torture_must_stop()); |
Paul E. McKenney | b8969d1 | 2014-10-27 15:52:04 -0700 | [diff] [blame] | 865 | vfree(rhp); |
Paul E. McKenney | 3a0af33 | 2015-06-22 18:11:31 -0700 | [diff] [blame] | 866 | wait_for_stop: |
Paul E. McKenney | 38706bc | 2014-08-18 21:12:17 -0700 | [diff] [blame] | 867 | torture_kthread_stopping("rcu_torture_cbflood"); |
| 868 | return 0; |
| 869 | } |
| 870 | |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 871 | /* |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 872 | * RCU torture force-quiescent-state kthread. Repeatedly induces |
| 873 | * bursts of calls to force_quiescent_state(), increasing the probability |
| 874 | * of occurrence of some important types of race conditions. |
| 875 | */ |
| 876 | static int |
| 877 | rcu_torture_fqs(void *arg) |
| 878 | { |
| 879 | unsigned long fqs_resume_time; |
| 880 | int fqs_burst_remaining; |
| 881 | |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 882 | VERBOSE_TOROUT_STRING("rcu_torture_fqs task started"); |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 883 | do { |
| 884 | fqs_resume_time = jiffies + fqs_stutter * HZ; |
Paul E. McKenney | 93898fb | 2011-08-17 12:39:34 -0700 | [diff] [blame] | 885 | while (ULONG_CMP_LT(jiffies, fqs_resume_time) && |
| 886 | !kthread_should_stop()) { |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 887 | schedule_timeout_interruptible(1); |
| 888 | } |
| 889 | fqs_burst_remaining = fqs_duration; |
Paul E. McKenney | 93898fb | 2011-08-17 12:39:34 -0700 | [diff] [blame] | 890 | while (fqs_burst_remaining > 0 && |
| 891 | !kthread_should_stop()) { |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 892 | cur_ops->fqs(); |
| 893 | udelay(fqs_holdoff); |
| 894 | fqs_burst_remaining -= fqs_holdoff; |
| 895 | } |
Paul E. McKenney | 628edaa | 2014-01-31 11:57:43 -0800 | [diff] [blame] | 896 | stutter_wait("rcu_torture_fqs"); |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 897 | } while (!torture_must_stop()); |
Paul E. McKenney | 7fafaac | 2014-01-31 17:37:28 -0800 | [diff] [blame] | 898 | torture_kthread_stopping("rcu_torture_fqs"); |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 899 | return 0; |
| 900 | } |
| 901 | |
| 902 | /* |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 903 | * RCU torture writer kthread. Repeatedly substitutes a new structure |
| 904 | * for that pointed to by rcu_torture_current, freeing the old structure |
| 905 | * after a series of grace periods (the "pipeline"). |
| 906 | */ |
| 907 | static int |
| 908 | rcu_torture_writer(void *arg) |
| 909 | { |
Paul E. McKenney | 9efafb8 | 2015-12-31 18:11:47 -0800 | [diff] [blame] | 910 | bool can_expedite = !rcu_gp_is_expedited() && !rcu_gp_is_normal(); |
Paul E. McKenney | 4bb3c5f | 2015-02-18 16:31:29 -0800 | [diff] [blame] | 911 | int expediting = 0; |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 912 | unsigned long gp_snap; |
| 913 | bool gp_cond1 = gp_cond, gp_exp1 = gp_exp, gp_normal1 = gp_normal; |
Paul E. McKenney | f0bf8fa | 2014-03-21 16:17:56 -0700 | [diff] [blame] | 914 | bool gp_sync1 = gp_sync; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 915 | int i; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 916 | struct rcu_torture *rp; |
| 917 | struct rcu_torture *old_rp; |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 918 | static DEFINE_TORTURE_RANDOM(rand); |
Paul E. McKenney | f0bf8fa | 2014-03-21 16:17:56 -0700 | [diff] [blame] | 919 | int synctype[] = { RTWS_DEF_FREE, RTWS_EXP_SYNC, |
| 920 | RTWS_COND_GET, RTWS_SYNC }; |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 921 | int nsynctypes = 0; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 922 | |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 923 | VERBOSE_TOROUT_STRING("rcu_torture_writer task started"); |
Paul E. McKenney | f7c0e6a | 2017-12-08 11:37:24 -0800 | [diff] [blame] | 924 | if (!can_expedite) |
Paul E. McKenney | aa5a898 | 2015-12-31 16:27:06 -0800 | [diff] [blame] | 925 | pr_alert("%s" TORTURE_FLAG |
Paul E. McKenney | f7c0e6a | 2017-12-08 11:37:24 -0800 | [diff] [blame] | 926 | " GP expediting controlled from boot/sysfs for %s.\n", |
Paul E. McKenney | aa5a898 | 2015-12-31 16:27:06 -0800 | [diff] [blame] | 927 | torture_type, cur_ops->name); |
Ingo Molnar | dbdf65b | 2005-11-13 16:07:22 -0800 | [diff] [blame] | 928 | |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 929 | /* Initialize synctype[] array. If none set, take default. */ |
Paul E. McKenney | c136f99 | 2015-02-19 12:15:19 -0800 | [diff] [blame] | 930 | if (!gp_cond1 && !gp_exp1 && !gp_normal1 && !gp_sync1) |
Paul E. McKenney | f0bf8fa | 2014-03-21 16:17:56 -0700 | [diff] [blame] | 931 | gp_cond1 = gp_exp1 = gp_normal1 = gp_sync1 = true; |
Paul E. McKenney | db0c1a8 | 2017-12-08 12:23:10 -0800 | [diff] [blame] | 932 | if (gp_cond1 && cur_ops->get_state && cur_ops->cond_sync) { |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 933 | synctype[nsynctypes++] = RTWS_COND_GET; |
Paul E. McKenney | db0c1a8 | 2017-12-08 12:23:10 -0800 | [diff] [blame] | 934 | pr_info("%s: Testing conditional GPs.\n", __func__); |
| 935 | } else if (gp_cond && (!cur_ops->get_state || !cur_ops->cond_sync)) { |
Paul E. McKenney | e0d31a34c | 2017-12-01 15:22:38 -0800 | [diff] [blame] | 936 | pr_alert("%s: gp_cond without primitives.\n", __func__); |
Paul E. McKenney | db0c1a8 | 2017-12-08 12:23:10 -0800 | [diff] [blame] | 937 | } |
| 938 | if (gp_exp1 && cur_ops->exp_sync) { |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 939 | synctype[nsynctypes++] = RTWS_EXP_SYNC; |
Paul E. McKenney | db0c1a8 | 2017-12-08 12:23:10 -0800 | [diff] [blame] | 940 | pr_info("%s: Testing expedited GPs.\n", __func__); |
| 941 | } else if (gp_exp && !cur_ops->exp_sync) { |
Paul E. McKenney | e0d31a34c | 2017-12-01 15:22:38 -0800 | [diff] [blame] | 942 | pr_alert("%s: gp_exp without primitives.\n", __func__); |
Paul E. McKenney | db0c1a8 | 2017-12-08 12:23:10 -0800 | [diff] [blame] | 943 | } |
| 944 | if (gp_normal1 && cur_ops->deferred_free) { |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 945 | synctype[nsynctypes++] = RTWS_DEF_FREE; |
Paul E. McKenney | db0c1a8 | 2017-12-08 12:23:10 -0800 | [diff] [blame] | 946 | pr_info("%s: Testing asynchronous GPs.\n", __func__); |
| 947 | } else if (gp_normal && !cur_ops->deferred_free) { |
Paul E. McKenney | e0d31a34c | 2017-12-01 15:22:38 -0800 | [diff] [blame] | 948 | pr_alert("%s: gp_normal without primitives.\n", __func__); |
Paul E. McKenney | db0c1a8 | 2017-12-08 12:23:10 -0800 | [diff] [blame] | 949 | } |
| 950 | if (gp_sync1 && cur_ops->sync) { |
Paul E. McKenney | f0bf8fa | 2014-03-21 16:17:56 -0700 | [diff] [blame] | 951 | synctype[nsynctypes++] = RTWS_SYNC; |
Paul E. McKenney | db0c1a8 | 2017-12-08 12:23:10 -0800 | [diff] [blame] | 952 | pr_info("%s: Testing normal GPs.\n", __func__); |
| 953 | } else if (gp_sync && !cur_ops->sync) { |
Paul E. McKenney | e0d31a34c | 2017-12-01 15:22:38 -0800 | [diff] [blame] | 954 | pr_alert("%s: gp_sync without primitives.\n", __func__); |
Paul E. McKenney | db0c1a8 | 2017-12-08 12:23:10 -0800 | [diff] [blame] | 955 | } |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 956 | if (WARN_ONCE(nsynctypes == 0, |
| 957 | "rcu_torture_writer: No update-side primitives.\n")) { |
Paul E. McKenney | f0bf8fa | 2014-03-21 16:17:56 -0700 | [diff] [blame] | 958 | /* |
| 959 | * No updates primitives, so don't try updating. |
| 960 | * The resulting test won't be testing much, hence the |
| 961 | * above WARN_ONCE(). |
| 962 | */ |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 963 | rcu_torture_writer_state = RTWS_STOPPING; |
| 964 | torture_kthread_stopping("rcu_torture_writer"); |
| 965 | } |
| 966 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 967 | do { |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 968 | rcu_torture_writer_state = RTWS_FIXED_DELAY; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 969 | schedule_timeout_uninterruptible(1); |
Paul E. McKenney | a71fca5 | 2009-09-18 10:28:19 -0700 | [diff] [blame] | 970 | rp = rcu_torture_alloc(); |
| 971 | if (rp == NULL) |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 972 | continue; |
| 973 | rp->rtort_pipe_count = 0; |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 974 | rcu_torture_writer_state = RTWS_DELAY; |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 975 | udelay(torture_random(&rand) & 0x3ff); |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 976 | rcu_torture_writer_state = RTWS_REPLACE; |
Paul E. McKenney | 0ddea0e | 2010-09-19 21:06:14 -0700 | [diff] [blame] | 977 | old_rp = rcu_dereference_check(rcu_torture_current, |
| 978 | current == writer_task); |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 979 | rp->rtort_mbtest = 1; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 980 | rcu_assign_pointer(rcu_torture_current, rp); |
Paul E. McKenney | 9b2619a | 2009-09-23 09:50:43 -0700 | [diff] [blame] | 981 | smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */ |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 982 | if (old_rp) { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 983 | i = old_rp->rtort_pipe_count; |
| 984 | if (i > RCU_TORTURE_PIPE_LEN) |
| 985 | i = RCU_TORTURE_PIPE_LEN; |
| 986 | atomic_inc(&rcu_torture_wcount[i]); |
| 987 | old_rp->rtort_pipe_count++; |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 988 | switch (synctype[torture_random(&rand) % nsynctypes]) { |
| 989 | case RTWS_DEF_FREE: |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 990 | rcu_torture_writer_state = RTWS_DEF_FREE; |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 991 | cur_ops->deferred_free(old_rp); |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 992 | break; |
| 993 | case RTWS_EXP_SYNC: |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 994 | rcu_torture_writer_state = RTWS_EXP_SYNC; |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 995 | cur_ops->exp_sync(); |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 996 | rcu_torture_pipe_update(old_rp); |
| 997 | break; |
| 998 | case RTWS_COND_GET: |
| 999 | rcu_torture_writer_state = RTWS_COND_GET; |
| 1000 | gp_snap = cur_ops->get_state(); |
| 1001 | i = torture_random(&rand) % 16; |
| 1002 | if (i != 0) |
| 1003 | schedule_timeout_interruptible(i); |
| 1004 | udelay(torture_random(&rand) % 1000); |
| 1005 | rcu_torture_writer_state = RTWS_COND_SYNC; |
| 1006 | cur_ops->cond_sync(gp_snap); |
| 1007 | rcu_torture_pipe_update(old_rp); |
| 1008 | break; |
Paul E. McKenney | f0bf8fa | 2014-03-21 16:17:56 -0700 | [diff] [blame] | 1009 | case RTWS_SYNC: |
| 1010 | rcu_torture_writer_state = RTWS_SYNC; |
| 1011 | cur_ops->sync(); |
| 1012 | rcu_torture_pipe_update(old_rp); |
| 1013 | break; |
Paul E. McKenney | a48f3fa | 2014-03-18 15:57:41 -0700 | [diff] [blame] | 1014 | default: |
| 1015 | WARN_ON_ONCE(1); |
| 1016 | break; |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 1017 | } |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1018 | } |
Paul E. McKenney | 6bea2cc | 2018-05-16 15:30:36 -0700 | [diff] [blame] | 1019 | rcu_torture_current_version++; |
Paul E. McKenney | 4bb3c5f | 2015-02-18 16:31:29 -0800 | [diff] [blame] | 1020 | /* Cycle through nesting levels of rcu_expedite_gp() calls. */ |
| 1021 | if (can_expedite && |
| 1022 | !(torture_random(&rand) & 0xff & (!!expediting - 1))) { |
| 1023 | WARN_ON_ONCE(expediting == 0 && rcu_gp_is_expedited()); |
| 1024 | if (expediting >= 0) |
| 1025 | rcu_expedite_gp(); |
| 1026 | else |
| 1027 | rcu_unexpedite_gp(); |
| 1028 | if (++expediting > 3) |
| 1029 | expediting = -expediting; |
Paul E. McKenney | f7c0e6a | 2017-12-08 11:37:24 -0800 | [diff] [blame] | 1030 | } else if (!can_expedite) { /* Disabled during boot, recheck. */ |
| 1031 | can_expedite = !rcu_gp_is_expedited() && |
| 1032 | !rcu_gp_is_normal(); |
Paul E. McKenney | 4bb3c5f | 2015-02-18 16:31:29 -0800 | [diff] [blame] | 1033 | } |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 1034 | rcu_torture_writer_state = RTWS_STUTTER; |
Paul E. McKenney | 628edaa | 2014-01-31 11:57:43 -0800 | [diff] [blame] | 1035 | stutter_wait("rcu_torture_writer"); |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 1036 | } while (!torture_must_stop()); |
Paul E. McKenney | 4bb3c5f | 2015-02-18 16:31:29 -0800 | [diff] [blame] | 1037 | /* Reset expediting back to unexpedited. */ |
| 1038 | if (expediting > 0) |
| 1039 | expediting = -expediting; |
| 1040 | while (can_expedite && expediting++ < 0) |
| 1041 | rcu_unexpedite_gp(); |
| 1042 | WARN_ON_ONCE(can_expedite && rcu_gp_is_expedited()); |
Paul E. McKenney | f7c0e6a | 2017-12-08 11:37:24 -0800 | [diff] [blame] | 1043 | if (!can_expedite) |
| 1044 | pr_alert("%s" TORTURE_FLAG |
| 1045 | " Dynamic grace-period expediting was disabled.\n", |
| 1046 | torture_type); |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 1047 | rcu_torture_writer_state = RTWS_STOPPING; |
Paul E. McKenney | 7fafaac | 2014-01-31 17:37:28 -0800 | [diff] [blame] | 1048 | torture_kthread_stopping("rcu_torture_writer"); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1049 | return 0; |
| 1050 | } |
| 1051 | |
| 1052 | /* |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 1053 | * RCU torture fake writer kthread. Repeatedly calls sync, with a random |
| 1054 | * delay between calls. |
| 1055 | */ |
| 1056 | static int |
| 1057 | rcu_torture_fakewriter(void *arg) |
| 1058 | { |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 1059 | DEFINE_TORTURE_RANDOM(rand); |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 1060 | |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 1061 | VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task started"); |
Linus Torvalds | 971eae7 | 2014-03-31 11:21:19 -0700 | [diff] [blame] | 1062 | set_user_nice(current, MAX_NICE); |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 1063 | |
| 1064 | do { |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 1065 | schedule_timeout_uninterruptible(1 + torture_random(&rand)%10); |
| 1066 | udelay(torture_random(&rand) & 0x3ff); |
Paul E. McKenney | 72472a0 | 2012-05-29 17:50:51 -0700 | [diff] [blame] | 1067 | if (cur_ops->cb_barrier != NULL && |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 1068 | torture_random(&rand) % (nfakewriters * 8) == 0) { |
Paul E. McKenney | 72472a0 | 2012-05-29 17:50:51 -0700 | [diff] [blame] | 1069 | cur_ops->cb_barrier(); |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 1070 | } else if (gp_normal == gp_exp) { |
Paul E. McKenney | eb03399 | 2017-12-08 10:48:41 -0800 | [diff] [blame] | 1071 | if (cur_ops->sync && torture_random(&rand) & 0x80) |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 1072 | cur_ops->sync(); |
Paul E. McKenney | eb03399 | 2017-12-08 10:48:41 -0800 | [diff] [blame] | 1073 | else if (cur_ops->exp_sync) |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 1074 | cur_ops->exp_sync(); |
Paul E. McKenney | eb03399 | 2017-12-08 10:48:41 -0800 | [diff] [blame] | 1075 | } else if (gp_normal && cur_ops->sync) { |
Paul E. McKenney | 72472a0 | 2012-05-29 17:50:51 -0700 | [diff] [blame] | 1076 | cur_ops->sync(); |
Paul E. McKenney | eb03399 | 2017-12-08 10:48:41 -0800 | [diff] [blame] | 1077 | } else if (cur_ops->exp_sync) { |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 1078 | cur_ops->exp_sync(); |
| 1079 | } |
Paul E. McKenney | 628edaa | 2014-01-31 11:57:43 -0800 | [diff] [blame] | 1080 | stutter_wait("rcu_torture_fakewriter"); |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 1081 | } while (!torture_must_stop()); |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 1082 | |
Paul E. McKenney | 7fafaac | 2014-01-31 17:37:28 -0800 | [diff] [blame] | 1083 | torture_kthread_stopping("rcu_torture_fakewriter"); |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 1084 | return 0; |
| 1085 | } |
| 1086 | |
Paul E. McKenney | f34c8585 | 2017-07-20 15:27:32 -0700 | [diff] [blame] | 1087 | static void rcu_torture_timer_cb(struct rcu_head *rhp) |
| 1088 | { |
| 1089 | kfree(rhp); |
| 1090 | } |
| 1091 | |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 1092 | /* |
Paul E. McKenney | 6b06aa7 | 2018-05-22 10:56:05 -0700 | [diff] [blame] | 1093 | * Do one read-side critical section, returning false if there was |
| 1094 | * no data to read. Can be invoked both from process context and |
| 1095 | * from a timer handler. |
| 1096 | */ |
| 1097 | static bool rcu_torture_one_read(struct torture_random_state *trsp) |
| 1098 | { |
| 1099 | int idx; |
| 1100 | unsigned long started; |
| 1101 | unsigned long completed; |
| 1102 | struct rcu_torture *p; |
| 1103 | int pipe_count; |
| 1104 | unsigned long long ts; |
| 1105 | |
| 1106 | idx = cur_ops->readlock(); |
| 1107 | started = cur_ops->get_gp_seq(); |
| 1108 | ts = rcu_trace_clock_local(); |
| 1109 | p = rcu_dereference_check(rcu_torture_current, |
| 1110 | rcu_read_lock_bh_held() || |
| 1111 | rcu_read_lock_sched_held() || |
| 1112 | srcu_read_lock_held(srcu_ctlp) || |
| 1113 | torturing_tasks()); |
| 1114 | if (p == NULL) { |
| 1115 | /* Wait for rcu_torture_writer to get underway */ |
| 1116 | cur_ops->readunlock(idx); |
| 1117 | return false; |
| 1118 | } |
| 1119 | if (p->rtort_mbtest == 0) |
| 1120 | atomic_inc(&n_rcu_torture_mberror); |
| 1121 | cur_ops->read_delay(trsp); |
| 1122 | preempt_disable(); |
| 1123 | pipe_count = p->rtort_pipe_count; |
| 1124 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { |
| 1125 | /* Should not happen, but... */ |
| 1126 | pipe_count = RCU_TORTURE_PIPE_LEN; |
| 1127 | } |
| 1128 | completed = cur_ops->get_gp_seq(); |
| 1129 | if (pipe_count > 1) { |
| 1130 | do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, |
| 1131 | ts, started, completed); |
| 1132 | rcu_ftrace_dump(DUMP_ALL); |
| 1133 | } |
| 1134 | __this_cpu_inc(rcu_torture_count[pipe_count]); |
| 1135 | completed = rcutorture_seq_diff(completed, started); |
| 1136 | if (completed > RCU_TORTURE_PIPE_LEN) { |
| 1137 | /* Should not happen, but... */ |
| 1138 | completed = RCU_TORTURE_PIPE_LEN; |
| 1139 | } |
| 1140 | __this_cpu_inc(rcu_torture_batch[completed]); |
| 1141 | preempt_enable(); |
| 1142 | cur_ops->readunlock(idx); |
| 1143 | return true; |
| 1144 | } |
| 1145 | |
Paul E. McKenney | 3025520e | 2018-05-22 11:38:47 -0700 | [diff] [blame^] | 1146 | static DEFINE_TORTURE_RANDOM_PERCPU(rcu_torture_timer_rand); |
| 1147 | |
Paul E. McKenney | 6b06aa7 | 2018-05-22 10:56:05 -0700 | [diff] [blame] | 1148 | /* |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 1149 | * RCU torture reader from timer handler. Dereferences rcu_torture_current, |
| 1150 | * incrementing the corresponding element of the pipeline array. The |
| 1151 | * counter in the element should never be greater than 1, otherwise, the |
| 1152 | * RCU implementation is broken. |
| 1153 | */ |
Kees Cook | fd30b71 | 2017-10-22 17:58:54 -0700 | [diff] [blame] | 1154 | static void rcu_torture_timer(struct timer_list *unused) |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 1155 | { |
| 1156 | int idx; |
Paul E. McKenney | 917963d | 2014-11-21 17:10:16 -0800 | [diff] [blame] | 1157 | unsigned long started; |
Paul E. McKenney | 6b80da4 | 2014-11-21 14:19:26 -0800 | [diff] [blame] | 1158 | unsigned long completed; |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 1159 | struct rcu_torture *p; |
| 1160 | int pipe_count; |
Paul E. McKenney | 3025520e | 2018-05-22 11:38:47 -0700 | [diff] [blame^] | 1161 | struct torture_random_state *trsp; |
Paul E. McKenney | 5249453 | 2012-11-14 16:26:40 -0800 | [diff] [blame] | 1162 | unsigned long long ts; |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 1163 | |
Paul E. McKenney | 3025520e | 2018-05-22 11:38:47 -0700 | [diff] [blame^] | 1164 | trsp = this_cpu_ptr(&rcu_torture_timer_rand); |
Paul E. McKenney | 8da9a59 | 2018-05-22 11:17:51 -0700 | [diff] [blame] | 1165 | atomic_long_inc(&n_rcu_torture_timers); |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 1166 | idx = cur_ops->readlock(); |
Paul E. McKenney | 17ef2fe | 2018-04-27 11:39:34 -0700 | [diff] [blame] | 1167 | started = cur_ops->get_gp_seq(); |
Steven Rostedt | e4aa0da | 2013-02-04 13:36:13 -0500 | [diff] [blame] | 1168 | ts = rcu_trace_clock_local(); |
Paul E. McKenney | 632ee20 | 2010-02-22 17:04:45 -0800 | [diff] [blame] | 1169 | p = rcu_dereference_check(rcu_torture_current, |
Paul E. McKenney | 632ee20 | 2010-02-22 17:04:45 -0800 | [diff] [blame] | 1170 | rcu_read_lock_bh_held() || |
| 1171 | rcu_read_lock_sched_held() || |
Paul E. McKenney | 5be5d1a | 2015-06-30 08:57:57 -0700 | [diff] [blame] | 1172 | srcu_read_lock_held(srcu_ctlp) || |
| 1173 | torturing_tasks()); |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 1174 | if (p == NULL) { |
| 1175 | /* Leave because rcu_torture_writer is not yet underway */ |
| 1176 | cur_ops->readunlock(idx); |
| 1177 | return; |
| 1178 | } |
| 1179 | if (p->rtort_mbtest == 0) |
| 1180 | atomic_inc(&n_rcu_torture_mberror); |
Paul E. McKenney | 3025520e | 2018-05-22 11:38:47 -0700 | [diff] [blame^] | 1181 | cur_ops->read_delay(trsp); |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 1182 | preempt_disable(); |
| 1183 | pipe_count = p->rtort_pipe_count; |
| 1184 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { |
| 1185 | /* Should not happen, but... */ |
| 1186 | pipe_count = RCU_TORTURE_PIPE_LEN; |
| 1187 | } |
Paul E. McKenney | 17ef2fe | 2018-04-27 11:39:34 -0700 | [diff] [blame] | 1188 | completed = cur_ops->get_gp_seq(); |
Paul E. McKenney | 5249453 | 2012-11-14 16:26:40 -0800 | [diff] [blame] | 1189 | if (pipe_count > 1) { |
Paul E. McKenney | 5249453 | 2012-11-14 16:26:40 -0800 | [diff] [blame] | 1190 | do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, ts, |
Paul E. McKenney | 917963d | 2014-11-21 17:10:16 -0800 | [diff] [blame] | 1191 | started, completed); |
Paul E. McKenney | 274529b | 2016-03-21 19:46:04 -0700 | [diff] [blame] | 1192 | rcu_ftrace_dump(DUMP_ALL); |
Paul E. McKenney | 5249453 | 2012-11-14 16:26:40 -0800 | [diff] [blame] | 1193 | } |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 1194 | __this_cpu_inc(rcu_torture_count[pipe_count]); |
Paul E. McKenney | d7219312 | 2018-05-15 15:24:41 -0700 | [diff] [blame] | 1195 | completed = rcutorture_seq_diff(completed, started); |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 1196 | if (completed > RCU_TORTURE_PIPE_LEN) { |
| 1197 | /* Should not happen, but... */ |
| 1198 | completed = RCU_TORTURE_PIPE_LEN; |
| 1199 | } |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 1200 | __this_cpu_inc(rcu_torture_batch[completed]); |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 1201 | preempt_enable(); |
| 1202 | cur_ops->readunlock(idx); |
Paul E. McKenney | f34c8585 | 2017-07-20 15:27:32 -0700 | [diff] [blame] | 1203 | |
| 1204 | /* Test call_rcu() invocation from interrupt handler. */ |
| 1205 | if (cur_ops->call) { |
| 1206 | struct rcu_head *rhp = kmalloc(sizeof(*rhp), GFP_NOWAIT); |
| 1207 | |
| 1208 | if (rhp) |
| 1209 | cur_ops->call(rhp, rcu_torture_timer_cb); |
| 1210 | } |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | /* |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1214 | * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current, |
| 1215 | * incrementing the corresponding element of the pipeline array. The |
| 1216 | * counter in the element should never be greater than 1, otherwise, the |
| 1217 | * RCU implementation is broken. |
| 1218 | */ |
| 1219 | static int |
| 1220 | rcu_torture_reader(void *arg) |
| 1221 | { |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 1222 | DEFINE_TORTURE_RANDOM(rand); |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 1223 | struct timer_list t; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1224 | |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 1225 | VERBOSE_TOROUT_STRING("rcu_torture_reader task started"); |
Linus Torvalds | 971eae7 | 2014-03-31 11:21:19 -0700 | [diff] [blame] | 1226 | set_user_nice(current, MAX_NICE); |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 1227 | if (irqreader && cur_ops->irq_capable) |
Kees Cook | fd30b71 | 2017-10-22 17:58:54 -0700 | [diff] [blame] | 1228 | timer_setup_on_stack(&t, rcu_torture_timer, 0); |
Ingo Molnar | dbdf65b | 2005-11-13 16:07:22 -0800 | [diff] [blame] | 1229 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1230 | do { |
Paul E. McKenney | 0acc512 | 2009-06-25 09:08:17 -0700 | [diff] [blame] | 1231 | if (irqreader && cur_ops->irq_capable) { |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 1232 | if (!timer_pending(&t)) |
Paul E. McKenney | 6155fec | 2010-02-22 17:05:04 -0800 | [diff] [blame] | 1233 | mod_timer(&t, jiffies + 1); |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 1234 | } |
Paul E. McKenney | 6b06aa7 | 2018-05-22 10:56:05 -0700 | [diff] [blame] | 1235 | if (!rcu_torture_one_read(&rand)) |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1236 | schedule_timeout_interruptible(HZ); |
Paul E. McKenney | 628edaa | 2014-01-31 11:57:43 -0800 | [diff] [blame] | 1237 | stutter_wait("rcu_torture_reader"); |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 1238 | } while (!torture_must_stop()); |
Thomas Gleixner | 424c1b6 | 2014-03-23 08:58:27 -0700 | [diff] [blame] | 1239 | if (irqreader && cur_ops->irq_capable) { |
Paul E. McKenney | 0729fbf | 2008-06-25 12:24:52 -0700 | [diff] [blame] | 1240 | del_timer_sync(&t); |
Thomas Gleixner | 424c1b6 | 2014-03-23 08:58:27 -0700 | [diff] [blame] | 1241 | destroy_timer_on_stack(&t); |
| 1242 | } |
Paul E. McKenney | 7fafaac | 2014-01-31 17:37:28 -0800 | [diff] [blame] | 1243 | torture_kthread_stopping("rcu_torture_reader"); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1244 | return 0; |
| 1245 | } |
| 1246 | |
| 1247 | /* |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 1248 | * Print torture statistics. Caller must ensure that there is only |
| 1249 | * one call to this function at a given time!!! This is normally |
| 1250 | * accomplished by relying on the module system to only have one copy |
| 1251 | * of the module loaded, and then by giving the rcu_torture_stats |
| 1252 | * kthread full control (or the init/cleanup functions when rcu_torture_stats |
| 1253 | * thread is not running). |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1254 | */ |
Chen Gang | d100895 | 2013-11-07 10:30:25 +0800 | [diff] [blame] | 1255 | static void |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 1256 | rcu_torture_stats_print(void) |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1257 | { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1258 | int cpu; |
| 1259 | int i; |
| 1260 | long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; |
| 1261 | long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 1262 | static unsigned long rtcv_snap = ULONG_MAX; |
Paul E. McKenney | 0032f4e | 2017-08-30 10:40:17 -0700 | [diff] [blame] | 1263 | static bool splatted; |
Paul E. McKenney | 4ffa669 | 2016-06-30 11:56:38 -0700 | [diff] [blame] | 1264 | struct task_struct *wtp; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1265 | |
KAMEZAWA Hiroyuki | 0a94502 | 2006-03-28 01:56:37 -0800 | [diff] [blame] | 1266 | for_each_possible_cpu(cpu) { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1267 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
| 1268 | pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i]; |
| 1269 | batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i]; |
| 1270 | } |
| 1271 | } |
| 1272 | for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) { |
| 1273 | if (pipesummary[i] != 0) |
| 1274 | break; |
| 1275 | } |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 1276 | |
| 1277 | pr_alert("%s%s ", torture_type, TORTURE_FLAG); |
| 1278 | pr_cont("rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ", |
| 1279 | rcu_torture_current, |
| 1280 | rcu_torture_current_version, |
| 1281 | list_empty(&rcu_torture_freelist), |
| 1282 | atomic_read(&n_rcu_torture_alloc), |
| 1283 | atomic_read(&n_rcu_torture_alloc_fail), |
| 1284 | atomic_read(&n_rcu_torture_free)); |
SeongJae Park | 472213a | 2016-08-13 15:54:35 +0900 | [diff] [blame] | 1285 | pr_cont("rtmbe: %d rtbe: %ld rtbke: %ld rtbre: %ld ", |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 1286 | atomic_read(&n_rcu_torture_mberror), |
SeongJae Park | 472213a | 2016-08-13 15:54:35 +0900 | [diff] [blame] | 1287 | n_rcu_torture_barrier_error, |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 1288 | n_rcu_torture_boost_ktrerror, |
| 1289 | n_rcu_torture_boost_rterror); |
| 1290 | pr_cont("rtbf: %ld rtb: %ld nt: %ld ", |
| 1291 | n_rcu_torture_boost_failure, |
| 1292 | n_rcu_torture_boosts, |
Paul E. McKenney | 8da9a59 | 2018-05-22 11:17:51 -0700 | [diff] [blame] | 1293 | atomic_long_read(&n_rcu_torture_timers)); |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 1294 | torture_onoff_stats(); |
Paul E. McKenney | 38706bc | 2014-08-18 21:12:17 -0700 | [diff] [blame] | 1295 | pr_cont("barrier: %ld/%ld:%ld ", |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 1296 | n_barrier_successes, |
| 1297 | n_barrier_attempts, |
| 1298 | n_rcu_torture_barrier_error); |
Paul E. McKenney | 38706bc | 2014-08-18 21:12:17 -0700 | [diff] [blame] | 1299 | pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods)); |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 1300 | |
| 1301 | pr_alert("%s%s ", torture_type, TORTURE_FLAG); |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1302 | if (atomic_read(&n_rcu_torture_mberror) != 0 || |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1303 | n_rcu_torture_barrier_error != 0 || |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1304 | n_rcu_torture_boost_ktrerror != 0 || |
| 1305 | n_rcu_torture_boost_rterror != 0 || |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1306 | n_rcu_torture_boost_failure != 0 || |
| 1307 | i > 1) { |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 1308 | pr_cont("%s", "!!! "); |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 1309 | atomic_inc(&n_rcu_torture_error); |
Ingo Molnar | 5af970a | 2008-06-18 10:09:48 +0200 | [diff] [blame] | 1310 | WARN_ON_ONCE(1); |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 1311 | } |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 1312 | pr_cont("Reader Pipe: "); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1313 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 1314 | pr_cont(" %ld", pipesummary[i]); |
| 1315 | pr_cont("\n"); |
| 1316 | |
| 1317 | pr_alert("%s%s ", torture_type, TORTURE_FLAG); |
| 1318 | pr_cont("Reader Batch: "); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 1319 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 1320 | pr_cont(" %ld", batchsummary[i]); |
| 1321 | pr_cont("\n"); |
| 1322 | |
| 1323 | pr_alert("%s%s ", torture_type, TORTURE_FLAG); |
| 1324 | pr_cont("Free-Block Circulation: "); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1325 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 1326 | pr_cont(" %d", atomic_read(&rcu_torture_wcount[i])); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1327 | } |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 1328 | pr_cont("\n"); |
| 1329 | |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 1330 | if (cur_ops->stats) |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 1331 | cur_ops->stats(); |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 1332 | if (rtcv_snap == rcu_torture_current_version && |
| 1333 | rcu_torture_current != NULL) { |
Paul E. McKenney | 7f6733c | 2017-04-18 17:17:35 -0700 | [diff] [blame] | 1334 | int __maybe_unused flags = 0; |
Paul E. McKenney | aebc826 | 2018-05-01 06:42:51 -0700 | [diff] [blame] | 1335 | unsigned long __maybe_unused gp_seq = 0; |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 1336 | |
| 1337 | rcutorture_get_gp_data(cur_ops->ttype, |
Paul E. McKenney | aebc826 | 2018-05-01 06:42:51 -0700 | [diff] [blame] | 1338 | &flags, &gp_seq); |
Paul E. McKenney | 7f6733c | 2017-04-18 17:17:35 -0700 | [diff] [blame] | 1339 | srcutorture_get_gp_data(cur_ops->ttype, srcu_ctlp, |
Paul E. McKenney | aebc826 | 2018-05-01 06:42:51 -0700 | [diff] [blame] | 1340 | &flags, &gp_seq); |
Paul E. McKenney | 4ffa669 | 2016-06-30 11:56:38 -0700 | [diff] [blame] | 1341 | wtp = READ_ONCE(writer_task); |
Paul E. McKenney | aebc826 | 2018-05-01 06:42:51 -0700 | [diff] [blame] | 1342 | pr_alert("??? Writer stall state %s(%d) g%lu f%#x ->state %#lx cpu %d\n", |
Paul E. McKenney | 18aff33 | 2015-11-17 13:35:28 -0800 | [diff] [blame] | 1343 | rcu_torture_writer_state_getname(), |
Paul E. McKenney | aebc826 | 2018-05-01 06:42:51 -0700 | [diff] [blame] | 1344 | rcu_torture_writer_state, gp_seq, flags, |
Paul E. McKenney | 808de39 | 2017-06-19 10:03:22 -0700 | [diff] [blame] | 1345 | wtp == NULL ? ~0UL : wtp->state, |
| 1346 | wtp == NULL ? -1 : (int)task_cpu(wtp)); |
Paul E. McKenney | 0032f4e | 2017-08-30 10:40:17 -0700 | [diff] [blame] | 1347 | if (!splatted && wtp) { |
| 1348 | sched_show_task(wtp); |
| 1349 | splatted = true; |
| 1350 | } |
Paul E. McKenney | afea227 | 2014-03-12 07:10:41 -0700 | [diff] [blame] | 1351 | show_rcu_gp_kthreads(); |
Paul E. McKenney | 274529b | 2016-03-21 19:46:04 -0700 | [diff] [blame] | 1352 | rcu_ftrace_dump(DUMP_ALL); |
Paul E. McKenney | ad0dc7f | 2014-02-19 10:51:42 -0800 | [diff] [blame] | 1353 | } |
| 1354 | rtcv_snap = rcu_torture_current_version; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | /* |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1358 | * Periodically prints torture statistics, if periodic statistics printing |
| 1359 | * was specified via the stat_interval module parameter. |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1360 | */ |
| 1361 | static int |
| 1362 | rcu_torture_stats(void *arg) |
| 1363 | { |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 1364 | VERBOSE_TOROUT_STRING("rcu_torture_stats task started"); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1365 | do { |
| 1366 | schedule_timeout_interruptible(stat_interval * HZ); |
| 1367 | rcu_torture_stats_print(); |
Paul E. McKenney | f67a335 | 2014-01-29 07:40:27 -0800 | [diff] [blame] | 1368 | torture_shutdown_absorb("rcu_torture_stats"); |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 1369 | } while (!torture_must_stop()); |
Paul E. McKenney | 7fafaac | 2014-01-31 17:37:28 -0800 | [diff] [blame] | 1370 | torture_kthread_stopping("rcu_torture_stats"); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1371 | return 0; |
| 1372 | } |
| 1373 | |
Paul E. McKenney | 95c3832 | 2006-03-24 03:15:58 -0800 | [diff] [blame] | 1374 | static inline void |
Steven Rostedt (Red Hat) | e66c33d | 2013-07-12 16:50:28 -0400 | [diff] [blame] | 1375 | rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag) |
Paul E. McKenney | 95c3832 | 2006-03-24 03:15:58 -0800 | [diff] [blame] | 1376 | { |
Paul E. McKenney | 2caa1e4 | 2012-08-09 16:30:45 -0700 | [diff] [blame] | 1377 | pr_alert("%s" TORTURE_FLAG |
| 1378 | "--- %s: nreaders=%d nfakewriters=%d " |
| 1379 | "stat_interval=%d verbose=%d test_no_idle_hz=%d " |
| 1380 | "shuffle_interval=%d stutter=%d irqreader=%d " |
| 1381 | "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d " |
| 1382 | "test_boost=%d/%d test_boost_interval=%d " |
| 1383 | "test_boost_duration=%d shutdown_secs=%d " |
Paul E. McKenney | 2b1516e | 2017-08-18 16:11:37 -0700 | [diff] [blame] | 1384 | "stall_cpu=%d stall_cpu_holdoff=%d stall_cpu_irqsoff=%d " |
Paul E. McKenney | 67afeed | 2012-10-20 12:56:06 -0700 | [diff] [blame] | 1385 | "n_barrier_cbs=%d " |
Paul E. McKenney | 2caa1e4 | 2012-08-09 16:30:45 -0700 | [diff] [blame] | 1386 | "onoff_interval=%d onoff_holdoff=%d\n", |
| 1387 | torture_type, tag, nrealreaders, nfakewriters, |
| 1388 | stat_interval, verbose, test_no_idle_hz, shuffle_interval, |
| 1389 | stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter, |
| 1390 | test_boost, cur_ops->can_boost, |
| 1391 | test_boost_interval, test_boost_duration, shutdown_secs, |
Paul E. McKenney | 2b1516e | 2017-08-18 16:11:37 -0700 | [diff] [blame] | 1392 | stall_cpu, stall_cpu_holdoff, stall_cpu_irqsoff, |
Paul E. McKenney | 67afeed | 2012-10-20 12:56:06 -0700 | [diff] [blame] | 1393 | n_barrier_cbs, |
Paul E. McKenney | 2caa1e4 | 2012-08-09 16:30:45 -0700 | [diff] [blame] | 1394 | onoff_interval, onoff_holdoff); |
Paul E. McKenney | 95c3832 | 2006-03-24 03:15:58 -0800 | [diff] [blame] | 1395 | } |
| 1396 | |
Sebastian Andrzej Siewior | 0ffd374 | 2016-08-18 14:57:22 +0200 | [diff] [blame] | 1397 | static int rcutorture_booster_cleanup(unsigned int cpu) |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1398 | { |
| 1399 | struct task_struct *t; |
| 1400 | |
| 1401 | if (boost_tasks[cpu] == NULL) |
Sebastian Andrzej Siewior | 0ffd374 | 2016-08-18 14:57:22 +0200 | [diff] [blame] | 1402 | return 0; |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1403 | mutex_lock(&boost_mutex); |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1404 | t = boost_tasks[cpu]; |
| 1405 | boost_tasks[cpu] = NULL; |
| 1406 | mutex_unlock(&boost_mutex); |
| 1407 | |
| 1408 | /* This must be outside of the mutex, otherwise deadlock! */ |
Paul E. McKenney | 9c029b8 | 2014-02-04 11:47:08 -0800 | [diff] [blame] | 1409 | torture_stop_kthread(rcu_torture_boost, t); |
Sebastian Andrzej Siewior | 0ffd374 | 2016-08-18 14:57:22 +0200 | [diff] [blame] | 1410 | return 0; |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
Sebastian Andrzej Siewior | 0ffd374 | 2016-08-18 14:57:22 +0200 | [diff] [blame] | 1413 | static int rcutorture_booster_init(unsigned int cpu) |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1414 | { |
| 1415 | int retval; |
| 1416 | |
| 1417 | if (boost_tasks[cpu] != NULL) |
| 1418 | return 0; /* Already created, nothing more to do. */ |
| 1419 | |
| 1420 | /* Don't allow time recalculation while creating a new task. */ |
| 1421 | mutex_lock(&boost_mutex); |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 1422 | VERBOSE_TOROUT_STRING("Creating rcu_torture_boost task"); |
Eric Dumazet | 1f28809 | 2011-06-16 15:53:18 -0700 | [diff] [blame] | 1423 | boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL, |
| 1424 | cpu_to_node(cpu), |
| 1425 | "rcu_torture_boost"); |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1426 | if (IS_ERR(boost_tasks[cpu])) { |
| 1427 | retval = PTR_ERR(boost_tasks[cpu]); |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 1428 | VERBOSE_TOROUT_STRING("rcu_torture_boost task create failed"); |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1429 | n_rcu_torture_boost_ktrerror++; |
| 1430 | boost_tasks[cpu] = NULL; |
| 1431 | mutex_unlock(&boost_mutex); |
| 1432 | return retval; |
| 1433 | } |
| 1434 | kthread_bind(boost_tasks[cpu], cpu); |
| 1435 | wake_up_process(boost_tasks[cpu]); |
| 1436 | mutex_unlock(&boost_mutex); |
| 1437 | return 0; |
| 1438 | } |
| 1439 | |
Paul E. McKenney | d5f546d | 2011-11-04 11:44:12 -0700 | [diff] [blame] | 1440 | /* |
Paul E. McKenney | c13f375 | 2012-01-20 15:36:33 -0800 | [diff] [blame] | 1441 | * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then |
| 1442 | * induces a CPU stall for the time specified by stall_cpu. |
| 1443 | */ |
Paul Gortmaker | 49fb4c6 | 2013-06-19 14:52:21 -0400 | [diff] [blame] | 1444 | static int rcu_torture_stall(void *args) |
Paul E. McKenney | c13f375 | 2012-01-20 15:36:33 -0800 | [diff] [blame] | 1445 | { |
| 1446 | unsigned long stop_at; |
| 1447 | |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 1448 | VERBOSE_TOROUT_STRING("rcu_torture_stall task started"); |
Paul E. McKenney | c13f375 | 2012-01-20 15:36:33 -0800 | [diff] [blame] | 1449 | if (stall_cpu_holdoff > 0) { |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 1450 | VERBOSE_TOROUT_STRING("rcu_torture_stall begin holdoff"); |
Paul E. McKenney | c13f375 | 2012-01-20 15:36:33 -0800 | [diff] [blame] | 1451 | schedule_timeout_interruptible(stall_cpu_holdoff * HZ); |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 1452 | VERBOSE_TOROUT_STRING("rcu_torture_stall end holdoff"); |
Paul E. McKenney | c13f375 | 2012-01-20 15:36:33 -0800 | [diff] [blame] | 1453 | } |
| 1454 | if (!kthread_should_stop()) { |
| 1455 | stop_at = get_seconds() + stall_cpu; |
| 1456 | /* RCU CPU stall is expected behavior in following code. */ |
Paul E. McKenney | c13f375 | 2012-01-20 15:36:33 -0800 | [diff] [blame] | 1457 | rcu_read_lock(); |
Paul E. McKenney | 2b1516e | 2017-08-18 16:11:37 -0700 | [diff] [blame] | 1458 | if (stall_cpu_irqsoff) |
| 1459 | local_irq_disable(); |
| 1460 | else |
| 1461 | preempt_disable(); |
| 1462 | pr_alert("rcu_torture_stall start on CPU %d.\n", |
| 1463 | smp_processor_id()); |
Paul E. McKenney | c13f375 | 2012-01-20 15:36:33 -0800 | [diff] [blame] | 1464 | while (ULONG_CMP_LT(get_seconds(), stop_at)) |
| 1465 | continue; /* Induce RCU CPU stall warning. */ |
Paul E. McKenney | 2b1516e | 2017-08-18 16:11:37 -0700 | [diff] [blame] | 1466 | if (stall_cpu_irqsoff) |
| 1467 | local_irq_enable(); |
| 1468 | else |
| 1469 | preempt_enable(); |
Paul E. McKenney | c13f375 | 2012-01-20 15:36:33 -0800 | [diff] [blame] | 1470 | rcu_read_unlock(); |
Paul E. McKenney | 2caa1e4 | 2012-08-09 16:30:45 -0700 | [diff] [blame] | 1471 | pr_alert("rcu_torture_stall end.\n"); |
Paul E. McKenney | c13f375 | 2012-01-20 15:36:33 -0800 | [diff] [blame] | 1472 | } |
Paul E. McKenney | f67a335 | 2014-01-29 07:40:27 -0800 | [diff] [blame] | 1473 | torture_shutdown_absorb("rcu_torture_stall"); |
Paul E. McKenney | c13f375 | 2012-01-20 15:36:33 -0800 | [diff] [blame] | 1474 | while (!kthread_should_stop()) |
| 1475 | schedule_timeout_interruptible(10 * HZ); |
| 1476 | return 0; |
| 1477 | } |
| 1478 | |
| 1479 | /* Spawn CPU-stall kthread, if stall_cpu specified. */ |
| 1480 | static int __init rcu_torture_stall_init(void) |
| 1481 | { |
Paul E. McKenney | c13f375 | 2012-01-20 15:36:33 -0800 | [diff] [blame] | 1482 | if (stall_cpu <= 0) |
| 1483 | return 0; |
Paul E. McKenney | 47cf29b | 2014-02-03 11:52:27 -0800 | [diff] [blame] | 1484 | return torture_create_kthread(rcu_torture_stall, NULL, stall_task); |
Paul E. McKenney | c13f375 | 2012-01-20 15:36:33 -0800 | [diff] [blame] | 1485 | } |
| 1486 | |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1487 | /* Callback function for RCU barrier testing. */ |
Rashika Kheria | b3b8a4d | 2014-02-27 17:16:57 +0530 | [diff] [blame] | 1488 | static void rcu_torture_barrier_cbf(struct rcu_head *rcu) |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1489 | { |
| 1490 | atomic_inc(&barrier_cbs_invoked); |
| 1491 | } |
| 1492 | |
| 1493 | /* kthread function to register callbacks used to test RCU barriers. */ |
| 1494 | static int rcu_torture_barrier_cbs(void *arg) |
| 1495 | { |
| 1496 | long myid = (long)arg; |
Paul E. McKenney | c6ebcbb | 2012-05-28 19:21:41 -0700 | [diff] [blame] | 1497 | bool lastphase = 0; |
Paul E. McKenney | 78e4bc3 | 2013-09-24 15:04:06 -0700 | [diff] [blame] | 1498 | bool newphase; |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1499 | struct rcu_head rcu; |
| 1500 | |
| 1501 | init_rcu_head_on_stack(&rcu); |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 1502 | VERBOSE_TOROUT_STRING("rcu_torture_barrier_cbs task started"); |
Linus Torvalds | 971eae7 | 2014-03-31 11:21:19 -0700 | [diff] [blame] | 1503 | set_user_nice(current, MAX_NICE); |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1504 | do { |
| 1505 | wait_event(barrier_cbs_wq[myid], |
Paul E. McKenney | 78e4bc3 | 2013-09-24 15:04:06 -0700 | [diff] [blame] | 1506 | (newphase = |
Paul E. McKenney | 6c7ed42 | 2015-04-13 11:58:08 -0700 | [diff] [blame] | 1507 | smp_load_acquire(&barrier_phase)) != lastphase || |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 1508 | torture_must_stop()); |
Paul E. McKenney | 78e4bc3 | 2013-09-24 15:04:06 -0700 | [diff] [blame] | 1509 | lastphase = newphase; |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 1510 | if (torture_must_stop()) |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1511 | break; |
Paul E. McKenney | 6c7ed42 | 2015-04-13 11:58:08 -0700 | [diff] [blame] | 1512 | /* |
| 1513 | * The above smp_load_acquire() ensures barrier_phase load |
Paul E. McKenney | aab0573 | 2016-05-02 12:20:51 -0700 | [diff] [blame] | 1514 | * is ordered before the following ->call(). |
Paul E. McKenney | 6c7ed42 | 2015-04-13 11:58:08 -0700 | [diff] [blame] | 1515 | */ |
Paul E. McKenney | 0aa67e7 | 2016-03-30 11:40:44 -0700 | [diff] [blame] | 1516 | local_irq_disable(); /* Just to test no-irq call_rcu(). */ |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1517 | cur_ops->call(&rcu, rcu_torture_barrier_cbf); |
Paul E. McKenney | 0aa67e7 | 2016-03-30 11:40:44 -0700 | [diff] [blame] | 1518 | local_irq_enable(); |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1519 | if (atomic_dec_and_test(&barrier_cbs_count)) |
| 1520 | wake_up(&barrier_wq); |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 1521 | } while (!torture_must_stop()); |
Paul E. McKenney | 69c6045 | 2014-07-01 11:59:36 -0700 | [diff] [blame] | 1522 | if (cur_ops->cb_barrier != NULL) |
| 1523 | cur_ops->cb_barrier(); |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1524 | destroy_rcu_head_on_stack(&rcu); |
Paul E. McKenney | 7fafaac | 2014-01-31 17:37:28 -0800 | [diff] [blame] | 1525 | torture_kthread_stopping("rcu_torture_barrier_cbs"); |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1526 | return 0; |
| 1527 | } |
| 1528 | |
| 1529 | /* kthread function to drive and coordinate RCU barrier testing. */ |
| 1530 | static int rcu_torture_barrier(void *arg) |
| 1531 | { |
| 1532 | int i; |
| 1533 | |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 1534 | VERBOSE_TOROUT_STRING("rcu_torture_barrier task starting"); |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1535 | do { |
| 1536 | atomic_set(&barrier_cbs_invoked, 0); |
| 1537 | atomic_set(&barrier_cbs_count, n_barrier_cbs); |
Paul E. McKenney | 6c7ed42 | 2015-04-13 11:58:08 -0700 | [diff] [blame] | 1538 | /* Ensure barrier_phase ordered after prior assignments. */ |
| 1539 | smp_store_release(&barrier_phase, !barrier_phase); |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1540 | for (i = 0; i < n_barrier_cbs; i++) |
| 1541 | wake_up(&barrier_cbs_wq[i]); |
| 1542 | wait_event(barrier_wq, |
| 1543 | atomic_read(&barrier_cbs_count) == 0 || |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 1544 | torture_must_stop()); |
| 1545 | if (torture_must_stop()) |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1546 | break; |
| 1547 | n_barrier_attempts++; |
Paul E. McKenney | 78e4bc3 | 2013-09-24 15:04:06 -0700 | [diff] [blame] | 1548 | cur_ops->cb_barrier(); /* Implies smp_mb() for wait_event(). */ |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1549 | if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) { |
| 1550 | n_rcu_torture_barrier_error++; |
Paul E. McKenney | 7602de4a | 2014-12-17 18:39:54 -0800 | [diff] [blame] | 1551 | pr_err("barrier_cbs_invoked = %d, n_barrier_cbs = %d\n", |
| 1552 | atomic_read(&barrier_cbs_invoked), |
| 1553 | n_barrier_cbs); |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1554 | WARN_ON_ONCE(1); |
| 1555 | } |
| 1556 | n_barrier_successes++; |
| 1557 | schedule_timeout_interruptible(HZ / 10); |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 1558 | } while (!torture_must_stop()); |
Paul E. McKenney | 7fafaac | 2014-01-31 17:37:28 -0800 | [diff] [blame] | 1559 | torture_kthread_stopping("rcu_torture_barrier"); |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1560 | return 0; |
| 1561 | } |
| 1562 | |
| 1563 | /* Initialize RCU barrier testing. */ |
| 1564 | static int rcu_torture_barrier_init(void) |
| 1565 | { |
| 1566 | int i; |
| 1567 | int ret; |
| 1568 | |
Paul E. McKenney | d9eba768 | 2015-05-14 15:35:43 -0700 | [diff] [blame] | 1569 | if (n_barrier_cbs <= 0) |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1570 | return 0; |
| 1571 | if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) { |
Paul E. McKenney | 2caa1e4 | 2012-08-09 16:30:45 -0700 | [diff] [blame] | 1572 | pr_alert("%s" TORTURE_FLAG |
| 1573 | " Call or barrier ops missing for %s,\n", |
| 1574 | torture_type, cur_ops->name); |
| 1575 | pr_alert("%s" TORTURE_FLAG |
| 1576 | " RCU barrier testing omitted from run.\n", |
| 1577 | torture_type); |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1578 | return 0; |
| 1579 | } |
| 1580 | atomic_set(&barrier_cbs_count, 0); |
| 1581 | atomic_set(&barrier_cbs_invoked, 0); |
| 1582 | barrier_cbs_tasks = |
Paul E. McKenney | 68a675d | 2017-12-01 14:26:56 -0800 | [diff] [blame] | 1583 | kcalloc(n_barrier_cbs, sizeof(barrier_cbs_tasks[0]), |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1584 | GFP_KERNEL); |
| 1585 | barrier_cbs_wq = |
Paul E. McKenney | 68a675d | 2017-12-01 14:26:56 -0800 | [diff] [blame] | 1586 | kcalloc(n_barrier_cbs, sizeof(barrier_cbs_wq[0]), GFP_KERNEL); |
Sasha Levin | de5e643 | 2012-12-20 14:11:28 -0500 | [diff] [blame] | 1587 | if (barrier_cbs_tasks == NULL || !barrier_cbs_wq) |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1588 | return -ENOMEM; |
| 1589 | for (i = 0; i < n_barrier_cbs; i++) { |
| 1590 | init_waitqueue_head(&barrier_cbs_wq[i]); |
Paul E. McKenney | 47cf29b | 2014-02-03 11:52:27 -0800 | [diff] [blame] | 1591 | ret = torture_create_kthread(rcu_torture_barrier_cbs, |
| 1592 | (void *)(long)i, |
| 1593 | barrier_cbs_tasks[i]); |
| 1594 | if (ret) |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1595 | return ret; |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1596 | } |
Paul E. McKenney | 47cf29b | 2014-02-03 11:52:27 -0800 | [diff] [blame] | 1597 | return torture_create_kthread(rcu_torture_barrier, NULL, barrier_task); |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | /* Clean up after RCU barrier testing. */ |
| 1601 | static void rcu_torture_barrier_cleanup(void) |
| 1602 | { |
| 1603 | int i; |
| 1604 | |
Paul E. McKenney | 9c029b8 | 2014-02-04 11:47:08 -0800 | [diff] [blame] | 1605 | torture_stop_kthread(rcu_torture_barrier, barrier_task); |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1606 | if (barrier_cbs_tasks != NULL) { |
Paul E. McKenney | 9c029b8 | 2014-02-04 11:47:08 -0800 | [diff] [blame] | 1607 | for (i = 0; i < n_barrier_cbs; i++) |
| 1608 | torture_stop_kthread(rcu_torture_barrier_cbs, |
| 1609 | barrier_cbs_tasks[i]); |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1610 | kfree(barrier_cbs_tasks); |
| 1611 | barrier_cbs_tasks = NULL; |
| 1612 | } |
| 1613 | if (barrier_cbs_wq != NULL) { |
| 1614 | kfree(barrier_cbs_wq); |
| 1615 | barrier_cbs_wq = NULL; |
| 1616 | } |
| 1617 | } |
| 1618 | |
Sebastian Andrzej Siewior | 0ffd374 | 2016-08-18 14:57:22 +0200 | [diff] [blame] | 1619 | static enum cpuhp_state rcutor_hp; |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1620 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1621 | static void |
| 1622 | rcu_torture_cleanup(void) |
| 1623 | { |
Paul E. McKenney | 034777d | 2018-04-19 08:43:11 -0700 | [diff] [blame] | 1624 | int flags = 0; |
Paul E. McKenney | aebc826 | 2018-05-01 06:42:51 -0700 | [diff] [blame] | 1625 | unsigned long gp_seq = 0; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1626 | int i; |
| 1627 | |
Davidlohr Bueso | d36a7a0 | 2014-09-11 20:40:21 -0700 | [diff] [blame] | 1628 | if (torture_cleanup_begin()) { |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 1629 | if (cur_ops->cb_barrier != NULL) |
| 1630 | cur_ops->cb_barrier(); |
| 1631 | return; |
| 1632 | } |
Paul E. McKenney | 3808dc9 | 2014-01-28 15:29:21 -0800 | [diff] [blame] | 1633 | |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1634 | rcu_torture_barrier_cleanup(); |
Paul E. McKenney | 9c029b8 | 2014-02-04 11:47:08 -0800 | [diff] [blame] | 1635 | torture_stop_kthread(rcu_torture_stall, stall_task); |
Paul E. McKenney | 9c029b8 | 2014-02-04 11:47:08 -0800 | [diff] [blame] | 1636 | torture_stop_kthread(rcu_torture_writer, writer_task); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1637 | |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 1638 | if (reader_tasks) { |
Paul E. McKenney | 9c029b8 | 2014-02-04 11:47:08 -0800 | [diff] [blame] | 1639 | for (i = 0; i < nrealreaders; i++) |
| 1640 | torture_stop_kthread(rcu_torture_reader, |
| 1641 | reader_tasks[i]); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1642 | kfree(reader_tasks); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1643 | } |
| 1644 | rcu_torture_current = NULL; |
| 1645 | |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 1646 | if (fakewriter_tasks) { |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 1647 | for (i = 0; i < nfakewriters; i++) { |
Paul E. McKenney | 9c029b8 | 2014-02-04 11:47:08 -0800 | [diff] [blame] | 1648 | torture_stop_kthread(rcu_torture_fakewriter, |
| 1649 | fakewriter_tasks[i]); |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 1650 | } |
| 1651 | kfree(fakewriter_tasks); |
| 1652 | fakewriter_tasks = NULL; |
| 1653 | } |
| 1654 | |
Paul E. McKenney | aebc826 | 2018-05-01 06:42:51 -0700 | [diff] [blame] | 1655 | rcutorture_get_gp_data(cur_ops->ttype, &flags, &gp_seq); |
| 1656 | srcutorture_get_gp_data(cur_ops->ttype, srcu_ctlp, &flags, &gp_seq); |
| 1657 | pr_alert("%s: End-test grace-period state: g%lu f%#x\n", |
| 1658 | cur_ops->name, gp_seq, flags); |
Paul E. McKenney | 9c029b8 | 2014-02-04 11:47:08 -0800 | [diff] [blame] | 1659 | torture_stop_kthread(rcu_torture_stats, stats_task); |
| 1660 | torture_stop_kthread(rcu_torture_fqs, fqs_task); |
Paul E. McKenney | 38706bc | 2014-08-18 21:12:17 -0700 | [diff] [blame] | 1661 | for (i = 0; i < ncbflooders; i++) |
| 1662 | torture_stop_kthread(rcu_torture_cbflood, cbflood_task[i]); |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1663 | if ((test_boost == 1 && cur_ops->can_boost) || |
Sebastian Andrzej Siewior | 0ffd374 | 2016-08-18 14:57:22 +0200 | [diff] [blame] | 1664 | test_boost == 2) |
| 1665 | cpuhp_remove_state(rcutor_hp); |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 1666 | |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 1667 | /* |
| 1668 | * Wait for all RCU callbacks to fire, then do flavor-specific |
| 1669 | * cleanup operations. |
| 1670 | */ |
Paul E. McKenney | 2326974 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 1671 | if (cur_ops->cb_barrier != NULL) |
| 1672 | cur_ops->cb_barrier(); |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 1673 | if (cur_ops->cleanup != NULL) |
| 1674 | cur_ops->cleanup(); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1675 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1676 | rcu_torture_stats_print(); /* -After- the stats thread is stopped! */ |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 1677 | |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1678 | 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] | 1679 | rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE"); |
Paul E. McKenney | 2e9e808 | 2014-01-28 15:58:22 -0800 | [diff] [blame] | 1680 | else if (torture_onoff_failures()) |
Paul E. McKenney | 091541b | 2012-01-10 12:51:14 -0800 | [diff] [blame] | 1681 | rcu_torture_print_module_parms(cur_ops, |
| 1682 | "End of test: RCU_HOTPLUG"); |
Paul E. McKenney | 95c3832 | 2006-03-24 03:15:58 -0800 | [diff] [blame] | 1683 | else |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1684 | rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS"); |
Davidlohr Bueso | d36a7a0 | 2014-09-11 20:40:21 -0700 | [diff] [blame] | 1685 | torture_cleanup_end(); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1686 | } |
| 1687 | |
Paul E. McKenney | d2818df | 2013-04-23 17:05:42 -0700 | [diff] [blame] | 1688 | #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD |
| 1689 | static void rcu_torture_leak_cb(struct rcu_head *rhp) |
| 1690 | { |
| 1691 | } |
| 1692 | |
| 1693 | static void rcu_torture_err_cb(struct rcu_head *rhp) |
| 1694 | { |
| 1695 | /* |
| 1696 | * This -might- happen due to race conditions, but is unlikely. |
| 1697 | * The scenario that leads to this happening is that the |
| 1698 | * first of the pair of duplicate callbacks is queued, |
| 1699 | * someone else starts a grace period that includes that |
| 1700 | * callback, then the second of the pair must wait for the |
| 1701 | * next grace period. Unlikely, but can happen. If it |
| 1702 | * does happen, the debug-objects subsystem won't have splatted. |
| 1703 | */ |
Paul E. McKenney | e0d31a34c | 2017-12-01 15:22:38 -0800 | [diff] [blame] | 1704 | pr_alert("%s: duplicated callback was invoked.\n", KBUILD_MODNAME); |
Paul E. McKenney | d2818df | 2013-04-23 17:05:42 -0700 | [diff] [blame] | 1705 | } |
| 1706 | #endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */ |
| 1707 | |
| 1708 | /* |
| 1709 | * Verify that double-free causes debug-objects to complain, but only |
| 1710 | * if CONFIG_DEBUG_OBJECTS_RCU_HEAD=y. Otherwise, say that the test |
| 1711 | * cannot be carried out. |
| 1712 | */ |
| 1713 | static void rcu_test_debug_objects(void) |
| 1714 | { |
| 1715 | #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD |
| 1716 | struct rcu_head rh1; |
| 1717 | struct rcu_head rh2; |
| 1718 | |
| 1719 | init_rcu_head_on_stack(&rh1); |
| 1720 | init_rcu_head_on_stack(&rh2); |
Paul E. McKenney | e0d31a34c | 2017-12-01 15:22:38 -0800 | [diff] [blame] | 1721 | pr_alert("%s: WARN: Duplicate call_rcu() test starting.\n", KBUILD_MODNAME); |
Paul E. McKenney | d2818df | 2013-04-23 17:05:42 -0700 | [diff] [blame] | 1722 | |
| 1723 | /* Try to queue the rh2 pair of callbacks for the same grace period. */ |
| 1724 | preempt_disable(); /* Prevent preemption from interrupting test. */ |
| 1725 | rcu_read_lock(); /* Make it impossible to finish a grace period. */ |
| 1726 | call_rcu(&rh1, rcu_torture_leak_cb); /* Start grace period. */ |
| 1727 | local_irq_disable(); /* Make it harder to start a new grace period. */ |
| 1728 | call_rcu(&rh2, rcu_torture_leak_cb); |
| 1729 | call_rcu(&rh2, rcu_torture_err_cb); /* Duplicate callback. */ |
| 1730 | local_irq_enable(); |
| 1731 | rcu_read_unlock(); |
| 1732 | preempt_enable(); |
| 1733 | |
| 1734 | /* Wait for them all to get done so we can safely return. */ |
| 1735 | rcu_barrier(); |
Paul E. McKenney | e0d31a34c | 2017-12-01 15:22:38 -0800 | [diff] [blame] | 1736 | pr_alert("%s: WARN: Duplicate call_rcu() test complete.\n", KBUILD_MODNAME); |
Paul E. McKenney | d2818df | 2013-04-23 17:05:42 -0700 | [diff] [blame] | 1737 | destroy_rcu_head_on_stack(&rh1); |
| 1738 | destroy_rcu_head_on_stack(&rh2); |
| 1739 | #else /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */ |
Paul E. McKenney | e0d31a34c | 2017-12-01 15:22:38 -0800 | [diff] [blame] | 1740 | pr_alert("%s: !CONFIG_DEBUG_OBJECTS_RCU_HEAD, not testing duplicate call_rcu()\n", KBUILD_MODNAME); |
Paul E. McKenney | d2818df | 2013-04-23 17:05:42 -0700 | [diff] [blame] | 1741 | #endif /* #else #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */ |
| 1742 | } |
| 1743 | |
Josh Triplett | 6f8bc500 | 2007-05-08 00:25:24 -0700 | [diff] [blame] | 1744 | static int __init |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1745 | rcu_torture_init(void) |
| 1746 | { |
| 1747 | int i; |
| 1748 | int cpu; |
| 1749 | int firsterr = 0; |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 1750 | static struct rcu_torture_ops *torture_ops[] = { |
Paul E. McKenney | ca1d51e | 2015-04-14 12:28:22 -0700 | [diff] [blame] | 1751 | &rcu_ops, &rcu_bh_ops, &rcu_busted_ops, &srcu_ops, &srcud_ops, |
Paul E. McKenney | 7e42776 | 2017-05-25 08:05:00 -0700 | [diff] [blame] | 1752 | &sched_ops, &tasks_ops, |
Paul E. McKenney | 2ec1f2d | 2013-06-12 15:12:21 -0700 | [diff] [blame] | 1753 | }; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1754 | |
Paul E. McKenney | a2f2577 | 2017-11-21 20:19:17 -0800 | [diff] [blame] | 1755 | if (!torture_init_begin(torture_type, verbose)) |
Paul E. McKenney | 5228084 | 2014-04-07 09:14:11 -0700 | [diff] [blame] | 1756 | return -EBUSY; |
Paul E. McKenney | 343e909 | 2008-12-15 16:13:07 -0800 | [diff] [blame] | 1757 | |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1758 | /* 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] | 1759 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) { |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 1760 | cur_ops = torture_ops[i]; |
Josh Triplett | ade5fb8 | 2007-05-08 00:33:22 -0700 | [diff] [blame] | 1761 | if (strcmp(torture_type, cur_ops->name) == 0) |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 1762 | break; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 1763 | } |
Josh Triplett | ade5fb8 | 2007-05-08 00:33:22 -0700 | [diff] [blame] | 1764 | if (i == ARRAY_SIZE(torture_ops)) { |
Paul E. McKenney | 2caa1e4 | 2012-08-09 16:30:45 -0700 | [diff] [blame] | 1765 | pr_alert("rcu-torture: invalid torture type: \"%s\"\n", |
| 1766 | torture_type); |
| 1767 | pr_alert("rcu-torture types:"); |
Paul E. McKenney | cf886c4 | 2009-10-25 19:03:54 -0700 | [diff] [blame] | 1768 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) |
Paul E. McKenney | 2caa1e4 | 2012-08-09 16:30:45 -0700 | [diff] [blame] | 1769 | pr_alert(" %s", torture_ops[i]->name); |
| 1770 | pr_alert("\n"); |
Paul E. McKenney | 889d487 | 2015-08-24 11:37:58 -0700 | [diff] [blame] | 1771 | firsterr = -EINVAL; |
| 1772 | goto unwind; |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 1773 | } |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 1774 | if (cur_ops->fqs == NULL && fqs_duration != 0) { |
Paul E. McKenney | 2caa1e4 | 2012-08-09 16:30:45 -0700 | [diff] [blame] | 1775 | 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] | 1776 | fqs_duration = 0; |
| 1777 | } |
Josh Triplett | c8e5b16 | 2007-05-08 00:33:20 -0700 | [diff] [blame] | 1778 | if (cur_ops->init) |
Paul E. McKenney | 889d487 | 2015-08-24 11:37:58 -0700 | [diff] [blame] | 1779 | cur_ops->init(); |
Paul E. McKenney | 72e9bb5 | 2006-06-27 02:54:03 -0700 | [diff] [blame] | 1780 | |
Paul E. McKenney | 64e4b43 | 2014-03-12 10:26:35 -0700 | [diff] [blame] | 1781 | if (nreaders >= 0) { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1782 | nrealreaders = nreaders; |
Paul E. McKenney | 64e4b43 | 2014-03-12 10:26:35 -0700 | [diff] [blame] | 1783 | } else { |
Paul E. McKenney | 3838cc1 | 2015-03-12 13:55:48 -0700 | [diff] [blame] | 1784 | nrealreaders = num_online_cpus() - 2 - nreaders; |
Paul E. McKenney | 64e4b43 | 2014-03-12 10:26:35 -0700 | [diff] [blame] | 1785 | if (nrealreaders <= 0) |
| 1786 | nrealreaders = 1; |
| 1787 | } |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1788 | rcu_torture_print_module_parms(cur_ops, "Start of test"); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1789 | |
| 1790 | /* Set up the freelist. */ |
| 1791 | |
| 1792 | INIT_LIST_HEAD(&rcu_torture_freelist); |
Ahmed S. Darwish | 788e770 | 2007-05-08 00:33:14 -0700 | [diff] [blame] | 1793 | for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) { |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 1794 | rcu_tortures[i].rtort_mbtest = 0; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1795 | list_add_tail(&rcu_tortures[i].rtort_free, |
| 1796 | &rcu_torture_freelist); |
| 1797 | } |
| 1798 | |
| 1799 | /* Initialize the statistics so that each run gets its own numbers. */ |
| 1800 | |
| 1801 | rcu_torture_current = NULL; |
| 1802 | rcu_torture_current_version = 0; |
| 1803 | atomic_set(&n_rcu_torture_alloc, 0); |
| 1804 | atomic_set(&n_rcu_torture_alloc_fail, 0); |
| 1805 | atomic_set(&n_rcu_torture_free, 0); |
Paul E. McKenney | 996417d | 2005-11-18 01:10:50 -0800 | [diff] [blame] | 1806 | atomic_set(&n_rcu_torture_mberror, 0); |
| 1807 | atomic_set(&n_rcu_torture_error, 0); |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1808 | n_rcu_torture_barrier_error = 0; |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1809 | n_rcu_torture_boost_ktrerror = 0; |
| 1810 | n_rcu_torture_boost_rterror = 0; |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1811 | n_rcu_torture_boost_failure = 0; |
| 1812 | n_rcu_torture_boosts = 0; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1813 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
| 1814 | atomic_set(&rcu_torture_wcount[i], 0); |
KAMEZAWA Hiroyuki | 0a94502 | 2006-03-28 01:56:37 -0800 | [diff] [blame] | 1815 | for_each_possible_cpu(cpu) { |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1816 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
| 1817 | per_cpu(rcu_torture_count, cpu)[i] = 0; |
| 1818 | per_cpu(rcu_torture_batch, cpu)[i] = 0; |
| 1819 | } |
| 1820 | } |
| 1821 | |
| 1822 | /* Start up the kthreads. */ |
| 1823 | |
Paul E. McKenney | 47cf29b | 2014-02-03 11:52:27 -0800 | [diff] [blame] | 1824 | firsterr = torture_create_kthread(rcu_torture_writer, NULL, |
| 1825 | writer_task); |
| 1826 | if (firsterr) |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1827 | goto unwind; |
Paul E. McKenney | 4444d85 | 2015-05-14 15:42:40 -0700 | [diff] [blame] | 1828 | if (nfakewriters > 0) { |
Paul E. McKenney | 68a675d | 2017-12-01 14:26:56 -0800 | [diff] [blame] | 1829 | fakewriter_tasks = kcalloc(nfakewriters, |
Paul E. McKenney | 4444d85 | 2015-05-14 15:42:40 -0700 | [diff] [blame] | 1830 | sizeof(fakewriter_tasks[0]), |
| 1831 | GFP_KERNEL); |
| 1832 | if (fakewriter_tasks == NULL) { |
| 1833 | VERBOSE_TOROUT_ERRSTRING("out of memory"); |
| 1834 | firsterr = -ENOMEM; |
| 1835 | goto unwind; |
| 1836 | } |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 1837 | } |
| 1838 | for (i = 0; i < nfakewriters; i++) { |
Paul E. McKenney | 47cf29b | 2014-02-03 11:52:27 -0800 | [diff] [blame] | 1839 | firsterr = torture_create_kthread(rcu_torture_fakewriter, |
| 1840 | NULL, fakewriter_tasks[i]); |
| 1841 | if (firsterr) |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 1842 | goto unwind; |
Josh Triplett | b772e1d | 2006-10-04 02:17:13 -0700 | [diff] [blame] | 1843 | } |
Paul E. McKenney | 68a675d | 2017-12-01 14:26:56 -0800 | [diff] [blame] | 1844 | reader_tasks = kcalloc(nrealreaders, sizeof(reader_tasks[0]), |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1845 | GFP_KERNEL); |
| 1846 | if (reader_tasks == NULL) { |
Paul E. McKenney | 5ccf60f | 2014-01-29 07:25:25 -0800 | [diff] [blame] | 1847 | VERBOSE_TOROUT_ERRSTRING("out of memory"); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1848 | firsterr = -ENOMEM; |
| 1849 | goto unwind; |
| 1850 | } |
| 1851 | for (i = 0; i < nrealreaders; i++) { |
Paul E. McKenney | 47cf29b | 2014-02-03 11:52:27 -0800 | [diff] [blame] | 1852 | firsterr = torture_create_kthread(rcu_torture_reader, NULL, |
| 1853 | reader_tasks[i]); |
| 1854 | if (firsterr) |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1855 | goto unwind; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1856 | } |
| 1857 | if (stat_interval > 0) { |
Paul E. McKenney | 47cf29b | 2014-02-03 11:52:27 -0800 | [diff] [blame] | 1858 | firsterr = torture_create_kthread(rcu_torture_stats, NULL, |
| 1859 | stats_task); |
| 1860 | if (firsterr) |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1861 | goto unwind; |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1862 | } |
Paul E. McKenney | e8e255f | 2015-05-14 16:55:45 -0700 | [diff] [blame] | 1863 | if (test_no_idle_hz && shuffle_interval > 0) { |
Paul E. McKenney | 3808dc9 | 2014-01-28 15:29:21 -0800 | [diff] [blame] | 1864 | firsterr = torture_shuffle_init(shuffle_interval * HZ); |
| 1865 | if (firsterr) |
Rusty Russell | 73d0a4b | 2009-03-30 22:05:16 -0600 | [diff] [blame] | 1866 | goto unwind; |
Srivatsa Vaddagiri | d84f520 | 2006-01-08 01:03:42 -0800 | [diff] [blame] | 1867 | } |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 1868 | if (stutter < 0) |
| 1869 | stutter = 0; |
| 1870 | if (stutter) { |
Paul E. McKenney | 628edaa | 2014-01-31 11:57:43 -0800 | [diff] [blame] | 1871 | firsterr = torture_stutter_init(stutter * HZ); |
| 1872 | if (firsterr) |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 1873 | goto unwind; |
Paul E. McKenney | d120f65 | 2008-06-18 05:21:44 -0700 | [diff] [blame] | 1874 | } |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 1875 | if (fqs_duration < 0) |
| 1876 | fqs_duration = 0; |
| 1877 | if (fqs_duration) { |
Paul E. McKenney | 628edaa | 2014-01-31 11:57:43 -0800 | [diff] [blame] | 1878 | /* Create the fqs thread */ |
Paul E. McKenney | d0d0606 | 2014-03-17 20:56:45 -0700 | [diff] [blame] | 1879 | firsterr = torture_create_kthread(rcu_torture_fqs, NULL, |
| 1880 | fqs_task); |
Paul E. McKenney | 47cf29b | 2014-02-03 11:52:27 -0800 | [diff] [blame] | 1881 | if (firsterr) |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 1882 | goto unwind; |
Paul E. McKenney | bf66f18 | 2010-01-04 15:09:10 -0800 | [diff] [blame] | 1883 | } |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1884 | if (test_boost_interval < 1) |
| 1885 | test_boost_interval = 1; |
| 1886 | if (test_boost_duration < 2) |
| 1887 | test_boost_duration = 2; |
| 1888 | if ((test_boost == 1 && cur_ops->can_boost) || |
| 1889 | test_boost == 2) { |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1890 | |
| 1891 | boost_starttime = jiffies + test_boost_interval * HZ; |
Sebastian Andrzej Siewior | 0ffd374 | 2016-08-18 14:57:22 +0200 | [diff] [blame] | 1892 | |
| 1893 | firsterr = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "RCU_TORTURE", |
| 1894 | rcutorture_booster_init, |
| 1895 | rcutorture_booster_cleanup); |
| 1896 | if (firsterr < 0) |
| 1897 | goto unwind; |
| 1898 | rcutor_hp = firsterr; |
Paul E. McKenney | 8e8be45 | 2010-09-02 16:16:14 -0700 | [diff] [blame] | 1899 | } |
Paul E. McKenney | 01025eb | 2014-01-31 15:15:02 -0800 | [diff] [blame] | 1900 | firsterr = torture_shutdown_init(shutdown_secs, rcu_torture_cleanup); |
| 1901 | if (firsterr) |
Paul E. McKenney | e991dbc | 2014-01-31 14:52:13 -0800 | [diff] [blame] | 1902 | goto unwind; |
Paul E. McKenney | 028be12 | 2018-05-08 09:20:34 -0700 | [diff] [blame] | 1903 | firsterr = torture_onoff_init(onoff_holdoff * HZ, onoff_interval); |
Paul E. McKenney | 01025eb | 2014-01-31 15:15:02 -0800 | [diff] [blame] | 1904 | if (firsterr) |
Paul E. McKenney | 37e377d | 2012-02-17 22:12:18 -0800 | [diff] [blame] | 1905 | goto unwind; |
Paul E. McKenney | 01025eb | 2014-01-31 15:15:02 -0800 | [diff] [blame] | 1906 | firsterr = rcu_torture_stall_init(); |
| 1907 | if (firsterr) |
Paul E. McKenney | 37e377d | 2012-02-17 22:12:18 -0800 | [diff] [blame] | 1908 | goto unwind; |
Paul E. McKenney | 01025eb | 2014-01-31 15:15:02 -0800 | [diff] [blame] | 1909 | firsterr = rcu_torture_barrier_init(); |
| 1910 | if (firsterr) |
Paul E. McKenney | fae4b54 | 2012-02-20 17:51:45 -0800 | [diff] [blame] | 1911 | goto unwind; |
Paul E. McKenney | d2818df | 2013-04-23 17:05:42 -0700 | [diff] [blame] | 1912 | if (object_debug) |
| 1913 | rcu_test_debug_objects(); |
Paul E. McKenney | 38706bc | 2014-08-18 21:12:17 -0700 | [diff] [blame] | 1914 | if (cbflood_n_burst > 0) { |
| 1915 | /* Create the cbflood threads */ |
| 1916 | ncbflooders = (num_online_cpus() + 3) / 4; |
| 1917 | cbflood_task = kcalloc(ncbflooders, sizeof(*cbflood_task), |
| 1918 | GFP_KERNEL); |
| 1919 | if (!cbflood_task) { |
| 1920 | VERBOSE_TOROUT_ERRSTRING("out of memory"); |
| 1921 | firsterr = -ENOMEM; |
| 1922 | goto unwind; |
| 1923 | } |
| 1924 | for (i = 0; i < ncbflooders; i++) { |
| 1925 | firsterr = torture_create_kthread(rcu_torture_cbflood, |
| 1926 | NULL, |
| 1927 | cbflood_task[i]); |
| 1928 | if (firsterr) |
| 1929 | goto unwind; |
| 1930 | } |
| 1931 | } |
Paul E. McKenney | b5daa8f | 2014-01-30 13:38:09 -0800 | [diff] [blame] | 1932 | torture_init_end(); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1933 | return 0; |
| 1934 | |
| 1935 | unwind: |
Paul E. McKenney | b5daa8f | 2014-01-30 13:38:09 -0800 | [diff] [blame] | 1936 | torture_init_end(); |
Paul E. McKenney | a241ec6 | 2005-10-30 15:03:12 -0800 | [diff] [blame] | 1937 | rcu_torture_cleanup(); |
| 1938 | return firsterr; |
| 1939 | } |
| 1940 | |
| 1941 | module_init(rcu_torture_init); |
| 1942 | module_exit(rcu_torture_cleanup); |