rcutorture: Abstract rcu_torture_random()
[linux-2.6-block.git] / kernel / torture.c
CommitLineData
51b1130e
PM
1/*
2 * Common functions for in-kernel torture tests.
3 *
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 *
18 * Copyright (C) IBM Corporation, 2014
19 *
20 * Author: Paul E. McKenney <paulmck@us.ibm.com>
21 * Based on kernel/rcu/torture.c.
22 */
23#include <linux/types.h>
24#include <linux/kernel.h>
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/kthread.h>
28#include <linux/err.h>
29#include <linux/spinlock.h>
30#include <linux/smp.h>
31#include <linux/interrupt.h>
32#include <linux/sched.h>
33#include <linux/atomic.h>
34#include <linux/bitops.h>
35#include <linux/completion.h>
36#include <linux/moduleparam.h>
37#include <linux/percpu.h>
38#include <linux/notifier.h>
39#include <linux/reboot.h>
40#include <linux/freezer.h>
41#include <linux/cpu.h>
42#include <linux/delay.h>
43#include <linux/stat.h>
44#include <linux/slab.h>
45#include <linux/trace_clock.h>
46#include <asm/byteorder.h>
47#include <linux/torture.h>
48
49MODULE_LICENSE("GPL");
50MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com>");
51
52#define TORTURE_RANDOM_MULT 39916801 /* prime */
53#define TORTURE_RANDOM_ADD 479001701 /* prime */
54#define TORTURE_RANDOM_REFRESH 10000
55
56/*
57 * Crude but fast random-number generator. Uses a linear congruential
58 * generator, with occasional help from cpu_clock().
59 */
60unsigned long
61torture_random(struct torture_random_state *trsp)
62{
63 if (--trsp->trs_count < 0) {
64 trsp->trs_state += (unsigned long)local_clock();
65 trsp->trs_count = TORTURE_RANDOM_REFRESH;
66 }
67 trsp->trs_state = trsp->trs_state * TORTURE_RANDOM_MULT +
68 TORTURE_RANDOM_ADD;
69 return swahw32(trsp->trs_state);
70}
71EXPORT_SYMBOL_GPL(torture_random);