Skip to content

Commit 03f246f

Browse files
metan-ucwwangli5665
authored andcommitted
syscalls/timer_settime03: Scale interval with clock precision
What the test does is to: - set initial expiration in the past - set very small interval value - expect the timer to overrun immediatelly many times to trigger timer overrun counter overflow However the test has harcoded expectation that the kernel timers have 1ns resolution. And while that is true for many modern hardware high resolution timers are generally not always present. The test tried to cope with that by adding kernel requirement for CONFIG_HIGH_RES_TIMERS=y however that does not necessarily mean that the high resolution hardware is present or that the drivers are loaded. This only means that the support has been compiled in the kernel. So instead of disabling the test when kernel timers have lower precision we scale the timer interval so that the inverval length divided by the timer precision is constant i.e. handler_delay. Fixes #925 Signed-off-by: Cyril Hrubis <[email protected]> Reviewed-by: Li Wang <[email protected]> Reviewed-by: Petr Vorel <[email protected]>
1 parent a7362af commit 03f246f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

testcases/kernel/syscalls/timer_settime/timer_settime03.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
static timer_t timer;
3333
static volatile int handler_called, overrun, saved_errno;
3434

35+
static struct timespec realtime_resolution;
36+
3537
static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
3638
{
3739
struct itimerspec spec;
@@ -61,6 +63,11 @@ static void setup(void)
6163

6264
SAFE_SIGNAL(SIGUSR1, sighandler);
6365
SAFE_TIMER_CREATE(CLOCK_REALTIME, &sev, &timer);
66+
67+
SAFE_CLOCK_GETRES(CLOCK_REALTIME, &realtime_resolution);
68+
69+
tst_res(TINFO, "CLOCK_REALTIME resolution %lins",
70+
(long)realtime_resolution.tv_nsec);
6471
}
6572

6673
static void run(void)
@@ -81,9 +88,9 @@ static void run(void)
8188

8289
/* spec.it_value = now - 1.4 * max overrun value */
8390
/* IOW, overflow will land right in the middle of negative range */
84-
spec.it_value.tv_sec -= handler_delay / 100000000;
91+
spec.it_value.tv_sec -= (handler_delay / 100000000) * realtime_resolution.tv_nsec;
8592
spec.it_value.tv_nsec -= nsec;
86-
spec.it_interval.tv_nsec = 1;
93+
spec.it_interval.tv_nsec = realtime_resolution.tv_nsec;
8794

8895
SAFE_TIMER_SETTIME(timer, TIMER_ABSTIME, &spec, NULL);
8996
while (!handler_called);
@@ -115,10 +122,6 @@ static struct tst_test test = {
115122
.test_all = run,
116123
.setup = setup,
117124
.cleanup = cleanup,
118-
.needs_kconfigs = (const char *[]) {
119-
"CONFIG_HIGH_RES_TIMERS=y",
120-
NULL
121-
},
122125
.tags = (const struct tst_tag[]) {
123126
{"linux-git", "78c9c4dfbf8c"},
124127
{"CVE", "2018-12896"},

0 commit comments

Comments
 (0)