Paul E. McKenney | 082dfb3 | 2019-01-17 10:46:34 -0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Common functions for in-kernel torture tests. |
| 4 | * |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 5 | * Copyright IBM Corporation, 2014 |
| 6 | * |
Paul E. McKenney | 082dfb3 | 2019-01-17 10:46:34 -0800 | [diff] [blame] | 7 | * Author: Paul E. McKenney <paulmck@linux.ibm.com> |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 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 | |
Paul E. McKenney | 9e25022 | 2014-01-27 16:27:00 -0800 | [diff] [blame] | 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 | |
Paul E. McKenney | c2884de | 2014-01-29 07:30:50 -0800 | [diff] [blame] | 31 | #define TORTURE_FLAG "-torture:" |
| 32 | #define TOROUT_STRING(s) \ |
SeongJae Park | 489bb3d2 | 2016-08-21 16:54:40 +0900 | [diff] [blame] | 33 | pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s) |
Paul E. McKenney | c2884de | 2014-01-29 07:30:50 -0800 | [diff] [blame] | 34 | #define VERBOSE_TOROUT_STRING(s) \ |
Paul E. McKenney | 7fafaac | 2014-01-31 17:37:28 -0800 | [diff] [blame] | 35 | do { if (verbose) pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s); } while (0) |
Paul E. McKenney | c2884de | 2014-01-29 07:30:50 -0800 | [diff] [blame] | 36 | #define VERBOSE_TOROUT_ERRSTRING(s) \ |
Paul E. McKenney | 47cf29b | 2014-02-03 11:52:27 -0800 | [diff] [blame] | 37 | do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s); } while (0) |
Paul E. McKenney | c2884de | 2014-01-29 07:30:50 -0800 | [diff] [blame] | 38 | |
Paul E. McKenney | 2e9e808 | 2014-01-28 15:58:22 -0800 | [diff] [blame] | 39 | /* Definitions for online/offline exerciser. */ |
Paul E. McKenney | 3a6cb58 | 2018-12-10 09:44:52 -0800 | [diff] [blame] | 40 | typedef void torture_ofl_func(void); |
Paul E. McKenney | d95f5ba | 2016-04-20 17:18:41 -0700 | [diff] [blame] | 41 | bool torture_offline(int cpu, long *n_onl_attempts, long *n_onl_successes, |
| 42 | unsigned long *sum_offl, int *min_onl, int *max_onl); |
| 43 | bool 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. McKenney | 3a6cb58 | 2018-12-10 09:44:52 -0800 | [diff] [blame] | 45 | int torture_onoff_init(long ooholdoff, long oointerval, torture_ofl_func *f); |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 46 | void torture_onoff_stats(void); |
Paul E. McKenney | 2e9e808 | 2014-01-28 15:58:22 -0800 | [diff] [blame] | 47 | bool torture_onoff_failures(void); |
| 48 | |
Paul E. McKenney | 9e25022 | 2014-01-27 16:27:00 -0800 | [diff] [blame] | 49 | /* Low-rider random number generator. */ |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 50 | struct torture_random_state { |
| 51 | unsigned long trs_state; |
| 52 | long trs_count; |
| 53 | }; |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 54 | #define DEFINE_TORTURE_RANDOM(name) struct torture_random_state name = { 0, 0 } |
Paul E. McKenney | 3025520e | 2018-05-22 11:38:47 -0700 | [diff] [blame] | 55 | #define DEFINE_TORTURE_RANDOM_PERCPU(name) \ |
| 56 | DEFINE_PER_CPU(struct torture_random_state, name) |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 57 | unsigned long torture_random(struct torture_random_state *trsp); |
| 58 | |
Paul E. McKenney | 3808dc9 | 2014-01-28 15:29:21 -0800 | [diff] [blame] | 59 | /* Task shuffler, which causes CPUs to occasionally go idle. */ |
| 60 | void torture_shuffle_task_register(struct task_struct *tp); |
| 61 | int torture_shuffle_init(long shuffint); |
Paul E. McKenney | 3808dc9 | 2014-01-28 15:29:21 -0800 | [diff] [blame] | 62 | |
Paul E. McKenney | e991dbc | 2014-01-31 14:52:13 -0800 | [diff] [blame] | 63 | /* Test auto-shutdown handling. */ |
Paul E. McKenney | f67a335 | 2014-01-29 07:40:27 -0800 | [diff] [blame] | 64 | void torture_shutdown_absorb(const char *title); |
Paul E. McKenney | e991dbc | 2014-01-31 14:52:13 -0800 | [diff] [blame] | 65 | int torture_shutdown_init(int ssecs, void (*cleanup)(void)); |
Paul E. McKenney | f67a335 | 2014-01-29 07:40:27 -0800 | [diff] [blame] | 66 | |
Paul E. McKenney | 628edaa | 2014-01-31 11:57:43 -0800 | [diff] [blame] | 67 | /* Task stuttering, which forces load/no-load transitions. */ |
Paul E. McKenney | 474e59b | 2018-08-07 14:34:44 -0700 | [diff] [blame] | 68 | bool stutter_wait(const char *title); |
Paul E. McKenney | ff3bf92 | 2019-04-09 14:44:49 -0700 | [diff] [blame] | 69 | int torture_stutter_init(int s, int sgap); |
Paul E. McKenney | 628edaa | 2014-01-31 11:57:43 -0800 | [diff] [blame] | 70 | |
Paul E. McKenney | b5daa8f | 2014-01-30 13:38:09 -0800 | [diff] [blame] | 71 | /* Initialization and cleanup. */ |
Paul E. McKenney | 90127d6 | 2018-05-09 10:29:18 -0700 | [diff] [blame] | 72 | bool torture_init_begin(char *ttype, int v); |
Paul E. McKenney | b5daa8f | 2014-01-30 13:38:09 -0800 | [diff] [blame] | 73 | void torture_init_end(void); |
Davidlohr Bueso | d36a7a0 | 2014-09-11 20:40:21 -0700 | [diff] [blame] | 74 | bool torture_cleanup_begin(void); |
| 75 | void torture_cleanup_end(void); |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 76 | bool torture_must_stop(void); |
| 77 | bool torture_must_stop_irq(void); |
Paul E. McKenney | 7fafaac | 2014-01-31 17:37:28 -0800 | [diff] [blame] | 78 | void torture_kthread_stopping(char *title); |
Paul E. McKenney | 47cf29b | 2014-02-03 11:52:27 -0800 | [diff] [blame] | 79 | int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m, |
| 80 | char *f, struct task_struct **tp); |
Paul E. McKenney | 9c029b8 | 2014-02-04 11:47:08 -0800 | [diff] [blame] | 81 | void _torture_stop_kthread(char *m, struct task_struct **tp); |
Paul E. McKenney | 47cf29b | 2014-02-03 11:52:27 -0800 | [diff] [blame] | 82 | |
| 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. McKenney | 9c029b8 | 2014-02-04 11:47:08 -0800 | [diff] [blame] | 86 | #define torture_stop_kthread(n, tp) \ |
| 87 | _torture_stop_kthread("Stopping " #n " task", &(tp)) |
Paul E. McKenney | b5daa8f | 2014-01-30 13:38:09 -0800 | [diff] [blame] | 88 | |
Thomas Gleixner | 01b1d88 | 2019-07-26 23:19:38 +0200 | [diff] [blame] | 89 | #ifdef CONFIG_PREEMPTION |
Paul E. McKenney | cc1321c | 2017-10-16 11:05:03 -0700 | [diff] [blame] | 90 | #define torture_preempt_schedule() preempt_schedule() |
| 91 | #else |
| 92 | #define torture_preempt_schedule() |
| 93 | #endif |
| 94 | |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 95 | #endif /* __LINUX_TORTURE_H */ |