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