Skip to content

Commit 35e2206

Browse files
committed
Update semu_timer_clocksource() to use mult_frac()
Enhance the semu_timer_clocksource() function by utilizing the mult_frac() function to improve the precision of converting time to clock ticks. This update refines the calculations for converting time derived from clock_gettime() and mach_absolute_time() into clock ticks. This ensures that the time-to-clock-ticks conversion is more reliable and precise, addressing potential precision issues effectively.
1 parent 83185ab commit 35e2206

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ static uint64_t semu_timer_clocksource(uint64_t freq)
4343
#if defined(HAVE_POSIX_TIMER)
4444
struct timespec t;
4545
clock_gettime(CLOCKID, &t);
46-
return (t.tv_sec * freq) + (t.tv_nsec * freq / 1e9);
46+
return t.tv_sec * freq + mult_frac(t.tv_nsec, freq, 1e9);
4747
#elif defined(HAVE_MACH_TIMER)
4848
static mach_timebase_info_data_t t;
4949
if (mach_clk.denom == 0)
5050
(void) mach_timebase_info(&t);
51-
return mach_absolute_time() * freq / t.denom * t.numer;
51+
return mult_frac(mach_absolute_time() * freq, t.numer, t.denom);
5252
#else
5353
return time(0) * freq;
5454
#endif

0 commit comments

Comments
 (0)