From c73a490a10f57d2800818d3d54c551d2235e1927 Mon Sep 17 00:00:00 2001 From: MBaesken Date: Fri, 3 Feb 2023 09:20:46 +0100 Subject: [PATCH 1/6] JDK-8301661 --- src/hotspot/os/bsd/os_bsd.cpp | 28 ++++++++++++++++++++- src/hotspot/os/windows/os_windows.cpp | 35 ++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/hotspot/os/bsd/os_bsd.cpp b/src/hotspot/os/bsd/os_bsd.cpp index ed4d183b53526..282ff63a432b6 100644 --- a/src/hotspot/os/bsd/os_bsd.cpp +++ b/src/hotspot/os/bsd/os_bsd.cpp @@ -1299,8 +1299,34 @@ void os::print_os_info(outputStream* st) { VM_Version::print_platform_virtualization_info(st); } +#ifdef __APPLE__ +static void print_sysctl_info_string(const char* sysctlkey, outputStream* st, char* buf, size_t size) { + if (sysctlbyname(sysctlkey, buf, &size, NULL, 0) >= 0) { + st->print_cr("%s:%s", sysctlkey, buf); + } +} + +static void print_sysctl_info_uint64(const char* sysctlkey, outputStream* st) { + uint64_t val; + size_t size=sizeof(uint64_t); + if (sysctlbyname(sysctlkey, &val, &size, NULL, 0) >= 0) { + st->print_cr("%s:%llu", sysctlkey, val); + } +} +#endif + void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) { - // Nothing to do for now. +#ifdef __APPLE__ + print_sysctl_info_string("machdep.cpu.brand_string", st, buf, buflen); + print_sysctl_info_uint64("hw.cpufrequency", st); + print_sysctl_info_uint64("hw.cpufrequency_min", st); + print_sysctl_info_uint64("hw.cpufrequency_max", st); + print_sysctl_info_uint64("hw.cachelinesize", st); + print_sysctl_info_uint64("hw.l1icachesize", st); + print_sysctl_info_uint64("hw.l1dcachesize", st); + print_sysctl_info_uint64("hw.l2cachesize", st); + print_sysctl_info_uint64("hw.l3cachesize", st); +#endif } void os::get_summary_cpu_info(char* buf, size_t buflen) { diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index 00148c043089c..eedd475f42110 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -91,6 +91,7 @@ #include #include +#include #include #include #include @@ -1876,8 +1877,40 @@ void os::win32::print_windows_version(outputStream* st) { st->cr(); } +// Processor Power Information; missing from Windows headers +typedef struct _PROCESSOR_POWER_INFORMATION { + ULONG Number; + ULONG MaxMhz; // max specified clock frequency of the system processor + ULONG CurrentMhz; // max specified processor clock frequency mult. by current processor throttle + ULONG MhzLimit; // max specified processor clock frequency mult. by current processor thermal throttle limit + ULONG MaxIdleState; + ULONG CurrentIdleState; +} PROCESSOR_POWER_INFORMATION, *PTR_PROCESSOR_POWER_INFORMATION; + +// additional lib needed for PowerProf functionality +#pragma comment(lib, "Powrprof.lib") + void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) { - // Nothing to do for now. + SYSTEM_INFO si; + GetSystemInfo(&si); + + PROCESSOR_POWER_INFORMATION ppi; + size_t sz_check = sizeof(ppi) * (size_t)si.dwNumberOfProcessors; + NTSTATUS status = ::CallNtPowerInformation(ProcessorInformation, NULL, 0, buf, (ULONG) buflen); + + if (status == ERROR_SUCCESS) { + PTR_PROCESSOR_POWER_INFORMATION pppi = (PTR_PROCESSOR_POWER_INFORMATION) buf; + for (size_t i = 0; i < si.dwNumberOfProcessors; i++) { + st->print_cr("ProcessorInformation for processor %d", (int) pppi->Number); + st->print_cr(" Max Mhz: %d", (int) pppi->MaxMhz); + st->print_cr(" Current Mhz: %d", (int) pppi->CurrentMhz); + st->print_cr(" Mhz Limit: %d", (int) pppi->MhzLimit); + st->print_cr(" MaxIdleState: %d", (int) pppi->MaxIdleState); + st->print_cr(" CurrentIdleState: %d", (int) pppi->CurrentIdleState); + if (sz_check > buflen) break; + pppi++; + } + } } void os::get_summary_cpu_info(char* buf, size_t buflen) { From 08bba6d11e210f0f29b31b6f0f89ba6814c9076c Mon Sep 17 00:00:00 2001 From: MBaesken Date: Mon, 6 Feb 2023 14:08:02 +0100 Subject: [PATCH 2/6] Some adjustments mostly suggested by David --- src/hotspot/os/windows/os_windows.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index eedd475f42110..29bdbc9118b4e 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -91,7 +91,7 @@ #include #include -#include +#include #include #include #include @@ -1885,7 +1885,7 @@ typedef struct _PROCESSOR_POWER_INFORMATION { ULONG MhzLimit; // max specified processor clock frequency mult. by current processor thermal throttle limit ULONG MaxIdleState; ULONG CurrentIdleState; -} PROCESSOR_POWER_INFORMATION, *PTR_PROCESSOR_POWER_INFORMATION; +} PROCESSOR_POWER_INFORMATION; // additional lib needed for PowerProf functionality #pragma comment(lib, "Powrprof.lib") @@ -1894,12 +1894,11 @@ void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) { SYSTEM_INFO si; GetSystemInfo(&si); - PROCESSOR_POWER_INFORMATION ppi; - size_t sz_check = sizeof(ppi) * (size_t)si.dwNumberOfProcessors; + size_t sz_check = sizeof(PROCESSOR_POWER_INFORMATION) * (size_t)si.dwNumberOfProcessors; NTSTATUS status = ::CallNtPowerInformation(ProcessorInformation, NULL, 0, buf, (ULONG) buflen); if (status == ERROR_SUCCESS) { - PTR_PROCESSOR_POWER_INFORMATION pppi = (PTR_PROCESSOR_POWER_INFORMATION) buf; + PROCESSOR_POWER_INFORMATION* pppi = (PROCESSOR_POWER_INFORMATION*) buf; for (size_t i = 0; i < si.dwNumberOfProcessors; i++) { st->print_cr("ProcessorInformation for processor %d", (int) pppi->Number); st->print_cr(" Max Mhz: %d", (int) pppi->MaxMhz); From 12cf8db342b1fcfd1cc173f988203ba2d6479777 Mon Sep 17 00:00:00 2001 From: MBaesken Date: Wed, 8 Feb 2023 15:51:51 +0100 Subject: [PATCH 3/6] Reuse processor count if possible, adjust output a bit --- src/hotspot/os/windows/os_windows.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index 29bdbc9118b4e..5282d6d293e37 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -1891,21 +1891,25 @@ typedef struct _PROCESSOR_POWER_INFORMATION { #pragma comment(lib, "Powrprof.lib") void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) { - SYSTEM_INFO si; - GetSystemInfo(&si); + int proc_count = os::processor_count(); + // handle potential early cases where processor count is not yet set + if (proc_count < 1) { + SYSTEM_INFO si; + GetSystemInfo(&si); + proc_count = si.dwNumberOfProcessors; + } - size_t sz_check = sizeof(PROCESSOR_POWER_INFORMATION) * (size_t)si.dwNumberOfProcessors; + size_t sz_check = sizeof(PROCESSOR_POWER_INFORMATION) * (size_t)proc_count; NTSTATUS status = ::CallNtPowerInformation(ProcessorInformation, NULL, 0, buf, (ULONG) buflen); if (status == ERROR_SUCCESS) { PROCESSOR_POWER_INFORMATION* pppi = (PROCESSOR_POWER_INFORMATION*) buf; - for (size_t i = 0; i < si.dwNumberOfProcessors; i++) { + for (size_t i = 0; i < proc_count; i++) { st->print_cr("ProcessorInformation for processor %d", (int) pppi->Number); - st->print_cr(" Max Mhz: %d", (int) pppi->MaxMhz); - st->print_cr(" Current Mhz: %d", (int) pppi->CurrentMhz); - st->print_cr(" Mhz Limit: %d", (int) pppi->MhzLimit); - st->print_cr(" MaxIdleState: %d", (int) pppi->MaxIdleState); - st->print_cr(" CurrentIdleState: %d", (int) pppi->CurrentIdleState); + st->print_cr(" Max Mhz: %d, Current Mhz: %d, Mhz Limit: %d", + (int) pppi->MaxMhz, (int) pppi->CurrentMhz, (int) pppi->MhzLimit); + st->print_cr(" MaxIdleState: %d, CurrentIdleState: %d", + (int) pppi->MaxIdleState, (int) pppi->CurrentIdleState); if (sz_check > buflen) break; pppi++; } From 9a311018c1873ae6f63ff158e1db4d4284bcb959 Mon Sep 17 00:00:00 2001 From: MBaesken Date: Thu, 9 Feb 2023 11:17:05 +0100 Subject: [PATCH 4/6] link powrprof lib without pragma --- make/autoconf/libraries.m4 | 2 +- src/hotspot/os/windows/os_windows.cpp | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/make/autoconf/libraries.m4 b/make/autoconf/libraries.m4 index e057626b676d1..a50ce57318186 100644 --- a/make/autoconf/libraries.m4 +++ b/make/autoconf/libraries.m4 @@ -170,7 +170,7 @@ AC_DEFUN_ONCE([LIB_SETUP_LIBRARIES], if test "x$OPENJDK_TARGET_OS" = xwindows; then BASIC_JVM_LIBS="$BASIC_JVM_LIBS kernel32.lib user32.lib gdi32.lib winspool.lib \ - comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib \ + comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib powrprof.lib uuid.lib \ wsock32.lib winmm.lib version.lib psapi.lib" fi LIB_SETUP_JVM_LIBS(BUILD) diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index 5282d6d293e37..b9dab52a21180 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -1887,9 +1887,6 @@ typedef struct _PROCESSOR_POWER_INFORMATION { ULONG CurrentIdleState; } PROCESSOR_POWER_INFORMATION; -// additional lib needed for PowerProf functionality -#pragma comment(lib, "Powrprof.lib") - void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) { int proc_count = os::processor_count(); // handle potential early cases where processor count is not yet set @@ -1904,7 +1901,7 @@ void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) { if (status == ERROR_SUCCESS) { PROCESSOR_POWER_INFORMATION* pppi = (PROCESSOR_POWER_INFORMATION*) buf; - for (size_t i = 0; i < proc_count; i++) { + for (int i = 0; i < proc_count; i++) { st->print_cr("ProcessorInformation for processor %d", (int) pppi->Number); st->print_cr(" Max Mhz: %d, Current Mhz: %d, Mhz Limit: %d", (int) pppi->MaxMhz, (int) pppi->CurrentMhz, (int) pppi->MhzLimit); From 2811225e211cbabbe6278bf5bf23a4a04dc5cdc7 Mon Sep 17 00:00:00 2001 From: MBaesken Date: Thu, 16 Feb 2023 10:12:55 +0100 Subject: [PATCH 5/6] Do not print idle state infos on Windows, print same MHz values for all proces only once --- src/hotspot/os/windows/os_windows.cpp | 30 ++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index b9dab52a21180..518fb1b8862d0 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -1898,15 +1898,39 @@ void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) { size_t sz_check = sizeof(PROCESSOR_POWER_INFORMATION) * (size_t)proc_count; NTSTATUS status = ::CallNtPowerInformation(ProcessorInformation, NULL, 0, buf, (ULONG) buflen); + int MaxMhz = -1, CurrentMhz = -1, MhzLimit = -1; + bool same_vals_for_all_cpus = true; if (status == ERROR_SUCCESS) { PROCESSOR_POWER_INFORMATION* pppi = (PROCESSOR_POWER_INFORMATION*) buf; + for (int i = 0; i < proc_count; i++) { + if (i == 0) { + MaxMhz = (int) pppi->MaxMhz; + CurrentMhz = (int) pppi->CurrentMhz; + MhzLimit = (int) pppi->MhzLimit; + } else { + if (MaxMhz != (int) pppi->MaxMhz || + CurrentMhz != (int) pppi->CurrentMhz || + MhzLimit != (int) pppi->MhzLimit) { + same_vals_for_all_cpus = false; + } + } + // avoid iteration in case buf is too small to hold all proc infos + if (sz_check > buflen) break; + pppi++; + } + + if (same_vals_for_all_cpus && MaxMhz != -1) { + st->print_cr("ProcessorInformation for all %d processors :", proc_count); + st->print_cr(" Max Mhz: %d, Current Mhz: %d, Mhz Limit: %d", MaxMhz, CurrentMhz, MhzLimit); + return; + } + // differing values, iterate again + pppi = (PROCESSOR_POWER_INFORMATION*) buf; for (int i = 0; i < proc_count; i++) { st->print_cr("ProcessorInformation for processor %d", (int) pppi->Number); st->print_cr(" Max Mhz: %d, Current Mhz: %d, Mhz Limit: %d", - (int) pppi->MaxMhz, (int) pppi->CurrentMhz, (int) pppi->MhzLimit); - st->print_cr(" MaxIdleState: %d, CurrentIdleState: %d", - (int) pppi->MaxIdleState, (int) pppi->CurrentIdleState); + (int) pppi->MaxMhz, (int) pppi->CurrentMhz, (int) pppi->MhzLimit); if (sz_check > buflen) break; pppi++; } From 439644e2e4ee2c7b4b83c329e8fb0a891383e5ba Mon Sep 17 00:00:00 2001 From: MBaesken Date: Fri, 17 Feb 2023 09:12:20 +0100 Subject: [PATCH 6/6] Rename variables, adjust output, add a break --- src/hotspot/os/windows/os_windows.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index 518fb1b8862d0..b3ba21027bdfe 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -1898,21 +1898,22 @@ void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) { size_t sz_check = sizeof(PROCESSOR_POWER_INFORMATION) * (size_t)proc_count; NTSTATUS status = ::CallNtPowerInformation(ProcessorInformation, NULL, 0, buf, (ULONG) buflen); - int MaxMhz = -1, CurrentMhz = -1, MhzLimit = -1; + int max_mhz = -1, current_mhz = -1, mhz_limit = -1; bool same_vals_for_all_cpus = true; if (status == ERROR_SUCCESS) { PROCESSOR_POWER_INFORMATION* pppi = (PROCESSOR_POWER_INFORMATION*) buf; for (int i = 0; i < proc_count; i++) { if (i == 0) { - MaxMhz = (int) pppi->MaxMhz; - CurrentMhz = (int) pppi->CurrentMhz; - MhzLimit = (int) pppi->MhzLimit; + max_mhz = (int) pppi->MaxMhz; + current_mhz = (int) pppi->CurrentMhz; + mhz_limit = (int) pppi->MhzLimit; } else { - if (MaxMhz != (int) pppi->MaxMhz || - CurrentMhz != (int) pppi->CurrentMhz || - MhzLimit != (int) pppi->MhzLimit) { + if (max_mhz != (int) pppi->MaxMhz || + current_mhz != (int) pppi->CurrentMhz || + mhz_limit != (int) pppi->MhzLimit) { same_vals_for_all_cpus = false; + break; } } // avoid iteration in case buf is too small to hold all proc infos @@ -1920,15 +1921,15 @@ void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) { pppi++; } - if (same_vals_for_all_cpus && MaxMhz != -1) { - st->print_cr("ProcessorInformation for all %d processors :", proc_count); - st->print_cr(" Max Mhz: %d, Current Mhz: %d, Mhz Limit: %d", MaxMhz, CurrentMhz, MhzLimit); + if (same_vals_for_all_cpus && max_mhz != -1) { + st->print_cr("Processor Information for all %d processors :", proc_count); + st->print_cr(" Max Mhz: %d, Current Mhz: %d, Mhz Limit: %d", max_mhz, current_mhz, mhz_limit); return; } // differing values, iterate again pppi = (PROCESSOR_POWER_INFORMATION*) buf; for (int i = 0; i < proc_count; i++) { - st->print_cr("ProcessorInformation for processor %d", (int) pppi->Number); + st->print_cr("Processor Information for processor %d", (int) pppi->Number); st->print_cr(" Max Mhz: %d, Current Mhz: %d, Mhz Limit: %d", (int) pppi->MaxMhz, (int) pppi->CurrentMhz, (int) pppi->MhzLimit); if (sz_check > buflen) break;