Skip to content

Commit a741dea

Browse files
paulmckrcuFrederic Weisbecker
authored and
Frederic Weisbecker
committed
torture: Make torture_hrtimeout_ns() take an hrtimer mode parameter
The current torture-test sleeps are waiting for a duration, but there are situations where it is better to wait for an absolute time, for example, when ending a stutter interval. This commit therefore adds an hrtimer mode parameter to torture_hrtimeout_ns(). Why not also the other torture_hrtimeout_*() functions? The theory is that most absolute times will be in nanoseconds, especially not (say) jiffies. Signed-off-by: Paul E. McKenney <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]>
1 parent 40baf39 commit a741dea

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

include/linux/torture.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ static inline void torture_random_init(struct torture_random_state *trsp)
8181
}
8282

8383
/* Definitions for high-resolution-timer sleeps. */
84-
int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, struct torture_random_state *trsp);
84+
int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, const enum hrtimer_mode mode,
85+
struct torture_random_state *trsp);
8586
int torture_hrtimeout_us(u32 baset_us, u32 fuzzt_ns, struct torture_random_state *trsp);
8687
int torture_hrtimeout_ms(u32 baset_ms, u32 fuzzt_us, struct torture_random_state *trsp);
8788
int torture_hrtimeout_jiffies(u32 baset_j, struct torture_random_state *trsp);

kernel/torture.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,15 @@ EXPORT_SYMBOL_GPL(verbose_torout_sleep);
8787
* nanosecond random fuzz. This function and its friends desynchronize
8888
* testing from the timer wheel.
8989
*/
90-
int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, struct torture_random_state *trsp)
90+
int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, const enum hrtimer_mode mode,
91+
struct torture_random_state *trsp)
9192
{
9293
ktime_t hto = baset_ns;
9394

9495
if (trsp)
9596
hto += torture_random(trsp) % fuzzt_ns;
9697
set_current_state(TASK_IDLE);
97-
return schedule_hrtimeout(&hto, HRTIMER_MODE_REL);
98+
return schedule_hrtimeout(&hto, mode);
9899
}
99100
EXPORT_SYMBOL_GPL(torture_hrtimeout_ns);
100101

@@ -106,7 +107,7 @@ int torture_hrtimeout_us(u32 baset_us, u32 fuzzt_ns, struct torture_random_state
106107
{
107108
ktime_t baset_ns = baset_us * NSEC_PER_USEC;
108109

109-
return torture_hrtimeout_ns(baset_ns, fuzzt_ns, trsp);
110+
return torture_hrtimeout_ns(baset_ns, fuzzt_ns, HRTIMER_MODE_REL, trsp);
110111
}
111112
EXPORT_SYMBOL_GPL(torture_hrtimeout_us);
112113

@@ -123,7 +124,7 @@ int torture_hrtimeout_ms(u32 baset_ms, u32 fuzzt_us, struct torture_random_state
123124
fuzzt_ns = (u32)~0U;
124125
else
125126
fuzzt_ns = fuzzt_us * NSEC_PER_USEC;
126-
return torture_hrtimeout_ns(baset_ns, fuzzt_ns, trsp);
127+
return torture_hrtimeout_ns(baset_ns, fuzzt_ns, HRTIMER_MODE_REL, trsp);
127128
}
128129
EXPORT_SYMBOL_GPL(torture_hrtimeout_ms);
129130

@@ -136,7 +137,7 @@ int torture_hrtimeout_jiffies(u32 baset_j, struct torture_random_state *trsp)
136137
{
137138
ktime_t baset_ns = jiffies_to_nsecs(baset_j);
138139

139-
return torture_hrtimeout_ns(baset_ns, jiffies_to_nsecs(1), trsp);
140+
return torture_hrtimeout_ns(baset_ns, jiffies_to_nsecs(1), HRTIMER_MODE_REL, trsp);
140141
}
141142
EXPORT_SYMBOL_GPL(torture_hrtimeout_jiffies);
142143

@@ -153,7 +154,7 @@ int torture_hrtimeout_s(u32 baset_s, u32 fuzzt_ms, struct torture_random_state *
153154
fuzzt_ns = (u32)~0U;
154155
else
155156
fuzzt_ns = fuzzt_ms * NSEC_PER_MSEC;
156-
return torture_hrtimeout_ns(baset_ns, fuzzt_ns, trsp);
157+
return torture_hrtimeout_ns(baset_ns, fuzzt_ns, HRTIMER_MODE_REL, trsp);
157158
}
158159
EXPORT_SYMBOL_GPL(torture_hrtimeout_s);
159160

0 commit comments

Comments
 (0)