Skip to content

Commit 9145670

Browse files
committed
8301661: Enhance os::pd_print_cpu_info on macOS and Windows
Reviewed-by: ihse, lucy, dholmes
1 parent aa10f0d commit 9145670

File tree

3 files changed

+87
-3
lines changed

3 files changed

+87
-3
lines changed

make/autoconf/libraries.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ AC_DEFUN_ONCE([LIB_SETUP_LIBRARIES],
170170
171171
if test "x$OPENJDK_TARGET_OS" = xwindows; then
172172
BASIC_JVM_LIBS="$BASIC_JVM_LIBS kernel32.lib user32.lib gdi32.lib winspool.lib \
173-
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib \
173+
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib powrprof.lib uuid.lib \
174174
wsock32.lib winmm.lib version.lib psapi.lib"
175175
fi
176176
LIB_SETUP_JVM_LIBS(BUILD)

src/hotspot/os/bsd/os_bsd.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,8 +1299,34 @@ void os::print_os_info(outputStream* st) {
12991299
VM_Version::print_platform_virtualization_info(st);
13001300
}
13011301

1302+
#ifdef __APPLE__
1303+
static void print_sysctl_info_string(const char* sysctlkey, outputStream* st, char* buf, size_t size) {
1304+
if (sysctlbyname(sysctlkey, buf, &size, NULL, 0) >= 0) {
1305+
st->print_cr("%s:%s", sysctlkey, buf);
1306+
}
1307+
}
1308+
1309+
static void print_sysctl_info_uint64(const char* sysctlkey, outputStream* st) {
1310+
uint64_t val;
1311+
size_t size=sizeof(uint64_t);
1312+
if (sysctlbyname(sysctlkey, &val, &size, NULL, 0) >= 0) {
1313+
st->print_cr("%s:%llu", sysctlkey, val);
1314+
}
1315+
}
1316+
#endif
1317+
13021318
void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) {
1303-
// Nothing to do for now.
1319+
#ifdef __APPLE__
1320+
print_sysctl_info_string("machdep.cpu.brand_string", st, buf, buflen);
1321+
print_sysctl_info_uint64("hw.cpufrequency", st);
1322+
print_sysctl_info_uint64("hw.cpufrequency_min", st);
1323+
print_sysctl_info_uint64("hw.cpufrequency_max", st);
1324+
print_sysctl_info_uint64("hw.cachelinesize", st);
1325+
print_sysctl_info_uint64("hw.l1icachesize", st);
1326+
print_sysctl_info_uint64("hw.l1dcachesize", st);
1327+
print_sysctl_info_uint64("hw.l2cachesize", st);
1328+
print_sysctl_info_uint64("hw.l3cachesize", st);
1329+
#endif
13041330
}
13051331

13061332
void os::get_summary_cpu_info(char* buf, size_t buflen) {

src/hotspot/os/windows/os_windows.cpp

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
#include <shlobj.h>
9292

9393
#include <malloc.h>
94+
#include <powerbase.h>
9495
#include <signal.h>
9596
#include <direct.h>
9697
#include <errno.h>
@@ -1876,8 +1877,65 @@ void os::win32::print_windows_version(outputStream* st) {
18761877
st->cr();
18771878
}
18781879

1880+
// Processor Power Information; missing from Windows headers
1881+
typedef struct _PROCESSOR_POWER_INFORMATION {
1882+
ULONG Number;
1883+
ULONG MaxMhz; // max specified clock frequency of the system processor
1884+
ULONG CurrentMhz; // max specified processor clock frequency mult. by current processor throttle
1885+
ULONG MhzLimit; // max specified processor clock frequency mult. by current processor thermal throttle limit
1886+
ULONG MaxIdleState;
1887+
ULONG CurrentIdleState;
1888+
} PROCESSOR_POWER_INFORMATION;
1889+
18791890
void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) {
1880-
// Nothing to do for now.
1891+
int proc_count = os::processor_count();
1892+
// handle potential early cases where processor count is not yet set
1893+
if (proc_count < 1) {
1894+
SYSTEM_INFO si;
1895+
GetSystemInfo(&si);
1896+
proc_count = si.dwNumberOfProcessors;
1897+
}
1898+
1899+
size_t sz_check = sizeof(PROCESSOR_POWER_INFORMATION) * (size_t)proc_count;
1900+
NTSTATUS status = ::CallNtPowerInformation(ProcessorInformation, NULL, 0, buf, (ULONG) buflen);
1901+
int max_mhz = -1, current_mhz = -1, mhz_limit = -1;
1902+
bool same_vals_for_all_cpus = true;
1903+
1904+
if (status == ERROR_SUCCESS) {
1905+
PROCESSOR_POWER_INFORMATION* pppi = (PROCESSOR_POWER_INFORMATION*) buf;
1906+
for (int i = 0; i < proc_count; i++) {
1907+
if (i == 0) {
1908+
max_mhz = (int) pppi->MaxMhz;
1909+
current_mhz = (int) pppi->CurrentMhz;
1910+
mhz_limit = (int) pppi->MhzLimit;
1911+
} else {
1912+
if (max_mhz != (int) pppi->MaxMhz ||
1913+
current_mhz != (int) pppi->CurrentMhz ||
1914+
mhz_limit != (int) pppi->MhzLimit) {
1915+
same_vals_for_all_cpus = false;
1916+
break;
1917+
}
1918+
}
1919+
// avoid iteration in case buf is too small to hold all proc infos
1920+
if (sz_check > buflen) break;
1921+
pppi++;
1922+
}
1923+
1924+
if (same_vals_for_all_cpus && max_mhz != -1) {
1925+
st->print_cr("Processor Information for all %d processors :", proc_count);
1926+
st->print_cr(" Max Mhz: %d, Current Mhz: %d, Mhz Limit: %d", max_mhz, current_mhz, mhz_limit);
1927+
return;
1928+
}
1929+
// differing values, iterate again
1930+
pppi = (PROCESSOR_POWER_INFORMATION*) buf;
1931+
for (int i = 0; i < proc_count; i++) {
1932+
st->print_cr("Processor Information for processor %d", (int) pppi->Number);
1933+
st->print_cr(" Max Mhz: %d, Current Mhz: %d, Mhz Limit: %d",
1934+
(int) pppi->MaxMhz, (int) pppi->CurrentMhz, (int) pppi->MhzLimit);
1935+
if (sz_check > buflen) break;
1936+
pppi++;
1937+
}
1938+
}
18811939
}
18821940

18831941
void os::get_summary_cpu_info(char* buf, size_t buflen) {

0 commit comments

Comments
 (0)