blob: e1ca7a2fae91b58f81d6e438a3a5f5fa59b9f61a [file] [log] [blame]
Paul E. McKenney0af3fe12014-02-04 15:51:41 -08001/*
2 * Module-based torture test facility for locking
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, you can access it online at
16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 *
18 * Copyright (C) IBM Corporation, 2014
19 *
Davidlohr Bueso095777c2015-07-22 14:07:27 -070020 * Authors: Paul E. McKenney <paulmck@us.ibm.com>
21 * Davidlohr Bueso <dave@stgolabs.net>
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080022 * Based on kernel/rcu/torture.c.
23 */
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080024#include <linux/kernel.h>
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080025#include <linux/module.h>
26#include <linux/kthread.h>
Davidlohr Bueso095777c2015-07-22 14:07:27 -070027#include <linux/sched/rt.h>
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080028#include <linux/spinlock.h>
Davidlohr Buesoe34191f2014-09-29 06:14:23 -070029#include <linux/rwlock.h>
Davidlohr Bueso42ddc752014-09-11 20:40:18 -070030#include <linux/mutex.h>
Davidlohr Buesoc98fed92014-09-29 06:14:26 -070031#include <linux/rwsem.h>
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080032#include <linux/smp.h>
33#include <linux/interrupt.h>
34#include <linux/sched.h>
35#include <linux/atomic.h>
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080036#include <linux/moduleparam.h>
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080037#include <linux/delay.h>
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080038#include <linux/slab.h>
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080039#include <linux/torture.h>
40
41MODULE_LICENSE("GPL");
42MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com>");
43
44torture_param(int, nwriters_stress, -1,
45 "Number of write-locking stress-test threads");
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -070046torture_param(int, nreaders_stress, -1,
47 "Number of read-locking stress-test threads");
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080048torture_param(int, onoff_holdoff, 0, "Time after boot before CPU hotplugs (s)");
49torture_param(int, onoff_interval, 0,
50 "Time between CPU hotplugs (s), 0=disable");
51torture_param(int, shuffle_interval, 3,
52 "Number of jiffies between shuffles, 0=disable");
53torture_param(int, shutdown_secs, 0, "Shutdown time (j), <= zero to disable.");
54torture_param(int, stat_interval, 60,
55 "Number of seconds between stats printk()s");
56torture_param(int, stutter, 5, "Number of jiffies to run/halt test, 0=disable");
57torture_param(bool, verbose, true,
58 "Enable verbose debugging printk()s");
59
60static char *torture_type = "spin_lock";
61module_param(torture_type, charp, 0444);
62MODULE_PARM_DESC(torture_type,
Davidlohr Bueso42ddc752014-09-11 20:40:18 -070063 "Type of lock to torture (spin_lock, spin_lock_irq, mutex_lock, ...)");
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080064
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080065static struct task_struct *stats_task;
66static struct task_struct **writer_tasks;
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -070067static struct task_struct **reader_tasks;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080068
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080069static bool lock_is_write_held;
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -070070static bool lock_is_read_held;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080071
Davidlohr Bueso1e6757a2014-09-11 20:40:20 -070072struct lock_stress_stats {
73 long n_lock_fail;
74 long n_lock_acquired;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080075};
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080076
Paul E. McKenneyd065eac2014-04-04 17:17:35 -070077#if defined(MODULE)
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080078#define LOCKTORTURE_RUNNABLE_INIT 1
79#else
80#define LOCKTORTURE_RUNNABLE_INIT 0
81#endif
Davidlohr Bueso23a8e5c2014-09-11 20:40:16 -070082int torture_runnable = LOCKTORTURE_RUNNABLE_INIT;
83module_param(torture_runnable, int, 0444);
84MODULE_PARM_DESC(torture_runnable, "Start locktorture at module init");
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080085
86/* Forward reference. */
87static void lock_torture_cleanup(void);
88
89/*
90 * Operations vector for selecting different types of tests.
91 */
92struct lock_torture_ops {
93 void (*init)(void);
94 int (*writelock)(void);
95 void (*write_delay)(struct torture_random_state *trsp);
Davidlohr Bueso095777c2015-07-22 14:07:27 -070096 void (*task_boost)(struct torture_random_state *trsp);
Paul E. McKenney0af3fe12014-02-04 15:51:41 -080097 void (*writeunlock)(void);
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -070098 int (*readlock)(void);
99 void (*read_delay)(struct torture_random_state *trsp);
100 void (*readunlock)(void);
Davidlohr Bueso095777c2015-07-22 14:07:27 -0700101
102 unsigned long flags; /* for irq spinlocks */
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800103 const char *name;
104};
105
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700106struct lock_torture_cxt {
107 int nrealwriters_stress;
108 int nrealreaders_stress;
109 bool debug_lock;
110 atomic_t n_lock_torture_errors;
111 struct lock_torture_ops *cur_ops;
112 struct lock_stress_stats *lwsa; /* writer statistics */
113 struct lock_stress_stats *lrsa; /* reader statistics */
114};
115static struct lock_torture_cxt cxt = { 0, 0, false,
116 ATOMIC_INIT(0),
117 NULL, NULL};
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800118/*
119 * Definitions for lock torture testing.
120 */
121
Paul E. McKenneye0864812014-02-11 08:05:07 -0800122static int torture_lock_busted_write_lock(void)
123{
124 return 0; /* BUGGY, do not use in real life!!! */
125}
126
127static void torture_lock_busted_write_delay(struct torture_random_state *trsp)
128{
Paul E. McKenney61d49d22015-04-01 08:42:27 -0700129 const unsigned long longdelay_ms = 100;
Paul E. McKenneye0864812014-02-11 08:05:07 -0800130
131 /* We want a long delay occasionally to force massive contention. */
132 if (!(torture_random(trsp) %
Paul E. McKenney61d49d22015-04-01 08:42:27 -0700133 (cxt.nrealwriters_stress * 2000 * longdelay_ms)))
134 mdelay(longdelay_ms);
Paul E. McKenneye0864812014-02-11 08:05:07 -0800135#ifdef CONFIG_PREEMPT
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700136 if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000)))
Paul E. McKenneye0864812014-02-11 08:05:07 -0800137 preempt_schedule(); /* Allow test to be preempted. */
138#endif
139}
140
141static void torture_lock_busted_write_unlock(void)
142{
143 /* BUGGY, do not use in real life!!! */
144}
145
Davidlohr Bueso095777c2015-07-22 14:07:27 -0700146static void torture_boost_dummy(struct torture_random_state *trsp)
147{
148 /* Only rtmutexes care about priority */
149}
150
Paul E. McKenneye0864812014-02-11 08:05:07 -0800151static struct lock_torture_ops lock_busted_ops = {
152 .writelock = torture_lock_busted_write_lock,
153 .write_delay = torture_lock_busted_write_delay,
Davidlohr Bueso095777c2015-07-22 14:07:27 -0700154 .task_boost = torture_boost_dummy,
Paul E. McKenneye0864812014-02-11 08:05:07 -0800155 .writeunlock = torture_lock_busted_write_unlock,
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700156 .readlock = NULL,
157 .read_delay = NULL,
158 .readunlock = NULL,
Paul E. McKenneye0864812014-02-11 08:05:07 -0800159 .name = "lock_busted"
160};
161
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800162static DEFINE_SPINLOCK(torture_spinlock);
163
164static int torture_spin_lock_write_lock(void) __acquires(torture_spinlock)
165{
166 spin_lock(&torture_spinlock);
167 return 0;
168}
169
170static void torture_spin_lock_write_delay(struct torture_random_state *trsp)
171{
172 const unsigned long shortdelay_us = 2;
Paul E. McKenney61d49d22015-04-01 08:42:27 -0700173 const unsigned long longdelay_ms = 100;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800174
175 /* We want a short delay mostly to emulate likely code, and
176 * we want a long delay occasionally to force massive contention.
177 */
178 if (!(torture_random(trsp) %
Paul E. McKenney61d49d22015-04-01 08:42:27 -0700179 (cxt.nrealwriters_stress * 2000 * longdelay_ms)))
180 mdelay(longdelay_ms);
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800181 if (!(torture_random(trsp) %
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700182 (cxt.nrealwriters_stress * 2 * shortdelay_us)))
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800183 udelay(shortdelay_us);
184#ifdef CONFIG_PREEMPT
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700185 if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000)))
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800186 preempt_schedule(); /* Allow test to be preempted. */
187#endif
188}
189
190static void torture_spin_lock_write_unlock(void) __releases(torture_spinlock)
191{
192 spin_unlock(&torture_spinlock);
193}
194
195static struct lock_torture_ops spin_lock_ops = {
196 .writelock = torture_spin_lock_write_lock,
197 .write_delay = torture_spin_lock_write_delay,
Davidlohr Bueso095777c2015-07-22 14:07:27 -0700198 .task_boost = torture_boost_dummy,
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800199 .writeunlock = torture_spin_lock_write_unlock,
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700200 .readlock = NULL,
201 .read_delay = NULL,
202 .readunlock = NULL,
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800203 .name = "spin_lock"
204};
205
206static int torture_spin_lock_write_lock_irq(void)
Davidlohr Bueso219f8002014-09-29 06:14:24 -0700207__acquires(torture_spinlock)
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800208{
209 unsigned long flags;
210
211 spin_lock_irqsave(&torture_spinlock, flags);
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700212 cxt.cur_ops->flags = flags;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800213 return 0;
214}
215
216static void torture_lock_spin_write_unlock_irq(void)
217__releases(torture_spinlock)
218{
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700219 spin_unlock_irqrestore(&torture_spinlock, cxt.cur_ops->flags);
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800220}
221
222static struct lock_torture_ops spin_lock_irq_ops = {
223 .writelock = torture_spin_lock_write_lock_irq,
224 .write_delay = torture_spin_lock_write_delay,
Davidlohr Bueso095777c2015-07-22 14:07:27 -0700225 .task_boost = torture_boost_dummy,
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800226 .writeunlock = torture_lock_spin_write_unlock_irq,
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700227 .readlock = NULL,
228 .read_delay = NULL,
229 .readunlock = NULL,
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800230 .name = "spin_lock_irq"
231};
232
Davidlohr Buesoe34191f2014-09-29 06:14:23 -0700233static DEFINE_RWLOCK(torture_rwlock);
234
235static int torture_rwlock_write_lock(void) __acquires(torture_rwlock)
236{
237 write_lock(&torture_rwlock);
238 return 0;
239}
240
241static void torture_rwlock_write_delay(struct torture_random_state *trsp)
242{
243 const unsigned long shortdelay_us = 2;
244 const unsigned long longdelay_ms = 100;
245
246 /* We want a short delay mostly to emulate likely code, and
247 * we want a long delay occasionally to force massive contention.
248 */
249 if (!(torture_random(trsp) %
250 (cxt.nrealwriters_stress * 2000 * longdelay_ms)))
251 mdelay(longdelay_ms);
252 else
253 udelay(shortdelay_us);
254}
255
256static void torture_rwlock_write_unlock(void) __releases(torture_rwlock)
257{
258 write_unlock(&torture_rwlock);
259}
260
261static int torture_rwlock_read_lock(void) __acquires(torture_rwlock)
262{
263 read_lock(&torture_rwlock);
264 return 0;
265}
266
267static void torture_rwlock_read_delay(struct torture_random_state *trsp)
268{
269 const unsigned long shortdelay_us = 10;
270 const unsigned long longdelay_ms = 100;
271
272 /* We want a short delay mostly to emulate likely code, and
273 * we want a long delay occasionally to force massive contention.
274 */
275 if (!(torture_random(trsp) %
276 (cxt.nrealreaders_stress * 2000 * longdelay_ms)))
277 mdelay(longdelay_ms);
278 else
279 udelay(shortdelay_us);
280}
281
282static void torture_rwlock_read_unlock(void) __releases(torture_rwlock)
283{
284 read_unlock(&torture_rwlock);
285}
286
287static struct lock_torture_ops rw_lock_ops = {
288 .writelock = torture_rwlock_write_lock,
289 .write_delay = torture_rwlock_write_delay,
Davidlohr Bueso095777c2015-07-22 14:07:27 -0700290 .task_boost = torture_boost_dummy,
Davidlohr Buesoe34191f2014-09-29 06:14:23 -0700291 .writeunlock = torture_rwlock_write_unlock,
292 .readlock = torture_rwlock_read_lock,
293 .read_delay = torture_rwlock_read_delay,
294 .readunlock = torture_rwlock_read_unlock,
295 .name = "rw_lock"
296};
297
298static int torture_rwlock_write_lock_irq(void) __acquires(torture_rwlock)
299{
300 unsigned long flags;
301
302 write_lock_irqsave(&torture_rwlock, flags);
303 cxt.cur_ops->flags = flags;
304 return 0;
305}
306
307static void torture_rwlock_write_unlock_irq(void)
308__releases(torture_rwlock)
309{
310 write_unlock_irqrestore(&torture_rwlock, cxt.cur_ops->flags);
311}
312
313static int torture_rwlock_read_lock_irq(void) __acquires(torture_rwlock)
314{
315 unsigned long flags;
316
317 read_lock_irqsave(&torture_rwlock, flags);
318 cxt.cur_ops->flags = flags;
319 return 0;
320}
321
322static void torture_rwlock_read_unlock_irq(void)
323__releases(torture_rwlock)
324{
Alexey Kodanevf548d992015-03-07 03:06:53 +0300325 read_unlock_irqrestore(&torture_rwlock, cxt.cur_ops->flags);
Davidlohr Buesoe34191f2014-09-29 06:14:23 -0700326}
327
328static struct lock_torture_ops rw_lock_irq_ops = {
329 .writelock = torture_rwlock_write_lock_irq,
330 .write_delay = torture_rwlock_write_delay,
Davidlohr Bueso095777c2015-07-22 14:07:27 -0700331 .task_boost = torture_boost_dummy,
Davidlohr Buesoe34191f2014-09-29 06:14:23 -0700332 .writeunlock = torture_rwlock_write_unlock_irq,
333 .readlock = torture_rwlock_read_lock_irq,
334 .read_delay = torture_rwlock_read_delay,
335 .readunlock = torture_rwlock_read_unlock_irq,
336 .name = "rw_lock_irq"
337};
338
Davidlohr Bueso42ddc752014-09-11 20:40:18 -0700339static DEFINE_MUTEX(torture_mutex);
340
341static int torture_mutex_lock(void) __acquires(torture_mutex)
342{
343 mutex_lock(&torture_mutex);
344 return 0;
345}
346
347static void torture_mutex_delay(struct torture_random_state *trsp)
348{
349 const unsigned long longdelay_ms = 100;
350
351 /* We want a long delay occasionally to force massive contention. */
352 if (!(torture_random(trsp) %
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700353 (cxt.nrealwriters_stress * 2000 * longdelay_ms)))
Davidlohr Bueso42ddc752014-09-11 20:40:18 -0700354 mdelay(longdelay_ms * 5);
355 else
356 mdelay(longdelay_ms / 5);
357#ifdef CONFIG_PREEMPT
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700358 if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000)))
Davidlohr Bueso42ddc752014-09-11 20:40:18 -0700359 preempt_schedule(); /* Allow test to be preempted. */
360#endif
361}
362
363static void torture_mutex_unlock(void) __releases(torture_mutex)
364{
365 mutex_unlock(&torture_mutex);
366}
367
368static struct lock_torture_ops mutex_lock_ops = {
369 .writelock = torture_mutex_lock,
370 .write_delay = torture_mutex_delay,
Davidlohr Bueso095777c2015-07-22 14:07:27 -0700371 .task_boost = torture_boost_dummy,
Davidlohr Bueso42ddc752014-09-11 20:40:18 -0700372 .writeunlock = torture_mutex_unlock,
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700373 .readlock = NULL,
374 .read_delay = NULL,
375 .readunlock = NULL,
Davidlohr Bueso42ddc752014-09-11 20:40:18 -0700376 .name = "mutex_lock"
377};
378
Davidlohr Bueso095777c2015-07-22 14:07:27 -0700379#ifdef CONFIG_RT_MUTEXES
380static DEFINE_RT_MUTEX(torture_rtmutex);
381
382static int torture_rtmutex_lock(void) __acquires(torture_rtmutex)
383{
384 rt_mutex_lock(&torture_rtmutex);
385 return 0;
386}
387
388static void torture_rtmutex_boost(struct torture_random_state *trsp)
389{
390 int policy;
391 struct sched_param param;
392 const unsigned int factor = 50000; /* yes, quite arbitrary */
393
394 if (!rt_task(current)) {
395 /*
396 * (1) Boost priority once every ~50k operations. When the
397 * task tries to take the lock, the rtmutex it will account
398 * for the new priority, and do any corresponding pi-dance.
399 */
400 if (!(torture_random(trsp) %
401 (cxt.nrealwriters_stress * factor))) {
402 policy = SCHED_FIFO;
403 param.sched_priority = MAX_RT_PRIO - 1;
404 } else /* common case, do nothing */
405 return;
406 } else {
407 /*
408 * The task will remain boosted for another ~500k operations,
409 * then restored back to its original prio, and so forth.
410 *
411 * When @trsp is nil, we want to force-reset the task for
412 * stopping the kthread.
413 */
414 if (!trsp || !(torture_random(trsp) %
415 (cxt.nrealwriters_stress * factor * 2))) {
416 policy = SCHED_NORMAL;
417 param.sched_priority = 0;
418 } else /* common case, do nothing */
419 return;
420 }
421
422 sched_setscheduler_nocheck(current, policy, &param);
423}
424
425static void torture_rtmutex_delay(struct torture_random_state *trsp)
426{
427 const unsigned long shortdelay_us = 2;
428 const unsigned long longdelay_ms = 100;
429
430 /*
431 * We want a short delay mostly to emulate likely code, and
432 * we want a long delay occasionally to force massive contention.
433 */
434 if (!(torture_random(trsp) %
435 (cxt.nrealwriters_stress * 2000 * longdelay_ms)))
436 mdelay(longdelay_ms);
437 if (!(torture_random(trsp) %
438 (cxt.nrealwriters_stress * 2 * shortdelay_us)))
439 udelay(shortdelay_us);
440#ifdef CONFIG_PREEMPT
441 if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000)))
442 preempt_schedule(); /* Allow test to be preempted. */
443#endif
444}
445
446static void torture_rtmutex_unlock(void) __releases(torture_rtmutex)
447{
448 rt_mutex_unlock(&torture_rtmutex);
449}
450
451static struct lock_torture_ops rtmutex_lock_ops = {
452 .writelock = torture_rtmutex_lock,
453 .write_delay = torture_rtmutex_delay,
454 .task_boost = torture_rtmutex_boost,
455 .writeunlock = torture_rtmutex_unlock,
456 .readlock = NULL,
457 .read_delay = NULL,
458 .readunlock = NULL,
459 .name = "rtmutex_lock"
460};
461#endif
462
Davidlohr Bueso4a3b4272014-09-11 21:41:30 -0700463static DECLARE_RWSEM(torture_rwsem);
464static int torture_rwsem_down_write(void) __acquires(torture_rwsem)
465{
466 down_write(&torture_rwsem);
467 return 0;
468}
469
470static void torture_rwsem_write_delay(struct torture_random_state *trsp)
471{
472 const unsigned long longdelay_ms = 100;
473
474 /* We want a long delay occasionally to force massive contention. */
475 if (!(torture_random(trsp) %
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700476 (cxt.nrealwriters_stress * 2000 * longdelay_ms)))
Davidlohr Bueso4a3b4272014-09-11 21:41:30 -0700477 mdelay(longdelay_ms * 10);
478 else
479 mdelay(longdelay_ms / 10);
480#ifdef CONFIG_PREEMPT
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700481 if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000)))
Davidlohr Bueso4a3b4272014-09-11 21:41:30 -0700482 preempt_schedule(); /* Allow test to be preempted. */
483#endif
484}
485
486static void torture_rwsem_up_write(void) __releases(torture_rwsem)
487{
488 up_write(&torture_rwsem);
489}
490
491static int torture_rwsem_down_read(void) __acquires(torture_rwsem)
492{
493 down_read(&torture_rwsem);
494 return 0;
495}
496
497static void torture_rwsem_read_delay(struct torture_random_state *trsp)
498{
499 const unsigned long longdelay_ms = 100;
500
501 /* We want a long delay occasionally to force massive contention. */
502 if (!(torture_random(trsp) %
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700503 (cxt.nrealwriters_stress * 2000 * longdelay_ms)))
Davidlohr Bueso4a3b4272014-09-11 21:41:30 -0700504 mdelay(longdelay_ms * 2);
505 else
506 mdelay(longdelay_ms / 2);
507#ifdef CONFIG_PREEMPT
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700508 if (!(torture_random(trsp) % (cxt.nrealreaders_stress * 20000)))
Davidlohr Bueso4a3b4272014-09-11 21:41:30 -0700509 preempt_schedule(); /* Allow test to be preempted. */
510#endif
511}
512
513static void torture_rwsem_up_read(void) __releases(torture_rwsem)
514{
515 up_read(&torture_rwsem);
516}
517
518static struct lock_torture_ops rwsem_lock_ops = {
519 .writelock = torture_rwsem_down_write,
520 .write_delay = torture_rwsem_write_delay,
Davidlohr Bueso095777c2015-07-22 14:07:27 -0700521 .task_boost = torture_boost_dummy,
Davidlohr Bueso4a3b4272014-09-11 21:41:30 -0700522 .writeunlock = torture_rwsem_up_write,
523 .readlock = torture_rwsem_down_read,
524 .read_delay = torture_rwsem_read_delay,
525 .readunlock = torture_rwsem_up_read,
526 .name = "rwsem_lock"
527};
528
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800529/*
530 * Lock torture writer kthread. Repeatedly acquires and releases
531 * the lock, checking for duplicate acquisitions.
532 */
533static int lock_torture_writer(void *arg)
534{
Davidlohr Bueso1e6757a2014-09-11 20:40:20 -0700535 struct lock_stress_stats *lwsp = arg;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800536 static DEFINE_TORTURE_RANDOM(rand);
537
538 VERBOSE_TOROUT_STRING("lock_torture_writer task started");
Dongsheng Yang8698a742014-03-11 18:09:12 +0800539 set_user_nice(current, MAX_NICE);
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800540
541 do {
Paul E. McKenneyda601c62014-02-26 12:14:51 -0800542 if ((torture_random(&rand) & 0xfffff) == 0)
543 schedule_timeout_uninterruptible(1);
Davidlohr Buesoa1229492014-09-29 06:14:25 -0700544
Davidlohr Bueso095777c2015-07-22 14:07:27 -0700545 cxt.cur_ops->task_boost(&rand);
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700546 cxt.cur_ops->writelock();
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800547 if (WARN_ON_ONCE(lock_is_write_held))
Davidlohr Bueso1e6757a2014-09-11 20:40:20 -0700548 lwsp->n_lock_fail++;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800549 lock_is_write_held = 1;
Davidlohr Buesoa1229492014-09-29 06:14:25 -0700550 if (WARN_ON_ONCE(lock_is_read_held))
551 lwsp->n_lock_fail++; /* rare, but... */
552
Davidlohr Bueso1e6757a2014-09-11 20:40:20 -0700553 lwsp->n_lock_acquired++;
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700554 cxt.cur_ops->write_delay(&rand);
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800555 lock_is_write_held = 0;
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700556 cxt.cur_ops->writeunlock();
Davidlohr Buesoa1229492014-09-29 06:14:25 -0700557
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800558 stutter_wait("lock_torture_writer");
559 } while (!torture_must_stop());
Davidlohr Bueso095777c2015-07-22 14:07:27 -0700560
561 cxt.cur_ops->task_boost(NULL); /* reset prio */
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800562 torture_kthread_stopping("lock_torture_writer");
563 return 0;
564}
565
566/*
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700567 * Lock torture reader kthread. Repeatedly acquires and releases
568 * the reader lock.
569 */
570static int lock_torture_reader(void *arg)
571{
572 struct lock_stress_stats *lrsp = arg;
573 static DEFINE_TORTURE_RANDOM(rand);
574
575 VERBOSE_TOROUT_STRING("lock_torture_reader task started");
576 set_user_nice(current, MAX_NICE);
577
578 do {
579 if ((torture_random(&rand) & 0xfffff) == 0)
580 schedule_timeout_uninterruptible(1);
Davidlohr Buesoa1229492014-09-29 06:14:25 -0700581
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700582 cxt.cur_ops->readlock();
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700583 lock_is_read_held = 1;
Davidlohr Buesoa1229492014-09-29 06:14:25 -0700584 if (WARN_ON_ONCE(lock_is_write_held))
585 lrsp->n_lock_fail++; /* rare, but... */
586
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700587 lrsp->n_lock_acquired++;
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700588 cxt.cur_ops->read_delay(&rand);
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700589 lock_is_read_held = 0;
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700590 cxt.cur_ops->readunlock();
Davidlohr Buesoa1229492014-09-29 06:14:25 -0700591
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700592 stutter_wait("lock_torture_reader");
593 } while (!torture_must_stop());
594 torture_kthread_stopping("lock_torture_reader");
595 return 0;
596}
597
598/*
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800599 * Create an lock-torture-statistics message in the specified buffer.
600 */
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700601static void __torture_print_stats(char *page,
602 struct lock_stress_stats *statp, bool write)
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800603{
604 bool fail = 0;
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700605 int i, n_stress;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800606 long max = 0;
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700607 long min = statp[0].n_lock_acquired;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800608 long long sum = 0;
609
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700610 n_stress = write ? cxt.nrealwriters_stress : cxt.nrealreaders_stress;
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700611 for (i = 0; i < n_stress; i++) {
612 if (statp[i].n_lock_fail)
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800613 fail = true;
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700614 sum += statp[i].n_lock_acquired;
615 if (max < statp[i].n_lock_fail)
616 max = statp[i].n_lock_fail;
617 if (min > statp[i].n_lock_fail)
618 min = statp[i].n_lock_fail;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800619 }
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800620 page += sprintf(page,
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700621 "%s: Total: %lld Max/Min: %ld/%ld %s Fail: %d %s\n",
622 write ? "Writes" : "Reads ",
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800623 sum, max, min, max / 2 > min ? "???" : "",
624 fail, fail ? "!!!" : "");
625 if (fail)
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700626 atomic_inc(&cxt.n_lock_torture_errors);
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800627}
628
629/*
630 * Print torture statistics. Caller must ensure that there is only one
631 * call to this function at a given time!!! This is normally accomplished
632 * by relying on the module system to only have one copy of the module
633 * loaded, and then by giving the lock_torture_stats kthread full control
634 * (or the init/cleanup functions when lock_torture_stats thread is not
635 * running).
636 */
637static void lock_torture_stats_print(void)
638{
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700639 int size = cxt.nrealwriters_stress * 200 + 8192;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800640 char *buf;
641
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700642 if (cxt.cur_ops->readlock)
643 size += cxt.nrealreaders_stress * 200 + 8192;
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700644
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800645 buf = kmalloc(size, GFP_KERNEL);
646 if (!buf) {
647 pr_err("lock_torture_stats_print: Out of memory, need: %d",
648 size);
649 return;
650 }
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700651
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700652 __torture_print_stats(buf, cxt.lwsa, true);
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800653 pr_alert("%s", buf);
654 kfree(buf);
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700655
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700656 if (cxt.cur_ops->readlock) {
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700657 buf = kmalloc(size, GFP_KERNEL);
658 if (!buf) {
659 pr_err("lock_torture_stats_print: Out of memory, need: %d",
660 size);
661 return;
662 }
663
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700664 __torture_print_stats(buf, cxt.lrsa, false);
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700665 pr_alert("%s", buf);
666 kfree(buf);
667 }
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800668}
669
670/*
671 * Periodically prints torture statistics, if periodic statistics printing
672 * was specified via the stat_interval module parameter.
673 *
674 * No need to worry about fullstop here, since this one doesn't reference
675 * volatile state or register callbacks.
676 */
677static int lock_torture_stats(void *arg)
678{
679 VERBOSE_TOROUT_STRING("lock_torture_stats task started");
680 do {
681 schedule_timeout_interruptible(stat_interval * HZ);
682 lock_torture_stats_print();
683 torture_shutdown_absorb("lock_torture_stats");
684 } while (!torture_must_stop());
685 torture_kthread_stopping("lock_torture_stats");
686 return 0;
687}
688
689static inline void
690lock_torture_print_module_parms(struct lock_torture_ops *cur_ops,
691 const char *tag)
692{
693 pr_alert("%s" TORTURE_FLAG
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700694 "--- %s%s: nwriters_stress=%d nreaders_stress=%d stat_interval=%d verbose=%d shuffle_interval=%d stutter=%d shutdown_secs=%d onoff_interval=%d onoff_holdoff=%d\n",
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700695 torture_type, tag, cxt.debug_lock ? " [debug]": "",
696 cxt.nrealwriters_stress, cxt.nrealreaders_stress, stat_interval,
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700697 verbose, shuffle_interval, stutter, shutdown_secs,
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800698 onoff_interval, onoff_holdoff);
699}
700
701static void lock_torture_cleanup(void)
702{
703 int i;
704
Davidlohr Buesod36a7a02014-09-11 20:40:21 -0700705 if (torture_cleanup_begin())
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800706 return;
707
708 if (writer_tasks) {
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700709 for (i = 0; i < cxt.nrealwriters_stress; i++)
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800710 torture_stop_kthread(lock_torture_writer,
711 writer_tasks[i]);
712 kfree(writer_tasks);
713 writer_tasks = NULL;
714 }
715
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700716 if (reader_tasks) {
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700717 for (i = 0; i < cxt.nrealreaders_stress; i++)
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700718 torture_stop_kthread(lock_torture_reader,
719 reader_tasks[i]);
720 kfree(reader_tasks);
721 reader_tasks = NULL;
722 }
723
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800724 torture_stop_kthread(lock_torture_stats, stats_task);
725 lock_torture_stats_print(); /* -After- the stats thread is stopped! */
726
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700727 if (atomic_read(&cxt.n_lock_torture_errors))
728 lock_torture_print_module_parms(cxt.cur_ops,
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800729 "End of test: FAILURE");
730 else if (torture_onoff_failures())
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700731 lock_torture_print_module_parms(cxt.cur_ops,
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800732 "End of test: LOCK_HOTPLUG");
733 else
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700734 lock_torture_print_module_parms(cxt.cur_ops,
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800735 "End of test: SUCCESS");
Davidlohr Buesod36a7a02014-09-11 20:40:21 -0700736 torture_cleanup_end();
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800737}
738
739static int __init lock_torture_init(void)
740{
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700741 int i, j;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800742 int firsterr = 0;
743 static struct lock_torture_ops *torture_ops[] = {
Davidlohr Buesoe34191f2014-09-29 06:14:23 -0700744 &lock_busted_ops,
745 &spin_lock_ops, &spin_lock_irq_ops,
746 &rw_lock_ops, &rw_lock_irq_ops,
747 &mutex_lock_ops,
Davidlohr Bueso095777c2015-07-22 14:07:27 -0700748#ifdef CONFIG_RT_MUTEXES
749 &rtmutex_lock_ops,
750#endif
Davidlohr Buesoe34191f2014-09-29 06:14:23 -0700751 &rwsem_lock_ops,
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800752 };
753
Davidlohr Bueso23a8e5c2014-09-11 20:40:16 -0700754 if (!torture_init_begin(torture_type, verbose, &torture_runnable))
Paul E. McKenney52280842014-04-07 09:14:11 -0700755 return -EBUSY;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800756
757 /* Process args and tell the world that the torturer is on the job. */
758 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700759 cxt.cur_ops = torture_ops[i];
760 if (strcmp(torture_type, cxt.cur_ops->name) == 0)
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800761 break;
762 }
763 if (i == ARRAY_SIZE(torture_ops)) {
764 pr_alert("lock-torture: invalid torture type: \"%s\"\n",
765 torture_type);
766 pr_alert("lock-torture types:");
767 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
768 pr_alert(" %s", torture_ops[i]->name);
769 pr_alert("\n");
770 torture_init_end();
771 return -EINVAL;
772 }
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700773 if (cxt.cur_ops->init)
774 cxt.cur_ops->init(); /* no "goto unwind" prior to this point!!! */
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800775
776 if (nwriters_stress >= 0)
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700777 cxt.nrealwriters_stress = nwriters_stress;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800778 else
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700779 cxt.nrealwriters_stress = 2 * num_online_cpus();
Davidlohr Buesof095bfc2014-09-11 20:40:19 -0700780
781#ifdef CONFIG_DEBUG_MUTEXES
782 if (strncmp(torture_type, "mutex", 5) == 0)
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700783 cxt.debug_lock = true;
Davidlohr Buesof095bfc2014-09-11 20:40:19 -0700784#endif
Davidlohr Bueso095777c2015-07-22 14:07:27 -0700785#ifdef CONFIG_DEBUG_RT_MUTEXES
786 if (strncmp(torture_type, "rtmutex", 7) == 0)
787 cxt.debug_lock = true;
788#endif
Davidlohr Buesof095bfc2014-09-11 20:40:19 -0700789#ifdef CONFIG_DEBUG_SPINLOCK
Davidlohr Buesoe34191f2014-09-29 06:14:23 -0700790 if ((strncmp(torture_type, "spin", 4) == 0) ||
791 (strncmp(torture_type, "rw_lock", 7) == 0))
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700792 cxt.debug_lock = true;
Davidlohr Buesof095bfc2014-09-11 20:40:19 -0700793#endif
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800794
795 /* Initialize the statistics so that each run gets its own numbers. */
796
797 lock_is_write_held = 0;
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700798 cxt.lwsa = kmalloc(sizeof(*cxt.lwsa) * cxt.nrealwriters_stress, GFP_KERNEL);
799 if (cxt.lwsa == NULL) {
800 VERBOSE_TOROUT_STRING("cxt.lwsa: Out of memory");
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800801 firsterr = -ENOMEM;
802 goto unwind;
803 }
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700804 for (i = 0; i < cxt.nrealwriters_stress; i++) {
805 cxt.lwsa[i].n_lock_fail = 0;
806 cxt.lwsa[i].n_lock_acquired = 0;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800807 }
808
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700809 if (cxt.cur_ops->readlock) {
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700810 if (nreaders_stress >= 0)
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700811 cxt.nrealreaders_stress = nreaders_stress;
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700812 else {
813 /*
814 * By default distribute evenly the number of
815 * readers and writers. We still run the same number
816 * of threads as the writer-only locks default.
817 */
818 if (nwriters_stress < 0) /* user doesn't care */
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700819 cxt.nrealwriters_stress = num_online_cpus();
820 cxt.nrealreaders_stress = cxt.nrealwriters_stress;
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700821 }
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800822
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700823 lock_is_read_held = 0;
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700824 cxt.lrsa = kmalloc(sizeof(*cxt.lrsa) * cxt.nrealreaders_stress, GFP_KERNEL);
825 if (cxt.lrsa == NULL) {
826 VERBOSE_TOROUT_STRING("cxt.lrsa: Out of memory");
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700827 firsterr = -ENOMEM;
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700828 kfree(cxt.lwsa);
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700829 goto unwind;
830 }
831
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700832 for (i = 0; i < cxt.nrealreaders_stress; i++) {
833 cxt.lrsa[i].n_lock_fail = 0;
834 cxt.lrsa[i].n_lock_acquired = 0;
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700835 }
836 }
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700837 lock_torture_print_module_parms(cxt.cur_ops, "Start of test");
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700838
839 /* Prepare torture context. */
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800840 if (onoff_interval > 0) {
841 firsterr = torture_onoff_init(onoff_holdoff * HZ,
842 onoff_interval * HZ);
843 if (firsterr)
844 goto unwind;
845 }
846 if (shuffle_interval > 0) {
847 firsterr = torture_shuffle_init(shuffle_interval);
848 if (firsterr)
849 goto unwind;
850 }
851 if (shutdown_secs > 0) {
852 firsterr = torture_shutdown_init(shutdown_secs,
853 lock_torture_cleanup);
854 if (firsterr)
855 goto unwind;
856 }
857 if (stutter > 0) {
858 firsterr = torture_stutter_init(stutter);
859 if (firsterr)
860 goto unwind;
861 }
862
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700863 writer_tasks = kzalloc(cxt.nrealwriters_stress * sizeof(writer_tasks[0]),
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800864 GFP_KERNEL);
865 if (writer_tasks == NULL) {
866 VERBOSE_TOROUT_ERRSTRING("writer_tasks: Out of memory");
867 firsterr = -ENOMEM;
868 goto unwind;
869 }
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700870
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700871 if (cxt.cur_ops->readlock) {
872 reader_tasks = kzalloc(cxt.nrealreaders_stress * sizeof(reader_tasks[0]),
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700873 GFP_KERNEL);
874 if (reader_tasks == NULL) {
875 VERBOSE_TOROUT_ERRSTRING("reader_tasks: Out of memory");
876 firsterr = -ENOMEM;
877 goto unwind;
878 }
879 }
880
881 /*
882 * Create the kthreads and start torturing (oh, those poor little locks).
883 *
884 * TODO: Note that we interleave writers with readers, giving writers a
885 * slight advantage, by creating its kthread first. This can be modified
886 * for very specific needs, or even let the user choose the policy, if
887 * ever wanted.
888 */
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700889 for (i = 0, j = 0; i < cxt.nrealwriters_stress ||
890 j < cxt.nrealreaders_stress; i++, j++) {
891 if (i >= cxt.nrealwriters_stress)
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700892 goto create_reader;
893
894 /* Create writer. */
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700895 firsterr = torture_create_kthread(lock_torture_writer, &cxt.lwsa[i],
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800896 writer_tasks[i]);
897 if (firsterr)
898 goto unwind;
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700899
900 create_reader:
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700901 if (cxt.cur_ops->readlock == NULL || (j >= cxt.nrealreaders_stress))
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700902 continue;
903 /* Create reader. */
Davidlohr Bueso630952c2014-09-11 21:42:25 -0700904 firsterr = torture_create_kthread(lock_torture_reader, &cxt.lrsa[j],
Davidlohr Bueso4f6332c2014-09-11 21:40:41 -0700905 reader_tasks[j]);
906 if (firsterr)
907 goto unwind;
Paul E. McKenney0af3fe12014-02-04 15:51:41 -0800908 }
909 if (stat_interval > 0) {
910 firsterr = torture_create_kthread(lock_torture_stats, NULL,
911 stats_task);
912 if (firsterr)
913 goto unwind;
914 }
915 torture_init_end();
916 return 0;
917
918unwind:
919 torture_init_end();
920 lock_torture_cleanup();
921 return firsterr;
922}
923
924module_init(lock_torture_init);
925module_exit(lock_torture_cleanup);