From 7ebd22edaa4b74b611768706ce9465163c01d112 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Tue, 28 Apr 2020 07:10:57 -0700 Subject: [PATCH] TIMER: Fix sim_idle_ms_sleep() return value to be more precise delta time computation converting the difference between two timespec structures values to milliseconds previously truncated the difference which, depending on the value of when the starting value in the delta happened, along with when an OS clock tick occurred, may have resulted in a small delta and an apparent sleep time of 0. A more accurate result is produced when the conversion from nanoseconds to milliseconds is rounded up before the usecs/nsecs are truncated. --- sim_timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sim_timer.c b/sim_timer.c index 3fe6d119..7754d3f0 100644 --- a/sim_timer.c +++ b/sim_timer.c @@ -312,7 +312,7 @@ if (!timedout) { AIO_UPDATE_QUEUE; } sim_timespec_diff (&delta_time, &done_time, &start_time); -delta_ms = (uint32)((delta_time.tv_sec * 1000) + (delta_time.tv_nsec / 1000000)); +delta_ms = (uint32)((delta_time.tv_sec * 1000) + ((delta_time.tv_nsec + 500000) / 1000000)); return delta_ms; } #else