History

torture: Add fuzzed hrtimer-based sleep functions

This commit adds torture_hrtimeout_ns(), torture_hrtimeout_us(), torture_hrtimeout_ms(), torture_hrtimeout_jiffies(), and torture_hrtimeout_s(), each of which uses hrtimers to block for a fuzzed time interval. These functions are intended to be used by the various torture tests to decouple wakeups from the timer wheel, thus providing more opportunity for Murphy to insert destructive race conditions.

Paul E. McKenney committed 5 years ago

Commit ae19aaa1 parent 682189a2 files · +82 −0Browse files

Unified · Split

2 files
  1. include/linux/torture.h +7 −0
  2. kernel/torture.c +75 −0
include/linux/torture.h+7−0
@@ -61,6 +61,13 @@ static inline void torture_random_init(struct torture_random_state *trsp) · 60 unmodified lines
61 trsp->trs_count = 0;61 trsp->trs_count = 0;
62}62}
63 63
64/* Definitions for high-resolution-timer sleeps. */
65int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, struct torture_random_state *trsp);
66int torture_hrtimeout_us(u32 baset_us, u32 fuzzt_ns, struct torture_random_state *trsp);
67int torture_hrtimeout_ms(u32 baset_ms, u32 fuzzt_us, struct torture_random_state *trsp);
68int torture_hrtimeout_jiffies(u32 baset_j, struct torture_random_state *trsp);
69int torture_hrtimeout_s(u32 baset_s, u32 fuzzt_ms, struct torture_random_state *trsp);
70
64/* Task shuffler, which causes CPUs to occasionally go idle. */71/* Task shuffler, which causes CPUs to occasionally go idle. */
65void torture_shuffle_task_register(struct task_struct *tp);72void torture_shuffle_task_register(struct task_struct *tp);
66int torture_shuffle_init(long shuffint);73int torture_shuffle_init(long shuffint);
kernel/torture.c+75−0
@@ -58,6 +58,81 @@ static int verbose; · 57 unmodified lines
58static int fullstop = FULLSTOP_RMMOD;58static int fullstop = FULLSTOP_RMMOD;
59static DEFINE_MUTEX(fullstop_mutex);59static DEFINE_MUTEX(fullstop_mutex);
60 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_CPU136#ifdef CONFIG_HOTPLUG_CPU
62 137
63/*138/*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t