2019-01-18 02:46:34 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2014-01-28 03:49:39 +08:00
|
|
|
/*
|
|
|
|
* Common functions for in-kernel torture tests.
|
|
|
|
*
|
|
|
|
* Copyright IBM Corporation, 2014
|
|
|
|
*
|
2019-01-18 02:46:34 +08:00
|
|
|
* Author: Paul E. McKenney <paulmck@linux.ibm.com>
|
2014-01-28 03:49:39 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LINUX_TORTURE_H
|
|
|
|
#define __LINUX_TORTURE_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/cache.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/threads.h>
|
|
|
|
#include <linux/cpumask.h>
|
|
|
|
#include <linux/seqlock.h>
|
|
|
|
#include <linux/lockdep.h>
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/debugobjects.h>
|
|
|
|
#include <linux/bug.h>
|
|
|
|
#include <linux/compiler.h>
|
|
|
|
|
2014-01-28 08:27:00 +08:00
|
|
|
/* Definitions for a non-string torture-test module parameter. */
|
|
|
|
#define torture_param(type, name, init, msg) \
|
|
|
|
static type name = init; \
|
|
|
|
module_param(name, type, 0444); \
|
|
|
|
MODULE_PARM_DESC(name, msg);
|
|
|
|
|
2014-01-29 23:30:50 +08:00
|
|
|
#define TORTURE_FLAG "-torture:"
|
|
|
|
#define TOROUT_STRING(s) \
|
2016-08-21 15:54:40 +08:00
|
|
|
pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s)
|
2014-01-29 23:30:50 +08:00
|
|
|
#define VERBOSE_TOROUT_STRING(s) \
|
2020-11-26 05:00:04 +08:00
|
|
|
do { \
|
|
|
|
if (verbose) { \
|
|
|
|
verbose_torout_sleep(); \
|
|
|
|
pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2014-01-29 23:30:50 +08:00
|
|
|
#define VERBOSE_TOROUT_ERRSTRING(s) \
|
2020-11-26 05:00:04 +08:00
|
|
|
do { \
|
|
|
|
if (verbose) { \
|
|
|
|
verbose_torout_sleep(); \
|
|
|
|
pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
void verbose_torout_sleep(void);
|
2014-01-29 23:30:50 +08:00
|
|
|
|
2014-01-29 07:58:22 +08:00
|
|
|
/* Definitions for online/offline exerciser. */
|
2020-12-19 23:34:35 +08:00
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
|
|
int torture_num_online_cpus(void);
|
|
|
|
#else /* #ifdef CONFIG_HOTPLUG_CPU */
|
|
|
|
static inline int torture_num_online_cpus(void) { return 1; }
|
|
|
|
#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
|
2018-12-11 01:44:52 +08:00
|
|
|
typedef void torture_ofl_func(void);
|
2016-04-21 08:18:41 +08:00
|
|
|
bool torture_offline(int cpu, long *n_onl_attempts, long *n_onl_successes,
|
|
|
|
unsigned long *sum_offl, int *min_onl, int *max_onl);
|
|
|
|
bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes,
|
|
|
|
unsigned long *sum_onl, int *min_onl, int *max_onl);
|
2018-12-11 01:44:52 +08:00
|
|
|
int torture_onoff_init(long ooholdoff, long oointerval, torture_ofl_func *f);
|
2014-07-14 21:16:15 +08:00
|
|
|
void torture_onoff_stats(void);
|
2014-01-29 07:58:22 +08:00
|
|
|
bool torture_onoff_failures(void);
|
|
|
|
|
2014-01-28 08:27:00 +08:00
|
|
|
/* Low-rider random number generator. */
|
2014-01-28 03:49:39 +08:00
|
|
|
struct torture_random_state {
|
|
|
|
unsigned long trs_state;
|
|
|
|
long trs_count;
|
|
|
|
};
|
|
|
|
#define DEFINE_TORTURE_RANDOM(name) struct torture_random_state name = { 0, 0 }
|
2018-05-23 02:38:47 +08:00
|
|
|
#define DEFINE_TORTURE_RANDOM_PERCPU(name) \
|
|
|
|
DEFINE_PER_CPU(struct torture_random_state, name)
|
2014-01-28 03:49:39 +08:00
|
|
|
unsigned long torture_random(struct torture_random_state *trsp);
|
2020-04-25 02:21:40 +08:00
|
|
|
static inline void torture_random_init(struct torture_random_state *trsp)
|
|
|
|
{
|
|
|
|
trsp->trs_state = 0;
|
|
|
|
trsp->trs_count = 0;
|
|
|
|
}
|
2014-01-28 03:49:39 +08:00
|
|
|
|
2020-11-18 03:30:18 +08:00
|
|
|
/* Definitions for high-resolution-timer sleeps. */
|
|
|
|
int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, struct torture_random_state *trsp);
|
|
|
|
int torture_hrtimeout_us(u32 baset_us, u32 fuzzt_ns, struct torture_random_state *trsp);
|
|
|
|
int torture_hrtimeout_ms(u32 baset_ms, u32 fuzzt_us, struct torture_random_state *trsp);
|
|
|
|
int torture_hrtimeout_jiffies(u32 baset_j, struct torture_random_state *trsp);
|
|
|
|
int torture_hrtimeout_s(u32 baset_s, u32 fuzzt_ms, struct torture_random_state *trsp);
|
|
|
|
|
2014-01-29 07:29:21 +08:00
|
|
|
/* Task shuffler, which causes CPUs to occasionally go idle. */
|
|
|
|
void torture_shuffle_task_register(struct task_struct *tp);
|
|
|
|
int torture_shuffle_init(long shuffint);
|
|
|
|
|
2014-02-01 06:52:13 +08:00
|
|
|
/* Test auto-shutdown handling. */
|
2014-01-29 23:40:27 +08:00
|
|
|
void torture_shutdown_absorb(const char *title);
|
2014-02-01 06:52:13 +08:00
|
|
|
int torture_shutdown_init(int ssecs, void (*cleanup)(void));
|
2014-01-29 23:40:27 +08:00
|
|
|
|
2014-02-01 03:57:43 +08:00
|
|
|
/* Task stuttering, which forces load/no-load transitions. */
|
2018-08-08 05:34:44 +08:00
|
|
|
bool stutter_wait(const char *title);
|
2019-04-10 05:44:49 +08:00
|
|
|
int torture_stutter_init(int s, int sgap);
|
2014-02-01 03:57:43 +08:00
|
|
|
|
2014-01-31 05:38:09 +08:00
|
|
|
/* Initialization and cleanup. */
|
2018-05-10 01:29:18 +08:00
|
|
|
bool torture_init_begin(char *ttype, int v);
|
2014-01-31 05:38:09 +08:00
|
|
|
void torture_init_end(void);
|
2014-09-12 11:40:21 +08:00
|
|
|
bool torture_cleanup_begin(void);
|
|
|
|
void torture_cleanup_end(void);
|
2014-01-31 07:49:29 +08:00
|
|
|
bool torture_must_stop(void);
|
|
|
|
bool torture_must_stop_irq(void);
|
2014-02-01 09:37:28 +08:00
|
|
|
void torture_kthread_stopping(char *title);
|
2014-02-04 03:52:27 +08:00
|
|
|
int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
|
|
|
|
char *f, struct task_struct **tp);
|
2014-02-05 03:47:08 +08:00
|
|
|
void _torture_stop_kthread(char *m, struct task_struct **tp);
|
2014-02-04 03:52:27 +08:00
|
|
|
|
|
|
|
#define torture_create_kthread(n, arg, tp) \
|
|
|
|
_torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
|
|
|
|
"Failed to create " #n, &(tp))
|
2014-02-05 03:47:08 +08:00
|
|
|
#define torture_stop_kthread(n, tp) \
|
|
|
|
_torture_stop_kthread("Stopping " #n " task", &(tp))
|
2014-01-31 05:38:09 +08:00
|
|
|
|
2019-07-27 05:19:38 +08:00
|
|
|
#ifdef CONFIG_PREEMPTION
|
2017-10-17 02:05:03 +08:00
|
|
|
#define torture_preempt_schedule() preempt_schedule()
|
|
|
|
#else
|
2020-02-26 13:09:19 +08:00
|
|
|
#define torture_preempt_schedule() do { } while (0)
|
2017-10-17 02:05:03 +08:00
|
|
|
#endif
|
|
|
|
|
2014-01-28 03:49:39 +08:00
|
|
|
#endif /* __LINUX_TORTURE_H */
|