rcutorture: Abstract torture_shutdown_absorb()
[deliverable/linux.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
f67a3356
PM
52int fullstop = FULLSTOP_RMMOD;
53EXPORT_SYMBOL_GPL(fullstop);
54DEFINE_MUTEX(fullstop_mutex);
55EXPORT_SYMBOL_GPL(fullstop_mutex);
56
51b1130e
PM
57#define TORTURE_RANDOM_MULT 39916801 /* prime */
58#define TORTURE_RANDOM_ADD 479001701 /* prime */
59#define TORTURE_RANDOM_REFRESH 10000
60
61/*
62 * Crude but fast random-number generator. Uses a linear congruential
63 * generator, with occasional help from cpu_clock().
64 */
65unsigned long
66torture_random(struct torture_random_state *trsp)
67{
68 if (--trsp->trs_count < 0) {
69 trsp->trs_state += (unsigned long)local_clock();
70 trsp->trs_count = TORTURE_RANDOM_REFRESH;
71 }
72 trsp->trs_state = trsp->trs_state * TORTURE_RANDOM_MULT +
73 TORTURE_RANDOM_ADD;
74 return swahw32(trsp->trs_state);
75}
76EXPORT_SYMBOL_GPL(torture_random);
f67a3356
PM
77
78/*
79 * Absorb kthreads into a kernel function that won't return, so that
80 * they won't ever access module text or data again.
81 */
82void torture_shutdown_absorb(const char *title)
83{
84 while (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
85 pr_notice(
86 "torture thread %s parking due to system shutdown\n",
87 title);
88 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
89 }
90}
91EXPORT_SYMBOL_GPL(torture_shutdown_absorb);
This page took 0.02765 seconds and 5 git commands to generate.