Skip to content

Commit 6803da9

Browse files
committed
8301661: Enhance os::pd_print_cpu_info on macOS and Windows
Backport-of: 9145670354c41381614877aa71895dc2bd5cce9d
1 parent 0d2cc35 commit 6803da9

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
@@ -153,7 +153,7 @@ AC_DEFUN_ONCE([LIB_SETUP_LIBRARIES],
153153
154154
if test "x$OPENJDK_TARGET_OS" = xwindows; then
155155
BASIC_JVM_LIBS="$BASIC_JVM_LIBS kernel32.lib user32.lib gdi32.lib winspool.lib \
156-
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib \
156+
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib powrprof.lib uuid.lib \
157157
wsock32.lib winmm.lib version.lib psapi.lib"
158158
fi
159159

src/hotspot/os/bsd/os_bsd.cpp

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

1380+
#ifdef __APPLE__
1381+
static void print_sysctl_info_string(const char* sysctlkey, outputStream* st, char* buf, size_t size) {
1382+
if (sysctlbyname(sysctlkey, buf, &size, NULL, 0) >= 0) {
1383+
st->print_cr("%s:%s", sysctlkey, buf);
1384+
}
1385+
}
1386+
1387+
static void print_sysctl_info_uint64(const char* sysctlkey, outputStream* st) {
1388+
uint64_t val;
1389+
size_t size=sizeof(uint64_t);
1390+
if (sysctlbyname(sysctlkey, &val, &size, NULL, 0) >= 0) {
1391+
st->print_cr("%s:%llu", sysctlkey, val);
1392+
}
1393+
}
1394+
#endif
1395+
13801396
void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) {
1381-
// Nothing to do for now.
1397+
#ifdef __APPLE__
1398+
print_sysctl_info_string("machdep.cpu.brand_string", st, buf, buflen);
1399+
print_sysctl_info_uint64("hw.cpufrequency", st);
1400+
print_sysctl_info_uint64("hw.cpufrequency_min", st);
1401+
print_sysctl_info_uint64("hw.cpufrequency_max", st);
1402+
print_sysctl_info_uint64("hw.cachelinesize", st);
1403+
print_sysctl_info_uint64("hw.l1icachesize", st);
1404+
print_sysctl_info_uint64("hw.l1dcachesize", st);
1405+
print_sysctl_info_uint64("hw.l2cachesize", st);
1406+
print_sysctl_info_uint64("hw.l3cachesize", st);
1407+
#endif
13821408
}
13831409

13841410
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
@@ -88,6 +88,7 @@
8888
#include <shlobj.h>
8989

9090
#include <malloc.h>
91+
#include <powerbase.h>
9192
#include <signal.h>
9293
#include <direct.h>
9394
#include <errno.h>
@@ -1925,8 +1926,65 @@ void os::win32::print_windows_version(outputStream* st) {
19251926
st->cr();
19261927
}
19271928

1929+
// Processor Power Information; missing from Windows headers
1930+
typedef struct _PROCESSOR_POWER_INFORMATION {
1931+
ULONG Number;
1932+
ULONG MaxMhz; // max specified clock frequency of the system processor
1933+
ULONG CurrentMhz; // max specified processor clock frequency mult. by current processor throttle
1934+
ULONG MhzLimit; // max specified processor clock frequency mult. by current processor thermal throttle limit
1935+
ULONG MaxIdleState;
1936+
ULONG CurrentIdleState;
1937+
} PROCESSOR_POWER_INFORMATION;
1938+
19281939
void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) {
1929-
// Nothing to do for now.
1940+
int proc_count = os::processor_count();
1941+
// handle potential early cases where processor count is not yet set
1942+
if (proc_count < 1) {
1943+
SYSTEM_INFO si;
1944+
GetSystemInfo(&si);
1945+
proc_count = si.dwNumberOfProcessors;
1946+
}
1947+
1948+
size_t sz_check = sizeof(PROCESSOR_POWER_INFORMATION) * (size_t)proc_count;
1949+
NTSTATUS status = ::CallNtPowerInformation(ProcessorInformation, NULL, 0, buf, (ULONG) buflen);
1950+
int max_mhz = -1, current_mhz = -1, mhz_limit = -1;
1951+
bool same_vals_for_all_cpus = true;
1952+
1953+
if (status == ERROR_SUCCESS) {
1954+
PROCESSOR_POWER_INFORMATION* pppi = (PROCESSOR_POWER_INFORMATION*) buf;
1955+
for (int i = 0; i < proc_count; i++) {
1956+
if (i == 0) {
1957+
max_mhz = (int) pppi->MaxMhz;
1958+
current_mhz = (int) pppi->CurrentMhz;
1959+
mhz_limit = (int) pppi->MhzLimit;
1960+
} else {
1961+
if (max_mhz != (int) pppi->MaxMhz ||
1962+
current_mhz != (int) pppi->CurrentMhz ||
1963+
mhz_limit != (int) pppi->MhzLimit) {
1964+
same_vals_for_all_cpus = false;
1965+
break;
1966+
}
1967+
}
1968+
// avoid iteration in case buf is too small to hold all proc infos
1969+
if (sz_check > buflen) break;
1970+
pppi++;
1971+
}
1972+
1973+
if (same_vals_for_all_cpus && max_mhz != -1) {
1974+
st->print_cr("Processor Information for all %d processors :", proc_count);
1975+
st->print_cr(" Max Mhz: %d, Current Mhz: %d, Mhz Limit: %d", max_mhz, current_mhz, mhz_limit);
1976+
return;
1977+
}
1978+
// differing values, iterate again
1979+
pppi = (PROCESSOR_POWER_INFORMATION*) buf;
1980+
for (int i = 0; i < proc_count; i++) {
1981+
st->print_cr("Processor Information for processor %d", (int) pppi->Number);
1982+
st->print_cr(" Max Mhz: %d, Current Mhz: %d, Mhz Limit: %d",
1983+
(int) pppi->MaxMhz, (int) pppi->CurrentMhz, (int) pppi->MhzLimit);
1984+
if (sz_check > buflen) break;
1985+
pppi++;
1986+
}
1987+
}
19301988
}
19311989

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

0 commit comments

Comments
 (0)