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