Skip to content
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

Z: Accelerate inlining Thread.onSpinWait() #20714

Merged

Conversation

ehsankianifar
Copy link
Contributor

Thread.onSpinWait() is a simple nop instruction on z. Enabled by default. Disable by setting the TR_noPauseOnSpinWait environment variable.

TR::Instruction* cursor = new (cg->trHeapMemory()) TR::S390NOPInstruction(TR::InstOpCode::NOP, 2, node, cg);

TR::Compilation *comp = cg->comp();
static const bool printIt = feGetEnv("TR_showPauseOnSpinWait") != NULL;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TR_showPauseOnSpinWait would be a little misleading since "PAUSE" instruction is x86 specific but I have to use the same env variable because it was used in shared code and x86!

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we even need condition for the traceMsg? It should be done in the entry unconditionally,

@ehsankianifar
Copy link
Contributor Author

@r30shah I renamed the branch and it caused the older PR to close. I opened this one with a different branch name. Please take a look.
I am running builds and tests.

@ehsankianifar ehsankianifar force-pushed the Z_Accelerate-onSpinWait-inlining branch from 72e0d9d to a5374a1 Compare December 4, 2024 21:04
Copy link
Contributor

@r30shah r30shah left a comment

Choose a reason for hiding this comment

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

Minor nitpicks, overall looks ok, please update the commit message and title (May be recognize is a better suited word than accelerate ? ) And change the reference to IBM Z from z.

TR::Instruction* cursor = new (cg->trHeapMemory()) TR::S390NOPInstruction(TR::InstOpCode::NOP, 2, node, cg);

TR::Compilation *comp = cg->comp();
static const bool printIt = feGetEnv("TR_showPauseOnSpinWait") != NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we even need condition for the traceMsg? It should be done in the entry unconditionally,

static const bool printIt = feGetEnv("TR_showPauseOnSpinWait") != NULL;
if (printIt && comp->getOption(TR_TraceCG))
{
traceMsg(comp, "Insert NOP for onSpinWait : node=%p, %s\n", node, comp->signature());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think printing the method name in the JIT compilation log is redundant. We would see this message in the compilation log of the method we want to log. I think, a simple message saying inlining call to Thread.onSpinWait to NOP is sufficient.

@@ -14665,3 +14665,18 @@ J9::Z::TreeEvaluator::inlineIntegerStringSize(TR::Node* node, TR::CodeGenerator*

return node->setRegister(lengthReg);
}

TR::Register*
J9::Z::TreeEvaluator::inlineOnSpinWait(TR::Node *node, TR::CodeGenerator *cg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add reference / Comment to the JNI call to OnSpinWait that emits NOP for reference to explain why we are generating NOP.

@ehsankianifar ehsankianifar force-pushed the Z_Accelerate-onSpinWait-inlining branch 2 times, most recently from e70d501 to aba70ba Compare December 10, 2024 15:43
@ehsankianifar
Copy link
Contributor Author

@r30shah thank you for your comments. When you have time, could you please check if the recent changes look good to you? thanks.

TR::Instruction* cursor = new (cg->trHeapMemory()) TR::S390NOPInstruction(TR::InstOpCode::NOP, 2, node, cg);

TR::Compilation *comp = cg->comp();
if (comp->getOption(TR_TraceCG))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this at the entry of the function - It just seems bit odd reading the code - Cosmetic change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Thread.onSpinWait() is a simple `nop` instruction on z.
Added instructions to recognize that method and inline it in jit code.
Enabled by default. Disable by setting the `TR_noPauseOnSpinWait`
environment variable.

Signed-off-by: Ehsan Kiani Far <[email protected]>
@ehsankianifar ehsankianifar force-pushed the Z_Accelerate-onSpinWait-inlining branch from aba70ba to 4e89f97 Compare December 10, 2024 16:02
Copy link
Contributor

@r30shah r30shah left a comment

Choose a reason for hiding this comment

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

LGTM

@r30shah
Copy link
Contributor

r30shah commented Dec 10, 2024

Jenkins test sanity zlinux jdk11,jdk21

@r30shah
Copy link
Contributor

r30shah commented Dec 10, 2024

Based on the tests done by @ehsankianifar internally and on PR, merging this change.

@r30shah r30shah merged commit 1e928fe into eclipse-openj9:master Dec 10, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants