pgsql: Use GetSystemTimeAsFileTime directly in win32

From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Use GetSystemTimeAsFileTime directly in win32
Date: 2014-12-08 14:35:00
Message-ID: E1XxzOu-0006EX-HX@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Use GetSystemTimeAsFileTime directly in win32

PostgreSQL was calling GetSystemTime followed by SystemTimeToFileTime in the
win32 port gettimeofday function. This is not necessary and limits the reported
precision to the 1ms granularity that the SYSTEMTIME struct can represent. By
using GetSystemTimeAsFileTime we avoid unnecessary conversions and capture
timestamps at 100ns granularity, which is then rounded to 1µs granularity for
storage in a PostgreSQL timestamp.

On most Windows systems this change will actually have no significant effect on
timestamp resolution as the system timer tick is typically between 1ms and 15ms
depending on what timer resolution currently running applications have
requested. You can check this with clockres.exe from sysinternals. Despite the
platform limiation this change still permits capture of finer timestamps where
the system is capable of producing them and it gets rid of an unnecessary
syscall.

The higher resolution GetSystemTimePreciseAsFileTime call available on Windows
8 and Windows Server 2012 has the same interface as GetSystemTimeAsFileTime, so
switching to GetSystemTimeAsFileTime makes it easier to use the Precise variant
later.

Craig Ringer, reviewed by David Rowley

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/519b0757a37254452e013ea0ac95f4e56391608c

Modified Files
--------------
src/port/gettimeofday.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Simon Riggs 2014-12-08 14:40:16 pgsql: Windows: use GetSystemTimePreciseAsFileTime if available
Previous Message Peter Eisentraut 2014-12-08 07:29:17 pgsql: doc: Fix DocBook table column count declaration