Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
locking-selftest.c File Reference
#include <linux/rwsem.h>
#include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/lockdep.h>
#include <linux/spinlock.h>
#include <linux/kallsyms.h>
#include <linux/interrupt.h>
#include <linux/debug_locks.h>
#include <linux/irqflags.h>
#include "locking-selftest-spin.h"
#include "locking-selftest-wlock.h"
#include "locking-selftest-rlock.h"
#include "locking-selftest-mutex.h"
#include "locking-selftest-wsem.h"
#include "locking-selftest-rsem.h"
#include "locking-selftest-spin-hardirq.h"
#include "locking-selftest-rlock-hardirq.h"
#include "locking-selftest-wlock-hardirq.h"
#include "locking-selftest-spin-softirq.h"
#include "locking-selftest-rlock-softirq.h"
#include "locking-selftest-wlock-softirq.h"
#include "locking-selftest-hardirq.h"
#include "locking-selftest-softirq.h"

Go to the source code of this file.

Macros

#define FAILURE   0
 
#define SUCCESS   1
 
#define LOCKTYPE_SPIN   0x1
 
#define LOCKTYPE_RWLOCK   0x2
 
#define LOCKTYPE_MUTEX   0x4
 
#define LOCKTYPE_RWSEM   0x8
 
#define INIT_CLASS_FUNC(class)
 
#define HARDIRQ_DISABLE   local_irq_disable
 
#define HARDIRQ_ENABLE   local_irq_enable
 
#define HARDIRQ_ENTER()
 
#define HARDIRQ_EXIT()
 
#define SOFTIRQ_DISABLE   local_bh_disable
 
#define SOFTIRQ_ENABLE   local_bh_enable
 
#define SOFTIRQ_ENTER()
 
#define SOFTIRQ_EXIT()
 
#define L(x)   spin_lock(&lock_##x)
 
#define U(x)   spin_unlock(&lock_##x)
 
#define LU(x)   L(x); U(x)
 
#define SI(x)   spin_lock_init(&lock_##x)
 
#define WL(x)   write_lock(&rwlock_##x)
 
#define WU(x)   write_unlock(&rwlock_##x)
 
#define WLU(x)   WL(x); WU(x)
 
#define RL(x)   read_lock(&rwlock_##x)
 
#define RU(x)   read_unlock(&rwlock_##x)
 
#define RLU(x)   RL(x); RU(x)
 
#define RWI(x)   rwlock_init(&rwlock_##x)
 
#define ML(x)   mutex_lock(&mutex_##x)
 
#define MU(x)   mutex_unlock(&mutex_##x)
 
#define MI(x)   mutex_init(&mutex_##x)
 
#define WSL(x)   down_write(&rwsem_##x)
 
#define WSU(x)   up_write(&rwsem_##x)
 
#define RSL(x)   down_read(&rwsem_##x)
 
#define RSU(x)   up_read(&rwsem_##x)
 
#define RWSI(x)   init_rwsem(&rwsem_##x)
 
#define LOCK_UNLOCK_2(x, y)   LOCK(x); LOCK(y); UNLOCK(y); UNLOCK(x)
 
#define GENERATE_TESTCASE(name)
 
#define GENERATE_PERMUTATIONS_2_EVENTS(name)
 
#define GENERATE_PERMUTATIONS_3_EVENTS(name)
 
#define E()
 
#define E()
 
#define E()
 
#define E()
 
#define E()
 
#define E()
 
#define E()
 
#define E()
 
#define E()
 
#define E()
 
#define E1()
 
#define E2()
 
#define E1()
 
#define E2()
 
#define E1()
 
#define E2()
 
#define E1()
 
#define E2()
 
#define E3()
 
#define E1()
 
#define E2()
 
#define E3()
 
#define E1()
 
#define E2()
 
#define E3()
 
#define E1()
 
#define E2()
 
#define E3()
 
#define E1()
 
#define E2()
 
#define E3()
 
#define I_SPINLOCK(x)
 
#define I_RWLOCK(x)
 
#define I_MUTEX(x)
 
#define I_RWSEM(x)
 
#define I1(x)
 
#define I2(x)
 
#define DO_TESTCASE_1(desc, name, nr)
 
#define DO_TESTCASE_1B(desc, name, nr)
 
#define DO_TESTCASE_3(desc, name, nr)
 
#define DO_TESTCASE_3RW(desc, name, nr)
 
#define DO_TESTCASE_6(desc, name)
 
#define DO_TESTCASE_6_SUCCESS(desc, name)
 
#define DO_TESTCASE_6R(desc, name)
 
#define DO_TESTCASE_2I(desc, name, nr)
 
#define DO_TESTCASE_2IB(desc, name, nr)
 
#define DO_TESTCASE_6I(desc, name, nr)
 
#define DO_TESTCASE_6IRW(desc, name, nr)
 
#define DO_TESTCASE_2x3(desc, name)
 
#define DO_TESTCASE_2x6(desc, name)
 
#define DO_TESTCASE_6x2(desc, name)
 
#define DO_TESTCASE_6x2B(desc, name)
 
#define DO_TESTCASE_6x6(desc, name)
 
#define DO_TESTCASE_6x6RW(desc, name)
 

Functions

 __setup ("debug_locks_verbose=", setup_debug_locks_verbose)
 
void locking_selftest (void)
 

Macro Definition Documentation

#define DO_TESTCASE_1 (   desc,
  name,
  nr 
)
Value:
print_testname(desc"/"#nr); \
dotest(name##_##nr, SUCCESS, LOCKTYPE_RWLOCK); \
printk("\n");

Definition at line 998 of file locking-selftest.c.

#define DO_TESTCASE_1B (   desc,
  name,
  nr 
)
Value:
print_testname(desc"/"#nr); \
dotest(name##_##nr, FAILURE, LOCKTYPE_RWLOCK); \
printk("\n");

Definition at line 1003 of file locking-selftest.c.

#define DO_TESTCASE_2I (   desc,
  name,
  nr 
)
Value:
DO_TESTCASE_1("hard-"desc, name##_hard, nr); \
DO_TESTCASE_1("soft-"desc, name##_soft, nr);

Definition at line 1055 of file locking-selftest.c.

#define DO_TESTCASE_2IB (   desc,
  name,
  nr 
)
Value:
DO_TESTCASE_1B("hard-"desc, name##_hard, nr); \
DO_TESTCASE_1B("soft-"desc, name##_soft, nr);

Definition at line 1059 of file locking-selftest.c.

#define DO_TESTCASE_2x3 (   desc,
  name 
)
Value:
DO_TESTCASE_3(desc, name, 21);

Definition at line 1071 of file locking-selftest.c.

#define DO_TESTCASE_2x6 (   desc,
  name 
)
Value:
DO_TESTCASE_6I(desc, name, 21);

Definition at line 1075 of file locking-selftest.c.

#define DO_TESTCASE_3 (   desc,
  name,
  nr 
)
Value:
print_testname(desc"/"#nr); \
dotest(name##_spin_##nr, FAILURE, LOCKTYPE_SPIN); \
dotest(name##_wlock_##nr, FAILURE, LOCKTYPE_RWLOCK); \
dotest(name##_rlock_##nr, SUCCESS, LOCKTYPE_RWLOCK); \
printk("\n");

Definition at line 1008 of file locking-selftest.c.

#define DO_TESTCASE_3RW (   desc,
  name,
  nr 
)
Value:
print_testname(desc"/"#nr); \
dotest(name##_wlock_##nr, FAILURE, LOCKTYPE_RWLOCK); \
dotest(name##_rlock_##nr, SUCCESS, LOCKTYPE_RWLOCK); \
printk("\n");

Definition at line 1015 of file locking-selftest.c.

#define DO_TESTCASE_6 (   desc,
  name 
)
Value:
print_testname(desc); \
dotest(name##_spin, FAILURE, LOCKTYPE_SPIN); \
dotest(name##_wlock, FAILURE, LOCKTYPE_RWLOCK); \
dotest(name##_rlock, FAILURE, LOCKTYPE_RWLOCK); \
dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \
dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \
dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM); \
printk("\n");

Definition at line 1022 of file locking-selftest.c.

#define DO_TESTCASE_6_SUCCESS (   desc,
  name 
)
Value:
print_testname(desc); \
dotest(name##_spin, SUCCESS, LOCKTYPE_SPIN); \
dotest(name##_wlock, SUCCESS, LOCKTYPE_RWLOCK); \
dotest(name##_rlock, SUCCESS, LOCKTYPE_RWLOCK); \
dotest(name##_mutex, SUCCESS, LOCKTYPE_MUTEX); \
dotest(name##_wsem, SUCCESS, LOCKTYPE_RWSEM); \
dotest(name##_rsem, SUCCESS, LOCKTYPE_RWSEM); \
printk("\n");

Definition at line 1032 of file locking-selftest.c.

#define DO_TESTCASE_6I (   desc,
  name,
  nr 
)
Value:
DO_TESTCASE_3("hard-"desc, name##_hard, nr); \
DO_TESTCASE_3("soft-"desc, name##_soft, nr);

Definition at line 1063 of file locking-selftest.c.

#define DO_TESTCASE_6IRW (   desc,
  name,
  nr 
)
Value:
DO_TESTCASE_3RW("hard-"desc, name##_hard, nr); \
DO_TESTCASE_3RW("soft-"desc, name##_soft, nr);

Definition at line 1067 of file locking-selftest.c.

#define DO_TESTCASE_6R (   desc,
  name 
)
Value:
print_testname(desc); \
dotest(name##_spin, FAILURE, LOCKTYPE_SPIN); \
dotest(name##_wlock, FAILURE, LOCKTYPE_RWLOCK); \
dotest(name##_rlock, SUCCESS, LOCKTYPE_RWLOCK); \
dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \
dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \
dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM); \
printk("\n");

Definition at line 1045 of file locking-selftest.c.

#define DO_TESTCASE_6x2 (   desc,
  name 
)
Value:
DO_TESTCASE_2I(desc, name, 132); \
DO_TESTCASE_2I(desc, name, 213); \
DO_TESTCASE_2I(desc, name, 231); \
DO_TESTCASE_2I(desc, name, 312); \
DO_TESTCASE_2I(desc, name, 321);

Definition at line 1079 of file locking-selftest.c.

#define DO_TESTCASE_6x2B (   desc,
  name 
)
Value:
DO_TESTCASE_2IB(desc, name, 132); \
DO_TESTCASE_2IB(desc, name, 213); \
DO_TESTCASE_2IB(desc, name, 231); \
DO_TESTCASE_2IB(desc, name, 312); \
DO_TESTCASE_2IB(desc, name, 321);

Definition at line 1087 of file locking-selftest.c.

#define DO_TESTCASE_6x6 (   desc,
  name 
)
Value:
DO_TESTCASE_6I(desc, name, 132); \
DO_TESTCASE_6I(desc, name, 213); \
DO_TESTCASE_6I(desc, name, 231); \
DO_TESTCASE_6I(desc, name, 312); \
DO_TESTCASE_6I(desc, name, 321);

Definition at line 1095 of file locking-selftest.c.

#define DO_TESTCASE_6x6RW (   desc,
  name 
)
Value:
DO_TESTCASE_6IRW(desc, name, 132); \
DO_TESTCASE_6IRW(desc, name, 213); \
DO_TESTCASE_6IRW(desc, name, 231); \
DO_TESTCASE_6IRW(desc, name, 312); \
DO_TESTCASE_6IRW(desc, name, 321);

Definition at line 1103 of file locking-selftest.c.

#define E ( )
Value:
\
LOCK(X1); \
LOCK(X2); /* this one should fail */

Definition at line 528 of file locking-selftest.c.

#define E ( )
Value:
\
LOCK_UNLOCK_2(A, B); \
LOCK_UNLOCK_2(B, A); /* fail */

Definition at line 528 of file locking-selftest.c.

#define E ( )
Value:
\
LOCK_UNLOCK_2(A, B); \
LOCK_UNLOCK_2(B, C); \
LOCK_UNLOCK_2(C, A); /* fail */

Definition at line 528 of file locking-selftest.c.

#define E ( )
Value:
\
LOCK_UNLOCK_2(A, B); \
LOCK_UNLOCK_2(C, A); \
LOCK_UNLOCK_2(B, C); /* fail */

Definition at line 528 of file locking-selftest.c.

#define E ( )
Value:
\
LOCK_UNLOCK_2(A, B); \
LOCK_UNLOCK_2(B, C); \
LOCK_UNLOCK_2(C, D); \
LOCK_UNLOCK_2(D, A); /* fail */

Definition at line 528 of file locking-selftest.c.

#define E ( )
Value:
\
LOCK_UNLOCK_2(A, B); \
LOCK_UNLOCK_2(C, D); \
LOCK_UNLOCK_2(B, D); \
LOCK_UNLOCK_2(D, A); /* fail */

Definition at line 528 of file locking-selftest.c.

#define E ( )
Value:
\
LOCK_UNLOCK_2(A, B); \
LOCK_UNLOCK_2(C, D); \
LOCK_UNLOCK_2(B, C); \
LOCK_UNLOCK_2(D, A); /* fail */

Definition at line 528 of file locking-selftest.c.

#define E ( )
Value:
\
LOCK(A); \
UNLOCK(A); \
UNLOCK(A); /* fail */

Definition at line 528 of file locking-selftest.c.

#define E ( )
Value:
\
LOCK(A); \
LOCK(B); \
UNLOCK(A); /* fail */ \
UNLOCK(B);

Definition at line 528 of file locking-selftest.c.

#define E ( )
Value:
\
LOCK(A); \
INIT(A); /* fail */

Definition at line 528 of file locking-selftest.c.

#define E1 ( )
Value:
\
IRQ_ENTER(); \
LOCK(A); \
UNLOCK(A); \
IRQ_EXIT();

Definition at line 862 of file locking-selftest.c.

#define E1 ( )
Value:
\
SOFTIRQ_ENTER(); \
LOCK(A); \
UNLOCK(A); \
SOFTIRQ_EXIT();

Definition at line 862 of file locking-selftest.c.

#define E1 ( )
Value:
\
IRQ_ENTER(); \
LOCK(A); \
UNLOCK(A); \
IRQ_EXIT();

Definition at line 862 of file locking-selftest.c.

#define E1 ( )
Value:
\
LOCK(A); \
LOCK(B); \
UNLOCK(B); \
UNLOCK(A); \

Definition at line 862 of file locking-selftest.c.

#define E1 ( )
Value:
LOCK(A); \
LOCK(B); \
UNLOCK(B); \
UNLOCK(A); \
IRQ_ENABLE();

Definition at line 862 of file locking-selftest.c.

#define E1 ( )
Value:
\
IRQ_DISABLE(); \
WL(A); \
LOCK(B); \
UNLOCK(B); \
WU(A); \
IRQ_ENABLE();

Definition at line 862 of file locking-selftest.c.

#define E1 ( )
Value:
\
IRQ_DISABLE(); \
WL(A); \
WU(A); \
IRQ_ENABLE();

Definition at line 862 of file locking-selftest.c.

#define E1 ( )
Value:
\
IRQ_DISABLE(); \
L(B); \
WL(A); \
WU(A); \
U(B); \
IRQ_ENABLE();

Definition at line 862 of file locking-selftest.c.

#define E2 ( )
Value:
\
LOCK(A); \
UNLOCK(A);

Definition at line 871 of file locking-selftest.c.

#define E2 ( )
Value:
\
HARDIRQ_DISABLE(); \
LOCK(A); \
HARDIRQ_ENABLE(); \
UNLOCK(A);

Definition at line 871 of file locking-selftest.c.

#define E2 ( )
Value:
\
IRQ_DISABLE(); \
LOCK(A); \
IRQ_ENABLE(); \
UNLOCK(A);

Definition at line 871 of file locking-selftest.c.

#define E2 ( )
Value:
\
LOCK(B); \
UNLOCK(B);

Definition at line 871 of file locking-selftest.c.

#define E2 ( )
Value:
LOCK(B); \
UNLOCK(B);

Definition at line 871 of file locking-selftest.c.

#define E2 ( )
Value:
\
LOCK(B); \
UNLOCK(B);

Definition at line 871 of file locking-selftest.c.

#define E2 ( )
Value:
\
RL(A); \
RU(A); \

Definition at line 871 of file locking-selftest.c.

#define E2 ( )
Value:
\
RL(A); \
RU(A); \

Definition at line 871 of file locking-selftest.c.

#define E3 ( )
Value:
\
IRQ_ENTER(); \
LOCK(A); \
UNLOCK(A); \
IRQ_EXIT();

Definition at line 876 of file locking-selftest.c.

#define E3 ( )
Value:
LOCK(A); \
UNLOCK(A); \
IRQ_EXIT();

Definition at line 876 of file locking-selftest.c.

#define E3 ( )
Value:
\
IRQ_ENTER(); \
RL(A); \
RU(A); \
IRQ_EXIT();

Definition at line 876 of file locking-selftest.c.

#define E3 ( )
Value:
\
IRQ_ENTER(); \
RL(A); \
L(B); \
U(B); \
RU(A); \
IRQ_EXIT();

Definition at line 876 of file locking-selftest.c.

#define E3 ( )
Value:
\
IRQ_ENTER(); \
L(B); \
U(B); \
IRQ_EXIT();

Definition at line 876 of file locking-selftest.c.

#define FAILURE   0

Definition at line 38 of file locking-selftest.c.

#define GENERATE_PERMUTATIONS_2_EVENTS (   name)
Value:
\
static void name##_12(void) { E1(); E2(); } \
static void name##_21(void) { E2(); E1(); }

Definition at line 207 of file locking-selftest.c.

#define GENERATE_PERMUTATIONS_3_EVENTS (   name)
Value:
\
static void name##_123(void) { E1(); E2(); E3(); } \
static void name##_132(void) { E1(); E3(); E2(); } \
static void name##_213(void) { E2(); E1(); E3(); } \
static void name##_231(void) { E2(); E3(); E1(); } \
static void name##_312(void) { E3(); E1(); E2(); } \
static void name##_321(void) { E3(); E2(); E1(); }

Definition at line 212 of file locking-selftest.c.

#define GENERATE_TESTCASE (   name)
Value:
\
static void name(void) { E(); }

Definition at line 203 of file locking-selftest.c.

#define HARDIRQ_DISABLE   local_irq_disable

Definition at line 141 of file locking-selftest.c.

#define HARDIRQ_ENABLE   local_irq_enable

Definition at line 142 of file locking-selftest.c.

#define HARDIRQ_ENTER ( )
Value:
__irq_enter(); \
WARN_ON(!in_irq());

Definition at line 144 of file locking-selftest.c.

#define HARDIRQ_EXIT ( )
Value:
local_irq_enable();

Definition at line 149 of file locking-selftest.c.

#define I1 (   x)
Value:
do { \
I_SPINLOCK(x); \
I_RWLOCK(x); \
I_MUTEX(x); \
I_RWSEM(x); \
} while (0)

Definition at line 904 of file locking-selftest.c.

#define I2 (   x)
Value:
do { \
spin_lock_init(&lock_##x); \
rwlock_init(&rwlock_##x); \
mutex_init(&mutex_##x); \
init_rwsem(&rwsem_##x); \
} while (0)

Definition at line 912 of file locking-selftest.c.

#define I_MUTEX (   x)

Definition at line 900 of file locking-selftest.c.

#define I_RWLOCK (   x)

Definition at line 899 of file locking-selftest.c.

#define I_RWSEM (   x)

Definition at line 901 of file locking-selftest.c.

#define I_SPINLOCK (   x)

Definition at line 898 of file locking-selftest.c.

#define INIT_CLASS_FUNC (   class)
Value:
static noinline void \
init_class_##class(spinlock_t *lock, rwlock_t *rwlock, struct mutex *mutex, \
{ \
spin_lock_init(lock); \
rwlock_init(rwlock); \
mutex_init(mutex); \
init_rwsem(rwsem); \
}

Definition at line 108 of file locking-selftest.c.

#define L (   x)    spin_lock(&lock_##x)

Definition at line 171 of file locking-selftest.c.

#define LOCK_UNLOCK_2 (   x,
  y 
)    LOCK(x); LOCK(y); UNLOCK(y); UNLOCK(x)

Definition at line 196 of file locking-selftest.c.

#define LOCKTYPE_MUTEX   0x4

Definition at line 43 of file locking-selftest.c.

#define LOCKTYPE_RWLOCK   0x2

Definition at line 42 of file locking-selftest.c.

#define LOCKTYPE_RWSEM   0x8

Definition at line 44 of file locking-selftest.c.

#define LOCKTYPE_SPIN   0x1

Definition at line 41 of file locking-selftest.c.

#define LU (   x)    L(x); U(x)

Definition at line 173 of file locking-selftest.c.

#define MI (   x)    mutex_init(&mutex_##x)

Definition at line 187 of file locking-selftest.c.

#define ML (   x)    mutex_lock(&mutex_##x)

Definition at line 185 of file locking-selftest.c.

#define MU (   x)    mutex_unlock(&mutex_##x)

Definition at line 186 of file locking-selftest.c.

#define RL (   x)    read_lock(&rwlock_##x)

Definition at line 180 of file locking-selftest.c.

#define RLU (   x)    RL(x); RU(x)

Definition at line 182 of file locking-selftest.c.

#define RSL (   x)    down_read(&rwsem_##x)

Definition at line 192 of file locking-selftest.c.

#define RSU (   x)    up_read(&rwsem_##x)

Definition at line 193 of file locking-selftest.c.

#define RU (   x)    read_unlock(&rwlock_##x)

Definition at line 181 of file locking-selftest.c.

#define RWI (   x)    rwlock_init(&rwlock_##x)

Definition at line 183 of file locking-selftest.c.

#define RWSI (   x)    init_rwsem(&rwsem_##x)

Definition at line 194 of file locking-selftest.c.

#define SI (   x)    spin_lock_init(&lock_##x)

Definition at line 174 of file locking-selftest.c.

#define SOFTIRQ_DISABLE   local_bh_disable

Definition at line 153 of file locking-selftest.c.

#define SOFTIRQ_ENABLE   local_bh_enable

Definition at line 154 of file locking-selftest.c.

#define SOFTIRQ_ENTER ( )
Value:
local_irq_disable(); \
lockdep_softirq_enter(); \
WARN_ON(!in_softirq());

Definition at line 156 of file locking-selftest.c.

#define SOFTIRQ_EXIT ( )
Value:
local_irq_enable(); \
local_bh_enable();

Definition at line 162 of file locking-selftest.c.

#define SUCCESS   1

Definition at line 39 of file locking-selftest.c.

#define U (   x)    spin_unlock(&lock_##x)

Definition at line 172 of file locking-selftest.c.

#define WL (   x)    write_lock(&rwlock_##x)

Definition at line 176 of file locking-selftest.c.

#define WLU (   x)    WL(x); WU(x)

Definition at line 178 of file locking-selftest.c.

#define WSL (   x)    down_write(&rwsem_##x)

Definition at line 189 of file locking-selftest.c.

#define WSU (   x)    up_write(&rwsem_##x)

Definition at line 190 of file locking-selftest.c.

#define WU (   x)    write_unlock(&rwlock_##x)

Definition at line 177 of file locking-selftest.c.

Function Documentation

__setup ( )
void locking_selftest ( void  )

Definition at line 1112 of file locking-selftest.c.