]>
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 <[email protected]> | |
a71fca58 | 21 | * Josh Triplett <[email protected]> |
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 | 52 | MODULE_AUTHOR("Paul E. McKenney <[email protected]> and " |
a71fca58 | 53 | "Josh Triplett <[email protected]>"); |
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). */ |
bf66f18e PM |
64 | static int fqs_duration = 0; /* Duration of bursts (us), 0 to disable. */ |
65 | static int fqs_holdoff = 0; /* Hold time within burst (us). */ | |
66 | static int fqs_stutter = 3; /* Wait time between bursts (s). */ | |
8e8be45e PM |
67 | static int test_boost = 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */ |
68 | static int test_boost_interval = 7; /* Interval between boost tests, seconds. */ | |
69 | static int test_boost_duration = 4; /* Duration of each boost test, seconds. */ | |
20d2e428 | 70 | static char *torture_type = "rcu"; /* What RCU implementation to torture. */ |
a241ec65 | 71 | |
d6ad6711 | 72 | module_param(nreaders, int, 0444); |
a241ec65 | 73 | MODULE_PARM_DESC(nreaders, "Number of RCU reader threads"); |
d6ad6711 | 74 | module_param(nfakewriters, int, 0444); |
b772e1dd | 75 | MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads"); |
d6ad6711 | 76 | module_param(stat_interval, int, 0444); |
a241ec65 | 77 | MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s"); |
d6ad6711 | 78 | module_param(verbose, bool, 0444); |
a241ec65 | 79 | MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s"); |
d6ad6711 | 80 | module_param(test_no_idle_hz, bool, 0444); |
d84f5203 | 81 | MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs"); |
d6ad6711 | 82 | module_param(shuffle_interval, int, 0444); |
d84f5203 | 83 | MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles"); |
d120f65f PM |
84 | module_param(stutter, int, 0444); |
85 | MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test"); | |
0729fbf3 PM |
86 | module_param(irqreader, int, 0444); |
87 | MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers"); | |
bf66f18e PM |
88 | module_param(fqs_duration, int, 0444); |
89 | MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us)"); | |
90 | module_param(fqs_holdoff, int, 0444); | |
91 | MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)"); | |
92 | module_param(fqs_stutter, int, 0444); | |
93 | MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)"); | |
8e8be45e PM |
94 | module_param(test_boost, int, 0444); |
95 | MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes."); | |
96 | module_param(test_boost_interval, int, 0444); | |
97 | MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds."); | |
98 | module_param(test_boost_duration, int, 0444); | |
99 | MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds."); | |
d6ad6711 | 100 | module_param(torture_type, charp, 0444); |
b2896d2e | 101 | MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)"); |
72e9bb54 PM |
102 | |
103 | #define TORTURE_FLAG "-torture:" | |
a241ec65 | 104 | #define PRINTK_STRING(s) \ |
72e9bb54 | 105 | do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0) |
a241ec65 | 106 | #define VERBOSE_PRINTK_STRING(s) \ |
72e9bb54 | 107 | do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0) |
a241ec65 | 108 | #define VERBOSE_PRINTK_ERRSTRING(s) \ |
72e9bb54 | 109 | do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0) |
a241ec65 PM |
110 | |
111 | static char printk_buf[4096]; | |
112 | ||
113 | static int nrealreaders; | |
114 | static struct task_struct *writer_task; | |
b772e1dd | 115 | static struct task_struct **fakewriter_tasks; |
a241ec65 PM |
116 | static struct task_struct **reader_tasks; |
117 | static struct task_struct *stats_task; | |
d84f5203 | 118 | static struct task_struct *shuffler_task; |
d120f65f | 119 | static struct task_struct *stutter_task; |
bf66f18e | 120 | static struct task_struct *fqs_task; |
8e8be45e | 121 | static struct task_struct *boost_tasks[NR_CPUS]; |
a241ec65 PM |
122 | |
123 | #define RCU_TORTURE_PIPE_LEN 10 | |
124 | ||
125 | struct rcu_torture { | |
126 | struct rcu_head rtort_rcu; | |
127 | int rtort_pipe_count; | |
128 | struct list_head rtort_free; | |
996417d2 | 129 | int rtort_mbtest; |
a241ec65 PM |
130 | }; |
131 | ||
a241ec65 | 132 | static LIST_HEAD(rcu_torture_freelist); |
0ddea0ea | 133 | static struct rcu_torture __rcu *rcu_torture_current; |
a71fca58 | 134 | static long rcu_torture_current_version; |
a241ec65 PM |
135 | static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN]; |
136 | static DEFINE_SPINLOCK(rcu_torture_lock); | |
137 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) = | |
138 | { 0 }; | |
139 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) = | |
140 | { 0 }; | |
141 | static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1]; | |
b2896d2e PM |
142 | static atomic_t n_rcu_torture_alloc; |
143 | static atomic_t n_rcu_torture_alloc_fail; | |
144 | static atomic_t n_rcu_torture_free; | |
145 | static atomic_t n_rcu_torture_mberror; | |
146 | static atomic_t n_rcu_torture_error; | |
8e8be45e PM |
147 | static long n_rcu_torture_boost_ktrerror; |
148 | static long n_rcu_torture_boost_rterror; | |
8e8be45e PM |
149 | static long n_rcu_torture_boost_failure; |
150 | static long n_rcu_torture_boosts; | |
a71fca58 | 151 | static long n_rcu_torture_timers; |
e3033736 | 152 | static struct list_head rcu_torture_removed; |
73d0a4b1 | 153 | static cpumask_var_t shuffle_tmp_mask; |
a241ec65 | 154 | |
a71fca58 | 155 | static int stutter_pause_test; |
d120f65f | 156 | |
31a72bce PM |
157 | #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE) |
158 | #define RCUTORTURE_RUNNABLE_INIT 1 | |
159 | #else | |
160 | #define RCUTORTURE_RUNNABLE_INIT 0 | |
161 | #endif | |
162 | int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT; | |
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 PM |
169 | |
170 | static unsigned long boost_starttime; /* jiffies of next boost test start. */ | |
171 | DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */ | |
172 | /* and boost task create/destroy. */ | |
173 | ||
c9d557c1 PM |
174 | /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */ |
175 | ||
176 | #define FULLSTOP_DONTSTOP 0 /* Normal operation. */ | |
177 | #define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */ | |
178 | #define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */ | |
179 | static int fullstop = FULLSTOP_RMMOD; | |
0ddea0ea PM |
180 | /* |
181 | * Protect fullstop transitions and spawning of kthreads. | |
182 | */ | |
183 | static DEFINE_MUTEX(fullstop_mutex); | |
343e9099 PM |
184 | |
185 | /* | |
c9d557c1 | 186 | * Detect and respond to a system shutdown. |
343e9099 PM |
187 | */ |
188 | static int | |
189 | rcutorture_shutdown_notify(struct notifier_block *unused1, | |
190 | unsigned long unused2, void *unused3) | |
191 | { | |
c59ab97e | 192 | mutex_lock(&fullstop_mutex); |
c9d557c1 | 193 | if (fullstop == FULLSTOP_DONTSTOP) |
c59ab97e | 194 | fullstop = FULLSTOP_SHUTDOWN; |
c9d557c1 PM |
195 | else |
196 | printk(KERN_WARNING /* but going down anyway, so... */ | |
197 | "Concurrent 'rmmod rcutorture' and shutdown illegal!\n"); | |
c59ab97e | 198 | mutex_unlock(&fullstop_mutex); |
343e9099 PM |
199 | return NOTIFY_DONE; |
200 | } | |
201 | ||
c9d557c1 PM |
202 | /* |
203 | * Absorb kthreads into a kernel function that won't return, so that | |
204 | * they won't ever access module text or data again. | |
205 | */ | |
206 | static void rcutorture_shutdown_absorb(char *title) | |
207 | { | |
208 | if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) { | |
209 | printk(KERN_NOTICE | |
210 | "rcutorture thread %s parking due to system shutdown\n", | |
211 | title); | |
212 | schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT); | |
213 | } | |
214 | } | |
215 | ||
a241ec65 PM |
216 | /* |
217 | * Allocate an element from the rcu_tortures pool. | |
218 | */ | |
97a41e26 | 219 | static struct rcu_torture * |
a241ec65 PM |
220 | rcu_torture_alloc(void) |
221 | { | |
222 | struct list_head *p; | |
223 | ||
adac1665 | 224 | spin_lock_bh(&rcu_torture_lock); |
a241ec65 PM |
225 | if (list_empty(&rcu_torture_freelist)) { |
226 | atomic_inc(&n_rcu_torture_alloc_fail); | |
adac1665 | 227 | spin_unlock_bh(&rcu_torture_lock); |
a241ec65 PM |
228 | return NULL; |
229 | } | |
230 | atomic_inc(&n_rcu_torture_alloc); | |
231 | p = rcu_torture_freelist.next; | |
232 | list_del_init(p); | |
adac1665 | 233 | spin_unlock_bh(&rcu_torture_lock); |
a241ec65 PM |
234 | return container_of(p, struct rcu_torture, rtort_free); |
235 | } | |
236 | ||
237 | /* | |
238 | * Free an element to the rcu_tortures pool. | |
239 | */ | |
240 | static void | |
241 | rcu_torture_free(struct rcu_torture *p) | |
242 | { | |
243 | atomic_inc(&n_rcu_torture_free); | |
adac1665 | 244 | spin_lock_bh(&rcu_torture_lock); |
a241ec65 | 245 | list_add_tail(&p->rtort_free, &rcu_torture_freelist); |
adac1665 | 246 | spin_unlock_bh(&rcu_torture_lock); |
a241ec65 PM |
247 | } |
248 | ||
a241ec65 PM |
249 | struct rcu_random_state { |
250 | unsigned long rrs_state; | |
75cfef32 | 251 | long rrs_count; |
a241ec65 PM |
252 | }; |
253 | ||
254 | #define RCU_RANDOM_MULT 39916801 /* prime */ | |
255 | #define RCU_RANDOM_ADD 479001701 /* prime */ | |
256 | #define RCU_RANDOM_REFRESH 10000 | |
257 | ||
258 | #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 } | |
259 | ||
260 | /* | |
261 | * Crude but fast random-number generator. Uses a linear congruential | |
c17ac855 | 262 | * generator, with occasional help from cpu_clock(). |
a241ec65 | 263 | */ |
75cfef32 | 264 | static unsigned long |
a241ec65 PM |
265 | rcu_random(struct rcu_random_state *rrsp) |
266 | { | |
a241ec65 | 267 | if (--rrsp->rrs_count < 0) { |
c676329a | 268 | rrsp->rrs_state += (unsigned long)local_clock(); |
a241ec65 PM |
269 | rrsp->rrs_count = RCU_RANDOM_REFRESH; |
270 | } | |
271 | rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD; | |
272 | return swahw32(rrsp->rrs_state); | |
273 | } | |
274 | ||
d120f65f | 275 | static void |
c9d557c1 | 276 | rcu_stutter_wait(char *title) |
d120f65f | 277 | { |
c9d557c1 | 278 | while (stutter_pause_test || !rcutorture_runnable) { |
e3d7be27 PM |
279 | if (rcutorture_runnable) |
280 | schedule_timeout_interruptible(1); | |
281 | else | |
3ccf79f4 | 282 | schedule_timeout_interruptible(round_jiffies_relative(HZ)); |
c9d557c1 | 283 | rcutorture_shutdown_absorb(title); |
343e9099 | 284 | } |
d120f65f PM |
285 | } |
286 | ||
72e9bb54 PM |
287 | /* |
288 | * Operations vector for selecting different types of tests. | |
289 | */ | |
290 | ||
291 | struct rcu_torture_ops { | |
292 | void (*init)(void); | |
293 | void (*cleanup)(void); | |
294 | int (*readlock)(void); | |
0acc512c | 295 | void (*read_delay)(struct rcu_random_state *rrsp); |
72e9bb54 PM |
296 | void (*readunlock)(int idx); |
297 | int (*completed)(void); | |
0acc512c | 298 | void (*deferred_free)(struct rcu_torture *p); |
b772e1dd | 299 | void (*sync)(void); |
2326974d | 300 | void (*cb_barrier)(void); |
bf66f18e | 301 | void (*fqs)(void); |
72e9bb54 | 302 | int (*stats)(char *page); |
0acc512c | 303 | int irq_capable; |
8e8be45e | 304 | int can_boost; |
72e9bb54 PM |
305 | char *name; |
306 | }; | |
a71fca58 PM |
307 | |
308 | static struct rcu_torture_ops *cur_ops; | |
72e9bb54 PM |
309 | |
310 | /* | |
311 | * Definitions for rcu torture testing. | |
312 | */ | |
313 | ||
a49a4af7 | 314 | static int rcu_torture_read_lock(void) __acquires(RCU) |
72e9bb54 PM |
315 | { |
316 | rcu_read_lock(); | |
317 | return 0; | |
318 | } | |
319 | ||
b2896d2e PM |
320 | static void rcu_read_delay(struct rcu_random_state *rrsp) |
321 | { | |
b8d57a76 JT |
322 | const unsigned long shortdelay_us = 200; |
323 | const unsigned long longdelay_ms = 50; | |
b2896d2e | 324 | |
b8d57a76 JT |
325 | /* We want a short delay sometimes to make a reader delay the grace |
326 | * period, and we want a long delay occasionally to trigger | |
327 | * force_quiescent_state. */ | |
b2896d2e | 328 | |
b8d57a76 JT |
329 | if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms))) |
330 | mdelay(longdelay_ms); | |
331 | if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us))) | |
332 | udelay(shortdelay_us); | |
e546f485 LJ |
333 | #ifdef CONFIG_PREEMPT |
334 | if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000))) | |
335 | preempt_schedule(); /* No QS if preempt_disable() in effect */ | |
336 | #endif | |
b2896d2e PM |
337 | } |
338 | ||
a49a4af7 | 339 | static void rcu_torture_read_unlock(int idx) __releases(RCU) |
72e9bb54 PM |
340 | { |
341 | rcu_read_unlock(); | |
342 | } | |
343 | ||
344 | static int rcu_torture_completed(void) | |
345 | { | |
346 | return rcu_batches_completed(); | |
347 | } | |
348 | ||
349 | static void | |
350 | rcu_torture_cb(struct rcu_head *p) | |
351 | { | |
352 | int i; | |
353 | struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu); | |
354 | ||
c9d557c1 | 355 | if (fullstop != FULLSTOP_DONTSTOP) { |
72e9bb54 PM |
356 | /* Test is ending, just drop callbacks on the floor. */ |
357 | /* The next initialization will pick up the pieces. */ | |
358 | return; | |
359 | } | |
360 | i = rp->rtort_pipe_count; | |
361 | if (i > RCU_TORTURE_PIPE_LEN) | |
362 | i = RCU_TORTURE_PIPE_LEN; | |
363 | atomic_inc(&rcu_torture_wcount[i]); | |
364 | if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) { | |
365 | rp->rtort_mbtest = 0; | |
366 | rcu_torture_free(rp); | |
367 | } else | |
0acc512c | 368 | cur_ops->deferred_free(rp); |
72e9bb54 PM |
369 | } |
370 | ||
d9a3da06 PM |
371 | static int rcu_no_completed(void) |
372 | { | |
373 | return 0; | |
374 | } | |
375 | ||
72e9bb54 PM |
376 | static void rcu_torture_deferred_free(struct rcu_torture *p) |
377 | { | |
378 | call_rcu(&p->rtort_rcu, rcu_torture_cb); | |
379 | } | |
380 | ||
381 | static struct rcu_torture_ops rcu_ops = { | |
0acc512c PM |
382 | .init = NULL, |
383 | .cleanup = NULL, | |
384 | .readlock = rcu_torture_read_lock, | |
385 | .read_delay = rcu_read_delay, | |
386 | .readunlock = rcu_torture_read_unlock, | |
387 | .completed = rcu_torture_completed, | |
388 | .deferred_free = rcu_torture_deferred_free, | |
389 | .sync = synchronize_rcu, | |
390 | .cb_barrier = rcu_barrier, | |
bf66f18e | 391 | .fqs = rcu_force_quiescent_state, |
0acc512c | 392 | .stats = NULL, |
a71fca58 | 393 | .irq_capable = 1, |
8e8be45e | 394 | .can_boost = rcu_can_boost(), |
a71fca58 | 395 | .name = "rcu" |
72e9bb54 PM |
396 | }; |
397 | ||
e3033736 JT |
398 | static void rcu_sync_torture_deferred_free(struct rcu_torture *p) |
399 | { | |
400 | int i; | |
401 | struct rcu_torture *rp; | |
402 | struct rcu_torture *rp1; | |
403 | ||
404 | cur_ops->sync(); | |
405 | list_add(&p->rtort_free, &rcu_torture_removed); | |
406 | list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) { | |
407 | i = rp->rtort_pipe_count; | |
408 | if (i > RCU_TORTURE_PIPE_LEN) | |
409 | i = RCU_TORTURE_PIPE_LEN; | |
410 | atomic_inc(&rcu_torture_wcount[i]); | |
411 | if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) { | |
412 | rp->rtort_mbtest = 0; | |
413 | list_del(&rp->rtort_free); | |
414 | rcu_torture_free(rp); | |
415 | } | |
416 | } | |
417 | } | |
418 | ||
419 | static void rcu_sync_torture_init(void) | |
420 | { | |
421 | INIT_LIST_HEAD(&rcu_torture_removed); | |
422 | } | |
423 | ||
20d2e428 | 424 | static struct rcu_torture_ops rcu_sync_ops = { |
0acc512c PM |
425 | .init = rcu_sync_torture_init, |
426 | .cleanup = NULL, | |
427 | .readlock = rcu_torture_read_lock, | |
428 | .read_delay = rcu_read_delay, | |
429 | .readunlock = rcu_torture_read_unlock, | |
430 | .completed = rcu_torture_completed, | |
431 | .deferred_free = rcu_sync_torture_deferred_free, | |
432 | .sync = synchronize_rcu, | |
433 | .cb_barrier = NULL, | |
bf66f18e | 434 | .fqs = rcu_force_quiescent_state, |
0acc512c PM |
435 | .stats = NULL, |
436 | .irq_capable = 1, | |
8e8be45e | 437 | .can_boost = rcu_can_boost(), |
0acc512c | 438 | .name = "rcu_sync" |
20d2e428 JT |
439 | }; |
440 | ||
d9a3da06 PM |
441 | static struct rcu_torture_ops rcu_expedited_ops = { |
442 | .init = rcu_sync_torture_init, | |
443 | .cleanup = NULL, | |
444 | .readlock = rcu_torture_read_lock, | |
445 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
446 | .readunlock = rcu_torture_read_unlock, | |
447 | .completed = rcu_no_completed, | |
448 | .deferred_free = rcu_sync_torture_deferred_free, | |
449 | .sync = synchronize_rcu_expedited, | |
450 | .cb_barrier = NULL, | |
bf66f18e | 451 | .fqs = rcu_force_quiescent_state, |
d9a3da06 PM |
452 | .stats = NULL, |
453 | .irq_capable = 1, | |
8e8be45e | 454 | .can_boost = rcu_can_boost(), |
d9a3da06 PM |
455 | .name = "rcu_expedited" |
456 | }; | |
457 | ||
c32e0660 PM |
458 | /* |
459 | * Definitions for rcu_bh torture testing. | |
460 | */ | |
461 | ||
a49a4af7 | 462 | static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH) |
c32e0660 PM |
463 | { |
464 | rcu_read_lock_bh(); | |
465 | return 0; | |
466 | } | |
467 | ||
a49a4af7 | 468 | static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH) |
c32e0660 PM |
469 | { |
470 | rcu_read_unlock_bh(); | |
471 | } | |
472 | ||
473 | static int rcu_bh_torture_completed(void) | |
474 | { | |
475 | return rcu_batches_completed_bh(); | |
476 | } | |
477 | ||
478 | static void rcu_bh_torture_deferred_free(struct rcu_torture *p) | |
479 | { | |
480 | call_rcu_bh(&p->rtort_rcu, rcu_torture_cb); | |
481 | } | |
482 | ||
b772e1dd JT |
483 | struct rcu_bh_torture_synchronize { |
484 | struct rcu_head head; | |
485 | struct completion completion; | |
486 | }; | |
487 | ||
488 | static void rcu_bh_torture_wakeme_after_cb(struct rcu_head *head) | |
489 | { | |
490 | struct rcu_bh_torture_synchronize *rcu; | |
491 | ||
492 | rcu = container_of(head, struct rcu_bh_torture_synchronize, head); | |
493 | complete(&rcu->completion); | |
494 | } | |
495 | ||
496 | static void rcu_bh_torture_synchronize(void) | |
497 | { | |
498 | struct rcu_bh_torture_synchronize rcu; | |
499 | ||
72d5a9f7 | 500 | init_rcu_head_on_stack(&rcu.head); |
b772e1dd JT |
501 | init_completion(&rcu.completion); |
502 | call_rcu_bh(&rcu.head, rcu_bh_torture_wakeme_after_cb); | |
503 | wait_for_completion(&rcu.completion); | |
72d5a9f7 | 504 | destroy_rcu_head_on_stack(&rcu.head); |
b772e1dd JT |
505 | } |
506 | ||
c32e0660 | 507 | static struct rcu_torture_ops rcu_bh_ops = { |
0acc512c PM |
508 | .init = NULL, |
509 | .cleanup = NULL, | |
510 | .readlock = rcu_bh_torture_read_lock, | |
511 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
512 | .readunlock = rcu_bh_torture_read_unlock, | |
513 | .completed = rcu_bh_torture_completed, | |
514 | .deferred_free = rcu_bh_torture_deferred_free, | |
515 | .sync = rcu_bh_torture_synchronize, | |
516 | .cb_barrier = rcu_barrier_bh, | |
bf66f18e | 517 | .fqs = rcu_bh_force_quiescent_state, |
0acc512c PM |
518 | .stats = NULL, |
519 | .irq_capable = 1, | |
520 | .name = "rcu_bh" | |
c32e0660 PM |
521 | }; |
522 | ||
11a14701 | 523 | static struct rcu_torture_ops rcu_bh_sync_ops = { |
0acc512c PM |
524 | .init = rcu_sync_torture_init, |
525 | .cleanup = NULL, | |
526 | .readlock = rcu_bh_torture_read_lock, | |
527 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
528 | .readunlock = rcu_bh_torture_read_unlock, | |
529 | .completed = rcu_bh_torture_completed, | |
530 | .deferred_free = rcu_sync_torture_deferred_free, | |
531 | .sync = rcu_bh_torture_synchronize, | |
532 | .cb_barrier = NULL, | |
bf66f18e | 533 | .fqs = rcu_bh_force_quiescent_state, |
0acc512c PM |
534 | .stats = NULL, |
535 | .irq_capable = 1, | |
536 | .name = "rcu_bh_sync" | |
11a14701 JT |
537 | }; |
538 | ||
b2896d2e PM |
539 | /* |
540 | * Definitions for srcu torture testing. | |
541 | */ | |
542 | ||
543 | static struct srcu_struct srcu_ctl; | |
b2896d2e PM |
544 | |
545 | static void srcu_torture_init(void) | |
546 | { | |
547 | init_srcu_struct(&srcu_ctl); | |
e3033736 | 548 | rcu_sync_torture_init(); |
b2896d2e PM |
549 | } |
550 | ||
551 | static void srcu_torture_cleanup(void) | |
552 | { | |
553 | synchronize_srcu(&srcu_ctl); | |
554 | cleanup_srcu_struct(&srcu_ctl); | |
555 | } | |
556 | ||
012d3ca8 | 557 | static int srcu_torture_read_lock(void) __acquires(&srcu_ctl) |
b2896d2e PM |
558 | { |
559 | return srcu_read_lock(&srcu_ctl); | |
560 | } | |
561 | ||
562 | static void srcu_read_delay(struct rcu_random_state *rrsp) | |
563 | { | |
564 | long delay; | |
565 | const long uspertick = 1000000 / HZ; | |
566 | const long longdelay = 10; | |
567 | ||
568 | /* We want there to be long-running readers, but not all the time. */ | |
569 | ||
570 | delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick); | |
571 | if (!delay) | |
572 | schedule_timeout_interruptible(longdelay); | |
e546f485 LJ |
573 | else |
574 | rcu_read_delay(rrsp); | |
b2896d2e PM |
575 | } |
576 | ||
012d3ca8 | 577 | static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl) |
b2896d2e PM |
578 | { |
579 | srcu_read_unlock(&srcu_ctl, idx); | |
580 | } | |
581 | ||
582 | static int srcu_torture_completed(void) | |
583 | { | |
584 | return srcu_batches_completed(&srcu_ctl); | |
585 | } | |
586 | ||
b772e1dd JT |
587 | static void srcu_torture_synchronize(void) |
588 | { | |
589 | synchronize_srcu(&srcu_ctl); | |
590 | } | |
591 | ||
b2896d2e PM |
592 | static int srcu_torture_stats(char *page) |
593 | { | |
594 | int cnt = 0; | |
595 | int cpu; | |
596 | int idx = srcu_ctl.completed & 0x1; | |
597 | ||
598 | cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):", | |
599 | torture_type, TORTURE_FLAG, idx); | |
600 | for_each_possible_cpu(cpu) { | |
601 | cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu, | |
602 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx], | |
603 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]); | |
604 | } | |
605 | cnt += sprintf(&page[cnt], "\n"); | |
606 | return cnt; | |
607 | } | |
608 | ||
609 | static struct rcu_torture_ops srcu_ops = { | |
0acc512c PM |
610 | .init = srcu_torture_init, |
611 | .cleanup = srcu_torture_cleanup, | |
612 | .readlock = srcu_torture_read_lock, | |
613 | .read_delay = srcu_read_delay, | |
614 | .readunlock = srcu_torture_read_unlock, | |
615 | .completed = srcu_torture_completed, | |
616 | .deferred_free = rcu_sync_torture_deferred_free, | |
617 | .sync = srcu_torture_synchronize, | |
618 | .cb_barrier = NULL, | |
619 | .stats = srcu_torture_stats, | |
620 | .name = "srcu" | |
b2896d2e PM |
621 | }; |
622 | ||
804bb837 PM |
623 | static void srcu_torture_synchronize_expedited(void) |
624 | { | |
625 | synchronize_srcu_expedited(&srcu_ctl); | |
626 | } | |
627 | ||
628 | static struct rcu_torture_ops srcu_expedited_ops = { | |
629 | .init = srcu_torture_init, | |
630 | .cleanup = srcu_torture_cleanup, | |
631 | .readlock = srcu_torture_read_lock, | |
632 | .read_delay = srcu_read_delay, | |
633 | .readunlock = srcu_torture_read_unlock, | |
634 | .completed = srcu_torture_completed, | |
635 | .deferred_free = rcu_sync_torture_deferred_free, | |
636 | .sync = srcu_torture_synchronize_expedited, | |
637 | .cb_barrier = NULL, | |
638 | .stats = srcu_torture_stats, | |
639 | .name = "srcu_expedited" | |
640 | }; | |
641 | ||
4b6c2cca JT |
642 | /* |
643 | * Definitions for sched torture testing. | |
644 | */ | |
645 | ||
646 | static int sched_torture_read_lock(void) | |
647 | { | |
648 | preempt_disable(); | |
649 | return 0; | |
650 | } | |
651 | ||
652 | static void sched_torture_read_unlock(int idx) | |
653 | { | |
654 | preempt_enable(); | |
655 | } | |
656 | ||
2326974d PM |
657 | static void rcu_sched_torture_deferred_free(struct rcu_torture *p) |
658 | { | |
659 | call_rcu_sched(&p->rtort_rcu, rcu_torture_cb); | |
660 | } | |
661 | ||
4b6c2cca JT |
662 | static void sched_torture_synchronize(void) |
663 | { | |
664 | synchronize_sched(); | |
665 | } | |
666 | ||
667 | static struct rcu_torture_ops sched_ops = { | |
0acc512c PM |
668 | .init = rcu_sync_torture_init, |
669 | .cleanup = NULL, | |
670 | .readlock = sched_torture_read_lock, | |
671 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
672 | .readunlock = sched_torture_read_unlock, | |
d9a3da06 | 673 | .completed = rcu_no_completed, |
0acc512c PM |
674 | .deferred_free = rcu_sched_torture_deferred_free, |
675 | .sync = sched_torture_synchronize, | |
676 | .cb_barrier = rcu_barrier_sched, | |
bf66f18e | 677 | .fqs = rcu_sched_force_quiescent_state, |
0acc512c PM |
678 | .stats = NULL, |
679 | .irq_capable = 1, | |
680 | .name = "sched" | |
4b6c2cca JT |
681 | }; |
682 | ||
804bb837 | 683 | static struct rcu_torture_ops sched_sync_ops = { |
0acc512c PM |
684 | .init = rcu_sync_torture_init, |
685 | .cleanup = NULL, | |
686 | .readlock = sched_torture_read_lock, | |
687 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
688 | .readunlock = sched_torture_read_unlock, | |
d9a3da06 | 689 | .completed = rcu_no_completed, |
0acc512c PM |
690 | .deferred_free = rcu_sync_torture_deferred_free, |
691 | .sync = sched_torture_synchronize, | |
692 | .cb_barrier = NULL, | |
bf66f18e | 693 | .fqs = rcu_sched_force_quiescent_state, |
0acc512c PM |
694 | .stats = NULL, |
695 | .name = "sched_sync" | |
696 | }; | |
697 | ||
0acc512c PM |
698 | static struct rcu_torture_ops sched_expedited_ops = { |
699 | .init = rcu_sync_torture_init, | |
700 | .cleanup = NULL, | |
701 | .readlock = sched_torture_read_lock, | |
702 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
703 | .readunlock = sched_torture_read_unlock, | |
d9a3da06 | 704 | .completed = rcu_no_completed, |
0acc512c PM |
705 | .deferred_free = rcu_sync_torture_deferred_free, |
706 | .sync = synchronize_sched_expedited, | |
707 | .cb_barrier = NULL, | |
bf66f18e | 708 | .fqs = rcu_sched_force_quiescent_state, |
969c7921 | 709 | .stats = NULL, |
0acc512c PM |
710 | .irq_capable = 1, |
711 | .name = "sched_expedited" | |
2326974d PM |
712 | }; |
713 | ||
8e8be45e PM |
714 | /* |
715 | * RCU torture priority-boost testing. Runs one real-time thread per | |
716 | * CPU for moderate bursts, repeatedly registering RCU callbacks and | |
717 | * spinning waiting for them to be invoked. If a given callback takes | |
718 | * too long to be invoked, we assume that priority inversion has occurred. | |
719 | */ | |
720 | ||
721 | struct rcu_boost_inflight { | |
722 | struct rcu_head rcu; | |
723 | int inflight; | |
724 | }; | |
725 | ||
726 | static void rcu_torture_boost_cb(struct rcu_head *head) | |
727 | { | |
728 | struct rcu_boost_inflight *rbip = | |
729 | container_of(head, struct rcu_boost_inflight, rcu); | |
730 | ||
731 | smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */ | |
732 | rbip->inflight = 0; | |
733 | } | |
734 | ||
735 | static int rcu_torture_boost(void *arg) | |
736 | { | |
737 | unsigned long call_rcu_time; | |
738 | unsigned long endtime; | |
739 | unsigned long oldstarttime; | |
740 | struct rcu_boost_inflight rbi = { .inflight = 0 }; | |
741 | struct sched_param sp; | |
742 | ||
743 | VERBOSE_PRINTK_STRING("rcu_torture_boost started"); | |
744 | ||
745 | /* Set real-time priority. */ | |
746 | sp.sched_priority = 1; | |
747 | if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) { | |
748 | VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!"); | |
749 | n_rcu_torture_boost_rterror++; | |
750 | } | |
751 | ||
752 | /* Each pass through the following loop does one boost-test cycle. */ | |
753 | do { | |
754 | /* Wait for the next test interval. */ | |
755 | oldstarttime = boost_starttime; | |
756 | while (jiffies - oldstarttime > ULONG_MAX / 2) { | |
757 | schedule_timeout_uninterruptible(1); | |
758 | rcu_stutter_wait("rcu_torture_boost"); | |
759 | if (kthread_should_stop() || | |
760 | fullstop != FULLSTOP_DONTSTOP) | |
761 | goto checkwait; | |
762 | } | |
763 | ||
764 | /* Do one boost-test interval. */ | |
765 | endtime = oldstarttime + test_boost_duration * HZ; | |
766 | call_rcu_time = jiffies; | |
767 | while (jiffies - endtime > ULONG_MAX / 2) { | |
768 | /* If we don't have a callback in flight, post one. */ | |
769 | if (!rbi.inflight) { | |
770 | smp_mb(); /* RCU core before ->inflight = 1. */ | |
771 | rbi.inflight = 1; | |
772 | call_rcu(&rbi.rcu, rcu_torture_boost_cb); | |
773 | if (jiffies - call_rcu_time > | |
774 | test_boost_duration * HZ - HZ / 2) { | |
775 | VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed"); | |
776 | n_rcu_torture_boost_failure++; | |
777 | } | |
778 | call_rcu_time = jiffies; | |
779 | } | |
780 | cond_resched(); | |
781 | rcu_stutter_wait("rcu_torture_boost"); | |
782 | if (kthread_should_stop() || | |
783 | fullstop != FULLSTOP_DONTSTOP) | |
784 | goto checkwait; | |
785 | } | |
786 | ||
787 | /* | |
788 | * Set the start time of the next test interval. | |
789 | * Yes, this is vulnerable to long delays, but such | |
790 | * delays simply cause a false negative for the next | |
791 | * interval. Besides, we are running at RT priority, | |
792 | * so delays should be relatively rare. | |
793 | */ | |
794 | while (oldstarttime == boost_starttime) { | |
795 | if (mutex_trylock(&boost_mutex)) { | |
796 | boost_starttime = jiffies + | |
797 | test_boost_interval * HZ; | |
798 | n_rcu_torture_boosts++; | |
799 | mutex_unlock(&boost_mutex); | |
800 | break; | |
801 | } | |
802 | schedule_timeout_uninterruptible(1); | |
803 | } | |
804 | ||
805 | /* Go do the stutter. */ | |
806 | checkwait: rcu_stutter_wait("rcu_torture_boost"); | |
807 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
808 | ||
809 | /* Clean up and exit. */ | |
810 | VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping"); | |
811 | rcutorture_shutdown_absorb("rcu_torture_boost"); | |
812 | while (!kthread_should_stop() || rbi.inflight) | |
813 | schedule_timeout_uninterruptible(1); | |
814 | smp_mb(); /* order accesses to ->inflight before stack-frame death. */ | |
815 | return 0; | |
816 | } | |
817 | ||
bf66f18e PM |
818 | /* |
819 | * RCU torture force-quiescent-state kthread. Repeatedly induces | |
820 | * bursts of calls to force_quiescent_state(), increasing the probability | |
821 | * of occurrence of some important types of race conditions. | |
822 | */ | |
823 | static int | |
824 | rcu_torture_fqs(void *arg) | |
825 | { | |
826 | unsigned long fqs_resume_time; | |
827 | int fqs_burst_remaining; | |
828 | ||
829 | VERBOSE_PRINTK_STRING("rcu_torture_fqs task started"); | |
830 | do { | |
831 | fqs_resume_time = jiffies + fqs_stutter * HZ; | |
832 | while (jiffies - fqs_resume_time > LONG_MAX) { | |
833 | schedule_timeout_interruptible(1); | |
834 | } | |
835 | fqs_burst_remaining = fqs_duration; | |
836 | while (fqs_burst_remaining > 0) { | |
837 | cur_ops->fqs(); | |
838 | udelay(fqs_holdoff); | |
839 | fqs_burst_remaining -= fqs_holdoff; | |
840 | } | |
841 | rcu_stutter_wait("rcu_torture_fqs"); | |
842 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
843 | VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping"); | |
844 | rcutorture_shutdown_absorb("rcu_torture_fqs"); | |
845 | while (!kthread_should_stop()) | |
846 | schedule_timeout_uninterruptible(1); | |
847 | return 0; | |
848 | } | |
849 | ||
a241ec65 PM |
850 | /* |
851 | * RCU torture writer kthread. Repeatedly substitutes a new structure | |
852 | * for that pointed to by rcu_torture_current, freeing the old structure | |
853 | * after a series of grace periods (the "pipeline"). | |
854 | */ | |
855 | static int | |
856 | rcu_torture_writer(void *arg) | |
857 | { | |
858 | int i; | |
859 | long oldbatch = rcu_batches_completed(); | |
860 | struct rcu_torture *rp; | |
861 | struct rcu_torture *old_rp; | |
862 | static DEFINE_RCU_RANDOM(rand); | |
863 | ||
864 | VERBOSE_PRINTK_STRING("rcu_torture_writer task started"); | |
dbdf65b1 IM |
865 | set_user_nice(current, 19); |
866 | ||
a241ec65 PM |
867 | do { |
868 | schedule_timeout_uninterruptible(1); | |
a71fca58 PM |
869 | rp = rcu_torture_alloc(); |
870 | if (rp == NULL) | |
a241ec65 PM |
871 | continue; |
872 | rp->rtort_pipe_count = 0; | |
873 | udelay(rcu_random(&rand) & 0x3ff); | |
0ddea0ea PM |
874 | old_rp = rcu_dereference_check(rcu_torture_current, |
875 | current == writer_task); | |
996417d2 | 876 | rp->rtort_mbtest = 1; |
a241ec65 | 877 | rcu_assign_pointer(rcu_torture_current, rp); |
9b2619af | 878 | smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */ |
c8e5b163 | 879 | if (old_rp) { |
a241ec65 PM |
880 | i = old_rp->rtort_pipe_count; |
881 | if (i > RCU_TORTURE_PIPE_LEN) | |
882 | i = RCU_TORTURE_PIPE_LEN; | |
883 | atomic_inc(&rcu_torture_wcount[i]); | |
884 | old_rp->rtort_pipe_count++; | |
0acc512c | 885 | cur_ops->deferred_free(old_rp); |
a241ec65 PM |
886 | } |
887 | rcu_torture_current_version++; | |
72e9bb54 | 888 | oldbatch = cur_ops->completed(); |
c9d557c1 PM |
889 | rcu_stutter_wait("rcu_torture_writer"); |
890 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
a241ec65 | 891 | VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping"); |
c9d557c1 PM |
892 | rcutorture_shutdown_absorb("rcu_torture_writer"); |
893 | while (!kthread_should_stop()) | |
a241ec65 PM |
894 | schedule_timeout_uninterruptible(1); |
895 | return 0; | |
896 | } | |
897 | ||
b772e1dd JT |
898 | /* |
899 | * RCU torture fake writer kthread. Repeatedly calls sync, with a random | |
900 | * delay between calls. | |
901 | */ | |
902 | static int | |
903 | rcu_torture_fakewriter(void *arg) | |
904 | { | |
905 | DEFINE_RCU_RANDOM(rand); | |
906 | ||
907 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started"); | |
908 | set_user_nice(current, 19); | |
909 | ||
910 | do { | |
911 | schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10); | |
912 | udelay(rcu_random(&rand) & 0x3ff); | |
913 | cur_ops->sync(); | |
c9d557c1 PM |
914 | rcu_stutter_wait("rcu_torture_fakewriter"); |
915 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
b772e1dd JT |
916 | |
917 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping"); | |
c9d557c1 PM |
918 | rcutorture_shutdown_absorb("rcu_torture_fakewriter"); |
919 | while (!kthread_should_stop()) | |
b772e1dd JT |
920 | schedule_timeout_uninterruptible(1); |
921 | return 0; | |
922 | } | |
923 | ||
0729fbf3 PM |
924 | /* |
925 | * RCU torture reader from timer handler. Dereferences rcu_torture_current, | |
926 | * incrementing the corresponding element of the pipeline array. The | |
927 | * counter in the element should never be greater than 1, otherwise, the | |
928 | * RCU implementation is broken. | |
929 | */ | |
930 | static void rcu_torture_timer(unsigned long unused) | |
931 | { | |
932 | int idx; | |
933 | int completed; | |
934 | static DEFINE_RCU_RANDOM(rand); | |
935 | static DEFINE_SPINLOCK(rand_lock); | |
936 | struct rcu_torture *p; | |
937 | int pipe_count; | |
938 | ||
939 | idx = cur_ops->readlock(); | |
940 | completed = cur_ops->completed(); | |
632ee200 PM |
941 | p = rcu_dereference_check(rcu_torture_current, |
942 | rcu_read_lock_held() || | |
943 | rcu_read_lock_bh_held() || | |
944 | rcu_read_lock_sched_held() || | |
945 | srcu_read_lock_held(&srcu_ctl)); | |
0729fbf3 PM |
946 | if (p == NULL) { |
947 | /* Leave because rcu_torture_writer is not yet underway */ | |
948 | cur_ops->readunlock(idx); | |
949 | return; | |
950 | } | |
951 | if (p->rtort_mbtest == 0) | |
952 | atomic_inc(&n_rcu_torture_mberror); | |
953 | spin_lock(&rand_lock); | |
0acc512c | 954 | cur_ops->read_delay(&rand); |
0729fbf3 PM |
955 | n_rcu_torture_timers++; |
956 | spin_unlock(&rand_lock); | |
957 | preempt_disable(); | |
958 | pipe_count = p->rtort_pipe_count; | |
959 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { | |
960 | /* Should not happen, but... */ | |
961 | pipe_count = RCU_TORTURE_PIPE_LEN; | |
962 | } | |
dd17c8f7 | 963 | __this_cpu_inc(rcu_torture_count[pipe_count]); |
0729fbf3 PM |
964 | completed = cur_ops->completed() - completed; |
965 | if (completed > RCU_TORTURE_PIPE_LEN) { | |
966 | /* Should not happen, but... */ | |
967 | completed = RCU_TORTURE_PIPE_LEN; | |
968 | } | |
dd17c8f7 | 969 | __this_cpu_inc(rcu_torture_batch[completed]); |
0729fbf3 PM |
970 | preempt_enable(); |
971 | cur_ops->readunlock(idx); | |
972 | } | |
973 | ||
a241ec65 PM |
974 | /* |
975 | * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current, | |
976 | * incrementing the corresponding element of the pipeline array. The | |
977 | * counter in the element should never be greater than 1, otherwise, the | |
978 | * RCU implementation is broken. | |
979 | */ | |
980 | static int | |
981 | rcu_torture_reader(void *arg) | |
982 | { | |
983 | int completed; | |
72e9bb54 | 984 | int idx; |
a241ec65 PM |
985 | DEFINE_RCU_RANDOM(rand); |
986 | struct rcu_torture *p; | |
987 | int pipe_count; | |
0729fbf3 | 988 | struct timer_list t; |
a241ec65 PM |
989 | |
990 | VERBOSE_PRINTK_STRING("rcu_torture_reader task started"); | |
dbdf65b1 | 991 | set_user_nice(current, 19); |
0acc512c | 992 | if (irqreader && cur_ops->irq_capable) |
0729fbf3 | 993 | setup_timer_on_stack(&t, rcu_torture_timer, 0); |
dbdf65b1 | 994 | |
a241ec65 | 995 | do { |
0acc512c | 996 | if (irqreader && cur_ops->irq_capable) { |
0729fbf3 | 997 | if (!timer_pending(&t)) |
6155fec9 | 998 | mod_timer(&t, jiffies + 1); |
0729fbf3 | 999 | } |
72e9bb54 PM |
1000 | idx = cur_ops->readlock(); |
1001 | completed = cur_ops->completed(); | |
632ee200 PM |
1002 | p = rcu_dereference_check(rcu_torture_current, |
1003 | rcu_read_lock_held() || | |
1004 | rcu_read_lock_bh_held() || | |
1005 | rcu_read_lock_sched_held() || | |
1006 | srcu_read_lock_held(&srcu_ctl)); | |
a241ec65 PM |
1007 | if (p == NULL) { |
1008 | /* Wait for rcu_torture_writer to get underway */ | |
72e9bb54 | 1009 | cur_ops->readunlock(idx); |
a241ec65 PM |
1010 | schedule_timeout_interruptible(HZ); |
1011 | continue; | |
1012 | } | |
996417d2 PM |
1013 | if (p->rtort_mbtest == 0) |
1014 | atomic_inc(&n_rcu_torture_mberror); | |
0acc512c | 1015 | cur_ops->read_delay(&rand); |
a241ec65 PM |
1016 | preempt_disable(); |
1017 | pipe_count = p->rtort_pipe_count; | |
1018 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { | |
1019 | /* Should not happen, but... */ | |
1020 | pipe_count = RCU_TORTURE_PIPE_LEN; | |
1021 | } | |
dd17c8f7 | 1022 | __this_cpu_inc(rcu_torture_count[pipe_count]); |
72e9bb54 | 1023 | completed = cur_ops->completed() - completed; |
a241ec65 PM |
1024 | if (completed > RCU_TORTURE_PIPE_LEN) { |
1025 | /* Should not happen, but... */ | |
1026 | completed = RCU_TORTURE_PIPE_LEN; | |
1027 | } | |
dd17c8f7 | 1028 | __this_cpu_inc(rcu_torture_batch[completed]); |
a241ec65 | 1029 | preempt_enable(); |
72e9bb54 | 1030 | cur_ops->readunlock(idx); |
a241ec65 | 1031 | schedule(); |
c9d557c1 PM |
1032 | rcu_stutter_wait("rcu_torture_reader"); |
1033 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
a241ec65 | 1034 | VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping"); |
c9d557c1 | 1035 | rcutorture_shutdown_absorb("rcu_torture_reader"); |
0acc512c | 1036 | if (irqreader && cur_ops->irq_capable) |
0729fbf3 | 1037 | del_timer_sync(&t); |
c9d557c1 | 1038 | while (!kthread_should_stop()) |
a241ec65 PM |
1039 | schedule_timeout_uninterruptible(1); |
1040 | return 0; | |
1041 | } | |
1042 | ||
1043 | /* | |
1044 | * Create an RCU-torture statistics message in the specified buffer. | |
1045 | */ | |
1046 | static int | |
1047 | rcu_torture_printk(char *page) | |
1048 | { | |
1049 | int cnt = 0; | |
1050 | int cpu; | |
1051 | int i; | |
1052 | long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; | |
1053 | long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; | |
1054 | ||
0a945022 | 1055 | for_each_possible_cpu(cpu) { |
a241ec65 PM |
1056 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
1057 | pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i]; | |
1058 | batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i]; | |
1059 | } | |
1060 | } | |
1061 | for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) { | |
1062 | if (pipesummary[i] != 0) | |
1063 | break; | |
1064 | } | |
72e9bb54 | 1065 | cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG); |
a241ec65 | 1066 | cnt += sprintf(&page[cnt], |
996417d2 | 1067 | "rtc: %p ver: %ld tfle: %d rta: %d rtaf: %d rtf: %d " |
67b98dba | 1068 | "rtmbe: %d rtbke: %ld rtbre: %ld " |
8e8be45e | 1069 | "rtbf: %ld rtb: %ld nt: %ld", |
a241ec65 PM |
1070 | rcu_torture_current, |
1071 | rcu_torture_current_version, | |
1072 | list_empty(&rcu_torture_freelist), | |
1073 | atomic_read(&n_rcu_torture_alloc), | |
1074 | atomic_read(&n_rcu_torture_alloc_fail), | |
996417d2 | 1075 | atomic_read(&n_rcu_torture_free), |
0729fbf3 | 1076 | atomic_read(&n_rcu_torture_mberror), |
8e8be45e PM |
1077 | n_rcu_torture_boost_ktrerror, |
1078 | n_rcu_torture_boost_rterror, | |
8e8be45e PM |
1079 | n_rcu_torture_boost_failure, |
1080 | n_rcu_torture_boosts, | |
0729fbf3 | 1081 | n_rcu_torture_timers); |
8e8be45e PM |
1082 | if (atomic_read(&n_rcu_torture_mberror) != 0 || |
1083 | n_rcu_torture_boost_ktrerror != 0 || | |
1084 | n_rcu_torture_boost_rterror != 0 || | |
8e8be45e | 1085 | n_rcu_torture_boost_failure != 0) |
996417d2 | 1086 | cnt += sprintf(&page[cnt], " !!!"); |
72e9bb54 | 1087 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
996417d2 | 1088 | if (i > 1) { |
a241ec65 | 1089 | cnt += sprintf(&page[cnt], "!!! "); |
996417d2 | 1090 | atomic_inc(&n_rcu_torture_error); |
5af970a4 | 1091 | WARN_ON_ONCE(1); |
996417d2 | 1092 | } |
a241ec65 PM |
1093 | cnt += sprintf(&page[cnt], "Reader Pipe: "); |
1094 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) | |
1095 | cnt += sprintf(&page[cnt], " %ld", pipesummary[i]); | |
72e9bb54 | 1096 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
a241ec65 | 1097 | cnt += sprintf(&page[cnt], "Reader Batch: "); |
72e9bb54 | 1098 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
a241ec65 | 1099 | cnt += sprintf(&page[cnt], " %ld", batchsummary[i]); |
72e9bb54 | 1100 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
a241ec65 PM |
1101 | cnt += sprintf(&page[cnt], "Free-Block Circulation: "); |
1102 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { | |
1103 | cnt += sprintf(&page[cnt], " %d", | |
1104 | atomic_read(&rcu_torture_wcount[i])); | |
1105 | } | |
1106 | cnt += sprintf(&page[cnt], "\n"); | |
c8e5b163 | 1107 | if (cur_ops->stats) |
72e9bb54 | 1108 | cnt += cur_ops->stats(&page[cnt]); |
a241ec65 PM |
1109 | return cnt; |
1110 | } | |
1111 | ||
1112 | /* | |
1113 | * Print torture statistics. Caller must ensure that there is only | |
1114 | * one call to this function at a given time!!! This is normally | |
1115 | * accomplished by relying on the module system to only have one copy | |
1116 | * of the module loaded, and then by giving the rcu_torture_stats | |
1117 | * kthread full control (or the init/cleanup functions when rcu_torture_stats | |
1118 | * thread is not running). | |
1119 | */ | |
1120 | static void | |
1121 | rcu_torture_stats_print(void) | |
1122 | { | |
1123 | int cnt; | |
1124 | ||
1125 | cnt = rcu_torture_printk(printk_buf); | |
1126 | printk(KERN_ALERT "%s", printk_buf); | |
1127 | } | |
1128 | ||
1129 | /* | |
1130 | * Periodically prints torture statistics, if periodic statistics printing | |
1131 | * was specified via the stat_interval module parameter. | |
1132 | * | |
1133 | * No need to worry about fullstop here, since this one doesn't reference | |
1134 | * volatile state or register callbacks. | |
1135 | */ | |
1136 | static int | |
1137 | rcu_torture_stats(void *arg) | |
1138 | { | |
1139 | VERBOSE_PRINTK_STRING("rcu_torture_stats task started"); | |
1140 | do { | |
1141 | schedule_timeout_interruptible(stat_interval * HZ); | |
1142 | rcu_torture_stats_print(); | |
c9d557c1 PM |
1143 | rcutorture_shutdown_absorb("rcu_torture_stats"); |
1144 | } while (!kthread_should_stop()); | |
a241ec65 PM |
1145 | VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping"); |
1146 | return 0; | |
1147 | } | |
1148 | ||
d84f5203 SV |
1149 | static int rcu_idle_cpu; /* Force all torture tasks off this CPU */ |
1150 | ||
1151 | /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case | |
1152 | * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs. | |
1153 | */ | |
b2896d2e | 1154 | static void rcu_torture_shuffle_tasks(void) |
d84f5203 | 1155 | { |
d84f5203 SV |
1156 | int i; |
1157 | ||
73d0a4b1 | 1158 | cpumask_setall(shuffle_tmp_mask); |
86ef5c9a | 1159 | get_online_cpus(); |
d84f5203 SV |
1160 | |
1161 | /* No point in shuffling if there is only one online CPU (ex: UP) */ | |
c9d557c1 PM |
1162 | if (num_online_cpus() == 1) { |
1163 | put_online_cpus(); | |
1164 | return; | |
1165 | } | |
d84f5203 SV |
1166 | |
1167 | if (rcu_idle_cpu != -1) | |
73d0a4b1 | 1168 | cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask); |
d84f5203 | 1169 | |
73d0a4b1 | 1170 | set_cpus_allowed_ptr(current, shuffle_tmp_mask); |
d84f5203 | 1171 | |
c8e5b163 | 1172 | if (reader_tasks) { |
d84f5203 SV |
1173 | for (i = 0; i < nrealreaders; i++) |
1174 | if (reader_tasks[i]) | |
f70316da | 1175 | set_cpus_allowed_ptr(reader_tasks[i], |
73d0a4b1 | 1176 | shuffle_tmp_mask); |
d84f5203 SV |
1177 | } |
1178 | ||
c8e5b163 | 1179 | if (fakewriter_tasks) { |
b772e1dd JT |
1180 | for (i = 0; i < nfakewriters; i++) |
1181 | if (fakewriter_tasks[i]) | |
f70316da | 1182 | set_cpus_allowed_ptr(fakewriter_tasks[i], |
73d0a4b1 | 1183 | shuffle_tmp_mask); |
b772e1dd JT |
1184 | } |
1185 | ||
d84f5203 | 1186 | if (writer_task) |
73d0a4b1 | 1187 | set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask); |
d84f5203 SV |
1188 | |
1189 | if (stats_task) | |
73d0a4b1 | 1190 | set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask); |
d84f5203 SV |
1191 | |
1192 | if (rcu_idle_cpu == -1) | |
1193 | rcu_idle_cpu = num_online_cpus() - 1; | |
1194 | else | |
1195 | rcu_idle_cpu--; | |
1196 | ||
86ef5c9a | 1197 | put_online_cpus(); |
d84f5203 SV |
1198 | } |
1199 | ||
1200 | /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the | |
1201 | * system to become idle at a time and cut off its timer ticks. This is meant | |
1202 | * to test the support for such tickless idle CPU in RCU. | |
1203 | */ | |
1204 | static int | |
1205 | rcu_torture_shuffle(void *arg) | |
1206 | { | |
1207 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started"); | |
1208 | do { | |
1209 | schedule_timeout_interruptible(shuffle_interval * HZ); | |
1210 | rcu_torture_shuffle_tasks(); | |
c9d557c1 PM |
1211 | rcutorture_shutdown_absorb("rcu_torture_shuffle"); |
1212 | } while (!kthread_should_stop()); | |
d84f5203 SV |
1213 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping"); |
1214 | return 0; | |
1215 | } | |
1216 | ||
d120f65f PM |
1217 | /* Cause the rcutorture test to "stutter", starting and stopping all |
1218 | * threads periodically. | |
1219 | */ | |
1220 | static int | |
1221 | rcu_torture_stutter(void *arg) | |
1222 | { | |
1223 | VERBOSE_PRINTK_STRING("rcu_torture_stutter task started"); | |
1224 | do { | |
1225 | schedule_timeout_interruptible(stutter * HZ); | |
1226 | stutter_pause_test = 1; | |
c9d557c1 | 1227 | if (!kthread_should_stop()) |
d120f65f PM |
1228 | schedule_timeout_interruptible(stutter * HZ); |
1229 | stutter_pause_test = 0; | |
c9d557c1 PM |
1230 | rcutorture_shutdown_absorb("rcu_torture_stutter"); |
1231 | } while (!kthread_should_stop()); | |
d120f65f PM |
1232 | VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping"); |
1233 | return 0; | |
1234 | } | |
1235 | ||
95c38322 | 1236 | static inline void |
8e8be45e | 1237 | rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag) |
95c38322 | 1238 | { |
b772e1dd JT |
1239 | printk(KERN_ALERT "%s" TORTURE_FLAG |
1240 | "--- %s: nreaders=%d nfakewriters=%d " | |
95c38322 | 1241 | "stat_interval=%d verbose=%d test_no_idle_hz=%d " |
bf66f18e | 1242 | "shuffle_interval=%d stutter=%d irqreader=%d " |
8e8be45e PM |
1243 | "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d " |
1244 | "test_boost=%d/%d test_boost_interval=%d " | |
1245 | "test_boost_duration=%d\n", | |
b772e1dd | 1246 | torture_type, tag, nrealreaders, nfakewriters, |
d120f65f | 1247 | stat_interval, verbose, test_no_idle_hz, shuffle_interval, |
8e8be45e PM |
1248 | stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter, |
1249 | test_boost, cur_ops->can_boost, | |
1250 | test_boost_interval, test_boost_duration); | |
95c38322 PM |
1251 | } |
1252 | ||
8e8be45e | 1253 | static struct notifier_block rcutorture_shutdown_nb = { |
343e9099 PM |
1254 | .notifier_call = rcutorture_shutdown_notify, |
1255 | }; | |
1256 | ||
8e8be45e PM |
1257 | static void rcutorture_booster_cleanup(int cpu) |
1258 | { | |
1259 | struct task_struct *t; | |
1260 | ||
1261 | if (boost_tasks[cpu] == NULL) | |
1262 | return; | |
1263 | mutex_lock(&boost_mutex); | |
1264 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task"); | |
1265 | t = boost_tasks[cpu]; | |
1266 | boost_tasks[cpu] = NULL; | |
1267 | mutex_unlock(&boost_mutex); | |
1268 | ||
1269 | /* This must be outside of the mutex, otherwise deadlock! */ | |
1270 | kthread_stop(t); | |
1271 | } | |
1272 | ||
1273 | static int rcutorture_booster_init(int cpu) | |
1274 | { | |
1275 | int retval; | |
1276 | ||
1277 | if (boost_tasks[cpu] != NULL) | |
1278 | return 0; /* Already created, nothing more to do. */ | |
1279 | ||
1280 | /* Don't allow time recalculation while creating a new task. */ | |
1281 | mutex_lock(&boost_mutex); | |
1282 | VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task"); | |
1283 | boost_tasks[cpu] = kthread_create(rcu_torture_boost, NULL, | |
1284 | "rcu_torture_boost"); | |
1285 | if (IS_ERR(boost_tasks[cpu])) { | |
1286 | retval = PTR_ERR(boost_tasks[cpu]); | |
1287 | VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed"); | |
1288 | n_rcu_torture_boost_ktrerror++; | |
1289 | boost_tasks[cpu] = NULL; | |
1290 | mutex_unlock(&boost_mutex); | |
1291 | return retval; | |
1292 | } | |
1293 | kthread_bind(boost_tasks[cpu], cpu); | |
1294 | wake_up_process(boost_tasks[cpu]); | |
1295 | mutex_unlock(&boost_mutex); | |
1296 | return 0; | |
1297 | } | |
1298 | ||
1299 | static int rcutorture_cpu_notify(struct notifier_block *self, | |
1300 | unsigned long action, void *hcpu) | |
1301 | { | |
1302 | long cpu = (long)hcpu; | |
1303 | ||
1304 | switch (action) { | |
1305 | case CPU_ONLINE: | |
1306 | case CPU_DOWN_FAILED: | |
1307 | (void)rcutorture_booster_init(cpu); | |
1308 | break; | |
1309 | case CPU_DOWN_PREPARE: | |
1310 | rcutorture_booster_cleanup(cpu); | |
1311 | break; | |
1312 | default: | |
1313 | break; | |
1314 | } | |
1315 | return NOTIFY_OK; | |
1316 | } | |
1317 | ||
1318 | static struct notifier_block rcutorture_cpu_nb = { | |
1319 | .notifier_call = rcutorture_cpu_notify, | |
1320 | }; | |
1321 | ||
a241ec65 PM |
1322 | static void |
1323 | rcu_torture_cleanup(void) | |
1324 | { | |
1325 | int i; | |
1326 | ||
343e9099 | 1327 | mutex_lock(&fullstop_mutex); |
c9d557c1 PM |
1328 | if (fullstop == FULLSTOP_SHUTDOWN) { |
1329 | printk(KERN_WARNING /* but going down anyway, so... */ | |
1330 | "Concurrent 'rmmod rcutorture' and shutdown illegal!\n"); | |
343e9099 | 1331 | mutex_unlock(&fullstop_mutex); |
c9d557c1 | 1332 | schedule_timeout_uninterruptible(10); |
343e9099 PM |
1333 | if (cur_ops->cb_barrier != NULL) |
1334 | cur_ops->cb_barrier(); | |
1335 | return; | |
1336 | } | |
c9d557c1 | 1337 | fullstop = FULLSTOP_RMMOD; |
343e9099 | 1338 | mutex_unlock(&fullstop_mutex); |
8e8be45e | 1339 | unregister_reboot_notifier(&rcutorture_shutdown_nb); |
d120f65f PM |
1340 | if (stutter_task) { |
1341 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task"); | |
1342 | kthread_stop(stutter_task); | |
1343 | } | |
1344 | stutter_task = NULL; | |
c8e5b163 | 1345 | if (shuffler_task) { |
d84f5203 SV |
1346 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task"); |
1347 | kthread_stop(shuffler_task); | |
73d0a4b1 | 1348 | free_cpumask_var(shuffle_tmp_mask); |
d84f5203 SV |
1349 | } |
1350 | shuffler_task = NULL; | |
1351 | ||
c8e5b163 | 1352 | if (writer_task) { |
a241ec65 PM |
1353 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task"); |
1354 | kthread_stop(writer_task); | |
1355 | } | |
1356 | writer_task = NULL; | |
1357 | ||
c8e5b163 | 1358 | if (reader_tasks) { |
a241ec65 | 1359 | for (i = 0; i < nrealreaders; i++) { |
c8e5b163 | 1360 | if (reader_tasks[i]) { |
a241ec65 PM |
1361 | VERBOSE_PRINTK_STRING( |
1362 | "Stopping rcu_torture_reader task"); | |
1363 | kthread_stop(reader_tasks[i]); | |
1364 | } | |
1365 | reader_tasks[i] = NULL; | |
1366 | } | |
1367 | kfree(reader_tasks); | |
1368 | reader_tasks = NULL; | |
1369 | } | |
1370 | rcu_torture_current = NULL; | |
1371 | ||
c8e5b163 | 1372 | if (fakewriter_tasks) { |
b772e1dd | 1373 | for (i = 0; i < nfakewriters; i++) { |
c8e5b163 | 1374 | if (fakewriter_tasks[i]) { |
b772e1dd JT |
1375 | VERBOSE_PRINTK_STRING( |
1376 | "Stopping rcu_torture_fakewriter task"); | |
1377 | kthread_stop(fakewriter_tasks[i]); | |
1378 | } | |
1379 | fakewriter_tasks[i] = NULL; | |
1380 | } | |
1381 | kfree(fakewriter_tasks); | |
1382 | fakewriter_tasks = NULL; | |
1383 | } | |
1384 | ||
c8e5b163 | 1385 | if (stats_task) { |
a241ec65 PM |
1386 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task"); |
1387 | kthread_stop(stats_task); | |
1388 | } | |
1389 | stats_task = NULL; | |
1390 | ||
bf66f18e PM |
1391 | if (fqs_task) { |
1392 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task"); | |
1393 | kthread_stop(fqs_task); | |
1394 | } | |
1395 | fqs_task = NULL; | |
8e8be45e PM |
1396 | if ((test_boost == 1 && cur_ops->can_boost) || |
1397 | test_boost == 2) { | |
1398 | unregister_cpu_notifier(&rcutorture_cpu_nb); | |
1399 | for_each_possible_cpu(i) | |
1400 | rcutorture_booster_cleanup(i); | |
1401 | } | |
bf66f18e | 1402 | |
a241ec65 | 1403 | /* Wait for all RCU callbacks to fire. */ |
2326974d PM |
1404 | |
1405 | if (cur_ops->cb_barrier != NULL) | |
1406 | cur_ops->cb_barrier(); | |
a241ec65 | 1407 | |
a241ec65 | 1408 | rcu_torture_stats_print(); /* -After- the stats thread is stopped! */ |
72e9bb54 | 1409 | |
c8e5b163 | 1410 | if (cur_ops->cleanup) |
72e9bb54 | 1411 | cur_ops->cleanup(); |
95c38322 | 1412 | if (atomic_read(&n_rcu_torture_error)) |
8e8be45e | 1413 | rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE"); |
95c38322 | 1414 | else |
8e8be45e | 1415 | rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS"); |
a241ec65 PM |
1416 | } |
1417 | ||
6f8bc500 | 1418 | static int __init |
a241ec65 PM |
1419 | rcu_torture_init(void) |
1420 | { | |
1421 | int i; | |
1422 | int cpu; | |
1423 | int firsterr = 0; | |
ade5fb81 | 1424 | static struct rcu_torture_ops *torture_ops[] = |
d9a3da06 PM |
1425 | { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops, |
1426 | &rcu_bh_ops, &rcu_bh_sync_ops, | |
804bb837 PM |
1427 | &srcu_ops, &srcu_expedited_ops, |
1428 | &sched_ops, &sched_sync_ops, &sched_expedited_ops, }; | |
a241ec65 | 1429 | |
343e9099 PM |
1430 | mutex_lock(&fullstop_mutex); |
1431 | ||
a241ec65 | 1432 | /* Process args and tell the world that the torturer is on the job. */ |
ade5fb81 | 1433 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) { |
72e9bb54 | 1434 | cur_ops = torture_ops[i]; |
ade5fb81 | 1435 | if (strcmp(torture_type, cur_ops->name) == 0) |
72e9bb54 | 1436 | break; |
72e9bb54 | 1437 | } |
ade5fb81 | 1438 | if (i == ARRAY_SIZE(torture_ops)) { |
cf886c44 | 1439 | printk(KERN_ALERT "rcu-torture: invalid torture type: \"%s\"\n", |
72e9bb54 | 1440 | torture_type); |
cf886c44 PM |
1441 | printk(KERN_ALERT "rcu-torture types:"); |
1442 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) | |
1443 | printk(KERN_ALERT " %s", torture_ops[i]->name); | |
1444 | printk(KERN_ALERT "\n"); | |
343e9099 | 1445 | mutex_unlock(&fullstop_mutex); |
a71fca58 | 1446 | return -EINVAL; |
72e9bb54 | 1447 | } |
bf66f18e PM |
1448 | if (cur_ops->fqs == NULL && fqs_duration != 0) { |
1449 | printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero " | |
1450 | "fqs_duration, fqs disabled.\n"); | |
1451 | fqs_duration = 0; | |
1452 | } | |
c8e5b163 | 1453 | if (cur_ops->init) |
72e9bb54 PM |
1454 | cur_ops->init(); /* no "goto unwind" prior to this point!!! */ |
1455 | ||
a241ec65 PM |
1456 | if (nreaders >= 0) |
1457 | nrealreaders = nreaders; | |
1458 | else | |
1459 | nrealreaders = 2 * num_online_cpus(); | |
8e8be45e | 1460 | rcu_torture_print_module_parms(cur_ops, "Start of test"); |
c9d557c1 | 1461 | fullstop = FULLSTOP_DONTSTOP; |
a241ec65 PM |
1462 | |
1463 | /* Set up the freelist. */ | |
1464 | ||
1465 | INIT_LIST_HEAD(&rcu_torture_freelist); | |
788e770e | 1466 | for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) { |
996417d2 | 1467 | rcu_tortures[i].rtort_mbtest = 0; |
a241ec65 PM |
1468 | list_add_tail(&rcu_tortures[i].rtort_free, |
1469 | &rcu_torture_freelist); | |
1470 | } | |
1471 | ||
1472 | /* Initialize the statistics so that each run gets its own numbers. */ | |
1473 | ||
1474 | rcu_torture_current = NULL; | |
1475 | rcu_torture_current_version = 0; | |
1476 | atomic_set(&n_rcu_torture_alloc, 0); | |
1477 | atomic_set(&n_rcu_torture_alloc_fail, 0); | |
1478 | atomic_set(&n_rcu_torture_free, 0); | |
996417d2 PM |
1479 | atomic_set(&n_rcu_torture_mberror, 0); |
1480 | atomic_set(&n_rcu_torture_error, 0); | |
8e8be45e PM |
1481 | n_rcu_torture_boost_ktrerror = 0; |
1482 | n_rcu_torture_boost_rterror = 0; | |
8e8be45e PM |
1483 | n_rcu_torture_boost_failure = 0; |
1484 | n_rcu_torture_boosts = 0; | |
a241ec65 PM |
1485 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
1486 | atomic_set(&rcu_torture_wcount[i], 0); | |
0a945022 | 1487 | for_each_possible_cpu(cpu) { |
a241ec65 PM |
1488 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
1489 | per_cpu(rcu_torture_count, cpu)[i] = 0; | |
1490 | per_cpu(rcu_torture_batch, cpu)[i] = 0; | |
1491 | } | |
1492 | } | |
1493 | ||
1494 | /* Start up the kthreads. */ | |
1495 | ||
1496 | VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task"); | |
1497 | writer_task = kthread_run(rcu_torture_writer, NULL, | |
1498 | "rcu_torture_writer"); | |
1499 | if (IS_ERR(writer_task)) { | |
1500 | firsterr = PTR_ERR(writer_task); | |
1501 | VERBOSE_PRINTK_ERRSTRING("Failed to create writer"); | |
1502 | writer_task = NULL; | |
1503 | goto unwind; | |
1504 | } | |
b772e1dd | 1505 | fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]), |
a71fca58 | 1506 | GFP_KERNEL); |
b772e1dd JT |
1507 | if (fakewriter_tasks == NULL) { |
1508 | VERBOSE_PRINTK_ERRSTRING("out of memory"); | |
1509 | firsterr = -ENOMEM; | |
1510 | goto unwind; | |
1511 | } | |
1512 | for (i = 0; i < nfakewriters; i++) { | |
1513 | VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task"); | |
1514 | fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL, | |
a71fca58 | 1515 | "rcu_torture_fakewriter"); |
b772e1dd JT |
1516 | if (IS_ERR(fakewriter_tasks[i])) { |
1517 | firsterr = PTR_ERR(fakewriter_tasks[i]); | |
1518 | VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter"); | |
1519 | fakewriter_tasks[i] = NULL; | |
1520 | goto unwind; | |
1521 | } | |
1522 | } | |
2860aaba | 1523 | reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]), |
a241ec65 PM |
1524 | GFP_KERNEL); |
1525 | if (reader_tasks == NULL) { | |
1526 | VERBOSE_PRINTK_ERRSTRING("out of memory"); | |
1527 | firsterr = -ENOMEM; | |
1528 | goto unwind; | |
1529 | } | |
1530 | for (i = 0; i < nrealreaders; i++) { | |
1531 | VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task"); | |
1532 | reader_tasks[i] = kthread_run(rcu_torture_reader, NULL, | |
1533 | "rcu_torture_reader"); | |
1534 | if (IS_ERR(reader_tasks[i])) { | |
1535 | firsterr = PTR_ERR(reader_tasks[i]); | |
1536 | VERBOSE_PRINTK_ERRSTRING("Failed to create reader"); | |
1537 | reader_tasks[i] = NULL; | |
1538 | goto unwind; | |
1539 | } | |
1540 | } | |
1541 | if (stat_interval > 0) { | |
1542 | VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task"); | |
1543 | stats_task = kthread_run(rcu_torture_stats, NULL, | |
1544 | "rcu_torture_stats"); | |
1545 | if (IS_ERR(stats_task)) { | |
1546 | firsterr = PTR_ERR(stats_task); | |
1547 | VERBOSE_PRINTK_ERRSTRING("Failed to create stats"); | |
1548 | stats_task = NULL; | |
1549 | goto unwind; | |
1550 | } | |
1551 | } | |
d84f5203 SV |
1552 | if (test_no_idle_hz) { |
1553 | rcu_idle_cpu = num_online_cpus() - 1; | |
73d0a4b1 RR |
1554 | |
1555 | if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) { | |
1556 | firsterr = -ENOMEM; | |
1557 | VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask"); | |
1558 | goto unwind; | |
1559 | } | |
1560 | ||
d84f5203 SV |
1561 | /* Create the shuffler thread */ |
1562 | shuffler_task = kthread_run(rcu_torture_shuffle, NULL, | |
1563 | "rcu_torture_shuffle"); | |
1564 | if (IS_ERR(shuffler_task)) { | |
73d0a4b1 | 1565 | free_cpumask_var(shuffle_tmp_mask); |
d84f5203 SV |
1566 | firsterr = PTR_ERR(shuffler_task); |
1567 | VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler"); | |
1568 | shuffler_task = NULL; | |
1569 | goto unwind; | |
1570 | } | |
1571 | } | |
d120f65f PM |
1572 | if (stutter < 0) |
1573 | stutter = 0; | |
1574 | if (stutter) { | |
1575 | /* Create the stutter thread */ | |
1576 | stutter_task = kthread_run(rcu_torture_stutter, NULL, | |
1577 | "rcu_torture_stutter"); | |
1578 | if (IS_ERR(stutter_task)) { | |
1579 | firsterr = PTR_ERR(stutter_task); | |
1580 | VERBOSE_PRINTK_ERRSTRING("Failed to create stutter"); | |
1581 | stutter_task = NULL; | |
1582 | goto unwind; | |
1583 | } | |
1584 | } | |
bf66f18e PM |
1585 | if (fqs_duration < 0) |
1586 | fqs_duration = 0; | |
1587 | if (fqs_duration) { | |
1588 | /* Create the stutter thread */ | |
1589 | fqs_task = kthread_run(rcu_torture_fqs, NULL, | |
1590 | "rcu_torture_fqs"); | |
1591 | if (IS_ERR(fqs_task)) { | |
1592 | firsterr = PTR_ERR(fqs_task); | |
1593 | VERBOSE_PRINTK_ERRSTRING("Failed to create fqs"); | |
1594 | fqs_task = NULL; | |
1595 | goto unwind; | |
1596 | } | |
1597 | } | |
8e8be45e PM |
1598 | if (test_boost_interval < 1) |
1599 | test_boost_interval = 1; | |
1600 | if (test_boost_duration < 2) | |
1601 | test_boost_duration = 2; | |
1602 | if ((test_boost == 1 && cur_ops->can_boost) || | |
1603 | test_boost == 2) { | |
1604 | int retval; | |
1605 | ||
1606 | boost_starttime = jiffies + test_boost_interval * HZ; | |
1607 | register_cpu_notifier(&rcutorture_cpu_nb); | |
1608 | for_each_possible_cpu(i) { | |
1609 | if (cpu_is_offline(i)) | |
1610 | continue; /* Heuristic: CPU can go offline. */ | |
1611 | retval = rcutorture_booster_init(i); | |
1612 | if (retval < 0) { | |
1613 | firsterr = retval; | |
1614 | goto unwind; | |
1615 | } | |
1616 | } | |
1617 | } | |
1618 | register_reboot_notifier(&rcutorture_shutdown_nb); | |
343e9099 | 1619 | mutex_unlock(&fullstop_mutex); |
a241ec65 PM |
1620 | return 0; |
1621 | ||
1622 | unwind: | |
343e9099 | 1623 | mutex_unlock(&fullstop_mutex); |
a241ec65 PM |
1624 | rcu_torture_cleanup(); |
1625 | return firsterr; | |
1626 | } | |
1627 | ||
1628 | module_init(rcu_torture_init); | |
1629 | module_exit(rcu_torture_cleanup); |