Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

win: uv_hrtime() return non-incremental value #850

Closed
witchu opened this Issue Jul 12, 2013 · 2 comments

Comments

Projects
None yet
3 participants

witchu commented Jul 12, 2013

on windows server (windows with high performance frequency) when call uv_hrtime() many times, return values will decrease sometimes.

to fix please apply:

1a39914af186f5db73ba8507d60da5d3bb3e39dc
 src/win/util.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/win/util.c b/src/win/util.c
index f19d30a..2deb39d 100644
--- a/src/win/util.c
+++ b/src/win/util.c
@@ -460,8 +460,8 @@ uint64_t uv_hrtime(void) {
   /* performance counter frequency, and there may not be much headroom to */
   /* multiply by NANOSEC without overflowing, we use 128-bit math instead. */
   return ((uint64_t) counter.LowPart * NANOSEC / hrtime_frequency_) +
-         (((uint64_t) counter.HighPart * NANOSEC / hrtime_frequency_)
-         << 32);
+         (((uint64_t) counter.HighPart * NANOSEC / hrtime_frequency_) << 32) +
+         (((uint64_t) counter.HighPart * NANOSEC % hrtime_frequency_) * 4294967296 / hrtime_frequency_);
 }

Contributor

bnoordhuis commented Oct 17, 2013

/cc @piscisaureus - this has been open for a while now.

Contributor

Keno commented Oct 21, 2013

Can we get this applied?

vtjnash added a commit to JuliaLang/libuv that referenced this issue Jan 1, 2014

windows/timer: fix uv_hrtime discontinuity
Large performance counter frequency values would cause overflows, even
when 64-bit integers were used to do the multiplication with NANOSEC.
Fix this by using floating point math instead.

Fixes #850
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment