Bug #64633 [Com]: microtime regression - resolution reduced to 64 ticks per second

From: Date: Wed, 08 Jan 2014 14:13:21 +0000
Subject: Bug #64633 [Com]: microtime regression - resolution reduced to 64 ticks per second
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183645@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64633&edit=1

 ID:                 64633
 Comment by:         louis at stovesonline dot co dot uk
 Reported by:        phpbugs at musiclogistics dot net
 Summary:            microtime regression - resolution reduced to 64
                     ticks per second
 Status:             Assigned
 Type:               Bug
 Package:            Date/time related
 Operating System:   Windows 7
 PHP Version:        5.4.14
 Assigned To:        pajoye
 Block user comment: N
 Private report:     N

 New Comment:

Having the same issue with 5.5.7 on Windows Server 2008 R2.

Interestingly starting Google Chrome on the server increases the tick rate for a few seconds,
meaning I can briefly get accurate results from my timing functions!


Previous Comments:
------------------------------------------------------------------------
[2013-08-01 06:53:57] yohgaki@php.net

Anyone could verify that this wouldn't happen with Windows 8/Windows Server 2012?
It seems different API is used for these platforms.

------------------------------------------------------------------------
[2013-08-01 06:07:53] yohgaki@php.net

I guess this commit is the cause.

git show  b022e54bd100a914417e216
commit b022e54bd100a914417e216d0872d3e67edecaf9
Author: Anatol Belski <ab@php.net>
Date:   Sat Mar 23 17:40:06 2013 +0100

    Fixed possible precision loss in microtime
    
    This is related to the fix for bug #64370. MSVC natively supports __int64 
type,
    so calculating with 32 bit ints is neither necessary nor reliable. Therefore
    an older piece of code is reused.

diff --git a/win32/time.c b/win32/time.c
index 77e4504..7553974 100644
--- a/win32/time.c
+++ b/win32/time.c
@@ -50,6 +50,7 @@ int getfilesystemtime(struct timeval *tv)
        FILETIME ft;
        unsigned __int64 ff = 0;
        MyGetSystemTimeAsFileTime timefunc;
+       ULARGE_INTEGER fft;
 
        timefunc = get_time_func();
        if (timefunc) {
@@ -58,14 +59,20 @@ int getfilesystemtime(struct timeval *tv)
                GetSystemTimeAsFileTime(&ft);
        }
 
-       ff |= ft.dwHighDateTime;
-       ff <<= 32;
-       ff |= ft.dwLowDateTime;
-       ff /= 10; /* convert to microseconds */
+        /*
+        * Do not cast a pointer to a FILETIME structure to either a 
+        * ULARGE_INTEGER* or __int64* value because it can cause alignment 
faults on 64-bit Windows.
+        * via  http://technet.microsoft.com/en-
us/library/ms724284(v=vs.85).aspx
+        */
+       fft.HighPart = ft.dwHighDateTime;
+       fft.LowPart = ft.dwLowDateTime;
+       ff = fft.QuadPart;
+
+       ff /= 10Ui64; /* convert to microseconds */
        ff -= 11644473600000000Ui64; /* convert to unix epoch */
 
-       tv->tv_sec = (long)(ff / 1000000UL);
-       tv->tv_usec = (long)(ff % 1000000UL);
+       tv->tv_sec = (long)(ff / 1000000Ui64);
+       tv->tv_usec = (long)(ff % 1000000Ui64);
 
        return 0;
 }

------------------------------------------------------------------------
[2013-08-01 05:43:03] yohgaki@php.net

Just a note.
Linux does not have problem at all, it seems.

http://3v4l.org/nMBha

------------------------------------------------------------------------
[2013-08-01 05:04:57] yaro2000 at yandex dot ru

5.4.09 - OK, 5.4.10 - OK ... 5.4.14 - BUG, 5.4.15 - BUG
Why?

------------------------------------------------------------------------
[2013-07-31 07:19:11] martin dot hason at gmail dot com

The same problem occurs in PHP 5.5.1 too! Please fix this bug.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=64633


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64633&edit=1


Thread (15 messages)

« previous php.bugs (#183645) next »