Skip to content

Conversation

@eastig
Copy link
Member

@eastig eastig commented Jun 13, 2025

There is data SB-based spin pauses are less disruptive then ISB-based one on them, so performance is better:

There are discussions regarding using it for spin pauses:

Instruction support: https://developer.arm.com/documentation/109697/2025_03/Feature-descriptions/The-Armv8-5-architecture-extension

CPUs supporting it:

  • Apple M2+
  • Neoverse-N2
  • Neoverse-V2

Tests:

  • Gtests passed.
  • test/hotspot/jtreg/compiler/onSpinWait/TestOnSpinWaitAArch64.java passed.
  • test/hotspot/jtreg/compiler/onSpinWait/TestOnSpinWaitNoneAArch64.java passed.

Micro-benchmarks (Graviton 4, c8g.16xlarge (64 CPU), Neoverse-V2):

Benchmark Mode Cnt Score Error Units Diff ThreadOnSpinWait.ISB avgt 15 11.875 ± 0.129 ns/op ThreadOnSpinWait.SB avgt 15 6.930 ± 0.054 ns/op -42% Benchmark (maxNum) (threadCount) Mode Cnt Score Error Units Diff ThreadOnSpinWaitSharedCounter.ISB 1000000 4 avgt 15 49.874 ± 10.160 ms/op ThreadOnSpinWaitSharedCounter.SB 1000000 4 avgt 15 26.948 ± 4.036 ms/op -46% ThreadOnSpinWaitSharedCounter.ISB 1000000 8 avgt 15 65.173 ± 7.228 ms/op ThreadOnSpinWaitSharedCounter.SB 1000000 8 avgt 15 44.476 ± 1.292 ms/op -31% ThreadOnSpinWaitSharedCounter.ISB 1000000 16 avgt 15 177.805 ± 44.925 ms/op ThreadOnSpinWaitSharedCounter.SB 1000000 16 avgt 15 67.267 ± 13.814 ms/op -62% ThreadOnSpinWaitSharedCounter.ISB 1000000 32 avgt 15 265.149 ± 5.353 ms/op ThreadOnSpinWaitSharedCounter.SB 1000000 32 avgt 15 42.297 ± 3.436 ms/op -84% ThreadOnSpinWaitSharedCounter.ISB 1000000 48 avgt 15 125.231 ± 9.272 ms/op ThreadOnSpinWaitSharedCounter.SB 1000000 48 avgt 15 83.504 ± 8.561 ms/op -33% ThreadOnSpinWaitSharedCounter.ISB 1000000 64 avgt 15 124.505 ± 7.543 ms/op ThreadOnSpinWaitSharedCounter.SB 1000000 64 avgt 15 86.588 ± 9.519 ms/op -30% 

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8359435: AArch64: add support for SB instruction to MacroAssembler::spin_wait (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25801

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25801.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 13, 2025

👋 Welcome back eastigeevich! A progress list of the required criteria for merging this PR into master 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

openjdk bot commented Jun 13, 2025

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

8359435: AArch64: add support for SB instruction to MacroAssembler::spin_wait Reviewed-by: shade, aph 

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 11 new commits pushed to the master branch:

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 13, 2025
@openjdk
Copy link

openjdk bot commented Jun 13, 2025

@eastig The following label will be automatically applied to this pull request:

  • hotspot-compiler

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.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Jun 13, 2025
@eastig
Copy link
Member Author

eastig commented Jun 13, 2025

Hi @theRealAph ,
Could you please take a look?

@mlbridge
Copy link

mlbridge bot commented Jun 13, 2025

@theRealAph
Copy link
Contributor

I think this can wait until we have a use for SB.

@eastig
Copy link
Member Author

eastig commented Jun 13, 2025

The case is to use it for spin pauses instead of ISB on Neoverse-N2/V2.
There is data SB-based spin pauses are less disruptive then ISB-based one on them, so performance is better:

There are discussions regarding using it for spin pauses:

Do you think it is better to have a PR combining this PR and use of SB for spin pauses?

@eastig
Copy link
Member Author

eastig commented Jun 13, 2025

BTW Arm published a post in their blog about different implementations of spin pauses: https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/multi-threaded-applications-arm
A high accuracy delay requires FEAT_SB (Armv8.5-A), FEAT_ECV (Armv8.6-A) and FEAT_WFxT (Armv8.7-A).

@shipilev
Copy link
Member

FWIW, I don't mind the SB assembler support to go under this, separate PR. We sometimes do it to split the work in the series of atomic commits, where the commit like this should certainly be non-regressing. The actual use of SB (spin-pauses) can then come under separate RFE, and would require much more work (and have associated risk).

So, it would be tad less confusing if we had a dependent RFE for using SB in spin pauses, so it was obvious why do we need it.

@theRealAph
Copy link
Contributor

Do you think it is better to have a PR combining this PR and use of SB for spin pauses?

Yes, definitely, otherwise we're pushing dead code. Thanks.

@theRealAph
Copy link
Contributor

So, it would be tad less confusing if we had a dependent RFE for using SB in spin pauses, so it was obvious why do we need it.

Huh? The least confusing is when the SB support goes in the PR where it is used. That really is obvious, without any dependency chain.

@shipilev
Copy link
Member

So, it would be tad less confusing if we had a dependent RFE for using SB in spin pauses, so it was obvious why do we need it.

Huh? The least confusing is when the SB support goes in the PR where it is used. That really is obvious, without any dependency chain.

I am flexible to have it either way.

One of the drawbacks of piling up the instruction support and the feature that uses these instructions: if there is ever a second feature that depends on the same instruction support, we would effectively bind two commits (commit A: instruction support + feature A; commit B: feature B) together with an accidental dependency. Which gets extra funky if you ever go with bisects, backouts, backports. Atomic commits rule, and I personally strive to do them, even if there is a window when some code appears dead momentarily.

But as I said, I would not quibble here. SB looks like something that we would solely use for spin-wait hints.

@eastig eastig changed the title 8359435: AArch64: add support for 8.5 SB instruction 8359435: AArch64: add support for SB instruction to MacroAssembler::spin_wait Jun 23, 2025
@eastig eastig marked this pull request as draft June 23, 2025 14:32
@openjdk openjdk bot removed the rfr Pull request is ready for review label Jun 23, 2025
@eastig eastig marked this pull request as ready for review June 24, 2025 14:48
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 24, 2025
Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

Looks reasonable, but test needs more work.

OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());

analyzer.shouldHaveExitValue(0);
if (analyzer.getExitValue() != 0 && "sb".equals(spinWaitInst) && analyzer.contains("CPU does not support SB")) {
Copy link
Member

Choose a reason for hiding this comment

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

The logic here is a bit off. Suppose we do have non-zero exit code for, say, isb. This would not fail the test now. Do it something like this instead?

if ("sb".equals(spinWaitInst) && analyzer.contains("CPU does not support SB")) { System.out.println("Skipping the test. The current CPU does not support SB instruction."); return; } analyzer.shouldHaveExitValue(0); 
Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you, Aleksey for finding this. I accidentally removed analyzer.shouldHaveExitValue(0)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

* @run driver compiler.onSpinWait.TestOnSpinWaitAArch64 c2 nop 7
* @run driver compiler.onSpinWait.TestOnSpinWaitAArch64 c2 isb 3
* @run driver compiler.onSpinWait.TestOnSpinWaitAArch64 c2 yield 1
* @run driver compiler.onSpinWait.TestOnSpinWaitAArch64 c2 sb
Copy link
Member

Choose a reason for hiding this comment

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

Since we are touching up the test: maybe just say sb 1 explicitly, and then read spinWaitInstCount from args[2] unconditionally?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@shipilev
Copy link
Member

Also, merge from mainline to get windows-aarch64 build fix, so that we test things there too.

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

Looks okay to me. @theRealAph should also take a look.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 25, 2025
@theRealAph
Copy link
Contributor

Looks okay to me. @theRealAph should also take a look.

I'm still waiting for a use for this thing. Then we'll be able to see it in action.

@eastig
Copy link
Member Author

eastig commented Jun 25, 2025

Looks okay to me. @theRealAph should also take a look.

I'm still waiting for a use for this thing. Then we'll be able to see it in action.

Do you mean we need real-life workloads relying on j.l.Thread.onSpinWait to show improvements?

@shipilev
Copy link
Member

I'm still waiting for a use for this thing.

The other project reports Evgeny linked in PR body look pretty convincing, as well as ThreadOnSpinWait microbenchmarks we have as well. This PR does not propose to switch to SB for spin-waits, AFAICS. Just having SB as the spin-wait option does look fine to me.

Copy link
Contributor

@theRealAph theRealAph left a comment

Choose a reason for hiding this comment

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

Very sorry, my mistake. This is fine. :-)

@theRealAph
Copy link
Contributor

The other project reports Evgeny linked in PR body look pretty convincing

Yes. Again, my apologies.

@eastig
Copy link
Member Author

eastig commented Jun 26, 2025

Thank you, Andrew.

@eastig
Copy link
Member Author

eastig commented Jun 27, 2025

/integrate

@openjdk
Copy link

openjdk bot commented Jun 27, 2025

Going to push as commit ecd2d83.
Since your change was applied there have been 29 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 27, 2025
@openjdk openjdk bot closed this Jun 27, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 27, 2025
@openjdk
Copy link

openjdk bot commented Jun 27, 2025

@eastig Pushed as commit ecd2d83.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@dholmes-ora
Copy link
Member

dholmes-ora commented Jun 28, 2025

The modified test is now failing in our CI:

java.lang.RuntimeException: Missing compiler output for Thread.onSpinWait intrinsic 

Filed: JDK-8360936

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

Labels

hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated

4 participants