@@ -46,6 +46,8 @@ torture_param(int, shutdown_secs, 0, "Shutdown time (j), <= zero to disable.");
4646torture_param (int , stat_interval , 60 ,
4747 "Number of seconds between stats printk()s" );
4848torture_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." );
4951torture_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
135171static 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)
179215static 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)
206242static 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)
275311static 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)
318354static 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)
358394static 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-
508513static 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+
533546static 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)
600613static 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