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