[crac] RFR: RFC: -XX:CPUFeatures=0xnumber for CPU migration [v35]

Anton Kozlov akozlov at openjdk.org
Thu Jun 15 12:39:42 UTC 2023


On Mon, 12 Jun 2023 09:56:32 GMT, Jan Kratochvil <jkratochvil at openjdk.org> wrote:

>> Currently if you `-XX:CRaCCheckpointTo` on a better CPU and `-XX:CRaCRestoreFrom` on a worse CPU the restored OpenJDK will crash.
>> 
>> 1. An obvious reason is that JIT-compiled code is using CPU features not implemented on the CPU where the image is restored.
>> 2. A second reason is that glibc has a similar problem, its PLT entries point to CPU optimized functions also crashing on the worse CPU. https://sourceware.org/glibc/wiki/GNU_IFUNC
>> 
>> (1) could be solved somehow automatically by deoptimizing and re-JITing all the JIT code. But that would defeat the performance goal of restoring a ready image in the first place. Therefore there had to be implemented a new OpenJDK option:
>> 
>>> use -XX:CPUFeatures=0xnumber with -XX:CRaCCheckpointTo when you get an error during -XX:CRaCRestoreFrom on a different machine
>> 
>> It is intended to specify the lowest common denominator of all CPUs in a farm. Instead of a possible crash of OpenJDK it will now refuse to run:
>> 
>>> Error occurred during initialization of VM
>>> You have to specify -XX:CPUFeatures=0x421801fcfbd7 during -XX:CRaCCheckpointTo making of the checkpoint; specified -XX:CRaCRestoreFrom file contains CPU features 0x7fff9dfcfbf7; this machine's CPU features are 0x421801fcfbd7; missing features of this CPU are 0x3de79c000020 = 3dnowpref, adx, avx512f, avx512dq, avx512cd, avx512bw, avx512vl, sha, avx512_vpopcntdq, avx512_vpclmulqdq, avx512_vaes, avx512_vnni, clflushopt, clwb, avx512_vbmi2, avx512_vbmi
>> 
>> (2) has been implemented according to Anton Kozlov's idea that glibc can just reset its IFUNC PLT entries any time later (after restore), not just during the first initialization of glibc. That has currently a problem that it has turned out to be very invasive into private glibc structures. It could work somehow with glibc debuginfo (*-debuginfo.rpm or *-dbg.deb) installed but that has been considered as unacceptable requirement just to run CRaC. Therefore I have provided this proof of concept while I will propose such feature for glibc upstream where it is sure easily implementable.
>> 
>> If upstream glibc maintainers do not like the IFUNC reset idea then I do not think this hacky IFUNC reset patching many glibc internal data structures is a good way forward for a 3rd party implementation like CRaC/OpenJDK. In such case I believe one should switch to using GLIBC_TUNABLES environment variable, re-execing OpenJDK after converting the `-XX:CPUFeatures` OpenJDK format into glibc GLIBC_TUNABLES format. Unfo...
>
> Jan Kratochvil has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 110 commits:
> 
>  - Merge branch 'crac' into crac-altstack-cpu-cpuexplicit-strip
>  - Fix slowdebug compilation.
>    Split better get_processor_features_hardware/get_processor_features_hotspot().
>  - Compatibility with non-X86; untested.
>  - Simplify error reporting by err_msg().
>  - Fix printing missing features on target CPU.
>  - Fix hotspot 'ht' vs. glibc 'htt'.
>  - CPUFeatures refactorization.
>    Start CPU Features checking without libc.
>  - Reintroduce initialize_processor_count() requiring -XX:+CRaCCPUCountInit.
>     - requested by Anton Kozlov
>  - Remove initialize_processor_count().
>     - requested by Anton Kozlov
>     - it was crashing for me for 4 CPU <-> 16 CPU moves
>  - Reintroduce the "leftover" code which was not leftover.
>  - ... and 100 more: https://git.openjdk.org/crac/compare/a282698d...7c567e99

I could not spot anything, considering the size of the patch :)

LGTM!

src/hotspot/cpu/x86/vm_version_x86.cpp line 2564:

> 2562: 
> 2563:   if (ShowCPUFeatures)
> 2564:     nonlibc_tty_print_using_features_cr();

Do I understand correctly that at this point all features are checked, and this can be a regular printing function call, involving libc?

src/hotspot/cpu/x86/vm_version_x86.cpp line 2608:

> 2606: 
> 2607:   if (ShowCPUFeatures)
> 2608:     nonlibc_tty_print_using_features_cr();

Can be a regular printing function call?

-------------

Marked as reviewed by akozlov (Lead).

PR Review: https://git.openjdk.org/crac/pull/41#pullrequestreview-1481394404
PR Review Comment: https://git.openjdk.org/crac/pull/41#discussion_r1230899173
PR Review Comment: https://git.openjdk.org/crac/pull/41#discussion_r1230908479


More information about the crac-dev mailing list