Commit 45bcf0bd authored by John Stultz's avatar John Stultz Committed by Paul E. McKenney

locktorture: With nested locks, occasionally skip main lock

If we're using nested locking to stress things, occasionally
skip taking the main lock, so that we can get some different
contention patterns between the writers (to hopefully get two
disjoint blocked trees)

Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Joel Fernandes <joel@joelfernandes.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: kernel-team@android.com
Co-developed-by: default avatarConnor O'Brien <connoro@google.com>
Signed-off-by: default avatarConnor O'Brien <connoro@google.com>
Signed-off-by: default avatarJohn Stultz <jstultz@google.com>
Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
parent ae4823e4
...@@ -760,6 +760,7 @@ static int lock_torture_writer(void *arg) ...@@ -760,6 +760,7 @@ static int lock_torture_writer(void *arg)
int tid = lwsp - cxt.lwsa; int tid = lwsp - cxt.lwsa;
DEFINE_TORTURE_RANDOM(rand); DEFINE_TORTURE_RANDOM(rand);
u32 lockset_mask; u32 lockset_mask;
bool skip_main_lock;
VERBOSE_TOROUT_STRING("lock_torture_writer task started"); VERBOSE_TOROUT_STRING("lock_torture_writer task started");
set_user_nice(current, MAX_NICE); set_user_nice(current, MAX_NICE);
...@@ -769,9 +770,22 @@ static int lock_torture_writer(void *arg) ...@@ -769,9 +770,22 @@ static int lock_torture_writer(void *arg)
schedule_timeout_uninterruptible(1); schedule_timeout_uninterruptible(1);
lockset_mask = torture_random(&rand); lockset_mask = torture_random(&rand);
/*
* When using nested_locks, we want to occasionally
* skip the main lock so we can avoid always serializing
* the lock chains on that central lock. By skipping the
* main lock occasionally, we can create different
* contention patterns (allowing for multiple disjoint
* blocked trees)
*/
skip_main_lock = (nested_locks &&
!(torture_random(&rand) % 100));
cxt.cur_ops->task_boost(&rand); cxt.cur_ops->task_boost(&rand);
if (cxt.cur_ops->nested_lock) if (cxt.cur_ops->nested_lock)
cxt.cur_ops->nested_lock(tid, lockset_mask); cxt.cur_ops->nested_lock(tid, lockset_mask);
if (!skip_main_lock) {
cxt.cur_ops->writelock(tid); cxt.cur_ops->writelock(tid);
if (WARN_ON_ONCE(lock_is_write_held)) if (WARN_ON_ONCE(lock_is_write_held))
lwsp->n_lock_fail++; lwsp->n_lock_fail++;
...@@ -780,10 +794,13 @@ static int lock_torture_writer(void *arg) ...@@ -780,10 +794,13 @@ static int lock_torture_writer(void *arg)
lwsp->n_lock_fail++; /* rare, but... */ lwsp->n_lock_fail++; /* rare, but... */
lwsp->n_lock_acquired++; lwsp->n_lock_acquired++;
}
cxt.cur_ops->write_delay(&rand); cxt.cur_ops->write_delay(&rand);
if (!skip_main_lock) {
lock_is_write_held = false; lock_is_write_held = false;
WRITE_ONCE(last_lock_release, jiffies); WRITE_ONCE(last_lock_release, jiffies);
cxt.cur_ops->writeunlock(tid); cxt.cur_ops->writeunlock(tid);
}
if (cxt.cur_ops->nested_unlock) if (cxt.cur_ops->nested_unlock)
cxt.cur_ops->nested_unlock(tid, lockset_mask); cxt.cur_ops->nested_unlock(tid, lockset_mask);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment