Discussion:
[Mingw-w64-public] MinGW-w64 clock_gettime()
McLachlan, Donald (IC)
2017-06-14 19:33:16 UTC
Permalink
Hi,

I've recently followed https://stackoverflow.com/questions/30069830/how-to-install-mingw-w64-and-msys2 and installed MSYS2 and then installed gcc. This appears to be MinGW-w64. Is this correct?

I was hoping to use clock_gettime(CLOCK_REALTIME, &ts) for high resolution synchronized timestamps. But it appears the time reported is only updated every system tick (~15.6 ms). Is this correct?

If so, why isn't clock_gettime(CLOCK_REALTIME, &ts) just implemented as a wrapper around GetSystemTimePreciseAsFileTime() and adjusting the epoch to Jan 1 1970?

I've written a similar wrapper function and I found GetSystemTimePreciseAsFileTime() usually takes 11 ns per call and I usually see time "steps" of 300 or 400 ns (worst case was about 1 ms). N.B. This was with NTP running so the big step could be a time adjustment.

I've not checked the resolution of clock_gettime(CLOCK_MONOTONIC, ) for high resolution unsynchronized timestamps, but I guess that could be also easily be implemented as a wrapper (around QueryPerformanceCounter()).

Don
LRN
2017-06-14 22:31:47 UTC
Permalink
Post by McLachlan, Donald (IC)
Hi,
I was hoping to use clock_gettime(CLOCK_REALTIME, &ts) for high resolution synchronized timestamps. But it appears the time reported is only updated every system tick (~15.6 ms). Is this correct?
This is what git version of winpthreads does in clock_gettime (not sure which
version is the latest in msys2):

case CLOCK_REALTIME:
{
GetSystemTimeAsFileTime(&ct.ft);
t = ct.u64 - DELTA_EPOCH_IN_100NS;
tp->tv_sec = t / POW10_7;
tp->tv_nsec = ((int) (t % POW10_7)) * 100;

return 0;
}
--
O< ascii ribbon - stop html email! - www.asciiribbon.org
McLachlan, Donald (IC)
2017-06-15 14:30:12 UTC
Permalink
1) I'll try to check which version of winpthreads is installed by msys2. (rats, someone just "borrowed" the Surface Book Pro. Grrr.) :-)

2) that is almost identical to the wrapper I wrote, except I just used a FILETIME struct and copied low/high as per https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284(v=vs.85).aspx
I'm guessing ct is a union that resolves the alignment issue.


-----Original Message-----
From: LRN [mailto:***@gmail.com]
Sent: June-14-17 6:32 PM
To: mingw-w64-***@lists.sourceforge.net
Subject: Re: [Mingw-w64-public] MinGW-w64 clock_gettime()
Post by McLachlan, Donald (IC)
Hi,
I was hoping to use clock_gettime(CLOCK_REALTIME, &ts) for high resolution synchronized timestamps. But it appears the time reported is only updated every system tick (~15.6 ms). Is this correct?
This is what git version of winpthreads does in clock_gettime (not sure which version is the latest in msys2):

case CLOCK_REALTIME:
{
GetSystemTimeAsFileTime(&ct.ft);
t = ct.u64 - DELTA_EPOCH_IN_100NS;
tp->tv_sec = t / POW10_7;
tp->tv_nsec = ((int) (t % POW10_7)) * 100;

return 0;
}




--
O< ascii ribbon - stop html email! - www.asciiribbon.org

Loading...