Skip to content

Commit f8619c3

Browse files
committed
locktorture: Add long_hold to adjust lock-hold delays
This commit adds a long_hold module parameter to allow testing diagnostics for excessive lock-hold times. Also adjust torture_param() invocations for longer line length while in the area. Signed-off-by: Paul E. McKenney <[email protected]> Reviewed-by: Joel Fernandes (Google) <[email protected]>
1 parent ac9a786 commit f8619c3

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

kernel/locking/locktorture.c

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

36-
torture_param(int, nwriters_stress, -1,
37-
"Number of write-locking stress-test threads");
38-
torture_param(int, nreaders_stress, -1,
39-
"Number of read-locking stress-test threads");
36+
torture_param(int, nwriters_stress, -1, "Number of write-locking stress-test threads");
37+
torture_param(int, nreaders_stress, -1, "Number of read-locking stress-test threads");
38+
torture_param(int, long_hold, 100, "Do occasional long hold of lock (ms), 0=disable");
4039
torture_param(int, onoff_holdoff, 0, "Time after boot before CPU hotplugs (s)");
41-
torture_param(int, onoff_interval, 0,
42-
"Time between CPU hotplugs (s), 0=disable");
43-
torture_param(int, shuffle_interval, 3,
44-
"Number of jiffies between shuffles, 0=disable");
40+
torture_param(int, onoff_interval, 0, "Time between CPU hotplugs (s), 0=disable");
41+
torture_param(int, shuffle_interval, 3, "Number of jiffies between shuffles, 0=disable");
4542
torture_param(int, shutdown_secs, 0, "Shutdown time (j), <= zero to disable.");
46-
torture_param(int, stat_interval, 60,
47-
"Number of seconds between stats printk()s");
43+
torture_param(int, stat_interval, 60, "Number of seconds between stats printk()s");
4844
torture_param(int, stutter, 5, "Number of jiffies to run/halt test, 0=disable");
4945
torture_param(int, rt_boost, 2,
50-
"Do periodic rt-boost. 0=Disable, 1=Only for rt_mutex, 2=For all lock types.");
46+
"Do periodic rt-boost. 0=Disable, 1=Only for rt_mutex, 2=For all lock types.");
5147
torture_param(int, rt_boost_factor, 50, "A factor determining how often rt-boost happens.");
52-
torture_param(int, verbose, 1,
53-
"Enable verbose debugging printk()s");
48+
torture_param(int, verbose, 1, "Enable verbose debugging printk()s");
5449
torture_param(int, nested_locks, 0, "Number of nested locks (max = 8)");
5550
/* Going much higher trips "BUG: MAX_LOCKDEP_CHAIN_HLOCKS too low!" errors */
5651
#define MAX_NESTED_LOCKS 8
@@ -120,7 +115,7 @@ static int torture_lock_busted_write_lock(int tid __maybe_unused)
120115

121116
static void torture_lock_busted_write_delay(struct torture_random_state *trsp)
122117
{
123-
const unsigned long longdelay_ms = 100;
118+
const unsigned long longdelay_ms = long_hold ? long_hold : ULONG_MAX;
124119

125120
/* We want a long delay occasionally to force massive contention. */
126121
if (!(torture_random(trsp) %
@@ -198,16 +193,18 @@ __acquires(torture_spinlock)
198193
static void torture_spin_lock_write_delay(struct torture_random_state *trsp)
199194
{
200195
const unsigned long shortdelay_us = 2;
201-
const unsigned long longdelay_ms = 100;
196+
const unsigned long longdelay_ms = long_hold ? long_hold : ULONG_MAX;
197+
unsigned long j;
202198

203199
/* We want a short delay mostly to emulate likely code, and
204200
* we want a long delay occasionally to force massive contention.
205201
*/
206-
if (!(torture_random(trsp) %
207-
(cxt.nrealwriters_stress * 2000 * longdelay_ms)))
202+
if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 2000 * longdelay_ms))) {
203+
j = jiffies;
208204
mdelay(longdelay_ms);
209-
if (!(torture_random(trsp) %
210-
(cxt.nrealwriters_stress * 2 * shortdelay_us)))
205+
pr_alert("%s: delay = %lu jiffies.\n", __func__, jiffies - j);
206+
}
207+
if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 200 * shortdelay_us)))
211208
udelay(shortdelay_us);
212209
if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000)))
213210
torture_preempt_schedule(); /* Allow test to be preempted. */
@@ -322,7 +319,7 @@ __acquires(torture_rwlock)
322319
static void torture_rwlock_write_delay(struct torture_random_state *trsp)
323320
{
324321
const unsigned long shortdelay_us = 2;
325-
const unsigned long longdelay_ms = 100;
322+
const unsigned long longdelay_ms = long_hold ? long_hold : ULONG_MAX;
326323

327324
/* We want a short delay mostly to emulate likely code, and
328325
* we want a long delay occasionally to force massive contention.
@@ -455,14 +452,12 @@ __acquires(torture_mutex)
455452

456453
static void torture_mutex_delay(struct torture_random_state *trsp)
457454
{
458-
const unsigned long longdelay_ms = 100;
455+
const unsigned long longdelay_ms = long_hold ? long_hold : ULONG_MAX;
459456

460457
/* We want a long delay occasionally to force massive contention. */
461458
if (!(torture_random(trsp) %
462459
(cxt.nrealwriters_stress * 2000 * longdelay_ms)))
463460
mdelay(longdelay_ms * 5);
464-
else
465-
mdelay(longdelay_ms / 5);
466461
if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000)))
467462
torture_preempt_schedule(); /* Allow test to be preempted. */
468463
}
@@ -630,7 +625,7 @@ __acquires(torture_rtmutex)
630625
static void torture_rtmutex_delay(struct torture_random_state *trsp)
631626
{
632627
const unsigned long shortdelay_us = 2;
633-
const unsigned long longdelay_ms = 100;
628+
const unsigned long longdelay_ms = long_hold ? long_hold : ULONG_MAX;
634629

635630
/*
636631
* We want a short delay mostly to emulate likely code, and
@@ -640,7 +635,7 @@ static void torture_rtmutex_delay(struct torture_random_state *trsp)
640635
(cxt.nrealwriters_stress * 2000 * longdelay_ms)))
641636
mdelay(longdelay_ms);
642637
if (!(torture_random(trsp) %
643-
(cxt.nrealwriters_stress * 2 * shortdelay_us)))
638+
(cxt.nrealwriters_stress * 200 * shortdelay_us)))
644639
udelay(shortdelay_us);
645640
if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000)))
646641
torture_preempt_schedule(); /* Allow test to be preempted. */
@@ -695,14 +690,12 @@ __acquires(torture_rwsem)
695690

696691
static void torture_rwsem_write_delay(struct torture_random_state *trsp)
697692
{
698-
const unsigned long longdelay_ms = 100;
693+
const unsigned long longdelay_ms = long_hold ? long_hold : ULONG_MAX;
699694

700695
/* We want a long delay occasionally to force massive contention. */
701696
if (!(torture_random(trsp) %
702697
(cxt.nrealwriters_stress * 2000 * longdelay_ms)))
703698
mdelay(longdelay_ms * 10);
704-
else
705-
mdelay(longdelay_ms / 10);
706699
if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000)))
707700
torture_preempt_schedule(); /* Allow test to be preempted. */
708701
}
@@ -848,8 +841,8 @@ static int lock_torture_writer(void *arg)
848841

849842
lwsp->n_lock_acquired++;
850843
}
851-
cxt.cur_ops->write_delay(&rand);
852844
if (!skip_main_lock) {
845+
cxt.cur_ops->write_delay(&rand);
853846
lock_is_write_held = false;
854847
WRITE_ONCE(last_lock_release, jiffies);
855848
cxt.cur_ops->writeunlock(tid);

0 commit comments

Comments
 (0)