-
Notifications
You must be signed in to change notification settings - Fork 6.2k
JDK-8301661: Enhance os::pd_print_cpu_info on macOS and Windows #12403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
👋 Welcome back mbaesken! A progress list of the required criteria for merging this PR into |
Webrevs
|
|
Okay the usual question when we augment the information that will appear in hs_err file: how safe is this going to be to call from a signal handler? |
Hi David , I think the sysctl / sysctlbyname calls on macOS are rather safe (and we use this already for some time for other entries e.g. in os::print_summary_info in vm error reporting, so nothing really new. Not so sure about the Windows powerprof / powerbase API, this was not used before to my knowledge in OpenJDK. However we use both macOS and Windows APIs for some time in our internal JVM, no issues seen so far. |
| 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the *PTR_PROCESSOR_POWER_INFORMATION
| #include <shlobj.h> | ||
|
|
||
| #include <malloc.h> | ||
| #include <powrprof.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The header should be powerbase.h
| // additional lib needed for PowerProf functionality | ||
| #pragma comment(lib, "Powrprof.lib") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this mechanism versus adding it to Makefile ??
| SYSTEM_INFO si; | ||
| GetSystemInfo(&si); | ||
|
|
||
| PROCESSOR_POWER_INFORMATION ppi; | ||
| size_t sz_check = sizeof(ppi) * (size_t)si.dwNumberOfProcessors; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have dwNumberOfProcessors available in processor_count() - though we may have to zero-initialize it and check for zero in case we crash before we've done os::init
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said from what I'm reading if systems have more than 64 processors they will be divided into processor groups and the max number will be 64. However IIUC CallNtPowerInformation will expect a buffer big enough for the true number of logical processors >64.
|
Hi David, thanks for the comments. I did a few adjustments following your comments. Regarding
Both works. From what I see, currently we use the Makefile to set the lib deps, should I remove the pragma and use the Makefile ? |
I'm asking the build folk if they have any preference/concerns.
True. I still think we might reuse processor_count(). Showing zero very early during VM init is not really an issue.
As this is intended as fairly general information shortening would be good - especially if the values reported are the same. Do we need to report all processors, or can we just use one as representative? |
|
Hi David , I did another small adjustment. Reused os::processor_count if it delivers a value larger than 0. And adjusted the output a bit.
On my notebook I noticed that the current idle state sometimes differs among processors. So it is not always the same.
|
|
With regards to the pragma I had the following response from @magicus :
|
I have no idea what possible use the "idle state" information would be in any case. We don't have that per-processor info on non-Windows. |
|
/label build |
magicus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build changes look good now. Thanks for removing the pragma.
/reviewers 2
|
@magicus |
|
@MBaesken This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 274 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Hi David, there is some info about the idle states at https://learn.microsoft.com/en-us/windows-hardware/test/wpt/cpu-analysis ; if you think that currently, with the info only available on Windows, it makes not that much sense to add, it I can omit it for now. Would probably make it easier to scan through the cpu-infos and observe same MHz numbers for all and then print the same info for all processors (as I said, where I tested the MHz values were the same for all CPUs only the current idle states varied). |
|
Hi Magnus, thanks for the review ! |
RealLucy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me
|
Hi David are you okay with the latest version ? |
I thought you were looking at reducing the output:
I don't think idle states are particularly useful, so I'd prefer to see similar output to non-Windows rather than per-processor info that is the same for everything of interest. |
…ll proces only once
dholmes-ora
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General approach seems okay. A couple of queries and nits.
Thanks.
| if (MaxMhz != (int) pppi->MaxMhz || | ||
| CurrentMhz != (int) pppi->CurrentMhz || | ||
| MhzLimit != (int) pppi->MhzLimit) { | ||
| same_vals_for_all_cpus = false; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a break.
| } | ||
|
|
||
| size_t sz_check = sizeof(PROCESSOR_POWER_INFORMATION) * (size_t)proc_count; | ||
| NTSTATUS status = ::CallNtPowerInformation(ProcessorInformation, NULL, 0, buf, (ULONG) buflen); |
There was a problem hiding this comment.
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??
| } | ||
| } | ||
| // avoid iteration in case buf is too small to hold all proc infos | ||
| if (sz_check > buflen) break; |
There was a problem hiding this comment.
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?
|
Hi David I adjusted the output, renamed some variables and added a break where you suggested.
I think this would be the case, but I was not sure so I added the check.
I think this is the same for most of the print_ functions from https://github.com/openjdk/jdk/blob/master/src/hotspot/share/runtime/os.hpp#L754 // Print out system information; they are called by fatal error handler. |
dholmes-ora
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still a little dubious about the buffer size check but lets see how this goes.
Thanks.
|
Hi David and Lutz, thanks for the reviews. /integrate |
|
Going to push as commit 9145670.
Your commit was automatically rebased without conflicts. |
Enhance os::pd_print_cpu_info on macOS and Windows by information about CPU frequency and caches.
On Windows , this info can be obtained by the Processor Power Information API or "powerbase" (CallNtPowerInformation , see https://learn.microsoft.com/en-us/windows/win32/api/powerbase/nf-powerbase-callntpowerinformation ); this is available since Windows Server 2003/XP.
On macOS, sysctlbyname can be used.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/12403/head:pull/12403$ git checkout pull/12403Update a local copy of the PR:
$ git checkout pull/12403$ git pull https://git.openjdk.org/jdk pull/12403/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 12403View PR using the GUI difftool:
$ git pr show -t 12403Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/12403.diff