Skip to content

Commit e01f3a1

Browse files
joelagnelpaulmckrcu
authored andcommitted
locktorture: Allow non-rtmutex lock types to be boosted
Currently RT boosting is only done for rtmutex_lock, however with proxy execution, we also have the mutex_lock participating in priorities. To exercise the testing better, add RT boosting to other lock testing types as well, using a new knob (rt_boost). Tested with boot parameters: locktorture.torture_type=mutex_lock locktorture.onoff_interval=1 locktorture.nwriters_stress=8 locktorture.stutter=0 locktorture.rt_boost=1 locktorture.rt_boost_factor=1 locktorture.nlocks=3 Signed-off-by: Joel Fernandes (Google) <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent a6889be commit e01f3a1

File tree

1 file changed

+56
-43
lines changed

1 file changed

+56
-43
lines changed

kernel/locking/locktorture.c

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ torture_param(int, shutdown_secs, 0, "Shutdown time (j), <= zero to disable.");
4646
torture_param(int, stat_interval, 60,
4747
"Number of seconds between stats printk()s");
4848
torture_param(int, stutter, 5, "Number of jiffies to run/halt test, 0=disable");
49+
torture_param(int, rt_boost, 2,
50+
"Do periodic rt-boost. 0=Disable, 1=Only for rt_mutex, 2=For all lock types.");
4951
torture_param(int, verbose, 1,
5052
"Enable verbose debugging printk()s");
5153

@@ -127,15 +129,49 @@ static void torture_lock_busted_write_unlock(int tid __maybe_unused)
127129
/* BUGGY, do not use in real life!!! */
128130
}
129131

130-
static void torture_boost_dummy(struct torture_random_state *trsp)
132+
static void __torture_rt_boost(struct torture_random_state *trsp)
131133
{
132-
/* Only rtmutexes care about priority */
134+
const unsigned int factor = 50000; /* yes, quite arbitrary */
135+
136+
if (!rt_task(current)) {
137+
/*
138+
* Boost priority once every ~50k operations. When the
139+
* task tries to take the lock, the rtmutex it will account
140+
* for the new priority, and do any corresponding pi-dance.
141+
*/
142+
if (trsp && !(torture_random(trsp) %
143+
(cxt.nrealwriters_stress * factor))) {
144+
sched_set_fifo(current);
145+
} else /* common case, do nothing */
146+
return;
147+
} else {
148+
/*
149+
* The task will remain boosted for another ~500k operations,
150+
* then restored back to its original prio, and so forth.
151+
*
152+
* When @trsp is nil, we want to force-reset the task for
153+
* stopping the kthread.
154+
*/
155+
if (!trsp || !(torture_random(trsp) %
156+
(cxt.nrealwriters_stress * factor * 2))) {
157+
sched_set_normal(current, 0);
158+
} else /* common case, do nothing */
159+
return;
160+
}
161+
}
162+
163+
static void torture_rt_boost(struct torture_random_state *trsp)
164+
{
165+
if (rt_boost != 2)
166+
return;
167+
168+
__torture_rt_boost(trsp);
133169
}
134170

135171
static struct lock_torture_ops lock_busted_ops = {
136172
.writelock = torture_lock_busted_write_lock,
137173
.write_delay = torture_lock_busted_write_delay,
138-
.task_boost = torture_boost_dummy,
174+
.task_boost = torture_rt_boost,
139175
.writeunlock = torture_lock_busted_write_unlock,
140176
.readlock = NULL,
141177
.read_delay = NULL,
@@ -179,7 +215,7 @@ __releases(torture_spinlock)
179215
static struct lock_torture_ops spin_lock_ops = {
180216
.writelock = torture_spin_lock_write_lock,
181217
.write_delay = torture_spin_lock_write_delay,
182-
.task_boost = torture_boost_dummy,
218+
.task_boost = torture_rt_boost,
183219
.writeunlock = torture_spin_lock_write_unlock,
184220
.readlock = NULL,
185221
.read_delay = NULL,
@@ -206,7 +242,7 @@ __releases(torture_spinlock)
206242
static struct lock_torture_ops spin_lock_irq_ops = {
207243
.writelock = torture_spin_lock_write_lock_irq,
208244
.write_delay = torture_spin_lock_write_delay,
209-
.task_boost = torture_boost_dummy,
245+
.task_boost = torture_rt_boost,
210246
.writeunlock = torture_lock_spin_write_unlock_irq,
211247
.readlock = NULL,
212248
.read_delay = NULL,
@@ -275,7 +311,7 @@ __releases(torture_rwlock)
275311
static struct lock_torture_ops rw_lock_ops = {
276312
.writelock = torture_rwlock_write_lock,
277313
.write_delay = torture_rwlock_write_delay,
278-
.task_boost = torture_boost_dummy,
314+
.task_boost = torture_rt_boost,
279315
.writeunlock = torture_rwlock_write_unlock,
280316
.readlock = torture_rwlock_read_lock,
281317
.read_delay = torture_rwlock_read_delay,
@@ -318,7 +354,7 @@ __releases(torture_rwlock)
318354
static struct lock_torture_ops rw_lock_irq_ops = {
319355
.writelock = torture_rwlock_write_lock_irq,
320356
.write_delay = torture_rwlock_write_delay,
321-
.task_boost = torture_boost_dummy,
357+
.task_boost = torture_rt_boost,
322358
.writeunlock = torture_rwlock_write_unlock_irq,
323359
.readlock = torture_rwlock_read_lock_irq,
324360
.read_delay = torture_rwlock_read_delay,
@@ -358,7 +394,7 @@ __releases(torture_mutex)
358394
static struct lock_torture_ops mutex_lock_ops = {
359395
.writelock = torture_mutex_lock,
360396
.write_delay = torture_mutex_delay,
361-
.task_boost = torture_boost_dummy,
397+
.task_boost = torture_rt_boost,
362398
.writeunlock = torture_mutex_unlock,
363399
.readlock = NULL,
364400
.read_delay = NULL,
@@ -456,7 +492,7 @@ static struct lock_torture_ops ww_mutex_lock_ops = {
456492
.exit = torture_ww_mutex_exit,
457493
.writelock = torture_ww_mutex_lock,
458494
.write_delay = torture_mutex_delay,
459-
.task_boost = torture_boost_dummy,
495+
.task_boost = torture_rt_boost,
460496
.writeunlock = torture_ww_mutex_unlock,
461497
.readlock = NULL,
462498
.read_delay = NULL,
@@ -474,37 +510,6 @@ __acquires(torture_rtmutex)
474510
return 0;
475511
}
476512

477-
static void torture_rtmutex_boost(struct torture_random_state *trsp)
478-
{
479-
const unsigned int factor = 50000; /* yes, quite arbitrary */
480-
481-
if (!rt_task(current)) {
482-
/*
483-
* Boost priority once every ~50k operations. When the
484-
* task tries to take the lock, the rtmutex it will account
485-
* for the new priority, and do any corresponding pi-dance.
486-
*/
487-
if (trsp && !(torture_random(trsp) %
488-
(cxt.nrealwriters_stress * factor))) {
489-
sched_set_fifo(current);
490-
} else /* common case, do nothing */
491-
return;
492-
} else {
493-
/*
494-
* The task will remain boosted for another ~500k operations,
495-
* then restored back to its original prio, and so forth.
496-
*
497-
* When @trsp is nil, we want to force-reset the task for
498-
* stopping the kthread.
499-
*/
500-
if (!trsp || !(torture_random(trsp) %
501-
(cxt.nrealwriters_stress * factor * 2))) {
502-
sched_set_normal(current, 0);
503-
} else /* common case, do nothing */
504-
return;
505-
}
506-
}
507-
508513
static void torture_rtmutex_delay(struct torture_random_state *trsp)
509514
{
510515
const unsigned long shortdelay_us = 2;
@@ -530,10 +535,18 @@ __releases(torture_rtmutex)
530535
rt_mutex_unlock(&torture_rtmutex);
531536
}
532537

538+
static void torture_rt_boost_rtmutex(struct torture_random_state *trsp)
539+
{
540+
if (!rt_boost)
541+
return;
542+
543+
__torture_rt_boost(trsp);
544+
}
545+
533546
static struct lock_torture_ops rtmutex_lock_ops = {
534547
.writelock = torture_rtmutex_lock,
535548
.write_delay = torture_rtmutex_delay,
536-
.task_boost = torture_rtmutex_boost,
549+
.task_boost = torture_rt_boost_rtmutex,
537550
.writeunlock = torture_rtmutex_unlock,
538551
.readlock = NULL,
539552
.read_delay = NULL,
@@ -600,7 +613,7 @@ __releases(torture_rwsem)
600613
static struct lock_torture_ops rwsem_lock_ops = {
601614
.writelock = torture_rwsem_down_write,
602615
.write_delay = torture_rwsem_write_delay,
603-
.task_boost = torture_boost_dummy,
616+
.task_boost = torture_rt_boost,
604617
.writeunlock = torture_rwsem_up_write,
605618
.readlock = torture_rwsem_down_read,
606619
.read_delay = torture_rwsem_read_delay,
@@ -652,7 +665,7 @@ static struct lock_torture_ops percpu_rwsem_lock_ops = {
652665
.exit = torture_percpu_rwsem_exit,
653666
.writelock = torture_percpu_rwsem_down_write,
654667
.write_delay = torture_rwsem_write_delay,
655-
.task_boost = torture_boost_dummy,
668+
.task_boost = torture_rt_boost,
656669
.writeunlock = torture_percpu_rwsem_up_write,
657670
.readlock = torture_percpu_rwsem_down_read,
658671
.read_delay = torture_rwsem_read_delay,

0 commit comments

Comments
 (0)