Commit | Line | Data |
---|---|---|
a241ec65 | 1 | /* |
29766f1e | 2 | * Read-Copy Update module-based torture test facility |
a241ec65 PM |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | * | |
b772e1dd | 18 | * Copyright (C) IBM Corporation, 2005, 2006 |
a241ec65 PM |
19 | * |
20 | * Authors: Paul E. McKenney <paulmck@us.ibm.com> | |
a71fca58 | 21 | * Josh Triplett <josh@freedesktop.org> |
a241ec65 PM |
22 | * |
23 | * See also: Documentation/RCU/torture.txt | |
24 | */ | |
25 | #include <linux/types.h> | |
26 | #include <linux/kernel.h> | |
27 | #include <linux/init.h> | |
28 | #include <linux/module.h> | |
29 | #include <linux/kthread.h> | |
30 | #include <linux/err.h> | |
31 | #include <linux/spinlock.h> | |
32 | #include <linux/smp.h> | |
33 | #include <linux/rcupdate.h> | |
34 | #include <linux/interrupt.h> | |
35 | #include <linux/sched.h> | |
60063497 | 36 | #include <linux/atomic.h> |
a241ec65 | 37 | #include <linux/bitops.h> |
a241ec65 PM |
38 | #include <linux/completion.h> |
39 | #include <linux/moduleparam.h> | |
40 | #include <linux/percpu.h> | |
41 | #include <linux/notifier.h> | |
343e9099 | 42 | #include <linux/reboot.h> |
83144186 | 43 | #include <linux/freezer.h> |
a241ec65 | 44 | #include <linux/cpu.h> |
a241ec65 | 45 | #include <linux/delay.h> |
a241ec65 | 46 | #include <linux/stat.h> |
b2896d2e | 47 | #include <linux/srcu.h> |
1aeb272c | 48 | #include <linux/slab.h> |
f07767fd | 49 | #include <asm/byteorder.h> |
a241ec65 PM |
50 | |
51 | MODULE_LICENSE("GPL"); | |
b772e1dd | 52 | MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and " |
a71fca58 | 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). */ |
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"); |
3721bc1d | 76 | module_param(stat_interval, int, 0644); |
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; |
4a298656 | 134 | static unsigned 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 | ||
483 | static struct rcu_torture_ops rcu_bh_ops = { | |
0acc512c PM |
484 | .init = NULL, |
485 | .cleanup = NULL, | |
486 | .readlock = rcu_bh_torture_read_lock, | |
487 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
488 | .readunlock = rcu_bh_torture_read_unlock, | |
489 | .completed = rcu_bh_torture_completed, | |
490 | .deferred_free = rcu_bh_torture_deferred_free, | |
bdf2a436 | 491 | .sync = synchronize_rcu_bh, |
0acc512c | 492 | .cb_barrier = rcu_barrier_bh, |
bf66f18e | 493 | .fqs = rcu_bh_force_quiescent_state, |
0acc512c PM |
494 | .stats = NULL, |
495 | .irq_capable = 1, | |
496 | .name = "rcu_bh" | |
c32e0660 PM |
497 | }; |
498 | ||
11a14701 | 499 | static struct rcu_torture_ops rcu_bh_sync_ops = { |
0acc512c PM |
500 | .init = rcu_sync_torture_init, |
501 | .cleanup = NULL, | |
502 | .readlock = rcu_bh_torture_read_lock, | |
503 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
504 | .readunlock = rcu_bh_torture_read_unlock, | |
505 | .completed = rcu_bh_torture_completed, | |
506 | .deferred_free = rcu_sync_torture_deferred_free, | |
bdf2a436 | 507 | .sync = synchronize_rcu_bh, |
0acc512c | 508 | .cb_barrier = NULL, |
bf66f18e | 509 | .fqs = rcu_bh_force_quiescent_state, |
0acc512c PM |
510 | .stats = NULL, |
511 | .irq_capable = 1, | |
512 | .name = "rcu_bh_sync" | |
11a14701 JT |
513 | }; |
514 | ||
bdf2a436 PM |
515 | static struct rcu_torture_ops rcu_bh_expedited_ops = { |
516 | .init = rcu_sync_torture_init, | |
517 | .cleanup = NULL, | |
518 | .readlock = rcu_bh_torture_read_lock, | |
519 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
520 | .readunlock = rcu_bh_torture_read_unlock, | |
521 | .completed = rcu_bh_torture_completed, | |
522 | .deferred_free = rcu_sync_torture_deferred_free, | |
523 | .sync = synchronize_rcu_bh_expedited, | |
524 | .cb_barrier = NULL, | |
525 | .fqs = rcu_bh_force_quiescent_state, | |
526 | .stats = NULL, | |
527 | .irq_capable = 1, | |
528 | .name = "rcu_bh_expedited" | |
529 | }; | |
530 | ||
b2896d2e PM |
531 | /* |
532 | * Definitions for srcu torture testing. | |
533 | */ | |
534 | ||
535 | static struct srcu_struct srcu_ctl; | |
b2896d2e PM |
536 | |
537 | static void srcu_torture_init(void) | |
538 | { | |
539 | init_srcu_struct(&srcu_ctl); | |
e3033736 | 540 | rcu_sync_torture_init(); |
b2896d2e PM |
541 | } |
542 | ||
543 | static void srcu_torture_cleanup(void) | |
544 | { | |
545 | synchronize_srcu(&srcu_ctl); | |
546 | cleanup_srcu_struct(&srcu_ctl); | |
547 | } | |
548 | ||
012d3ca8 | 549 | static int srcu_torture_read_lock(void) __acquires(&srcu_ctl) |
b2896d2e PM |
550 | { |
551 | return srcu_read_lock(&srcu_ctl); | |
552 | } | |
553 | ||
554 | static void srcu_read_delay(struct rcu_random_state *rrsp) | |
555 | { | |
556 | long delay; | |
557 | const long uspertick = 1000000 / HZ; | |
558 | const long longdelay = 10; | |
559 | ||
560 | /* We want there to be long-running readers, but not all the time. */ | |
561 | ||
562 | delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick); | |
563 | if (!delay) | |
564 | schedule_timeout_interruptible(longdelay); | |
e546f485 LJ |
565 | else |
566 | rcu_read_delay(rrsp); | |
b2896d2e PM |
567 | } |
568 | ||
012d3ca8 | 569 | static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl) |
b2896d2e PM |
570 | { |
571 | srcu_read_unlock(&srcu_ctl, idx); | |
572 | } | |
573 | ||
574 | static int srcu_torture_completed(void) | |
575 | { | |
576 | return srcu_batches_completed(&srcu_ctl); | |
577 | } | |
578 | ||
b772e1dd JT |
579 | static void srcu_torture_synchronize(void) |
580 | { | |
581 | synchronize_srcu(&srcu_ctl); | |
582 | } | |
583 | ||
b2896d2e PM |
584 | static int srcu_torture_stats(char *page) |
585 | { | |
586 | int cnt = 0; | |
587 | int cpu; | |
588 | int idx = srcu_ctl.completed & 0x1; | |
589 | ||
590 | cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):", | |
591 | torture_type, TORTURE_FLAG, idx); | |
592 | for_each_possible_cpu(cpu) { | |
593 | cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu, | |
594 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx], | |
595 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]); | |
596 | } | |
597 | cnt += sprintf(&page[cnt], "\n"); | |
598 | return cnt; | |
599 | } | |
600 | ||
601 | static struct rcu_torture_ops srcu_ops = { | |
0acc512c PM |
602 | .init = srcu_torture_init, |
603 | .cleanup = srcu_torture_cleanup, | |
604 | .readlock = srcu_torture_read_lock, | |
605 | .read_delay = srcu_read_delay, | |
606 | .readunlock = srcu_torture_read_unlock, | |
607 | .completed = srcu_torture_completed, | |
608 | .deferred_free = rcu_sync_torture_deferred_free, | |
609 | .sync = srcu_torture_synchronize, | |
610 | .cb_barrier = NULL, | |
611 | .stats = srcu_torture_stats, | |
612 | .name = "srcu" | |
b2896d2e PM |
613 | }; |
614 | ||
804bb837 PM |
615 | static void srcu_torture_synchronize_expedited(void) |
616 | { | |
617 | synchronize_srcu_expedited(&srcu_ctl); | |
618 | } | |
619 | ||
620 | static struct rcu_torture_ops srcu_expedited_ops = { | |
621 | .init = srcu_torture_init, | |
622 | .cleanup = srcu_torture_cleanup, | |
623 | .readlock = srcu_torture_read_lock, | |
624 | .read_delay = srcu_read_delay, | |
625 | .readunlock = srcu_torture_read_unlock, | |
626 | .completed = srcu_torture_completed, | |
627 | .deferred_free = rcu_sync_torture_deferred_free, | |
628 | .sync = srcu_torture_synchronize_expedited, | |
629 | .cb_barrier = NULL, | |
630 | .stats = srcu_torture_stats, | |
631 | .name = "srcu_expedited" | |
632 | }; | |
633 | ||
4b6c2cca JT |
634 | /* |
635 | * Definitions for sched torture testing. | |
636 | */ | |
637 | ||
638 | static int sched_torture_read_lock(void) | |
639 | { | |
640 | preempt_disable(); | |
641 | return 0; | |
642 | } | |
643 | ||
644 | static void sched_torture_read_unlock(int idx) | |
645 | { | |
646 | preempt_enable(); | |
647 | } | |
648 | ||
2326974d PM |
649 | static void rcu_sched_torture_deferred_free(struct rcu_torture *p) |
650 | { | |
651 | call_rcu_sched(&p->rtort_rcu, rcu_torture_cb); | |
652 | } | |
653 | ||
4b6c2cca | 654 | static struct rcu_torture_ops sched_ops = { |
0acc512c PM |
655 | .init = rcu_sync_torture_init, |
656 | .cleanup = NULL, | |
657 | .readlock = sched_torture_read_lock, | |
658 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
659 | .readunlock = sched_torture_read_unlock, | |
d9a3da06 | 660 | .completed = rcu_no_completed, |
0acc512c | 661 | .deferred_free = rcu_sched_torture_deferred_free, |
bdf2a436 | 662 | .sync = synchronize_sched, |
0acc512c | 663 | .cb_barrier = rcu_barrier_sched, |
bf66f18e | 664 | .fqs = rcu_sched_force_quiescent_state, |
0acc512c PM |
665 | .stats = NULL, |
666 | .irq_capable = 1, | |
667 | .name = "sched" | |
4b6c2cca JT |
668 | }; |
669 | ||
804bb837 | 670 | static struct rcu_torture_ops sched_sync_ops = { |
0acc512c PM |
671 | .init = rcu_sync_torture_init, |
672 | .cleanup = NULL, | |
673 | .readlock = sched_torture_read_lock, | |
674 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
675 | .readunlock = sched_torture_read_unlock, | |
d9a3da06 | 676 | .completed = rcu_no_completed, |
0acc512c | 677 | .deferred_free = rcu_sync_torture_deferred_free, |
bdf2a436 | 678 | .sync = synchronize_sched, |
0acc512c | 679 | .cb_barrier = NULL, |
bf66f18e | 680 | .fqs = rcu_sched_force_quiescent_state, |
0acc512c PM |
681 | .stats = NULL, |
682 | .name = "sched_sync" | |
683 | }; | |
684 | ||
0acc512c PM |
685 | static struct rcu_torture_ops sched_expedited_ops = { |
686 | .init = rcu_sync_torture_init, | |
687 | .cleanup = NULL, | |
688 | .readlock = sched_torture_read_lock, | |
689 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | |
690 | .readunlock = sched_torture_read_unlock, | |
d9a3da06 | 691 | .completed = rcu_no_completed, |
0acc512c PM |
692 | .deferred_free = rcu_sync_torture_deferred_free, |
693 | .sync = synchronize_sched_expedited, | |
694 | .cb_barrier = NULL, | |
bf66f18e | 695 | .fqs = rcu_sched_force_quiescent_state, |
969c7921 | 696 | .stats = NULL, |
0acc512c PM |
697 | .irq_capable = 1, |
698 | .name = "sched_expedited" | |
2326974d PM |
699 | }; |
700 | ||
8e8be45e PM |
701 | /* |
702 | * RCU torture priority-boost testing. Runs one real-time thread per | |
703 | * CPU for moderate bursts, repeatedly registering RCU callbacks and | |
704 | * spinning waiting for them to be invoked. If a given callback takes | |
705 | * too long to be invoked, we assume that priority inversion has occurred. | |
706 | */ | |
707 | ||
708 | struct rcu_boost_inflight { | |
709 | struct rcu_head rcu; | |
710 | int inflight; | |
711 | }; | |
712 | ||
713 | static void rcu_torture_boost_cb(struct rcu_head *head) | |
714 | { | |
715 | struct rcu_boost_inflight *rbip = | |
716 | container_of(head, struct rcu_boost_inflight, rcu); | |
717 | ||
718 | smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */ | |
719 | rbip->inflight = 0; | |
720 | } | |
721 | ||
722 | static int rcu_torture_boost(void *arg) | |
723 | { | |
724 | unsigned long call_rcu_time; | |
725 | unsigned long endtime; | |
726 | unsigned long oldstarttime; | |
727 | struct rcu_boost_inflight rbi = { .inflight = 0 }; | |
728 | struct sched_param sp; | |
729 | ||
730 | VERBOSE_PRINTK_STRING("rcu_torture_boost started"); | |
731 | ||
732 | /* Set real-time priority. */ | |
733 | sp.sched_priority = 1; | |
734 | if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) { | |
735 | VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!"); | |
736 | n_rcu_torture_boost_rterror++; | |
737 | } | |
738 | ||
561190e3 | 739 | init_rcu_head_on_stack(&rbi.rcu); |
8e8be45e PM |
740 | /* Each pass through the following loop does one boost-test cycle. */ |
741 | do { | |
742 | /* Wait for the next test interval. */ | |
743 | oldstarttime = boost_starttime; | |
93898fb1 | 744 | while (ULONG_CMP_LT(jiffies, oldstarttime)) { |
8e8be45e PM |
745 | schedule_timeout_uninterruptible(1); |
746 | rcu_stutter_wait("rcu_torture_boost"); | |
747 | if (kthread_should_stop() || | |
748 | fullstop != FULLSTOP_DONTSTOP) | |
749 | goto checkwait; | |
750 | } | |
751 | ||
752 | /* Do one boost-test interval. */ | |
753 | endtime = oldstarttime + test_boost_duration * HZ; | |
754 | call_rcu_time = jiffies; | |
93898fb1 | 755 | while (ULONG_CMP_LT(jiffies, endtime)) { |
8e8be45e PM |
756 | /* If we don't have a callback in flight, post one. */ |
757 | if (!rbi.inflight) { | |
758 | smp_mb(); /* RCU core before ->inflight = 1. */ | |
759 | rbi.inflight = 1; | |
760 | call_rcu(&rbi.rcu, rcu_torture_boost_cb); | |
761 | if (jiffies - call_rcu_time > | |
762 | test_boost_duration * HZ - HZ / 2) { | |
763 | VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed"); | |
764 | n_rcu_torture_boost_failure++; | |
765 | } | |
766 | call_rcu_time = jiffies; | |
767 | } | |
768 | cond_resched(); | |
769 | rcu_stutter_wait("rcu_torture_boost"); | |
770 | if (kthread_should_stop() || | |
771 | fullstop != FULLSTOP_DONTSTOP) | |
772 | goto checkwait; | |
773 | } | |
774 | ||
775 | /* | |
776 | * Set the start time of the next test interval. | |
777 | * Yes, this is vulnerable to long delays, but such | |
778 | * delays simply cause a false negative for the next | |
779 | * interval. Besides, we are running at RT priority, | |
780 | * so delays should be relatively rare. | |
781 | */ | |
ab8f11e5 PM |
782 | while (oldstarttime == boost_starttime && |
783 | !kthread_should_stop()) { | |
8e8be45e PM |
784 | if (mutex_trylock(&boost_mutex)) { |
785 | boost_starttime = jiffies + | |
786 | test_boost_interval * HZ; | |
787 | n_rcu_torture_boosts++; | |
788 | mutex_unlock(&boost_mutex); | |
789 | break; | |
790 | } | |
791 | schedule_timeout_uninterruptible(1); | |
792 | } | |
793 | ||
794 | /* Go do the stutter. */ | |
795 | checkwait: rcu_stutter_wait("rcu_torture_boost"); | |
796 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
797 | ||
798 | /* Clean up and exit. */ | |
799 | VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping"); | |
800 | rcutorture_shutdown_absorb("rcu_torture_boost"); | |
801 | while (!kthread_should_stop() || rbi.inflight) | |
802 | schedule_timeout_uninterruptible(1); | |
803 | smp_mb(); /* order accesses to ->inflight before stack-frame death. */ | |
9d68197c | 804 | destroy_rcu_head_on_stack(&rbi.rcu); |
8e8be45e PM |
805 | return 0; |
806 | } | |
807 | ||
bf66f18e PM |
808 | /* |
809 | * RCU torture force-quiescent-state kthread. Repeatedly induces | |
810 | * bursts of calls to force_quiescent_state(), increasing the probability | |
811 | * of occurrence of some important types of race conditions. | |
812 | */ | |
813 | static int | |
814 | rcu_torture_fqs(void *arg) | |
815 | { | |
816 | unsigned long fqs_resume_time; | |
817 | int fqs_burst_remaining; | |
818 | ||
819 | VERBOSE_PRINTK_STRING("rcu_torture_fqs task started"); | |
820 | do { | |
821 | fqs_resume_time = jiffies + fqs_stutter * HZ; | |
93898fb1 PM |
822 | while (ULONG_CMP_LT(jiffies, fqs_resume_time) && |
823 | !kthread_should_stop()) { | |
bf66f18e PM |
824 | schedule_timeout_interruptible(1); |
825 | } | |
826 | fqs_burst_remaining = fqs_duration; | |
93898fb1 PM |
827 | while (fqs_burst_remaining > 0 && |
828 | !kthread_should_stop()) { | |
bf66f18e PM |
829 | cur_ops->fqs(); |
830 | udelay(fqs_holdoff); | |
831 | fqs_burst_remaining -= fqs_holdoff; | |
832 | } | |
833 | rcu_stutter_wait("rcu_torture_fqs"); | |
834 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
835 | VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping"); | |
836 | rcutorture_shutdown_absorb("rcu_torture_fqs"); | |
837 | while (!kthread_should_stop()) | |
838 | schedule_timeout_uninterruptible(1); | |
839 | return 0; | |
840 | } | |
841 | ||
a241ec65 PM |
842 | /* |
843 | * RCU torture writer kthread. Repeatedly substitutes a new structure | |
844 | * for that pointed to by rcu_torture_current, freeing the old structure | |
845 | * after a series of grace periods (the "pipeline"). | |
846 | */ | |
847 | static int | |
848 | rcu_torture_writer(void *arg) | |
849 | { | |
850 | int i; | |
851 | long oldbatch = rcu_batches_completed(); | |
852 | struct rcu_torture *rp; | |
853 | struct rcu_torture *old_rp; | |
854 | static DEFINE_RCU_RANDOM(rand); | |
855 | ||
856 | VERBOSE_PRINTK_STRING("rcu_torture_writer task started"); | |
dbdf65b1 IM |
857 | set_user_nice(current, 19); |
858 | ||
a241ec65 PM |
859 | do { |
860 | schedule_timeout_uninterruptible(1); | |
a71fca58 PM |
861 | rp = rcu_torture_alloc(); |
862 | if (rp == NULL) | |
a241ec65 PM |
863 | continue; |
864 | rp->rtort_pipe_count = 0; | |
865 | udelay(rcu_random(&rand) & 0x3ff); | |
0ddea0ea PM |
866 | old_rp = rcu_dereference_check(rcu_torture_current, |
867 | current == writer_task); | |
996417d2 | 868 | rp->rtort_mbtest = 1; |
a241ec65 | 869 | rcu_assign_pointer(rcu_torture_current, rp); |
9b2619af | 870 | smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */ |
c8e5b163 | 871 | if (old_rp) { |
a241ec65 PM |
872 | i = old_rp->rtort_pipe_count; |
873 | if (i > RCU_TORTURE_PIPE_LEN) | |
874 | i = RCU_TORTURE_PIPE_LEN; | |
875 | atomic_inc(&rcu_torture_wcount[i]); | |
876 | old_rp->rtort_pipe_count++; | |
0acc512c | 877 | cur_ops->deferred_free(old_rp); |
a241ec65 | 878 | } |
4a298656 | 879 | rcutorture_record_progress(++rcu_torture_current_version); |
72e9bb54 | 880 | oldbatch = cur_ops->completed(); |
c9d557c1 PM |
881 | rcu_stutter_wait("rcu_torture_writer"); |
882 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
a241ec65 | 883 | VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping"); |
c9d557c1 PM |
884 | rcutorture_shutdown_absorb("rcu_torture_writer"); |
885 | while (!kthread_should_stop()) | |
a241ec65 PM |
886 | schedule_timeout_uninterruptible(1); |
887 | return 0; | |
888 | } | |
889 | ||
b772e1dd JT |
890 | /* |
891 | * RCU torture fake writer kthread. Repeatedly calls sync, with a random | |
892 | * delay between calls. | |
893 | */ | |
894 | static int | |
895 | rcu_torture_fakewriter(void *arg) | |
896 | { | |
897 | DEFINE_RCU_RANDOM(rand); | |
898 | ||
899 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started"); | |
900 | set_user_nice(current, 19); | |
901 | ||
902 | do { | |
903 | schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10); | |
904 | udelay(rcu_random(&rand) & 0x3ff); | |
905 | cur_ops->sync(); | |
c9d557c1 PM |
906 | rcu_stutter_wait("rcu_torture_fakewriter"); |
907 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
b772e1dd JT |
908 | |
909 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping"); | |
c9d557c1 PM |
910 | rcutorture_shutdown_absorb("rcu_torture_fakewriter"); |
911 | while (!kthread_should_stop()) | |
b772e1dd JT |
912 | schedule_timeout_uninterruptible(1); |
913 | return 0; | |
914 | } | |
915 | ||
0729fbf3 PM |
916 | /* |
917 | * RCU torture reader from timer handler. Dereferences rcu_torture_current, | |
918 | * incrementing the corresponding element of the pipeline array. The | |
919 | * counter in the element should never be greater than 1, otherwise, the | |
920 | * RCU implementation is broken. | |
921 | */ | |
922 | static void rcu_torture_timer(unsigned long unused) | |
923 | { | |
924 | int idx; | |
925 | int completed; | |
926 | static DEFINE_RCU_RANDOM(rand); | |
927 | static DEFINE_SPINLOCK(rand_lock); | |
928 | struct rcu_torture *p; | |
929 | int pipe_count; | |
930 | ||
931 | idx = cur_ops->readlock(); | |
932 | completed = cur_ops->completed(); | |
632ee200 | 933 | p = rcu_dereference_check(rcu_torture_current, |
632ee200 PM |
934 | rcu_read_lock_bh_held() || |
935 | rcu_read_lock_sched_held() || | |
936 | srcu_read_lock_held(&srcu_ctl)); | |
0729fbf3 PM |
937 | if (p == NULL) { |
938 | /* Leave because rcu_torture_writer is not yet underway */ | |
939 | cur_ops->readunlock(idx); | |
940 | return; | |
941 | } | |
942 | if (p->rtort_mbtest == 0) | |
943 | atomic_inc(&n_rcu_torture_mberror); | |
944 | spin_lock(&rand_lock); | |
0acc512c | 945 | cur_ops->read_delay(&rand); |
0729fbf3 PM |
946 | n_rcu_torture_timers++; |
947 | spin_unlock(&rand_lock); | |
948 | preempt_disable(); | |
949 | pipe_count = p->rtort_pipe_count; | |
950 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { | |
951 | /* Should not happen, but... */ | |
952 | pipe_count = RCU_TORTURE_PIPE_LEN; | |
953 | } | |
dd17c8f7 | 954 | __this_cpu_inc(rcu_torture_count[pipe_count]); |
0729fbf3 PM |
955 | completed = cur_ops->completed() - completed; |
956 | if (completed > RCU_TORTURE_PIPE_LEN) { | |
957 | /* Should not happen, but... */ | |
958 | completed = RCU_TORTURE_PIPE_LEN; | |
959 | } | |
dd17c8f7 | 960 | __this_cpu_inc(rcu_torture_batch[completed]); |
0729fbf3 PM |
961 | preempt_enable(); |
962 | cur_ops->readunlock(idx); | |
963 | } | |
964 | ||
a241ec65 PM |
965 | /* |
966 | * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current, | |
967 | * incrementing the corresponding element of the pipeline array. The | |
968 | * counter in the element should never be greater than 1, otherwise, the | |
969 | * RCU implementation is broken. | |
970 | */ | |
971 | static int | |
972 | rcu_torture_reader(void *arg) | |
973 | { | |
974 | int completed; | |
72e9bb54 | 975 | int idx; |
a241ec65 PM |
976 | DEFINE_RCU_RANDOM(rand); |
977 | struct rcu_torture *p; | |
978 | int pipe_count; | |
0729fbf3 | 979 | struct timer_list t; |
a241ec65 PM |
980 | |
981 | VERBOSE_PRINTK_STRING("rcu_torture_reader task started"); | |
dbdf65b1 | 982 | set_user_nice(current, 19); |
0acc512c | 983 | if (irqreader && cur_ops->irq_capable) |
0729fbf3 | 984 | setup_timer_on_stack(&t, rcu_torture_timer, 0); |
dbdf65b1 | 985 | |
a241ec65 | 986 | do { |
0acc512c | 987 | if (irqreader && cur_ops->irq_capable) { |
0729fbf3 | 988 | if (!timer_pending(&t)) |
6155fec9 | 989 | mod_timer(&t, jiffies + 1); |
0729fbf3 | 990 | } |
72e9bb54 PM |
991 | idx = cur_ops->readlock(); |
992 | completed = cur_ops->completed(); | |
632ee200 | 993 | p = rcu_dereference_check(rcu_torture_current, |
632ee200 PM |
994 | rcu_read_lock_bh_held() || |
995 | rcu_read_lock_sched_held() || | |
996 | srcu_read_lock_held(&srcu_ctl)); | |
a241ec65 PM |
997 | if (p == NULL) { |
998 | /* Wait for rcu_torture_writer to get underway */ | |
72e9bb54 | 999 | cur_ops->readunlock(idx); |
a241ec65 PM |
1000 | schedule_timeout_interruptible(HZ); |
1001 | continue; | |
1002 | } | |
996417d2 PM |
1003 | if (p->rtort_mbtest == 0) |
1004 | atomic_inc(&n_rcu_torture_mberror); | |
0acc512c | 1005 | cur_ops->read_delay(&rand); |
a241ec65 PM |
1006 | preempt_disable(); |
1007 | pipe_count = p->rtort_pipe_count; | |
1008 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { | |
1009 | /* Should not happen, but... */ | |
1010 | pipe_count = RCU_TORTURE_PIPE_LEN; | |
1011 | } | |
dd17c8f7 | 1012 | __this_cpu_inc(rcu_torture_count[pipe_count]); |
72e9bb54 | 1013 | completed = cur_ops->completed() - completed; |
a241ec65 PM |
1014 | if (completed > RCU_TORTURE_PIPE_LEN) { |
1015 | /* Should not happen, but... */ | |
1016 | completed = RCU_TORTURE_PIPE_LEN; | |
1017 | } | |
dd17c8f7 | 1018 | __this_cpu_inc(rcu_torture_batch[completed]); |
a241ec65 | 1019 | preempt_enable(); |
72e9bb54 | 1020 | cur_ops->readunlock(idx); |
a241ec65 | 1021 | schedule(); |
c9d557c1 PM |
1022 | rcu_stutter_wait("rcu_torture_reader"); |
1023 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | |
a241ec65 | 1024 | VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping"); |
c9d557c1 | 1025 | rcutorture_shutdown_absorb("rcu_torture_reader"); |
0acc512c | 1026 | if (irqreader && cur_ops->irq_capable) |
0729fbf3 | 1027 | del_timer_sync(&t); |
c9d557c1 | 1028 | while (!kthread_should_stop()) |
a241ec65 PM |
1029 | schedule_timeout_uninterruptible(1); |
1030 | return 0; | |
1031 | } | |
1032 | ||
1033 | /* | |
1034 | * Create an RCU-torture statistics message in the specified buffer. | |
1035 | */ | |
1036 | static int | |
1037 | rcu_torture_printk(char *page) | |
1038 | { | |
1039 | int cnt = 0; | |
1040 | int cpu; | |
1041 | int i; | |
1042 | long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; | |
1043 | long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; | |
1044 | ||
0a945022 | 1045 | for_each_possible_cpu(cpu) { |
a241ec65 PM |
1046 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
1047 | pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i]; | |
1048 | batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i]; | |
1049 | } | |
1050 | } | |
1051 | for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) { | |
1052 | if (pipesummary[i] != 0) | |
1053 | break; | |
1054 | } | |
72e9bb54 | 1055 | cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG); |
a241ec65 | 1056 | cnt += sprintf(&page[cnt], |
4a298656 | 1057 | "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d " |
67b98dba | 1058 | "rtmbe: %d rtbke: %ld rtbre: %ld " |
8e8be45e | 1059 | "rtbf: %ld rtb: %ld nt: %ld", |
a241ec65 PM |
1060 | rcu_torture_current, |
1061 | rcu_torture_current_version, | |
1062 | list_empty(&rcu_torture_freelist), | |
1063 | atomic_read(&n_rcu_torture_alloc), | |
1064 | atomic_read(&n_rcu_torture_alloc_fail), | |
996417d2 | 1065 | atomic_read(&n_rcu_torture_free), |
0729fbf3 | 1066 | atomic_read(&n_rcu_torture_mberror), |
8e8be45e PM |
1067 | n_rcu_torture_boost_ktrerror, |
1068 | n_rcu_torture_boost_rterror, | |
8e8be45e PM |
1069 | n_rcu_torture_boost_failure, |
1070 | n_rcu_torture_boosts, | |
0729fbf3 | 1071 | n_rcu_torture_timers); |
8e8be45e PM |
1072 | if (atomic_read(&n_rcu_torture_mberror) != 0 || |
1073 | n_rcu_torture_boost_ktrerror != 0 || | |
1074 | n_rcu_torture_boost_rterror != 0 || | |
8e8be45e | 1075 | n_rcu_torture_boost_failure != 0) |
996417d2 | 1076 | cnt += sprintf(&page[cnt], " !!!"); |
72e9bb54 | 1077 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
996417d2 | 1078 | if (i > 1) { |
a241ec65 | 1079 | cnt += sprintf(&page[cnt], "!!! "); |
996417d2 | 1080 | atomic_inc(&n_rcu_torture_error); |
5af970a4 | 1081 | WARN_ON_ONCE(1); |
996417d2 | 1082 | } |
a241ec65 PM |
1083 | cnt += sprintf(&page[cnt], "Reader Pipe: "); |
1084 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) | |
1085 | cnt += sprintf(&page[cnt], " %ld", pipesummary[i]); | |
72e9bb54 | 1086 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
a241ec65 | 1087 | cnt += sprintf(&page[cnt], "Reader Batch: "); |
72e9bb54 | 1088 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
a241ec65 | 1089 | cnt += sprintf(&page[cnt], " %ld", batchsummary[i]); |
72e9bb54 | 1090 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); |
a241ec65 PM |
1091 | cnt += sprintf(&page[cnt], "Free-Block Circulation: "); |
1092 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { | |
1093 | cnt += sprintf(&page[cnt], " %d", | |
1094 | atomic_read(&rcu_torture_wcount[i])); | |
1095 | } | |
1096 | cnt += sprintf(&page[cnt], "\n"); | |
c8e5b163 | 1097 | if (cur_ops->stats) |
72e9bb54 | 1098 | cnt += cur_ops->stats(&page[cnt]); |
a241ec65 PM |
1099 | return cnt; |
1100 | } | |
1101 | ||
1102 | /* | |
1103 | * Print torture statistics. Caller must ensure that there is only | |
1104 | * one call to this function at a given time!!! This is normally | |
1105 | * accomplished by relying on the module system to only have one copy | |
1106 | * of the module loaded, and then by giving the rcu_torture_stats | |
1107 | * kthread full control (or the init/cleanup functions when rcu_torture_stats | |
1108 | * thread is not running). | |
1109 | */ | |
1110 | static void | |
1111 | rcu_torture_stats_print(void) | |
1112 | { | |
1113 | int cnt; | |
1114 | ||
1115 | cnt = rcu_torture_printk(printk_buf); | |
1116 | printk(KERN_ALERT "%s", printk_buf); | |
1117 | } | |
1118 | ||
1119 | /* | |
1120 | * Periodically prints torture statistics, if periodic statistics printing | |
1121 | * was specified via the stat_interval module parameter. | |
1122 | * | |
1123 | * No need to worry about fullstop here, since this one doesn't reference | |
1124 | * volatile state or register callbacks. | |
1125 | */ | |
1126 | static int | |
1127 | rcu_torture_stats(void *arg) | |
1128 | { | |
1129 | VERBOSE_PRINTK_STRING("rcu_torture_stats task started"); | |
1130 | do { | |
1131 | schedule_timeout_interruptible(stat_interval * HZ); | |
1132 | rcu_torture_stats_print(); | |
c9d557c1 PM |
1133 | rcutorture_shutdown_absorb("rcu_torture_stats"); |
1134 | } while (!kthread_should_stop()); | |
a241ec65 PM |
1135 | VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping"); |
1136 | return 0; | |
1137 | } | |
1138 | ||
d84f5203 SV |
1139 | static int rcu_idle_cpu; /* Force all torture tasks off this CPU */ |
1140 | ||
1141 | /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case | |
1142 | * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs. | |
1143 | */ | |
b2896d2e | 1144 | static void rcu_torture_shuffle_tasks(void) |
d84f5203 | 1145 | { |
d84f5203 SV |
1146 | int i; |
1147 | ||
73d0a4b1 | 1148 | cpumask_setall(shuffle_tmp_mask); |
86ef5c9a | 1149 | get_online_cpus(); |
d84f5203 SV |
1150 | |
1151 | /* No point in shuffling if there is only one online CPU (ex: UP) */ | |
c9d557c1 PM |
1152 | if (num_online_cpus() == 1) { |
1153 | put_online_cpus(); | |
1154 | return; | |
1155 | } | |
d84f5203 SV |
1156 | |
1157 | if (rcu_idle_cpu != -1) | |
73d0a4b1 | 1158 | cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask); |
d84f5203 | 1159 | |
73d0a4b1 | 1160 | set_cpus_allowed_ptr(current, shuffle_tmp_mask); |
d84f5203 | 1161 | |
c8e5b163 | 1162 | if (reader_tasks) { |
d84f5203 SV |
1163 | for (i = 0; i < nrealreaders; i++) |
1164 | if (reader_tasks[i]) | |
f70316da | 1165 | set_cpus_allowed_ptr(reader_tasks[i], |
73d0a4b1 | 1166 | shuffle_tmp_mask); |
d84f5203 SV |
1167 | } |
1168 | ||
c8e5b163 | 1169 | if (fakewriter_tasks) { |
b772e1dd JT |
1170 | for (i = 0; i < nfakewriters; i++) |
1171 | if (fakewriter_tasks[i]) | |
f70316da | 1172 | set_cpus_allowed_ptr(fakewriter_tasks[i], |
73d0a4b1 | 1173 | shuffle_tmp_mask); |
b772e1dd JT |
1174 | } |
1175 | ||
d84f5203 | 1176 | if (writer_task) |
73d0a4b1 | 1177 | set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask); |
d84f5203 SV |
1178 | |
1179 | if (stats_task) | |
73d0a4b1 | 1180 | set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask); |
d84f5203 SV |
1181 | |
1182 | if (rcu_idle_cpu == -1) | |
1183 | rcu_idle_cpu = num_online_cpus() - 1; | |
1184 | else | |
1185 | rcu_idle_cpu--; | |
1186 | ||
86ef5c9a | 1187 | put_online_cpus(); |
d84f5203 SV |
1188 | } |
1189 | ||
1190 | /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the | |
1191 | * system to become idle at a time and cut off its timer ticks. This is meant | |
1192 | * to test the support for such tickless idle CPU in RCU. | |
1193 | */ | |
1194 | static int | |
1195 | rcu_torture_shuffle(void *arg) | |
1196 | { | |
1197 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started"); | |
1198 | do { | |
1199 | schedule_timeout_interruptible(shuffle_interval * HZ); | |
1200 | rcu_torture_shuffle_tasks(); | |
c9d557c1 PM |
1201 | rcutorture_shutdown_absorb("rcu_torture_shuffle"); |
1202 | } while (!kthread_should_stop()); | |
d84f5203 SV |
1203 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping"); |
1204 | return 0; | |
1205 | } | |
1206 | ||
d120f65f PM |
1207 | /* Cause the rcutorture test to "stutter", starting and stopping all |
1208 | * threads periodically. | |
1209 | */ | |
1210 | static int | |
1211 | rcu_torture_stutter(void *arg) | |
1212 | { | |
1213 | VERBOSE_PRINTK_STRING("rcu_torture_stutter task started"); | |
1214 | do { | |
1215 | schedule_timeout_interruptible(stutter * HZ); | |
1216 | stutter_pause_test = 1; | |
c9d557c1 | 1217 | if (!kthread_should_stop()) |
d120f65f PM |
1218 | schedule_timeout_interruptible(stutter * HZ); |
1219 | stutter_pause_test = 0; | |
c9d557c1 PM |
1220 | rcutorture_shutdown_absorb("rcu_torture_stutter"); |
1221 | } while (!kthread_should_stop()); | |
d120f65f PM |
1222 | VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping"); |
1223 | return 0; | |
1224 | } | |
1225 | ||
95c38322 | 1226 | static inline void |
8e8be45e | 1227 | rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag) |
95c38322 | 1228 | { |
b772e1dd JT |
1229 | printk(KERN_ALERT "%s" TORTURE_FLAG |
1230 | "--- %s: nreaders=%d nfakewriters=%d " | |
95c38322 | 1231 | "stat_interval=%d verbose=%d test_no_idle_hz=%d " |
bf66f18e | 1232 | "shuffle_interval=%d stutter=%d irqreader=%d " |
8e8be45e PM |
1233 | "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d " |
1234 | "test_boost=%d/%d test_boost_interval=%d " | |
1235 | "test_boost_duration=%d\n", | |
b772e1dd | 1236 | torture_type, tag, nrealreaders, nfakewriters, |
d120f65f | 1237 | stat_interval, verbose, test_no_idle_hz, shuffle_interval, |
8e8be45e PM |
1238 | stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter, |
1239 | test_boost, cur_ops->can_boost, | |
1240 | test_boost_interval, test_boost_duration); | |
95c38322 PM |
1241 | } |
1242 | ||
8e8be45e | 1243 | static struct notifier_block rcutorture_shutdown_nb = { |
343e9099 PM |
1244 | .notifier_call = rcutorture_shutdown_notify, |
1245 | }; | |
1246 | ||
8e8be45e PM |
1247 | static void rcutorture_booster_cleanup(int cpu) |
1248 | { | |
1249 | struct task_struct *t; | |
1250 | ||
1251 | if (boost_tasks[cpu] == NULL) | |
1252 | return; | |
1253 | mutex_lock(&boost_mutex); | |
1254 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task"); | |
1255 | t = boost_tasks[cpu]; | |
1256 | boost_tasks[cpu] = NULL; | |
1257 | mutex_unlock(&boost_mutex); | |
1258 | ||
1259 | /* This must be outside of the mutex, otherwise deadlock! */ | |
1260 | kthread_stop(t); | |
1261 | } | |
1262 | ||
1263 | static int rcutorture_booster_init(int cpu) | |
1264 | { | |
1265 | int retval; | |
1266 | ||
1267 | if (boost_tasks[cpu] != NULL) | |
1268 | return 0; /* Already created, nothing more to do. */ | |
1269 | ||
1270 | /* Don't allow time recalculation while creating a new task. */ | |
1271 | mutex_lock(&boost_mutex); | |
1272 | VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task"); | |
1f288094 ED |
1273 | boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL, |
1274 | cpu_to_node(cpu), | |
1275 | "rcu_torture_boost"); | |
8e8be45e PM |
1276 | if (IS_ERR(boost_tasks[cpu])) { |
1277 | retval = PTR_ERR(boost_tasks[cpu]); | |
1278 | VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed"); | |
1279 | n_rcu_torture_boost_ktrerror++; | |
1280 | boost_tasks[cpu] = NULL; | |
1281 | mutex_unlock(&boost_mutex); | |
1282 | return retval; | |
1283 | } | |
1284 | kthread_bind(boost_tasks[cpu], cpu); | |
1285 | wake_up_process(boost_tasks[cpu]); | |
1286 | mutex_unlock(&boost_mutex); | |
1287 | return 0; | |
1288 | } | |
1289 | ||
1290 | static int rcutorture_cpu_notify(struct notifier_block *self, | |
1291 | unsigned long action, void *hcpu) | |
1292 | { | |
1293 | long cpu = (long)hcpu; | |
1294 | ||
1295 | switch (action) { | |
1296 | case CPU_ONLINE: | |
1297 | case CPU_DOWN_FAILED: | |
1298 | (void)rcutorture_booster_init(cpu); | |
1299 | break; | |
1300 | case CPU_DOWN_PREPARE: | |
1301 | rcutorture_booster_cleanup(cpu); | |
1302 | break; | |
1303 | default: | |
1304 | break; | |
1305 | } | |
1306 | return NOTIFY_OK; | |
1307 | } | |
1308 | ||
1309 | static struct notifier_block rcutorture_cpu_nb = { | |
1310 | .notifier_call = rcutorture_cpu_notify, | |
1311 | }; | |
1312 | ||
a241ec65 PM |
1313 | static void |
1314 | rcu_torture_cleanup(void) | |
1315 | { | |
1316 | int i; | |
1317 | ||
343e9099 | 1318 | mutex_lock(&fullstop_mutex); |
4a298656 | 1319 | rcutorture_record_test_transition(); |
c9d557c1 PM |
1320 | if (fullstop == FULLSTOP_SHUTDOWN) { |
1321 | printk(KERN_WARNING /* but going down anyway, so... */ | |
1322 | "Concurrent 'rmmod rcutorture' and shutdown illegal!\n"); | |
343e9099 | 1323 | mutex_unlock(&fullstop_mutex); |
c9d557c1 | 1324 | schedule_timeout_uninterruptible(10); |
343e9099 PM |
1325 | if (cur_ops->cb_barrier != NULL) |
1326 | cur_ops->cb_barrier(); | |
1327 | return; | |
1328 | } | |
c9d557c1 | 1329 | fullstop = FULLSTOP_RMMOD; |
343e9099 | 1330 | mutex_unlock(&fullstop_mutex); |
8e8be45e | 1331 | unregister_reboot_notifier(&rcutorture_shutdown_nb); |
d120f65f PM |
1332 | if (stutter_task) { |
1333 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task"); | |
1334 | kthread_stop(stutter_task); | |
1335 | } | |
1336 | stutter_task = NULL; | |
c8e5b163 | 1337 | if (shuffler_task) { |
d84f5203 SV |
1338 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task"); |
1339 | kthread_stop(shuffler_task); | |
73d0a4b1 | 1340 | free_cpumask_var(shuffle_tmp_mask); |
d84f5203 SV |
1341 | } |
1342 | shuffler_task = NULL; | |
1343 | ||
c8e5b163 | 1344 | if (writer_task) { |
a241ec65 PM |
1345 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task"); |
1346 | kthread_stop(writer_task); | |
1347 | } | |
1348 | writer_task = NULL; | |
1349 | ||
c8e5b163 | 1350 | if (reader_tasks) { |
a241ec65 | 1351 | for (i = 0; i < nrealreaders; i++) { |
c8e5b163 | 1352 | if (reader_tasks[i]) { |
a241ec65 PM |
1353 | VERBOSE_PRINTK_STRING( |
1354 | "Stopping rcu_torture_reader task"); | |
1355 | kthread_stop(reader_tasks[i]); | |
1356 | } | |
1357 | reader_tasks[i] = NULL; | |
1358 | } | |
1359 | kfree(reader_tasks); | |
1360 | reader_tasks = NULL; | |
1361 | } | |
1362 | rcu_torture_current = NULL; | |
1363 | ||
c8e5b163 | 1364 | if (fakewriter_tasks) { |
b772e1dd | 1365 | for (i = 0; i < nfakewriters; i++) { |
c8e5b163 | 1366 | if (fakewriter_tasks[i]) { |
b772e1dd JT |
1367 | VERBOSE_PRINTK_STRING( |
1368 | "Stopping rcu_torture_fakewriter task"); | |
1369 | kthread_stop(fakewriter_tasks[i]); | |
1370 | } | |
1371 | fakewriter_tasks[i] = NULL; | |
1372 | } | |
1373 | kfree(fakewriter_tasks); | |
1374 | fakewriter_tasks = NULL; | |
1375 | } | |
1376 | ||
c8e5b163 | 1377 | if (stats_task) { |
a241ec65 PM |
1378 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task"); |
1379 | kthread_stop(stats_task); | |
1380 | } | |
1381 | stats_task = NULL; | |
1382 | ||
bf66f18e PM |
1383 | if (fqs_task) { |
1384 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task"); | |
1385 | kthread_stop(fqs_task); | |
1386 | } | |
1387 | fqs_task = NULL; | |
8e8be45e PM |
1388 | if ((test_boost == 1 && cur_ops->can_boost) || |
1389 | test_boost == 2) { | |
1390 | unregister_cpu_notifier(&rcutorture_cpu_nb); | |
1391 | for_each_possible_cpu(i) | |
1392 | rcutorture_booster_cleanup(i); | |
1393 | } | |
bf66f18e | 1394 | |
a241ec65 | 1395 | /* Wait for all RCU callbacks to fire. */ |
2326974d PM |
1396 | |
1397 | if (cur_ops->cb_barrier != NULL) | |
1398 | cur_ops->cb_barrier(); | |
a241ec65 | 1399 | |
a241ec65 | 1400 | rcu_torture_stats_print(); /* -After- the stats thread is stopped! */ |
72e9bb54 | 1401 | |
c8e5b163 | 1402 | if (cur_ops->cleanup) |
72e9bb54 | 1403 | cur_ops->cleanup(); |
95c38322 | 1404 | if (atomic_read(&n_rcu_torture_error)) |
8e8be45e | 1405 | rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE"); |
95c38322 | 1406 | else |
8e8be45e | 1407 | rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS"); |
a241ec65 PM |
1408 | } |
1409 | ||
6f8bc500 | 1410 | static int __init |
a241ec65 PM |
1411 | rcu_torture_init(void) |
1412 | { | |
1413 | int i; | |
1414 | int cpu; | |
1415 | int firsterr = 0; | |
ade5fb81 | 1416 | static struct rcu_torture_ops *torture_ops[] = |
d9a3da06 | 1417 | { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops, |
bdf2a436 | 1418 | &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops, |
804bb837 PM |
1419 | &srcu_ops, &srcu_expedited_ops, |
1420 | &sched_ops, &sched_sync_ops, &sched_expedited_ops, }; | |
a241ec65 | 1421 | |
343e9099 PM |
1422 | mutex_lock(&fullstop_mutex); |
1423 | ||
a241ec65 | 1424 | /* Process args and tell the world that the torturer is on the job. */ |
ade5fb81 | 1425 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) { |
72e9bb54 | 1426 | cur_ops = torture_ops[i]; |
ade5fb81 | 1427 | if (strcmp(torture_type, cur_ops->name) == 0) |
72e9bb54 | 1428 | break; |
72e9bb54 | 1429 | } |
ade5fb81 | 1430 | if (i == ARRAY_SIZE(torture_ops)) { |
cf886c44 | 1431 | printk(KERN_ALERT "rcu-torture: invalid torture type: \"%s\"\n", |
72e9bb54 | 1432 | torture_type); |
cf886c44 PM |
1433 | printk(KERN_ALERT "rcu-torture types:"); |
1434 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) | |
1435 | printk(KERN_ALERT " %s", torture_ops[i]->name); | |
1436 | printk(KERN_ALERT "\n"); | |
343e9099 | 1437 | mutex_unlock(&fullstop_mutex); |
a71fca58 | 1438 | return -EINVAL; |
72e9bb54 | 1439 | } |
bf66f18e PM |
1440 | if (cur_ops->fqs == NULL && fqs_duration != 0) { |
1441 | printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero " | |
1442 | "fqs_duration, fqs disabled.\n"); | |
1443 | fqs_duration = 0; | |
1444 | } | |
c8e5b163 | 1445 | if (cur_ops->init) |
72e9bb54 PM |
1446 | cur_ops->init(); /* no "goto unwind" prior to this point!!! */ |
1447 | ||
a241ec65 PM |
1448 | if (nreaders >= 0) |
1449 | nrealreaders = nreaders; | |
1450 | else | |
1451 | nrealreaders = 2 * num_online_cpus(); | |
8e8be45e | 1452 | rcu_torture_print_module_parms(cur_ops, "Start of test"); |
c9d557c1 | 1453 | fullstop = FULLSTOP_DONTSTOP; |
a241ec65 PM |
1454 | |
1455 | /* Set up the freelist. */ | |
1456 | ||
1457 | INIT_LIST_HEAD(&rcu_torture_freelist); | |
788e770e | 1458 | for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) { |
996417d2 | 1459 | rcu_tortures[i].rtort_mbtest = 0; |
a241ec65 PM |
1460 | list_add_tail(&rcu_tortures[i].rtort_free, |
1461 | &rcu_torture_freelist); | |
1462 | } | |
1463 | ||
1464 | /* Initialize the statistics so that each run gets its own numbers. */ | |
1465 | ||
1466 | rcu_torture_current = NULL; | |
1467 | rcu_torture_current_version = 0; | |
1468 | atomic_set(&n_rcu_torture_alloc, 0); | |
1469 | atomic_set(&n_rcu_torture_alloc_fail, 0); | |
1470 | atomic_set(&n_rcu_torture_free, 0); | |
996417d2 PM |
1471 | atomic_set(&n_rcu_torture_mberror, 0); |
1472 | atomic_set(&n_rcu_torture_error, 0); | |
8e8be45e PM |
1473 | n_rcu_torture_boost_ktrerror = 0; |
1474 | n_rcu_torture_boost_rterror = 0; | |
8e8be45e PM |
1475 | n_rcu_torture_boost_failure = 0; |
1476 | n_rcu_torture_boosts = 0; | |
a241ec65 PM |
1477 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
1478 | atomic_set(&rcu_torture_wcount[i], 0); | |
0a945022 | 1479 | for_each_possible_cpu(cpu) { |
a241ec65 PM |
1480 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
1481 | per_cpu(rcu_torture_count, cpu)[i] = 0; | |
1482 | per_cpu(rcu_torture_batch, cpu)[i] = 0; | |
1483 | } | |
1484 | } | |
1485 | ||
1486 | /* Start up the kthreads. */ | |
1487 | ||
1488 | VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task"); | |
1489 | writer_task = kthread_run(rcu_torture_writer, NULL, | |
1490 | "rcu_torture_writer"); | |
1491 | if (IS_ERR(writer_task)) { | |
1492 | firsterr = PTR_ERR(writer_task); | |
1493 | VERBOSE_PRINTK_ERRSTRING("Failed to create writer"); | |
1494 | writer_task = NULL; | |
1495 | goto unwind; | |
1496 | } | |
b772e1dd | 1497 | fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]), |
a71fca58 | 1498 | GFP_KERNEL); |
b772e1dd JT |
1499 | if (fakewriter_tasks == NULL) { |
1500 | VERBOSE_PRINTK_ERRSTRING("out of memory"); | |
1501 | firsterr = -ENOMEM; | |
1502 | goto unwind; | |
1503 | } | |
1504 | for (i = 0; i < nfakewriters; i++) { | |
1505 | VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task"); | |
1506 | fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL, | |
a71fca58 | 1507 | "rcu_torture_fakewriter"); |
b772e1dd JT |
1508 | if (IS_ERR(fakewriter_tasks[i])) { |
1509 | firsterr = PTR_ERR(fakewriter_tasks[i]); | |
1510 | VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter"); | |
1511 | fakewriter_tasks[i] = NULL; | |
1512 | goto unwind; | |
1513 | } | |
1514 | } | |
2860aaba | 1515 | reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]), |
a241ec65 PM |
1516 | GFP_KERNEL); |
1517 | if (reader_tasks == NULL) { | |
1518 | VERBOSE_PRINTK_ERRSTRING("out of memory"); | |
1519 | firsterr = -ENOMEM; | |
1520 | goto unwind; | |
1521 | } | |
1522 | for (i = 0; i < nrealreaders; i++) { | |
1523 | VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task"); | |
1524 | reader_tasks[i] = kthread_run(rcu_torture_reader, NULL, | |
1525 | "rcu_torture_reader"); | |
1526 | if (IS_ERR(reader_tasks[i])) { | |
1527 | firsterr = PTR_ERR(reader_tasks[i]); | |
1528 | VERBOSE_PRINTK_ERRSTRING("Failed to create reader"); | |
1529 | reader_tasks[i] = NULL; | |
1530 | goto unwind; | |
1531 | } | |
1532 | } | |
1533 | if (stat_interval > 0) { | |
1534 | VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task"); | |
1535 | stats_task = kthread_run(rcu_torture_stats, NULL, | |
1536 | "rcu_torture_stats"); | |
1537 | if (IS_ERR(stats_task)) { | |
1538 | firsterr = PTR_ERR(stats_task); | |
1539 | VERBOSE_PRINTK_ERRSTRING("Failed to create stats"); | |
1540 | stats_task = NULL; | |
1541 | goto unwind; | |
1542 | } | |
1543 | } | |
d84f5203 SV |
1544 | if (test_no_idle_hz) { |
1545 | rcu_idle_cpu = num_online_cpus() - 1; | |
73d0a4b1 RR |
1546 | |
1547 | if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) { | |
1548 | firsterr = -ENOMEM; | |
1549 | VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask"); | |
1550 | goto unwind; | |
1551 | } | |
1552 | ||
d84f5203 SV |
1553 | /* Create the shuffler thread */ |
1554 | shuffler_task = kthread_run(rcu_torture_shuffle, NULL, | |
1555 | "rcu_torture_shuffle"); | |
1556 | if (IS_ERR(shuffler_task)) { | |
73d0a4b1 | 1557 | free_cpumask_var(shuffle_tmp_mask); |
d84f5203 SV |
1558 | firsterr = PTR_ERR(shuffler_task); |
1559 | VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler"); | |
1560 | shuffler_task = NULL; | |
1561 | goto unwind; | |
1562 | } | |
1563 | } | |
d120f65f PM |
1564 | if (stutter < 0) |
1565 | stutter = 0; | |
1566 | if (stutter) { | |
1567 | /* Create the stutter thread */ | |
1568 | stutter_task = kthread_run(rcu_torture_stutter, NULL, | |
1569 | "rcu_torture_stutter"); | |
1570 | if (IS_ERR(stutter_task)) { | |
1571 | firsterr = PTR_ERR(stutter_task); | |
1572 | VERBOSE_PRINTK_ERRSTRING("Failed to create stutter"); | |
1573 | stutter_task = NULL; | |
1574 | goto unwind; | |
1575 | } | |
1576 | } | |
bf66f18e PM |
1577 | if (fqs_duration < 0) |
1578 | fqs_duration = 0; | |
1579 | if (fqs_duration) { | |
1580 | /* Create the stutter thread */ | |
1581 | fqs_task = kthread_run(rcu_torture_fqs, NULL, | |
1582 | "rcu_torture_fqs"); | |
1583 | if (IS_ERR(fqs_task)) { | |
1584 | firsterr = PTR_ERR(fqs_task); | |
1585 | VERBOSE_PRINTK_ERRSTRING("Failed to create fqs"); | |
1586 | fqs_task = NULL; | |
1587 | goto unwind; | |
1588 | } | |
1589 | } | |
8e8be45e PM |
1590 | if (test_boost_interval < 1) |
1591 | test_boost_interval = 1; | |
1592 | if (test_boost_duration < 2) | |
1593 | test_boost_duration = 2; | |
1594 | if ((test_boost == 1 && cur_ops->can_boost) || | |
1595 | test_boost == 2) { | |
1596 | int retval; | |
1597 | ||
1598 | boost_starttime = jiffies + test_boost_interval * HZ; | |
1599 | register_cpu_notifier(&rcutorture_cpu_nb); | |
1600 | for_each_possible_cpu(i) { | |
1601 | if (cpu_is_offline(i)) | |
1602 | continue; /* Heuristic: CPU can go offline. */ | |
1603 | retval = rcutorture_booster_init(i); | |
1604 | if (retval < 0) { | |
1605 | firsterr = retval; | |
1606 | goto unwind; | |
1607 | } | |
1608 | } | |
1609 | } | |
1610 | register_reboot_notifier(&rcutorture_shutdown_nb); | |
4a298656 | 1611 | rcutorture_record_test_transition(); |
343e9099 | 1612 | mutex_unlock(&fullstop_mutex); |
a241ec65 PM |
1613 | return 0; |
1614 | ||
1615 | unwind: | |
343e9099 | 1616 | mutex_unlock(&fullstop_mutex); |
a241ec65 PM |
1617 | rcu_torture_cleanup(); |
1618 | return firsterr; | |
1619 | } | |
1620 | ||
1621 | module_init(rcu_torture_init); | |
1622 | module_exit(rcu_torture_cleanup); |