This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] POSIX monotonic clock


On Tue, 03 Aug 2010 09:32:47 +0200, VÃclav Haisman
wrote:
> On Mon, 02 Aug 2010 15:49:08 -0500, "Yaakov (Cygwin/X)" wrote:
>> Here is an attempt to implement POSIX.1-2004+ Monotonic Clock:
>> 
>>
>
http://www.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html
>> 
>> In summary, I took hires_us and changed the resolution to nanoseconds.
I
>> dropped systime() because the only place hires_us was being used is in
>> strace.cc which ignored it, and WRT POSIX monotonic clocks the absolute
>> value of the clock is meaningless.  Since systime() has only 100ns
>> precision, using it would either force a loss in resolution or (if
>> multiplied by 100 to get ns) an early overflow.  I also switched from
>> ENOSYS to EINVAL, as POSIX.1-2004 and 2008 dropped references to the
>> former (as noted in Change History).
>> 
>> Patches for newlib, winsup/cygwin and winsup/doc attached.
>> 
>> I have also attached an STC for the new functionality.  FWIW, on my
>> machine, QueryPerformanceFrequency() returns just over 2.9 million,
>> resulting in a clock_getres(CLOCK_MONOTONIC) of 340ns.
>> 
>> I would appreciate a careful review of this patch, both from the Cygwin
>> API and POSIX POVs.
> Is it really ok to use QueryPerformanceCounter() to implement this?
Quote
> from <http://msdn.microsoft.com/en-us/library/ms644904%28VS.85%29.aspx>:
> 
> "On a multiprocessor computer, it should not matter which processor is
> called. However, you can get different results on different processors
due
> to bugs in the basic input/output system (BIOS) or the hardware
abstraction
> layer (HAL). To specify processor affinity for a thread, use the
> SetThreadAffinityMask function."
> 
> This looks like you could get monotonic clock going backwards.
See also <http://www.virtualdub.org/blog/pivot/entry.php?id=106>.

-- 
VH


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]