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