locktorture.c (62731433591156ece255e23ffd69ea4544b424f1) locktorture.c (e34191fad8e5d9fe4e76f6d03b5e29e3eae7535a)
1/*
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 *

--- 13 unchanged lines hidden (view full) ---

22 */
23#include <linux/types.h>
24#include <linux/kernel.h>
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/kthread.h>
28#include <linux/err.h>
29#include <linux/spinlock.h>
1/*
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 *

--- 13 unchanged lines hidden (view full) ---

22 */
23#include <linux/types.h>
24#include <linux/kernel.h>
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/kthread.h>
28#include <linux/err.h>
29#include <linux/spinlock.h>
30#include <linux/rwlock.h>
30#include <linux/mutex.h>
31#include <linux/smp.h>
32#include <linux/interrupt.h>
33#include <linux/sched.h>
34#include <linux/atomic.h>
35#include <linux/bitops.h>
36#include <linux/completion.h>
37#include <linux/moduleparam.h>

--- 186 unchanged lines hidden (view full) ---

224 .write_delay = torture_spin_lock_write_delay,
225 .writeunlock = torture_lock_spin_write_unlock_irq,
226 .readlock = NULL,
227 .read_delay = NULL,
228 .readunlock = NULL,
229 .name = "spin_lock_irq"
230};
231
31#include <linux/mutex.h>
32#include <linux/smp.h>
33#include <linux/interrupt.h>
34#include <linux/sched.h>
35#include <linux/atomic.h>
36#include <linux/bitops.h>
37#include <linux/completion.h>
38#include <linux/moduleparam.h>

--- 186 unchanged lines hidden (view full) ---

225 .write_delay = torture_spin_lock_write_delay,
226 .writeunlock = torture_lock_spin_write_unlock_irq,
227 .readlock = NULL,
228 .read_delay = NULL,
229 .readunlock = NULL,
230 .name = "spin_lock_irq"
231};
232
233static 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,
290 .writeunlock = torture_rwlock_write_unlock,
291 .readlock = torture_rwlock_read_lock,
292 .read_delay = torture_rwlock_read_delay,
293 .readunlock = torture_rwlock_read_unlock,
294 .name = "rw_lock"
295};
296
297static int torture_rwlock_write_lock_irq(void) __acquires(torture_rwlock)
298{
299 unsigned long flags;
300
301 write_lock_irqsave(&torture_rwlock, flags);
302 cxt.cur_ops->flags = flags;
303 return 0;
304}
305
306static void torture_rwlock_write_unlock_irq(void)
307__releases(torture_rwlock)
308{
309 write_unlock_irqrestore(&torture_rwlock, cxt.cur_ops->flags);
310}
311
312static int torture_rwlock_read_lock_irq(void) __acquires(torture_rwlock)
313{
314 unsigned long flags;
315
316 read_lock_irqsave(&torture_rwlock, flags);
317 cxt.cur_ops->flags = flags;
318 return 0;
319}
320
321static void torture_rwlock_read_unlock_irq(void)
322__releases(torture_rwlock)
323{
324 write_unlock_irqrestore(&torture_rwlock, cxt.cur_ops->flags);
325}
326
327static struct lock_torture_ops rw_lock_irq_ops = {
328 .writelock = torture_rwlock_write_lock_irq,
329 .write_delay = torture_rwlock_write_delay,
330 .writeunlock = torture_rwlock_write_unlock_irq,
331 .readlock = torture_rwlock_read_lock_irq,
332 .read_delay = torture_rwlock_read_delay,
333 .readunlock = torture_rwlock_read_unlock_irq,
334 .name = "rw_lock_irq"
335};
336
232static DEFINE_MUTEX(torture_mutex);
233
234static int torture_mutex_lock(void) __acquires(torture_mutex)
235{
236 mutex_lock(&torture_mutex);
237 return 0;
238}
239

--- 290 unchanged lines hidden (view full) ---

530 torture_cleanup_end();
531}
532
533static int __init lock_torture_init(void)
534{
535 int i, j;
536 int firsterr = 0;
537 static struct lock_torture_ops *torture_ops[] = {
337static DEFINE_MUTEX(torture_mutex);
338
339static int torture_mutex_lock(void) __acquires(torture_mutex)
340{
341 mutex_lock(&torture_mutex);
342 return 0;
343}
344

--- 290 unchanged lines hidden (view full) ---

635 torture_cleanup_end();
636}
637
638static int __init lock_torture_init(void)
639{
640 int i, j;
641 int firsterr = 0;
642 static struct lock_torture_ops *torture_ops[] = {
538 &lock_busted_ops, &spin_lock_ops, &spin_lock_irq_ops,
539 &mutex_lock_ops, &rwsem_lock_ops,
643 &lock_busted_ops,
644 &spin_lock_ops, &spin_lock_irq_ops,
645 &rw_lock_ops, &rw_lock_irq_ops,
646 &mutex_lock_ops,
647 &rwsem_lock_ops,
540 };
541
542 if (!torture_init_begin(torture_type, verbose, &torture_runnable))
543 return -EBUSY;
544
545 /* Process args and tell the world that the torturer is on the job. */
546 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
547 cxt.cur_ops = torture_ops[i];

--- 18 unchanged lines hidden (view full) ---

566 else
567 cxt.nrealwriters_stress = 2 * num_online_cpus();
568
569#ifdef CONFIG_DEBUG_MUTEXES
570 if (strncmp(torture_type, "mutex", 5) == 0)
571 cxt.debug_lock = true;
572#endif
573#ifdef CONFIG_DEBUG_SPINLOCK
648 };
649
650 if (!torture_init_begin(torture_type, verbose, &torture_runnable))
651 return -EBUSY;
652
653 /* Process args and tell the world that the torturer is on the job. */
654 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
655 cxt.cur_ops = torture_ops[i];

--- 18 unchanged lines hidden (view full) ---

674 else
675 cxt.nrealwriters_stress = 2 * num_online_cpus();
676
677#ifdef CONFIG_DEBUG_MUTEXES
678 if (strncmp(torture_type, "mutex", 5) == 0)
679 cxt.debug_lock = true;
680#endif
681#ifdef CONFIG_DEBUG_SPINLOCK
574 if (strncmp(torture_type, "spin", 4) == 0)
682 if ((strncmp(torture_type, "spin", 4) == 0) ||
683 (strncmp(torture_type, "rw_lock", 7) == 0))
575 cxt.debug_lock = true;
576#endif
577
578 /* Initialize the statistics so that each run gets its own numbers. */
579
580 lock_is_write_held = 0;
581 cxt.lwsa = kmalloc(sizeof(*cxt.lwsa) * cxt.nrealwriters_stress, GFP_KERNEL);
582 if (cxt.lwsa == NULL) {

--- 126 unchanged lines hidden ---
684 cxt.debug_lock = true;
685#endif
686
687 /* Initialize the statistics so that each run gets its own numbers. */
688
689 lock_is_write_held = 0;
690 cxt.lwsa = kmalloc(sizeof(*cxt.lwsa) * cxt.nrealwriters_stress, GFP_KERNEL);
691 if (cxt.lwsa == NULL) {

--- 126 unchanged lines hidden ---