Skip to content

Commit

Permalink
syscalls/timer_settime01: Avoid rounding from nsec to usec
Browse files Browse the repository at this point in the history
When using TIMER_ABSTIME, the value is added to the current clock time.
However, usecs is used instead of nsecs, leading to a possible rounding up from
tst_ts_to_us().

That rounding can lead to up to 500 nsecs of difference between the current
time and the absolute time used for setting the timer. When reading the timer
back, that same difference can be found, which leads to a test failure.

By adding the usecs to timespec structure then setting the timer from
the structure we avoid the rounding and end up with precise value
instead.

This can be easily reproducible by booting linux with clocksource=jiffies.

Fixes: b34e243 (syscalls/timer_settime01: Make sure the timer fires)
Reported-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Tested-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Tested-by: Alexander Egorenkov <egorenar@linux.ibm.com>
  • Loading branch information
metan-ucw committed Oct 27, 2020
1 parent a638361 commit cba1f26
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions testcases/kernel/syscalls/timer_settime/timer_settime01.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ static void run(unsigned int n)
get_clock_str(clock));
continue;
}
val += tst_ts_to_us(timenow);
tst_ts_add_us(timenow, val);
tst_its_set_value_from_ts(&new_set, timenow);
} else {
tst_its_set_value_from_us(&new_set, val);
}

tst_its_set_interval_from_us(&new_set, tc->it_interval_tv_usec);
tst_its_set_value_from_us(&new_set, val);

TEST(tv->timer_settime(timer, tc->flag, tst_its_get(&new_set), tst_its_get(tc->old_ptr)));

Expand Down

0 comments on commit cba1f26

Please sign in to comment.