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> | |
b772e1dd | 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> | |
36 | #include <asm/atomic.h> | |
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> |
f07767fd | 49 | #include <asm/byteorder.h> |
a241ec65 PM |
50 | |
51 | MODULE_LICENSE("GPL"); | |
b772e1dd JT |
52 | MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and " |
53 | "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 */ |
d84f5203 | 57 | static int stat_interval; /* Interval between stats, in seconds. */ |
a241ec65 | 58 | /* Defaults to "only at end of test". */ |
d84f5203 SV |
59 | static int verbose; /* Print more debug info. */ |
60 | static int test_no_idle_hz; /* Test RCU's support for tickless idle CPUs. */ | |
d120f65f PM |
61 | static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/ |
62 | static int stutter = 5; /* Start/stop testing interval (in sec) */ | |
0729fbf3 | 63 | static int irqreader = 1; /* RCU readers from irq (timers). */ |
20d2e428 | 64 | static char *torture_type = "rcu"; /* What RCU implementation to torture. */ |
a241ec65 | 65 | |
d6ad6711 | 66 | module_param(nreaders, int, 0444); |
a241ec65 | 67 | MODULE_PARM_DESC(nreaders, "Number of RCU reader threads"); |
d6ad6711 | 68 | module_param(nfakewriters, int, 0444); |
b772e1dd | 69 | MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads"); |
d6ad6711 | 70 | module_param(stat_interval, int, 0444); |
a241ec65 | 71 | MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s"); |
d6ad6711 | 72 | module_param(verbose, bool, 0444); |
a241ec65 | 73 | MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s"); |
d6ad6711 | 74 | module_param(test_no_idle_hz, bool, 0444); |
d84f5203 | 75 | MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs"); |
d6ad6711 | 76 | module_param(shuffle_interval, int, 0444); |
d84f5203 | 77 | MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles"); |
d120f65f PM |
78 | module_param(stutter, int, 0444); |
79 | MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test"); | |
0729fbf3 PM |
80 | module_param(irqreader, int, 0444); |
81 | MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers"); | |
d6ad6711 | 82 | module_param(torture_type, charp, 0444); |
b2896d2e | 83 | MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)"); |
72e9bb54 PM |
84 | |
85 | #define TORTURE_FLAG "-torture:" | |
a241ec65 | 86 | #define PRINTK_STRING(s) \ |
72e9bb54 | 87 | do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0) |
a241ec65 | 88 | #define VERBOSE_PRINTK_STRING(s) \ |
72e9bb54 | 89 | do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0) |
a241ec65 | 90 | #define VERBOSE_PRINTK_ERRSTRING(s) \ |
72e9bb54 | 91 | do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0) |
a241ec65 PM |
92 | |
93 | static char printk_buf[4096]; | |
94 | ||
95 | static int nrealreaders; | |
96 | static struct task_struct *writer_task; | |
b772e1dd | 97 | static struct task_struct **fakewriter_tasks; |
a241ec65 PM |
98 | static struct task_struct **reader_tasks; |
99 | static struct task_struct *stats_task; | |
d84f5203 | 100 | static struct task_struct *shuffler_task; |
d120f65f | 101 | static struct task_struct *stutter_task; |
a241ec65 PM |
102 | |
103 | #define RCU_TORTURE_PIPE_LEN 10 | |
104 | ||
105 | struct rcu_torture { | |
106 | struct rcu_head rtort_rcu; | |
107 | int rtort_pipe_count; | |
108 | struct list_head rtort_free; | |
996417d2 | 109 | int rtort_mbtest; |
a241ec65 PM |
110 | }; |
111 | ||
a241ec65 PM |
112 | static LIST_HEAD(rcu_torture_freelist); |
113 | static struct rcu_torture *rcu_torture_current = NULL; | |
114 | static long rcu_torture_current_version = 0; | |
115 | static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN]; | |
116 | static DEFINE_SPINLOCK(rcu_torture_lock); | |
117 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) = | |
118 | { 0 }; | |
119 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) = | |
120 | { 0 }; | |
121 | static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1]; | |
b2896d2e PM |
122 | static atomic_t n_rcu_torture_alloc; |
123 | static atomic_t n_rcu_torture_alloc_fail; | |
124 | static atomic_t n_rcu_torture_free; | |
125 | static atomic_t n_rcu_torture_mberror; | |
126 | static atomic_t n_rcu_torture_error; | |
0729fbf3 | 127 | static long n_rcu_torture_timers = 0; |
e3033736 | 128 | static struct list_head rcu_torture_removed; |
a241ec65 | 129 | |
d120f65f PM |
130 | static int stutter_pause_test = 0; |
131 | ||
31a72bce PM |
132 | #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE) |
133 | #define RCUTORTURE_RUNNABLE_INIT 1 | |
134 | #else | |
135 | #define RCUTORTURE_RUNNABLE_INIT 0 | |
136 | #endif | |
137 | int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT; | |
138 | ||
c59ab97e | 139 | #define FULLSTOP_SHUTDOWN 1 /* Bail due to system shutdown/panic. */ |
343e9099 PM |
140 | #define FULLSTOP_CLEANUP 2 /* Orderly shutdown. */ |
141 | static int fullstop; /* stop generating callbacks at test end. */ | |
142 | DEFINE_MUTEX(fullstop_mutex); /* protect fullstop transitions and */ | |
143 | /* spawning of kthreads. */ | |
144 | ||
145 | /* | |
146 | * Detect and respond to a signal-based shutdown. | |
147 | */ | |
148 | static int | |
149 | rcutorture_shutdown_notify(struct notifier_block *unused1, | |
150 | unsigned long unused2, void *unused3) | |
151 | { | |
152 | if (fullstop) | |
153 | return NOTIFY_DONE; | |
c59ab97e PM |
154 | mutex_lock(&fullstop_mutex); |
155 | if (!fullstop) | |
156 | fullstop = FULLSTOP_SHUTDOWN; | |
157 | mutex_unlock(&fullstop_mutex); | |
343e9099 PM |
158 | return NOTIFY_DONE; |
159 | } | |
160 | ||
a241ec65 PM |
161 | /* |
162 | * Allocate an element from the rcu_tortures pool. | |
163 | */ | |
97a41e26 | 164 | static struct rcu_torture * |
a241ec65 PM |
165 | rcu_torture_alloc(void) |
166 | { | |
167 | struct list_head *p; | |
168 | ||
adac1665 | 169 | spin_lock_bh(&rcu_torture_lock); |
a241ec65 PM |
170 | if (list_empty(&rcu_torture_freelist)) { |
171 | atomic_inc(&n_rcu_torture_alloc_fail); | |
adac1665 | 172 | spin_unlock_bh(&rcu_torture_lock); |
a241ec65 PM |
173 | return NULL; |
174 | } | |
175 | atomic_inc(&n_rcu_torture_alloc); | |
176 | p = rcu_torture_freelist.next; | |
177 | list_del_init(p); | |
adac1665 | 178 | spin_unlock_bh(&rcu_torture_lock); |
a241ec65 PM |
179 | return container_of(p, struct rcu_torture, rtort_free); |
180 | } | |
181 | ||
182 | /* | |
183 | * Free an element to the rcu_tortures pool. | |
184 | */ | |
185 | static void | |
186 | rcu_torture_free(struct rcu_torture *p) | |
187 | { | |
188 | atomic_inc(&n_rcu_torture_free); | |
adac1665 | 189 | spin_lock_bh(&rcu_torture_lock); |
a241ec65 | 190 | list_add_tail(&p->rtort_free, &rcu_torture_freelist); |
adac1665 | 191 | spin_unlock_bh(&rcu_torture_lock); |
a241ec65 PM |
192 | } |
193 | ||
a241ec65 PM |
194 | struct rcu_random_state { |
195 | unsigned long rrs_state; | |
75cfef32 | 196 | long rrs_count; |
a241ec65 PM |
197 | }; |
198 | ||
199 | #define RCU_RANDOM_MULT 39916801 /* prime */ | |
200 | #define RCU_RANDOM_ADD 479001701 /* prime */ | |
201 | #define RCU_RANDOM_REFRESH 10000 | |
202 | ||
203 | #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 } | |
204 | ||
205 | /* | |
206 | * Crude but fast random-number generator. Uses a linear congruential | |
c17ac855 | 207 | * generator, with occasional help from cpu_clock(). |
a241ec65 | 208 | */ |
75cfef32 | 209 | static unsigned long |
a241ec65 PM |
210 | rcu_random(struct rcu_random_state *rrsp) |
211 | { | |
a241ec65 | 212 | if (--rrsp->rrs_count < 0) { |
c17ac855 PM |
213 | rrsp->rrs_state += |
214 | (unsigned long)cpu_clock(raw_smp_processor_id()); | |
a241ec65 PM |
215 | rrsp->rrs_count = RCU_RANDOM_REFRESH; |
216 | } | |
217 | rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD; | |
218 | return swahw32(rrsp->rrs_state); | |
219 | } | |
220 | ||
d120f65f PM |
221 | static void |
222 | rcu_stutter_wait(void) | |
223 | { | |
343e9099 | 224 | while ((stutter_pause_test || !rcutorture_runnable) && !fullstop) { |
e3d7be27 PM |
225 | if (rcutorture_runnable) |
226 | schedule_timeout_interruptible(1); | |
227 | else | |
3ccf79f4 | 228 | schedule_timeout_interruptible(round_jiffies_relative(HZ)); |
343e9099 | 229 | } |
d120f65f PM |
230 | } |
231 | ||
72e9bb54 PM |
232 | /* |
233 | * Operations vector for selecting different types of tests. | |
234 | */ | |
235 | ||
236 | struct rcu_torture_ops { | |
237 | void (*init)(void); | |
238 | void (*cleanup)(void); | |
239 | int (*readlock)(void); | |
b2896d2e | 240 | void (*readdelay)(struct rcu_random_state *rrsp); |
72e9bb54 PM |
241 | void (*readunlock)(int idx); |
242 | int (*completed)(void); | |
243 | void (*deferredfree)(struct rcu_torture *p); | |
b772e1dd | 244 | void (*sync)(void); |
2326974d | 245 | void (*cb_barrier)(void); |
72e9bb54 | 246 | int (*stats)(char *page); |
0729fbf3 | 247 | int irqcapable; |
72e9bb54 PM |
248 | char *name; |
249 | }; | |
250 | static struct rcu_torture_ops *cur_ops = NULL; | |
251 | ||
252 | /* | |
253 | * Definitions for rcu torture testing. | |
254 | */ | |
255 | ||
a49a4af7 | 256 | static int rcu_torture_read_lock(void) __acquires(RCU) |
72e9bb54 PM |
257 | { |
258 | rcu_read_lock(); | |
259 | return 0; | |
260 | } | |
261 | ||
b2896d2e PM |
262 | static void rcu_read_delay(struct rcu_random_state *rrsp) |
263 | { | |
264 | long delay; | |
265 | const long longdelay = 200; | |
266 | ||
267 | /* We want there to be long-running readers, but not all the time. */ | |
268 | ||
269 | delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay); | |
270 | if (!delay) | |
271 | udelay(longdelay); | |
272 | } | |
273 | ||
a49a4af7 | 274 | static void rcu_torture_read_unlock(int idx) __releases(RCU) |
72e9bb54 PM |
275 | { |
276 | rcu_read_unlock(); | |
277 | } | |
278 | ||
279 | static int rcu_torture_completed(void) | |
280 | { | |
281 | return rcu_batches_completed(); | |
282 | } | |
283 | ||
284 | static void | |
285 | rcu_torture_cb(struct rcu_head *p) | |
286 | { | |
287 | int i; | |
288 | struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu); | |
289 | ||
290 | if (fullstop) { | |
291 | /* Test is ending, just drop callbacks on the floor. */ | |
292 | /* The next initialization will pick up the pieces. */ | |
293 | return; | |
294 | } | |
295 | i = rp->rtort_pipe_count; | |
296 | if (i > RCU_TORTURE_PIPE_LEN) | |
297 | i = RCU_TORTURE_PIPE_LEN; | |
298 | atomic_inc(&rcu_torture_wcount[i]); | |
299 | if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) { | |
300 | rp->rtort_mbtest = 0; | |
301 | rcu_torture_free(rp); | |
302 | } else | |
303 | cur_ops->deferredfree(rp); | |
304 | } | |
305 | ||
306 | static void rcu_torture_deferred_free(struct rcu_torture *p) | |
307 | { | |
308 | call_rcu(&p->rtort_rcu, rcu_torture_cb); | |
309 | } | |
310 | ||
311 | static struct rcu_torture_ops rcu_ops = { | |
312 | .init = NULL, | |
313 | .cleanup = NULL, | |
314 | .readlock = rcu_torture_read_lock, | |
b2896d2e | 315 | .readdelay = rcu_read_delay, |
72e9bb54 PM |
316 | .readunlock = rcu_torture_read_unlock, |
317 | .completed = rcu_torture_completed, | |
318 | .deferredfree = rcu_torture_deferred_free, | |
b772e1dd | 319 | .sync = synchronize_rcu, |
2326974d | 320 | .cb_barrier = rcu_barrier, |
72e9bb54 | 321 | .stats = NULL, |
0729fbf3 | 322 | .irqcapable = 1, |
72e9bb54 PM |
323 | .name = "rcu" |
324 | }; | |
325 | ||
e3033736 JT |
326 | static void rcu_sync_torture_deferred_free(struct rcu_torture *p) |
327 | { | |
328 | int i; | |
329 | struct rcu_torture *rp; | |
330 | struct rcu_torture *rp1; | |
331 | ||
332 | cur_ops->sync(); | |
333 | list_add(&p->rtort_free, &rcu_torture_removed); | |
334 | list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) { | |
335 | i = rp->rtort_pipe_count; | |
336 | if (i > RCU_TORTURE_PIPE_LEN) | |
337 | i = RCU_TORTURE_PIPE_LEN; | |
338 | atomic_inc(&rcu_torture_wcount[i]); | |
339 | if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) { | |
340 | rp->rtort_mbtest = 0; | |
341 | list_del(&rp->rtort_free); | |
342 | rcu_torture_free(rp); | |
343 | } | |
344 | } | |
345 | } | |
346 | ||
347 | static void rcu_sync_torture_init(void) | |
348 | { | |
349 | INIT_LIST_HEAD(&rcu_torture_removed); | |
350 | } | |
351 | ||
20d2e428 JT |
352 | static struct rcu_torture_ops rcu_sync_ops = { |
353 | .init = rcu_sync_torture_init, | |
354 | .cleanup = NULL, | |
355 | .readlock = rcu_torture_read_lock, | |
356 | .readdelay = rcu_read_delay, | |
357 | .readunlock = rcu_torture_read_unlock, | |
358 | .completed = rcu_torture_completed, | |
359 | .deferredfree = rcu_sync_torture_deferred_free, | |
360 | .sync = synchronize_rcu, | |
2326974d | 361 | .cb_barrier = NULL, |
20d2e428 | 362 | .stats = NULL, |
0729fbf3 | 363 | .irqcapable = 1, |
20d2e428 JT |
364 | .name = "rcu_sync" |
365 | }; | |
366 | ||
c32e0660 PM |
367 | /* |
368 | * Definitions for rcu_bh torture testing. | |
369 | */ | |
370 | ||
a49a4af7 | 371 | static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH) |
c32e0660 PM |
372 | { |
373 | rcu_read_lock_bh(); | |
374 | return 0; | |
375 | } | |
376 | ||
a49a4af7 | 377 | static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH) |
c32e0660 PM |
378 | { |
379 | rcu_read_unlock_bh(); | |
380 | } | |
381 | ||
382 | static int rcu_bh_torture_completed(void) | |
383 | { | |
384 | return rcu_batches_completed_bh(); | |
385 | } | |
386 | ||
387 | static void rcu_bh_torture_deferred_free(struct rcu_torture *p) | |
388 | { | |
389 | call_rcu_bh(&p->rtort_rcu, rcu_torture_cb); | |
390 | } | |
391 | ||
b772e1dd JT |
392 | struct rcu_bh_torture_synchronize { |
393 | struct rcu_head head; | |
394 | struct completion completion; | |
395 | }; | |
396 | ||
397 | static void rcu_bh_torture_wakeme_after_cb(struct rcu_head *head) | |
398 | { | |
399 | struct rcu_bh_torture_synchronize *rcu; | |
400 | ||
401 | rcu = container_of(head, struct rcu_bh_torture_synchronize, head); | |
402 | complete(&rcu->completion); | |
403 | } | |
404 | ||
405 | static void rcu_bh_torture_synchronize(void) | |
406 | { | |
407 | struct rcu_bh_torture_synchronize rcu; | |
408 | ||
409 | init_completion(&rcu.completion); | |
410 | call_rcu_bh(&rcu.head, rcu_bh_torture_wakeme_after_cb); | |
411 | wait_for_completion(&rcu.completion); | |
412 | } | |
413 | ||
c32e0660 PM |
414 | static struct rcu_torture_ops rcu_bh_ops = { |
415 | .init = NULL, | |
416 | .cleanup = NULL, | |
417 | .readlock = rcu_bh_torture_read_lock, | |
b2896d2e | 418 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ |
c32e0660 PM |
419 | .readunlock = rcu_bh_torture_read_unlock, |
420 | .completed = rcu_bh_torture_completed, | |
421 | .deferredfree = rcu_bh_torture_deferred_free, | |
b772e1dd | 422 | .sync = rcu_bh_torture_synchronize, |
2326974d | 423 | .cb_barrier = rcu_barrier_bh, |
c32e0660 | 424 | .stats = NULL, |
0729fbf3 | 425 | .irqcapable = 1, |
c32e0660 PM |
426 | .name = "rcu_bh" |
427 | }; | |
428 | ||
11a14701 JT |
429 | static struct rcu_torture_ops rcu_bh_sync_ops = { |
430 | .init = rcu_sync_torture_init, | |
431 | .cleanup = NULL, | |
432 | .readlock = rcu_bh_torture_read_lock, | |
433 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ | |
434 | .readunlock = rcu_bh_torture_read_unlock, | |
435 | .completed = rcu_bh_torture_completed, | |
436 | .deferredfree = rcu_sync_torture_deferred_free, | |
437 | .sync = rcu_bh_torture_synchronize, | |
2326974d | 438 | .cb_barrier = NULL, |
11a14701 | 439 | .stats = NULL, |
0729fbf3 | 440 | .irqcapable = 1, |
11a14701 JT |
441 | .name = "rcu_bh_sync" |
442 | }; | |
443 | ||
b2896d2e PM |
444 | /* |
445 | * Definitions for srcu torture testing. | |
446 | */ | |
447 | ||
448 | static struct srcu_struct srcu_ctl; | |
b2896d2e PM |
449 | |
450 | static void srcu_torture_init(void) | |
451 | { | |
452 | init_srcu_struct(&srcu_ctl); | |
e3033736 | 453 | rcu_sync_torture_init(); |
b2896d2e PM |
454 | } |
455 | ||
456 | static void srcu_torture_cleanup(void) | |
457 | { | |
458 | synchronize_srcu(&srcu_ctl); | |
459 | cleanup_srcu_struct(&srcu_ctl); | |
460 | } | |
461 | ||
012d3ca8 | 462 | static int srcu_torture_read_lock(void) __acquires(&srcu_ctl) |
b2896d2e PM |
463 | { |
464 | return srcu_read_lock(&srcu_ctl); | |
465 | } | |
466 | ||
467 | static void srcu_read_delay(struct rcu_random_state *rrsp) | |
468 | { | |
469 | long delay; | |
470 | const long uspertick = 1000000 / HZ; | |
471 | const long longdelay = 10; | |
472 | ||
473 | /* We want there to be long-running readers, but not all the time. */ | |
474 | ||
475 | delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick); | |
476 | if (!delay) | |
477 | schedule_timeout_interruptible(longdelay); | |
478 | } | |
479 | ||
012d3ca8 | 480 | static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl) |
b2896d2e PM |
481 | { |
482 | srcu_read_unlock(&srcu_ctl, idx); | |
483 | } | |
484 | ||
485 | static int srcu_torture_completed(void) | |
486 | { | |
487 | return srcu_batches_completed(&srcu_ctl); | |
488 | } | |
489 | ||
b772e1dd JT |
490 | static void srcu_torture_synchronize(void) |
491 | { | |
492 | synchronize_srcu(&srcu_ctl); | |
493 | } | |
494 | ||
b2896d2e PM |
495 | static int srcu_torture_stats(char *page) |
496 | { | |
497 | int cnt = 0; | |
498 | int cpu; | |
499 | int idx = srcu_ctl.completed & 0x1; | |
500 | ||
501 | cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):", | |
502 | torture_type, TORTURE_FLAG, idx); | |
503 | for_each_possible_cpu(cpu) { | |
504 | cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu, | |
505 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx], | |
506 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]); | |
507 | } | |
508 | cnt += sprintf(&page[cnt], "\n"); | |
509 | return cnt; | |
510 | } | |
511 | ||
512 | static struct rcu_torture_ops srcu_ops = { | |
513 | .init = srcu_torture_init, | |
514 | .cleanup = srcu_torture_cleanup, | |
515 | .readlock = srcu_torture_read_lock, | |
516 | .readdelay = srcu_read_delay, | |
517 | .readunlock = srcu_torture_read_unlock, | |
518 | .completed = srcu_torture_completed, | |
e3033736 | 519 | .deferredfree = rcu_sync_torture_deferred_free, |
b772e1dd | 520 | .sync = srcu_torture_synchronize, |
2326974d | 521 | .cb_barrier = NULL, |
b2896d2e PM |
522 | .stats = srcu_torture_stats, |
523 | .name = "srcu" | |
524 | }; | |
525 | ||
4b6c2cca JT |
526 | /* |
527 | * Definitions for sched torture testing. | |
528 | */ | |
529 | ||
530 | static int sched_torture_read_lock(void) | |
531 | { | |
532 | preempt_disable(); | |
533 | return 0; | |
534 | } | |
535 | ||
536 | static void sched_torture_read_unlock(int idx) | |
537 | { | |
538 | preempt_enable(); | |
539 | } | |
540 | ||
541 | static int sched_torture_completed(void) | |
542 | { | |
543 | return 0; | |
544 | } | |
545 | ||
2326974d PM |
546 | static void rcu_sched_torture_deferred_free(struct rcu_torture *p) |
547 | { | |
548 | call_rcu_sched(&p->rtort_rcu, rcu_torture_cb); | |
549 | } | |
550 | ||
4b6c2cca JT |
551 | static void sched_torture_synchronize(void) |
552 | { | |
553 | synchronize_sched(); | |
554 | } | |
555 | ||
556 | static struct rcu_torture_ops sched_ops = { | |
557 | .init = rcu_sync_torture_init, | |
558 | .cleanup = NULL, | |
559 | .readlock = sched_torture_read_lock, | |
560 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ | |
561 | .readunlock = sched_torture_read_unlock, | |
562 | .completed = sched_torture_completed, | |
2326974d | 563 | .deferredfree = rcu_sched_torture_deferred_free, |
4b6c2cca | 564 | .sync = sched_torture_synchronize, |
2326974d | 565 | .cb_barrier = rcu_barrier_sched, |
4b6c2cca | 566 | .stats = NULL, |
0729fbf3 | 567 | .irqcapable = 1, |
4b6c2cca JT |
568 | .name = "sched" |
569 | }; | |
570 | ||
2326974d PM |
571 | static struct rcu_torture_ops sched_ops_sync = { |
572 | .init = rcu_sync_torture_init, | |
573 | .cleanup = NULL, | |
574 | .readlock = sched_torture_read_lock, | |
575 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ | |
576 | .readunlock = sched_torture_read_unlock, | |
577 | .completed = sched_torture_completed, | |
578 | .deferredfree = rcu_sync_torture_deferred_free, | |
579 | .sync = sched_torture_synchronize, | |
580 | .cb_barrier = NULL, | |
581 | .stats = NULL, | |
582 | .name = "sched_sync" | |
583 | }; | |
584 | ||
a241ec65 PM |
585 | /* |
586 | * RCU torture writer kthread. Repeatedly substitutes a new structure | |
587 | * for that pointed to by rcu_torture_current, freeing the old structure | |
588 | * after a series of grace periods (the "pipeline"). | |
589 | */ | |
590 | static int | |
591 | rcu_torture_writer(void *arg) | |
592 | { | |
593 | int i; | |
594 | long oldbatch = rcu_batches_completed(); | |
595 | struct rcu_torture *rp; | |
596 | struct rcu_torture *old_rp; | |
597 | static DEFINE_RCU_RANDOM(rand); | |
598 | ||
599 | VERBOSE_PRINTK_STRING("rcu_torture_writer task started"); | |
dbdf65b1 IM |
600 | set_user_nice(current, 19); |
601 | ||
a241ec65 PM |
602 | do { |
603 | schedule_timeout_uninterruptible(1); | |
a241ec65 PM |
604 | if ((rp = rcu_torture_alloc()) == NULL) |
605 | continue; | |
606 | rp->rtort_pipe_count = 0; | |
607 | udelay(rcu_random(&rand) & 0x3ff); | |
608 | old_rp = rcu_torture_current; | |
996417d2 | 609 | rp->rtort_mbtest = 1; |
a241ec65 PM |
610 | rcu_assign_pointer(rcu_torture_current, rp); |
611 | smp_wmb(); | |
c8e5b163 | 612 | if (old_rp) { |
a241ec65 PM |
613 | i = old_rp->rtort_pipe_count; |
614 | if (i > RCU_TORTURE_PIPE_LEN) | |
615 | i = RCU_TORTURE_PIPE_LEN; | |
616 | atomic_inc(&rcu_torture_wcount[i]); | |
617 | old_rp->rtort_pipe_count++; | |
72e9bb54 | 618 | cur_ops->deferredfree(old_rp); |
a241ec65 PM |
619 | } |
620 | rcu_torture_current_version++; | |
72e9bb54 | 621 | oldbatch = cur_ops->completed(); |
d120f65f | 622 | rcu_stutter_wait(); |
a241ec65 PM |
623 | } while (!kthread_should_stop() && !fullstop); |
624 | VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping"); | |
c59ab97e | 625 | while (!kthread_should_stop() && fullstop != FULLSTOP_SHUTDOWN) |
a241ec65 PM |
626 | schedule_timeout_uninterruptible(1); |
627 | return 0; | |
628 | } | |
629 | ||
b772e1dd JT |
630 | /* |
631 | * RCU torture fake writer kthread. Repeatedly calls sync, with a random | |
632 | * delay between calls. | |
633 | */ | |
634 | static int | |
635 | rcu_torture_fakewriter(void *arg) | |
636 | { | |
637 | DEFINE_RCU_RANDOM(rand); | |
638 | ||
639 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started"); | |
640 | set_user_nice(current, 19); | |
641 | ||
642 | do { | |
643 | schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10); | |
644 | udelay(rcu_random(&rand) & 0x3ff); | |
645 | cur_ops->sync(); | |
d120f65f | 646 | rcu_stutter_wait(); |
b772e1dd JT |
647 | } while (!kthread_should_stop() && !fullstop); |
648 | ||
649 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping"); | |
c59ab97e | 650 | while (!kthread_should_stop() && fullstop != FULLSTOP_SHUTDOWN) |
b772e1dd JT |
651 | schedule_timeout_uninterruptible(1); |
652 | return 0; | |
653 | } | |
654 | ||
0729fbf3 PM |
655 | /* |
656 | * RCU torture reader from timer handler. Dereferences rcu_torture_current, | |
657 | * incrementing the corresponding element of the pipeline array. The | |
658 | * counter in the element should never be greater than 1, otherwise, the | |
659 | * RCU implementation is broken. | |
660 | */ | |
661 | static void rcu_torture_timer(unsigned long unused) | |
662 | { | |
663 | int idx; | |
664 | int completed; | |
665 | static DEFINE_RCU_RANDOM(rand); | |
666 | static DEFINE_SPINLOCK(rand_lock); | |
667 | struct rcu_torture *p; | |
668 | int pipe_count; | |
669 | ||
670 | idx = cur_ops->readlock(); | |
671 | completed = cur_ops->completed(); | |
672 | p = rcu_dereference(rcu_torture_current); | |
673 | if (p == NULL) { | |
674 | /* Leave because rcu_torture_writer is not yet underway */ | |
675 | cur_ops->readunlock(idx); | |
676 | return; | |
677 | } | |
678 | if (p->rtort_mbtest == 0) | |
679 | atomic_inc(&n_rcu_torture_mberror); | |
680 | spin_lock(&rand_lock); | |
681 | cur_ops->readdelay(&rand); | |
682 | n_rcu_torture_timers++; | |
683 | spin_unlock(&rand_lock); | |
684 | preempt_disable(); | |
685 | pipe_count = p->rtort_pipe_count; | |
686 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { | |
687 | /* Should not happen, but... */ | |
688 | pipe_count = RCU_TORTURE_PIPE_LEN; | |
689 | } | |
690 | ++__get_cpu_var(rcu_torture_count)[pipe_count]; | |
691 | completed = cur_ops->completed() - completed; | |
692 | if (completed > RCU_TORTURE_PIPE_LEN) { | |
693 | /* Should not happen, but... */ | |
694 | completed = RCU_TORTURE_PIPE_LEN; | |
695 | } | |
696 | ++__get_cpu_var(rcu_torture_batch)[completed]; | |
697 | preempt_enable(); | |
698 | cur_ops->readunlock(idx); | |
699 | } | |
700 | ||
a241ec65 PM |
701 | /* |
702 | * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current, | |
703 | * incrementing the corresponding element of the pipeline array. The | |
704 | * counter in the element should never be greater than 1, otherwise, the | |
705 | * RCU implementation is broken. | |
706 | */ | |
707 | static int | |
708 | rcu_torture_reader(void *arg) | |
709 | { | |
710 | int completed; | |
72e9bb54 | 711 | int idx; |
a241ec65 PM |
712 | DEFINE_RCU_RANDOM(rand); |
713 | struct rcu_torture *p; | |
714 | int pipe_count; | |
0729fbf3 | 715 | struct timer_list t; |
a241ec65 PM |
716 | |
717 | VERBOSE_PRINTK_STRING("rcu_torture_reader task started"); | |
dbdf65b1 | 718 | set_user_nice(current, 19); |
0729fbf3 PM |
719 | if (irqreader && cur_ops->irqcapable) |
720 | setup_timer_on_stack(&t, rcu_torture_timer, 0); | |
dbdf65b1 | 721 | |
a241ec65 | 722 | do { |
0729fbf3 PM |
723 | if (irqreader && cur_ops->irqcapable) { |
724 | if (!timer_pending(&t)) | |
725 | mod_timer(&t, 1); | |
726 | } | |
72e9bb54 PM |
727 | idx = cur_ops->readlock(); |
728 | completed = cur_ops->completed(); | |
a241ec65 PM |
729 | p = rcu_dereference(rcu_torture_current); |
730 | if (p == NULL) { | |
731 | /* Wait for rcu_torture_writer to get underway */ | |
72e9bb54 | 732 | cur_ops->readunlock(idx); |
a241ec65 PM |
733 | schedule_timeout_interruptible(HZ); |
734 | continue; | |
735 | } | |
996417d2 PM |
736 | if (p->rtort_mbtest == 0) |
737 | atomic_inc(&n_rcu_torture_mberror); | |
b2896d2e | 738 | cur_ops->readdelay(&rand); |
a241ec65 PM |
739 | preempt_disable(); |
740 | pipe_count = p->rtort_pipe_count; | |
741 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { | |
742 | /* Should not happen, but... */ | |
743 | pipe_count = RCU_TORTURE_PIPE_LEN; | |
744 | } | |
745 | ++__get_cpu_var(rcu_torture_count)[pipe_count]; | |
72e9bb54 | 746 | completed = cur_ops->completed() - completed; |
a241ec65 PM |
747 | if (completed > RCU_TORTURE_PIPE_LEN) { |
748 | /* Should not happen, but... */ | |
749 | completed = RCU_TORTURE_PIPE_LEN; | |
750 | } | |
751 | ++__get_cpu_var(rcu_torture_batch)[completed]; | |
752 | preempt_enable(); | |
72e9bb54 | 753 | cur_ops->readunlock(idx); |
a241ec65 | 754 | schedule(); |
d120f65f | 755 | rcu_stutter_wait(); |
a241ec65 PM |
756 | } while (!kthread_should_stop() && !fullstop); |
757 | VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping"); | |
0729fbf3 PM |
758 | if (irqreader && cur_ops->irqcapable) |
759 | del_timer_sync(&t); | |
c59ab97e | 760 | while (!kthread_should_stop() && fullstop != FULLSTOP_SHUTDOWN) |
a241ec65 PM |
761 | schedule_timeout_uninterruptible(1); |
762 | return 0; | |
763 | } | |
764 | ||
765 | /* | |
766 | * Create an RCU-torture statistics message in the specified buffer. | |
767 | */ | |
768 | static int | |
769 | rcu_torture_printk(char *page) | |
770 | { | |
771 | int cnt = 0; | |
772 | int cpu; | |
773 | int i; | |
774 | long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; | |
775 | long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; | |
776 | ||
0a945022 | 777 | for_each_possible_cpu(cpu) { |
a241ec65 PM |
778 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
779 | pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i]; | |
780 | batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i]; | |
781 | } | |
782 | } | |
783 | for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) { | |
784 | if (pipesummary[i] != 0) | |
785 | break; | |
786 | } | |
72e9bb54 | 787 | cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG); |
a241ec65 | 788 | cnt += sprintf(&page[cnt], |
996417d2 | 789 | "rtc: %p ver: %ld tfle: %d rta: %d rtaf: %d rtf: %d " |
0729fbf3 | 790 | "rtmbe: %d nt: %ld", |
a241ec65 PM |
791 | rcu_torture_current, |
792 | rcu_torture_current_version, | |
793 | list_empty(&rcu_torture_freelist), | |
794 | atomic_read(&n_rcu_torture_alloc), | |
795 | atomic_read(&n_rcu_torture_alloc_fail), | |
996417d2 | 796 | atomic_read(&n_rcu_torture_free), |
0729fbf3 PM |
797 | atomic_read(&n_rcu_torture_mberror), |
798 | n_rcu_torture_timers); | |
996417d2 PM |
799 | if (atomic_read(&n_rcu_torture_mberror) != 0) |
800 | cnt += sprintf(&page[cnt], " !!!"); | |
72e9bb54 | 801 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
996417d2 | 802 | if (i > 1) { |
a241ec65 | 803 | cnt += sprintf(&page[cnt], "!!! "); |
996417d2 | 804 | atomic_inc(&n_rcu_torture_error); |
5af970a4 | 805 | WARN_ON_ONCE(1); |
996417d2 | 806 | } |
a241ec65 PM |
807 | cnt += sprintf(&page[cnt], "Reader Pipe: "); |
808 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) | |
809 | cnt += sprintf(&page[cnt], " %ld", pipesummary[i]); | |
72e9bb54 | 810 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
a241ec65 | 811 | cnt += sprintf(&page[cnt], "Reader Batch: "); |
72e9bb54 | 812 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
a241ec65 | 813 | cnt += sprintf(&page[cnt], " %ld", batchsummary[i]); |
72e9bb54 | 814 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
a241ec65 PM |
815 | cnt += sprintf(&page[cnt], "Free-Block Circulation: "); |
816 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { | |
817 | cnt += sprintf(&page[cnt], " %d", | |
818 | atomic_read(&rcu_torture_wcount[i])); | |
819 | } | |
820 | cnt += sprintf(&page[cnt], "\n"); | |
c8e5b163 | 821 | if (cur_ops->stats) |
72e9bb54 | 822 | cnt += cur_ops->stats(&page[cnt]); |
a241ec65 PM |
823 | return cnt; |
824 | } | |
825 | ||
826 | /* | |
827 | * Print torture statistics. Caller must ensure that there is only | |
828 | * one call to this function at a given time!!! This is normally | |
829 | * accomplished by relying on the module system to only have one copy | |
830 | * of the module loaded, and then by giving the rcu_torture_stats | |
831 | * kthread full control (or the init/cleanup functions when rcu_torture_stats | |
832 | * thread is not running). | |
833 | */ | |
834 | static void | |
835 | rcu_torture_stats_print(void) | |
836 | { | |
837 | int cnt; | |
838 | ||
839 | cnt = rcu_torture_printk(printk_buf); | |
840 | printk(KERN_ALERT "%s", printk_buf); | |
841 | } | |
842 | ||
843 | /* | |
844 | * Periodically prints torture statistics, if periodic statistics printing | |
845 | * was specified via the stat_interval module parameter. | |
846 | * | |
847 | * No need to worry about fullstop here, since this one doesn't reference | |
848 | * volatile state or register callbacks. | |
849 | */ | |
850 | static int | |
851 | rcu_torture_stats(void *arg) | |
852 | { | |
853 | VERBOSE_PRINTK_STRING("rcu_torture_stats task started"); | |
854 | do { | |
855 | schedule_timeout_interruptible(stat_interval * HZ); | |
856 | rcu_torture_stats_print(); | |
343e9099 | 857 | } while (!kthread_should_stop() && !fullstop); |
a241ec65 PM |
858 | VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping"); |
859 | return 0; | |
860 | } | |
861 | ||
d84f5203 SV |
862 | static int rcu_idle_cpu; /* Force all torture tasks off this CPU */ |
863 | ||
864 | /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case | |
865 | * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs. | |
866 | */ | |
b2896d2e | 867 | static void rcu_torture_shuffle_tasks(void) |
d84f5203 | 868 | { |
bd232f97 | 869 | cpumask_var_t tmp_mask; |
d84f5203 SV |
870 | int i; |
871 | ||
bd232f97 RR |
872 | if (!alloc_cpumask_var(&tmp_mask, GFP_KERNEL)) |
873 | BUG(); | |
874 | ||
875 | cpumask_setall(tmp_mask); | |
86ef5c9a | 876 | get_online_cpus(); |
d84f5203 SV |
877 | |
878 | /* No point in shuffling if there is only one online CPU (ex: UP) */ | |
bd232f97 RR |
879 | if (num_online_cpus() == 1) |
880 | goto out; | |
d84f5203 SV |
881 | |
882 | if (rcu_idle_cpu != -1) | |
bd232f97 | 883 | cpumask_clear_cpu(rcu_idle_cpu, tmp_mask); |
d84f5203 | 884 | |
bd232f97 | 885 | set_cpus_allowed_ptr(current, tmp_mask); |
d84f5203 | 886 | |
c8e5b163 | 887 | if (reader_tasks) { |
d84f5203 SV |
888 | for (i = 0; i < nrealreaders; i++) |
889 | if (reader_tasks[i]) | |
f70316da | 890 | set_cpus_allowed_ptr(reader_tasks[i], |
bd232f97 | 891 | tmp_mask); |
d84f5203 SV |
892 | } |
893 | ||
c8e5b163 | 894 | if (fakewriter_tasks) { |
b772e1dd JT |
895 | for (i = 0; i < nfakewriters; i++) |
896 | if (fakewriter_tasks[i]) | |
f70316da | 897 | set_cpus_allowed_ptr(fakewriter_tasks[i], |
bd232f97 | 898 | tmp_mask); |
b772e1dd JT |
899 | } |
900 | ||
d84f5203 | 901 | if (writer_task) |
bd232f97 | 902 | set_cpus_allowed_ptr(writer_task, tmp_mask); |
d84f5203 SV |
903 | |
904 | if (stats_task) | |
bd232f97 | 905 | set_cpus_allowed_ptr(stats_task, tmp_mask); |
d84f5203 SV |
906 | |
907 | if (rcu_idle_cpu == -1) | |
908 | rcu_idle_cpu = num_online_cpus() - 1; | |
909 | else | |
910 | rcu_idle_cpu--; | |
911 | ||
bd232f97 | 912 | out: |
86ef5c9a | 913 | put_online_cpus(); |
bd232f97 | 914 | free_cpumask_var(tmp_mask); |
d84f5203 SV |
915 | } |
916 | ||
917 | /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the | |
918 | * system to become idle at a time and cut off its timer ticks. This is meant | |
919 | * to test the support for such tickless idle CPU in RCU. | |
920 | */ | |
921 | static int | |
922 | rcu_torture_shuffle(void *arg) | |
923 | { | |
924 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started"); | |
925 | do { | |
926 | schedule_timeout_interruptible(shuffle_interval * HZ); | |
927 | rcu_torture_shuffle_tasks(); | |
343e9099 | 928 | } while (!kthread_should_stop() && !fullstop); |
d84f5203 SV |
929 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping"); |
930 | return 0; | |
931 | } | |
932 | ||
d120f65f PM |
933 | /* Cause the rcutorture test to "stutter", starting and stopping all |
934 | * threads periodically. | |
935 | */ | |
936 | static int | |
937 | rcu_torture_stutter(void *arg) | |
938 | { | |
939 | VERBOSE_PRINTK_STRING("rcu_torture_stutter task started"); | |
940 | do { | |
941 | schedule_timeout_interruptible(stutter * HZ); | |
942 | stutter_pause_test = 1; | |
343e9099 | 943 | if (!kthread_should_stop() && !fullstop) |
d120f65f PM |
944 | schedule_timeout_interruptible(stutter * HZ); |
945 | stutter_pause_test = 0; | |
343e9099 | 946 | } while (!kthread_should_stop() && !fullstop); |
d120f65f PM |
947 | VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping"); |
948 | return 0; | |
949 | } | |
950 | ||
95c38322 PM |
951 | static inline void |
952 | rcu_torture_print_module_parms(char *tag) | |
953 | { | |
b772e1dd JT |
954 | printk(KERN_ALERT "%s" TORTURE_FLAG |
955 | "--- %s: nreaders=%d nfakewriters=%d " | |
95c38322 | 956 | "stat_interval=%d verbose=%d test_no_idle_hz=%d " |
0729fbf3 | 957 | "shuffle_interval=%d stutter=%d irqreader=%d\n", |
b772e1dd | 958 | torture_type, tag, nrealreaders, nfakewriters, |
d120f65f | 959 | stat_interval, verbose, test_no_idle_hz, shuffle_interval, |
0729fbf3 | 960 | stutter, irqreader); |
95c38322 PM |
961 | } |
962 | ||
343e9099 PM |
963 | static struct notifier_block rcutorture_nb = { |
964 | .notifier_call = rcutorture_shutdown_notify, | |
965 | }; | |
966 | ||
a241ec65 PM |
967 | static void |
968 | rcu_torture_cleanup(void) | |
969 | { | |
970 | int i; | |
971 | ||
343e9099 PM |
972 | mutex_lock(&fullstop_mutex); |
973 | if (!fullstop) { | |
974 | /* If being signaled, let it happen, then exit. */ | |
975 | mutex_unlock(&fullstop_mutex); | |
976 | schedule_timeout_interruptible(10 * HZ); | |
977 | if (cur_ops->cb_barrier != NULL) | |
978 | cur_ops->cb_barrier(); | |
979 | return; | |
980 | } | |
981 | fullstop = FULLSTOP_CLEANUP; | |
982 | mutex_unlock(&fullstop_mutex); | |
983 | unregister_reboot_notifier(&rcutorture_nb); | |
d120f65f PM |
984 | if (stutter_task) { |
985 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task"); | |
986 | kthread_stop(stutter_task); | |
987 | } | |
988 | stutter_task = NULL; | |
c8e5b163 | 989 | if (shuffler_task) { |
d84f5203 SV |
990 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task"); |
991 | kthread_stop(shuffler_task); | |
992 | } | |
993 | shuffler_task = NULL; | |
994 | ||
c8e5b163 | 995 | if (writer_task) { |
a241ec65 PM |
996 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task"); |
997 | kthread_stop(writer_task); | |
998 | } | |
999 | writer_task = NULL; | |
1000 | ||
c8e5b163 | 1001 | if (reader_tasks) { |
a241ec65 | 1002 | for (i = 0; i < nrealreaders; i++) { |
c8e5b163 | 1003 | if (reader_tasks[i]) { |
a241ec65 PM |
1004 | VERBOSE_PRINTK_STRING( |
1005 | "Stopping rcu_torture_reader task"); | |
1006 | kthread_stop(reader_tasks[i]); | |
1007 | } | |
1008 | reader_tasks[i] = NULL; | |
1009 | } | |
1010 | kfree(reader_tasks); | |
1011 | reader_tasks = NULL; | |
1012 | } | |
1013 | rcu_torture_current = NULL; | |
1014 | ||
c8e5b163 | 1015 | if (fakewriter_tasks) { |
b772e1dd | 1016 | for (i = 0; i < nfakewriters; i++) { |
c8e5b163 | 1017 | if (fakewriter_tasks[i]) { |
b772e1dd JT |
1018 | VERBOSE_PRINTK_STRING( |
1019 | "Stopping rcu_torture_fakewriter task"); | |
1020 | kthread_stop(fakewriter_tasks[i]); | |
1021 | } | |
1022 | fakewriter_tasks[i] = NULL; | |
1023 | } | |
1024 | kfree(fakewriter_tasks); | |
1025 | fakewriter_tasks = NULL; | |
1026 | } | |
1027 | ||
c8e5b163 | 1028 | if (stats_task) { |
a241ec65 PM |
1029 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task"); |
1030 | kthread_stop(stats_task); | |
1031 | } | |
1032 | stats_task = NULL; | |
1033 | ||
1034 | /* Wait for all RCU callbacks to fire. */ | |
2326974d PM |
1035 | |
1036 | if (cur_ops->cb_barrier != NULL) | |
1037 | cur_ops->cb_barrier(); | |
a241ec65 | 1038 | |
a241ec65 | 1039 | rcu_torture_stats_print(); /* -After- the stats thread is stopped! */ |
72e9bb54 | 1040 | |
c8e5b163 | 1041 | if (cur_ops->cleanup) |
72e9bb54 | 1042 | cur_ops->cleanup(); |
95c38322 PM |
1043 | if (atomic_read(&n_rcu_torture_error)) |
1044 | rcu_torture_print_module_parms("End of test: FAILURE"); | |
1045 | else | |
1046 | rcu_torture_print_module_parms("End of test: SUCCESS"); | |
a241ec65 PM |
1047 | } |
1048 | ||
6f8bc500 | 1049 | static int __init |
a241ec65 PM |
1050 | rcu_torture_init(void) |
1051 | { | |
1052 | int i; | |
1053 | int cpu; | |
1054 | int firsterr = 0; | |
ade5fb81 JT |
1055 | static struct rcu_torture_ops *torture_ops[] = |
1056 | { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops, | |
2326974d | 1057 | &srcu_ops, &sched_ops, &sched_ops_sync, }; |
a241ec65 | 1058 | |
343e9099 PM |
1059 | mutex_lock(&fullstop_mutex); |
1060 | ||
a241ec65 | 1061 | /* Process args and tell the world that the torturer is on the job. */ |
ade5fb81 | 1062 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) { |
72e9bb54 | 1063 | cur_ops = torture_ops[i]; |
ade5fb81 | 1064 | if (strcmp(torture_type, cur_ops->name) == 0) |
72e9bb54 | 1065 | break; |
72e9bb54 | 1066 | } |
ade5fb81 | 1067 | if (i == ARRAY_SIZE(torture_ops)) { |
72e9bb54 PM |
1068 | printk(KERN_ALERT "rcutorture: invalid torture type: \"%s\"\n", |
1069 | torture_type); | |
343e9099 | 1070 | mutex_unlock(&fullstop_mutex); |
72e9bb54 PM |
1071 | return (-EINVAL); |
1072 | } | |
c8e5b163 | 1073 | if (cur_ops->init) |
72e9bb54 PM |
1074 | cur_ops->init(); /* no "goto unwind" prior to this point!!! */ |
1075 | ||
a241ec65 PM |
1076 | if (nreaders >= 0) |
1077 | nrealreaders = nreaders; | |
1078 | else | |
1079 | nrealreaders = 2 * num_online_cpus(); | |
95c38322 | 1080 | rcu_torture_print_module_parms("Start of test"); |
a241ec65 PM |
1081 | fullstop = 0; |
1082 | ||
1083 | /* Set up the freelist. */ | |
1084 | ||
1085 | INIT_LIST_HEAD(&rcu_torture_freelist); | |
788e770e | 1086 | for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) { |
996417d2 | 1087 | rcu_tortures[i].rtort_mbtest = 0; |
a241ec65 PM |
1088 | list_add_tail(&rcu_tortures[i].rtort_free, |
1089 | &rcu_torture_freelist); | |
1090 | } | |
1091 | ||
1092 | /* Initialize the statistics so that each run gets its own numbers. */ | |
1093 | ||
1094 | rcu_torture_current = NULL; | |
1095 | rcu_torture_current_version = 0; | |
1096 | atomic_set(&n_rcu_torture_alloc, 0); | |
1097 | atomic_set(&n_rcu_torture_alloc_fail, 0); | |
1098 | atomic_set(&n_rcu_torture_free, 0); | |
996417d2 PM |
1099 | atomic_set(&n_rcu_torture_mberror, 0); |
1100 | atomic_set(&n_rcu_torture_error, 0); | |
a241ec65 PM |
1101 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
1102 | atomic_set(&rcu_torture_wcount[i], 0); | |
0a945022 | 1103 | for_each_possible_cpu(cpu) { |
a241ec65 PM |
1104 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
1105 | per_cpu(rcu_torture_count, cpu)[i] = 0; | |
1106 | per_cpu(rcu_torture_batch, cpu)[i] = 0; | |
1107 | } | |
1108 | } | |
1109 | ||
1110 | /* Start up the kthreads. */ | |
1111 | ||
1112 | VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task"); | |
1113 | writer_task = kthread_run(rcu_torture_writer, NULL, | |
1114 | "rcu_torture_writer"); | |
1115 | if (IS_ERR(writer_task)) { | |
1116 | firsterr = PTR_ERR(writer_task); | |
1117 | VERBOSE_PRINTK_ERRSTRING("Failed to create writer"); | |
1118 | writer_task = NULL; | |
1119 | goto unwind; | |
1120 | } | |
b772e1dd JT |
1121 | fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]), |
1122 | GFP_KERNEL); | |
1123 | if (fakewriter_tasks == NULL) { | |
1124 | VERBOSE_PRINTK_ERRSTRING("out of memory"); | |
1125 | firsterr = -ENOMEM; | |
1126 | goto unwind; | |
1127 | } | |
1128 | for (i = 0; i < nfakewriters; i++) { | |
1129 | VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task"); | |
1130 | fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL, | |
1131 | "rcu_torture_fakewriter"); | |
1132 | if (IS_ERR(fakewriter_tasks[i])) { | |
1133 | firsterr = PTR_ERR(fakewriter_tasks[i]); | |
1134 | VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter"); | |
1135 | fakewriter_tasks[i] = NULL; | |
1136 | goto unwind; | |
1137 | } | |
1138 | } | |
2860aaba | 1139 | reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]), |
a241ec65 PM |
1140 | GFP_KERNEL); |
1141 | if (reader_tasks == NULL) { | |
1142 | VERBOSE_PRINTK_ERRSTRING("out of memory"); | |
1143 | firsterr = -ENOMEM; | |
1144 | goto unwind; | |
1145 | } | |
1146 | for (i = 0; i < nrealreaders; i++) { | |
1147 | VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task"); | |
1148 | reader_tasks[i] = kthread_run(rcu_torture_reader, NULL, | |
1149 | "rcu_torture_reader"); | |
1150 | if (IS_ERR(reader_tasks[i])) { | |
1151 | firsterr = PTR_ERR(reader_tasks[i]); | |
1152 | VERBOSE_PRINTK_ERRSTRING("Failed to create reader"); | |
1153 | reader_tasks[i] = NULL; | |
1154 | goto unwind; | |
1155 | } | |
1156 | } | |
1157 | if (stat_interval > 0) { | |
1158 | VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task"); | |
1159 | stats_task = kthread_run(rcu_torture_stats, NULL, | |
1160 | "rcu_torture_stats"); | |
1161 | if (IS_ERR(stats_task)) { | |
1162 | firsterr = PTR_ERR(stats_task); | |
1163 | VERBOSE_PRINTK_ERRSTRING("Failed to create stats"); | |
1164 | stats_task = NULL; | |
1165 | goto unwind; | |
1166 | } | |
1167 | } | |
d84f5203 SV |
1168 | if (test_no_idle_hz) { |
1169 | rcu_idle_cpu = num_online_cpus() - 1; | |
1170 | /* Create the shuffler thread */ | |
1171 | shuffler_task = kthread_run(rcu_torture_shuffle, NULL, | |
1172 | "rcu_torture_shuffle"); | |
1173 | if (IS_ERR(shuffler_task)) { | |
1174 | firsterr = PTR_ERR(shuffler_task); | |
1175 | VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler"); | |
1176 | shuffler_task = NULL; | |
1177 | goto unwind; | |
1178 | } | |
1179 | } | |
d120f65f PM |
1180 | if (stutter < 0) |
1181 | stutter = 0; | |
1182 | if (stutter) { | |
1183 | /* Create the stutter thread */ | |
1184 | stutter_task = kthread_run(rcu_torture_stutter, NULL, | |
1185 | "rcu_torture_stutter"); | |
1186 | if (IS_ERR(stutter_task)) { | |
1187 | firsterr = PTR_ERR(stutter_task); | |
1188 | VERBOSE_PRINTK_ERRSTRING("Failed to create stutter"); | |
1189 | stutter_task = NULL; | |
1190 | goto unwind; | |
1191 | } | |
1192 | } | |
343e9099 PM |
1193 | register_reboot_notifier(&rcutorture_nb); |
1194 | mutex_unlock(&fullstop_mutex); | |
a241ec65 PM |
1195 | return 0; |
1196 | ||
1197 | unwind: | |
343e9099 | 1198 | mutex_unlock(&fullstop_mutex); |
a241ec65 PM |
1199 | rcu_torture_cleanup(); |
1200 | return firsterr; | |
1201 | } | |
1202 | ||
1203 | module_init(rcu_torture_init); | |
1204 | module_exit(rcu_torture_cleanup); |