Commit | Line | Data |
---|---|---|
a241ec65 | 1 | /* |
29766f1e | 2 | * Read-Copy Update module-based torture test facility |
a241ec65 PM |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | * | |
b772e1dd | 18 | * Copyright (C) IBM Corporation, 2005, 2006 |
a241ec65 PM |
19 | * |
20 | * Authors: Paul E. McKenney <paulmck@us.ibm.com> | |
a71fca58 | 21 | * Josh Triplett <josh@freedesktop.org> |
a241ec65 PM |
22 | * |
23 | * See also: Documentation/RCU/torture.txt | |
24 | */ | |
25 | #include <linux/types.h> | |
26 | #include <linux/kernel.h> | |
27 | #include <linux/init.h> | |
28 | #include <linux/module.h> | |
29 | #include <linux/kthread.h> | |
30 | #include <linux/err.h> | |
31 | #include <linux/spinlock.h> | |
32 | #include <linux/smp.h> | |
33 | #include <linux/rcupdate.h> | |
34 | #include <linux/interrupt.h> | |
35 | #include <linux/sched.h> | |
60063497 | 36 | #include <linux/atomic.h> |
a241ec65 | 37 | #include <linux/bitops.h> |
a241ec65 PM |
38 | #include <linux/completion.h> |
39 | #include <linux/moduleparam.h> | |
40 | #include <linux/percpu.h> | |
41 | #include <linux/notifier.h> | |
343e9099 | 42 | #include <linux/reboot.h> |
83144186 | 43 | #include <linux/freezer.h> |
a241ec65 | 44 | #include <linux/cpu.h> |
a241ec65 | 45 | #include <linux/delay.h> |
a241ec65 | 46 | #include <linux/stat.h> |
b2896d2e | 47 | #include <linux/srcu.h> |
1aeb272c | 48 | #include <linux/slab.h> |
52494535 | 49 | #include <linux/trace_clock.h> |
f07767fd | 50 | #include <asm/byteorder.h> |
a241ec65 PM |
51 | |
52 | MODULE_LICENSE("GPL"); | |
5cf05ad7 | 53 | MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@freedesktop.org>"); |
a241ec65 | 54 | |
4802211c | 55 | static int nreaders = -1; /* # reader threads, defaults to 2*ncpus */ |
b772e1dd | 56 | static int nfakewriters = 4; /* # fake writer threads */ |
ab840f7a PM |
57 | static int stat_interval = 60; /* Interval between stats, in seconds. */ |
58 | /* Zero means "only at end of test". */ | |
d8e8ed95 | 59 | static bool verbose; /* Print more debug info. */ |
ab840f7a PM |
60 | static bool test_no_idle_hz = true; |
61 | /* Test RCU support for tickless idle CPUs. */ | |
d120f65f PM |
62 | static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/ |
63 | static int stutter = 5; /* Start/stop testing interval (in sec) */ | |
0729fbf3 | 64 | static int irqreader = 1; /* RCU readers from irq (timers). */ |
d5f546d8 PM |
65 | static int fqs_duration; /* Duration of bursts (us), 0 to disable. */ |
66 | static int fqs_holdoff; /* Hold time within burst (us). */ | |
bf66f18e | 67 | static int fqs_stutter = 3; /* Wait time between bursts (s). */ |
2ec1f2d9 PM |
68 | static bool gp_exp; /* Use expedited GP wait primitives. */ |
69 | static bool gp_normal; /* Use normal GP wait primitives. */ | |
fae4b54f | 70 | static int n_barrier_cbs; /* Number of callbacks to test RCU barriers. */ |
d2818df1 | 71 | static int object_debug; /* Test object-debug double call_rcu()?. */ |
b58bdcca | 72 | static int onoff_interval; /* Wait time between CPU hotplugs, 0=disable. */ |
9b9ec9b9 | 73 | static int onoff_holdoff; /* Seconds after boot before CPU hotplugs. */ |
d5f546d8 | 74 | static int shutdown_secs; /* Shutdown time (s). <=0 for no shutdown. */ |
c13f3757 PM |
75 | static int stall_cpu; /* CPU-stall duration (s). 0 for no stall. */ |
76 | static int stall_cpu_holdoff = 10; /* Time to wait until stall (s). */ | |
8e8be45e PM |
77 | static int test_boost = 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */ |
78 | static int test_boost_interval = 7; /* Interval between boost tests, seconds. */ | |
79 | static int test_boost_duration = 4; /* Duration of each boost test, seconds. */ | |
20d2e428 | 80 | static char *torture_type = "rcu"; /* What RCU implementation to torture. */ |
a241ec65 | 81 | |
d6ad6711 | 82 | module_param(nreaders, int, 0444); |
a241ec65 | 83 | MODULE_PARM_DESC(nreaders, "Number of RCU reader threads"); |
d6ad6711 | 84 | module_param(nfakewriters, int, 0444); |
b772e1dd | 85 | MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads"); |
3721bc1d | 86 | module_param(stat_interval, int, 0644); |
a241ec65 | 87 | MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s"); |
d6ad6711 | 88 | module_param(verbose, bool, 0444); |
a241ec65 | 89 | MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s"); |
d6ad6711 | 90 | module_param(test_no_idle_hz, bool, 0444); |
d84f5203 | 91 | MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs"); |
d6ad6711 | 92 | module_param(shuffle_interval, int, 0444); |
d84f5203 | 93 | MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles"); |
d120f65f PM |
94 | module_param(stutter, int, 0444); |
95 | MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test"); | |
0729fbf3 PM |
96 | module_param(irqreader, int, 0444); |
97 | MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers"); | |
bf66f18e PM |
98 | module_param(fqs_duration, int, 0444); |
99 | MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us)"); | |
100 | module_param(fqs_holdoff, int, 0444); | |
101 | MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)"); | |
102 | module_param(fqs_stutter, int, 0444); | |
103 | MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)"); | |
2ec1f2d9 PM |
104 | module_param(gp_normal, bool, 0444); |
105 | MODULE_PARM_DESC(gp_normal, "Use normal (non-expedited) GP wait primitives"); | |
106 | module_param(gp_exp, bool, 0444); | |
107 | MODULE_PARM_DESC(gp_exp, "Use expedited GP wait primitives"); | |
fae4b54f PM |
108 | module_param(n_barrier_cbs, int, 0444); |
109 | MODULE_PARM_DESC(n_barrier_cbs, "# of callbacks/kthreads for barrier testing"); | |
d2818df1 PM |
110 | module_param(object_debug, int, 0444); |
111 | MODULE_PARM_DESC(object_debug, "Enable debug-object double call_rcu() testing"); | |
b58bdcca PM |
112 | module_param(onoff_interval, int, 0444); |
113 | MODULE_PARM_DESC(onoff_interval, "Time between CPU hotplugs (s), 0=disable"); | |
9b9ec9b9 PM |
114 | module_param(onoff_holdoff, int, 0444); |
115 | MODULE_PARM_DESC(onoff_holdoff, "Time after boot before CPU hotplugs (s)"); | |
d5f546d8 PM |
116 | module_param(shutdown_secs, int, 0444); |
117 | MODULE_PARM_DESC(shutdown_secs, "Shutdown time (s), zero to disable."); | |
c13f3757 PM |
118 | module_param(stall_cpu, int, 0444); |
119 | MODULE_PARM_DESC(stall_cpu, "Stall duration (s), zero to disable."); | |
120 | module_param(stall_cpu_holdoff, int, 0444); | |
121 | MODULE_PARM_DESC(stall_cpu_holdoff, "Time to wait before starting stall (s)."); | |
8e8be45e PM |
122 | module_param(test_boost, int, 0444); |
123 | MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes."); | |
124 | module_param(test_boost_interval, int, 0444); | |
125 | MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds."); | |
126 | module_param(test_boost_duration, int, 0444); | |
127 | MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds."); | |
d6ad6711 | 128 | module_param(torture_type, charp, 0444); |
b2896d2e | 129 | MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)"); |
72e9bb54 PM |
130 | |
131 | #define TORTURE_FLAG "-torture:" | |
a241ec65 | 132 | #define PRINTK_STRING(s) \ |
2caa1e44 | 133 | do { pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0) |
a241ec65 | 134 | #define VERBOSE_PRINTK_STRING(s) \ |
2caa1e44 | 135 | do { if (verbose) pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0) |
a241ec65 | 136 | #define VERBOSE_PRINTK_ERRSTRING(s) \ |
2caa1e44 | 137 | do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0) |
a241ec65 PM |
138 | |
139 | static char printk_buf[4096]; | |
140 | ||
141 | static int nrealreaders; | |
142 | static struct task_struct *writer_task; | |
b772e1dd | 143 | static struct task_struct **fakewriter_tasks; |
a241ec65 PM |
144 | static struct task_struct **reader_tasks; |
145 | static struct task_struct *stats_task; | |
d84f5203 | 146 | static struct task_struct *shuffler_task; |
d120f65f | 147 | static struct task_struct *stutter_task; |
bf66f18e | 148 | static struct task_struct *fqs_task; |
8e8be45e | 149 | static struct task_struct *boost_tasks[NR_CPUS]; |
d5f546d8 | 150 | static struct task_struct *shutdown_task; |
b58bdcca PM |
151 | #ifdef CONFIG_HOTPLUG_CPU |
152 | static struct task_struct *onoff_task; | |
153 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | |
c13f3757 | 154 | static struct task_struct *stall_task; |
fae4b54f PM |
155 | static struct task_struct **barrier_cbs_tasks; |
156 | static struct task_struct *barrier_task; | |
a241ec65 PM |
157 | |
158 | #define RCU_TORTURE_PIPE_LEN 10 | |
159 | ||
160 | struct rcu_torture { | |
161 | struct rcu_head rtort_rcu; | |
162 | int rtort_pipe_count; | |
163 | struct list_head rtort_free; | |
996417d2 | 164 | int rtort_mbtest; |
a241ec65 PM |
165 | }; |
166 | ||
a241ec65 | 167 | static LIST_HEAD(rcu_torture_freelist); |
0ddea0ea | 168 | static struct rcu_torture __rcu *rcu_torture_current; |
4a298656 | 169 | static unsigned long rcu_torture_current_version; |
a241ec65 PM |
170 | static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN]; |
171 | static DEFINE_SPINLOCK(rcu_torture_lock); | |
172 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) = | |
173 | { 0 }; | |
174 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) = | |
175 | { 0 }; | |
176 | static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1]; | |
b2896d2e PM |
177 | static atomic_t n_rcu_torture_alloc; |
178 | static atomic_t n_rcu_torture_alloc_fail; | |
179 | static atomic_t n_rcu_torture_free; | |
180 | static atomic_t n_rcu_torture_mberror; | |
181 | static atomic_t n_rcu_torture_error; | |
fae4b54f | 182 | static long n_rcu_torture_barrier_error; |
8e8be45e PM |
183 | static long n_rcu_torture_boost_ktrerror; |
184 | static long n_rcu_torture_boost_rterror; | |
8e8be45e PM |
185 | static long n_rcu_torture_boost_failure; |
186 | static long n_rcu_torture_boosts; | |
a71fca58 | 187 | static long n_rcu_torture_timers; |
b58bdcca PM |
188 | static long n_offline_attempts; |
189 | static long n_offline_successes; | |
13dbf914 PM |
190 | static unsigned long sum_offline; |
191 | static int min_offline = -1; | |
192 | static int max_offline; | |
b58bdcca PM |
193 | static long n_online_attempts; |
194 | static long n_online_successes; | |
13dbf914 PM |
195 | static unsigned long sum_online; |
196 | static int min_online = -1; | |
197 | static int max_online; | |
fae4b54f PM |
198 | static long n_barrier_attempts; |
199 | static long n_barrier_successes; | |
e3033736 | 200 | static struct list_head rcu_torture_removed; |
73d0a4b1 | 201 | static cpumask_var_t shuffle_tmp_mask; |
a241ec65 | 202 | |
a71fca58 | 203 | static int stutter_pause_test; |
d120f65f | 204 | |
31a72bce PM |
205 | #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE) |
206 | #define RCUTORTURE_RUNNABLE_INIT 1 | |
207 | #else | |
208 | #define RCUTORTURE_RUNNABLE_INIT 0 | |
209 | #endif | |
210 | int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT; | |
bb3bf705 PM |
211 | module_param(rcutorture_runnable, int, 0444); |
212 | MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot"); | |
31a72bce | 213 | |
3acf4a9a | 214 | #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) |
8e8be45e | 215 | #define rcu_can_boost() 1 |
3acf4a9a | 216 | #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */ |
8e8be45e | 217 | #define rcu_can_boost() 0 |
3acf4a9a | 218 | #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */ |
8e8be45e | 219 | |
e4aa0da3 SR |
220 | #ifdef CONFIG_RCU_TRACE |
221 | static u64 notrace rcu_trace_clock_local(void) | |
222 | { | |
223 | u64 ts = trace_clock_local(); | |
224 | unsigned long __maybe_unused ts_rem = do_div(ts, NSEC_PER_USEC); | |
225 | return ts; | |
226 | } | |
227 | #else /* #ifdef CONFIG_RCU_TRACE */ | |
228 | static u64 notrace rcu_trace_clock_local(void) | |
229 | { | |
230 | return 0ULL; | |
231 | } | |
232 | #endif /* #else #ifdef CONFIG_RCU_TRACE */ | |
233 | ||
d5f546d8 | 234 | static unsigned long shutdown_time; /* jiffies to system shutdown. */ |
8e8be45e PM |
235 | static unsigned long boost_starttime; /* jiffies of next boost test start. */ |
236 | DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */ | |
237 | /* and boost task create/destroy. */ | |
fae4b54f | 238 | static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */ |
c6ebcbb6 | 239 | static bool barrier_phase; /* Test phase. */ |
fae4b54f PM |
240 | static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */ |
241 | static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */ | |
242 | static DECLARE_WAIT_QUEUE_HEAD(barrier_wq); | |
8e8be45e | 243 | |
c9d557c1 PM |
244 | /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */ |
245 | ||
246 | #define FULLSTOP_DONTSTOP 0 /* Normal operation. */ | |
247 | #define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */ | |
248 | #define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */ | |
249 | static int fullstop = FULLSTOP_RMMOD; | |
0ddea0ea PM |
250 | /* |
251 | * Protect fullstop transitions and spawning of kthreads. | |
252 | */ | |
253 | static DEFINE_MUTEX(fullstop_mutex); | |
343e9099 | 254 | |
d5f546d8 PM |
255 | /* Forward reference. */ |
256 | static void rcu_torture_cleanup(void); | |
257 | ||
343e9099 | 258 | /* |
c9d557c1 | 259 | * Detect and respond to a system shutdown. |
343e9099 PM |
260 | */ |
261 | static int | |
262 | rcutorture_shutdown_notify(struct notifier_block *unused1, | |
263 | unsigned long unused2, void *unused3) | |
264 | { | |
c59ab97e | 265 | mutex_lock(&fullstop_mutex); |
c9d557c1 | 266 | if (fullstop == FULLSTOP_DONTSTOP) |
c59ab97e | 267 | fullstop = FULLSTOP_SHUTDOWN; |
c9d557c1 | 268 | else |
2caa1e44 | 269 | pr_warn(/* but going down anyway, so... */ |
c9d557c1 | 270 | "Concurrent 'rmmod rcutorture' and shutdown illegal!\n"); |
c59ab97e | 271 | mutex_unlock(&fullstop_mutex); |
343e9099 PM |
272 | return NOTIFY_DONE; |
273 | } | |
274 | ||
c9d557c1 PM |
275 | /* |
276 | * Absorb kthreads into a kernel function that won't return, so that | |
277 | * they won't ever access module text or data again. | |
278 | */ | |
e66c33d5 | 279 | static void rcutorture_shutdown_absorb(const char *title) |
c9d557c1 PM |
280 | { |
281 | if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) { | |
2caa1e44 | 282 | pr_notice( |
c9d557c1 PM |
283 | "rcutorture thread %s parking due to system shutdown\n", |
284 | title); | |
285 | schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT); | |
286 | } | |
287 | } | |
288 | ||
a241ec65 PM |
289 | /* |
290 | * Allocate an element from the rcu_tortures pool. | |
291 | */ | |
97a41e26 | 292 | static struct rcu_torture * |
a241ec65 PM |
293 | rcu_torture_alloc(void) |
294 | { | |
295 | struct list_head *p; | |
296 | ||
adac1665 | 297 | spin_lock_bh(&rcu_torture_lock); |
a241ec65 PM |
298 | if (list_empty(&rcu_torture_freelist)) { |
299 | atomic_inc(&n_rcu_torture_alloc_fail); | |
adac1665 | 300 | spin_unlock_bh(&rcu_torture_lock); |
a241ec65 PM |
301 | return NULL; |
302 | } | |
303 | atomic_inc(&n_rcu_torture_alloc); | |
304 | p = rcu_torture_freelist.next; | |
305 | list_del_init(p); | |
adac1665 | 306 | spin_unlock_bh(&rcu_torture_lock); |
a241ec65 PM |
307 | return container_of(p, struct rcu_torture, rtort_free); |
308 | } | |
309 | ||
310 | /* | |
311 | * Free an element to the rcu_tortures pool. | |
312 | */ | |
313 | static void | |
314 | rcu_torture_free(struct rcu_torture *p) | |
315 | { | |
316 | atomic_inc(&n_rcu_torture_free); | |
adac1665 | 317 | spin_lock_bh(&rcu_torture_lock); |
a241ec65 | 318 | list_add_tail(&p->rtort_free, &rcu_torture_freelist); |
adac1665 | 319 | spin_unlock_bh(&rcu_torture_lock); |
a241ec65 PM |
320 | } |
321 | ||
a241ec65 PM |
322 | struct rcu_random_state { |
323 | unsigned long rrs_state; | |
75cfef32 | 324 | long rrs_count; |
a241ec65 PM |
325 | }; |
326 | ||
327 | #define RCU_RANDOM_MULT 39916801 /* prime */ | |
328 | #define RCU_RANDOM_ADD 479001701 /* prime */ | |
329 | #define RCU_RANDOM_REFRESH 10000 | |
330 | ||
331 | #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 } | |
332 | ||
333 | /* | |
334 | * Crude but fast random-number generator. Uses a linear congruential | |
c17ac855 | 335 | * generator, with occasional help from cpu_clock(). |
a241ec65 | 336 | */ |
75cfef32 | 337 | static unsigned long |
a241ec65 PM |
338 | rcu_random(struct rcu_random_state *rrsp) |
339 | { | |
a241ec65 | 340 | if (--rrsp->rrs_count < 0) { |
c676329a | 341 | rrsp->rrs_state += (unsigned long)local_clock(); |
a241ec65 PM |
342 | rrsp->rrs_count = RCU_RANDOM_REFRESH; |
343 | } | |
344 | rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD; | |
345 | return swahw32(rrsp->rrs_state); | |
346 | } | |
347 | ||
d120f65f | 348 | static void |
e66c33d5 | 349 | rcu_stutter_wait(const char *title) |
d120f65f | 350 | { |
c9d557c1 | 351 | while (stutter_pause_test || !rcutorture_runnable) { |
e3d7be27 PM |
352 | if (rcutorture_runnable) |
353 | schedule_timeout_interruptible(1); | |
354 | else | |
3ccf79f4 | 355 | schedule_timeout_interruptible(round_jiffies_relative(HZ)); |
c9d557c1 | 356 | rcutorture_shutdown_absorb(title); |
343e9099 | 357 | } |
d120f65f PM |
358 | } |
359 | ||
72e9bb54 PM |
360 | /* |
361 | * Operations vector for selecting different types of tests. | |
362 | */ | |
363 | ||
364 | struct rcu_torture_ops { | |
365 | void (*init)(void); | |
72e9bb54 | 366 | int (*readlock)(void); |
0acc512c | 367 | void (*read_delay)(struct rcu_random_state *rrsp); |
72e9bb54 PM |
368 | void (*readunlock)(int idx); |
369 | int (*completed)(void); | |
0acc512c | 370 | void (*deferred_free)(struct rcu_torture *p); |
b772e1dd | 371 | void (*sync)(void); |
2ec1f2d9 | 372 | void (*exp_sync)(void); |
fae4b54f | 373 | void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu)); |
2326974d | 374 | void (*cb_barrier)(void); |
bf66f18e | 375 | void (*fqs)(void); |
72e9bb54 | 376 | int (*stats)(char *page); |
0acc512c | 377 | int irq_capable; |
8e8be45e | 378 | int can_boost; |
e66c33d5 | 379 | const char *name; |
72e9bb54 | 380 | }; |
a71fca58 PM |
381 | |
382 | static struct rcu_torture_ops *cur_ops; | |
72e9bb54 PM |
383 | |
384 | /* | |
385 | * Definitions for rcu torture testing. | |
386 | */ | |
387 | ||
a49a4af7 | 388 | static int rcu_torture_read_lock(void) __acquires(RCU) |
72e9bb54 PM |
389 | { |
390 | rcu_read_lock(); | |
391 | return 0; | |
392 | } | |
393 | ||
b2896d2e PM |
394 | static void rcu_read_delay(struct rcu_random_state *rrsp) |
395 | { | |
b8d57a76 JT |
396 | const unsigned long shortdelay_us = 200; |
397 | const unsigned long longdelay_ms = 50; | |
b2896d2e | 398 | |
b8d57a76 JT |
399 | /* We want a short delay sometimes to make a reader delay the grace |
400 | * period, and we want a long delay occasionally to trigger | |
401 | * force_quiescent_state. */ | |
b2896d2e | 402 | |
b8d57a76 JT |
403 | if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms))) |
404 | mdelay(longdelay_ms); | |
405 | if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us))) | |
406 | udelay(shortdelay_us); | |
e546f485 LJ |
407 | #ifdef CONFIG_PREEMPT |
408 | if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000))) | |
409 | preempt_schedule(); /* No QS if preempt_disable() in effect */ | |
410 | #endif | |
b2896d2e PM |
411 | } |
412 | ||
a49a4af7 | 413 | static void rcu_torture_read_unlock(int idx) __releases(RCU) |
72e9bb54 PM |
414 | { |
415 | rcu_read_unlock(); | |
416 | } | |
417 | ||
418 | static int rcu_torture_completed(void) | |
419 | { | |
420 | return rcu_batches_completed(); | |
421 | } | |
422 | ||
423 | static void | |
424 | rcu_torture_cb(struct rcu_head *p) | |
425 | { | |
426 | int i; | |
427 | struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu); | |
428 | ||
c9d557c1 | 429 | if (fullstop != FULLSTOP_DONTSTOP) { |
72e9bb54 PM |
430 | /* Test is ending, just drop callbacks on the floor. */ |
431 | /* The next initialization will pick up the pieces. */ | |
432 | return; | |
433 | } | |
434 | i = rp->rtort_pipe_count; | |
435 | if (i > RCU_TORTURE_PIPE_LEN) | |
436 | i = RCU_TORTURE_PIPE_LEN; | |
437 | atomic_inc(&rcu_torture_wcount[i]); | |
438 | if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) { | |
439 | rp->rtort_mbtest = 0; | |
440 | rcu_torture_free(rp); | |
c701d5d9 | 441 | } else { |
0acc512c | 442 | cur_ops->deferred_free(rp); |
c701d5d9 | 443 | } |
72e9bb54 PM |
444 | } |
445 | ||
d9a3da06 PM |
446 | static int rcu_no_completed(void) |
447 | { | |
448 | return 0; | |
449 | } | |
450 | ||
72e9bb54 PM |
451 | static void rcu_torture_deferred_free(struct rcu_torture *p) |
452 | { | |
453 | call_rcu(&p->rtort_rcu, rcu_torture_cb); | |
454 | } | |
455 | ||
e3033736 JT |
456 | static void rcu_sync_torture_init(void) |
457 | { | |
458 | INIT_LIST_HEAD(&rcu_torture_removed); | |
459 | } | |
460 | ||
2ec1f2d9 | 461 | static struct rcu_torture_ops rcu_ops = { |
0acc512c | 462 | .init = rcu_sync_torture_init, |
0acc512c PM |
463 | .readlock = rcu_torture_read_lock, |
464 | .read_delay = rcu_read_delay, | |
465 | .readunlock = rcu_torture_read_unlock, | |
466 | .completed = rcu_torture_completed, | |
2ec1f2d9 | 467 | .deferred_free = rcu_torture_deferred_free, |
0acc512c | 468 | .sync = synchronize_rcu, |
2ec1f2d9 PM |
469 | .exp_sync = synchronize_rcu_expedited, |
470 | .call = call_rcu, | |
471 | .cb_barrier = rcu_barrier, | |
bf66f18e | 472 | .fqs = rcu_force_quiescent_state, |
d9a3da06 PM |
473 | .stats = NULL, |
474 | .irq_capable = 1, | |
8e8be45e | 475 | .can_boost = rcu_can_boost(), |
2ec1f2d9 | 476 | .name = "rcu" |
d9a3da06 PM |
477 | }; |
478 | ||
c32e0660 PM |
479 | /* |
480 | * Definitions for rcu_bh torture testing. | |
481 | */ | |
482 | ||
a49a4af7 | 483 | static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH) |
c32e0660 PM |
484 | { |
485 | rcu_read_lock_bh(); | |
486 | return 0; | |
487 | } | |
488 | ||
a49a4af7 | 489 | static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH) |
c32e0660 PM |
490 | { |
491 | rcu_read_unlock_bh(); | |
492 | } | |
493 | ||
494 | static int rcu_bh_torture_completed(void) | |
495 | { | |
496 | return rcu_batches_completed_bh(); | |
497 | } | |
498 | ||
499 | static void rcu_bh_torture_deferred_free(struct rcu_torture *p) | |
500 | { | |
501 | call_rcu_bh(&p->rtort_rcu, rcu_torture_cb); | |
502 | } | |
503 | ||
504 | static struct rcu_torture_ops rcu_bh_ops = { | |
2ec1f2d9 | 505 | .init = rcu_sync_torture_init, |
0acc512c PM |
506 | .readlock = rcu_bh_torture_read_lock, |
507 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
508 | .readunlock = rcu_bh_torture_read_unlock, | |
509 | .completed = rcu_bh_torture_completed, | |
510 | .deferred_free = rcu_bh_torture_deferred_free, | |
bdf2a436 | 511 | .sync = synchronize_rcu_bh, |
2ec1f2d9 | 512 | .exp_sync = synchronize_rcu_bh_expedited, |
fae4b54f | 513 | .call = call_rcu_bh, |
0acc512c | 514 | .cb_barrier = rcu_barrier_bh, |
bf66f18e | 515 | .fqs = rcu_bh_force_quiescent_state, |
0acc512c PM |
516 | .stats = NULL, |
517 | .irq_capable = 1, | |
518 | .name = "rcu_bh" | |
c32e0660 PM |
519 | }; |
520 | ||
b2896d2e PM |
521 | /* |
522 | * Definitions for srcu torture testing. | |
523 | */ | |
524 | ||
cda4dc81 | 525 | DEFINE_STATIC_SRCU(srcu_ctl); |
b2896d2e | 526 | |
012d3ca8 | 527 | static int srcu_torture_read_lock(void) __acquires(&srcu_ctl) |
b2896d2e PM |
528 | { |
529 | return srcu_read_lock(&srcu_ctl); | |
530 | } | |
531 | ||
532 | static void srcu_read_delay(struct rcu_random_state *rrsp) | |
533 | { | |
534 | long delay; | |
535 | const long uspertick = 1000000 / HZ; | |
536 | const long longdelay = 10; | |
537 | ||
538 | /* We want there to be long-running readers, but not all the time. */ | |
539 | ||
540 | delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick); | |
541 | if (!delay) | |
542 | schedule_timeout_interruptible(longdelay); | |
e546f485 LJ |
543 | else |
544 | rcu_read_delay(rrsp); | |
b2896d2e PM |
545 | } |
546 | ||
012d3ca8 | 547 | static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl) |
b2896d2e PM |
548 | { |
549 | srcu_read_unlock(&srcu_ctl, idx); | |
550 | } | |
551 | ||
552 | static int srcu_torture_completed(void) | |
553 | { | |
554 | return srcu_batches_completed(&srcu_ctl); | |
555 | } | |
556 | ||
9059c940 LJ |
557 | static void srcu_torture_deferred_free(struct rcu_torture *rp) |
558 | { | |
559 | call_srcu(&srcu_ctl, &rp->rtort_rcu, rcu_torture_cb); | |
560 | } | |
561 | ||
b772e1dd JT |
562 | static void srcu_torture_synchronize(void) |
563 | { | |
564 | synchronize_srcu(&srcu_ctl); | |
565 | } | |
566 | ||
e3f8d378 PM |
567 | static void srcu_torture_call(struct rcu_head *head, |
568 | void (*func)(struct rcu_head *head)) | |
569 | { | |
570 | call_srcu(&srcu_ctl, head, func); | |
571 | } | |
572 | ||
573 | static void srcu_torture_barrier(void) | |
574 | { | |
575 | srcu_barrier(&srcu_ctl); | |
576 | } | |
577 | ||
b2896d2e PM |
578 | static int srcu_torture_stats(char *page) |
579 | { | |
580 | int cnt = 0; | |
581 | int cpu; | |
582 | int idx = srcu_ctl.completed & 0x1; | |
583 | ||
584 | cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):", | |
585 | torture_type, TORTURE_FLAG, idx); | |
586 | for_each_possible_cpu(cpu) { | |
cef50120 | 587 | cnt += sprintf(&page[cnt], " %d(%lu,%lu)", cpu, |
b2896d2e PM |
588 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx], |
589 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]); | |
590 | } | |
591 | cnt += sprintf(&page[cnt], "\n"); | |
592 | return cnt; | |
593 | } | |
594 | ||
2ec1f2d9 PM |
595 | static void srcu_torture_synchronize_expedited(void) |
596 | { | |
597 | synchronize_srcu_expedited(&srcu_ctl); | |
598 | } | |
599 | ||
b2896d2e | 600 | static struct rcu_torture_ops srcu_ops = { |
cda4dc81 | 601 | .init = rcu_sync_torture_init, |
0acc512c PM |
602 | .readlock = srcu_torture_read_lock, |
603 | .read_delay = srcu_read_delay, | |
604 | .readunlock = srcu_torture_read_unlock, | |
605 | .completed = srcu_torture_completed, | |
9059c940 | 606 | .deferred_free = srcu_torture_deferred_free, |
0acc512c | 607 | .sync = srcu_torture_synchronize, |
2ec1f2d9 | 608 | .exp_sync = srcu_torture_synchronize_expedited, |
e3f8d378 PM |
609 | .call = srcu_torture_call, |
610 | .cb_barrier = srcu_torture_barrier, | |
0acc512c PM |
611 | .stats = srcu_torture_stats, |
612 | .name = "srcu" | |
b2896d2e PM |
613 | }; |
614 | ||
4b6c2cca JT |
615 | /* |
616 | * Definitions for sched torture testing. | |
617 | */ | |
618 | ||
619 | static int sched_torture_read_lock(void) | |
620 | { | |
621 | preempt_disable(); | |
622 | return 0; | |
623 | } | |
624 | ||
625 | static void sched_torture_read_unlock(int idx) | |
626 | { | |
627 | preempt_enable(); | |
628 | } | |
629 | ||
2326974d PM |
630 | static void rcu_sched_torture_deferred_free(struct rcu_torture *p) |
631 | { | |
632 | call_rcu_sched(&p->rtort_rcu, rcu_torture_cb); | |
633 | } | |
634 | ||
4b6c2cca | 635 | static struct rcu_torture_ops sched_ops = { |
0acc512c | 636 | .init = rcu_sync_torture_init, |
0acc512c PM |
637 | .readlock = sched_torture_read_lock, |
638 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
639 | .readunlock = sched_torture_read_unlock, | |
d9a3da06 | 640 | .completed = rcu_no_completed, |
0acc512c | 641 | .deferred_free = rcu_sched_torture_deferred_free, |
bdf2a436 | 642 | .sync = synchronize_sched, |
2ec1f2d9 PM |
643 | .exp_sync = synchronize_sched_expedited, |
644 | .call = call_rcu_sched, | |
0acc512c | 645 | .cb_barrier = rcu_barrier_sched, |
bf66f18e | 646 | .fqs = rcu_sched_force_quiescent_state, |
0acc512c PM |
647 | .stats = NULL, |
648 | .irq_capable = 1, | |
649 | .name = "sched" | |
4b6c2cca JT |
650 | }; |
651 | ||
8e8be45e PM |
652 | /* |
653 | * RCU torture priority-boost testing. Runs one real-time thread per | |
654 | * CPU for moderate bursts, repeatedly registering RCU callbacks and | |
655 | * spinning waiting for them to be invoked. If a given callback takes | |
656 | * too long to be invoked, we assume that priority inversion has occurred. | |
657 | */ | |
658 | ||
659 | struct rcu_boost_inflight { | |
660 | struct rcu_head rcu; | |
661 | int inflight; | |
662 | }; | |
663 | ||
664 | static void rcu_torture_boost_cb(struct rcu_head *head) | |
665 | { | |
666 | struct rcu_boost_inflight *rbip = | |
667 | container_of(head, struct rcu_boost_inflight, rcu); | |
668 | ||
669 | smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */ | |
670 | rbip->inflight = 0; | |
671 | } | |
672 | ||
673 | static int rcu_torture_boost(void *arg) | |
674 | { | |
675 | unsigned long call_rcu_time; | |
676 | unsigned long endtime; | |
677 | unsigned long oldstarttime; | |
678 | struct rcu_boost_inflight rbi = { .inflight = 0 }; | |
679 | struct sched_param sp; | |
680 | ||
681 | VERBOSE_PRINTK_STRING("rcu_torture_boost started"); | |
682 | ||
683 | /* Set real-time priority. */ | |
684 | sp.sched_priority = 1; | |
685 | if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) { | |
686 | VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!"); | |
687 | n_rcu_torture_boost_rterror++; | |
688 | } | |
689 | ||
561190e3 | 690 | init_rcu_head_on_stack(&rbi.rcu); |
8e8be45e PM |
691 | /* Each pass through the following loop does one boost-test cycle. */ |
692 | do { | |
693 | /* Wait for the next test interval. */ | |
694 | oldstarttime = boost_starttime; | |
93898fb1 | 695 | while (ULONG_CMP_LT(jiffies, oldstarttime)) { |
0e11c8e8 | 696 | schedule_timeout_interruptible(oldstarttime - jiffies); |
8e8be45e PM |
697 | rcu_stutter_wait("rcu_torture_boost"); |
698 | if (kthread_should_stop() || | |
699 | fullstop != FULLSTOP_DONTSTOP) | |
700 | goto checkwait; | |
701 | } | |
702 | ||
703 | /* Do one boost-test interval. */ | |
704 | endtime = oldstarttime + test_boost_duration * HZ; | |
705 | call_rcu_time = jiffies; | |
93898fb1 | 706 | while (ULONG_CMP_LT(jiffies, endtime)) { |
8e8be45e PM |
707 | /* If we don't have a callback in flight, post one. */ |
708 | if (!rbi.inflight) { | |
709 | smp_mb(); /* RCU core before ->inflight = 1. */ | |
710 | rbi.inflight = 1; | |
711 | call_rcu(&rbi.rcu, rcu_torture_boost_cb); | |
712 | if (jiffies - call_rcu_time > | |
713 | test_boost_duration * HZ - HZ / 2) { | |
714 | VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed"); | |
715 | n_rcu_torture_boost_failure++; | |
716 | } | |
717 | call_rcu_time = jiffies; | |
718 | } | |
719 | cond_resched(); | |
720 | rcu_stutter_wait("rcu_torture_boost"); | |
721 | if (kthread_should_stop() || | |
722 | fullstop != FULLSTOP_DONTSTOP) | |
723 | goto checkwait; | |
724 | } | |
725 | ||
726 | /* | |
727 | * Set the start time of the next test interval. | |
728 | * Yes, this is vulnerable to long delays, but such | |
729 | * delays simply cause a false negative for the next | |
730 | * interval. Besides, we are running at RT priority, | |
731 | * so delays should be relatively rare. | |
732 | */ | |
ab8f11e5 PM |
733 | while (oldstarttime == boost_starttime && |
734 | !kthread_should_stop()) { | |
8e8be45e PM |
735 | if (mutex_trylock(&boost_mutex)) { |
736 | boost_starttime = jiffies + | |
737 | test_boost_interval * HZ; | |
738 | n_rcu_torture_boosts++; | |
739 | mutex_unlock(&boost_mutex); | |
740 | break; | |
741 | } | |
742 | schedule_timeout_uninterruptible(1); | |
743 | } | |
744 | ||
745 | /* Go do the stutter. */ | |
746 | checkwait: rcu_stutter_wait("rcu_torture_boost"); | |
747 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
748 | ||
749 | /* Clean up and exit. */ | |
750 | VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping"); | |
751 | rcutorture_shutdown_absorb("rcu_torture_boost"); | |
752 | while (!kthread_should_stop() || rbi.inflight) | |
753 | schedule_timeout_uninterruptible(1); | |
754 | smp_mb(); /* order accesses to ->inflight before stack-frame death. */ | |
9d68197c | 755 | destroy_rcu_head_on_stack(&rbi.rcu); |
8e8be45e PM |
756 | return 0; |
757 | } | |
758 | ||
bf66f18e PM |
759 | /* |
760 | * RCU torture force-quiescent-state kthread. Repeatedly induces | |
761 | * bursts of calls to force_quiescent_state(), increasing the probability | |
762 | * of occurrence of some important types of race conditions. | |
763 | */ | |
764 | static int | |
765 | rcu_torture_fqs(void *arg) | |
766 | { | |
767 | unsigned long fqs_resume_time; | |
768 | int fqs_burst_remaining; | |
769 | ||
770 | VERBOSE_PRINTK_STRING("rcu_torture_fqs task started"); | |
771 | do { | |
772 | fqs_resume_time = jiffies + fqs_stutter * HZ; | |
93898fb1 PM |
773 | while (ULONG_CMP_LT(jiffies, fqs_resume_time) && |
774 | !kthread_should_stop()) { | |
bf66f18e PM |
775 | schedule_timeout_interruptible(1); |
776 | } | |
777 | fqs_burst_remaining = fqs_duration; | |
93898fb1 PM |
778 | while (fqs_burst_remaining > 0 && |
779 | !kthread_should_stop()) { | |
bf66f18e PM |
780 | cur_ops->fqs(); |
781 | udelay(fqs_holdoff); | |
782 | fqs_burst_remaining -= fqs_holdoff; | |
783 | } | |
784 | rcu_stutter_wait("rcu_torture_fqs"); | |
785 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
786 | VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping"); | |
787 | rcutorture_shutdown_absorb("rcu_torture_fqs"); | |
788 | while (!kthread_should_stop()) | |
789 | schedule_timeout_uninterruptible(1); | |
790 | return 0; | |
791 | } | |
792 | ||
a241ec65 PM |
793 | /* |
794 | * RCU torture writer kthread. Repeatedly substitutes a new structure | |
795 | * for that pointed to by rcu_torture_current, freeing the old structure | |
796 | * after a series of grace periods (the "pipeline"). | |
797 | */ | |
798 | static int | |
799 | rcu_torture_writer(void *arg) | |
800 | { | |
2ec1f2d9 | 801 | bool exp; |
a241ec65 PM |
802 | int i; |
803 | long oldbatch = rcu_batches_completed(); | |
804 | struct rcu_torture *rp; | |
2ec1f2d9 | 805 | struct rcu_torture *rp1; |
a241ec65 PM |
806 | struct rcu_torture *old_rp; |
807 | static DEFINE_RCU_RANDOM(rand); | |
808 | ||
809 | VERBOSE_PRINTK_STRING("rcu_torture_writer task started"); | |
dbdf65b1 IM |
810 | set_user_nice(current, 19); |
811 | ||
a241ec65 PM |
812 | do { |
813 | schedule_timeout_uninterruptible(1); | |
a71fca58 PM |
814 | rp = rcu_torture_alloc(); |
815 | if (rp == NULL) | |
a241ec65 PM |
816 | continue; |
817 | rp->rtort_pipe_count = 0; | |
818 | udelay(rcu_random(&rand) & 0x3ff); | |
0ddea0ea PM |
819 | old_rp = rcu_dereference_check(rcu_torture_current, |
820 | current == writer_task); | |
996417d2 | 821 | rp->rtort_mbtest = 1; |
a241ec65 | 822 | rcu_assign_pointer(rcu_torture_current, rp); |
9b2619af | 823 | smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */ |
c8e5b163 | 824 | if (old_rp) { |
a241ec65 PM |
825 | i = old_rp->rtort_pipe_count; |
826 | if (i > RCU_TORTURE_PIPE_LEN) | |
827 | i = RCU_TORTURE_PIPE_LEN; | |
828 | atomic_inc(&rcu_torture_wcount[i]); | |
829 | old_rp->rtort_pipe_count++; | |
2ec1f2d9 PM |
830 | if (gp_normal == gp_exp) |
831 | exp = !!(rcu_random(&rand) & 0x80); | |
832 | else | |
833 | exp = gp_exp; | |
834 | if (!exp) { | |
835 | cur_ops->deferred_free(old_rp); | |
836 | } else { | |
837 | cur_ops->exp_sync(); | |
838 | list_add(&old_rp->rtort_free, | |
839 | &rcu_torture_removed); | |
840 | list_for_each_entry_safe(rp, rp1, | |
841 | &rcu_torture_removed, | |
842 | rtort_free) { | |
843 | i = rp->rtort_pipe_count; | |
844 | if (i > RCU_TORTURE_PIPE_LEN) | |
845 | i = RCU_TORTURE_PIPE_LEN; | |
846 | atomic_inc(&rcu_torture_wcount[i]); | |
847 | if (++rp->rtort_pipe_count >= | |
848 | RCU_TORTURE_PIPE_LEN) { | |
849 | rp->rtort_mbtest = 0; | |
850 | list_del(&rp->rtort_free); | |
851 | rcu_torture_free(rp); | |
852 | } | |
853 | } | |
854 | } | |
a241ec65 | 855 | } |
4a298656 | 856 | rcutorture_record_progress(++rcu_torture_current_version); |
72e9bb54 | 857 | oldbatch = cur_ops->completed(); |
c9d557c1 PM |
858 | rcu_stutter_wait("rcu_torture_writer"); |
859 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
a241ec65 | 860 | VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping"); |
c9d557c1 PM |
861 | rcutorture_shutdown_absorb("rcu_torture_writer"); |
862 | while (!kthread_should_stop()) | |
a241ec65 PM |
863 | schedule_timeout_uninterruptible(1); |
864 | return 0; | |
865 | } | |
866 | ||
b772e1dd JT |
867 | /* |
868 | * RCU torture fake writer kthread. Repeatedly calls sync, with a random | |
869 | * delay between calls. | |
870 | */ | |
871 | static int | |
872 | rcu_torture_fakewriter(void *arg) | |
873 | { | |
874 | DEFINE_RCU_RANDOM(rand); | |
875 | ||
876 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started"); | |
877 | set_user_nice(current, 19); | |
878 | ||
879 | do { | |
880 | schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10); | |
881 | udelay(rcu_random(&rand) & 0x3ff); | |
72472a02 | 882 | if (cur_ops->cb_barrier != NULL && |
2ec1f2d9 | 883 | rcu_random(&rand) % (nfakewriters * 8) == 0) { |
72472a02 | 884 | cur_ops->cb_barrier(); |
2ec1f2d9 PM |
885 | } else if (gp_normal == gp_exp) { |
886 | if (rcu_random(&rand) & 0x80) | |
887 | cur_ops->sync(); | |
888 | else | |
889 | cur_ops->exp_sync(); | |
890 | } else if (gp_normal) { | |
72472a02 | 891 | cur_ops->sync(); |
2ec1f2d9 PM |
892 | } else { |
893 | cur_ops->exp_sync(); | |
894 | } | |
c9d557c1 PM |
895 | rcu_stutter_wait("rcu_torture_fakewriter"); |
896 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
b772e1dd JT |
897 | |
898 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping"); | |
c9d557c1 PM |
899 | rcutorture_shutdown_absorb("rcu_torture_fakewriter"); |
900 | while (!kthread_should_stop()) | |
b772e1dd JT |
901 | schedule_timeout_uninterruptible(1); |
902 | return 0; | |
903 | } | |
904 | ||
91afaf30 PM |
905 | void rcutorture_trace_dump(void) |
906 | { | |
907 | static atomic_t beenhere = ATOMIC_INIT(0); | |
908 | ||
909 | if (atomic_read(&beenhere)) | |
910 | return; | |
911 | if (atomic_xchg(&beenhere, 1) != 0) | |
912 | return; | |
91afaf30 PM |
913 | ftrace_dump(DUMP_ALL); |
914 | } | |
915 | ||
0729fbf3 PM |
916 | /* |
917 | * RCU torture reader from timer handler. Dereferences rcu_torture_current, | |
918 | * incrementing the corresponding element of the pipeline array. The | |
919 | * counter in the element should never be greater than 1, otherwise, the | |
920 | * RCU implementation is broken. | |
921 | */ | |
922 | static void rcu_torture_timer(unsigned long unused) | |
923 | { | |
924 | int idx; | |
925 | int completed; | |
52494535 | 926 | int completed_end; |
0729fbf3 PM |
927 | static DEFINE_RCU_RANDOM(rand); |
928 | static DEFINE_SPINLOCK(rand_lock); | |
929 | struct rcu_torture *p; | |
930 | int pipe_count; | |
52494535 | 931 | unsigned long long ts; |
0729fbf3 PM |
932 | |
933 | idx = cur_ops->readlock(); | |
934 | completed = cur_ops->completed(); | |
e4aa0da3 | 935 | ts = rcu_trace_clock_local(); |
632ee200 | 936 | p = rcu_dereference_check(rcu_torture_current, |
632ee200 PM |
937 | rcu_read_lock_bh_held() || |
938 | rcu_read_lock_sched_held() || | |
939 | srcu_read_lock_held(&srcu_ctl)); | |
0729fbf3 PM |
940 | if (p == NULL) { |
941 | /* Leave because rcu_torture_writer is not yet underway */ | |
942 | cur_ops->readunlock(idx); | |
943 | return; | |
944 | } | |
945 | if (p->rtort_mbtest == 0) | |
946 | atomic_inc(&n_rcu_torture_mberror); | |
947 | spin_lock(&rand_lock); | |
0acc512c | 948 | cur_ops->read_delay(&rand); |
0729fbf3 PM |
949 | n_rcu_torture_timers++; |
950 | spin_unlock(&rand_lock); | |
951 | preempt_disable(); | |
952 | pipe_count = p->rtort_pipe_count; | |
953 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { | |
954 | /* Should not happen, but... */ | |
955 | pipe_count = RCU_TORTURE_PIPE_LEN; | |
956 | } | |
52494535 PM |
957 | completed_end = cur_ops->completed(); |
958 | if (pipe_count > 1) { | |
52494535 PM |
959 | do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, ts, |
960 | completed, completed_end); | |
91afaf30 | 961 | rcutorture_trace_dump(); |
52494535 | 962 | } |
dd17c8f7 | 963 | __this_cpu_inc(rcu_torture_count[pipe_count]); |
52494535 | 964 | completed = completed_end - completed; |
0729fbf3 PM |
965 | if (completed > RCU_TORTURE_PIPE_LEN) { |
966 | /* Should not happen, but... */ | |
967 | completed = RCU_TORTURE_PIPE_LEN; | |
968 | } | |
dd17c8f7 | 969 | __this_cpu_inc(rcu_torture_batch[completed]); |
0729fbf3 PM |
970 | preempt_enable(); |
971 | cur_ops->readunlock(idx); | |
972 | } | |
973 | ||
a241ec65 PM |
974 | /* |
975 | * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current, | |
976 | * incrementing the corresponding element of the pipeline array. The | |
977 | * counter in the element should never be greater than 1, otherwise, the | |
978 | * RCU implementation is broken. | |
979 | */ | |
980 | static int | |
981 | rcu_torture_reader(void *arg) | |
982 | { | |
983 | int completed; | |
52494535 | 984 | int completed_end; |
72e9bb54 | 985 | int idx; |
a241ec65 PM |
986 | DEFINE_RCU_RANDOM(rand); |
987 | struct rcu_torture *p; | |
988 | int pipe_count; | |
0729fbf3 | 989 | struct timer_list t; |
52494535 | 990 | unsigned long long ts; |
a241ec65 PM |
991 | |
992 | VERBOSE_PRINTK_STRING("rcu_torture_reader task started"); | |
dbdf65b1 | 993 | set_user_nice(current, 19); |
0acc512c | 994 | if (irqreader && cur_ops->irq_capable) |
0729fbf3 | 995 | setup_timer_on_stack(&t, rcu_torture_timer, 0); |
dbdf65b1 | 996 | |
a241ec65 | 997 | do { |
0acc512c | 998 | if (irqreader && cur_ops->irq_capable) { |
0729fbf3 | 999 | if (!timer_pending(&t)) |
6155fec9 | 1000 | mod_timer(&t, jiffies + 1); |
0729fbf3 | 1001 | } |
72e9bb54 PM |
1002 | idx = cur_ops->readlock(); |
1003 | completed = cur_ops->completed(); | |
e4aa0da3 | 1004 | ts = rcu_trace_clock_local(); |
632ee200 | 1005 | p = rcu_dereference_check(rcu_torture_current, |
632ee200 PM |
1006 | rcu_read_lock_bh_held() || |
1007 | rcu_read_lock_sched_held() || | |
1008 | srcu_read_lock_held(&srcu_ctl)); | |
a241ec65 PM |
1009 | if (p == NULL) { |
1010 | /* Wait for rcu_torture_writer to get underway */ | |
72e9bb54 | 1011 | cur_ops->readunlock(idx); |
a241ec65 PM |
1012 | schedule_timeout_interruptible(HZ); |
1013 | continue; | |
1014 | } | |
996417d2 PM |
1015 | if (p->rtort_mbtest == 0) |
1016 | atomic_inc(&n_rcu_torture_mberror); | |
0acc512c | 1017 | cur_ops->read_delay(&rand); |
a241ec65 PM |
1018 | preempt_disable(); |
1019 | pipe_count = p->rtort_pipe_count; | |
1020 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { | |
1021 | /* Should not happen, but... */ | |
1022 | pipe_count = RCU_TORTURE_PIPE_LEN; | |
1023 | } | |
52494535 PM |
1024 | completed_end = cur_ops->completed(); |
1025 | if (pipe_count > 1) { | |
52494535 PM |
1026 | do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, |
1027 | ts, completed, completed_end); | |
91afaf30 | 1028 | rcutorture_trace_dump(); |
52494535 | 1029 | } |
dd17c8f7 | 1030 | __this_cpu_inc(rcu_torture_count[pipe_count]); |
52494535 | 1031 | completed = completed_end - completed; |
a241ec65 PM |
1032 | if (completed > RCU_TORTURE_PIPE_LEN) { |
1033 | /* Should not happen, but... */ | |
1034 | completed = RCU_TORTURE_PIPE_LEN; | |
1035 | } | |
dd17c8f7 | 1036 | __this_cpu_inc(rcu_torture_batch[completed]); |
a241ec65 | 1037 | preempt_enable(); |
72e9bb54 | 1038 | cur_ops->readunlock(idx); |
a241ec65 | 1039 | schedule(); |
c9d557c1 PM |
1040 | rcu_stutter_wait("rcu_torture_reader"); |
1041 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
a241ec65 | 1042 | VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping"); |
c9d557c1 | 1043 | rcutorture_shutdown_absorb("rcu_torture_reader"); |
0acc512c | 1044 | if (irqreader && cur_ops->irq_capable) |
0729fbf3 | 1045 | del_timer_sync(&t); |
c9d557c1 | 1046 | while (!kthread_should_stop()) |
a241ec65 PM |
1047 | schedule_timeout_uninterruptible(1); |
1048 | return 0; | |
1049 | } | |
1050 | ||
1051 | /* | |
1052 | * Create an RCU-torture statistics message in the specified buffer. | |
1053 | */ | |
1054 | static int | |
1055 | rcu_torture_printk(char *page) | |
1056 | { | |
1057 | int cnt = 0; | |
1058 | int cpu; | |
1059 | int i; | |
1060 | long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; | |
1061 | long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; | |
1062 | ||
0a945022 | 1063 | for_each_possible_cpu(cpu) { |
a241ec65 PM |
1064 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
1065 | pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i]; | |
1066 | batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i]; | |
1067 | } | |
1068 | } | |
1069 | for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) { | |
1070 | if (pipesummary[i] != 0) | |
1071 | break; | |
1072 | } | |
72e9bb54 | 1073 | cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG); |
a241ec65 | 1074 | cnt += sprintf(&page[cnt], |
5cf05ad7 | 1075 | "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ", |
a241ec65 PM |
1076 | rcu_torture_current, |
1077 | rcu_torture_current_version, | |
1078 | list_empty(&rcu_torture_freelist), | |
1079 | atomic_read(&n_rcu_torture_alloc), | |
1080 | atomic_read(&n_rcu_torture_alloc_fail), | |
5cf05ad7 PM |
1081 | atomic_read(&n_rcu_torture_free)); |
1082 | cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ", | |
0729fbf3 | 1083 | atomic_read(&n_rcu_torture_mberror), |
8e8be45e | 1084 | n_rcu_torture_boost_ktrerror, |
5cf05ad7 PM |
1085 | n_rcu_torture_boost_rterror); |
1086 | cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ", | |
8e8be45e PM |
1087 | n_rcu_torture_boost_failure, |
1088 | n_rcu_torture_boosts, | |
5cf05ad7 | 1089 | n_rcu_torture_timers); |
13dbf914 PM |
1090 | cnt += sprintf(&page[cnt], |
1091 | "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ", | |
1092 | n_online_successes, n_online_attempts, | |
1093 | n_offline_successes, n_offline_attempts, | |
1094 | min_online, max_online, | |
1095 | min_offline, max_offline, | |
1096 | sum_online, sum_offline, HZ); | |
5cf05ad7 | 1097 | cnt += sprintf(&page[cnt], "barrier: %ld/%ld:%ld", |
fae4b54f PM |
1098 | n_barrier_successes, |
1099 | n_barrier_attempts, | |
1100 | n_rcu_torture_barrier_error); | |
1101 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); | |
8e8be45e | 1102 | if (atomic_read(&n_rcu_torture_mberror) != 0 || |
fae4b54f | 1103 | n_rcu_torture_barrier_error != 0 || |
8e8be45e PM |
1104 | n_rcu_torture_boost_ktrerror != 0 || |
1105 | n_rcu_torture_boost_rterror != 0 || | |
fae4b54f PM |
1106 | n_rcu_torture_boost_failure != 0 || |
1107 | i > 1) { | |
a241ec65 | 1108 | cnt += sprintf(&page[cnt], "!!! "); |
996417d2 | 1109 | atomic_inc(&n_rcu_torture_error); |
5af970a4 | 1110 | WARN_ON_ONCE(1); |
996417d2 | 1111 | } |
a241ec65 PM |
1112 | cnt += sprintf(&page[cnt], "Reader Pipe: "); |
1113 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) | |
1114 | cnt += sprintf(&page[cnt], " %ld", pipesummary[i]); | |
72e9bb54 | 1115 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
a241ec65 | 1116 | cnt += sprintf(&page[cnt], "Reader Batch: "); |
72e9bb54 | 1117 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
a241ec65 | 1118 | cnt += sprintf(&page[cnt], " %ld", batchsummary[i]); |
72e9bb54 | 1119 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
a241ec65 PM |
1120 | cnt += sprintf(&page[cnt], "Free-Block Circulation: "); |
1121 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { | |
1122 | cnt += sprintf(&page[cnt], " %d", | |
1123 | atomic_read(&rcu_torture_wcount[i])); | |
1124 | } | |
1125 | cnt += sprintf(&page[cnt], "\n"); | |
c8e5b163 | 1126 | if (cur_ops->stats) |
72e9bb54 | 1127 | cnt += cur_ops->stats(&page[cnt]); |
a241ec65 PM |
1128 | return cnt; |
1129 | } | |
1130 | ||
1131 | /* | |
1132 | * Print torture statistics. Caller must ensure that there is only | |
1133 | * one call to this function at a given time!!! This is normally | |
1134 | * accomplished by relying on the module system to only have one copy | |
1135 | * of the module loaded, and then by giving the rcu_torture_stats | |
1136 | * kthread full control (or the init/cleanup functions when rcu_torture_stats | |
1137 | * thread is not running). | |
1138 | */ | |
1139 | static void | |
1140 | rcu_torture_stats_print(void) | |
1141 | { | |
1142 | int cnt; | |
1143 | ||
1144 | cnt = rcu_torture_printk(printk_buf); | |
2caa1e44 | 1145 | pr_alert("%s", printk_buf); |
a241ec65 PM |
1146 | } |
1147 | ||
1148 | /* | |
1149 | * Periodically prints torture statistics, if periodic statistics printing | |
1150 | * was specified via the stat_interval module parameter. | |
1151 | * | |
1152 | * No need to worry about fullstop here, since this one doesn't reference | |
1153 | * volatile state or register callbacks. | |
1154 | */ | |
1155 | static int | |
1156 | rcu_torture_stats(void *arg) | |
1157 | { | |
1158 | VERBOSE_PRINTK_STRING("rcu_torture_stats task started"); | |
1159 | do { | |
1160 | schedule_timeout_interruptible(stat_interval * HZ); | |
1161 | rcu_torture_stats_print(); | |
c9d557c1 PM |
1162 | rcutorture_shutdown_absorb("rcu_torture_stats"); |
1163 | } while (!kthread_should_stop()); | |
a241ec65 PM |
1164 | VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping"); |
1165 | return 0; | |
1166 | } | |
1167 | ||
d84f5203 SV |
1168 | static int rcu_idle_cpu; /* Force all torture tasks off this CPU */ |
1169 | ||
1170 | /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case | |
1171 | * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs. | |
1172 | */ | |
b2896d2e | 1173 | static void rcu_torture_shuffle_tasks(void) |
d84f5203 | 1174 | { |
d84f5203 SV |
1175 | int i; |
1176 | ||
73d0a4b1 | 1177 | cpumask_setall(shuffle_tmp_mask); |
86ef5c9a | 1178 | get_online_cpus(); |
d84f5203 SV |
1179 | |
1180 | /* No point in shuffling if there is only one online CPU (ex: UP) */ | |
c9d557c1 PM |
1181 | if (num_online_cpus() == 1) { |
1182 | put_online_cpus(); | |
1183 | return; | |
1184 | } | |
d84f5203 SV |
1185 | |
1186 | if (rcu_idle_cpu != -1) | |
73d0a4b1 | 1187 | cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask); |
d84f5203 | 1188 | |
73d0a4b1 | 1189 | set_cpus_allowed_ptr(current, shuffle_tmp_mask); |
d84f5203 | 1190 | |
c8e5b163 | 1191 | if (reader_tasks) { |
d84f5203 SV |
1192 | for (i = 0; i < nrealreaders; i++) |
1193 | if (reader_tasks[i]) | |
f70316da | 1194 | set_cpus_allowed_ptr(reader_tasks[i], |
73d0a4b1 | 1195 | shuffle_tmp_mask); |
d84f5203 | 1196 | } |
c8e5b163 | 1197 | if (fakewriter_tasks) { |
b772e1dd JT |
1198 | for (i = 0; i < nfakewriters; i++) |
1199 | if (fakewriter_tasks[i]) | |
f70316da | 1200 | set_cpus_allowed_ptr(fakewriter_tasks[i], |
73d0a4b1 | 1201 | shuffle_tmp_mask); |
b772e1dd | 1202 | } |
d84f5203 | 1203 | if (writer_task) |
73d0a4b1 | 1204 | set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask); |
d84f5203 | 1205 | if (stats_task) |
73d0a4b1 | 1206 | set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask); |
0e11c8e8 PM |
1207 | if (stutter_task) |
1208 | set_cpus_allowed_ptr(stutter_task, shuffle_tmp_mask); | |
1209 | if (fqs_task) | |
1210 | set_cpus_allowed_ptr(fqs_task, shuffle_tmp_mask); | |
1211 | if (shutdown_task) | |
1212 | set_cpus_allowed_ptr(shutdown_task, shuffle_tmp_mask); | |
1213 | #ifdef CONFIG_HOTPLUG_CPU | |
1214 | if (onoff_task) | |
1215 | set_cpus_allowed_ptr(onoff_task, shuffle_tmp_mask); | |
1216 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | |
1217 | if (stall_task) | |
1218 | set_cpus_allowed_ptr(stall_task, shuffle_tmp_mask); | |
1219 | if (barrier_cbs_tasks) | |
1220 | for (i = 0; i < n_barrier_cbs; i++) | |
1221 | if (barrier_cbs_tasks[i]) | |
1222 | set_cpus_allowed_ptr(barrier_cbs_tasks[i], | |
1223 | shuffle_tmp_mask); | |
1224 | if (barrier_task) | |
1225 | set_cpus_allowed_ptr(barrier_task, shuffle_tmp_mask); | |
d84f5203 SV |
1226 | |
1227 | if (rcu_idle_cpu == -1) | |
1228 | rcu_idle_cpu = num_online_cpus() - 1; | |
1229 | else | |
1230 | rcu_idle_cpu--; | |
1231 | ||
86ef5c9a | 1232 | put_online_cpus(); |
d84f5203 SV |
1233 | } |
1234 | ||
1235 | /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the | |
1236 | * system to become idle at a time and cut off its timer ticks. This is meant | |
1237 | * to test the support for such tickless idle CPU in RCU. | |
1238 | */ | |
1239 | static int | |
1240 | rcu_torture_shuffle(void *arg) | |
1241 | { | |
1242 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started"); | |
1243 | do { | |
1244 | schedule_timeout_interruptible(shuffle_interval * HZ); | |
1245 | rcu_torture_shuffle_tasks(); | |
c9d557c1 PM |
1246 | rcutorture_shutdown_absorb("rcu_torture_shuffle"); |
1247 | } while (!kthread_should_stop()); | |
d84f5203 SV |
1248 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping"); |
1249 | return 0; | |
1250 | } | |
1251 | ||
d120f65f PM |
1252 | /* Cause the rcutorture test to "stutter", starting and stopping all |
1253 | * threads periodically. | |
1254 | */ | |
1255 | static int | |
1256 | rcu_torture_stutter(void *arg) | |
1257 | { | |
1258 | VERBOSE_PRINTK_STRING("rcu_torture_stutter task started"); | |
1259 | do { | |
1260 | schedule_timeout_interruptible(stutter * HZ); | |
1261 | stutter_pause_test = 1; | |
c9d557c1 | 1262 | if (!kthread_should_stop()) |
d120f65f PM |
1263 | schedule_timeout_interruptible(stutter * HZ); |
1264 | stutter_pause_test = 0; | |
c9d557c1 PM |
1265 | rcutorture_shutdown_absorb("rcu_torture_stutter"); |
1266 | } while (!kthread_should_stop()); | |
d120f65f PM |
1267 | VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping"); |
1268 | return 0; | |
1269 | } | |
1270 | ||
95c38322 | 1271 | static inline void |
e66c33d5 | 1272 | rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag) |
95c38322 | 1273 | { |
2caa1e44 PM |
1274 | pr_alert("%s" TORTURE_FLAG |
1275 | "--- %s: nreaders=%d nfakewriters=%d " | |
1276 | "stat_interval=%d verbose=%d test_no_idle_hz=%d " | |
1277 | "shuffle_interval=%d stutter=%d irqreader=%d " | |
1278 | "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d " | |
1279 | "test_boost=%d/%d test_boost_interval=%d " | |
1280 | "test_boost_duration=%d shutdown_secs=%d " | |
67afeed2 PM |
1281 | "stall_cpu=%d stall_cpu_holdoff=%d " |
1282 | "n_barrier_cbs=%d " | |
2caa1e44 PM |
1283 | "onoff_interval=%d onoff_holdoff=%d\n", |
1284 | torture_type, tag, nrealreaders, nfakewriters, | |
1285 | stat_interval, verbose, test_no_idle_hz, shuffle_interval, | |
1286 | stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter, | |
1287 | test_boost, cur_ops->can_boost, | |
1288 | test_boost_interval, test_boost_duration, shutdown_secs, | |
67afeed2 PM |
1289 | stall_cpu, stall_cpu_holdoff, |
1290 | n_barrier_cbs, | |
2caa1e44 | 1291 | onoff_interval, onoff_holdoff); |
95c38322 PM |
1292 | } |
1293 | ||
8e8be45e | 1294 | static struct notifier_block rcutorture_shutdown_nb = { |
343e9099 PM |
1295 | .notifier_call = rcutorture_shutdown_notify, |
1296 | }; | |
1297 | ||
8e8be45e PM |
1298 | static void rcutorture_booster_cleanup(int cpu) |
1299 | { | |
1300 | struct task_struct *t; | |
1301 | ||
1302 | if (boost_tasks[cpu] == NULL) | |
1303 | return; | |
1304 | mutex_lock(&boost_mutex); | |
1305 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task"); | |
1306 | t = boost_tasks[cpu]; | |
1307 | boost_tasks[cpu] = NULL; | |
1308 | mutex_unlock(&boost_mutex); | |
1309 | ||
1310 | /* This must be outside of the mutex, otherwise deadlock! */ | |
1311 | kthread_stop(t); | |
37e377d2 | 1312 | boost_tasks[cpu] = NULL; |
8e8be45e PM |
1313 | } |
1314 | ||
1315 | static int rcutorture_booster_init(int cpu) | |
1316 | { | |
1317 | int retval; | |
1318 | ||
1319 | if (boost_tasks[cpu] != NULL) | |
1320 | return 0; /* Already created, nothing more to do. */ | |
1321 | ||
1322 | /* Don't allow time recalculation while creating a new task. */ | |
1323 | mutex_lock(&boost_mutex); | |
1324 | VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task"); | |
1f288094 ED |
1325 | boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL, |
1326 | cpu_to_node(cpu), | |
1327 | "rcu_torture_boost"); | |
8e8be45e PM |
1328 | if (IS_ERR(boost_tasks[cpu])) { |
1329 | retval = PTR_ERR(boost_tasks[cpu]); | |
1330 | VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed"); | |
1331 | n_rcu_torture_boost_ktrerror++; | |
1332 | boost_tasks[cpu] = NULL; | |
1333 | mutex_unlock(&boost_mutex); | |
1334 | return retval; | |
1335 | } | |
1336 | kthread_bind(boost_tasks[cpu], cpu); | |
1337 | wake_up_process(boost_tasks[cpu]); | |
1338 | mutex_unlock(&boost_mutex); | |
1339 | return 0; | |
1340 | } | |
1341 | ||
d5f546d8 PM |
1342 | /* |
1343 | * Cause the rcutorture test to shutdown the system after the test has | |
1344 | * run for the time specified by the shutdown_secs module parameter. | |
1345 | */ | |
1346 | static int | |
1347 | rcu_torture_shutdown(void *arg) | |
1348 | { | |
1349 | long delta; | |
1350 | unsigned long jiffies_snap; | |
1351 | ||
1352 | VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started"); | |
1353 | jiffies_snap = ACCESS_ONCE(jiffies); | |
1354 | while (ULONG_CMP_LT(jiffies_snap, shutdown_time) && | |
1355 | !kthread_should_stop()) { | |
1356 | delta = shutdown_time - jiffies_snap; | |
1357 | if (verbose) | |
2caa1e44 PM |
1358 | pr_alert("%s" TORTURE_FLAG |
1359 | "rcu_torture_shutdown task: %lu jiffies remaining\n", | |
1360 | torture_type, delta); | |
d5f546d8 PM |
1361 | schedule_timeout_interruptible(delta); |
1362 | jiffies_snap = ACCESS_ONCE(jiffies); | |
1363 | } | |
b58bdcca | 1364 | if (kthread_should_stop()) { |
d5f546d8 PM |
1365 | VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping"); |
1366 | return 0; | |
1367 | } | |
1368 | ||
1369 | /* OK, shut down the system. */ | |
1370 | ||
1371 | VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system"); | |
1372 | shutdown_task = NULL; /* Avoid self-kill deadlock. */ | |
1373 | rcu_torture_cleanup(); /* Get the success/failure message. */ | |
1374 | kernel_power_off(); /* Shut down the system. */ | |
1375 | return 0; | |
1376 | } | |
1377 | ||
b58bdcca PM |
1378 | #ifdef CONFIG_HOTPLUG_CPU |
1379 | ||
1380 | /* | |
1381 | * Execute random CPU-hotplug operations at the interval specified | |
1382 | * by the onoff_interval. | |
1383 | */ | |
49fb4c62 | 1384 | static int |
b58bdcca PM |
1385 | rcu_torture_onoff(void *arg) |
1386 | { | |
1387 | int cpu; | |
13dbf914 | 1388 | unsigned long delta; |
b58bdcca PM |
1389 | int maxcpu = -1; |
1390 | DEFINE_RCU_RANDOM(rand); | |
48983260 | 1391 | int ret; |
13dbf914 | 1392 | unsigned long starttime; |
b58bdcca PM |
1393 | |
1394 | VERBOSE_PRINTK_STRING("rcu_torture_onoff task started"); | |
1395 | for_each_online_cpu(cpu) | |
1396 | maxcpu = cpu; | |
1397 | WARN_ON(maxcpu < 0); | |
9b9ec9b9 PM |
1398 | if (onoff_holdoff > 0) { |
1399 | VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff"); | |
1400 | schedule_timeout_interruptible(onoff_holdoff * HZ); | |
1401 | VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff"); | |
1402 | } | |
b58bdcca PM |
1403 | while (!kthread_should_stop()) { |
1404 | cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1); | |
f220242a | 1405 | if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) { |
b58bdcca | 1406 | if (verbose) |
2caa1e44 PM |
1407 | pr_alert("%s" TORTURE_FLAG |
1408 | "rcu_torture_onoff task: offlining %d\n", | |
1409 | torture_type, cpu); | |
13dbf914 | 1410 | starttime = jiffies; |
b58bdcca | 1411 | n_offline_attempts++; |
48983260 PM |
1412 | ret = cpu_down(cpu); |
1413 | if (ret) { | |
1414 | if (verbose) | |
1415 | pr_alert("%s" TORTURE_FLAG | |
1416 | "rcu_torture_onoff task: offline %d failed: errno %d\n", | |
1417 | torture_type, cpu, ret); | |
1418 | } else { | |
b58bdcca | 1419 | if (verbose) |
2caa1e44 PM |
1420 | pr_alert("%s" TORTURE_FLAG |
1421 | "rcu_torture_onoff task: offlined %d\n", | |
1422 | torture_type, cpu); | |
b58bdcca | 1423 | n_offline_successes++; |
13dbf914 PM |
1424 | delta = jiffies - starttime; |
1425 | sum_offline += delta; | |
1426 | if (min_offline < 0) { | |
1427 | min_offline = delta; | |
1428 | max_offline = delta; | |
1429 | } | |
1430 | if (min_offline > delta) | |
1431 | min_offline = delta; | |
1432 | if (max_offline < delta) | |
1433 | max_offline = delta; | |
b58bdcca | 1434 | } |
f220242a | 1435 | } else if (cpu_is_hotpluggable(cpu)) { |
b58bdcca | 1436 | if (verbose) |
2caa1e44 PM |
1437 | pr_alert("%s" TORTURE_FLAG |
1438 | "rcu_torture_onoff task: onlining %d\n", | |
1439 | torture_type, cpu); | |
13dbf914 | 1440 | starttime = jiffies; |
b58bdcca PM |
1441 | n_online_attempts++; |
1442 | if (cpu_up(cpu) == 0) { | |
1443 | if (verbose) | |
2caa1e44 PM |
1444 | pr_alert("%s" TORTURE_FLAG |
1445 | "rcu_torture_onoff task: onlined %d\n", | |
1446 | torture_type, cpu); | |
b58bdcca | 1447 | n_online_successes++; |
13dbf914 PM |
1448 | delta = jiffies - starttime; |
1449 | sum_online += delta; | |
1450 | if (min_online < 0) { | |
1451 | min_online = delta; | |
1452 | max_online = delta; | |
1453 | } | |
1454 | if (min_online > delta) | |
1455 | min_online = delta; | |
1456 | if (max_online < delta) | |
1457 | max_online = delta; | |
b58bdcca PM |
1458 | } |
1459 | } | |
1460 | schedule_timeout_interruptible(onoff_interval * HZ); | |
1461 | } | |
1462 | VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping"); | |
1463 | return 0; | |
1464 | } | |
1465 | ||
49fb4c62 | 1466 | static int |
b58bdcca PM |
1467 | rcu_torture_onoff_init(void) |
1468 | { | |
3c1b1ce0 JL |
1469 | int ret; |
1470 | ||
b58bdcca PM |
1471 | if (onoff_interval <= 0) |
1472 | return 0; | |
1473 | onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff"); | |
1474 | if (IS_ERR(onoff_task)) { | |
3c1b1ce0 | 1475 | ret = PTR_ERR(onoff_task); |
b58bdcca | 1476 | onoff_task = NULL; |
3c1b1ce0 | 1477 | return ret; |
b58bdcca PM |
1478 | } |
1479 | return 0; | |
1480 | } | |
1481 | ||
1482 | static void rcu_torture_onoff_cleanup(void) | |
1483 | { | |
1484 | if (onoff_task == NULL) | |
1485 | return; | |
1486 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task"); | |
1487 | kthread_stop(onoff_task); | |
37e377d2 | 1488 | onoff_task = NULL; |
b58bdcca PM |
1489 | } |
1490 | ||
1491 | #else /* #ifdef CONFIG_HOTPLUG_CPU */ | |
1492 | ||
37e377d2 | 1493 | static int |
b58bdcca PM |
1494 | rcu_torture_onoff_init(void) |
1495 | { | |
37e377d2 | 1496 | return 0; |
b58bdcca PM |
1497 | } |
1498 | ||
1499 | static void rcu_torture_onoff_cleanup(void) | |
1500 | { | |
1501 | } | |
1502 | ||
1503 | #endif /* #else #ifdef CONFIG_HOTPLUG_CPU */ | |
1504 | ||
c13f3757 PM |
1505 | /* |
1506 | * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then | |
1507 | * induces a CPU stall for the time specified by stall_cpu. | |
1508 | */ | |
49fb4c62 | 1509 | static int rcu_torture_stall(void *args) |
c13f3757 PM |
1510 | { |
1511 | unsigned long stop_at; | |
1512 | ||
1513 | VERBOSE_PRINTK_STRING("rcu_torture_stall task started"); | |
1514 | if (stall_cpu_holdoff > 0) { | |
1515 | VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff"); | |
1516 | schedule_timeout_interruptible(stall_cpu_holdoff * HZ); | |
1517 | VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff"); | |
1518 | } | |
1519 | if (!kthread_should_stop()) { | |
1520 | stop_at = get_seconds() + stall_cpu; | |
1521 | /* RCU CPU stall is expected behavior in following code. */ | |
2caa1e44 | 1522 | pr_alert("rcu_torture_stall start.\n"); |
c13f3757 PM |
1523 | rcu_read_lock(); |
1524 | preempt_disable(); | |
1525 | while (ULONG_CMP_LT(get_seconds(), stop_at)) | |
1526 | continue; /* Induce RCU CPU stall warning. */ | |
1527 | preempt_enable(); | |
1528 | rcu_read_unlock(); | |
2caa1e44 | 1529 | pr_alert("rcu_torture_stall end.\n"); |
c13f3757 PM |
1530 | } |
1531 | rcutorture_shutdown_absorb("rcu_torture_stall"); | |
1532 | while (!kthread_should_stop()) | |
1533 | schedule_timeout_interruptible(10 * HZ); | |
1534 | return 0; | |
1535 | } | |
1536 | ||
1537 | /* Spawn CPU-stall kthread, if stall_cpu specified. */ | |
1538 | static int __init rcu_torture_stall_init(void) | |
1539 | { | |
1540 | int ret; | |
1541 | ||
1542 | if (stall_cpu <= 0) | |
1543 | return 0; | |
1544 | stall_task = kthread_run(rcu_torture_stall, NULL, "rcu_torture_stall"); | |
1545 | if (IS_ERR(stall_task)) { | |
1546 | ret = PTR_ERR(stall_task); | |
1547 | stall_task = NULL; | |
1548 | return ret; | |
1549 | } | |
1550 | return 0; | |
1551 | } | |
1552 | ||
1553 | /* Clean up after the CPU-stall kthread, if one was spawned. */ | |
1554 | static void rcu_torture_stall_cleanup(void) | |
1555 | { | |
1556 | if (stall_task == NULL) | |
1557 | return; | |
1558 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task."); | |
1559 | kthread_stop(stall_task); | |
37e377d2 | 1560 | stall_task = NULL; |
c13f3757 PM |
1561 | } |
1562 | ||
fae4b54f PM |
1563 | /* Callback function for RCU barrier testing. */ |
1564 | void rcu_torture_barrier_cbf(struct rcu_head *rcu) | |
1565 | { | |
1566 | atomic_inc(&barrier_cbs_invoked); | |
1567 | } | |
1568 | ||
1569 | /* kthread function to register callbacks used to test RCU barriers. */ | |
1570 | static int rcu_torture_barrier_cbs(void *arg) | |
1571 | { | |
1572 | long myid = (long)arg; | |
c6ebcbb6 | 1573 | bool lastphase = 0; |
fae4b54f PM |
1574 | struct rcu_head rcu; |
1575 | ||
1576 | init_rcu_head_on_stack(&rcu); | |
1577 | VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started"); | |
1578 | set_user_nice(current, 19); | |
1579 | do { | |
1580 | wait_event(barrier_cbs_wq[myid], | |
c6ebcbb6 | 1581 | barrier_phase != lastphase || |
fae4b54f PM |
1582 | kthread_should_stop() || |
1583 | fullstop != FULLSTOP_DONTSTOP); | |
c6ebcbb6 PM |
1584 | lastphase = barrier_phase; |
1585 | smp_mb(); /* ensure barrier_phase load before ->call(). */ | |
fae4b54f PM |
1586 | if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP) |
1587 | break; | |
1588 | cur_ops->call(&rcu, rcu_torture_barrier_cbf); | |
1589 | if (atomic_dec_and_test(&barrier_cbs_count)) | |
1590 | wake_up(&barrier_wq); | |
1591 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
1592 | VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task stopping"); | |
1593 | rcutorture_shutdown_absorb("rcu_torture_barrier_cbs"); | |
1594 | while (!kthread_should_stop()) | |
1595 | schedule_timeout_interruptible(1); | |
1596 | cur_ops->cb_barrier(); | |
1597 | destroy_rcu_head_on_stack(&rcu); | |
1598 | return 0; | |
1599 | } | |
1600 | ||
1601 | /* kthread function to drive and coordinate RCU barrier testing. */ | |
1602 | static int rcu_torture_barrier(void *arg) | |
1603 | { | |
1604 | int i; | |
1605 | ||
1606 | VERBOSE_PRINTK_STRING("rcu_torture_barrier task starting"); | |
1607 | do { | |
1608 | atomic_set(&barrier_cbs_invoked, 0); | |
1609 | atomic_set(&barrier_cbs_count, n_barrier_cbs); | |
c6ebcbb6 PM |
1610 | smp_mb(); /* Ensure barrier_phase after prior assignments. */ |
1611 | barrier_phase = !barrier_phase; | |
fae4b54f PM |
1612 | for (i = 0; i < n_barrier_cbs; i++) |
1613 | wake_up(&barrier_cbs_wq[i]); | |
1614 | wait_event(barrier_wq, | |
1615 | atomic_read(&barrier_cbs_count) == 0 || | |
1616 | kthread_should_stop() || | |
1617 | fullstop != FULLSTOP_DONTSTOP); | |
1618 | if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP) | |
1619 | break; | |
1620 | n_barrier_attempts++; | |
1621 | cur_ops->cb_barrier(); | |
1622 | if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) { | |
1623 | n_rcu_torture_barrier_error++; | |
1624 | WARN_ON_ONCE(1); | |
1625 | } | |
1626 | n_barrier_successes++; | |
1627 | schedule_timeout_interruptible(HZ / 10); | |
1628 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
1629 | VERBOSE_PRINTK_STRING("rcu_torture_barrier task stopping"); | |
143aa672 | 1630 | rcutorture_shutdown_absorb("rcu_torture_barrier"); |
fae4b54f PM |
1631 | while (!kthread_should_stop()) |
1632 | schedule_timeout_interruptible(1); | |
1633 | return 0; | |
1634 | } | |
1635 | ||
1636 | /* Initialize RCU barrier testing. */ | |
1637 | static int rcu_torture_barrier_init(void) | |
1638 | { | |
1639 | int i; | |
1640 | int ret; | |
1641 | ||
1642 | if (n_barrier_cbs == 0) | |
1643 | return 0; | |
1644 | if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) { | |
2caa1e44 PM |
1645 | pr_alert("%s" TORTURE_FLAG |
1646 | " Call or barrier ops missing for %s,\n", | |
1647 | torture_type, cur_ops->name); | |
1648 | pr_alert("%s" TORTURE_FLAG | |
1649 | " RCU barrier testing omitted from run.\n", | |
1650 | torture_type); | |
fae4b54f PM |
1651 | return 0; |
1652 | } | |
1653 | atomic_set(&barrier_cbs_count, 0); | |
1654 | atomic_set(&barrier_cbs_invoked, 0); | |
1655 | barrier_cbs_tasks = | |
1656 | kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]), | |
1657 | GFP_KERNEL); | |
1658 | barrier_cbs_wq = | |
1659 | kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]), | |
1660 | GFP_KERNEL); | |
de5e6437 | 1661 | if (barrier_cbs_tasks == NULL || !barrier_cbs_wq) |
fae4b54f PM |
1662 | return -ENOMEM; |
1663 | for (i = 0; i < n_barrier_cbs; i++) { | |
1664 | init_waitqueue_head(&barrier_cbs_wq[i]); | |
1665 | barrier_cbs_tasks[i] = kthread_run(rcu_torture_barrier_cbs, | |
9059c940 | 1666 | (void *)(long)i, |
fae4b54f PM |
1667 | "rcu_torture_barrier_cbs"); |
1668 | if (IS_ERR(barrier_cbs_tasks[i])) { | |
1669 | ret = PTR_ERR(barrier_cbs_tasks[i]); | |
1670 | VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier_cbs"); | |
1671 | barrier_cbs_tasks[i] = NULL; | |
1672 | return ret; | |
1673 | } | |
1674 | } | |
1675 | barrier_task = kthread_run(rcu_torture_barrier, NULL, | |
1676 | "rcu_torture_barrier"); | |
1677 | if (IS_ERR(barrier_task)) { | |
1678 | ret = PTR_ERR(barrier_task); | |
1679 | VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier"); | |
1680 | barrier_task = NULL; | |
1681 | } | |
1682 | return 0; | |
1683 | } | |
1684 | ||
1685 | /* Clean up after RCU barrier testing. */ | |
1686 | static void rcu_torture_barrier_cleanup(void) | |
1687 | { | |
1688 | int i; | |
1689 | ||
1690 | if (barrier_task != NULL) { | |
1691 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier task"); | |
1692 | kthread_stop(barrier_task); | |
1693 | barrier_task = NULL; | |
1694 | } | |
1695 | if (barrier_cbs_tasks != NULL) { | |
1696 | for (i = 0; i < n_barrier_cbs; i++) { | |
1697 | if (barrier_cbs_tasks[i] != NULL) { | |
1698 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier_cbs task"); | |
1699 | kthread_stop(barrier_cbs_tasks[i]); | |
1700 | barrier_cbs_tasks[i] = NULL; | |
1701 | } | |
1702 | } | |
1703 | kfree(barrier_cbs_tasks); | |
1704 | barrier_cbs_tasks = NULL; | |
1705 | } | |
1706 | if (barrier_cbs_wq != NULL) { | |
1707 | kfree(barrier_cbs_wq); | |
1708 | barrier_cbs_wq = NULL; | |
1709 | } | |
1710 | } | |
1711 | ||
8e8be45e PM |
1712 | static int rcutorture_cpu_notify(struct notifier_block *self, |
1713 | unsigned long action, void *hcpu) | |
1714 | { | |
1715 | long cpu = (long)hcpu; | |
1716 | ||
1717 | switch (action) { | |
1718 | case CPU_ONLINE: | |
1719 | case CPU_DOWN_FAILED: | |
1720 | (void)rcutorture_booster_init(cpu); | |
1721 | break; | |
1722 | case CPU_DOWN_PREPARE: | |
1723 | rcutorture_booster_cleanup(cpu); | |
1724 | break; | |
1725 | default: | |
1726 | break; | |
1727 | } | |
1728 | return NOTIFY_OK; | |
1729 | } | |
1730 | ||
1731 | static struct notifier_block rcutorture_cpu_nb = { | |
1732 | .notifier_call = rcutorture_cpu_notify, | |
1733 | }; | |
1734 | ||
a241ec65 PM |
1735 | static void |
1736 | rcu_torture_cleanup(void) | |
1737 | { | |
1738 | int i; | |
1739 | ||
343e9099 | 1740 | mutex_lock(&fullstop_mutex); |
4a298656 | 1741 | rcutorture_record_test_transition(); |
c9d557c1 | 1742 | if (fullstop == FULLSTOP_SHUTDOWN) { |
2caa1e44 | 1743 | pr_warn(/* but going down anyway, so... */ |
c9d557c1 | 1744 | "Concurrent 'rmmod rcutorture' and shutdown illegal!\n"); |
343e9099 | 1745 | mutex_unlock(&fullstop_mutex); |
c9d557c1 | 1746 | schedule_timeout_uninterruptible(10); |
343e9099 PM |
1747 | if (cur_ops->cb_barrier != NULL) |
1748 | cur_ops->cb_barrier(); | |
1749 | return; | |
1750 | } | |
c9d557c1 | 1751 | fullstop = FULLSTOP_RMMOD; |
343e9099 | 1752 | mutex_unlock(&fullstop_mutex); |
8e8be45e | 1753 | unregister_reboot_notifier(&rcutorture_shutdown_nb); |
fae4b54f | 1754 | rcu_torture_barrier_cleanup(); |
c13f3757 | 1755 | rcu_torture_stall_cleanup(); |
d120f65f PM |
1756 | if (stutter_task) { |
1757 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task"); | |
1758 | kthread_stop(stutter_task); | |
1759 | } | |
1760 | stutter_task = NULL; | |
c8e5b163 | 1761 | if (shuffler_task) { |
d84f5203 SV |
1762 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task"); |
1763 | kthread_stop(shuffler_task); | |
73d0a4b1 | 1764 | free_cpumask_var(shuffle_tmp_mask); |
d84f5203 SV |
1765 | } |
1766 | shuffler_task = NULL; | |
1767 | ||
c8e5b163 | 1768 | if (writer_task) { |
a241ec65 PM |
1769 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task"); |
1770 | kthread_stop(writer_task); | |
1771 | } | |
1772 | writer_task = NULL; | |
1773 | ||
c8e5b163 | 1774 | if (reader_tasks) { |
a241ec65 | 1775 | for (i = 0; i < nrealreaders; i++) { |
c8e5b163 | 1776 | if (reader_tasks[i]) { |
a241ec65 PM |
1777 | VERBOSE_PRINTK_STRING( |
1778 | "Stopping rcu_torture_reader task"); | |
1779 | kthread_stop(reader_tasks[i]); | |
1780 | } | |
1781 | reader_tasks[i] = NULL; | |
1782 | } | |
1783 | kfree(reader_tasks); | |
1784 | reader_tasks = NULL; | |
1785 | } | |
1786 | rcu_torture_current = NULL; | |
1787 | ||
c8e5b163 | 1788 | if (fakewriter_tasks) { |
b772e1dd | 1789 | for (i = 0; i < nfakewriters; i++) { |
c8e5b163 | 1790 | if (fakewriter_tasks[i]) { |
b772e1dd JT |
1791 | VERBOSE_PRINTK_STRING( |
1792 | "Stopping rcu_torture_fakewriter task"); | |
1793 | kthread_stop(fakewriter_tasks[i]); | |
1794 | } | |
1795 | fakewriter_tasks[i] = NULL; | |
1796 | } | |
1797 | kfree(fakewriter_tasks); | |
1798 | fakewriter_tasks = NULL; | |
1799 | } | |
1800 | ||
c8e5b163 | 1801 | if (stats_task) { |
a241ec65 PM |
1802 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task"); |
1803 | kthread_stop(stats_task); | |
1804 | } | |
1805 | stats_task = NULL; | |
1806 | ||
bf66f18e PM |
1807 | if (fqs_task) { |
1808 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task"); | |
1809 | kthread_stop(fqs_task); | |
1810 | } | |
1811 | fqs_task = NULL; | |
8e8be45e PM |
1812 | if ((test_boost == 1 && cur_ops->can_boost) || |
1813 | test_boost == 2) { | |
1814 | unregister_cpu_notifier(&rcutorture_cpu_nb); | |
1815 | for_each_possible_cpu(i) | |
1816 | rcutorture_booster_cleanup(i); | |
1817 | } | |
d5f546d8 PM |
1818 | if (shutdown_task != NULL) { |
1819 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task"); | |
1820 | kthread_stop(shutdown_task); | |
1821 | } | |
37e377d2 | 1822 | shutdown_task = NULL; |
b58bdcca | 1823 | rcu_torture_onoff_cleanup(); |
bf66f18e | 1824 | |
a241ec65 | 1825 | /* Wait for all RCU callbacks to fire. */ |
2326974d PM |
1826 | |
1827 | if (cur_ops->cb_barrier != NULL) | |
1828 | cur_ops->cb_barrier(); | |
a241ec65 | 1829 | |
a241ec65 | 1830 | rcu_torture_stats_print(); /* -After- the stats thread is stopped! */ |
72e9bb54 | 1831 | |
fae4b54f | 1832 | if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error) |
8e8be45e | 1833 | rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE"); |
091541bb PM |
1834 | else if (n_online_successes != n_online_attempts || |
1835 | n_offline_successes != n_offline_attempts) | |
1836 | rcu_torture_print_module_parms(cur_ops, | |
1837 | "End of test: RCU_HOTPLUG"); | |
95c38322 | 1838 | else |
8e8be45e | 1839 | rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS"); |
a241ec65 PM |
1840 | } |
1841 | ||
d2818df1 PM |
1842 | #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD |
1843 | static void rcu_torture_leak_cb(struct rcu_head *rhp) | |
1844 | { | |
1845 | } | |
1846 | ||
1847 | static void rcu_torture_err_cb(struct rcu_head *rhp) | |
1848 | { | |
1849 | /* | |
1850 | * This -might- happen due to race conditions, but is unlikely. | |
1851 | * The scenario that leads to this happening is that the | |
1852 | * first of the pair of duplicate callbacks is queued, | |
1853 | * someone else starts a grace period that includes that | |
1854 | * callback, then the second of the pair must wait for the | |
1855 | * next grace period. Unlikely, but can happen. If it | |
1856 | * does happen, the debug-objects subsystem won't have splatted. | |
1857 | */ | |
1858 | pr_alert("rcutorture: duplicated callback was invoked.\n"); | |
1859 | } | |
1860 | #endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */ | |
1861 | ||
1862 | /* | |
1863 | * Verify that double-free causes debug-objects to complain, but only | |
1864 | * if CONFIG_DEBUG_OBJECTS_RCU_HEAD=y. Otherwise, say that the test | |
1865 | * cannot be carried out. | |
1866 | */ | |
1867 | static void rcu_test_debug_objects(void) | |
1868 | { | |
1869 | #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD | |
1870 | struct rcu_head rh1; | |
1871 | struct rcu_head rh2; | |
1872 | ||
1873 | init_rcu_head_on_stack(&rh1); | |
1874 | init_rcu_head_on_stack(&rh2); | |
1875 | pr_alert("rcutorture: WARN: Duplicate call_rcu() test starting.\n"); | |
1876 | ||
1877 | /* Try to queue the rh2 pair of callbacks for the same grace period. */ | |
1878 | preempt_disable(); /* Prevent preemption from interrupting test. */ | |
1879 | rcu_read_lock(); /* Make it impossible to finish a grace period. */ | |
1880 | call_rcu(&rh1, rcu_torture_leak_cb); /* Start grace period. */ | |
1881 | local_irq_disable(); /* Make it harder to start a new grace period. */ | |
1882 | call_rcu(&rh2, rcu_torture_leak_cb); | |
1883 | call_rcu(&rh2, rcu_torture_err_cb); /* Duplicate callback. */ | |
1884 | local_irq_enable(); | |
1885 | rcu_read_unlock(); | |
1886 | preempt_enable(); | |
1887 | ||
1888 | /* Wait for them all to get done so we can safely return. */ | |
1889 | rcu_barrier(); | |
1890 | pr_alert("rcutorture: WARN: Duplicate call_rcu() test complete.\n"); | |
1891 | destroy_rcu_head_on_stack(&rh1); | |
1892 | destroy_rcu_head_on_stack(&rh2); | |
1893 | #else /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */ | |
1894 | pr_alert("rcutorture: !CONFIG_DEBUG_OBJECTS_RCU_HEAD, not testing duplicate call_rcu()\n"); | |
1895 | #endif /* #else #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */ | |
1896 | } | |
1897 | ||
6f8bc500 | 1898 | static int __init |
a241ec65 PM |
1899 | rcu_torture_init(void) |
1900 | { | |
1901 | int i; | |
1902 | int cpu; | |
1903 | int firsterr = 0; | |
fae4b54f | 1904 | int retval; |
2ec1f2d9 PM |
1905 | static struct rcu_torture_ops *torture_ops[] = { |
1906 | &rcu_ops, &rcu_bh_ops, &srcu_ops, &sched_ops, | |
1907 | }; | |
a241ec65 | 1908 | |
343e9099 PM |
1909 | mutex_lock(&fullstop_mutex); |
1910 | ||
a241ec65 | 1911 | /* Process args and tell the world that the torturer is on the job. */ |
ade5fb81 | 1912 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) { |
72e9bb54 | 1913 | cur_ops = torture_ops[i]; |
ade5fb81 | 1914 | if (strcmp(torture_type, cur_ops->name) == 0) |
72e9bb54 | 1915 | break; |
72e9bb54 | 1916 | } |
ade5fb81 | 1917 | if (i == ARRAY_SIZE(torture_ops)) { |
2caa1e44 PM |
1918 | pr_alert("rcu-torture: invalid torture type: \"%s\"\n", |
1919 | torture_type); | |
1920 | pr_alert("rcu-torture types:"); | |
cf886c44 | 1921 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) |
2caa1e44 PM |
1922 | pr_alert(" %s", torture_ops[i]->name); |
1923 | pr_alert("\n"); | |
343e9099 | 1924 | mutex_unlock(&fullstop_mutex); |
a71fca58 | 1925 | return -EINVAL; |
72e9bb54 | 1926 | } |
bf66f18e | 1927 | if (cur_ops->fqs == NULL && fqs_duration != 0) { |
2caa1e44 | 1928 | pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n"); |
bf66f18e PM |
1929 | fqs_duration = 0; |
1930 | } | |
c8e5b163 | 1931 | if (cur_ops->init) |
72e9bb54 PM |
1932 | cur_ops->init(); /* no "goto unwind" prior to this point!!! */ |
1933 | ||
a241ec65 PM |
1934 | if (nreaders >= 0) |
1935 | nrealreaders = nreaders; | |
1936 | else | |
1937 | nrealreaders = 2 * num_online_cpus(); | |
8e8be45e | 1938 | rcu_torture_print_module_parms(cur_ops, "Start of test"); |
c9d557c1 | 1939 | fullstop = FULLSTOP_DONTSTOP; |
a241ec65 PM |
1940 | |
1941 | /* Set up the freelist. */ | |
1942 | ||
1943 | INIT_LIST_HEAD(&rcu_torture_freelist); | |
788e770e | 1944 | for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) { |
996417d2 | 1945 | rcu_tortures[i].rtort_mbtest = 0; |
a241ec65 PM |
1946 | list_add_tail(&rcu_tortures[i].rtort_free, |
1947 | &rcu_torture_freelist); | |
1948 | } | |
1949 | ||
1950 | /* Initialize the statistics so that each run gets its own numbers. */ | |
1951 | ||
1952 | rcu_torture_current = NULL; | |
1953 | rcu_torture_current_version = 0; | |
1954 | atomic_set(&n_rcu_torture_alloc, 0); | |
1955 | atomic_set(&n_rcu_torture_alloc_fail, 0); | |
1956 | atomic_set(&n_rcu_torture_free, 0); | |
996417d2 PM |
1957 | atomic_set(&n_rcu_torture_mberror, 0); |
1958 | atomic_set(&n_rcu_torture_error, 0); | |
fae4b54f | 1959 | n_rcu_torture_barrier_error = 0; |
8e8be45e PM |
1960 | n_rcu_torture_boost_ktrerror = 0; |
1961 | n_rcu_torture_boost_rterror = 0; | |
8e8be45e PM |
1962 | n_rcu_torture_boost_failure = 0; |
1963 | n_rcu_torture_boosts = 0; | |
a241ec65 PM |
1964 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
1965 | atomic_set(&rcu_torture_wcount[i], 0); | |
0a945022 | 1966 | for_each_possible_cpu(cpu) { |
a241ec65 PM |
1967 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
1968 | per_cpu(rcu_torture_count, cpu)[i] = 0; | |
1969 | per_cpu(rcu_torture_batch, cpu)[i] = 0; | |
1970 | } | |
1971 | } | |
1972 | ||
1973 | /* Start up the kthreads. */ | |
1974 | ||
1975 | VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task"); | |
60f53782 PM |
1976 | writer_task = kthread_create(rcu_torture_writer, NULL, |
1977 | "rcu_torture_writer"); | |
a241ec65 PM |
1978 | if (IS_ERR(writer_task)) { |
1979 | firsterr = PTR_ERR(writer_task); | |
1980 | VERBOSE_PRINTK_ERRSTRING("Failed to create writer"); | |
1981 | writer_task = NULL; | |
1982 | goto unwind; | |
1983 | } | |
60f53782 | 1984 | wake_up_process(writer_task); |
b772e1dd | 1985 | fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]), |
a71fca58 | 1986 | GFP_KERNEL); |
b772e1dd JT |
1987 | if (fakewriter_tasks == NULL) { |
1988 | VERBOSE_PRINTK_ERRSTRING("out of memory"); | |
1989 | firsterr = -ENOMEM; | |
1990 | goto unwind; | |
1991 | } | |
1992 | for (i = 0; i < nfakewriters; i++) { | |
1993 | VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task"); | |
1994 | fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL, | |
a71fca58 | 1995 | "rcu_torture_fakewriter"); |
b772e1dd JT |
1996 | if (IS_ERR(fakewriter_tasks[i])) { |
1997 | firsterr = PTR_ERR(fakewriter_tasks[i]); | |
1998 | VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter"); | |
1999 | fakewriter_tasks[i] = NULL; | |
2000 | goto unwind; | |
2001 | } | |
2002 | } | |
2860aaba | 2003 | reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]), |
a241ec65 PM |
2004 | GFP_KERNEL); |
2005 | if (reader_tasks == NULL) { | |
2006 | VERBOSE_PRINTK_ERRSTRING("out of memory"); | |
2007 | firsterr = -ENOMEM; | |
2008 | goto unwind; | |
2009 | } | |
2010 | for (i = 0; i < nrealreaders; i++) { | |
2011 | VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task"); | |
2012 | reader_tasks[i] = kthread_run(rcu_torture_reader, NULL, | |
2013 | "rcu_torture_reader"); | |
2014 | if (IS_ERR(reader_tasks[i])) { | |
2015 | firsterr = PTR_ERR(reader_tasks[i]); | |
2016 | VERBOSE_PRINTK_ERRSTRING("Failed to create reader"); | |
2017 | reader_tasks[i] = NULL; | |
2018 | goto unwind; | |
2019 | } | |
2020 | } | |
2021 | if (stat_interval > 0) { | |
2022 | VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task"); | |
2023 | stats_task = kthread_run(rcu_torture_stats, NULL, | |
2024 | "rcu_torture_stats"); | |
2025 | if (IS_ERR(stats_task)) { | |
2026 | firsterr = PTR_ERR(stats_task); | |
2027 | VERBOSE_PRINTK_ERRSTRING("Failed to create stats"); | |
2028 | stats_task = NULL; | |
2029 | goto unwind; | |
2030 | } | |
2031 | } | |
d84f5203 SV |
2032 | if (test_no_idle_hz) { |
2033 | rcu_idle_cpu = num_online_cpus() - 1; | |
73d0a4b1 RR |
2034 | |
2035 | if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) { | |
2036 | firsterr = -ENOMEM; | |
2037 | VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask"); | |
2038 | goto unwind; | |
2039 | } | |
2040 | ||
d84f5203 SV |
2041 | /* Create the shuffler thread */ |
2042 | shuffler_task = kthread_run(rcu_torture_shuffle, NULL, | |
2043 | "rcu_torture_shuffle"); | |
2044 | if (IS_ERR(shuffler_task)) { | |
73d0a4b1 | 2045 | free_cpumask_var(shuffle_tmp_mask); |
d84f5203 SV |
2046 | firsterr = PTR_ERR(shuffler_task); |
2047 | VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler"); | |
2048 | shuffler_task = NULL; | |
2049 | goto unwind; | |
2050 | } | |
2051 | } | |
d120f65f PM |
2052 | if (stutter < 0) |
2053 | stutter = 0; | |
2054 | if (stutter) { | |
2055 | /* Create the stutter thread */ | |
2056 | stutter_task = kthread_run(rcu_torture_stutter, NULL, | |
2057 | "rcu_torture_stutter"); | |
2058 | if (IS_ERR(stutter_task)) { | |
2059 | firsterr = PTR_ERR(stutter_task); | |
2060 | VERBOSE_PRINTK_ERRSTRING("Failed to create stutter"); | |
2061 | stutter_task = NULL; | |
2062 | goto unwind; | |
2063 | } | |
2064 | } | |
bf66f18e PM |
2065 | if (fqs_duration < 0) |
2066 | fqs_duration = 0; | |
2067 | if (fqs_duration) { | |
2068 | /* Create the stutter thread */ | |
2069 | fqs_task = kthread_run(rcu_torture_fqs, NULL, | |
2070 | "rcu_torture_fqs"); | |
2071 | if (IS_ERR(fqs_task)) { | |
2072 | firsterr = PTR_ERR(fqs_task); | |
2073 | VERBOSE_PRINTK_ERRSTRING("Failed to create fqs"); | |
2074 | fqs_task = NULL; | |
2075 | goto unwind; | |
2076 | } | |
2077 | } | |
8e8be45e PM |
2078 | if (test_boost_interval < 1) |
2079 | test_boost_interval = 1; | |
2080 | if (test_boost_duration < 2) | |
2081 | test_boost_duration = 2; | |
2082 | if ((test_boost == 1 && cur_ops->can_boost) || | |
2083 | test_boost == 2) { | |
8e8be45e PM |
2084 | |
2085 | boost_starttime = jiffies + test_boost_interval * HZ; | |
2086 | register_cpu_notifier(&rcutorture_cpu_nb); | |
2087 | for_each_possible_cpu(i) { | |
2088 | if (cpu_is_offline(i)) | |
2089 | continue; /* Heuristic: CPU can go offline. */ | |
2090 | retval = rcutorture_booster_init(i); | |
2091 | if (retval < 0) { | |
2092 | firsterr = retval; | |
2093 | goto unwind; | |
2094 | } | |
2095 | } | |
2096 | } | |
d5f546d8 PM |
2097 | if (shutdown_secs > 0) { |
2098 | shutdown_time = jiffies + shutdown_secs * HZ; | |
60f53782 PM |
2099 | shutdown_task = kthread_create(rcu_torture_shutdown, NULL, |
2100 | "rcu_torture_shutdown"); | |
d5f546d8 PM |
2101 | if (IS_ERR(shutdown_task)) { |
2102 | firsterr = PTR_ERR(shutdown_task); | |
2103 | VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown"); | |
2104 | shutdown_task = NULL; | |
2105 | goto unwind; | |
2106 | } | |
60f53782 | 2107 | wake_up_process(shutdown_task); |
d5f546d8 | 2108 | } |
37e377d2 PM |
2109 | i = rcu_torture_onoff_init(); |
2110 | if (i != 0) { | |
2111 | firsterr = i; | |
2112 | goto unwind; | |
2113 | } | |
8e8be45e | 2114 | register_reboot_notifier(&rcutorture_shutdown_nb); |
37e377d2 PM |
2115 | i = rcu_torture_stall_init(); |
2116 | if (i != 0) { | |
2117 | firsterr = i; | |
2118 | goto unwind; | |
2119 | } | |
fae4b54f PM |
2120 | retval = rcu_torture_barrier_init(); |
2121 | if (retval != 0) { | |
2122 | firsterr = retval; | |
2123 | goto unwind; | |
2124 | } | |
d2818df1 PM |
2125 | if (object_debug) |
2126 | rcu_test_debug_objects(); | |
4a298656 | 2127 | rcutorture_record_test_transition(); |
343e9099 | 2128 | mutex_unlock(&fullstop_mutex); |
a241ec65 PM |
2129 | return 0; |
2130 | ||
2131 | unwind: | |
343e9099 | 2132 | mutex_unlock(&fullstop_mutex); |
a241ec65 PM |
2133 | rcu_torture_cleanup(); |
2134 | return firsterr; | |
2135 | } | |
2136 | ||
2137 | module_init(rcu_torture_init); | |
2138 | module_exit(rcu_torture_cleanup); |