* hires.h (hires_ms::dmsecs): Drop unused method.

* times.cc (JITTER): Remove.
	(gtod): Revert to process-local variable.
	(hires_ms::nsecs): Just return system time to disallow discrepancy with
	the OS.
	(hires_ms::resolution): Return coarsest timer value from OS.  Add
	comment to explain why.
	(clock_setres): Ditto.
This commit is contained in:
Corinna Vinschen 2012-03-26 09:05:50 +00:00
parent cff00a2038
commit b54d64de05
3 changed files with 26 additions and 27 deletions

View File

@ -1,3 +1,14 @@
2012-03-26 Corinna Vinschen <corinna@vinschen.de>
* hires.h (hires_ms::dmsecs): Drop unused method.
* times.cc (JITTER): Remove.
(gtod): Revert to process-local variable.
(hires_ms::nsecs): Just return system time to disallow discrepancy with
the OS.
(hires_ms::resolution): Return coarsest timer value from OS. Add
comment to explain why.
(clock_setres): Ditto.
2012-03-21 Christopher Faylor <me.cygwin2012@cgf.cx>
* child_info.h: Reset magic number.

View File

@ -1,6 +1,6 @@
/* hires.h: Definitions for hires clock calculations
Copyright 2002, 2003, 2004, 2005, 2009, 2010, 2011 Red Hat, Inc.
Copyright 2002, 2003, 2004, 2005, 2009, 2010, 2011, 2012 Red Hat, Inc.
This file is part of Cygwin.
@ -62,7 +62,6 @@ class hires_ms : public hires_base
LONGLONG nsecs ();
LONGLONG usecs () {return nsecs () / 10LL;}
LONGLONG msecs () {return nsecs () / 10000LL;}
UINT dmsecs () { return timeGetTime_ns () / 10000LL; }
UINT resolution ();
LONGLONG uptime () {return (nsecs () - initime_ns) / 10000LL;}
};

View File

@ -1,7 +1,7 @@
/* times.cc
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006, 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Red Hat, Inc.
This file is part of Cygwin.
@ -27,17 +27,7 @@ details. */
#include "cygtls.h"
#include "ntdll.h"
/* Max allowed diversion in 100ns of internal timer from system time. If
this difference is exceeded, the internal timer gets re-primed. */
#define JITTER (40 * 10000LL)
/* TODO: Putting this variable in the shared cygwin region partially solves
the problem of cygwin processes not recognizing date changes when other
cygwin processes set the date. There is still an additional problem of
long-running cygwin processes becoming confused when a non-cygwin process
sets the date. Unfortunately, it looks like a minor redesign is required
to handle that case. */
hires_ms gtod __attribute__((section (".cygwin_dll_common"), shared));
hires_ms NO_COPY gtod;
hires_ns NO_COPY ntod;
@ -575,16 +565,7 @@ hires_ms::nsecs ()
{
if (!inited)
prime ();
LONGLONG t = systime_ns ();
LONGLONG res = initime_ns + timeGetTime_ns ();
if (llabs (res - t) > JITTER)
{
inited = false;
prime ();
res = initime_ns + timeGetTime_ns ();
}
return res;
return systime_ns ();
}
extern "C" int
@ -731,10 +712,15 @@ hires_ms::resolution ()
status = NtQueryTimerResolution (&coarsest, &finest, &actual);
if (NT_SUCCESS (status))
minperiod = (DWORD) actual;
/* The actual resolution of the OS timer is a system-wide setting which
can be changed any time, by any process. The only fixed value we
can rely on is the coarsest value. */
minperiod = coarsest;
else
{
/* Try to empirically determine current timer resolution */
/* There's no good reason that NtQueryTimerResolution should fail
at all, but let's play it safe. Try to empirically determine
current timer resolution */
int priority = GetThreadPriority (GetCurrentThread ());
SetThreadPriority (GetCurrentThread (),
THREAD_PRIORITY_TIME_CRITICAL);
@ -837,7 +823,10 @@ clock_setres (clockid_t clk_id, struct timespec *tp)
__seterrno_from_nt_status (status);
return -1;
}
minperiod = actual;
/* The actual resolution of the OS timer is a system-wide setting which
can be changed any time, by any process. The only fixed value we can
rely on is the coarsest value. */
minperiod = coarsest;
period_set = true;
return 0;
}