All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/timer_settime01: adjust for rounding from nsec to usec
@ 2020-10-06  8:53 Thadeu Lima de Souza Cascardo
  2020-10-13 14:03 ` Cyril Hrubis
  2020-10-26 14:04 ` [LTP] " Alexander Egorenkov
  0 siblings, 2 replies; 8+ messages in thread
From: Thadeu Lima de Souza Cascardo @ 2020-10-06  8:53 UTC (permalink / raw)
  To: ltp

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.

Accounting for that possible difference in the time allows the test to pass.

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

Fixes: b34e243e85dd (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>
---
 testcases/kernel/syscalls/timer_settime/timer_settime01.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/timer_settime/timer_settime01.c b/testcases/kernel/syscalls/timer_settime/timer_settime01.c
index 67143e8f88b2..7ecf0c18d1c4 100644
--- a/testcases/kernel/syscalls/timer_settime/timer_settime01.c
+++ b/testcases/kernel/syscalls/timer_settime/timer_settime01.c
@@ -149,10 +149,15 @@ static void run(unsigned int n)
 		if (TST_RET != 0) {
 			tst_res(TFAIL | TTERRNO, "timer_gettime(%s) failed",
 				get_clock_str(clock));
+		/*
+		 * With TIMER_ABSTIME, we add to the current clock after
+		 * rounding up by 500 ns to the value. Do the same here after
+		 * reading the timer back.
+		 */
 		} else if ((tst_its_get_interval_nsec(new_set) !=
 				tc->it_interval_tv_usec * 1000) ||
 			   (tst_its_get_value_nsec(new_set) >
-				MAX(tc->it_value_tv_usec * 1000, tc->it_interval_tv_usec * 1000))) {
+				MAX(tc->it_value_tv_usec * 1000 + 500, tc->it_interval_tv_usec * 1000))) {
 			tst_res(TFAIL | TTERRNO,
 				"timer_gettime(%s) reported bad values (%llu: %llu)",
 				get_clock_str(clock),
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-10-27 13:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-06  8:53 [LTP] [PATCH] syscalls/timer_settime01: adjust for rounding from nsec to usec Thadeu Lima de Souza Cascardo
2020-10-13 14:03 ` Cyril Hrubis
2020-10-20 12:23   ` Cyril Hrubis
2020-10-26 15:12     ` Thadeu Lima de Souza Cascardo
2020-10-27 13:39       ` Cyril Hrubis
2020-10-26 14:04 ` [LTP] " Alexander Egorenkov
2020-10-26 14:34   ` Cyril Hrubis
2020-10-26 15:07     ` Alexander Egorenkov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.