xref: /openbmc/linux/kernel/torture.c (revision 51b1130eb5823ddb90a9ad07d243031d8cb7ecf2)
1*51b1130eSPaul E. McKenney /*
2*51b1130eSPaul E. McKenney  * Common functions for in-kernel torture tests.
3*51b1130eSPaul E. McKenney  *
4*51b1130eSPaul E. McKenney  * This program is free software; you can redistribute it and/or modify
5*51b1130eSPaul E. McKenney  * it under the terms of the GNU General Public License as published by
6*51b1130eSPaul E. McKenney  * the Free Software Foundation; either version 2 of the License, or
7*51b1130eSPaul E. McKenney  * (at your option) any later version.
8*51b1130eSPaul E. McKenney  *
9*51b1130eSPaul E. McKenney  * This program is distributed in the hope that it will be useful,
10*51b1130eSPaul E. McKenney  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*51b1130eSPaul E. McKenney  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*51b1130eSPaul E. McKenney  * GNU General Public License for more details.
13*51b1130eSPaul E. McKenney  *
14*51b1130eSPaul E. McKenney  * You should have received a copy of the GNU General Public License
15*51b1130eSPaul E. McKenney  * along with this program; if not, you can access it online at
16*51b1130eSPaul E. McKenney  * http://www.gnu.org/licenses/gpl-2.0.html.
17*51b1130eSPaul E. McKenney  *
18*51b1130eSPaul E. McKenney  * Copyright (C) IBM Corporation, 2014
19*51b1130eSPaul E. McKenney  *
20*51b1130eSPaul E. McKenney  * Author: Paul E. McKenney <paulmck@us.ibm.com>
21*51b1130eSPaul E. McKenney  *	Based on kernel/rcu/torture.c.
22*51b1130eSPaul E. McKenney  */
23*51b1130eSPaul E. McKenney #include <linux/types.h>
24*51b1130eSPaul E. McKenney #include <linux/kernel.h>
25*51b1130eSPaul E. McKenney #include <linux/init.h>
26*51b1130eSPaul E. McKenney #include <linux/module.h>
27*51b1130eSPaul E. McKenney #include <linux/kthread.h>
28*51b1130eSPaul E. McKenney #include <linux/err.h>
29*51b1130eSPaul E. McKenney #include <linux/spinlock.h>
30*51b1130eSPaul E. McKenney #include <linux/smp.h>
31*51b1130eSPaul E. McKenney #include <linux/interrupt.h>
32*51b1130eSPaul E. McKenney #include <linux/sched.h>
33*51b1130eSPaul E. McKenney #include <linux/atomic.h>
34*51b1130eSPaul E. McKenney #include <linux/bitops.h>
35*51b1130eSPaul E. McKenney #include <linux/completion.h>
36*51b1130eSPaul E. McKenney #include <linux/moduleparam.h>
37*51b1130eSPaul E. McKenney #include <linux/percpu.h>
38*51b1130eSPaul E. McKenney #include <linux/notifier.h>
39*51b1130eSPaul E. McKenney #include <linux/reboot.h>
40*51b1130eSPaul E. McKenney #include <linux/freezer.h>
41*51b1130eSPaul E. McKenney #include <linux/cpu.h>
42*51b1130eSPaul E. McKenney #include <linux/delay.h>
43*51b1130eSPaul E. McKenney #include <linux/stat.h>
44*51b1130eSPaul E. McKenney #include <linux/slab.h>
45*51b1130eSPaul E. McKenney #include <linux/trace_clock.h>
46*51b1130eSPaul E. McKenney #include <asm/byteorder.h>
47*51b1130eSPaul E. McKenney #include <linux/torture.h>
48*51b1130eSPaul E. McKenney 
49*51b1130eSPaul E. McKenney MODULE_LICENSE("GPL");
50*51b1130eSPaul E. McKenney MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com>");
51*51b1130eSPaul E. McKenney 
52*51b1130eSPaul E. McKenney #define TORTURE_RANDOM_MULT	39916801  /* prime */
53*51b1130eSPaul E. McKenney #define TORTURE_RANDOM_ADD	479001701 /* prime */
54*51b1130eSPaul E. McKenney #define TORTURE_RANDOM_REFRESH	10000
55*51b1130eSPaul E. McKenney 
56*51b1130eSPaul E. McKenney /*
57*51b1130eSPaul E. McKenney  * Crude but fast random-number generator.  Uses a linear congruential
58*51b1130eSPaul E. McKenney  * generator, with occasional help from cpu_clock().
59*51b1130eSPaul E. McKenney  */
60*51b1130eSPaul E. McKenney unsigned long
61*51b1130eSPaul E. McKenney torture_random(struct torture_random_state *trsp)
62*51b1130eSPaul E. McKenney {
63*51b1130eSPaul E. McKenney 	if (--trsp->trs_count < 0) {
64*51b1130eSPaul E. McKenney 		trsp->trs_state += (unsigned long)local_clock();
65*51b1130eSPaul E. McKenney 		trsp->trs_count = TORTURE_RANDOM_REFRESH;
66*51b1130eSPaul E. McKenney 	}
67*51b1130eSPaul E. McKenney 	trsp->trs_state = trsp->trs_state * TORTURE_RANDOM_MULT +
68*51b1130eSPaul E. McKenney 		TORTURE_RANDOM_ADD;
69*51b1130eSPaul E. McKenney 	return swahw32(trsp->trs_state);
70*51b1130eSPaul E. McKenney }
71*51b1130eSPaul E. McKenney EXPORT_SYMBOL_GPL(torture_random);
72