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

Showing the changes to kernel/locking (1 of 4 files). Show all

Unified · Split

kernel/locking/locktorture.c+35−0
@@ -370,6 +370,28 @@ static struct lock_torture_ops rw_lock_irq_ops = { · 369 unmodified lines
370370 };
371371
372372 static DEFINE_MUTEX(torture_mutex);
373+static struct mutex torture_nested_mutexes[MAX_NESTED_LOCKS];
374+static struct lock_class_key nested_mutex_keys[MAX_NESTED_LOCKS];
375+
376+static 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+
385+static 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+}
373395
374396 static int torture_mutex_lock(int tid __maybe_unused)
375397 __acquires(torture_mutex)
@@ -398,11 +420,24 @@ __releases(torture_mutex) · 22 unmodified lines
398420 mutex_unlock(&torture_mutex);
399421 }
400422
423+static 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+
401433 static struct lock_torture_ops mutex_lock_ops = {
434+ .init = torture_mutex_init,
435+ .nested_lock = torture_mutex_nested_lock,
402436 .writelock = torture_mutex_lock,
403437 .write_delay = torture_mutex_delay,
404438 .task_boost = torture_rt_boost,
405439 .writeunlock = torture_mutex_unlock,
440+ .nested_unlock = torture_mutex_nested_unlock,
406441 .readlock = NULL,
407442 .read_delay = NULL,
408443 .readunlock = NULL,

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