Commit af5f6e27 authored by Paul E. McKenney's avatar Paul E. McKenney

locktorture: Count lock readers

Currently, the lock_is_read_held variable is bool, so that a reader sets
it to true just after lock acquisition and then to false just before
lock release.  This works in a rough statistical sense, but can result
in false negatives just after one of a pair of concurrent readers has
released the lock.  This approach does have low overhead, but at the
expense of the setting to true potentially never leaving the reader's
store buffer, thus resulting in an unconditional false negative.

This commit therefore converts this variable to atomic_t and makes
the reader use atomic_inc() just after acquisition and atomic_dec()
just before release.  This does increase overhead, but this increase is
negligible compared to the 10-microsecond lock hold time.
Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
parent 5b237d65
...@@ -59,7 +59,7 @@ static struct task_struct **writer_tasks; ...@@ -59,7 +59,7 @@ static struct task_struct **writer_tasks;
static struct task_struct **reader_tasks; static struct task_struct **reader_tasks;
static bool lock_is_write_held; static bool lock_is_write_held;
static bool lock_is_read_held; static atomic_t lock_is_read_held;
static unsigned long last_lock_release; static unsigned long last_lock_release;
struct lock_stress_stats { struct lock_stress_stats {
...@@ -682,7 +682,7 @@ static int lock_torture_writer(void *arg) ...@@ -682,7 +682,7 @@ static int lock_torture_writer(void *arg)
if (WARN_ON_ONCE(lock_is_write_held)) if (WARN_ON_ONCE(lock_is_write_held))
lwsp->n_lock_fail++; lwsp->n_lock_fail++;
lock_is_write_held = true; lock_is_write_held = true;
if (WARN_ON_ONCE(lock_is_read_held)) if (WARN_ON_ONCE(atomic_read(&lock_is_read_held)))
lwsp->n_lock_fail++; /* rare, but... */ lwsp->n_lock_fail++; /* rare, but... */
lwsp->n_lock_acquired++; lwsp->n_lock_acquired++;
...@@ -717,13 +717,13 @@ static int lock_torture_reader(void *arg) ...@@ -717,13 +717,13 @@ static int lock_torture_reader(void *arg)
schedule_timeout_uninterruptible(1); schedule_timeout_uninterruptible(1);
cxt.cur_ops->readlock(tid); cxt.cur_ops->readlock(tid);
lock_is_read_held = true; atomic_inc(&lock_is_read_held);
if (WARN_ON_ONCE(lock_is_write_held)) if (WARN_ON_ONCE(lock_is_write_held))
lrsp->n_lock_fail++; /* rare, but... */ lrsp->n_lock_fail++; /* rare, but... */
lrsp->n_lock_acquired++; lrsp->n_lock_acquired++;
cxt.cur_ops->read_delay(&rand); cxt.cur_ops->read_delay(&rand);
lock_is_read_held = false; atomic_dec(&lock_is_read_held);
cxt.cur_ops->readunlock(tid); cxt.cur_ops->readunlock(tid);
stutter_wait("lock_torture_reader"); stutter_wait("lock_torture_reader");
...@@ -998,7 +998,6 @@ static int __init lock_torture_init(void) ...@@ -998,7 +998,6 @@ static int __init lock_torture_init(void)
} }
if (nreaders_stress) { if (nreaders_stress) {
lock_is_read_held = false;
cxt.lrsa = kmalloc_array(cxt.nrealreaders_stress, cxt.lrsa = kmalloc_array(cxt.nrealreaders_stress,
sizeof(*cxt.lrsa), sizeof(*cxt.lrsa),
GFP_KERNEL); GFP_KERNEL);
......
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