Skip to content

8382337: [CRaC] Add CPU features nicknames for microarch levels#309

Open
antonvoznia wants to merge 8 commits intoopenjdk:cracfrom
antonvoznia:JDK-8382337-features-microarch-levels-impl
Open

8382337: [CRaC] Add CPU features nicknames for microarch levels#309
antonvoznia wants to merge 8 commits intoopenjdk:cracfrom
antonvoznia:JDK-8382337-features-microarch-levels-impl

Conversation

@antonvoznia
Copy link
Copy Markdown
Contributor

@antonvoznia antonvoznia commented Apr 16, 2026

x86_64 defines microarchitecture levels v1-v4: https://en.wikipedia.org/wiki/X86-64#Microarchitecture_levels

Let’s allow users to set -XX:CPUFeatures=x86-64-vX in addition to the current options (generic, native, ignore and bitmask).



Progress

  • Change must not contain extraneous whitespace

Issue

  • JDK-8382337: [CRaC] Add CPU features nicknames for microarch levels (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/crac.git pull/309/head:pull/309
$ git checkout pull/309

Update a local copy of the PR:
$ git checkout pull/309
$ git pull https://git.openjdk.org/crac.git pull/309/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 309

View PR using the GUI difftool:
$ git pr show -t 309

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/crac/pull/309.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Apr 16, 2026

👋 Welcome back antonvoznia! A progress list of the required criteria for merging this PR into crac will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 16, 2026

@antonvoznia 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:

8382337: [CRaC] Add CPU features nicknames for microarch levels

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 no new commits pushed to the crac branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@rvansa) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added ready Pull request is ready to be integrated rfr Pull request is ready for review labels Apr 16, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge bot commented Apr 16, 2026

Webrevs

Copy link
Copy Markdown
Collaborator

@rvansa rvansa left a comment

Choose a reason for hiding this comment

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

I see that you've followed the information on wiki, but from a practical point of you I am not sure if the FPU is present on modern CPUs. I will check AWS instance types and report my findings.
Also, I am somewhat concerned that v1 is not strictly superset of generic; we shall check out the FLUSH flag. Maybe these two could be equivalent?

Please add a test for the parsing; you can extend CheckCPUFeaturesTest or create a standalone one.

#ifdef AMD64
const char *microarch_prefix="x86-64-v";
const size_t microarch_prefix_len = strlen(microarch_prefix);
if (strncmp(str, microarch_prefix, strlen(microarch_prefix)) == 0 &&
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

replace the strlen(...) in here

}

#if defined(LINUX) && defined(AMD64)
void VM_Version::set_microarch_features(const char microarch_level, VM_Version::VM_Features &features) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could this return VM_Features rather than just modify reference?

uint32_t value;
struct {
uint32_t : 4,
uint32_t fpu : 1,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you add a link to the struct with some reference saying where the bit position comes from?

@antonvoznia
Copy link
Copy Markdown
Contributor Author

@rvansa , Thank you for reviewing!

I see that you've followed the information on wiki, but from a practical point of you I am not sure if the FPU is present on modern CPUs. I will check AWS instance types and report my findings.

I verified on my x86 vm

$ cat /proc/cpuinfo | grep -i fpu
fpu             : yes
fpu_exception   : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr....

Also, I am somewhat concerned that v1 is not strictly superset of generic; we shall check out the FLUSH flag. Maybe these two could be equivalent?

I followed this pages
https://en.opensuse.org/X86-64_microarchitecture_levels
and
https://gitlab.com/x86-psABIs/x86-64-ABI ,
there is no FLUSH mentioned.
Do you think we need to check it out for some reason?

I also didn't include flags OSFXSR and SCE. To have them, we need priveledge access to registers CR4 and MRS
CR4
https://stackoverflow.com/a/10186910
MRS
https://wiki.osdev.org/Model_Specific_Registers

Please add a test for the parsing; you can extend CheckCPUFeaturesTest or create a standalone one.

I'll add this

@rvansa
Copy link
Copy Markdown
Collaborator

rvansa commented Apr 16, 2026

I have verified that all Intel/AMD CPUs used for AWS instance types have the FPU flag in lscpu, so that should be good.

@jankratochvil Could you comment why is the FLUSH (clflush) "required by OpenJDK"?

@rvansa
Copy link
Copy Markdown
Collaborator

rvansa commented Apr 16, 2026

Actually the reason is documented in VM_Version::supports_clflush() - let's just add it to the required set, please.

union ExtCpuid1Edx {
uint32_t value;
struct {
uint32_t : 22,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fpu should not be added anywhere. It is only set, but nothing ever reads or queries it. The only code that queries it is already disabled.

// FPU is always present on i686+: _features.supports_feature(CPU_FPU) &&

@jankratochvil
Copy link
Copy Markdown
Contributor

There is an existing message in the code:

      log_error(crac)("Restore failed due to incompatible or missing CPU features, try using -XX:CPUFeatures=%s on checkpoint.", image_features.print_numbers());

The question is whether it should not say (which would make it a bit long and complicated suggestion for the user):

      log_error(crac)("Restore failed due to incompatible or missing CPU features, try using -XX:CPUFeatures=x86-64-v%c or -XX:CPUFeatures=%s on checkpoint.", image_features.print_level_TBD(), image_features.print_numbers());

or even just (which would make the performance sub-optimal due to some CPU features possibly missing):

      log_error(crac)("Restore failed due to incompatible or missing CPU features, try using -XX:CPUFeatures=x86-64-v%c on checkpoint.", image_features.print_level_TBD());

As otherwise I have some doubts anyone will ever find the x86-64-v%c possibility exists (nobody reads the docs) and which level is his/her CPU.

features.set_feature(CPU_MMX);
features.set_feature(CPU_SSE);
features.set_feature(CPU_SSE2);
break;
Copy link
Copy Markdown
Contributor

@jankratochvil jankratochvil Apr 17, 2026

Choose a reason for hiding this comment

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

Suggested change
break;
// The following options are all in /proc/cpuinfo of one of the first 64-bit CPUs - Atom D2700 (and Opteron 1352): https://superuser.com/q/1572306/1015048
features.set_feature(CPU_FLUSH);
features.set_feature(CPU_TSC);
break;

I do not know why they are not in the x86_64-v1 official set. I have already listed them for "generic" as they are required or useful for OpenJDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready Pull request is ready to be integrated rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

3 participants