diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2005-12-12 12:18:14 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2005-12-12 12:18:14 +0000 |
commit | e96abae130e53d118bd7491f98ebd6d56b0b1c85 (patch) | |
tree | e9f737604d800070ef4bad1b7341fc10b2d53409 | |
parent | 74ecef0dea580af825e4905c07c417b667bf510f (diff) | |
download | newlib-e96abae130e53d118bd7491f98ebd6d56b0b1c85.zip newlib-e96abae130e53d118bd7491f98ebd6d56b0b1c85.tar.gz newlib-e96abae130e53d118bd7491f98ebd6d56b0b1c85.tar.bz2 |
* fhandler_proc.cc (format_proc_uptime): Drop usage of GetSystemTimes.
Use NtQuerySystemInformation to evaluate uptime and idle_time from
all CPU's processor times. Fallback to GetTickCount.
-rw-r--r-- | winsup/cygwin/ChangeLog | 6 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_proc.cc | 43 |
2 files changed, 31 insertions, 18 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index af716dc..94ac571 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,11 @@ 2005-12-12 Corinna Vinschen <corinna@vinschen.de> + * fhandler_proc.cc (format_proc_uptime): Drop usage of GetSystemTimes. + Use NtQuerySystemInformation to evaluate uptime and idle_time from + all CPU's processor times. Fallback to GetTickCount. + +2005-12-12 Corinna Vinschen <corinna@vinschen.de> + * mmap.cc (gen_create_protect): Always generate WRITECOPY protection for private maps. (fixup_mmaps_after_fork): Fix calculation of WRITECOPY protection for diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc index 0ecfc0d..996444a 100644 --- a/winsup/cygwin/fhandler_proc.cc +++ b/winsup/cygwin/fhandler_proc.cc @@ -468,30 +468,37 @@ static _off64_t format_proc_uptime (char *destbuf, size_t maxsize) { unsigned long long uptime = 0ULL, idle_time = 0ULL; - SYSTEM_PROCESSOR_TIMES spt; - if (!GetSystemTimes ((FILETIME *) &spt.IdleTime, (FILETIME *) &spt.KernelTime, - (FILETIME *) &spt.UserTime) - && GetLastError () == ERROR_PROC_NOT_FOUND) + if (wincap.is_winnt ()) { - NTSTATUS ret = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) &spt, - sizeof spt, NULL); - if (!ret && GetLastError () == ERROR_PROC_NOT_FOUND) - { - uptime = GetTickCount () / 10; - goto out; - } - else if (ret != STATUS_SUCCESS) + NTSTATUS ret; + SYSTEM_BASIC_INFORMATION sbi; + + ret = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi, + sizeof sbi, NULL); + if (!NT_SUCCESS (ret)) { __seterrno_from_nt_status (ret); - debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret); - return 0; + debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret); + sbi.NumberProcessors = 1; } + + SYSTEM_PROCESSOR_TIMES spt[sbi.NumberProcessors]; + ret = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) spt, + sizeof spt[0] * sbi.NumberProcessors, + NULL); + if (NT_SUCCESS (ret)) + for (int i = 0; i < sbi.NumberProcessors; i++) + { + uptime += (spt[i].KernelTime.QuadPart + spt[i].UserTime.QuadPart) + / 100000ULL; + idle_time += spt[i].IdleTime.QuadPart / 100000ULL; + } + uptime /= sbi.NumberProcessors; + idle_time /= sbi.NumberProcessors; } - idle_time = spt.IdleTime.QuadPart / 100000ULL; - uptime = (spt.KernelTime.QuadPart + - spt.UserTime.QuadPart) / 100000ULL; -out: + if (!uptime) + uptime = GetTickCount () / 10; return __small_sprintf (destbuf, "%U.%02u %U.%02u\n", uptime / 100, long (uptime % 100), |