* hires.h (hires_ms::initime_ms): Delete.
(hires_ms::initime_us): Just define as LONGLONG. (hires_ms::uptime): New function. * select.cc (select_stuff::wait): Use gtod for timing to attempt to avoid windows 32 bit wraparound. * times.cc (systime): New function. (times): Replace GetTickCount with gtod.uptime. (hires_us::prime): Use systime() to calculate system time rather than calling GetSystemTimeAsFileTime directly. (hires_ms::prime): Ditto. Eliminate initime_ms. (hires_ms::usecs): Try harder to detect wraparound. * fhandler_proc.cc (format_proc_partitions): Set drive_size to zero to avoid a compiler warning.
This commit is contained in:
parent
c09178b052
commit
6c9a5ebbfc
|
@ -1,3 +1,20 @@
|
||||||
|
2005-12-07 Christopher Faylor <cgf@timesys.com>
|
||||||
|
|
||||||
|
* hires.h (hires_ms::initime_ms): Delete.
|
||||||
|
(hires_ms::initime_us): Just define as LONGLONG.
|
||||||
|
(hires_ms::uptime): New function.
|
||||||
|
* select.cc (select_stuff::wait): Use gtod for timing to attempt to
|
||||||
|
avoid windows 32 bit wraparound.
|
||||||
|
* times.cc (systime): New function.
|
||||||
|
(times): Replace GetTickCount with gtod.uptime.
|
||||||
|
(hires_us::prime): Use systime() to calculate system time rather than
|
||||||
|
calling GetSystemTimeAsFileTime directly.
|
||||||
|
(hires_ms::prime): Ditto. Eliminate initime_ms.
|
||||||
|
(hires_ms::usecs): Try harder to detect wraparound.
|
||||||
|
|
||||||
|
* fhandler_proc.cc (format_proc_partitions): Set drive_size to zero to
|
||||||
|
avoid a compiler warning.
|
||||||
|
|
||||||
2005-12-07 Corinna Vinschen <corinna@vinschen.de>
|
2005-12-07 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* fhandler_proc.cc (format_proc_partitions): Use modern IOCTLs
|
* fhandler_proc.cc (format_proc_partitions): Use modern IOCTLs
|
||||||
|
|
|
@ -997,6 +997,8 @@ format_proc_partitions (char *destbuf, size_t maxsize)
|
||||||
* dg->SectorsPerTrack
|
* dg->SectorsPerTrack
|
||||||
* dg->BytesPerSector;
|
* dg->BytesPerSector;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
drive_size = 0;
|
||||||
if (!pi && !pix && !dg)
|
if (!pi && !pix && !dg)
|
||||||
debug_printf ("DeviceIoControl %E");
|
debug_printf ("DeviceIoControl %E");
|
||||||
else
|
else
|
||||||
|
|
|
@ -39,13 +39,14 @@ class hires_us : hires_base
|
||||||
|
|
||||||
class hires_ms : hires_base
|
class hires_ms : hires_base
|
||||||
{
|
{
|
||||||
DWORD initime_ms;
|
LONGLONG initime_us;
|
||||||
LARGE_INTEGER initime_us;
|
|
||||||
void prime ();
|
void prime ();
|
||||||
public:
|
public:
|
||||||
LONGLONG usecs ();
|
LONGLONG usecs ();
|
||||||
|
LONGLONG msecs () {return usecs () / 1000LL;}
|
||||||
UINT dmsecs () { return timeGetTime (); }
|
UINT dmsecs () { return timeGetTime (); }
|
||||||
UINT resolution ();
|
UINT resolution ();
|
||||||
|
LONGLONG uptime () {return (usecs () - initime_us) / 1000LL;}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern hires_ms gtod;
|
extern hires_ms gtod;
|
||||||
|
|
|
@ -276,7 +276,7 @@ select_stuff::wait (fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD start_time = GetTickCount (); /* Record the current time for later use. */
|
LONGLONG start_time = gtod.msecs (); /* Record the current time for later use. */
|
||||||
|
|
||||||
debug_printf ("m %d, ms %u", m, ms);
|
debug_printf ("m %d, ms %u", m, ms);
|
||||||
for (;;)
|
for (;;)
|
||||||
|
@ -330,7 +330,7 @@ select_stuff::wait (fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
|
||||||
}
|
}
|
||||||
select_printf ("recalculating ms");
|
select_printf ("recalculating ms");
|
||||||
|
|
||||||
DWORD now = GetTickCount ();
|
LONGLONG now = gtod.msecs ();
|
||||||
if (now > (start_time + ms))
|
if (now > (start_time + ms))
|
||||||
{
|
{
|
||||||
select_printf ("timed out after verification");
|
select_printf ("timed out after verification");
|
||||||
|
|
|
@ -32,9 +32,22 @@ details. */
|
||||||
#define FACTOR (0x19db1ded53e8000LL)
|
#define FACTOR (0x19db1ded53e8000LL)
|
||||||
#define NSPERSEC 10000000LL
|
#define NSPERSEC 10000000LL
|
||||||
|
|
||||||
|
static inline LONGLONG
|
||||||
|
systime ()
|
||||||
|
{
|
||||||
|
LARGE_INTEGER x;
|
||||||
|
FILETIME ft;
|
||||||
|
GetSystemTimeAsFileTime (&ft);
|
||||||
|
x.HighPart = ft.dwHighDateTime;
|
||||||
|
x.LowPart = ft.dwLowDateTime;
|
||||||
|
x.QuadPart -= FACTOR; /* Add conversion factor for UNIX vs. Windows base time */
|
||||||
|
x.QuadPart /= 10; /* Convert to milliseconds */
|
||||||
|
return x.QuadPart;
|
||||||
|
}
|
||||||
|
|
||||||
/* Cygwin internal */
|
/* Cygwin internal */
|
||||||
static unsigned long long __stdcall
|
static unsigned long long __stdcall
|
||||||
__to_clock_t (FILETIME * src, int flag)
|
__to_clock_t (FILETIME *src, int flag)
|
||||||
{
|
{
|
||||||
unsigned long long total = ((unsigned long long) src->dwHighDateTime << 32) + ((unsigned)src->dwLowDateTime);
|
unsigned long long total = ((unsigned long long) src->dwHighDateTime << 32) + ((unsigned)src->dwLowDateTime);
|
||||||
syscall_printf ("dwHighDateTime %u, dwLowDateTime %u", src->dwHighDateTime, src->dwLowDateTime);
|
syscall_printf ("dwHighDateTime %u, dwLowDateTime %u", src->dwHighDateTime, src->dwLowDateTime);
|
||||||
|
@ -44,7 +57,7 @@ __to_clock_t (FILETIME * src, int flag)
|
||||||
total -= FACTOR;
|
total -= FACTOR;
|
||||||
|
|
||||||
total /= (unsigned long long) (NSPERSEC / CLOCKS_PER_SEC);
|
total /= (unsigned long long) (NSPERSEC / CLOCKS_PER_SEC);
|
||||||
syscall_printf ("total %08x %08x", (unsigned)(total>>32), (unsigned)(total));
|
syscall_printf ("total %08x %08x", (unsigned) (total>>32), (unsigned) (total));
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,10 +71,10 @@ times (struct tms *buf)
|
||||||
if (efault.faulted (EFAULT))
|
if (efault.faulted (EFAULT))
|
||||||
return ((clock_t) -1);
|
return ((clock_t) -1);
|
||||||
|
|
||||||
DWORD ticks = GetTickCount ();
|
LONGLONG ticks = gtod.uptime ();
|
||||||
/* Ticks is in milliseconds, convert to our ticks. Use long long to prevent
|
/* Ticks is in milliseconds, convert to our ticks. Use long long to prevent
|
||||||
overflow. */
|
overflow. */
|
||||||
clock_t tc = (clock_t) ((long long) ticks * CLOCKS_PER_SEC / 1000);
|
clock_t tc = (clock_t) (ticks * CLOCKS_PER_SEC / 1000);
|
||||||
if (wincap.has_get_process_times ())
|
if (wincap.has_get_process_times ())
|
||||||
{
|
{
|
||||||
GetProcessTimes (hMainProc, &creation_time, &exit_time,
|
GetProcessTimes (hMainProc, &creation_time, &exit_time,
|
||||||
|
@ -569,7 +582,6 @@ hires_us::prime ()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILETIME f;
|
|
||||||
int priority = GetThreadPriority (GetCurrentThread ());
|
int priority = GetThreadPriority (GetCurrentThread ());
|
||||||
|
|
||||||
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL);
|
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL);
|
||||||
|
@ -580,15 +592,10 @@ hires_us::prime ()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetSystemTimeAsFileTime (&f);
|
primed_ft.QuadPart = systime ();
|
||||||
SetThreadPriority (GetCurrentThread (), priority);
|
|
||||||
|
|
||||||
inited = 1;
|
|
||||||
primed_ft.HighPart = f.dwHighDateTime;
|
|
||||||
primed_ft.LowPart = f.dwLowDateTime;
|
|
||||||
primed_ft.QuadPart -= FACTOR;
|
|
||||||
primed_ft.QuadPart /= 10;
|
|
||||||
freq = (double) ((double) 1000000. / (double) ifreq.QuadPart);
|
freq = (double) ((double) 1000000. / (double) ifreq.QuadPart);
|
||||||
|
inited = true;
|
||||||
|
SetThreadPriority (GetCurrentThread (), priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
LONGLONG
|
LONGLONG
|
||||||
|
@ -620,18 +627,11 @@ hires_ms::prime ()
|
||||||
{
|
{
|
||||||
if (!inited)
|
if (!inited)
|
||||||
{
|
{
|
||||||
FILETIME f;
|
|
||||||
int priority = GetThreadPriority (GetCurrentThread ());
|
int priority = GetThreadPriority (GetCurrentThread ());
|
||||||
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL);
|
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL);
|
||||||
initime_ms = timeGetTime ();
|
initime_us = systime () - (((LONGLONG) timeGetTime ()) * 1000LL);
|
||||||
GetSystemTimeAsFileTime (&f);
|
inited = true;
|
||||||
SetThreadPriority (GetCurrentThread (), priority);
|
SetThreadPriority (GetCurrentThread (), priority);
|
||||||
|
|
||||||
initime_us.HighPart = f.dwHighDateTime;
|
|
||||||
initime_us.LowPart = f.dwLowDateTime;
|
|
||||||
initime_us.QuadPart -= FACTOR;
|
|
||||||
initime_us.QuadPart /= 10;
|
|
||||||
inited = 1;
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -642,15 +642,13 @@ hires_ms::usecs ()
|
||||||
if (!inited)
|
if (!inited)
|
||||||
prime ();
|
prime ();
|
||||||
|
|
||||||
DWORD now = timeGetTime ();
|
LONGLONG res = initime_us + (((LONGLONG) timeGetTime ()) * 1000LL);
|
||||||
if ((int) (now - initime_ms) < 0)
|
if (res <= systime ())
|
||||||
{
|
{
|
||||||
inited = 0;
|
inited = false;
|
||||||
prime ();
|
prime ();
|
||||||
now = timeGetTime ();
|
res = initime_us + (((LONGLONG) timeGetTime ()) * 1000LL);
|
||||||
}
|
}
|
||||||
// FIXME: Not sure how this will handle the 49.71 day wrap around
|
|
||||||
LONGLONG res = initime_us.QuadPart + ((LONGLONG) (now - initime_ms) * 1000);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue