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