blob: 6241f59e2d6fe19ca60b329c9eed162ed3de2cd7 [file] [log] [blame]
Paul E. McKenney082dfb32019-01-17 10:46:34 -08001/* SPDX-License-Identifier: GPL-2.0+ */
Paul E. McKenney51b11302014-01-27 11:49:39 -08002/*
3 * Common functions for in-kernel torture tests.
4 *
Paul E. McKenney51b11302014-01-27 11:49:39 -08005 * Copyright IBM Corporation, 2014
6 *
Paul E. McKenney082dfb32019-01-17 10:46:34 -08007 * Author: Paul E. McKenney <paulmck@linux.ibm.com>
Paul E. McKenney51b11302014-01-27 11:49:39 -08008 */
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
Paul E. McKenney9e250222014-01-27 16:27:00 -080025/* 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
Paul E. McKenneyc2884de2014-01-29 07:30:50 -080031#define TORTURE_FLAG "-torture:"
32#define TOROUT_STRING(s) \
SeongJae Park489bb3d22016-08-21 16:54:40 +090033 pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s)
Paul E. McKenneyc2884de2014-01-29 07:30:50 -080034#define VERBOSE_TOROUT_STRING(s) \
Paul E. McKenney7fafaac2014-01-31 17:37:28 -080035 do { if (verbose) pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s); } while (0)
Paul E. McKenneyc2884de2014-01-29 07:30:50 -080036#define VERBOSE_TOROUT_ERRSTRING(s) \
Paul E. McKenney47cf29b2014-02-03 11:52:27 -080037 do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s); } while (0)
Paul E. McKenneyc2884de2014-01-29 07:30:50 -080038
Paul E. McKenney2e9e8082014-01-28 15:58:22 -080039/* Definitions for online/offline exerciser. */
Paul E. McKenney3a6cb582018-12-10 09:44:52 -080040typedef void torture_ofl_func(void);
Paul E. McKenneyd95f5ba2016-04-20 17:18:41 -070041bool torture_offline(int cpu, long *n_onl_attempts, long *n_onl_successes,
42 unsigned long *sum_offl, int *min_onl, int *max_onl);
43bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes,
44 unsigned long *sum_onl, int *min_onl, int *max_onl);
Paul E. McKenney3a6cb582018-12-10 09:44:52 -080045int torture_onoff_init(long ooholdoff, long oointerval, torture_ofl_func *f);
Joe Percheseea203f2014-07-14 09:16:15 -040046void torture_onoff_stats(void);
Paul E. McKenney2e9e8082014-01-28 15:58:22 -080047bool torture_onoff_failures(void);
48
Paul E. McKenney9e250222014-01-27 16:27:00 -080049/* Low-rider random number generator. */
Paul E. McKenney51b11302014-01-27 11:49:39 -080050struct torture_random_state {
51 unsigned long trs_state;
52 long trs_count;
53};
Paul E. McKenney51b11302014-01-27 11:49:39 -080054#define DEFINE_TORTURE_RANDOM(name) struct torture_random_state name = { 0, 0 }
Paul E. McKenney3025520e2018-05-22 11:38:47 -070055#define DEFINE_TORTURE_RANDOM_PERCPU(name) \
56 DEFINE_PER_CPU(struct torture_random_state, name)
Paul E. McKenney51b11302014-01-27 11:49:39 -080057unsigned long torture_random(struct torture_random_state *trsp);
58
Paul E. McKenney3808dc92014-01-28 15:29:21 -080059/* Task shuffler, which causes CPUs to occasionally go idle. */
60void torture_shuffle_task_register(struct task_struct *tp);
61int torture_shuffle_init(long shuffint);
Paul E. McKenney3808dc92014-01-28 15:29:21 -080062
Paul E. McKenneye991dbc2014-01-31 14:52:13 -080063/* Test auto-shutdown handling. */
Paul E. McKenneyf67a3352014-01-29 07:40:27 -080064void torture_shutdown_absorb(const char *title);
Paul E. McKenneye991dbc2014-01-31 14:52:13 -080065int torture_shutdown_init(int ssecs, void (*cleanup)(void));
Paul E. McKenneyf67a3352014-01-29 07:40:27 -080066
Paul E. McKenney628edaa2014-01-31 11:57:43 -080067/* Task stuttering, which forces load/no-load transitions. */
Paul E. McKenney474e59b2018-08-07 14:34:44 -070068bool stutter_wait(const char *title);
Paul E. McKenneyff3bf922019-04-09 14:44:49 -070069int torture_stutter_init(int s, int sgap);
Paul E. McKenney628edaa2014-01-31 11:57:43 -080070
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -080071/* Initialization and cleanup. */
Paul E. McKenney90127d62018-05-09 10:29:18 -070072bool torture_init_begin(char *ttype, int v);
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -080073void torture_init_end(void);
Davidlohr Buesod36a7a02014-09-11 20:40:21 -070074bool torture_cleanup_begin(void);
75void torture_cleanup_end(void);
Paul E. McKenney36970bb2014-01-30 15:49:29 -080076bool torture_must_stop(void);
77bool torture_must_stop_irq(void);
Paul E. McKenney7fafaac2014-01-31 17:37:28 -080078void torture_kthread_stopping(char *title);
Paul E. McKenney47cf29b2014-02-03 11:52:27 -080079int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
80 char *f, struct task_struct **tp);
Paul E. McKenney9c029b82014-02-04 11:47:08 -080081void _torture_stop_kthread(char *m, struct task_struct **tp);
Paul E. McKenney47cf29b2014-02-03 11:52:27 -080082
83#define torture_create_kthread(n, arg, tp) \
84 _torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
85 "Failed to create " #n, &(tp))
Paul E. McKenney9c029b82014-02-04 11:47:08 -080086#define torture_stop_kthread(n, tp) \
87 _torture_stop_kthread("Stopping " #n " task", &(tp))
Paul E. McKenneyb5daa8f2014-01-30 13:38:09 -080088
Thomas Gleixner01b1d882019-07-26 23:19:38 +020089#ifdef CONFIG_PREEMPTION
Paul E. McKenneycc1321c2017-10-16 11:05:03 -070090#define torture_preempt_schedule() preempt_schedule()
91#else
92#define torture_preempt_schedule()
93#endif
94
Paul E. McKenney51b11302014-01-27 11:49:39 -080095#endif /* __LINUX_TORTURE_H */