Skip to content

Commit 018956d

Browse files
Peter Zijlstraingomolnar
authored andcommitted
locking/selftest: Add RT-mutex support
Now that RT-mutex has lockdep annotations, add them to the selftest. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent cfb6133 commit 018956d

2 files changed

Lines changed: 117 additions & 0 deletions

File tree

‎lib/locking-selftest-rtmutex.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#undef LOCK
2+
#define LOCK RTL
3+
4+
#undef UNLOCK
5+
#define UNLOCK RTU
6+
7+
#undef RLOCK
8+
#undef WLOCK
9+
10+
#undef INIT
11+
#define INIT RTI

‎lib/locking-selftest.c‎

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/interrupt.h>
2222
#include <linux/debug_locks.h>
2323
#include <linux/irqflags.h>
24+
#include <linux/rtmutex.h>
2425

2526
/*
2627
* Change this to 1 if you want to see the failure printouts:
@@ -46,6 +47,7 @@ __setup("debug_locks_verbose=", setup_debug_locks_verbose);
4647
#define LOCKTYPE_MUTEX 0x4
4748
#define LOCKTYPE_RWSEM 0x8
4849
#define LOCKTYPE_WW 0x10
50+
#define LOCKTYPE_RTMUTEX 0x20
4951

5052
static struct ww_acquire_ctx t, t2;
5153
static struct ww_mutex o, o2, o3;
@@ -74,6 +76,15 @@ static DECLARE_RWSEM(rwsem_B);
7476
static DECLARE_RWSEM(rwsem_C);
7577
static DECLARE_RWSEM(rwsem_D);
7678

79+
#ifdef CONFIG_RT_MUTEXES
80+
81+
static DEFINE_RT_MUTEX(rtmutex_A);
82+
static DEFINE_RT_MUTEX(rtmutex_B);
83+
static DEFINE_RT_MUTEX(rtmutex_C);
84+
static DEFINE_RT_MUTEX(rtmutex_D);
85+
86+
#endif
87+
7788
/*
7889
* Locks that we initialize dynamically as well so that
7990
* e.g. X1 and X2 becomes two instances of the same class,
@@ -108,6 +119,17 @@ static DECLARE_RWSEM(rwsem_Y2);
108119
static DECLARE_RWSEM(rwsem_Z1);
109120
static DECLARE_RWSEM(rwsem_Z2);
110121

122+
#ifdef CONFIG_RT_MUTEXES
123+
124+
static DEFINE_RT_MUTEX(rtmutex_X1);
125+
static DEFINE_RT_MUTEX(rtmutex_X2);
126+
static DEFINE_RT_MUTEX(rtmutex_Y1);
127+
static DEFINE_RT_MUTEX(rtmutex_Y2);
128+
static DEFINE_RT_MUTEX(rtmutex_Z1);
129+
static DEFINE_RT_MUTEX(rtmutex_Z2);
130+
131+
#endif
132+
111133
/*
112134
* non-inlined runtime initializers, to let separate locks share
113135
* the same lock-class:
@@ -129,6 +151,17 @@ INIT_CLASS_FUNC(Z)
129151

130152
static void init_shared_classes(void)
131153
{
154+
#ifdef CONFIG_RT_MUTEXES
155+
static struct lock_class_key rt_X, rt_Y, rt_Z;
156+
157+
__rt_mutex_init(&rtmutex_X1, __func__, &rt_X);
158+
__rt_mutex_init(&rtmutex_X2, __func__, &rt_X);
159+
__rt_mutex_init(&rtmutex_Y1, __func__, &rt_Y);
160+
__rt_mutex_init(&rtmutex_Y2, __func__, &rt_Y);
161+
__rt_mutex_init(&rtmutex_Z1, __func__, &rt_Z);
162+
__rt_mutex_init(&rtmutex_Z2, __func__, &rt_Z);
163+
#endif
164+
132165
init_class_X(&lock_X1, &rwlock_X1, &mutex_X1, &rwsem_X1);
133166
init_class_X(&lock_X2, &rwlock_X2, &mutex_X2, &rwsem_X2);
134167

@@ -193,6 +226,10 @@ static void init_shared_classes(void)
193226
#define MU(x) mutex_unlock(&mutex_##x)
194227
#define MI(x) mutex_init(&mutex_##x)
195228

229+
#define RTL(x) rt_mutex_lock(&rtmutex_##x)
230+
#define RTU(x) rt_mutex_unlock(&rtmutex_##x)
231+
#define RTI(x) rt_mutex_init(&rtmutex_##x)
232+
196233
#define WSL(x) down_write(&rwsem_##x)
197234
#define WSU(x) up_write(&rwsem_##x)
198235

@@ -264,6 +301,11 @@ GENERATE_TESTCASE(AA_wsem)
264301
#include "locking-selftest-rsem.h"
265302
GENERATE_TESTCASE(AA_rsem)
266303

304+
#ifdef CONFIG_RT_MUTEXES
305+
#include "locking-selftest-rtmutex.h"
306+
GENERATE_TESTCASE(AA_rtmutex);
307+
#endif
308+
267309
#undef E
268310

269311
/*
@@ -345,6 +387,11 @@ GENERATE_TESTCASE(ABBA_wsem)
345387
#include "locking-selftest-rsem.h"
346388
GENERATE_TESTCASE(ABBA_rsem)
347389

390+
#ifdef CONFIG_RT_MUTEXES
391+
#include "locking-selftest-rtmutex.h"
392+
GENERATE_TESTCASE(ABBA_rtmutex);
393+
#endif
394+
348395
#undef E
349396

350397
/*
@@ -373,6 +420,11 @@ GENERATE_TESTCASE(ABBCCA_wsem)
373420
#include "locking-selftest-rsem.h"
374421
GENERATE_TESTCASE(ABBCCA_rsem)
375422

423+
#ifdef CONFIG_RT_MUTEXES
424+
#include "locking-selftest-rtmutex.h"
425+
GENERATE_TESTCASE(ABBCCA_rtmutex);
426+
#endif
427+
376428
#undef E
377429

378430
/*
@@ -401,6 +453,11 @@ GENERATE_TESTCASE(ABCABC_wsem)
401453
#include "locking-selftest-rsem.h"
402454
GENERATE_TESTCASE(ABCABC_rsem)
403455

456+
#ifdef CONFIG_RT_MUTEXES
457+
#include "locking-selftest-rtmutex.h"
458+
GENERATE_TESTCASE(ABCABC_rtmutex);
459+
#endif
460+
404461
#undef E
405462

406463
/*
@@ -430,6 +487,11 @@ GENERATE_TESTCASE(ABBCCDDA_wsem)
430487
#include "locking-selftest-rsem.h"
431488
GENERATE_TESTCASE(ABBCCDDA_rsem)
432489

490+
#ifdef CONFIG_RT_MUTEXES
491+
#include "locking-selftest-rtmutex.h"
492+
GENERATE_TESTCASE(ABBCCDDA_rtmutex);
493+
#endif
494+
433495
#undef E
434496

435497
/*
@@ -458,6 +520,11 @@ GENERATE_TESTCASE(ABCDBDDA_wsem)
458520
#include "locking-selftest-rsem.h"
459521
GENERATE_TESTCASE(ABCDBDDA_rsem)
460522

523+
#ifdef CONFIG_RT_MUTEXES
524+
#include "locking-selftest-rtmutex.h"
525+
GENERATE_TESTCASE(ABCDBDDA_rtmutex);
526+
#endif
527+
461528
#undef E
462529

463530
/*
@@ -486,6 +553,11 @@ GENERATE_TESTCASE(ABCDBCDA_wsem)
486553
#include "locking-selftest-rsem.h"
487554
GENERATE_TESTCASE(ABCDBCDA_rsem)
488555

556+
#ifdef CONFIG_RT_MUTEXES
557+
#include "locking-selftest-rtmutex.h"
558+
GENERATE_TESTCASE(ABCDBCDA_rtmutex);
559+
#endif
560+
489561
#undef E
490562

491563
/*
@@ -513,6 +585,11 @@ GENERATE_TESTCASE(double_unlock_wsem)
513585
#include "locking-selftest-rsem.h"
514586
GENERATE_TESTCASE(double_unlock_rsem)
515587

588+
#ifdef CONFIG_RT_MUTEXES
589+
#include "locking-selftest-rtmutex.h"
590+
GENERATE_TESTCASE(double_unlock_rtmutex);
591+
#endif
592+
516593
#undef E
517594

518595
/*
@@ -539,6 +616,11 @@ GENERATE_TESTCASE(init_held_wsem)
539616
#include "locking-selftest-rsem.h"
540617
GENERATE_TESTCASE(init_held_rsem)
541618

619+
#ifdef CONFIG_RT_MUTEXES
620+
#include "locking-selftest-rtmutex.h"
621+
GENERATE_TESTCASE(init_held_rtmutex);
622+
#endif
623+
542624
#undef E
543625

544626
/*
@@ -888,6 +970,9 @@ GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_soft)
888970
# define I_MUTEX(x) lockdep_reset_lock(&mutex_##x.dep_map)
889971
# define I_RWSEM(x) lockdep_reset_lock(&rwsem_##x.dep_map)
890972
# define I_WW(x) lockdep_reset_lock(&x.dep_map)
973+
#ifdef CONFIG_RT_MUTEXES
974+
# define I_RTMUTEX(x) lockdep_reset_lock(&rtmutex_##x.dep_map)
975+
#endif
891976
#else
892977
# define I_SPINLOCK(x)
893978
# define I_RWLOCK(x)
@@ -896,12 +981,23 @@ GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_soft)
896981
# define I_WW(x)
897982
#endif
898983

984+
#ifndef I_RTMUTEX
985+
# define I_RTMUTEX(x)
986+
#endif
987+
988+
#ifdef CONFIG_RT_MUTEXES
989+
#define I2_RTMUTEX(x) rt_mutex_init(&rtmutex_##x)
990+
#else
991+
#define I2_RTMUTEX(x)
992+
#endif
993+
899994
#define I1(x) \
900995
do { \
901996
I_SPINLOCK(x); \
902997
I_RWLOCK(x); \
903998
I_MUTEX(x); \
904999
I_RWSEM(x); \
1000+
I_RTMUTEX(x); \
9051001
} while (0)
9061002

9071003
#define I2(x) \
@@ -910,6 +1006,7 @@ GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_soft)
9101006
rwlock_init(&rwlock_##x); \
9111007
mutex_init(&mutex_##x); \
9121008
init_rwsem(&rwsem_##x); \
1009+
I2_RTMUTEX(x); \
9131010
} while (0)
9141011

9151012
static void reset_locks(void)
@@ -985,6 +1082,12 @@ static void dotest(void (*testcase_fn)(void), int expected, int lockclass_mask)
9851082
reset_locks();
9861083
}
9871084

1085+
#ifdef CONFIG_RT_MUTEXES
1086+
#define dotest_rt(fn, e, m) dotest((fn), (e), (m))
1087+
#else
1088+
#define dotest_rt(fn, e, m)
1089+
#endif
1090+
9881091
static inline void print_testname(const char *testname)
9891092
{
9901093
printk("%33s:", testname);
@@ -1022,6 +1125,7 @@ static inline void print_testname(const char *testname)
10221125
dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \
10231126
dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \
10241127
dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM); \
1128+
dotest_rt(name##_rtmutex, FAILURE, LOCKTYPE_RTMUTEX); \
10251129
pr_cont("\n");
10261130

10271131
#define DO_TESTCASE_6_SUCCESS(desc, name) \
@@ -1032,6 +1136,7 @@ static inline void print_testname(const char *testname)
10321136
dotest(name##_mutex, SUCCESS, LOCKTYPE_MUTEX); \
10331137
dotest(name##_wsem, SUCCESS, LOCKTYPE_RWSEM); \
10341138
dotest(name##_rsem, SUCCESS, LOCKTYPE_RWSEM); \
1139+
dotest_rt(name##_rtmutex, SUCCESS, LOCKTYPE_RTMUTEX); \
10351140
pr_cont("\n");
10361141

10371142
/*
@@ -1045,6 +1150,7 @@ static inline void print_testname(const char *testname)
10451150
dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \
10461151
dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \
10471152
dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM); \
1153+
dotest_rt(name##_rtmutex, FAILURE, LOCKTYPE_RTMUTEX); \
10481154
pr_cont("\n");
10491155

10501156
#define DO_TESTCASE_2I(desc, name, nr) \

0 commit comments

Comments
 (0)