torture.c (8db90aa36063f471bea1e65e23185913043852dc) torture.c (ae19aaafae95a5487469433e9cae4c208f8d15cd)
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Common functions for in-kernel torture tests.
4 *
5 * Copyright (C) IBM Corporation, 2014
6 *
7 * Author: Paul E. McKenney <paulmck@linux.ibm.com>
8 * Based on kernel/rcu/torture.c.

--- 44 unchanged lines hidden (view full) ---

53
54/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
55#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
56#define FULLSTOP_SHUTDOWN 1 /* System shutdown with torture running. */
57#define FULLSTOP_RMMOD 2 /* Normal rmmod of torture. */
58static int fullstop = FULLSTOP_RMMOD;
59static DEFINE_MUTEX(fullstop_mutex);
60
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Common functions for in-kernel torture tests.
4 *
5 * Copyright (C) IBM Corporation, 2014
6 *
7 * Author: Paul E. McKenney <paulmck@linux.ibm.com>
8 * Based on kernel/rcu/torture.c.

--- 44 unchanged lines hidden (view full) ---

53
54/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
55#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
56#define FULLSTOP_SHUTDOWN 1 /* System shutdown with torture running. */
57#define FULLSTOP_RMMOD 2 /* Normal rmmod of torture. */
58static int fullstop = FULLSTOP_RMMOD;
59static DEFINE_MUTEX(fullstop_mutex);
60
61/*
62 * Schedule a high-resolution-timer sleep in nanoseconds, with a 32-bit
63 * nanosecond random fuzz. This function and its friends desynchronize
64 * testing from the timer wheel.
65 */
66int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, struct torture_random_state *trsp)
67{
68 ktime_t hto = baset_ns;
69
70 if (trsp)
71 hto += (torture_random(trsp) >> 3) % fuzzt_ns;
72 set_current_state(TASK_UNINTERRUPTIBLE);
73 return schedule_hrtimeout(&hto, HRTIMER_MODE_REL);
74}
75EXPORT_SYMBOL_GPL(torture_hrtimeout_ns);
76
77/*
78 * Schedule a high-resolution-timer sleep in microseconds, with a 32-bit
79 * nanosecond (not microsecond!) random fuzz.
80 */
81int torture_hrtimeout_us(u32 baset_us, u32 fuzzt_ns, struct torture_random_state *trsp)
82{
83 ktime_t baset_ns = baset_us * NSEC_PER_USEC;
84
85 return torture_hrtimeout_ns(baset_ns, fuzzt_ns, trsp);
86}
87EXPORT_SYMBOL_GPL(torture_hrtimeout_us);
88
89/*
90 * Schedule a high-resolution-timer sleep in milliseconds, with a 32-bit
91 * microsecond (not millisecond!) random fuzz.
92 */
93int torture_hrtimeout_ms(u32 baset_ms, u32 fuzzt_us, struct torture_random_state *trsp)
94{
95 ktime_t baset_ns = baset_ms * NSEC_PER_MSEC;
96 u32 fuzzt_ns;
97
98 if ((u32)~0U / NSEC_PER_USEC < fuzzt_us)
99 fuzzt_ns = (u32)~0U;
100 else
101 fuzzt_ns = fuzzt_us * NSEC_PER_USEC;
102 return torture_hrtimeout_ns(baset_ns, fuzzt_ns, trsp);
103}
104EXPORT_SYMBOL_GPL(torture_hrtimeout_ms);
105
106/*
107 * Schedule a high-resolution-timer sleep in jiffies, with an
108 * implied one-jiffy random fuzz. This is intended to replace calls to
109 * schedule_timeout_interruptible() and friends.
110 */
111int torture_hrtimeout_jiffies(u32 baset_j, struct torture_random_state *trsp)
112{
113 ktime_t baset_ns = jiffies_to_nsecs(baset_j);
114
115 return torture_hrtimeout_ns(baset_ns, jiffies_to_nsecs(1), trsp);
116}
117EXPORT_SYMBOL_GPL(torture_hrtimeout_jiffies);
118
119/*
120 * Schedule a high-resolution-timer sleep in milliseconds, with a 32-bit
121 * millisecond (not second!) random fuzz.
122 */
123int torture_hrtimeout_s(u32 baset_s, u32 fuzzt_ms, struct torture_random_state *trsp)
124{
125 ktime_t baset_ns = baset_s * NSEC_PER_SEC;
126 u32 fuzzt_ns;
127
128 if ((u32)~0U / NSEC_PER_MSEC < fuzzt_ms)
129 fuzzt_ns = (u32)~0U;
130 else
131 fuzzt_ns = fuzzt_ms * NSEC_PER_MSEC;
132 return torture_hrtimeout_ns(baset_ns, fuzzt_ns, trsp);
133}
134EXPORT_SYMBOL_GPL(torture_hrtimeout_s);
135
61#ifdef CONFIG_HOTPLUG_CPU
62
63/*
64 * Variables for online-offline handling. Only present if CPU hotplug
65 * is enabled, otherwise does nothing.
66 */
67
68static struct task_struct *onoff_task;

--- 779 unchanged lines hidden ---
136#ifdef CONFIG_HOTPLUG_CPU
137
138/*
139 * Variables for online-offline handling. Only present if CPU hotplug
140 * is enabled, otherwise does nothing.
141 */
142
143static struct task_struct *onoff_task;

--- 779 unchanged lines hidden ---