From c8bef4002688ea8a5d919c312f25c899f5552625 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Sat, 31 Aug 2002 16:37:51 +0000 Subject: [PATCH] * fhandler_proc.cc: Add include. (format_proc_uptime): Use KernelTime and UserTime only as they include the other counters. (format_proc_stat): KernelTime includes IdleTime, so subtract IdleTime from KernelTime. Make number of 'jiffies' per second same as HZ define. * fhandler_process.cc: Add include. (format_process_stat): Make number of 'jiffies' per second same as HZ define. Use KernelTime and UserTime only to calculate start_time. --- winsup/cygwin/ChangeLog | 11 +++++++++++ winsup/cygwin/fhandler_proc.cc | 12 ++++++------ winsup/cygwin/fhandler_process.cc | 17 +++++++---------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 4d27a2db5..c6de5d72b 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,14 @@ +2002-08-31 Christopher January + + * fhandler_proc.cc: Add include. + (format_proc_uptime): Use KernelTime and UserTime only as they include + the other counters. + (format_proc_stat): KernelTime includes IdleTime, so subtract IdleTime + from KernelTime. Make number of 'jiffies' per second same as HZ define. + * fhandler_process.cc: Add include. + (format_process_stat): Make number of 'jiffies' per second same as + HZ define. Use KernelTime and UserTime only to calculate start_time. + 2002-08-30 Christopher Faylor (inspired by a patch from Egor Duda) diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc index 97b8a1751..417b59a25 100644 --- a/winsup/cygwin/fhandler_proc.cc +++ b/winsup/cygwin/fhandler_proc.cc @@ -23,6 +23,7 @@ details. */ #include "cygheap.h" #include #include +#include #include "ntdll.h" #define _COMPILING_NEWLIB @@ -423,9 +424,8 @@ format_proc_uptime (char *destbuf, size_t maxsize) else { idle_time = spt.IdleTime.QuadPart / 100000ULL; - uptime = (spt.InterruptTime.QuadPart + spt.KernelTime.QuadPart + - spt.IdleTime.QuadPart + spt.UserTime.QuadPart + - spt.DpcTime.QuadPart) / 100000ULL; + uptime = (spt.KernelTime.QuadPart + + spt.UserTime.QuadPart) / 100000ULL; } return __small_sprintf (destbuf, "%U.%02u %U.%02u\n", @@ -467,9 +467,9 @@ format_proc_stat (char *destbuf, size_t maxsize) ret, RtlNtStatusToDosError (ret)); return 0; } - kernel_time = (spt.KernelTime.QuadPart + spt.InterruptTime.QuadPart + spt.DpcTime.QuadPart) / 100000ULL; - user_time = spt.UserTime.QuadPart / 100000ULL; - idle_time = spt.IdleTime.QuadPart / 100000ULL; + kernel_time = (spt.KernelTime.QuadPart - spt.IdleTime.QuadPart) * HZ / 10000000ULL; + user_time = spt.UserTime.QuadPart * HZ / 10000000ULL; + idle_time = spt.IdleTime.QuadPart * HZ / 10000000ULL; interrupt_count = spt.InterruptCount; pages_in = spi.PagesRead; pages_out = spi.PagefilePagesWritten + spi.MappedFilePagesWritten; diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc index dc885820a..6f59b2abd 100644 --- a/winsup/cygwin/fhandler_process.cc +++ b/winsup/cygwin/fhandler_process.cc @@ -23,6 +23,7 @@ details. */ #include "dtable.h" #include "cygheap.h" #include "ntdll.h" +#include #include #define _COMPILING_NEWLIB @@ -454,22 +455,18 @@ format_process_stat (_pinfo *p, char *destbuf, size_t maxsize) return 0; } fault_count = vmc.PageFaultCount; - utime = put.UserTime.QuadPart / 100000ULL; - stime = put.KernelTime.QuadPart / 100000ULL; + utime = put.UserTime.QuadPart * HZ / 10000000ULL; + stime = put.KernelTime.QuadPart * HZ / 10000000ULL; if (stodi.CurrentTime.QuadPart > put.CreateTime.QuadPart) - start_time = (spt.InterruptTime.QuadPart + spt.KernelTime.QuadPart + - spt.IdleTime.QuadPart + spt.UserTime.QuadPart + - spt.DpcTime.QuadPart - stodi.CurrentTime.QuadPart + - put.CreateTime.QuadPart) / 100000ULL; + start_time = (spt.KernelTime.QuadPart + spt.UserTime.QuadPart - + stodi.CurrentTime.QuadPart + put.CreateTime.QuadPart) * HZ / 10000000ULL; else /* * sometimes stodi.CurrentTime is a bit behind * Note: some older versions of procps are broken and can't cope * with process start times > time(NULL). */ - start_time = (spt.InterruptTime.QuadPart + spt.KernelTime.QuadPart + - spt.IdleTime.QuadPart + spt.UserTime.QuadPart + - spt.DpcTime.QuadPart) / 100000ULL; + start_time = (spt.KernelTime.QuadPart + spt.UserTime.QuadPart) * HZ / 10000000ULL; priority = pbi.BasePriority; unsigned page_size = getpagesize(); vmsize = vmc.VirtualSize; @@ -478,7 +475,7 @@ format_process_stat (_pinfo *p, char *destbuf, size_t maxsize) } else { - start_time = (GetTickCount() / 1000 - time(NULL) + p->start_time) * 100; + start_time = (GetTickCount() / 1000 - time(NULL) + p->start_time) * HZ; } return __small_sprintf (destbuf, "%d (%s) %c " "%d %d %d %d %d "