hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/kernel/locking/locktorture.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * Module-based torture test facility for locking
34 *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation; either version 2 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program; if not, you can access it online at
16
- * http://www.gnu.org/licenses/gpl-2.0.html.
17
- *
185 * Copyright (C) IBM Corporation, 2014
196 *
20
- * Authors: Paul E. McKenney <paulmck@us.ibm.com>
7
+ * Authors: Paul E. McKenney <paulmck@linux.ibm.com>
218 * Davidlohr Bueso <dave@stgolabs.net>
229 * Based on kernel/rcu/torture.c.
2310 */
....@@ -29,7 +16,6 @@
2916 #include <linux/kthread.h>
3017 #include <linux/sched/rt.h>
3118 #include <linux/spinlock.h>
32
-#include <linux/rwlock.h>
3319 #include <linux/mutex.h>
3420 #include <linux/rwsem.h>
3521 #include <linux/smp.h>
....@@ -45,7 +31,7 @@
4531 #include <linux/torture.h>
4632
4733 MODULE_LICENSE("GPL");
48
-MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com>");
34
+MODULE_AUTHOR("Paul E. McKenney <paulmck@linux.ibm.com>");
4935
5036 torture_param(int, nwriters_stress, -1,
5137 "Number of write-locking stress-test threads");
....@@ -450,8 +436,6 @@
450436
451437 static void torture_rtmutex_boost(struct torture_random_state *trsp)
452438 {
453
- int policy;
454
- struct sched_param param;
455439 const unsigned int factor = 50000; /* yes, quite arbitrary */
456440
457441 if (!rt_task(current)) {
....@@ -462,8 +446,7 @@
462446 */
463447 if (trsp && !(torture_random(trsp) %
464448 (cxt.nrealwriters_stress * factor))) {
465
- policy = SCHED_FIFO;
466
- param.sched_priority = MAX_RT_PRIO - 1;
449
+ sched_set_fifo(current);
467450 } else /* common case, do nothing */
468451 return;
469452 } else {
....@@ -476,13 +459,10 @@
476459 */
477460 if (!trsp || !(torture_random(trsp) %
478461 (cxt.nrealwriters_stress * factor * 2))) {
479
- policy = SCHED_NORMAL;
480
- param.sched_priority = 0;
462
+ sched_set_normal(current, 0);
481463 } else /* common case, do nothing */
482464 return;
483465 }
484
-
485
- sched_setscheduler_nocheck(current, policy, &param);
486466 }
487467
488468 static void torture_rtmutex_delay(struct torture_random_state *trsp)
....@@ -586,7 +566,7 @@
586566 #include <linux/percpu-rwsem.h>
587567 static struct percpu_rw_semaphore pcpu_rwsem;
588568
589
-void torture_percpu_rwsem_init(void)
569
+static void torture_percpu_rwsem_init(void)
590570 {
591571 BUG_ON(percpu_init_rwsem(&pcpu_rwsem));
592572 }
....@@ -632,7 +612,7 @@
632612 static int lock_torture_writer(void *arg)
633613 {
634614 struct lock_stress_stats *lwsp = arg;
635
- static DEFINE_TORTURE_RANDOM(rand);
615
+ DEFINE_TORTURE_RANDOM(rand);
636616
637617 VERBOSE_TOROUT_STRING("lock_torture_writer task started");
638618 set_user_nice(current, MAX_NICE);
....@@ -645,13 +625,13 @@
645625 cxt.cur_ops->writelock();
646626 if (WARN_ON_ONCE(lock_is_write_held))
647627 lwsp->n_lock_fail++;
648
- lock_is_write_held = 1;
628
+ lock_is_write_held = true;
649629 if (WARN_ON_ONCE(lock_is_read_held))
650630 lwsp->n_lock_fail++; /* rare, but... */
651631
652632 lwsp->n_lock_acquired++;
653633 cxt.cur_ops->write_delay(&rand);
654
- lock_is_write_held = 0;
634
+ lock_is_write_held = false;
655635 cxt.cur_ops->writeunlock();
656636
657637 stutter_wait("lock_torture_writer");
....@@ -669,7 +649,7 @@
669649 static int lock_torture_reader(void *arg)
670650 {
671651 struct lock_stress_stats *lrsp = arg;
672
- static DEFINE_TORTURE_RANDOM(rand);
652
+ DEFINE_TORTURE_RANDOM(rand);
673653
674654 VERBOSE_TOROUT_STRING("lock_torture_reader task started");
675655 set_user_nice(current, MAX_NICE);
....@@ -679,13 +659,13 @@
679659 schedule_timeout_uninterruptible(1);
680660
681661 cxt.cur_ops->readlock();
682
- lock_is_read_held = 1;
662
+ lock_is_read_held = true;
683663 if (WARN_ON_ONCE(lock_is_write_held))
684664 lrsp->n_lock_fail++; /* rare, but... */
685665
686666 lrsp->n_lock_acquired++;
687667 cxt.cur_ops->read_delay(&rand);
688
- lock_is_read_held = 0;
668
+ lock_is_read_held = false;
689669 cxt.cur_ops->readunlock();
690670
691671 stutter_wait("lock_torture_reader");
....@@ -700,7 +680,7 @@
700680 static void __torture_print_stats(char *page,
701681 struct lock_stress_stats *statp, bool write)
702682 {
703
- bool fail = 0;
683
+ bool fail = false;
704684 int i, n_stress;
705685 long max = 0, min = statp ? statp[0].n_lock_acquired : 0;
706686 long long sum = 0;
....@@ -718,7 +698,8 @@
718698 page += sprintf(page,
719699 "%s: Total: %lld Max/Min: %ld/%ld %s Fail: %d %s\n",
720700 write ? "Writes" : "Reads ",
721
- sum, max, min, max / 2 > min ? "???" : "",
701
+ sum, max, min,
702
+ !onoff_interval && max / 2 > min ? "???" : "",
722703 fail, fail ? "!!!" : "");
723704 if (fail)
724705 atomic_inc(&cxt.n_lock_torture_errors);
....@@ -842,7 +823,9 @@
842823 "End of test: SUCCESS");
843824
844825 kfree(cxt.lwsa);
826
+ cxt.lwsa = NULL;
845827 kfree(cxt.lrsa);
828
+ cxt.lrsa = NULL;
846829
847830 end:
848831 torture_cleanup_end();
....@@ -900,22 +883,22 @@
900883 cxt.nrealwriters_stress = 2 * num_online_cpus();
901884
902885 #ifdef CONFIG_DEBUG_MUTEXES
903
- if (strncmp(torture_type, "mutex", 5) == 0)
886
+ if (str_has_prefix(torture_type, "mutex"))
904887 cxt.debug_lock = true;
905888 #endif
906889 #ifdef CONFIG_DEBUG_RT_MUTEXES
907
- if (strncmp(torture_type, "rtmutex", 7) == 0)
890
+ if (str_has_prefix(torture_type, "rtmutex"))
908891 cxt.debug_lock = true;
909892 #endif
910893 #ifdef CONFIG_DEBUG_SPINLOCK
911
- if ((strncmp(torture_type, "spin", 4) == 0) ||
912
- (strncmp(torture_type, "rw_lock", 7) == 0))
894
+ if ((str_has_prefix(torture_type, "spin")) ||
895
+ (str_has_prefix(torture_type, "rw_lock")))
913896 cxt.debug_lock = true;
914897 #endif
915898
916899 /* Initialize the statistics so that each run gets its own numbers. */
917900 if (nwriters_stress) {
918
- lock_is_write_held = 0;
901
+ lock_is_write_held = false;
919902 cxt.lwsa = kmalloc_array(cxt.nrealwriters_stress,
920903 sizeof(*cxt.lwsa),
921904 GFP_KERNEL);
....@@ -946,7 +929,7 @@
946929 }
947930
948931 if (nreaders_stress) {
949
- lock_is_read_held = 0;
932
+ lock_is_read_held = false;
950933 cxt.lrsa = kmalloc_array(cxt.nrealreaders_stress,
951934 sizeof(*cxt.lrsa),
952935 GFP_KERNEL);
....@@ -970,7 +953,7 @@
970953 /* Prepare torture context. */
971954 if (onoff_interval > 0) {
972955 firsterr = torture_onoff_init(onoff_holdoff * HZ,
973
- onoff_interval * HZ);
956
+ onoff_interval * HZ, NULL);
974957 if (firsterr)
975958 goto unwind;
976959 }
....@@ -986,7 +969,7 @@
986969 goto unwind;
987970 }
988971 if (stutter > 0) {
989
- firsterr = torture_stutter_init(stutter);
972
+ firsterr = torture_stutter_init(stutter, stutter);
990973 if (firsterr)
991974 goto unwind;
992975 }