Linux Audio

Check our new training course

Loading...
v5.14.15
  1/* SPDX-License-Identifier: GPL-2.0+ */
  2/*
  3 * Common functions for in-kernel torture tests.
  4 *
  5 * Copyright IBM Corporation, 2014
  6 *
  7 * Author: Paul E. McKenney <paulmck@linux.ibm.com>
  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
 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
 31#define TORTURE_FLAG "-torture:"
 32#define TOROUT_STRING(s) \
 33	pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s)
 34#define VERBOSE_TOROUT_STRING(s) \
 35do {										\
 36	if (verbose) {								\
 37		verbose_torout_sleep();						\
 38		pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s);		\
 39	}									\
 40} while (0)
 41#define VERBOSE_TOROUT_ERRSTRING(s) \
 42do {										\
 43	if (verbose) {								\
 44		verbose_torout_sleep();						\
 45		pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s);	\
 46	}									\
 47} while (0)
 48void verbose_torout_sleep(void);
 49
 
 
 
 
 
 
 
 
 50/* Definitions for online/offline exerciser. */
 51#ifdef CONFIG_HOTPLUG_CPU
 52int torture_num_online_cpus(void);
 53#else /* #ifdef CONFIG_HOTPLUG_CPU */
 54static inline int torture_num_online_cpus(void) { return 1; }
 55#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
 56typedef void torture_ofl_func(void);
 57bool torture_offline(int cpu, long *n_onl_attempts, long *n_onl_successes,
 58		     unsigned long *sum_offl, int *min_onl, int *max_onl);
 59bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes,
 60		    unsigned long *sum_onl, int *min_onl, int *max_onl);
 61int torture_onoff_init(long ooholdoff, long oointerval, torture_ofl_func *f);
 62void torture_onoff_stats(void);
 63bool torture_onoff_failures(void);
 64
 65/* Low-rider random number generator. */
 66struct torture_random_state {
 67	unsigned long trs_state;
 68	long trs_count;
 69};
 70#define DEFINE_TORTURE_RANDOM(name) struct torture_random_state name = { 0, 0 }
 71#define DEFINE_TORTURE_RANDOM_PERCPU(name) \
 72	DEFINE_PER_CPU(struct torture_random_state, name)
 73unsigned long torture_random(struct torture_random_state *trsp);
 74static inline void torture_random_init(struct torture_random_state *trsp)
 75{
 76	trsp->trs_state = 0;
 77	trsp->trs_count = 0;
 78}
 79
 80/* Definitions for high-resolution-timer sleeps. */
 81int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, struct torture_random_state *trsp);
 
 82int torture_hrtimeout_us(u32 baset_us, u32 fuzzt_ns, struct torture_random_state *trsp);
 83int torture_hrtimeout_ms(u32 baset_ms, u32 fuzzt_us, struct torture_random_state *trsp);
 84int torture_hrtimeout_jiffies(u32 baset_j, struct torture_random_state *trsp);
 85int torture_hrtimeout_s(u32 baset_s, u32 fuzzt_ms, struct torture_random_state *trsp);
 86
 87/* Task shuffler, which causes CPUs to occasionally go idle. */
 88void torture_shuffle_task_register(struct task_struct *tp);
 89int torture_shuffle_init(long shuffint);
 90
 91/* Test auto-shutdown handling. */
 92void torture_shutdown_absorb(const char *title);
 93int torture_shutdown_init(int ssecs, void (*cleanup)(void));
 94
 95/* Task stuttering, which forces load/no-load transitions. */
 96bool stutter_wait(const char *title);
 97int torture_stutter_init(int s, int sgap);
 98
 99/* Initialization and cleanup. */
100bool torture_init_begin(char *ttype, int v);
101void torture_init_end(void);
102bool torture_cleanup_begin(void);
103void torture_cleanup_end(void);
104bool torture_must_stop(void);
105bool torture_must_stop_irq(void);
106void torture_kthread_stopping(char *title);
107int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
108			     char *f, struct task_struct **tp);
109void _torture_stop_kthread(char *m, struct task_struct **tp);
110
111#define torture_create_kthread(n, arg, tp) \
112	_torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
113				"Failed to create " #n, &(tp))
 
 
 
114#define torture_stop_kthread(n, tp) \
115	_torture_stop_kthread("Stopping " #n " task", &(tp))
116
 
117#ifdef CONFIG_PREEMPTION
118#define torture_preempt_schedule() preempt_schedule()
119#else
120#define torture_preempt_schedule()	do { } while (0)
 
 
 
 
121#endif
122
123#endif /* __LINUX_TORTURE_H */
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0+ */
  2/*
  3 * Common functions for in-kernel torture tests.
  4 *
  5 * Copyright IBM Corporation, 2014
  6 *
  7 * Author: Paul E. McKenney <paulmck@linux.ibm.com>
  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_types.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#include <linux/hrtimer.h>
 25
 26/* Definitions for a non-string torture-test module parameter. */
 27#define torture_param(type, name, init, msg) \
 28	static type name = init; \
 29	module_param(name, type, 0444); \
 30	MODULE_PARM_DESC(name, msg);
 31
 32#define TORTURE_FLAG "-torture:"
 33#define TOROUT_STRING(s) \
 34	pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s)
 35#define VERBOSE_TOROUT_STRING(s) \
 36do {										\
 37	if (verbose) {								\
 38		verbose_torout_sleep();						\
 39		pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s);		\
 40	}									\
 41} while (0)
 42#define TOROUT_ERRSTRING(s) \
 43	pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s)
 
 
 
 
 
 44void verbose_torout_sleep(void);
 45
 46#define torture_init_error(firsterr)						\
 47({										\
 48	int ___firsterr = (firsterr);						\
 49										\
 50	WARN_ONCE(!IS_MODULE(CONFIG_RCU_TORTURE_TEST) && ___firsterr < 0, "Torture-test initialization failed with error code %d\n", ___firsterr); \
 51	___firsterr < 0;								\
 52})
 53
 54/* Definitions for online/offline exerciser. */
 55#ifdef CONFIG_HOTPLUG_CPU
 56int torture_num_online_cpus(void);
 57#else /* #ifdef CONFIG_HOTPLUG_CPU */
 58static inline int torture_num_online_cpus(void) { return 1; }
 59#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
 60typedef void torture_ofl_func(void);
 61bool torture_offline(int cpu, long *n_onl_attempts, long *n_onl_successes,
 62		     unsigned long *sum_offl, int *min_onl, int *max_onl);
 63bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes,
 64		    unsigned long *sum_onl, int *min_onl, int *max_onl);
 65int torture_onoff_init(long ooholdoff, long oointerval, torture_ofl_func *f);
 66void torture_onoff_stats(void);
 67bool torture_onoff_failures(void);
 68
 69/* Low-rider random number generator. */
 70struct torture_random_state {
 71	unsigned long trs_state;
 72	long trs_count;
 73};
 74#define DEFINE_TORTURE_RANDOM(name) struct torture_random_state name = { 0, 0 }
 75#define DEFINE_TORTURE_RANDOM_PERCPU(name) \
 76	DEFINE_PER_CPU(struct torture_random_state, name)
 77unsigned long torture_random(struct torture_random_state *trsp);
 78static inline void torture_random_init(struct torture_random_state *trsp)
 79{
 80	trsp->trs_state = 0;
 81	trsp->trs_count = 0;
 82}
 83
 84/* Definitions for high-resolution-timer sleeps. */
 85int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, const enum hrtimer_mode mode,
 86			 struct torture_random_state *trsp);
 87int torture_hrtimeout_us(u32 baset_us, u32 fuzzt_ns, struct torture_random_state *trsp);
 88int torture_hrtimeout_ms(u32 baset_ms, u32 fuzzt_us, struct torture_random_state *trsp);
 89int torture_hrtimeout_jiffies(u32 baset_j, struct torture_random_state *trsp);
 90int torture_hrtimeout_s(u32 baset_s, u32 fuzzt_ms, struct torture_random_state *trsp);
 91
 92/* Task shuffler, which causes CPUs to occasionally go idle. */
 93void torture_shuffle_task_register(struct task_struct *tp);
 94int torture_shuffle_init(long shuffint);
 95
 96/* Test auto-shutdown handling. */
 97void torture_shutdown_absorb(const char *title);
 98int torture_shutdown_init(int ssecs, void (*cleanup)(void));
 99
100/* Task stuttering, which forces load/no-load transitions. */
101bool stutter_wait(const char *title);
102int torture_stutter_init(int s, int sgap);
103
104/* Initialization and cleanup. */
105bool torture_init_begin(char *ttype, int v);
106void torture_init_end(void);
107bool torture_cleanup_begin(void);
108void torture_cleanup_end(void);
109bool torture_must_stop(void);
110bool torture_must_stop_irq(void);
111void torture_kthread_stopping(char *title);
112int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
113			     char *f, struct task_struct **tp, void (*cbf)(struct task_struct *tp));
114void _torture_stop_kthread(char *m, struct task_struct **tp);
115
116#define torture_create_kthread(n, arg, tp) \
117	_torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
118				"Failed to create " #n, &(tp), NULL)
119#define torture_create_kthread_cb(n, arg, tp, cbf) \
120	_torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
121				"Failed to create " #n, &(tp), cbf)
122#define torture_stop_kthread(n, tp) \
123	_torture_stop_kthread("Stopping " #n " task", &(tp))
124
125/* Scheduler-related definitions. */
126#ifdef CONFIG_PREEMPTION
127#define torture_preempt_schedule() __preempt_schedule()
128#else
129#define torture_preempt_schedule()	do { } while (0)
130#endif
131
132#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)
133long torture_sched_setaffinity(pid_t pid, const struct cpumask *in_mask);
134#endif
135
136#endif /* __LINUX_TORTURE_H */