RFR: 8322535: Change default AArch64 SpinPause instruction

Fredrik Bredberg fbredberg at openjdk.org
Wed Jan 17 12:46:53 UTC 2024


On Mon, 15 Jan 2024 16:25:08 GMT, Fredrik Bredberg <fbredberg at openjdk.org> wrote:

> The Java options OnSpinWaitInst lets you choose which AArch64 instruction should be used in `SpinPause()`. Valid values are "none", "nop", "isb" and "yield". Today the default value for OnSpinWaitInst is unfortunately "none".
> 
> However some CPUs changes the default SpinPause instruction to something better if the user hasn't used the OnSpinWaitInst option. For instance if you run a Neoverse N1, N2, V1 or V2, the default SpinPause instruction will be changed to "isb". After doing some measurements on Apple's M1-M3 CPUs it also seems like "isb" is the best yielding instruction on on those CPUs.
> 
> This PR changes the default SpinPause instruction to "yield" on all AArch64 platforms except on Apple's M1, M2 and M3 CPUs on which the default value will be "isb".
> 
> Tested tier1-tier7 successfully on linux-aarch64 and macosx-aarch64.

When I was browsing the interweb I saw that it's not uncommon to use isb instead of yield while spinning on AArch64. Before jumping on the bandwagon I created a test program to measure how long time it takes to issue a large number of instructions from several threads running in parallel. I tested nop, yield and isb on Apple's M1, M2 and M3 CPUs. The yield instruction doesn't take longer to execute than a nop instruction (in fact it takes less time than nop). However isb always takes significantly longer time to run than nop or yield on all of the above mentioned Apple CPUs. This finding combined with the fact that the JVM 
 today uses isb as default for Neoverse CPUs, justified the use of isb on Apple's M1-M3 CPUs.

But I do agree with both @theRealAph and @stooart-mon, isb is not intended for this purpose. It might create a delay that is too long for spinning purposes and applications overall won't necessarily show any benefit from isb vs yield.

Maybe the most reasonable way forward is to only change the default value of OnSpinWaitInst from "none" to "yield" and NOT change it to "isb" for Apple CPUs.

After all, that would make us use the "correct" spinning instruction on all AArch64 CPUs (except Neoverse).

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

PR Comment: https://git.openjdk.org/jdk/pull/17430#issuecomment-1895736557


More information about the hotspot-dev mailing list