PM: fix missing rculist.h dependency
[linux-2.6-block.git] / include / linux / torture.h
CommitLineData
082dfb3c 1/* SPDX-License-Identifier: GPL-2.0+ */
51b1130e
PM
2/*
3 * Common functions for in-kernel torture tests.
4 *
51b1130e
PM
5 * Copyright IBM Corporation, 2014
6 *
082dfb3c 7 * Author: Paul E. McKenney <paulmck@linux.ibm.com>
51b1130e
PM
8 */
9
10#ifndef __LINUX_TORTURE_H
11#define __LINUX_TORTURE_H
12
13#include <linux/types.h>
14#include <linux/cache.h>
15#include <linux/spinlock.h>
16#include <linux/threads.h>
17#include <linux/cpumask.h>
18#include <linux/seqlock.h>
19#include <linux/lockdep.h>
20#include <linux/completion.h>
21#include <linux/debugobjects.h>
22#include <linux/bug.h>
23#include <linux/compiler.h>
24
9e250225
PM
25/* Definitions for a non-string torture-test module parameter. */
26#define torture_param(type, name, init, msg) \
27 static type name = init; \
28 module_param(name, type, 0444); \
29 MODULE_PARM_DESC(name, msg);
30
c2884de3
PM
31#define TORTURE_FLAG "-torture:"
32#define TOROUT_STRING(s) \
489bb3d2 33 pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s)
c2884de3 34#define VERBOSE_TOROUT_STRING(s) \
8a67a20b
PM
35do { \
36 if (verbose) { \
37 verbose_torout_sleep(); \
38 pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s); \
39 } \
40} while (0)
81faa4f6
LZ
41#define TOROUT_ERRSTRING(s) \
42 pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s)
8a67a20b 43void verbose_torout_sleep(void);
c2884de3 44
efeff6b3
PM
45#define torture_init_error(firsterr) \
46({ \
47 int ___firsterr = (firsterr); \
48 \
49 WARN_ONCE(!IS_MODULE(CONFIG_RCU_TORTURE_TEST) && ___firsterr < 0, "Torture-test initialization failed with error code %d\n", ___firsterr); \
50 ___firsterr < 0; \
51})
52
2e9e8081 53/* Definitions for online/offline exerciser. */
1afb95fe
PM
54#ifdef CONFIG_HOTPLUG_CPU
55int torture_num_online_cpus(void);
56#else /* #ifdef CONFIG_HOTPLUG_CPU */
57static inline int torture_num_online_cpus(void) { return 1; }
58#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
3a6cb58f 59typedef void torture_ofl_func(void);
d95f5ba9
PM
60bool torture_offline(int cpu, long *n_onl_attempts, long *n_onl_successes,
61 unsigned long *sum_offl, int *min_onl, int *max_onl);
62bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes,
63 unsigned long *sum_onl, int *min_onl, int *max_onl);
3a6cb58f 64int torture_onoff_init(long ooholdoff, long oointerval, torture_ofl_func *f);
eea203fe 65void torture_onoff_stats(void);
2e9e8081
PM
66bool torture_onoff_failures(void);
67
9e250225 68/* Low-rider random number generator. */
51b1130e
PM
69struct torture_random_state {
70 unsigned long trs_state;
71 long trs_count;
72};
51b1130e 73#define DEFINE_TORTURE_RANDOM(name) struct torture_random_state name = { 0, 0 }
3025520e
PM
74#define DEFINE_TORTURE_RANDOM_PERCPU(name) \
75 DEFINE_PER_CPU(struct torture_random_state, name)
51b1130e 76unsigned long torture_random(struct torture_random_state *trsp);
4a5f133c
PM
77static inline void torture_random_init(struct torture_random_state *trsp)
78{
79 trsp->trs_state = 0;
80 trsp->trs_count = 0;
81}
51b1130e 82
ae19aaaf 83/* Definitions for high-resolution-timer sleeps. */
a741deac
PM
84int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, const enum hrtimer_mode mode,
85 struct torture_random_state *trsp);
ae19aaaf
PM
86int torture_hrtimeout_us(u32 baset_us, u32 fuzzt_ns, struct torture_random_state *trsp);
87int torture_hrtimeout_ms(u32 baset_ms, u32 fuzzt_us, struct torture_random_state *trsp);
88int torture_hrtimeout_jiffies(u32 baset_j, struct torture_random_state *trsp);
89int torture_hrtimeout_s(u32 baset_s, u32 fuzzt_ms, struct torture_random_state *trsp);
90
3808dc9f
PM
91/* Task shuffler, which causes CPUs to occasionally go idle. */
92void torture_shuffle_task_register(struct task_struct *tp);
93int torture_shuffle_init(long shuffint);
3808dc9f 94
e991dbc0 95/* Test auto-shutdown handling. */
f67a3356 96void torture_shutdown_absorb(const char *title);
e991dbc0 97int torture_shutdown_init(int ssecs, void (*cleanup)(void));
f67a3356 98
628edaa5 99/* Task stuttering, which forces load/no-load transitions. */
474e59b4 100bool stutter_wait(const char *title);
ff3bf92d 101int torture_stutter_init(int s, int sgap);
628edaa5 102
b5daa8f3 103/* Initialization and cleanup. */
90127d60 104bool torture_init_begin(char *ttype, int v);
b5daa8f3 105void torture_init_end(void);
d36a7a0d
DB
106bool torture_cleanup_begin(void);
107void torture_cleanup_end(void);
36970bb9
PM
108bool torture_must_stop(void);
109bool torture_must_stop_irq(void);
7fafaac5 110void torture_kthread_stopping(char *title);
47cf29b9 111int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
67d5404d 112 char *f, struct task_struct **tp, void (*cbf)(struct task_struct *tp));
9c029b86 113void _torture_stop_kthread(char *m, struct task_struct **tp);
47cf29b9
PM
114
115#define torture_create_kthread(n, arg, tp) \
116 _torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
67d5404d
PM
117 "Failed to create " #n, &(tp), NULL)
118#define torture_create_kthread_cb(n, arg, tp, cbf) \
119 _torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
120 "Failed to create " #n, &(tp), cbf)
9c029b86
PM
121#define torture_stop_kthread(n, tp) \
122 _torture_stop_kthread("Stopping " #n " task", &(tp))
b5daa8f3 123
0cfecd7d 124/* Scheduler-related definitions. */
01b1d88b 125#ifdef CONFIG_PREEMPTION
bd6c375b 126#define torture_preempt_schedule() __preempt_schedule()
cc1321c9 127#else
be44ae62 128#define torture_preempt_schedule() do { } while (0)
cc1321c9
PM
129#endif
130
0cfecd7d
PM
131#if IS_ENABLED(CONFIG_RCU_TORTURE_TEST) || IS_MODULE(CONFIG_RCU_TORTURE_TEST) || IS_ENABLED(CONFIG_LOCK_TORTURE_TEST) || IS_MODULE(CONFIG_LOCK_TORTURE_TEST)
132long torture_sched_setaffinity(pid_t pid, const struct cpumask *in_mask);
133#endif
134
51b1130e 135#endif /* __LINUX_TORTURE_H */