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