diff options
author | Frank Richter <frank.richter@dynardo.de> | 2017-08-15 15:46:35 +0200 |
---|---|---|
committer | Andres Gomez <agomez@igalia.com> | 2017-08-19 17:39:35 +0300 |
commit | baf8c7b1c4bccbda9e2f9fd09d3647cb0f7027e6 (patch) | |
tree | 8af26d82d8121750423033e38a0ca80cbded5c27 | |
parent | 313fc5331d525e2f597cbc7acf96cb66ee4784d5 (diff) |
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 <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
(cherry picked from commit 7fb7287ce72066db7dffd918226bf15c3131a871)
-rw-r--r-- | src/gallium/auxiliary/os/os_time.c | 9 |
1 files changed, 8 insertions, 1 deletions
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 |