Skip to content

Commit e3bdaef

Browse files
paulmckrcuFrederic Weisbecker
authored andcommitted
locktorture: Add acq_writer_lim to complain about long acquistion times
This commit adds a locktorture.acq_writer_lim module parameter that specifies the maximum number of jiffies that is expected to be consumed by write-side lock acquisition. If this limit is exceeded, a WARN_ONCE() causes a splat. Note that this limit applies to the main lock acquisition only, not to any nested acquisitions. Signed-off-by: Paul E. McKenney <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]>
1 parent 84cee9e commit e3bdaef

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

kernel/locking/locktorture.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
MODULE_LICENSE("GPL");
3434
MODULE_AUTHOR("Paul E. McKenney <[email protected]>");
3535

36+
torture_param(int, acq_writer_lim, 0, "Write_acquisition time limit (jiffies).");
3637
torture_param(int, long_hold, 100, "Do occasional long hold of lock (ms), 0=disable");
3738
torture_param(int, nested_locks, 0, "Number of nested locks (max = 8)");
3839
torture_param(int, nreaders_stress, -1, "Number of read-locking stress-test threads");
@@ -852,11 +853,13 @@ static struct lock_torture_ops percpu_rwsem_lock_ops = {
852853
*/
853854
static int lock_torture_writer(void *arg)
854855
{
856+
unsigned long j;
857+
unsigned long j1;
858+
u32 lockset_mask;
855859
struct lock_stress_stats *lwsp = arg;
856-
int tid = lwsp - cxt.lwsa;
857860
DEFINE_TORTURE_RANDOM(rand);
858-
u32 lockset_mask;
859861
bool skip_main_lock;
862+
int tid = lwsp - cxt.lwsa;
860863

861864
VERBOSE_TOROUT_STRING("lock_torture_writer task started");
862865
if (!rt_task(current))
@@ -883,12 +886,20 @@ static int lock_torture_writer(void *arg)
883886
cxt.cur_ops->nested_lock(tid, lockset_mask);
884887

885888
if (!skip_main_lock) {
889+
if (acq_writer_lim > 0)
890+
j = jiffies;
886891
cxt.cur_ops->writelock(tid);
887892
if (WARN_ON_ONCE(lock_is_write_held))
888893
lwsp->n_lock_fail++;
889894
lock_is_write_held = true;
890895
if (WARN_ON_ONCE(atomic_read(&lock_is_read_held)))
891896
lwsp->n_lock_fail++; /* rare, but... */
897+
if (acq_writer_lim > 0) {
898+
j1 = jiffies;
899+
WARN_ONCE(time_after(j1, j + acq_writer_lim),
900+
"%s: Lock acquisition took %lu jiffies.\n",
901+
__func__, j1 - j);
902+
}
892903
lwsp->n_lock_acquired++;
893904

894905
cxt.cur_ops->write_delay(&rand);

0 commit comments

Comments
 (0)