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

Disable HANDLER_ENTRY_MUST_BE_IN_HOT_SECTION #71273

Merged
merged 4 commits into from
Jun 29, 2022

Conversation

amanasifkhalid
Copy link
Member

Follow-up to #71236. HANDLER_ENTRY_MUST_BE_IN_HOT_SECTION is currently hard-coded to 1, but the EE currently handles cold handler entrypoints correctly. This PR experiments with disabling HANDLER_ENTRY_MUST_BE_IN_HOT_SECTION. If successful, this could simplify code logic and enable hot/cold splitting in more scenarios.

@ghost ghost assigned amanasifkhalid Jun 24, 2022
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 24, 2022
@ghost
Copy link

ghost commented Jun 24, 2022

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

Follow-up to #71236. HANDLER_ENTRY_MUST_BE_IN_HOT_SECTION is currently hard-coded to 1, but the EE currently handles cold handler entrypoints correctly. This PR experiments with disabling HANDLER_ENTRY_MUST_BE_IN_HOT_SECTION. If successful, this could simplify code logic and enable hot/cold splitting in more scenarios.

Author: amanasifkhalid
Assignees: amanasifkhalid
Labels:

area-CodeGen-coreclr

Milestone: -

@amanasifkhalid
Copy link
Member Author

/azp run runtime-jit-experimental

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@amanasifkhalid
Copy link
Member Author

/azp run runtime-jit-experimental

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@amanasifkhalid amanasifkhalid marked this pull request as ready for review June 27, 2022 22:05
@amanasifkhalid
Copy link
Member Author

Disabling HANDLER_ENTRY_MUST_BE_IN_HOT_SECTION only revealed one failure, where a finally clause was mistakenly set as cold, thus not triggering the fgCloneFinally optimization. I've added a condition to fix this.

@AndyAyersMS PTAL. Assuming this solution is acceptable, would you like me to remove the macro from the codebase, or just leave it disabled for now? Thanks!

// (we want to enable fgCloneFinally() optimization).
if (hndBegBB->bbJumpKind != BBJ_EHFINALLYRET)
{
hndBegBB->bbSetRunRarely();
Copy link
Member

Choose a reason for hiding this comment

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

Why do we make any sort of assumption here?

Seems like perhaps we should just leave hndBegBB alone in this case.

Copy link
Member Author

@amanasifkhalid amanasifkhalid Jun 27, 2022

Choose a reason for hiding this comment

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

As far as I can tell, this assumption may be useful for selecting a splitting point in fgDetermineFirstColdBlock, but this hasn't been observed since HANDLER_ENTRY_MUST_BE_IN_HOT_SECTION has been forcing handler entries to be hot. Without this assumption, I don't think a handler entry will ever be selected as a candidate for fgFirstColdBlock here.

Are we ok with keeping this limitation, where handler entries cannot be cold? If so, I can clean this up.

Copy link
Member

Choose a reason for hiding this comment

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

Seems like perhaps we should just leave hndBegBB alone in this case.

@AndyAyersMS Do you think that here, and for the filtBB->bbSetRunRarely() case below, if we're not forcing the weight, we should just leave it alone and let natural weights be applied? In particular, we don't want to overwrite profile collected weights, which this is doing. It seems like the right thing to do would be to add logic to fgComputeMissingBlockWeights(), which computes weights for blocks that don't have any profile weights, so for every handler we call bbSetRunRarely() there.

Copy link
Member

Choose a reason for hiding this comment

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

Something like that.

In the absence of PGO, I think we can just decide catch / filter / fault funclets are rare with impunity (since they are only reached if there is an exception), but finallys should have a weight similar to the callfinallys that can invoke them.

@BruceForstall
Copy link
Member

Note that this change shows a lot of asm diffs

@amanasifkhalid
Copy link
Member Author

I've moved the logic for setting handler entry weights to fgComputeMissingBlockWeights():

  • For handler entries to finally blocks, we the predecessor's block weight is inherited, assuming the handler entry has a predecessor.
  • For all other handler entries, the block weight is set to 0.

@amanasifkhalid
Copy link
Member Author

/azp run runtime-jit-experimental

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@amanasifkhalid
Copy link
Member Author

To minimize asmdiffs, the above changes in fgComputeMissingBlockWeights() will only run if hot/cold splitting is enabled.

@amanasifkhalid
Copy link
Member Author

/azp run runtime-jit-experimental

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

LGTM.

You can leave removal of HANDLER_ENTRY_MUST_BE_IN_HOT_SECTION for a follow-up change. @BruceForstall said he might dig into the old change history and figure out when/why this was added.

@amanasifkhalid amanasifkhalid merged commit e9e04b8 into dotnet:main Jun 29, 2022
@amanasifkhalid amanasifkhalid deleted the cold-handler-entry branch June 29, 2022 06:16
@AndyAyersMS AndyAyersMS mentioned this pull request Jun 29, 2022
54 tasks
@ghost ghost locked as resolved and limited conversation to collaborators Jul 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants