Cygwin: Drop HZ usage in favor of MSPERSEC and CLOCKS_PER_SEC

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2018-02-12 22:08:42 +01:00
parent 58f72783ee
commit 01c643e49f
6 changed files with 25 additions and 19 deletions

View File

@ -535,9 +535,9 @@ format_proc_stat (void *, char *&destbuf)
for (unsigned long i = 0; i < wincap.cpu_count (); i++) for (unsigned long i = 0; i < wincap.cpu_count (); i++)
{ {
kernel_time += (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart) kernel_time += (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart)
* HZ / NS100PERSEC; * CLOCKS_PER_SEC / NS100PERSEC;
user_time += spt[i].UserTime.QuadPart * HZ / NS100PERSEC; user_time += spt[i].UserTime.QuadPart * CLOCKS_PER_SEC / NS100PERSEC;
idle_time += spt[i].IdleTime.QuadPart * HZ / NS100PERSEC; idle_time += spt[i].IdleTime.QuadPart * CLOCKS_PER_SEC / NS100PERSEC;
} }
eobuf += __small_sprintf (eobuf, "cpu %U %U %U %U\n", eobuf += __small_sprintf (eobuf, "cpu %U %U %U %U\n",
@ -546,9 +546,10 @@ format_proc_stat (void *, char *&destbuf)
for (unsigned long i = 0; i < wincap.cpu_count (); i++) for (unsigned long i = 0; i < wincap.cpu_count (); i++)
{ {
interrupt_count += spt[i].InterruptCount; interrupt_count += spt[i].InterruptCount;
kernel_time = (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart) * HZ / NS100PERSEC; kernel_time = (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart)
user_time = spt[i].UserTime.QuadPart * HZ / NS100PERSEC; * CLOCKS_PER_SEC / NS100PERSEC;
idle_time = spt[i].IdleTime.QuadPart * HZ / NS100PERSEC; user_time = spt[i].UserTime.QuadPart * CLOCKS_PER_SEC / NS100PERSEC;
idle_time = spt[i].IdleTime.QuadPart * CLOCKS_PER_SEC / NS100PERSEC;
eobuf += __small_sprintf (eobuf, "cpu%d %U %U %U %U\n", i, eobuf += __small_sprintf (eobuf, "cpu%d %U %U %U %U\n", i,
user_time, 0ULL, kernel_time, idle_time); user_time, 0ULL, kernel_time, idle_time);
} }

View File

@ -1092,7 +1092,8 @@ format_process_stat (void *data, char *&destbuf)
state = 'T'; state = 'T';
else else
state = get_process_state (p->dwProcessId); state = get_process_state (p->dwProcessId);
start_time = (GetTickCount () / 1000 - time (NULL) + p->start_time) * HZ; start_time = (GetTickCount () / MSPERSEC - time (NULL) + p->start_time)
* CLOCKS_PER_SEC;
NTSTATUS status; NTSTATUS status;
HANDLE hProcess; HANDLE hProcess;
@ -1139,19 +1140,21 @@ format_process_stat (void *data, char *&destbuf)
return 0; return 0;
} }
fault_count = vmc.PageFaultCount; fault_count = vmc.PageFaultCount;
utime = put.UserTime.QuadPart * HZ / NS100PERSEC; utime = put.UserTime.QuadPart * CLOCKS_PER_SEC / NS100PERSEC;
stime = put.KernelTime.QuadPart * HZ / NS100PERSEC; stime = put.KernelTime.QuadPart * CLOCKS_PER_SEC / NS100PERSEC;
#if 0 #if 0
if (stodi.CurrentTime.QuadPart > put.CreateTime.QuadPart) if (stodi.CurrentTime.QuadPart > put.CreateTime.QuadPart)
start_time = (spt.KernelTime.QuadPart + spt.UserTime.QuadPart - start_time = (spt.KernelTime.QuadPart + spt.UserTime.QuadPart -
stodi.CurrentTime.QuadPart + put.CreateTime.QuadPart) * HZ / NS100PERSEC; stodi.CurrentTime.QuadPart + put.CreateTime.QuadPart)
* CLOCKS_PER_SEC / NS100PERSEC;
else else
/* /*
* sometimes stodi.CurrentTime is a bit behind * sometimes stodi.CurrentTime is a bit behind
* Note: some older versions of procps are broken and can't cope * Note: some older versions of procps are broken and can't cope
* with process start times > time(NULL). * with process start times > time(NULL).
*/ */
start_time = (spt.KernelTme.QuadPart + spt.UserTime.QuadPart) * HZ / NS100PERSEC; start_time = (spt.KernelTme.QuadPart + spt.UserTime.QuadPart)
* CLOCKS_PER_SEC / NS100PERSEC;
#endif #endif
/* The BasePriority returned to a 32 bit process under WOW64 is /* The BasePriority returned to a 32 bit process under WOW64 is
apparently broken, for 32 and 64 bit target processes. 64 bit apparently broken, for 32 and 64 bit target processes. 64 bit

View File

@ -1033,8 +1033,8 @@ cygwin_getsockopt (int fd, int level, int optname, void *optval,
} }
else else
{ {
time_out->tv_sec = ms / HZ; time_out->tv_sec = ms / MSPERSEC;
time_out->tv_usec = ((ms % HZ) * USPERSEC) / HZ; time_out->tv_usec = ((ms % MSPERSEC) * USPERSEC) / MSPERSEC;
} }
*optlen = (socklen_t) sizeof *time_out; *optlen = (socklen_t) sizeof *time_out;
res = 0; res = 0;

View File

@ -201,7 +201,7 @@ sched_rr_get_interval (pid_t pid, struct timespec *interval)
slindex -= 1; slindex -= 1;
nsec = quantable[vfindex][slindex][qindex] / quantapertick nsec = quantable[vfindex][slindex][qindex] / quantapertick
* clocktickinterval * (NSPERSEC / HZ); * clocktickinterval * (NSPERSEC / MSPERSEC);
interval->tv_sec = nsec / NSPERSEC; interval->tv_sec = nsec / NSPERSEC;
interval->tv_nsec = nsec % NSPERSEC; interval->tv_nsec = nsec % NSPERSEC;

View File

@ -132,7 +132,8 @@ timer_thread (VOID *x)
if (sleep_us > 0) if (sleep_us > 0)
{ {
tt->sleepto_us = sleepto_us; tt->sleepto_us = sleepto_us;
sleep_ms = (sleep_us + (USPERSEC/HZ) - 1) / (USPERSEC/HZ); sleep_ms = (sleep_us + (USPERSEC / MSPERSEC) - 1)
/ (USPERSEC / MSPERSEC);
} }
else else
{ {

View File

@ -117,7 +117,7 @@ settimeofday (const struct timeval *tv, const struct timezone *tz)
st.wHour = ptm->tm_hour; st.wHour = ptm->tm_hour;
st.wMinute = ptm->tm_min; st.wMinute = ptm->tm_min;
st.wSecond = ptm->tm_sec; st.wSecond = ptm->tm_sec;
st.wMilliseconds = tv->tv_usec / (USPERSEC/HZ); st.wMilliseconds = tv->tv_usec / (USPERSEC / MSPERSEC);
res = -!SetSystemTime (&st); res = -!SetSystemTime (&st);
gtod.reset (); gtod.reset ();
@ -223,11 +223,12 @@ timeval_to_ms (const struct timeval *time_in, DWORD &ms)
|| time_in->tv_usec >= USPERSEC) || time_in->tv_usec >= USPERSEC)
return false; return false;
if ((time_in->tv_sec == 0 && time_in->tv_usec == 0) if ((time_in->tv_sec == 0 && time_in->tv_usec == 0)
|| time_in->tv_sec >= (time_t) (INFINITE / HZ)) || time_in->tv_sec >= (time_t) (INFINITE / MSPERSEC))
ms = INFINITE; ms = INFINITE;
else else
ms = time_in->tv_sec * HZ + (time_in->tv_usec + (USPERSEC/HZ) - 1) ms = time_in->tv_sec * MSPERSEC
/ (USPERSEC/HZ); + (time_in->tv_usec + (USPERSEC / MSPERSEC) - 1)
/ (USPERSEC / MSPERSEC);
return true; return true;
} }