GetSystemTimePreciseAsFileTime (was Re: [ANNOUNCEMENT] Updated: Cygwin 1.7.19)

Corinna Vinschen
Sun Jun 9 11:53:00 GMT 2013

On Jun  5 18:28, Corinna Vinschen wrote:
> On Jun  6 01:02, Shaddy Baddah wrote:
> > On 2013-06-05 19:39+1000, Corinna Vinschen wrote:
> > >- Drop support for Windows 2000 and Windows XP pre-SP3.
> > 
> > I find this change interesting. In no way am I complaining about this,
> > releases matching the above are well past end-of-life anyway.
> > 
> > But I am curious about the technical reason (and perhaps discussion)
> > that ruled Win 2K out.
> > [...]
> [...]
> There's also stuff we still not use a lot, foremost the Win32 API call
> CancelSynchronousIo which, if it had been introduced in NT4 already,
> would be probably heavily used by Cygwin (think signal handling).
> The next big thing developement-wise is not Windows 7, but Windows 8 (of
> all things!), because of the new GetSystemTimePreciseAsFileTime call,
> which I'm going to introduce into Cygwin pretty soon.

Or not.  I just tested the GetSystemTimePreciseAsFileTime call and it's
a wonderful performance killer.

Below I pasted my simple testcase.  It computes the average number of
CPU cycles per call to compare GetSystemTimeAsFileTime and
GetSystemTimePreciseAsFileTime with each other.

I tested the call on two 64 bit Windows 8 systems, one real machine,
one QEMU/KVM based virtual machine.  On real hardware I get:

On the virtual machine, the results are:

  Best case:

       8 cycles for GetSystemTimeAsFileTime
   15557 cycles for GetSystemTimePreciseAsFileTime

  Worst case under load:

      20 cycles for GetSystemTimeAsFileTime
   17443 cycles for GetSystemTimePreciseAsFileTime

On real hardware, the results are much better, but the difference between
GetSystemTimeAsFileTime and GetSystemTimePreciseAsFileTime are still

  Best case:

       9 cycles for GetSystemTimeAsFileTime
    2761 cycles for GetSystemTimePreciseAsFileTime

  Worst case under load:

      18 cycles for GetSystemTimeAsFileTime
    5874 cycles for GetSystemTimePreciseAsFileTime


#include <stdio.h>
#include <stdint.h>
#include <windows.h>

void (WINAPI *pGetSystemTimeAsFileTime) (LPFILETIME);
void (WINAPI *pGetSystemTimePreciseAsFileTime) (LPFILETIME);

static inline uint64_t
  uint32_t low, high;

  __asm __volatile("rdtsc" : "=a" (low), "=d" (high));
  return (low | ((uint64_t)high << 32));

static void
cycle (void (WINAPI *f) (LPFILETIME), const char *name)
  const int iter = 1000000;
  int i;
  uint64_t v;

  v = rdtsc ();
  for (i = 0; i < iter; i++)
    f (&l);
  v = rdtsc () - v;
  v /= iter;
  printf ("%6lld cycles for %s\n", v, name);

int main ()
  HMODULE h = GetModuleHandle ("kernel32.dll");
  pGetSystemTimeAsFileTime = (void (WINAPI *)(LPFILETIME))
  			GetProcAddress (h, "GetSystemTimeAsFileTime");
  pGetSystemTimePreciseAsFileTime = (void (WINAPI *)(LPFILETIME))
  			GetProcAddress (h, "GetSystemTimePreciseAsFileTime");
  if (!pGetSystemTimePreciseAsFileTime)
      fputs ("GetSystemTimePreciseAsFileTime unsupported\n", stderr);
      return 1;

  cycle (pGetSystemTimeAsFileTime, "GetSystemTimeAsFileTime");
  cycle (pGetSystemTimePreciseAsFileTime, "GetSystemTimePreciseAsFileTime");

  return 0;

Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Problem reports:
Unsubscribe info:

More information about the Cygwin mailing list