gallium/os: fix os_time_get_nano() to roll over less
authorFrank Richter <frank.richter@dynardo.de>
Tue, 15 Aug 2017 13:46:35 +0000 (15:46 +0200)
committerBrian Paul <brianp@vmware.com>
Thu, 17 Aug 2017 00:32:47 +0000 (18:32 -0600)
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102241
Cc: mesa-stable@lists.freedesktop.org
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/os/os_time.c

index e169139034ce7cfa80806a3e9eef93419d1b60df..e4a1cae641ae834a54dd9a43f12ee1a79af7999f 100644 (file)
@@ -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