From: Frank Richter Date: Tue, 15 Aug 2017 13:46:35 +0000 (+0200) Subject: gallium/os: fix os_time_get_nano() to roll over less X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7fb7287ce72066db7dffd918226bf15c3131a871;p=mesa.git gallium/os: fix os_time_get_nano() to roll over less Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102241 Cc: mesa-stable@lists.freedesktop.org Reviewed-by: Brian Paul Reviewed-by: Jose Fonseca --- diff --git a/src/gallium/auxiliary/os/os_time.c b/src/gallium/auxiliary/os/os_time.c index e169139034c..e4a1cae641a 100644 --- a/src/gallium/auxiliary/os/os_time.c +++ b/src/gallium/auxiliary/os/os_time.c @@ -69,10 +69,17 @@ os_time_get_nano(void) static LARGE_INTEGER frequency; LARGE_INTEGER counter; + int64_t secs, nanosecs; if(!frequency.QuadPart) QueryPerformanceFrequency(&frequency); QueryPerformanceCounter(&counter); - return counter.QuadPart*INT64_C(1000000000)/frequency.QuadPart; + /* Compute seconds and nanoseconds parts separately to + * reduce severity of precision loss. + */ + secs = counter.QuadPart / frequency.QuadPart; + nanosecs = (counter.QuadPart % frequency.QuadPart) * INT64_C(1000000000) + / frequency.QuadPart; + return secs*INT64_C(1000000000) + nanosecs; #else