Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion make/autoconf/libraries.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 27 additions & 1 deletion src/hotspot/os/bsd/os_bsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
60 changes: 59 additions & 1 deletion src/hotspot/os/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
#include <shlobj.h>

#include <malloc.h>
#include <powerbase.h>
#include <signal.h>
#include <direct.h>
#include <errno.h>
Expand Down Expand Up @@ -1876,8 +1877,65 @@ 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;

void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) {
// Nothing to do for now.
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)proc_count;
NTSTATUS status = ::CallNtPowerInformation(ProcessorInformation, NULL, 0, buf, (ULONG) buflen);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the caller supposed to know what size buffer to pass? Are they just supposed to guess and hope it is big enough??

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) {
max_mhz = (int) pppi->MaxMhz;
current_mhz = (int) pppi->CurrentMhz;
mhz_limit = (int) pppi->MhzLimit;
} else {
if (max_mhz != (int) pppi->MaxMhz ||
current_mhz != (int) pppi->CurrentMhz ||
mhz_limit != (int) pppi->MhzLimit) {
same_vals_for_all_cpus = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could break once this is false.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a break.

break;
}
}
// avoid iteration in case buf is too small to hold all proc infos
if (sz_check > buflen) break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case shouldn't the function have returned STATUS_BUFFER_TOO_SMALL?

pppi++;
}

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("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;
pppi++;
}
}
}

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