History

locktorture: Add nested locking to mutex torture tests

This patch adds randomized nested locking to the mutex torture tests, as well as new LOCK08 config files for testing mutexes with nested locking

John Stultz committed 3 years ago

Commit 3e5aeaf1 parent b6334324 files · +43 −0Browse files

Unified · Split

4 files
  1. kernel/locking/locktorture.c +35 −0
  2. tools/testing/selftests/rcutorture/configs/lock/CFLIST +1 −0
  3. tools/testing/selftests/rcutorture/configs/lock/LOCK08 +6 −0
  4. tools/testing/selftests/rcutorture/configs/lock/LOCK08.boot +1 −0
kernel/locking/locktorture.c+35−0
@@ -370,6 +370,28 @@ static struct lock_torture_ops rw_lock_irq_ops = { · 369 unmodified lines
370};370};
371 371
372static DEFINE_MUTEX(torture_mutex);372static DEFINE_MUTEX(torture_mutex);
373static struct mutex torture_nested_mutexes[MAX_NESTED_LOCKS];
374static struct lock_class_key nested_mutex_keys[MAX_NESTED_LOCKS];
375
376static void torture_mutex_init(void)
377{
378 int i;
379
380 for (i = 0; i < MAX_NESTED_LOCKS; i++)
381 __mutex_init(&torture_nested_mutexes[i], __func__,
382 &nested_mutex_keys[i]);
383}
384
385static int torture_mutex_nested_lock(int tid __maybe_unused,
386 u32 lockset)
387{
388 int i;
389
390 for (i = 0; i < nested_locks; i++)
391 if (lockset & (1 << i))
392 mutex_lock(&torture_nested_mutexes[i]);
393 return 0;
394}
373 395
374static int torture_mutex_lock(int tid __maybe_unused)396static int torture_mutex_lock(int tid __maybe_unused)
375__acquires(torture_mutex)397__acquires(torture_mutex)
@@ -398,11 +420,24 @@ __releases(torture_mutex) · 22 unmodified lines
398 mutex_unlock(&torture_mutex);420 mutex_unlock(&torture_mutex);
399}421}
400 422
423static void torture_mutex_nested_unlock(int tid __maybe_unused,
424 u32 lockset)
425{
426 int i;
427
428 for (i = nested_locks - 1; i >= 0; i--)
429 if (lockset & (1 << i))
430 mutex_unlock(&torture_nested_mutexes[i]);
431}
432
401static struct lock_torture_ops mutex_lock_ops = {433static struct lock_torture_ops mutex_lock_ops = {
434 .init = torture_mutex_init,
435 .nested_lock = torture_mutex_nested_lock,
402 .writelock = torture_mutex_lock,436 .writelock = torture_mutex_lock,
403 .write_delay = torture_mutex_delay,437 .write_delay = torture_mutex_delay,
404 .task_boost = torture_rt_boost,438 .task_boost = torture_rt_boost,
405 .writeunlock = torture_mutex_unlock,439 .writeunlock = torture_mutex_unlock,
440 .nested_unlock = torture_mutex_nested_unlock,
406 .readlock = NULL,441 .readlock = NULL,
407 .read_delay = NULL,442 .read_delay = NULL,
408 .readunlock = NULL,443 .readunlock = NULL,
tools/testing/selftests/rcutorture/configs/lock/CFLIST+1−0
@@ -5,3 +5,4 @@ LOCK04 · 4 unmodified lines
5LOCK055LOCK05
6LOCK066LOCK06
7LOCK077LOCK07
8LOCK08
tools/testing/selftests/rcutorture/configs/lock/LOCK08+6−0
@@ -0,0 +1,6 @@
1CONFIG_SMP=y
2CONFIG_NR_CPUS=4
3CONFIG_HOTPLUG_CPU=y
4CONFIG_PREEMPT_NONE=n
5CONFIG_PREEMPT_VOLUNTARY=n
6CONFIG_PREEMPT=y
tools/testing/selftests/rcutorture/configs/lock/LOCK08.boot+1−0
@@ -0,0 +1 @@
1locktorture.torture_type=mutex_lock locktorture.nested_locks=8

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t