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 | |
87de1cfd PM |
15 | * along with this program; if not, you can access it online at |
16 | * http://www.gnu.org/licenses/gpl-2.0.html. | |
a241ec65 | 17 | * |
b772e1dd | 18 | * Copyright (C) IBM Corporation, 2005, 2006 |
a241ec65 PM |
19 | * |
20 | * Authors: Paul E. McKenney <paulmck@us.ibm.com> | |
e0198b29 | 21 | * Josh Triplett <josh@joshtriplett.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> |
51b1130e | 51 | #include <linux/torture.h> |
a241ec65 PM |
52 | |
53 | MODULE_LICENSE("GPL"); | |
e0198b29 | 54 | MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@joshtriplett.org>"); |
a241ec65 | 55 | |
4102adab | 56 | |
9e250225 PM |
57 | torture_param(int, fqs_duration, 0, |
58 | "Duration of fqs bursts (us), 0 to disable"); | |
59 | torture_param(int, fqs_holdoff, 0, "Holdoff time within fqs bursts (us)"); | |
60 | torture_param(int, fqs_stutter, 3, "Wait time between fqs bursts (s)"); | |
a48f3fad | 61 | torture_param(bool, gp_cond, false, "Use conditional/async GP wait primitives"); |
9e250225 PM |
62 | torture_param(bool, gp_exp, false, "Use expedited GP wait primitives"); |
63 | torture_param(bool, gp_normal, false, | |
64 | "Use normal (non-expedited) GP wait primitives"); | |
f0bf8fab | 65 | torture_param(bool, gp_sync, false, "Use synchronous GP wait primitives"); |
9e250225 PM |
66 | torture_param(int, irqreader, 1, "Allow RCU readers from irq handlers"); |
67 | torture_param(int, n_barrier_cbs, 0, | |
68 | "# of callbacks/kthreads for barrier testing"); | |
69 | torture_param(int, nfakewriters, 4, "Number of RCU fake writer threads"); | |
70 | torture_param(int, nreaders, -1, "Number of RCU reader threads"); | |
71 | torture_param(int, object_debug, 0, | |
72 | "Enable debug-object double call_rcu() testing"); | |
73 | torture_param(int, onoff_holdoff, 0, "Time after boot before CPU hotplugs (s)"); | |
74 | torture_param(int, onoff_interval, 0, | |
75 | "Time between CPU hotplugs (s), 0=disable"); | |
76 | torture_param(int, shuffle_interval, 3, "Number of seconds between shuffles"); | |
77 | torture_param(int, shutdown_secs, 0, "Shutdown time (s), <= zero to disable."); | |
78 | torture_param(int, stall_cpu, 0, "Stall duration (s), zero to disable."); | |
79 | torture_param(int, stall_cpu_holdoff, 10, | |
80 | "Time to wait before starting stall (s)."); | |
81 | torture_param(int, stat_interval, 60, | |
82 | "Number of seconds between stats printk()s"); | |
83 | torture_param(int, stutter, 5, "Number of seconds to run/halt test"); | |
84 | torture_param(int, test_boost, 1, "Test RCU prio boost: 0=no, 1=maybe, 2=yes."); | |
85 | torture_param(int, test_boost_duration, 4, | |
86 | "Duration of each boost test, seconds."); | |
87 | torture_param(int, test_boost_interval, 7, | |
88 | "Interval between boost tests, seconds."); | |
89 | torture_param(bool, test_no_idle_hz, true, | |
90 | "Test support for tickless idle CPUs"); | |
b5daa8f3 PM |
91 | torture_param(bool, verbose, true, |
92 | "Enable verbose debugging printk()s"); | |
9e250225 | 93 | |
d10453e9 | 94 | static char *torture_type = "rcu"; |
d6ad6711 | 95 | module_param(torture_type, charp, 0444); |
d10453e9 | 96 | MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)"); |
a241ec65 | 97 | |
a241ec65 PM |
98 | static int nrealreaders; |
99 | static struct task_struct *writer_task; | |
b772e1dd | 100 | static struct task_struct **fakewriter_tasks; |
a241ec65 PM |
101 | static struct task_struct **reader_tasks; |
102 | static struct task_struct *stats_task; | |
bf66f18e | 103 | static struct task_struct *fqs_task; |
8e8be45e | 104 | static struct task_struct *boost_tasks[NR_CPUS]; |
c13f3757 | 105 | static struct task_struct *stall_task; |
fae4b54f PM |
106 | static struct task_struct **barrier_cbs_tasks; |
107 | static struct task_struct *barrier_task; | |
a241ec65 PM |
108 | |
109 | #define RCU_TORTURE_PIPE_LEN 10 | |
110 | ||
111 | struct rcu_torture { | |
112 | struct rcu_head rtort_rcu; | |
113 | int rtort_pipe_count; | |
114 | struct list_head rtort_free; | |
996417d2 | 115 | int rtort_mbtest; |
a241ec65 PM |
116 | }; |
117 | ||
a241ec65 | 118 | static LIST_HEAD(rcu_torture_freelist); |
0ddea0ea | 119 | static struct rcu_torture __rcu *rcu_torture_current; |
4a298656 | 120 | static unsigned long rcu_torture_current_version; |
a241ec65 PM |
121 | static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN]; |
122 | static DEFINE_SPINLOCK(rcu_torture_lock); | |
806274c0 PM |
123 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], |
124 | rcu_torture_count) = { 0 }; | |
125 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], | |
126 | rcu_torture_batch) = { 0 }; | |
a241ec65 | 127 | static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1]; |
b2896d2e PM |
128 | static atomic_t n_rcu_torture_alloc; |
129 | static atomic_t n_rcu_torture_alloc_fail; | |
130 | static atomic_t n_rcu_torture_free; | |
131 | static atomic_t n_rcu_torture_mberror; | |
132 | static atomic_t n_rcu_torture_error; | |
fae4b54f | 133 | static long n_rcu_torture_barrier_error; |
8e8be45e PM |
134 | static long n_rcu_torture_boost_ktrerror; |
135 | static long n_rcu_torture_boost_rterror; | |
8e8be45e PM |
136 | static long n_rcu_torture_boost_failure; |
137 | static long n_rcu_torture_boosts; | |
a71fca58 | 138 | static long n_rcu_torture_timers; |
fae4b54f PM |
139 | static long n_barrier_attempts; |
140 | static long n_barrier_successes; | |
e3033736 | 141 | static struct list_head rcu_torture_removed; |
d120f65f | 142 | |
ad0dc7f9 PM |
143 | static int rcu_torture_writer_state; |
144 | #define RTWS_FIXED_DELAY 0 | |
145 | #define RTWS_DELAY 1 | |
146 | #define RTWS_REPLACE 2 | |
147 | #define RTWS_DEF_FREE 3 | |
148 | #define RTWS_EXP_SYNC 4 | |
a48f3fad PM |
149 | #define RTWS_COND_GET 5 |
150 | #define RTWS_COND_SYNC 6 | |
f0bf8fab PM |
151 | #define RTWS_SYNC 7 |
152 | #define RTWS_STUTTER 8 | |
153 | #define RTWS_STOPPING 9 | |
ad0dc7f9 | 154 | |
31a72bce PM |
155 | #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE) |
156 | #define RCUTORTURE_RUNNABLE_INIT 1 | |
157 | #else | |
158 | #define RCUTORTURE_RUNNABLE_INIT 0 | |
159 | #endif | |
160 | int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT; | |
bb3bf705 PM |
161 | module_param(rcutorture_runnable, int, 0444); |
162 | MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot"); | |
31a72bce | 163 | |
3acf4a9a | 164 | #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) |
8e8be45e | 165 | #define rcu_can_boost() 1 |
3acf4a9a | 166 | #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */ |
8e8be45e | 167 | #define rcu_can_boost() 0 |
3acf4a9a | 168 | #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */ |
8e8be45e | 169 | |
e4aa0da3 SR |
170 | #ifdef CONFIG_RCU_TRACE |
171 | static u64 notrace rcu_trace_clock_local(void) | |
172 | { | |
173 | u64 ts = trace_clock_local(); | |
174 | unsigned long __maybe_unused ts_rem = do_div(ts, NSEC_PER_USEC); | |
175 | return ts; | |
176 | } | |
177 | #else /* #ifdef CONFIG_RCU_TRACE */ | |
178 | static u64 notrace rcu_trace_clock_local(void) | |
179 | { | |
180 | return 0ULL; | |
181 | } | |
182 | #endif /* #else #ifdef CONFIG_RCU_TRACE */ | |
183 | ||
8e8be45e | 184 | static unsigned long boost_starttime; /* jiffies of next boost test start. */ |
58ade2db | 185 | static DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */ |
8e8be45e | 186 | /* and boost task create/destroy. */ |
fae4b54f | 187 | static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */ |
c6ebcbb6 | 188 | static bool barrier_phase; /* Test phase. */ |
fae4b54f PM |
189 | static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */ |
190 | static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */ | |
191 | static DECLARE_WAIT_QUEUE_HEAD(barrier_wq); | |
8e8be45e | 192 | |
a241ec65 PM |
193 | /* |
194 | * Allocate an element from the rcu_tortures pool. | |
195 | */ | |
97a41e26 | 196 | static struct rcu_torture * |
a241ec65 PM |
197 | rcu_torture_alloc(void) |
198 | { | |
199 | struct list_head *p; | |
200 | ||
adac1665 | 201 | spin_lock_bh(&rcu_torture_lock); |
a241ec65 PM |
202 | if (list_empty(&rcu_torture_freelist)) { |
203 | atomic_inc(&n_rcu_torture_alloc_fail); | |
adac1665 | 204 | spin_unlock_bh(&rcu_torture_lock); |
a241ec65 PM |
205 | return NULL; |
206 | } | |
207 | atomic_inc(&n_rcu_torture_alloc); | |
208 | p = rcu_torture_freelist.next; | |
209 | list_del_init(p); | |
adac1665 | 210 | spin_unlock_bh(&rcu_torture_lock); |
a241ec65 PM |
211 | return container_of(p, struct rcu_torture, rtort_free); |
212 | } | |
213 | ||
214 | /* | |
215 | * Free an element to the rcu_tortures pool. | |
216 | */ | |
217 | static void | |
218 | rcu_torture_free(struct rcu_torture *p) | |
219 | { | |
220 | atomic_inc(&n_rcu_torture_free); | |
adac1665 | 221 | spin_lock_bh(&rcu_torture_lock); |
a241ec65 | 222 | list_add_tail(&p->rtort_free, &rcu_torture_freelist); |
adac1665 | 223 | spin_unlock_bh(&rcu_torture_lock); |
a241ec65 PM |
224 | } |
225 | ||
72e9bb54 PM |
226 | /* |
227 | * Operations vector for selecting different types of tests. | |
228 | */ | |
229 | ||
230 | struct rcu_torture_ops { | |
ad0dc7f9 | 231 | int ttype; |
72e9bb54 | 232 | void (*init)(void); |
72e9bb54 | 233 | int (*readlock)(void); |
51b1130e | 234 | void (*read_delay)(struct torture_random_state *rrsp); |
72e9bb54 PM |
235 | void (*readunlock)(int idx); |
236 | int (*completed)(void); | |
0acc512c | 237 | void (*deferred_free)(struct rcu_torture *p); |
b772e1dd | 238 | void (*sync)(void); |
2ec1f2d9 | 239 | void (*exp_sync)(void); |
a48f3fad PM |
240 | unsigned long (*get_state)(void); |
241 | void (*cond_sync)(unsigned long oldstate); | |
fae4b54f | 242 | void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu)); |
2326974d | 243 | void (*cb_barrier)(void); |
bf66f18e | 244 | void (*fqs)(void); |
eea203fe | 245 | void (*stats)(void); |
0acc512c | 246 | int irq_capable; |
8e8be45e | 247 | int can_boost; |
e66c33d5 | 248 | const char *name; |
72e9bb54 | 249 | }; |
a71fca58 PM |
250 | |
251 | static struct rcu_torture_ops *cur_ops; | |
72e9bb54 PM |
252 | |
253 | /* | |
254 | * Definitions for rcu torture testing. | |
255 | */ | |
256 | ||
a49a4af7 | 257 | static int rcu_torture_read_lock(void) __acquires(RCU) |
72e9bb54 PM |
258 | { |
259 | rcu_read_lock(); | |
260 | return 0; | |
261 | } | |
262 | ||
51b1130e | 263 | static void rcu_read_delay(struct torture_random_state *rrsp) |
b2896d2e | 264 | { |
b8d57a76 JT |
265 | const unsigned long shortdelay_us = 200; |
266 | const unsigned long longdelay_ms = 50; | |
b2896d2e | 267 | |
b8d57a76 JT |
268 | /* We want a short delay sometimes to make a reader delay the grace |
269 | * period, and we want a long delay occasionally to trigger | |
270 | * force_quiescent_state. */ | |
b2896d2e | 271 | |
51b1130e | 272 | if (!(torture_random(rrsp) % (nrealreaders * 2000 * longdelay_ms))) |
b8d57a76 | 273 | mdelay(longdelay_ms); |
51b1130e | 274 | if (!(torture_random(rrsp) % (nrealreaders * 2 * shortdelay_us))) |
b8d57a76 | 275 | udelay(shortdelay_us); |
e546f485 | 276 | #ifdef CONFIG_PREEMPT |
51b1130e PM |
277 | if (!preempt_count() && |
278 | !(torture_random(rrsp) % (nrealreaders * 20000))) | |
e546f485 LJ |
279 | preempt_schedule(); /* No QS if preempt_disable() in effect */ |
280 | #endif | |
b2896d2e PM |
281 | } |
282 | ||
a49a4af7 | 283 | static void rcu_torture_read_unlock(int idx) __releases(RCU) |
72e9bb54 PM |
284 | { |
285 | rcu_read_unlock(); | |
286 | } | |
287 | ||
288 | static int rcu_torture_completed(void) | |
289 | { | |
290 | return rcu_batches_completed(); | |
291 | } | |
292 | ||
a48f3fad PM |
293 | /* |
294 | * Update callback in the pipe. This should be invoked after a grace period. | |
295 | */ | |
296 | static bool | |
297 | rcu_torture_pipe_update_one(struct rcu_torture *rp) | |
298 | { | |
299 | int i; | |
300 | ||
301 | i = rp->rtort_pipe_count; | |
302 | if (i > RCU_TORTURE_PIPE_LEN) | |
303 | i = RCU_TORTURE_PIPE_LEN; | |
304 | atomic_inc(&rcu_torture_wcount[i]); | |
305 | if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) { | |
306 | rp->rtort_mbtest = 0; | |
307 | return true; | |
308 | } | |
309 | return false; | |
310 | } | |
311 | ||
312 | /* | |
313 | * Update all callbacks in the pipe. Suitable for synchronous grace-period | |
314 | * primitives. | |
315 | */ | |
316 | static void | |
317 | rcu_torture_pipe_update(struct rcu_torture *old_rp) | |
318 | { | |
319 | struct rcu_torture *rp; | |
320 | struct rcu_torture *rp1; | |
321 | ||
322 | if (old_rp) | |
323 | list_add(&old_rp->rtort_free, &rcu_torture_removed); | |
324 | list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) { | |
325 | if (rcu_torture_pipe_update_one(rp)) { | |
326 | list_del(&rp->rtort_free); | |
327 | rcu_torture_free(rp); | |
328 | } | |
329 | } | |
330 | } | |
331 | ||
72e9bb54 PM |
332 | static void |
333 | rcu_torture_cb(struct rcu_head *p) | |
334 | { | |
72e9bb54 PM |
335 | struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu); |
336 | ||
36970bb9 | 337 | if (torture_must_stop_irq()) { |
72e9bb54 PM |
338 | /* Test is ending, just drop callbacks on the floor. */ |
339 | /* The next initialization will pick up the pieces. */ | |
340 | return; | |
341 | } | |
a48f3fad | 342 | if (rcu_torture_pipe_update_one(rp)) |
72e9bb54 | 343 | rcu_torture_free(rp); |
a48f3fad | 344 | else |
0acc512c | 345 | cur_ops->deferred_free(rp); |
72e9bb54 PM |
346 | } |
347 | ||
d9a3da06 PM |
348 | static int rcu_no_completed(void) |
349 | { | |
350 | return 0; | |
351 | } | |
352 | ||
72e9bb54 PM |
353 | static void rcu_torture_deferred_free(struct rcu_torture *p) |
354 | { | |
355 | call_rcu(&p->rtort_rcu, rcu_torture_cb); | |
356 | } | |
357 | ||
e3033736 JT |
358 | static void rcu_sync_torture_init(void) |
359 | { | |
360 | INIT_LIST_HEAD(&rcu_torture_removed); | |
361 | } | |
362 | ||
2ec1f2d9 | 363 | static struct rcu_torture_ops rcu_ops = { |
ad0dc7f9 | 364 | .ttype = RCU_FLAVOR, |
0acc512c | 365 | .init = rcu_sync_torture_init, |
0acc512c PM |
366 | .readlock = rcu_torture_read_lock, |
367 | .read_delay = rcu_read_delay, | |
368 | .readunlock = rcu_torture_read_unlock, | |
369 | .completed = rcu_torture_completed, | |
2ec1f2d9 | 370 | .deferred_free = rcu_torture_deferred_free, |
0acc512c | 371 | .sync = synchronize_rcu, |
2ec1f2d9 | 372 | .exp_sync = synchronize_rcu_expedited, |
a48f3fad PM |
373 | .get_state = get_state_synchronize_rcu, |
374 | .cond_sync = cond_synchronize_rcu, | |
2ec1f2d9 PM |
375 | .call = call_rcu, |
376 | .cb_barrier = rcu_barrier, | |
bf66f18e | 377 | .fqs = rcu_force_quiescent_state, |
d9a3da06 PM |
378 | .stats = NULL, |
379 | .irq_capable = 1, | |
8e8be45e | 380 | .can_boost = rcu_can_boost(), |
2ec1f2d9 | 381 | .name = "rcu" |
d9a3da06 PM |
382 | }; |
383 | ||
c32e0660 PM |
384 | /* |
385 | * Definitions for rcu_bh torture testing. | |
386 | */ | |
387 | ||
a49a4af7 | 388 | static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH) |
c32e0660 PM |
389 | { |
390 | rcu_read_lock_bh(); | |
391 | return 0; | |
392 | } | |
393 | ||
a49a4af7 | 394 | static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH) |
c32e0660 PM |
395 | { |
396 | rcu_read_unlock_bh(); | |
397 | } | |
398 | ||
399 | static int rcu_bh_torture_completed(void) | |
400 | { | |
401 | return rcu_batches_completed_bh(); | |
402 | } | |
403 | ||
404 | static void rcu_bh_torture_deferred_free(struct rcu_torture *p) | |
405 | { | |
406 | call_rcu_bh(&p->rtort_rcu, rcu_torture_cb); | |
407 | } | |
408 | ||
409 | static struct rcu_torture_ops rcu_bh_ops = { | |
ad0dc7f9 | 410 | .ttype = RCU_BH_FLAVOR, |
2ec1f2d9 | 411 | .init = rcu_sync_torture_init, |
0acc512c PM |
412 | .readlock = rcu_bh_torture_read_lock, |
413 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
414 | .readunlock = rcu_bh_torture_read_unlock, | |
415 | .completed = rcu_bh_torture_completed, | |
416 | .deferred_free = rcu_bh_torture_deferred_free, | |
bdf2a436 | 417 | .sync = synchronize_rcu_bh, |
2ec1f2d9 | 418 | .exp_sync = synchronize_rcu_bh_expedited, |
fae4b54f | 419 | .call = call_rcu_bh, |
0acc512c | 420 | .cb_barrier = rcu_barrier_bh, |
bf66f18e | 421 | .fqs = rcu_bh_force_quiescent_state, |
0acc512c PM |
422 | .stats = NULL, |
423 | .irq_capable = 1, | |
424 | .name = "rcu_bh" | |
c32e0660 PM |
425 | }; |
426 | ||
ff20e251 PM |
427 | /* |
428 | * Don't even think about trying any of these in real life!!! | |
429 | * The names includes "busted", and they really means it! | |
430 | * The only purpose of these functions is to provide a buggy RCU | |
431 | * implementation to make sure that rcutorture correctly emits | |
432 | * buggy-RCU error messages. | |
433 | */ | |
434 | static void rcu_busted_torture_deferred_free(struct rcu_torture *p) | |
435 | { | |
436 | /* This is a deliberate bug for testing purposes only! */ | |
437 | rcu_torture_cb(&p->rtort_rcu); | |
438 | } | |
439 | ||
440 | static void synchronize_rcu_busted(void) | |
441 | { | |
442 | /* This is a deliberate bug for testing purposes only! */ | |
443 | } | |
444 | ||
445 | static void | |
446 | call_rcu_busted(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) | |
447 | { | |
448 | /* This is a deliberate bug for testing purposes only! */ | |
449 | func(head); | |
450 | } | |
451 | ||
452 | static struct rcu_torture_ops rcu_busted_ops = { | |
ad0dc7f9 | 453 | .ttype = INVALID_RCU_FLAVOR, |
ff20e251 PM |
454 | .init = rcu_sync_torture_init, |
455 | .readlock = rcu_torture_read_lock, | |
456 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
457 | .readunlock = rcu_torture_read_unlock, | |
458 | .completed = rcu_no_completed, | |
459 | .deferred_free = rcu_busted_torture_deferred_free, | |
460 | .sync = synchronize_rcu_busted, | |
461 | .exp_sync = synchronize_rcu_busted, | |
462 | .call = call_rcu_busted, | |
463 | .cb_barrier = NULL, | |
464 | .fqs = NULL, | |
465 | .stats = NULL, | |
466 | .irq_capable = 1, | |
467 | .name = "rcu_busted" | |
468 | }; | |
469 | ||
b2896d2e PM |
470 | /* |
471 | * Definitions for srcu torture testing. | |
472 | */ | |
473 | ||
cda4dc81 | 474 | DEFINE_STATIC_SRCU(srcu_ctl); |
b2896d2e | 475 | |
012d3ca8 | 476 | static int srcu_torture_read_lock(void) __acquires(&srcu_ctl) |
b2896d2e PM |
477 | { |
478 | return srcu_read_lock(&srcu_ctl); | |
479 | } | |
480 | ||
51b1130e | 481 | static void srcu_read_delay(struct torture_random_state *rrsp) |
b2896d2e PM |
482 | { |
483 | long delay; | |
484 | const long uspertick = 1000000 / HZ; | |
485 | const long longdelay = 10; | |
486 | ||
487 | /* We want there to be long-running readers, but not all the time. */ | |
488 | ||
51b1130e PM |
489 | delay = torture_random(rrsp) % |
490 | (nrealreaders * 2 * longdelay * uspertick); | |
b2896d2e PM |
491 | if (!delay) |
492 | schedule_timeout_interruptible(longdelay); | |
e546f485 LJ |
493 | else |
494 | rcu_read_delay(rrsp); | |
b2896d2e PM |
495 | } |
496 | ||
012d3ca8 | 497 | static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl) |
b2896d2e PM |
498 | { |
499 | srcu_read_unlock(&srcu_ctl, idx); | |
500 | } | |
501 | ||
502 | static int srcu_torture_completed(void) | |
503 | { | |
504 | return srcu_batches_completed(&srcu_ctl); | |
505 | } | |
506 | ||
9059c940 LJ |
507 | static void srcu_torture_deferred_free(struct rcu_torture *rp) |
508 | { | |
509 | call_srcu(&srcu_ctl, &rp->rtort_rcu, rcu_torture_cb); | |
510 | } | |
511 | ||
b772e1dd JT |
512 | static void srcu_torture_synchronize(void) |
513 | { | |
514 | synchronize_srcu(&srcu_ctl); | |
515 | } | |
516 | ||
e3f8d378 PM |
517 | static void srcu_torture_call(struct rcu_head *head, |
518 | void (*func)(struct rcu_head *head)) | |
519 | { | |
520 | call_srcu(&srcu_ctl, head, func); | |
521 | } | |
522 | ||
523 | static void srcu_torture_barrier(void) | |
524 | { | |
525 | srcu_barrier(&srcu_ctl); | |
526 | } | |
527 | ||
eea203fe | 528 | static void srcu_torture_stats(void) |
b2896d2e | 529 | { |
b2896d2e PM |
530 | int cpu; |
531 | int idx = srcu_ctl.completed & 0x1; | |
532 | ||
eea203fe JP |
533 | pr_alert("%s%s per-CPU(idx=%d):", |
534 | torture_type, TORTURE_FLAG, idx); | |
b2896d2e | 535 | for_each_possible_cpu(cpu) { |
589a8f59 PM |
536 | long c0, c1; |
537 | ||
538 | c0 = (long)per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx]; | |
539 | c1 = (long)per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]; | |
eea203fe | 540 | pr_cont(" %d(%ld,%ld)", cpu, c0, c1); |
b2896d2e | 541 | } |
eea203fe | 542 | pr_cont("\n"); |
b2896d2e PM |
543 | } |
544 | ||
2ec1f2d9 PM |
545 | static void srcu_torture_synchronize_expedited(void) |
546 | { | |
547 | synchronize_srcu_expedited(&srcu_ctl); | |
548 | } | |
549 | ||
b2896d2e | 550 | static struct rcu_torture_ops srcu_ops = { |
ad0dc7f9 | 551 | .ttype = SRCU_FLAVOR, |
cda4dc81 | 552 | .init = rcu_sync_torture_init, |
0acc512c PM |
553 | .readlock = srcu_torture_read_lock, |
554 | .read_delay = srcu_read_delay, | |
555 | .readunlock = srcu_torture_read_unlock, | |
556 | .completed = srcu_torture_completed, | |
9059c940 | 557 | .deferred_free = srcu_torture_deferred_free, |
0acc512c | 558 | .sync = srcu_torture_synchronize, |
2ec1f2d9 | 559 | .exp_sync = srcu_torture_synchronize_expedited, |
e3f8d378 PM |
560 | .call = srcu_torture_call, |
561 | .cb_barrier = srcu_torture_barrier, | |
0acc512c PM |
562 | .stats = srcu_torture_stats, |
563 | .name = "srcu" | |
b2896d2e PM |
564 | }; |
565 | ||
4b6c2cca JT |
566 | /* |
567 | * Definitions for sched torture testing. | |
568 | */ | |
569 | ||
570 | static int sched_torture_read_lock(void) | |
571 | { | |
572 | preempt_disable(); | |
573 | return 0; | |
574 | } | |
575 | ||
576 | static void sched_torture_read_unlock(int idx) | |
577 | { | |
578 | preempt_enable(); | |
579 | } | |
580 | ||
2326974d PM |
581 | static void rcu_sched_torture_deferred_free(struct rcu_torture *p) |
582 | { | |
583 | call_rcu_sched(&p->rtort_rcu, rcu_torture_cb); | |
584 | } | |
585 | ||
4b6c2cca | 586 | static struct rcu_torture_ops sched_ops = { |
ad0dc7f9 | 587 | .ttype = RCU_SCHED_FLAVOR, |
0acc512c | 588 | .init = rcu_sync_torture_init, |
0acc512c PM |
589 | .readlock = sched_torture_read_lock, |
590 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
591 | .readunlock = sched_torture_read_unlock, | |
d9a3da06 | 592 | .completed = rcu_no_completed, |
0acc512c | 593 | .deferred_free = rcu_sched_torture_deferred_free, |
bdf2a436 | 594 | .sync = synchronize_sched, |
2ec1f2d9 PM |
595 | .exp_sync = synchronize_sched_expedited, |
596 | .call = call_rcu_sched, | |
0acc512c | 597 | .cb_barrier = rcu_barrier_sched, |
bf66f18e | 598 | .fqs = rcu_sched_force_quiescent_state, |
0acc512c PM |
599 | .stats = NULL, |
600 | .irq_capable = 1, | |
601 | .name = "sched" | |
4b6c2cca JT |
602 | }; |
603 | ||
8e8be45e PM |
604 | /* |
605 | * RCU torture priority-boost testing. Runs one real-time thread per | |
606 | * CPU for moderate bursts, repeatedly registering RCU callbacks and | |
607 | * spinning waiting for them to be invoked. If a given callback takes | |
608 | * too long to be invoked, we assume that priority inversion has occurred. | |
609 | */ | |
610 | ||
611 | struct rcu_boost_inflight { | |
612 | struct rcu_head rcu; | |
613 | int inflight; | |
614 | }; | |
615 | ||
616 | static void rcu_torture_boost_cb(struct rcu_head *head) | |
617 | { | |
618 | struct rcu_boost_inflight *rbip = | |
619 | container_of(head, struct rcu_boost_inflight, rcu); | |
620 | ||
621 | smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */ | |
622 | rbip->inflight = 0; | |
623 | } | |
624 | ||
625 | static int rcu_torture_boost(void *arg) | |
626 | { | |
627 | unsigned long call_rcu_time; | |
628 | unsigned long endtime; | |
629 | unsigned long oldstarttime; | |
630 | struct rcu_boost_inflight rbi = { .inflight = 0 }; | |
631 | struct sched_param sp; | |
632 | ||
5ccf60f2 | 633 | VERBOSE_TOROUT_STRING("rcu_torture_boost started"); |
8e8be45e PM |
634 | |
635 | /* Set real-time priority. */ | |
636 | sp.sched_priority = 1; | |
637 | if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) { | |
5ccf60f2 | 638 | VERBOSE_TOROUT_STRING("rcu_torture_boost RT prio failed!"); |
8e8be45e PM |
639 | n_rcu_torture_boost_rterror++; |
640 | } | |
641 | ||
561190e3 | 642 | init_rcu_head_on_stack(&rbi.rcu); |
8e8be45e PM |
643 | /* Each pass through the following loop does one boost-test cycle. */ |
644 | do { | |
645 | /* Wait for the next test interval. */ | |
646 | oldstarttime = boost_starttime; | |
93898fb1 | 647 | while (ULONG_CMP_LT(jiffies, oldstarttime)) { |
0e11c8e8 | 648 | schedule_timeout_interruptible(oldstarttime - jiffies); |
628edaa5 | 649 | stutter_wait("rcu_torture_boost"); |
36970bb9 | 650 | if (torture_must_stop()) |
8e8be45e PM |
651 | goto checkwait; |
652 | } | |
653 | ||
654 | /* Do one boost-test interval. */ | |
655 | endtime = oldstarttime + test_boost_duration * HZ; | |
656 | call_rcu_time = jiffies; | |
93898fb1 | 657 | while (ULONG_CMP_LT(jiffies, endtime)) { |
8e8be45e PM |
658 | /* If we don't have a callback in flight, post one. */ |
659 | if (!rbi.inflight) { | |
660 | smp_mb(); /* RCU core before ->inflight = 1. */ | |
661 | rbi.inflight = 1; | |
662 | call_rcu(&rbi.rcu, rcu_torture_boost_cb); | |
663 | if (jiffies - call_rcu_time > | |
664 | test_boost_duration * HZ - HZ / 2) { | |
5ccf60f2 | 665 | VERBOSE_TOROUT_STRING("rcu_torture_boost boosting failed"); |
8e8be45e PM |
666 | n_rcu_torture_boost_failure++; |
667 | } | |
668 | call_rcu_time = jiffies; | |
669 | } | |
670 | cond_resched(); | |
628edaa5 | 671 | stutter_wait("rcu_torture_boost"); |
36970bb9 | 672 | if (torture_must_stop()) |
8e8be45e PM |
673 | goto checkwait; |
674 | } | |
675 | ||
676 | /* | |
677 | * Set the start time of the next test interval. | |
678 | * Yes, this is vulnerable to long delays, but such | |
679 | * delays simply cause a false negative for the next | |
680 | * interval. Besides, we are running at RT priority, | |
681 | * so delays should be relatively rare. | |
682 | */ | |
ab8f11e5 PM |
683 | while (oldstarttime == boost_starttime && |
684 | !kthread_should_stop()) { | |
8e8be45e PM |
685 | if (mutex_trylock(&boost_mutex)) { |
686 | boost_starttime = jiffies + | |
687 | test_boost_interval * HZ; | |
688 | n_rcu_torture_boosts++; | |
689 | mutex_unlock(&boost_mutex); | |
690 | break; | |
691 | } | |
692 | schedule_timeout_uninterruptible(1); | |
693 | } | |
694 | ||
695 | /* Go do the stutter. */ | |
628edaa5 | 696 | checkwait: stutter_wait("rcu_torture_boost"); |
36970bb9 | 697 | } while (!torture_must_stop()); |
8e8be45e PM |
698 | |
699 | /* Clean up and exit. */ | |
7fafaac5 PM |
700 | while (!kthread_should_stop() || rbi.inflight) { |
701 | torture_shutdown_absorb("rcu_torture_boost"); | |
8e8be45e | 702 | schedule_timeout_uninterruptible(1); |
7fafaac5 | 703 | } |
8e8be45e | 704 | smp_mb(); /* order accesses to ->inflight before stack-frame death. */ |
9d68197c | 705 | destroy_rcu_head_on_stack(&rbi.rcu); |
7fafaac5 | 706 | torture_kthread_stopping("rcu_torture_boost"); |
8e8be45e PM |
707 | return 0; |
708 | } | |
709 | ||
bf66f18e PM |
710 | /* |
711 | * RCU torture force-quiescent-state kthread. Repeatedly induces | |
712 | * bursts of calls to force_quiescent_state(), increasing the probability | |
713 | * of occurrence of some important types of race conditions. | |
714 | */ | |
715 | static int | |
716 | rcu_torture_fqs(void *arg) | |
717 | { | |
718 | unsigned long fqs_resume_time; | |
719 | int fqs_burst_remaining; | |
720 | ||
5ccf60f2 | 721 | VERBOSE_TOROUT_STRING("rcu_torture_fqs task started"); |
bf66f18e PM |
722 | do { |
723 | fqs_resume_time = jiffies + fqs_stutter * HZ; | |
93898fb1 PM |
724 | while (ULONG_CMP_LT(jiffies, fqs_resume_time) && |
725 | !kthread_should_stop()) { | |
bf66f18e PM |
726 | schedule_timeout_interruptible(1); |
727 | } | |
728 | fqs_burst_remaining = fqs_duration; | |
93898fb1 PM |
729 | while (fqs_burst_remaining > 0 && |
730 | !kthread_should_stop()) { | |
bf66f18e PM |
731 | cur_ops->fqs(); |
732 | udelay(fqs_holdoff); | |
733 | fqs_burst_remaining -= fqs_holdoff; | |
734 | } | |
628edaa5 | 735 | stutter_wait("rcu_torture_fqs"); |
36970bb9 | 736 | } while (!torture_must_stop()); |
7fafaac5 | 737 | torture_kthread_stopping("rcu_torture_fqs"); |
bf66f18e PM |
738 | return 0; |
739 | } | |
740 | ||
a241ec65 PM |
741 | /* |
742 | * RCU torture writer kthread. Repeatedly substitutes a new structure | |
743 | * for that pointed to by rcu_torture_current, freeing the old structure | |
744 | * after a series of grace periods (the "pipeline"). | |
745 | */ | |
746 | static int | |
747 | rcu_torture_writer(void *arg) | |
748 | { | |
a48f3fad PM |
749 | unsigned long gp_snap; |
750 | bool gp_cond1 = gp_cond, gp_exp1 = gp_exp, gp_normal1 = gp_normal; | |
f0bf8fab | 751 | bool gp_sync1 = gp_sync; |
a241ec65 | 752 | int i; |
a241ec65 PM |
753 | struct rcu_torture *rp; |
754 | struct rcu_torture *old_rp; | |
51b1130e | 755 | static DEFINE_TORTURE_RANDOM(rand); |
f0bf8fab PM |
756 | int synctype[] = { RTWS_DEF_FREE, RTWS_EXP_SYNC, |
757 | RTWS_COND_GET, RTWS_SYNC }; | |
a48f3fad | 758 | int nsynctypes = 0; |
a241ec65 | 759 | |
5ccf60f2 | 760 | VERBOSE_TOROUT_STRING("rcu_torture_writer task started"); |
dbdf65b1 | 761 | |
a48f3fad | 762 | /* Initialize synctype[] array. If none set, take default. */ |
f0bf8fab PM |
763 | if (!gp_cond1 && !gp_exp1 && !gp_normal1 && !gp_sync) |
764 | gp_cond1 = gp_exp1 = gp_normal1 = gp_sync1 = true; | |
a48f3fad PM |
765 | if (gp_cond1 && cur_ops->get_state && cur_ops->cond_sync) |
766 | synctype[nsynctypes++] = RTWS_COND_GET; | |
767 | else if (gp_cond && (!cur_ops->get_state || !cur_ops->cond_sync)) | |
768 | pr_alert("rcu_torture_writer: gp_cond without primitives.\n"); | |
769 | if (gp_exp1 && cur_ops->exp_sync) | |
770 | synctype[nsynctypes++] = RTWS_EXP_SYNC; | |
771 | else if (gp_exp && !cur_ops->exp_sync) | |
772 | pr_alert("rcu_torture_writer: gp_exp without primitives.\n"); | |
773 | if (gp_normal1 && cur_ops->deferred_free) | |
774 | synctype[nsynctypes++] = RTWS_DEF_FREE; | |
775 | else if (gp_normal && !cur_ops->deferred_free) | |
776 | pr_alert("rcu_torture_writer: gp_normal without primitives.\n"); | |
f0bf8fab PM |
777 | if (gp_sync1 && cur_ops->sync) |
778 | synctype[nsynctypes++] = RTWS_SYNC; | |
779 | else if (gp_sync && !cur_ops->sync) | |
780 | pr_alert("rcu_torture_writer: gp_sync without primitives.\n"); | |
a48f3fad PM |
781 | if (WARN_ONCE(nsynctypes == 0, |
782 | "rcu_torture_writer: No update-side primitives.\n")) { | |
f0bf8fab PM |
783 | /* |
784 | * No updates primitives, so don't try updating. | |
785 | * The resulting test won't be testing much, hence the | |
786 | * above WARN_ONCE(). | |
787 | */ | |
a48f3fad PM |
788 | rcu_torture_writer_state = RTWS_STOPPING; |
789 | torture_kthread_stopping("rcu_torture_writer"); | |
790 | } | |
791 | ||
a241ec65 | 792 | do { |
ad0dc7f9 | 793 | rcu_torture_writer_state = RTWS_FIXED_DELAY; |
a241ec65 | 794 | schedule_timeout_uninterruptible(1); |
a71fca58 PM |
795 | rp = rcu_torture_alloc(); |
796 | if (rp == NULL) | |
a241ec65 PM |
797 | continue; |
798 | rp->rtort_pipe_count = 0; | |
ad0dc7f9 | 799 | rcu_torture_writer_state = RTWS_DELAY; |
51b1130e | 800 | udelay(torture_random(&rand) & 0x3ff); |
ad0dc7f9 | 801 | rcu_torture_writer_state = RTWS_REPLACE; |
0ddea0ea PM |
802 | old_rp = rcu_dereference_check(rcu_torture_current, |
803 | current == writer_task); | |
996417d2 | 804 | rp->rtort_mbtest = 1; |
a241ec65 | 805 | rcu_assign_pointer(rcu_torture_current, rp); |
9b2619af | 806 | smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */ |
c8e5b163 | 807 | if (old_rp) { |
a241ec65 PM |
808 | i = old_rp->rtort_pipe_count; |
809 | if (i > RCU_TORTURE_PIPE_LEN) | |
810 | i = RCU_TORTURE_PIPE_LEN; | |
811 | atomic_inc(&rcu_torture_wcount[i]); | |
812 | old_rp->rtort_pipe_count++; | |
a48f3fad PM |
813 | switch (synctype[torture_random(&rand) % nsynctypes]) { |
814 | case RTWS_DEF_FREE: | |
ad0dc7f9 | 815 | rcu_torture_writer_state = RTWS_DEF_FREE; |
2ec1f2d9 | 816 | cur_ops->deferred_free(old_rp); |
a48f3fad PM |
817 | break; |
818 | case RTWS_EXP_SYNC: | |
ad0dc7f9 | 819 | rcu_torture_writer_state = RTWS_EXP_SYNC; |
2ec1f2d9 | 820 | cur_ops->exp_sync(); |
a48f3fad PM |
821 | rcu_torture_pipe_update(old_rp); |
822 | break; | |
823 | case RTWS_COND_GET: | |
824 | rcu_torture_writer_state = RTWS_COND_GET; | |
825 | gp_snap = cur_ops->get_state(); | |
826 | i = torture_random(&rand) % 16; | |
827 | if (i != 0) | |
828 | schedule_timeout_interruptible(i); | |
829 | udelay(torture_random(&rand) % 1000); | |
830 | rcu_torture_writer_state = RTWS_COND_SYNC; | |
831 | cur_ops->cond_sync(gp_snap); | |
832 | rcu_torture_pipe_update(old_rp); | |
833 | break; | |
f0bf8fab PM |
834 | case RTWS_SYNC: |
835 | rcu_torture_writer_state = RTWS_SYNC; | |
836 | cur_ops->sync(); | |
837 | rcu_torture_pipe_update(old_rp); | |
838 | break; | |
a48f3fad PM |
839 | default: |
840 | WARN_ON_ONCE(1); | |
841 | break; | |
2ec1f2d9 | 842 | } |
a241ec65 | 843 | } |
4a298656 | 844 | rcutorture_record_progress(++rcu_torture_current_version); |
ad0dc7f9 | 845 | rcu_torture_writer_state = RTWS_STUTTER; |
628edaa5 | 846 | stutter_wait("rcu_torture_writer"); |
36970bb9 | 847 | } while (!torture_must_stop()); |
ad0dc7f9 | 848 | rcu_torture_writer_state = RTWS_STOPPING; |
7fafaac5 | 849 | torture_kthread_stopping("rcu_torture_writer"); |
a241ec65 PM |
850 | return 0; |
851 | } | |
852 | ||
b772e1dd JT |
853 | /* |
854 | * RCU torture fake writer kthread. Repeatedly calls sync, with a random | |
855 | * delay between calls. | |
856 | */ | |
857 | static int | |
858 | rcu_torture_fakewriter(void *arg) | |
859 | { | |
51b1130e | 860 | DEFINE_TORTURE_RANDOM(rand); |
b772e1dd | 861 | |
5ccf60f2 | 862 | VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task started"); |
d277d868 | 863 | set_user_nice(current, MAX_NICE); |
b772e1dd JT |
864 | |
865 | do { | |
51b1130e PM |
866 | schedule_timeout_uninterruptible(1 + torture_random(&rand)%10); |
867 | udelay(torture_random(&rand) & 0x3ff); | |
72472a02 | 868 | if (cur_ops->cb_barrier != NULL && |
51b1130e | 869 | torture_random(&rand) % (nfakewriters * 8) == 0) { |
72472a02 | 870 | cur_ops->cb_barrier(); |
2ec1f2d9 | 871 | } else if (gp_normal == gp_exp) { |
51b1130e | 872 | if (torture_random(&rand) & 0x80) |
2ec1f2d9 PM |
873 | cur_ops->sync(); |
874 | else | |
875 | cur_ops->exp_sync(); | |
876 | } else if (gp_normal) { | |
72472a02 | 877 | cur_ops->sync(); |
2ec1f2d9 PM |
878 | } else { |
879 | cur_ops->exp_sync(); | |
880 | } | |
628edaa5 | 881 | stutter_wait("rcu_torture_fakewriter"); |
36970bb9 | 882 | } while (!torture_must_stop()); |
b772e1dd | 883 | |
7fafaac5 | 884 | torture_kthread_stopping("rcu_torture_fakewriter"); |
b772e1dd JT |
885 | return 0; |
886 | } | |
887 | ||
b3b8a4d4 | 888 | static void rcutorture_trace_dump(void) |
91afaf30 PM |
889 | { |
890 | static atomic_t beenhere = ATOMIC_INIT(0); | |
891 | ||
892 | if (atomic_read(&beenhere)) | |
893 | return; | |
894 | if (atomic_xchg(&beenhere, 1) != 0) | |
895 | return; | |
91afaf30 PM |
896 | ftrace_dump(DUMP_ALL); |
897 | } | |
898 | ||
0729fbf3 PM |
899 | /* |
900 | * RCU torture reader from timer handler. Dereferences rcu_torture_current, | |
901 | * incrementing the corresponding element of the pipeline array. The | |
902 | * counter in the element should never be greater than 1, otherwise, the | |
903 | * RCU implementation is broken. | |
904 | */ | |
905 | static void rcu_torture_timer(unsigned long unused) | |
906 | { | |
907 | int idx; | |
908 | int completed; | |
52494535 | 909 | int completed_end; |
51b1130e | 910 | static DEFINE_TORTURE_RANDOM(rand); |
0729fbf3 PM |
911 | static DEFINE_SPINLOCK(rand_lock); |
912 | struct rcu_torture *p; | |
913 | int pipe_count; | |
52494535 | 914 | unsigned long long ts; |
0729fbf3 PM |
915 | |
916 | idx = cur_ops->readlock(); | |
917 | completed = cur_ops->completed(); | |
e4aa0da3 | 918 | ts = rcu_trace_clock_local(); |
632ee200 | 919 | p = rcu_dereference_check(rcu_torture_current, |
632ee200 PM |
920 | rcu_read_lock_bh_held() || |
921 | rcu_read_lock_sched_held() || | |
922 | srcu_read_lock_held(&srcu_ctl)); | |
0729fbf3 PM |
923 | if (p == NULL) { |
924 | /* Leave because rcu_torture_writer is not yet underway */ | |
925 | cur_ops->readunlock(idx); | |
926 | return; | |
927 | } | |
928 | if (p->rtort_mbtest == 0) | |
929 | atomic_inc(&n_rcu_torture_mberror); | |
930 | spin_lock(&rand_lock); | |
0acc512c | 931 | cur_ops->read_delay(&rand); |
0729fbf3 PM |
932 | n_rcu_torture_timers++; |
933 | spin_unlock(&rand_lock); | |
934 | preempt_disable(); | |
935 | pipe_count = p->rtort_pipe_count; | |
936 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { | |
937 | /* Should not happen, but... */ | |
938 | pipe_count = RCU_TORTURE_PIPE_LEN; | |
939 | } | |
52494535 PM |
940 | completed_end = cur_ops->completed(); |
941 | if (pipe_count > 1) { | |
52494535 PM |
942 | do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, ts, |
943 | completed, completed_end); | |
91afaf30 | 944 | rcutorture_trace_dump(); |
52494535 | 945 | } |
dd17c8f7 | 946 | __this_cpu_inc(rcu_torture_count[pipe_count]); |
52494535 | 947 | completed = completed_end - completed; |
0729fbf3 PM |
948 | if (completed > RCU_TORTURE_PIPE_LEN) { |
949 | /* Should not happen, but... */ | |
950 | completed = RCU_TORTURE_PIPE_LEN; | |
951 | } | |
dd17c8f7 | 952 | __this_cpu_inc(rcu_torture_batch[completed]); |
0729fbf3 PM |
953 | preempt_enable(); |
954 | cur_ops->readunlock(idx); | |
955 | } | |
956 | ||
a241ec65 PM |
957 | /* |
958 | * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current, | |
959 | * incrementing the corresponding element of the pipeline array. The | |
960 | * counter in the element should never be greater than 1, otherwise, the | |
961 | * RCU implementation is broken. | |
962 | */ | |
963 | static int | |
964 | rcu_torture_reader(void *arg) | |
965 | { | |
966 | int completed; | |
52494535 | 967 | int completed_end; |
72e9bb54 | 968 | int idx; |
51b1130e | 969 | DEFINE_TORTURE_RANDOM(rand); |
a241ec65 PM |
970 | struct rcu_torture *p; |
971 | int pipe_count; | |
0729fbf3 | 972 | struct timer_list t; |
52494535 | 973 | unsigned long long ts; |
a241ec65 | 974 | |
5ccf60f2 | 975 | VERBOSE_TOROUT_STRING("rcu_torture_reader task started"); |
d277d868 | 976 | set_user_nice(current, MAX_NICE); |
0acc512c | 977 | if (irqreader && cur_ops->irq_capable) |
0729fbf3 | 978 | setup_timer_on_stack(&t, rcu_torture_timer, 0); |
dbdf65b1 | 979 | |
a241ec65 | 980 | do { |
0acc512c | 981 | if (irqreader && cur_ops->irq_capable) { |
0729fbf3 | 982 | if (!timer_pending(&t)) |
6155fec9 | 983 | mod_timer(&t, jiffies + 1); |
0729fbf3 | 984 | } |
72e9bb54 PM |
985 | idx = cur_ops->readlock(); |
986 | completed = cur_ops->completed(); | |
e4aa0da3 | 987 | ts = rcu_trace_clock_local(); |
632ee200 | 988 | p = rcu_dereference_check(rcu_torture_current, |
632ee200 PM |
989 | rcu_read_lock_bh_held() || |
990 | rcu_read_lock_sched_held() || | |
991 | srcu_read_lock_held(&srcu_ctl)); | |
a241ec65 PM |
992 | if (p == NULL) { |
993 | /* Wait for rcu_torture_writer to get underway */ | |
72e9bb54 | 994 | cur_ops->readunlock(idx); |
a241ec65 PM |
995 | schedule_timeout_interruptible(HZ); |
996 | continue; | |
997 | } | |
996417d2 PM |
998 | if (p->rtort_mbtest == 0) |
999 | atomic_inc(&n_rcu_torture_mberror); | |
0acc512c | 1000 | cur_ops->read_delay(&rand); |
a241ec65 PM |
1001 | preempt_disable(); |
1002 | pipe_count = p->rtort_pipe_count; | |
1003 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { | |
1004 | /* Should not happen, but... */ | |
1005 | pipe_count = RCU_TORTURE_PIPE_LEN; | |
1006 | } | |
52494535 PM |
1007 | completed_end = cur_ops->completed(); |
1008 | if (pipe_count > 1) { | |
52494535 PM |
1009 | do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, |
1010 | ts, completed, completed_end); | |
91afaf30 | 1011 | rcutorture_trace_dump(); |
52494535 | 1012 | } |
dd17c8f7 | 1013 | __this_cpu_inc(rcu_torture_count[pipe_count]); |
52494535 | 1014 | completed = completed_end - completed; |
a241ec65 PM |
1015 | if (completed > RCU_TORTURE_PIPE_LEN) { |
1016 | /* Should not happen, but... */ | |
1017 | completed = RCU_TORTURE_PIPE_LEN; | |
1018 | } | |
dd17c8f7 | 1019 | __this_cpu_inc(rcu_torture_batch[completed]); |
a241ec65 | 1020 | preempt_enable(); |
72e9bb54 | 1021 | cur_ops->readunlock(idx); |
64e4b43a | 1022 | cond_resched(); |
628edaa5 | 1023 | stutter_wait("rcu_torture_reader"); |
36970bb9 | 1024 | } while (!torture_must_stop()); |
424c1b68 | 1025 | if (irqreader && cur_ops->irq_capable) { |
0729fbf3 | 1026 | del_timer_sync(&t); |
424c1b68 TG |
1027 | destroy_timer_on_stack(&t); |
1028 | } | |
7fafaac5 | 1029 | torture_kthread_stopping("rcu_torture_reader"); |
a241ec65 PM |
1030 | return 0; |
1031 | } | |
1032 | ||
1033 | /* | |
eea203fe JP |
1034 | * Print torture statistics. Caller must ensure that there is only |
1035 | * one call to this function at a given time!!! This is normally | |
1036 | * accomplished by relying on the module system to only have one copy | |
1037 | * of the module loaded, and then by giving the rcu_torture_stats | |
1038 | * kthread full control (or the init/cleanup functions when rcu_torture_stats | |
1039 | * thread is not running). | |
a241ec65 | 1040 | */ |
d1008950 | 1041 | static void |
eea203fe | 1042 | rcu_torture_stats_print(void) |
a241ec65 | 1043 | { |
a241ec65 PM |
1044 | int cpu; |
1045 | int i; | |
1046 | long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; | |
1047 | long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; | |
ad0dc7f9 | 1048 | static unsigned long rtcv_snap = ULONG_MAX; |
a241ec65 | 1049 | |
0a945022 | 1050 | for_each_possible_cpu(cpu) { |
a241ec65 PM |
1051 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
1052 | pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i]; | |
1053 | batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i]; | |
1054 | } | |
1055 | } | |
1056 | for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) { | |
1057 | if (pipesummary[i] != 0) | |
1058 | break; | |
1059 | } | |
eea203fe JP |
1060 | |
1061 | pr_alert("%s%s ", torture_type, TORTURE_FLAG); | |
1062 | pr_cont("rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ", | |
1063 | rcu_torture_current, | |
1064 | rcu_torture_current_version, | |
1065 | list_empty(&rcu_torture_freelist), | |
1066 | atomic_read(&n_rcu_torture_alloc), | |
1067 | atomic_read(&n_rcu_torture_alloc_fail), | |
1068 | atomic_read(&n_rcu_torture_free)); | |
1069 | pr_cont("rtmbe: %d rtbke: %ld rtbre: %ld ", | |
1070 | atomic_read(&n_rcu_torture_mberror), | |
1071 | n_rcu_torture_boost_ktrerror, | |
1072 | n_rcu_torture_boost_rterror); | |
1073 | pr_cont("rtbf: %ld rtb: %ld nt: %ld ", | |
1074 | n_rcu_torture_boost_failure, | |
1075 | n_rcu_torture_boosts, | |
1076 | n_rcu_torture_timers); | |
1077 | torture_onoff_stats(); | |
1078 | pr_cont("barrier: %ld/%ld:%ld\n", | |
1079 | n_barrier_successes, | |
1080 | n_barrier_attempts, | |
1081 | n_rcu_torture_barrier_error); | |
1082 | ||
1083 | pr_alert("%s%s ", torture_type, TORTURE_FLAG); | |
8e8be45e | 1084 | if (atomic_read(&n_rcu_torture_mberror) != 0 || |
fae4b54f | 1085 | n_rcu_torture_barrier_error != 0 || |
8e8be45e PM |
1086 | n_rcu_torture_boost_ktrerror != 0 || |
1087 | n_rcu_torture_boost_rterror != 0 || | |
fae4b54f PM |
1088 | n_rcu_torture_boost_failure != 0 || |
1089 | i > 1) { | |
eea203fe | 1090 | pr_cont("%s", "!!! "); |
996417d2 | 1091 | atomic_inc(&n_rcu_torture_error); |
5af970a4 | 1092 | WARN_ON_ONCE(1); |
996417d2 | 1093 | } |
eea203fe | 1094 | pr_cont("Reader Pipe: "); |
a241ec65 | 1095 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
eea203fe JP |
1096 | pr_cont(" %ld", pipesummary[i]); |
1097 | pr_cont("\n"); | |
1098 | ||
1099 | pr_alert("%s%s ", torture_type, TORTURE_FLAG); | |
1100 | pr_cont("Reader Batch: "); | |
72e9bb54 | 1101 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
eea203fe JP |
1102 | pr_cont(" %ld", batchsummary[i]); |
1103 | pr_cont("\n"); | |
1104 | ||
1105 | pr_alert("%s%s ", torture_type, TORTURE_FLAG); | |
1106 | pr_cont("Free-Block Circulation: "); | |
a241ec65 | 1107 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
eea203fe | 1108 | pr_cont(" %d", atomic_read(&rcu_torture_wcount[i])); |
a241ec65 | 1109 | } |
eea203fe JP |
1110 | pr_cont("\n"); |
1111 | ||
c8e5b163 | 1112 | if (cur_ops->stats) |
eea203fe | 1113 | cur_ops->stats(); |
ad0dc7f9 PM |
1114 | if (rtcv_snap == rcu_torture_current_version && |
1115 | rcu_torture_current != NULL) { | |
1116 | int __maybe_unused flags; | |
1117 | unsigned long __maybe_unused gpnum; | |
1118 | unsigned long __maybe_unused completed; | |
1119 | ||
1120 | rcutorture_get_gp_data(cur_ops->ttype, | |
1121 | &flags, &gpnum, &completed); | |
eea203fe JP |
1122 | pr_alert("??? Writer stall state %d g%lu c%lu f%#x\n", |
1123 | rcu_torture_writer_state, | |
1124 | gpnum, completed, flags); | |
afea227f | 1125 | show_rcu_gp_kthreads(); |
945fa9c6 | 1126 | rcutorture_trace_dump(); |
ad0dc7f9 PM |
1127 | } |
1128 | rtcv_snap = rcu_torture_current_version; | |
a241ec65 PM |
1129 | } |
1130 | ||
a241ec65 PM |
1131 | /* |
1132 | * Periodically prints torture statistics, if periodic statistics printing | |
1133 | * was specified via the stat_interval module parameter. | |
a241ec65 PM |
1134 | */ |
1135 | static int | |
1136 | rcu_torture_stats(void *arg) | |
1137 | { | |
5ccf60f2 | 1138 | VERBOSE_TOROUT_STRING("rcu_torture_stats task started"); |
a241ec65 PM |
1139 | do { |
1140 | schedule_timeout_interruptible(stat_interval * HZ); | |
1141 | rcu_torture_stats_print(); | |
f67a3356 | 1142 | torture_shutdown_absorb("rcu_torture_stats"); |
36970bb9 | 1143 | } while (!torture_must_stop()); |
7fafaac5 | 1144 | torture_kthread_stopping("rcu_torture_stats"); |
d120f65f PM |
1145 | return 0; |
1146 | } | |
1147 | ||
95c38322 | 1148 | static inline void |
e66c33d5 | 1149 | rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag) |
95c38322 | 1150 | { |
2caa1e44 PM |
1151 | pr_alert("%s" TORTURE_FLAG |
1152 | "--- %s: nreaders=%d nfakewriters=%d " | |
1153 | "stat_interval=%d verbose=%d test_no_idle_hz=%d " | |
1154 | "shuffle_interval=%d stutter=%d irqreader=%d " | |
1155 | "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d " | |
1156 | "test_boost=%d/%d test_boost_interval=%d " | |
1157 | "test_boost_duration=%d shutdown_secs=%d " | |
67afeed2 PM |
1158 | "stall_cpu=%d stall_cpu_holdoff=%d " |
1159 | "n_barrier_cbs=%d " | |
2caa1e44 PM |
1160 | "onoff_interval=%d onoff_holdoff=%d\n", |
1161 | torture_type, tag, nrealreaders, nfakewriters, | |
1162 | stat_interval, verbose, test_no_idle_hz, shuffle_interval, | |
1163 | stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter, | |
1164 | test_boost, cur_ops->can_boost, | |
1165 | test_boost_interval, test_boost_duration, shutdown_secs, | |
67afeed2 PM |
1166 | stall_cpu, stall_cpu_holdoff, |
1167 | n_barrier_cbs, | |
2caa1e44 | 1168 | onoff_interval, onoff_holdoff); |
95c38322 PM |
1169 | } |
1170 | ||
8e8be45e PM |
1171 | static void rcutorture_booster_cleanup(int cpu) |
1172 | { | |
1173 | struct task_struct *t; | |
1174 | ||
1175 | if (boost_tasks[cpu] == NULL) | |
1176 | return; | |
1177 | mutex_lock(&boost_mutex); | |
8e8be45e PM |
1178 | t = boost_tasks[cpu]; |
1179 | boost_tasks[cpu] = NULL; | |
1180 | mutex_unlock(&boost_mutex); | |
1181 | ||
1182 | /* This must be outside of the mutex, otherwise deadlock! */ | |
9c029b86 | 1183 | torture_stop_kthread(rcu_torture_boost, t); |
8e8be45e PM |
1184 | } |
1185 | ||
1186 | static int rcutorture_booster_init(int cpu) | |
1187 | { | |
1188 | int retval; | |
1189 | ||
1190 | if (boost_tasks[cpu] != NULL) | |
1191 | return 0; /* Already created, nothing more to do. */ | |
1192 | ||
1193 | /* Don't allow time recalculation while creating a new task. */ | |
1194 | mutex_lock(&boost_mutex); | |
5ccf60f2 | 1195 | VERBOSE_TOROUT_STRING("Creating rcu_torture_boost task"); |
1f288094 ED |
1196 | boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL, |
1197 | cpu_to_node(cpu), | |
1198 | "rcu_torture_boost"); | |
8e8be45e PM |
1199 | if (IS_ERR(boost_tasks[cpu])) { |
1200 | retval = PTR_ERR(boost_tasks[cpu]); | |
5ccf60f2 | 1201 | VERBOSE_TOROUT_STRING("rcu_torture_boost task create failed"); |
8e8be45e PM |
1202 | n_rcu_torture_boost_ktrerror++; |
1203 | boost_tasks[cpu] = NULL; | |
1204 | mutex_unlock(&boost_mutex); | |
1205 | return retval; | |
1206 | } | |
1207 | kthread_bind(boost_tasks[cpu], cpu); | |
1208 | wake_up_process(boost_tasks[cpu]); | |
1209 | mutex_unlock(&boost_mutex); | |
1210 | return 0; | |
1211 | } | |
1212 | ||
c13f3757 PM |
1213 | /* |
1214 | * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then | |
1215 | * induces a CPU stall for the time specified by stall_cpu. | |
1216 | */ | |
49fb4c62 | 1217 | static int rcu_torture_stall(void *args) |
c13f3757 PM |
1218 | { |
1219 | unsigned long stop_at; | |
1220 | ||
5ccf60f2 | 1221 | VERBOSE_TOROUT_STRING("rcu_torture_stall task started"); |
c13f3757 | 1222 | if (stall_cpu_holdoff > 0) { |
5ccf60f2 | 1223 | VERBOSE_TOROUT_STRING("rcu_torture_stall begin holdoff"); |
c13f3757 | 1224 | schedule_timeout_interruptible(stall_cpu_holdoff * HZ); |
5ccf60f2 | 1225 | VERBOSE_TOROUT_STRING("rcu_torture_stall end holdoff"); |
c13f3757 PM |
1226 | } |
1227 | if (!kthread_should_stop()) { | |
1228 | stop_at = get_seconds() + stall_cpu; | |
1229 | /* RCU CPU stall is expected behavior in following code. */ | |
2caa1e44 | 1230 | pr_alert("rcu_torture_stall start.\n"); |
c13f3757 PM |
1231 | rcu_read_lock(); |
1232 | preempt_disable(); | |
1233 | while (ULONG_CMP_LT(get_seconds(), stop_at)) | |
1234 | continue; /* Induce RCU CPU stall warning. */ | |
1235 | preempt_enable(); | |
1236 | rcu_read_unlock(); | |
2caa1e44 | 1237 | pr_alert("rcu_torture_stall end.\n"); |
c13f3757 | 1238 | } |
f67a3356 | 1239 | torture_shutdown_absorb("rcu_torture_stall"); |
c13f3757 PM |
1240 | while (!kthread_should_stop()) |
1241 | schedule_timeout_interruptible(10 * HZ); | |
1242 | return 0; | |
1243 | } | |
1244 | ||
1245 | /* Spawn CPU-stall kthread, if stall_cpu specified. */ | |
1246 | static int __init rcu_torture_stall_init(void) | |
1247 | { | |
c13f3757 PM |
1248 | if (stall_cpu <= 0) |
1249 | return 0; | |
47cf29b9 | 1250 | return torture_create_kthread(rcu_torture_stall, NULL, stall_task); |
c13f3757 PM |
1251 | } |
1252 | ||
fae4b54f | 1253 | /* Callback function for RCU barrier testing. */ |
b3b8a4d4 | 1254 | static void rcu_torture_barrier_cbf(struct rcu_head *rcu) |
fae4b54f PM |
1255 | { |
1256 | atomic_inc(&barrier_cbs_invoked); | |
1257 | } | |
1258 | ||
1259 | /* kthread function to register callbacks used to test RCU barriers. */ | |
1260 | static int rcu_torture_barrier_cbs(void *arg) | |
1261 | { | |
1262 | long myid = (long)arg; | |
c6ebcbb6 | 1263 | bool lastphase = 0; |
78e4bc34 | 1264 | bool newphase; |
fae4b54f PM |
1265 | struct rcu_head rcu; |
1266 | ||
1267 | init_rcu_head_on_stack(&rcu); | |
5ccf60f2 | 1268 | VERBOSE_TOROUT_STRING("rcu_torture_barrier_cbs task started"); |
d277d868 | 1269 | set_user_nice(current, MAX_NICE); |
fae4b54f PM |
1270 | do { |
1271 | wait_event(barrier_cbs_wq[myid], | |
78e4bc34 PM |
1272 | (newphase = |
1273 | ACCESS_ONCE(barrier_phase)) != lastphase || | |
36970bb9 | 1274 | torture_must_stop()); |
78e4bc34 | 1275 | lastphase = newphase; |
c6ebcbb6 | 1276 | smp_mb(); /* ensure barrier_phase load before ->call(). */ |
36970bb9 | 1277 | if (torture_must_stop()) |
fae4b54f PM |
1278 | break; |
1279 | cur_ops->call(&rcu, rcu_torture_barrier_cbf); | |
1280 | if (atomic_dec_and_test(&barrier_cbs_count)) | |
1281 | wake_up(&barrier_wq); | |
36970bb9 | 1282 | } while (!torture_must_stop()); |
fae4b54f PM |
1283 | cur_ops->cb_barrier(); |
1284 | destroy_rcu_head_on_stack(&rcu); | |
7fafaac5 | 1285 | torture_kthread_stopping("rcu_torture_barrier_cbs"); |
fae4b54f PM |
1286 | return 0; |
1287 | } | |
1288 | ||
1289 | /* kthread function to drive and coordinate RCU barrier testing. */ | |
1290 | static int rcu_torture_barrier(void *arg) | |
1291 | { | |
1292 | int i; | |
1293 | ||
5ccf60f2 | 1294 | VERBOSE_TOROUT_STRING("rcu_torture_barrier task starting"); |
fae4b54f PM |
1295 | do { |
1296 | atomic_set(&barrier_cbs_invoked, 0); | |
1297 | atomic_set(&barrier_cbs_count, n_barrier_cbs); | |
c6ebcbb6 PM |
1298 | smp_mb(); /* Ensure barrier_phase after prior assignments. */ |
1299 | barrier_phase = !barrier_phase; | |
fae4b54f PM |
1300 | for (i = 0; i < n_barrier_cbs; i++) |
1301 | wake_up(&barrier_cbs_wq[i]); | |
1302 | wait_event(barrier_wq, | |
1303 | atomic_read(&barrier_cbs_count) == 0 || | |
36970bb9 PM |
1304 | torture_must_stop()); |
1305 | if (torture_must_stop()) | |
fae4b54f PM |
1306 | break; |
1307 | n_barrier_attempts++; | |
78e4bc34 | 1308 | cur_ops->cb_barrier(); /* Implies smp_mb() for wait_event(). */ |
fae4b54f PM |
1309 | if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) { |
1310 | n_rcu_torture_barrier_error++; | |
1311 | WARN_ON_ONCE(1); | |
1312 | } | |
1313 | n_barrier_successes++; | |
1314 | schedule_timeout_interruptible(HZ / 10); | |
36970bb9 | 1315 | } while (!torture_must_stop()); |
7fafaac5 | 1316 | torture_kthread_stopping("rcu_torture_barrier"); |
fae4b54f PM |
1317 | return 0; |
1318 | } | |
1319 | ||
1320 | /* Initialize RCU barrier testing. */ | |
1321 | static int rcu_torture_barrier_init(void) | |
1322 | { | |
1323 | int i; | |
1324 | int ret; | |
1325 | ||
1326 | if (n_barrier_cbs == 0) | |
1327 | return 0; | |
1328 | if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) { | |
2caa1e44 PM |
1329 | pr_alert("%s" TORTURE_FLAG |
1330 | " Call or barrier ops missing for %s,\n", | |
1331 | torture_type, cur_ops->name); | |
1332 | pr_alert("%s" TORTURE_FLAG | |
1333 | " RCU barrier testing omitted from run.\n", | |
1334 | torture_type); | |
fae4b54f PM |
1335 | return 0; |
1336 | } | |
1337 | atomic_set(&barrier_cbs_count, 0); | |
1338 | atomic_set(&barrier_cbs_invoked, 0); | |
1339 | barrier_cbs_tasks = | |
1340 | kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]), | |
1341 | GFP_KERNEL); | |
1342 | barrier_cbs_wq = | |
1343 | kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]), | |
1344 | GFP_KERNEL); | |
de5e6437 | 1345 | if (barrier_cbs_tasks == NULL || !barrier_cbs_wq) |
fae4b54f PM |
1346 | return -ENOMEM; |
1347 | for (i = 0; i < n_barrier_cbs; i++) { | |
1348 | init_waitqueue_head(&barrier_cbs_wq[i]); | |
47cf29b9 PM |
1349 | ret = torture_create_kthread(rcu_torture_barrier_cbs, |
1350 | (void *)(long)i, | |
1351 | barrier_cbs_tasks[i]); | |
1352 | if (ret) | |
fae4b54f | 1353 | return ret; |
fae4b54f | 1354 | } |
47cf29b9 | 1355 | return torture_create_kthread(rcu_torture_barrier, NULL, barrier_task); |
fae4b54f PM |
1356 | } |
1357 | ||
1358 | /* Clean up after RCU barrier testing. */ | |
1359 | static void rcu_torture_barrier_cleanup(void) | |
1360 | { | |
1361 | int i; | |
1362 | ||
9c029b86 | 1363 | torture_stop_kthread(rcu_torture_barrier, barrier_task); |
fae4b54f | 1364 | if (barrier_cbs_tasks != NULL) { |
9c029b86 PM |
1365 | for (i = 0; i < n_barrier_cbs; i++) |
1366 | torture_stop_kthread(rcu_torture_barrier_cbs, | |
1367 | barrier_cbs_tasks[i]); | |
fae4b54f PM |
1368 | kfree(barrier_cbs_tasks); |
1369 | barrier_cbs_tasks = NULL; | |
1370 | } | |
1371 | if (barrier_cbs_wq != NULL) { | |
1372 | kfree(barrier_cbs_wq); | |
1373 | barrier_cbs_wq = NULL; | |
1374 | } | |
1375 | } | |
1376 | ||
8e8be45e PM |
1377 | static int rcutorture_cpu_notify(struct notifier_block *self, |
1378 | unsigned long action, void *hcpu) | |
1379 | { | |
1380 | long cpu = (long)hcpu; | |
1381 | ||
1382 | switch (action) { | |
1383 | case CPU_ONLINE: | |
1384 | case CPU_DOWN_FAILED: | |
1385 | (void)rcutorture_booster_init(cpu); | |
1386 | break; | |
1387 | case CPU_DOWN_PREPARE: | |
1388 | rcutorture_booster_cleanup(cpu); | |
1389 | break; | |
1390 | default: | |
1391 | break; | |
1392 | } | |
1393 | return NOTIFY_OK; | |
1394 | } | |
1395 | ||
1396 | static struct notifier_block rcutorture_cpu_nb = { | |
1397 | .notifier_call = rcutorture_cpu_notify, | |
1398 | }; | |
1399 | ||
a241ec65 PM |
1400 | static void |
1401 | rcu_torture_cleanup(void) | |
1402 | { | |
1403 | int i; | |
1404 | ||
4a298656 | 1405 | rcutorture_record_test_transition(); |
cc47ae08 | 1406 | if (torture_cleanup()) { |
343e9099 PM |
1407 | if (cur_ops->cb_barrier != NULL) |
1408 | cur_ops->cb_barrier(); | |
1409 | return; | |
1410 | } | |
d84f5203 | 1411 | |
fae4b54f | 1412 | rcu_torture_barrier_cleanup(); |
9c029b86 | 1413 | torture_stop_kthread(rcu_torture_stall, stall_task); |
9c029b86 | 1414 | torture_stop_kthread(rcu_torture_writer, writer_task); |
a241ec65 | 1415 | |
c8e5b163 | 1416 | if (reader_tasks) { |
9c029b86 PM |
1417 | for (i = 0; i < nrealreaders; i++) |
1418 | torture_stop_kthread(rcu_torture_reader, | |
1419 | reader_tasks[i]); | |
a241ec65 | 1420 | kfree(reader_tasks); |
a241ec65 PM |
1421 | } |
1422 | rcu_torture_current = NULL; | |
1423 | ||
c8e5b163 | 1424 | if (fakewriter_tasks) { |
b772e1dd | 1425 | for (i = 0; i < nfakewriters; i++) { |
9c029b86 PM |
1426 | torture_stop_kthread(rcu_torture_fakewriter, |
1427 | fakewriter_tasks[i]); | |
b772e1dd JT |
1428 | } |
1429 | kfree(fakewriter_tasks); | |
1430 | fakewriter_tasks = NULL; | |
1431 | } | |
1432 | ||
9c029b86 PM |
1433 | torture_stop_kthread(rcu_torture_stats, stats_task); |
1434 | torture_stop_kthread(rcu_torture_fqs, fqs_task); | |
8e8be45e PM |
1435 | if ((test_boost == 1 && cur_ops->can_boost) || |
1436 | test_boost == 2) { | |
1437 | unregister_cpu_notifier(&rcutorture_cpu_nb); | |
1438 | for_each_possible_cpu(i) | |
1439 | rcutorture_booster_cleanup(i); | |
1440 | } | |
bf66f18e | 1441 | |
a241ec65 | 1442 | /* Wait for all RCU callbacks to fire. */ |
2326974d PM |
1443 | |
1444 | if (cur_ops->cb_barrier != NULL) | |
1445 | cur_ops->cb_barrier(); | |
a241ec65 | 1446 | |
a241ec65 | 1447 | rcu_torture_stats_print(); /* -After- the stats thread is stopped! */ |
72e9bb54 | 1448 | |
fae4b54f | 1449 | if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error) |
8e8be45e | 1450 | rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE"); |
2e9e8081 | 1451 | else if (torture_onoff_failures()) |
091541bb PM |
1452 | rcu_torture_print_module_parms(cur_ops, |
1453 | "End of test: RCU_HOTPLUG"); | |
95c38322 | 1454 | else |
8e8be45e | 1455 | rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS"); |
a241ec65 PM |
1456 | } |
1457 | ||
d2818df1 PM |
1458 | #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD |
1459 | static void rcu_torture_leak_cb(struct rcu_head *rhp) | |
1460 | { | |
1461 | } | |
1462 | ||
1463 | static void rcu_torture_err_cb(struct rcu_head *rhp) | |
1464 | { | |
1465 | /* | |
1466 | * This -might- happen due to race conditions, but is unlikely. | |
1467 | * The scenario that leads to this happening is that the | |
1468 | * first of the pair of duplicate callbacks is queued, | |
1469 | * someone else starts a grace period that includes that | |
1470 | * callback, then the second of the pair must wait for the | |
1471 | * next grace period. Unlikely, but can happen. If it | |
1472 | * does happen, the debug-objects subsystem won't have splatted. | |
1473 | */ | |
1474 | pr_alert("rcutorture: duplicated callback was invoked.\n"); | |
1475 | } | |
1476 | #endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */ | |
1477 | ||
1478 | /* | |
1479 | * Verify that double-free causes debug-objects to complain, but only | |
1480 | * if CONFIG_DEBUG_OBJECTS_RCU_HEAD=y. Otherwise, say that the test | |
1481 | * cannot be carried out. | |
1482 | */ | |
1483 | static void rcu_test_debug_objects(void) | |
1484 | { | |
1485 | #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD | |
1486 | struct rcu_head rh1; | |
1487 | struct rcu_head rh2; | |
1488 | ||
1489 | init_rcu_head_on_stack(&rh1); | |
1490 | init_rcu_head_on_stack(&rh2); | |
1491 | pr_alert("rcutorture: WARN: Duplicate call_rcu() test starting.\n"); | |
1492 | ||
1493 | /* Try to queue the rh2 pair of callbacks for the same grace period. */ | |
1494 | preempt_disable(); /* Prevent preemption from interrupting test. */ | |
1495 | rcu_read_lock(); /* Make it impossible to finish a grace period. */ | |
1496 | call_rcu(&rh1, rcu_torture_leak_cb); /* Start grace period. */ | |
1497 | local_irq_disable(); /* Make it harder to start a new grace period. */ | |
1498 | call_rcu(&rh2, rcu_torture_leak_cb); | |
1499 | call_rcu(&rh2, rcu_torture_err_cb); /* Duplicate callback. */ | |
1500 | local_irq_enable(); | |
1501 | rcu_read_unlock(); | |
1502 | preempt_enable(); | |
1503 | ||
1504 | /* Wait for them all to get done so we can safely return. */ | |
1505 | rcu_barrier(); | |
1506 | pr_alert("rcutorture: WARN: Duplicate call_rcu() test complete.\n"); | |
1507 | destroy_rcu_head_on_stack(&rh1); | |
1508 | destroy_rcu_head_on_stack(&rh2); | |
1509 | #else /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */ | |
1510 | pr_alert("rcutorture: !CONFIG_DEBUG_OBJECTS_RCU_HEAD, not testing duplicate call_rcu()\n"); | |
1511 | #endif /* #else #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */ | |
1512 | } | |
1513 | ||
6f8bc500 | 1514 | static int __init |
a241ec65 PM |
1515 | rcu_torture_init(void) |
1516 | { | |
1517 | int i; | |
1518 | int cpu; | |
1519 | int firsterr = 0; | |
2ec1f2d9 | 1520 | static struct rcu_torture_ops *torture_ops[] = { |
ff20e251 | 1521 | &rcu_ops, &rcu_bh_ops, &rcu_busted_ops, &srcu_ops, &sched_ops, |
2ec1f2d9 | 1522 | }; |
a241ec65 | 1523 | |
5228084e PM |
1524 | if (!torture_init_begin(torture_type, verbose, &rcutorture_runnable)) |
1525 | return -EBUSY; | |
343e9099 | 1526 | |
a241ec65 | 1527 | /* Process args and tell the world that the torturer is on the job. */ |
ade5fb81 | 1528 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) { |
72e9bb54 | 1529 | cur_ops = torture_ops[i]; |
ade5fb81 | 1530 | if (strcmp(torture_type, cur_ops->name) == 0) |
72e9bb54 | 1531 | break; |
72e9bb54 | 1532 | } |
ade5fb81 | 1533 | if (i == ARRAY_SIZE(torture_ops)) { |
2caa1e44 PM |
1534 | pr_alert("rcu-torture: invalid torture type: \"%s\"\n", |
1535 | torture_type); | |
1536 | pr_alert("rcu-torture types:"); | |
cf886c44 | 1537 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) |
2caa1e44 PM |
1538 | pr_alert(" %s", torture_ops[i]->name); |
1539 | pr_alert("\n"); | |
b5daa8f3 | 1540 | torture_init_end(); |
a71fca58 | 1541 | return -EINVAL; |
72e9bb54 | 1542 | } |
bf66f18e | 1543 | if (cur_ops->fqs == NULL && fqs_duration != 0) { |
2caa1e44 | 1544 | pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n"); |
bf66f18e PM |
1545 | fqs_duration = 0; |
1546 | } | |
c8e5b163 | 1547 | if (cur_ops->init) |
72e9bb54 PM |
1548 | cur_ops->init(); /* no "goto unwind" prior to this point!!! */ |
1549 | ||
64e4b43a | 1550 | if (nreaders >= 0) { |
a241ec65 | 1551 | nrealreaders = nreaders; |
64e4b43a PM |
1552 | } else { |
1553 | nrealreaders = num_online_cpus() - 1; | |
1554 | if (nrealreaders <= 0) | |
1555 | nrealreaders = 1; | |
1556 | } | |
8e8be45e | 1557 | rcu_torture_print_module_parms(cur_ops, "Start of test"); |
a241ec65 PM |
1558 | |
1559 | /* Set up the freelist. */ | |
1560 | ||
1561 | INIT_LIST_HEAD(&rcu_torture_freelist); | |
788e770e | 1562 | for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) { |
996417d2 | 1563 | rcu_tortures[i].rtort_mbtest = 0; |
a241ec65 PM |
1564 | list_add_tail(&rcu_tortures[i].rtort_free, |
1565 | &rcu_torture_freelist); | |
1566 | } | |
1567 | ||
1568 | /* Initialize the statistics so that each run gets its own numbers. */ | |
1569 | ||
1570 | rcu_torture_current = NULL; | |
1571 | rcu_torture_current_version = 0; | |
1572 | atomic_set(&n_rcu_torture_alloc, 0); | |
1573 | atomic_set(&n_rcu_torture_alloc_fail, 0); | |
1574 | atomic_set(&n_rcu_torture_free, 0); | |
996417d2 PM |
1575 | atomic_set(&n_rcu_torture_mberror, 0); |
1576 | atomic_set(&n_rcu_torture_error, 0); | |
fae4b54f | 1577 | n_rcu_torture_barrier_error = 0; |
8e8be45e PM |
1578 | n_rcu_torture_boost_ktrerror = 0; |
1579 | n_rcu_torture_boost_rterror = 0; | |
8e8be45e PM |
1580 | n_rcu_torture_boost_failure = 0; |
1581 | n_rcu_torture_boosts = 0; | |
a241ec65 PM |
1582 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
1583 | atomic_set(&rcu_torture_wcount[i], 0); | |
0a945022 | 1584 | for_each_possible_cpu(cpu) { |
a241ec65 PM |
1585 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
1586 | per_cpu(rcu_torture_count, cpu)[i] = 0; | |
1587 | per_cpu(rcu_torture_batch, cpu)[i] = 0; | |
1588 | } | |
1589 | } | |
1590 | ||
1591 | /* Start up the kthreads. */ | |
1592 | ||
47cf29b9 PM |
1593 | firsterr = torture_create_kthread(rcu_torture_writer, NULL, |
1594 | writer_task); | |
1595 | if (firsterr) | |
a241ec65 | 1596 | goto unwind; |
b772e1dd | 1597 | fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]), |
a71fca58 | 1598 | GFP_KERNEL); |
b772e1dd | 1599 | if (fakewriter_tasks == NULL) { |
5ccf60f2 | 1600 | VERBOSE_TOROUT_ERRSTRING("out of memory"); |
b772e1dd JT |
1601 | firsterr = -ENOMEM; |
1602 | goto unwind; | |
1603 | } | |
1604 | for (i = 0; i < nfakewriters; i++) { | |
47cf29b9 PM |
1605 | firsterr = torture_create_kthread(rcu_torture_fakewriter, |
1606 | NULL, fakewriter_tasks[i]); | |
1607 | if (firsterr) | |
b772e1dd | 1608 | goto unwind; |
b772e1dd | 1609 | } |
2860aaba | 1610 | reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]), |
a241ec65 PM |
1611 | GFP_KERNEL); |
1612 | if (reader_tasks == NULL) { | |
5ccf60f2 | 1613 | VERBOSE_TOROUT_ERRSTRING("out of memory"); |
a241ec65 PM |
1614 | firsterr = -ENOMEM; |
1615 | goto unwind; | |
1616 | } | |
1617 | for (i = 0; i < nrealreaders; i++) { | |
47cf29b9 PM |
1618 | firsterr = torture_create_kthread(rcu_torture_reader, NULL, |
1619 | reader_tasks[i]); | |
1620 | if (firsterr) | |
a241ec65 | 1621 | goto unwind; |
a241ec65 PM |
1622 | } |
1623 | if (stat_interval > 0) { | |
47cf29b9 PM |
1624 | firsterr = torture_create_kthread(rcu_torture_stats, NULL, |
1625 | stats_task); | |
1626 | if (firsterr) | |
a241ec65 | 1627 | goto unwind; |
a241ec65 | 1628 | } |
d84f5203 | 1629 | if (test_no_idle_hz) { |
3808dc9f PM |
1630 | firsterr = torture_shuffle_init(shuffle_interval * HZ); |
1631 | if (firsterr) | |
d84f5203 | 1632 | goto unwind; |
d84f5203 | 1633 | } |
d120f65f PM |
1634 | if (stutter < 0) |
1635 | stutter = 0; | |
1636 | if (stutter) { | |
628edaa5 PM |
1637 | firsterr = torture_stutter_init(stutter * HZ); |
1638 | if (firsterr) | |
d120f65f | 1639 | goto unwind; |
d120f65f | 1640 | } |
bf66f18e PM |
1641 | if (fqs_duration < 0) |
1642 | fqs_duration = 0; | |
1643 | if (fqs_duration) { | |
628edaa5 | 1644 | /* Create the fqs thread */ |
d0d0606e PM |
1645 | firsterr = torture_create_kthread(rcu_torture_fqs, NULL, |
1646 | fqs_task); | |
47cf29b9 | 1647 | if (firsterr) |
bf66f18e | 1648 | goto unwind; |
bf66f18e | 1649 | } |
8e8be45e PM |
1650 | if (test_boost_interval < 1) |
1651 | test_boost_interval = 1; | |
1652 | if (test_boost_duration < 2) | |
1653 | test_boost_duration = 2; | |
1654 | if ((test_boost == 1 && cur_ops->can_boost) || | |
1655 | test_boost == 2) { | |
8e8be45e PM |
1656 | |
1657 | boost_starttime = jiffies + test_boost_interval * HZ; | |
1658 | register_cpu_notifier(&rcutorture_cpu_nb); | |
1659 | for_each_possible_cpu(i) { | |
1660 | if (cpu_is_offline(i)) | |
1661 | continue; /* Heuristic: CPU can go offline. */ | |
01025ebc PM |
1662 | firsterr = rcutorture_booster_init(i); |
1663 | if (firsterr) | |
8e8be45e | 1664 | goto unwind; |
8e8be45e PM |
1665 | } |
1666 | } | |
01025ebc PM |
1667 | firsterr = torture_shutdown_init(shutdown_secs, rcu_torture_cleanup); |
1668 | if (firsterr) | |
37e377d2 | 1669 | goto unwind; |
01025ebc PM |
1670 | firsterr = torture_onoff_init(onoff_holdoff * HZ, onoff_interval * HZ); |
1671 | if (firsterr) | |
37e377d2 | 1672 | goto unwind; |
01025ebc PM |
1673 | firsterr = rcu_torture_stall_init(); |
1674 | if (firsterr) | |
37e377d2 | 1675 | goto unwind; |
01025ebc PM |
1676 | firsterr = rcu_torture_barrier_init(); |
1677 | if (firsterr) | |
fae4b54f | 1678 | goto unwind; |
d2818df1 PM |
1679 | if (object_debug) |
1680 | rcu_test_debug_objects(); | |
4a298656 | 1681 | rcutorture_record_test_transition(); |
b5daa8f3 | 1682 | torture_init_end(); |
a241ec65 PM |
1683 | return 0; |
1684 | ||
1685 | unwind: | |
b5daa8f3 | 1686 | torture_init_end(); |
a241ec65 PM |
1687 | rcu_torture_cleanup(); |
1688 | return firsterr; | |
1689 | } | |
1690 | ||
1691 | module_init(rcu_torture_init); | |
1692 | module_exit(rcu_torture_cleanup); |