-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8364128: Improve gathering of cpu feature names using stringStream #26515
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
8364128: Improve gathering of cpu feature names using stringStream #26515
Conversation
Signed-off-by: Ashutosh Mehra <asmehra@redhat.com>
|
👋 Welcome back asmehra! A progress list of the required criteria for merging this PR into |
|
@ashu-mehra 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 467 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 |
|
@ashu-mehra The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
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.
It seems like we can just use a stringStream instead and not have to deal with any overflow of some buffer, since we strdup at the end.
| #define CPU_INFO_BUF_SIZE 1024 | ||
| #endif // CPU_INFO_BUF_SIZE | ||
|
|
||
| template<size_t bufsz> class FormatBuffer; |
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.
Style: template <size_t bufsz>.
|
|
||
| template<size_t bufsz> class FormatBuffer; | ||
|
|
||
| using CpuInfoBuffer = FormatBuffer<CPU_INFO_BUF_SIZE>; |
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.
Is it important that we avoid dynamic allocation at this stage of VM initialization? Is that why we can't use stringStream instead?
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.
Yeah, I think stringStream can be used as well. Dynamic allocation shouldn't be a concern. I can set the initial size to be same as the CPU_INFO_BUF_SIZE to reduce churn a bit. I will try this out. Thanks for the suggestion.
| _features_string = extract_features_string(_cpu_info_string, | ||
| strnlen(_cpu_info_string, sizeof(buf)), | ||
| cpu_info_size); | ||
| _cpu_info_string = os::strdup(info_buffer); |
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.
Sorry, I'm going to need some help here :-). How can passing a FormatBuffer to os::strdup not fail to compile?
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.
And here we do os::strdup, so now we do have dynamic allocation, so maybe just use a stringStream?
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.
Sorry, I'm going to need some help here :-). How can passing a FormatBuffer to os::strdup not fail to compile?
It works because of this trick in its base class FormatBufferBase:
operator const char *() const { return _buf; }
| assert(!info_buffer.overflow(), "not enough buffer size"); | ||
| info_buffer.append(", "); | ||
| assert(!info_buffer.overflow(), "not enough buffer size"); | ||
| int features_offset = info_buffer.length(); | ||
| insert_features_names(_features, info_buffer); |
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.
Can't you just check the overflow at the end?
| // Appends comma separated strings obtained by mapping given range of numbers to strings | ||
| template<typename FN> | ||
| void insert_string_list(int start, int limit, FN fn) { | ||
| bool first = true; | ||
| for (int i = start; i < limit; i++) { | ||
| const char* str = fn(i); | ||
| if (str == nullptr) { | ||
| continue; | ||
| } | ||
| const char* comma = first ? "" : ", "; | ||
| int result = append("%s%s", comma, str); | ||
| if (result < 0) { | ||
| return; | ||
| } | ||
| first = false; | ||
| } | ||
| return; | ||
| } |
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.
This method seems overly specific to the use-case.
Something like this is more widely applicable.
// Append strings returned by gen, separating each with separator.
// Stops when gen returns null or when buffer is out of space.
template <typename Generator>
void join(Generator gen, const char* separator) {
bool first = true;
const char* str = gen();
while (str != nullptr) {
const char* sep = first ? "" : separator;
int result = append("%s%s", sep, str);
if (result < 0) {
return;
}
first = false;
}
return;
}Example usage:
void VM_Version::insert_features_names(uint64_t features, CpuInfoBuffer& info_buffer) {
int i = 0;
info_buffer.join([&]() {
while (!supports_feature((VM_Version::Feature_Flag)i) && i < MAX_CPU_FEATURES) {
i++;
}
if (i >= MAX_CPU_FEATURES) {
return nullptr;
}
return _features_names[i];
}, ", ");
assert(!info_buffer.overflow(), "not enough buffer size");
}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.
+1
I can add this to the stringStream class.
Signed-off-by: Ashutosh Mehra <asmehra@redhat.com>
Signed-off-by: Ashutosh Mehra <asmehra@redhat.com>
Signed-off-by: Ashutosh Mehra <asmehra@redhat.com>
Signed-off-by: Ashutosh Mehra <asmehra@redhat.com>
|
/contributor add @jdksjolen |
|
@ashu-mehra |
Signed-off-by: Ashutosh Mehra <asmehra@redhat.com>
|
@jdksjolen I updated the code as per your suggestion. Please review. |
|
@jdksjolen ping |
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.
This looks good to me! Added a few comments on the join method.
| first = false; | ||
| str = gen(); | ||
| } | ||
| return; |
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.
Let's delete this return
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.
Done
| void inc_cr() { inc(); cr(); } | ||
|
|
||
| // Append strings returned by gen, separating each with separator. | ||
| // Stops when gen returns null or when buffer is out of space. |
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 never really stop when the buffer runs out of space.
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.
Updated the comment.
| // Append strings returned by gen, separating each with separator. | ||
| // Stops when gen returns null or when buffer is out of space. | ||
| template <typename Generator> | ||
| void join(Generator gen, const char* separator) { |
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 can move this to the outputStream class instead!
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.
It is in the outputStream class
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.
Oops, I thought you moved it to the stringStream class, my bad :).
Signed-off-by: Ashutosh Mehra <asmehra@redhat.com>
|
@jdksjolen new commit pushed to address your comments. |
|
Can I get one more review of this please. |
|
I submitted our testing. |
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.
My testing passed.
|
/integrate |
|
Going to push as commit bc3d865.
Your commit was automatically rebased without conflicts. |
|
@ashu-mehra Pushed as commit bc3d865. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
|
|
||
| enum Feature_Flag { | ||
| #define DECLARE_CPU_FEATURE_FLAG(id, name, bit) CPU_##id = (1 << bit), | ||
| #define DECLARE_CPU_FEATURE_FLAG(id, name, bit) CPU_##id = bit, |
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.
It would be greatly appreciated if you could give the Graal devs a heads-up when changing CPU feature flags. JVMCI sees different CPU features with this change, and eventually leads to SIGILL by generating instruction not supported by the underlying CPU.
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.
@mur47x111 sorry for breaking JVMCI with this. I was not aware of such a dependency at all and I touched this code for the first time. For future work, how do I check if my change in hotspot has the potential to break JVMCI? And what is the best forum to inform about such changes?
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 will add a JVMCI test to assert this. You can inform us via /label add graal
This PR implements the code for cpu features names string using
FormatBufferstringStream.It also improves and extends FormatBuffer with an additional method that appends comma separated strings to the buffer.It also adds a method to stringStream that that appends separated strings separated by a delimiter to the buffer. This is useful in creating the cpu features names string.This code will also be useful in Leyden to implement cpu feature check for AOTCodeCache [0].
Platforms affected: x86-64 and aarch64
Other platforms can be done if and when Leyden changes are ported to them.
[0] openjdk/leyden#84
Progress
Issue
Reviewers
Contributors
<jsjolen@openjdk.org>Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26515/head:pull/26515$ git checkout pull/26515Update a local copy of the PR:
$ git checkout pull/26515$ git pull https://git.openjdk.org/jdk.git pull/26515/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26515View PR using the GUI difftool:
$ git pr show -t 26515Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26515.diff
Using Webrev
Link to Webrev Comment