-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Implement genProfilingEnterCallback genProfilingLeaveCallback on Arm64 #26460
Implement genProfilingEnterCallback genProfilingLeaveCallback on Arm64 #26460
Conversation
The following tests are failing:
due to an assertion in Lines 14565 to 14569 in d951f5f
Update: when JIT generates profiler hooks:
During the call to The similar assertion happens in synchronous methods during fgCreateMonitorTree and I created a repro - #26518. One more occurrence of the issue happens (https://github.com/dotnet/coreclr/issues/26491) on linux-arm with enabled profiler hooks for the following methods
|
@davmason @noahfalk Do you have any suggestions regarding what ABI should be chosen for CORINFO_HELP_PROF_FCN_ENTER, CORINFO_HELP_PROF_FCN_LEAVE, CORINFO_HELP_PROF_FCN_TAILCALL helpers on Arm64? I proposed and implemented the calling convention as described in #26460 (comment) since I could not find any documentation that would prescribe what ABI should be used. The implementation passes Pri1 tests except the few tests as mentioned in the previous post. That issue will be fixed separately since it reproduces not only during profiling hooks code generation. cc @dotnet/jit-contrib |
@echesakovMSFT What you propose seems reasonable, although I am far from an expert on arm64. I think it is important that we pick a calling convention and document it, as long as it is reasonably performant and allows us to do both fast and slow path ELT the exact ABI is flexible. |
I agree with @davmason, as long as the ABI is something the JIT can generate reasonable efficiently and we've documented it, the exact choice seems less critical. I am not remotely an ARM64 expert but what you described above seems reasonable to me. If it helps there is an old PR that I never finished that was trying to make some headway documenting some of our pre-existing ELT ABI work: #19560. I don't recall where I got the ARM64 part of that doc so don't feel like you need to give it any weight. I do strongly recommend that we document the ABI in the clr-abi doc. I know we haven't been good at that in the past but it shouldn't be hard to avoid making the hole any deeper while the info is fresh : ) |
I will still need to implement Windows/arm64 helpers but I suspect they would look almost like the Linux ones @davmason Can you please take a look at the profiler related changes? |
…chitecture specific versions
Define REG_PROFILER_{ENTER,LEAVE}_ARG_FUNC_ID and RBM_PROFILER_{ENTER,LEAVE}_ARG_CALLER_SP
…jit/codegenarm64.cpp
…/jit/lsraarm64.cpp
… src/vm/arm64/asmhelpers.S
src/jit/codegenarm64.cpp
Outdated
|
||
gcInfo.gcMarkRegSetNpt(RBM_PROFILER_LEAVE_ARG_FUNC_ID); | ||
|
||
if (compiler->lvaDoneFrameLayout == Compiler::FINAL_FRAME_LAYOUT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this just be an assert? We shouldn't ever call this function before final frame layout, should we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is true for genProfilingEnterCallback - I am not sure about genProfilingLeaveCallback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After discussion with Bruce we think that the pattern
if (compiler->lvaDoneFrameLayout == Compiler::FINAL_FRAME_LAYOUT)
{
}
else
{
}
in genProfilingLeaveCallback was used because of legacy backend.
It looks that we can remove the else-logic and just do an assertion. I will follow up in another PR and remove the logic on x64 and arm64.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the changes, and I didn't see any issues. But I am far from an expert in arm64 so I'm not sure I would be able to spot anything.
/azp run coreclr-outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
More changes:
|
I have update the first post to indicate what ABI is chosen for the ELT hooks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes https://github.com/dotnet/coreclr/issues/19368
The following conventions for
genProfilingEnterCallback
andgenProfilingLeaveCallback
will be used on arm64:functionIDOrClientID
to a helper (REG_PROFILER_ENTER_ARG_FUNC_ID
orREG_PROFILER_LEAVE_ARG_FUNC_ID
)callerSp
to a helper (REG_PROFILER_ENTER_ARG_CALLER_SP
orREG_PROFILER_LEAVE_ARG_CALLER_SP
). It's quite tricky to figure out the callerSp on arm64 since we have 5 or 6 different types of the stack frame and fp is not guaranteed to point at the top of the stack frame (as on x64 or arm).REG_DEFAULT_HELPER_CALL_TARGET
)contains call target (i.e. address of the helper function or jump stub)
CORINFO_HELP_PROF_FCN_ENTER
all the argument registers (x0-x7, x8, v0-v7) will contain valid values of the arguments and must be preserved during the call. This helps to avoid pre-spilling of the argument register as we do on arm32.