diff options
| author | Peter Zijlstra <peterz@infradead.org> | 2017-05-31 11:11:49 -0400 |
|---|---|---|
| committer | Ingo Molnar <mingo@kernel.org> | 2017-06-08 04:35:50 -0400 |
| commit | 018956d6419be3e5ff5aacc60b2a3cff585adee1 (patch) | |
| tree | 6ecde8e95a6fc80d93933ab0e4d8c8463ea3b1ce | |
| parent | cfb6133399a490419cda55fcdcf9dbbca65eacba (diff) | |
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>
| -rw-r--r-- | lib/locking-selftest-rtmutex.h | 11 | ||||
| -rw-r--r-- | lib/locking-selftest.c | 106 |
2 files changed, 117 insertions, 0 deletions
diff --git a/lib/locking-selftest-rtmutex.h b/lib/locking-selftest-rtmutex.h new file mode 100644 index 000000000000..e3cb83989d16 --- /dev/null +++ b/lib/locking-selftest-rtmutex.h | |||
| @@ -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 | ||
diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c index dd09e517c492..6f2b135dc5e8 100644 --- a/lib/locking-selftest.c +++ b/lib/locking-selftest.c | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | #include <linux/interrupt.h> | 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/debug_locks.h> | 22 | #include <linux/debug_locks.h> |
| 23 | #include <linux/irqflags.h> | 23 | #include <linux/irqflags.h> |
| 24 | #include <linux/rtmutex.h> | ||
| 24 | 25 | ||
| 25 | /* | 26 | /* |
| 26 | * Change this to 1 if you want to see the failure printouts: | 27 | * Change this to 1 if you want to see the failure printouts: |
| @@ -46,6 +47,7 @@ __setup("debug_locks_verbose=", setup_debug_locks_verbose); | |||
| 46 | #define LOCKTYPE_MUTEX 0x4 | 47 | #define LOCKTYPE_MUTEX 0x4 |
| 47 | #define LOCKTYPE_RWSEM 0x8 | 48 | #define LOCKTYPE_RWSEM 0x8 |
| 48 | #define LOCKTYPE_WW 0x10 | 49 | #define LOCKTYPE_WW 0x10 |
| 50 | #define LOCKTYPE_RTMUTEX 0x20 | ||
| 49 | 51 | ||
| 50 | static struct ww_acquire_ctx t, t2; | 52 | static struct ww_acquire_ctx t, t2; |
| 51 | static struct ww_mutex o, o2, o3; | 53 | static struct ww_mutex o, o2, o3; |
| @@ -74,6 +76,15 @@ static DECLARE_RWSEM(rwsem_B); | |||
| 74 | static DECLARE_RWSEM(rwsem_C); | 76 | static DECLARE_RWSEM(rwsem_C); |
| 75 | static DECLARE_RWSEM(rwsem_D); | 77 | static DECLARE_RWSEM(rwsem_D); |
| 76 | 78 | ||
| 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 | |||
| 77 | /* | 88 | /* |
| 78 | * Locks that we initialize dynamically as well so that | 89 | * Locks that we initialize dynamically as well so that |
| 79 | * e.g. X1 and X2 becomes two instances of the same class, | 90 | * e.g. X1 and X2 becomes two instances of the same class, |
| @@ -108,6 +119,17 @@ static DECLARE_RWSEM(rwsem_Y2); | |||
| 108 | static DECLARE_RWSEM(rwsem_Z1); | 119 | static DECLARE_RWSEM(rwsem_Z1); |
| 109 | static DECLARE_RWSEM(rwsem_Z2); | 120 | static DECLARE_RWSEM(rwsem_Z2); |
| 110 | 121 | ||
| 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 | |||
| 111 | /* | 133 | /* |
| 112 | * non-inlined runtime initializers, to let separate locks share | 134 | * non-inlined runtime initializers, to let separate locks share |
| 113 | * the same lock-class: | 135 | * the same lock-class: |
| @@ -129,6 +151,17 @@ INIT_CLASS_FUNC(Z) | |||
| 129 | 151 | ||
| 130 | static void init_shared_classes(void) | 152 | static void init_shared_classes(void) |
| 131 | { | 153 | { |
| 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 | |||
| 132 | init_class_X(&lock_X1, &rwlock_X1, &mutex_X1, &rwsem_X1); | 165 | init_class_X(&lock_X1, &rwlock_X1, &mutex_X1, &rwsem_X1); |
| 133 | init_class_X(&lock_X2, &rwlock_X2, &mutex_X2, &rwsem_X2); | 166 | init_class_X(&lock_X2, &rwlock_X2, &mutex_X2, &rwsem_X2); |
| 134 | 167 | ||
| @@ -193,6 +226,10 @@ static void init_shared_classes(void) | |||
| 193 | #define MU(x) mutex_unlock(&mutex_##x) | 226 | #define MU(x) mutex_unlock(&mutex_##x) |
| 194 | #define MI(x) mutex_init(&mutex_##x) | 227 | #define MI(x) mutex_init(&mutex_##x) |
| 195 | 228 | ||
| 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 | |||
| 196 | #define WSL(x) down_write(&rwsem_##x) | 233 | #define WSL(x) down_write(&rwsem_##x) |
| 197 | #define WSU(x) up_write(&rwsem_##x) | 234 | #define WSU(x) up_write(&rwsem_##x) |
| 198 | 235 | ||
| @@ -264,6 +301,11 @@ GENERATE_TESTCASE(AA_wsem) | |||
| 264 | #include "locking-selftest-rsem.h" | 301 | #include "locking-selftest-rsem.h" |
| 265 | GENERATE_TESTCASE(AA_rsem) | 302 | GENERATE_TESTCASE(AA_rsem) |
| 266 | 303 | ||
| 304 | #ifdef CONFIG_RT_MUTEXES | ||
| 305 | #include "locking-selftest-rtmutex.h" | ||
| 306 | GENERATE_TESTCASE(AA_rtmutex); | ||
| 307 | #endif | ||
| 308 | |||
| 267 | #undef E | 309 | #undef E |
| 268 | 310 | ||
| 269 | /* | 311 | /* |
| @@ -345,6 +387,11 @@ GENERATE_TESTCASE(ABBA_wsem) | |||
| 345 | #include "locking-selftest-rsem.h" | 387 | #include "locking-selftest-rsem.h" |
| 346 | GENERATE_TESTCASE(ABBA_rsem) | 388 | GENERATE_TESTCASE(ABBA_rsem) |
| 347 | 389 | ||
| 390 | #ifdef CONFIG_RT_MUTEXES | ||
| 391 | #include "locking-selftest-rtmutex.h" | ||
| 392 | GENERATE_TESTCASE(ABBA_rtmutex); | ||
| 393 | #endif | ||
| 394 | |||
| 348 | #undef E | 395 | #undef E |
| 349 | 396 | ||
| 350 | /* | 397 | /* |
| @@ -373,6 +420,11 @@ GENERATE_TESTCASE(ABBCCA_wsem) | |||
| 373 | #include "locking-selftest-rsem.h" | 420 | #include "locking-selftest-rsem.h" |
| 374 | GENERATE_TESTCASE(ABBCCA_rsem) | 421 | GENERATE_TESTCASE(ABBCCA_rsem) |
| 375 | 422 | ||
| 423 | #ifdef CONFIG_RT_MUTEXES | ||
| 424 | #include "locking-selftest-rtmutex.h" | ||
| 425 | GENERATE_TESTCASE(ABBCCA_rtmutex); | ||
| 426 | #endif | ||
| 427 | |||
| 376 | #undef E | 428 | #undef E |
| 377 | 429 | ||
| 378 | /* | 430 | /* |
| @@ -401,6 +453,11 @@ GENERATE_TESTCASE(ABCABC_wsem) | |||
| 401 | #include "locking-selftest-rsem.h" | 453 | #include "locking-selftest-rsem.h" |
| 402 | GENERATE_TESTCASE(ABCABC_rsem) | 454 | GENERATE_TESTCASE(ABCABC_rsem) |
| 403 | 455 | ||
| 456 | #ifdef CONFIG_RT_MUTEXES | ||
| 457 | #include "locking-selftest-rtmutex.h" | ||
| 458 | GENERATE_TESTCASE(ABCABC_rtmutex); | ||
| 459 | #endif | ||
| 460 | |||
| 404 | #undef E | 461 | #undef E |
| 405 | 462 | ||
| 406 | /* | 463 | /* |
| @@ -430,6 +487,11 @@ GENERATE_TESTCASE(ABBCCDDA_wsem) | |||
| 430 | #include "locking-selftest-rsem.h" | 487 | #include "locking-selftest-rsem.h" |
| 431 | GENERATE_TESTCASE(ABBCCDDA_rsem) | 488 | GENERATE_TESTCASE(ABBCCDDA_rsem) |
| 432 | 489 | ||
| 490 | #ifdef CONFIG_RT_MUTEXES | ||
| 491 | #include "locking-selftest-rtmutex.h" | ||
| 492 | GENERATE_TESTCASE(ABBCCDDA_rtmutex); | ||
| 493 | #endif | ||
| 494 | |||
| 433 | #undef E | 495 | #undef E |
| 434 | 496 | ||
| 435 | /* | 497 | /* |
| @@ -458,6 +520,11 @@ GENERATE_TESTCASE(ABCDBDDA_wsem) | |||
| 458 | #include "locking-selftest-rsem.h" | 520 | #include "locking-selftest-rsem.h" |
| 459 | GENERATE_TESTCASE(ABCDBDDA_rsem) | 521 | GENERATE_TESTCASE(ABCDBDDA_rsem) |
| 460 | 522 | ||
| 523 | #ifdef CONFIG_RT_MUTEXES | ||
| 524 | #include "locking-selftest-rtmutex.h" | ||
| 525 | GENERATE_TESTCASE(ABCDBDDA_rtmutex); | ||
| 526 | #endif | ||
| 527 | |||
| 461 | #undef E | 528 | #undef E |
| 462 | 529 | ||
| 463 | /* | 530 | /* |
| @@ -486,6 +553,11 @@ GENERATE_TESTCASE(ABCDBCDA_wsem) | |||
| 486 | #include "locking-selftest-rsem.h" | 553 | #include "locking-selftest-rsem.h" |
| 487 | GENERATE_TESTCASE(ABCDBCDA_rsem) | 554 | GENERATE_TESTCASE(ABCDBCDA_rsem) |
| 488 | 555 | ||
| 556 | #ifdef CONFIG_RT_MUTEXES | ||
| 557 | #include "locking-selftest-rtmutex.h" | ||
| 558 | GENERATE_TESTCASE(ABCDBCDA_rtmutex); | ||
| 559 | #endif | ||
| 560 | |||
| 489 | #undef E | 561 | #undef E |
| 490 | 562 | ||
| 491 | /* | 563 | /* |
| @@ -513,6 +585,11 @@ GENERATE_TESTCASE(double_unlock_wsem) | |||
| 513 | #include "locking-selftest-rsem.h" | 585 | #include "locking-selftest-rsem.h" |
| 514 | GENERATE_TESTCASE(double_unlock_rsem) | 586 | GENERATE_TESTCASE(double_unlock_rsem) |
| 515 | 587 | ||
| 588 | #ifdef CONFIG_RT_MUTEXES | ||
| 589 | #include "locking-selftest-rtmutex.h" | ||
| 590 | GENERATE_TESTCASE(double_unlock_rtmutex); | ||
| 591 | #endif | ||
| 592 | |||
