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 */
....@@ -44,7 +31,7 @@
4431 #include <linux/torture.h>
4532
4633 MODULE_LICENSE("GPL");
47
-MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com>");
34
+MODULE_AUTHOR("Paul E. McKenney <paulmck@linux.ibm.com>");
4835
4936 torture_param(int, nwriters_stress, -1,
5037 "Number of write-locking stress-test threads");
....@@ -449,8 +436,6 @@
449436
450437 static void torture_rtmutex_boost(struct torture_random_state *trsp)
451438 {
452
- int policy;
453
- struct sched_param param;
454439 const unsigned int factor = 50000; /* yes, quite arbitrary */
455440
456441 if (!rt_task(current)) {
....@@ -461,8 +446,7 @@
461446 */
462447 if (trsp && !(torture_random(trsp) %
463448 (cxt.nrealwriters_stress * factor))) {
464
- policy = SCHED_FIFO;
465
- param.sched_priority = MAX_RT_PRIO - 1;
449
+ sched_set_fifo(current);
466450 } else /* common case, do nothing */
467451 return;
468452 } else {
....@@ -475,13 +459,10 @@
475459 */
476460 if (!trsp || !(torture_random(trsp) %
477461 (cxt.nrealwriters_stress * factor * 2))) {
478
- policy = SCHED_NORMAL;
479
- param.sched_priority = 0;
462
+ sched_set_normal(current, 0);
480463 } else /* common case, do nothing */
481464 return;
482465 }
483
-
484
- sched_setscheduler_nocheck(current, policy, &param);
485466 }
486467
487468 static void torture_rtmutex_delay(struct torture_random_state *trsp)
....@@ -585,7 +566,7 @@
585566 #include <linux/percpu-rwsem.h>
586567 static struct percpu_rw_semaphore pcpu_rwsem;
587568
588
-void torture_percpu_rwsem_init(void)
569
+static void torture_percpu_rwsem_init(void)
589570 {
590571 BUG_ON(percpu_init_rwsem(&pcpu_rwsem));
591572 }
....@@ -631,7 +612,7 @@
631612 static int lock_torture_writer(void *arg)
632613 {
633614 struct lock_stress_stats *lwsp = arg;
634
- static DEFINE_TORTURE_RANDOM(rand);
615
+ DEFINE_TORTURE_RANDOM(rand);
635616
636617 VERBOSE_TOROUT_STRING("lock_torture_writer task started");
637618 set_user_nice(current, MAX_NICE);
....@@ -644,13 +625,13 @@
644625 cxt.cur_ops->writelock();
645626 if (WARN_ON_ONCE(lock_is_write_held))
646627 lwsp->n_lock_fail++;
647
- lock_is_write_held = 1;
628
+ lock_is_write_held = true;
648629 if (WARN_ON_ONCE(lock_is_read_held))
649630 lwsp->n_lock_fail++; /* rare, but... */
650631
651632 lwsp->n_lock_acquired++;
652633 cxt.cur_ops->write_delay(&rand);
653
- lock_is_write_held = 0;
634
+ lock_is_write_held = false;
654635 cxt.cur_ops->writeunlock();
655636
656637 stutter_wait("lock_torture_writer");
....@@ -668,7 +649,7 @@
668649 static int lock_torture_reader(void *arg)
669650 {
670651 struct lock_stress_stats *lrsp = arg;
671
- static DEFINE_TORTURE_RANDOM(rand);
652
+ DEFINE_TORTURE_RANDOM(rand);
672653
673654 VERBOSE_TOROUT_STRING("lock_torture_reader task started");
674655 set_user_nice(current, MAX_NICE);
....@@ -678,13 +659,13 @@
678659 schedule_timeout_uninterruptible(1);
679660
680661 cxt.cur_ops->readlock();
681
- lock_is_read_held = 1;
662
+ lock_is_read_held = true;
682663 if (WARN_ON_ONCE(lock_is_write_held))
683664 lrsp->n_lock_fail++; /* rare, but... */
684665
685666 lrsp->n_lock_acquired++;
686667 cxt.cur_ops->read_delay(&rand);
687
- lock_is_read_held = 0;
668
+ lock_is_read_held = false;
688669 cxt.cur_ops->readunlock();
689670
690671 stutter_wait("lock_torture_reader");
....@@ -699,7 +680,7 @@
699680 static void __torture_print_stats(char *page,
700681 struct lock_stress_stats *statp, bool write)
701682 {
702
- bool fail = 0;
683
+ bool fail = false;
703684 int i, n_stress;
704685 long max = 0, min = statp ? statp[0].n_lock_acquired : 0;
705686 long long sum = 0;
....@@ -717,7 +698,8 @@
717698 page += sprintf(page,
718699 "%s: Total: %lld Max/Min: %ld/%ld %s Fail: %d %s\n",
719700 write ? "Writes" : "Reads ",
720
- sum, max, min, max / 2 > min ? "???" : "",
701
+ sum, max, min,
702
+ !onoff_interval && max / 2 > min ? "???" : "",
721703 fail, fail ? "!!!" : "");
722704 if (fail)
723705 atomic_inc(&cxt.n_lock_torture_errors);
....@@ -841,7 +823,9 @@
841823 "End of test: SUCCESS");
842824
843825 kfree(cxt.lwsa);
826
+ cxt.lwsa = NULL;
844827 kfree(cxt.lrsa);
828
+ cxt.lrsa = NULL;
845829
846830 end:
847831 torture_cleanup_end();
....@@ -899,22 +883,22 @@
899883 cxt.nrealwriters_stress = 2 * num_online_cpus();
900884
901885 #ifdef CONFIG_DEBUG_MUTEXES
902
- if (strncmp(torture_type, "mutex", 5) == 0)
886
+ if (str_has_prefix(torture_type, "mutex"))
903887 cxt.debug_lock = true;
904888 #endif
905889 #ifdef CONFIG_DEBUG_RT_MUTEXES
906
- if (strncmp(torture_type, "rtmutex", 7) == 0)
890
+ if (str_has_prefix(torture_type, "rtmutex"))
907891 cxt.debug_lock = true;
908892 #endif
909893 #ifdef CONFIG_DEBUG_SPINLOCK
910
- if ((strncmp(torture_type, "spin", 4) == 0) ||
911
- (strncmp(torture_type, "rw_lock", 7) == 0))
894
+ if ((str_has_prefix(torture_type, "spin")) ||
895
+ (str_has_prefix(torture_type, "rw_lock")))
912896 cxt.debug_lock = true;
913897 #endif
914898
915899 /* Initialize the statistics so that each run gets its own numbers. */
916900 if (nwriters_stress) {
917
- lock_is_write_held = 0;
901
+ lock_is_write_held = false;
918902 cxt.lwsa = kmalloc_array(cxt.nrealwriters_stress,
919903 sizeof(*cxt.lwsa),
920904 GFP_KERNEL);
....@@ -945,7 +929,7 @@
945929 }
946930
947931 if (nreaders_stress) {
948
- lock_is_read_held = 0;
932
+ lock_is_read_held = false;
949933 cxt.lrsa = kmalloc_array(cxt.nrealreaders_stress,
950934 sizeof(*cxt.lrsa),
951935 GFP_KERNEL);
....@@ -969,7 +953,7 @@
969953 /* Prepare torture context. */
970954 if (onoff_interval > 0) {
971955 firsterr = torture_onoff_init(onoff_holdoff * HZ,
972
- onoff_interval * HZ);
956
+ onoff_interval * HZ, NULL);
973957 if (firsterr)
974958 goto unwind;
975959 }
....@@ -985,7 +969,7 @@
985969 goto unwind;
986970 }
987971 if (stutter > 0) {
988
- firsterr = torture_stutter_init(stutter);
972
+ firsterr = torture_stutter_init(stutter, stutter);
989973 if (firsterr)
990974 goto unwind;
991975 }