Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

kouvel
Copy link

@kouvel kouvel commented Oct 4, 2018

Port of the following PRs to 2.2:

Description

Ports of #20007 and #20010 don't affect shipping code.

#20009 - Add MethodImplOptions.AggressiveOptimization and use it for tiering

  • PR [2.2] Expose MethodImplOptions.AggressiveOptimization and MethodImplAttributes.AggressiveOptimization corefx#32622 is also included in the set
  • It's likely that people would run into issue https://github.com/dotnet/coreclr/issues/19751 in their benchmarks when tiering is enabled by default, and it was determined that we should have this workaround for 2.2 RTM when tiered compilation is enabled
  • PR [2.2] Disable tiered compilation by default for 2.2 RTM #20525 disables tiered compilation by default in 2.2. Despite that, we would like to encourage customers to use tiered compilation in 2.2 RTM and these changes would provide them a useful workaround for the issue above.
  • Added MethodImplOptions.AggressiveOptimization to be used in a MethodImplAttribute to indicate that the method contains hot code
  • For a method flagged with AggressiveOptimization, tiering uses a foreground tier 1 JIT on first call to the method, skipping the tier 0 JIT and call counting
  • Crossgen does not generate code for a method flagged with AggressiveOptimization, such that it will be jitted at run-time, whether tiering is enabled or not
  • Refactored some tiered compilation logic to simplify and to limit the frequency of metadata lookups necessary to check for the AggressiveOptimization flag
  • Adds a new keyword aggressiveoptimization to IL ASM:
    .method private hidebysig static void  Main() cil managed aggressiveoptimization
    

Customer impact

  • No impact for methods that are not flagged with AggressiveOptimization
  • Methods flagged with AggressiveOptimization will be jitted with optimizations at run-time
  • Enables working around issue https://github.com/dotnet/coreclr/issues/19751

Regression?

Packaging reviewed?

Yes, no impact (coreclr only)

Risk

  • Relatively low, as there are currently no methods in .NET Core that are flagged with AggressiveOptimization
  • Metadata lookups add some time to the prestub path (first invocation of a method, and each invocation while counting calls), but there was no measurable difference in perf (the prestub path is already very heavy)
  • Binary compat
    • Older runtimes run newer binaries with the AggressiveOptimization flag without error, but would ignore the flag
    • Older ildasm disassembles newer binaries with the AggressiveOptimization flag without error, but strips the flag
    • Newer runtimes run older binaries without issue
    • Older ilasm would fail to compile newer ildasm output if it includes the new aggressiveoptimization keyword, this is by design

m_optTier(NativeCodeVersion::OptimizationTier0),
#ifdef FEATURE_TIERED_COMPILATION
m_optTier(optimizationTier),
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I don't think this will compile if FEATURE_TIERED_COMPILATION is not defined. Not sure if it is worth fixing though.

Copy link
Author

Choose a reason for hiding this comment

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

It looked like m_optTier is defined under FEATURE_TIERED_COMPILATION so I thought that it would not compile without the define before the change

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, should have been more specific -- OptimizationTier is only defined under FEATURE_TIERED_COMPILATION, so it is the argument list where the problem arises, not the initializer list.

Copy link
Author

Choose a reason for hiding this comment

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

Oh ok, I had moved that out of the define here: https://github.com/dotnet/coreclr/pull/20265/files#diff-3fc5234394621d5eb9524166a67ddd82R67 due to some paths that are outside the define needing to refer to it, though it won't actually be stored or used without the define. There's probably a better way to do it but I had settled on that at the time.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see. I think it's fine how you have it ... varying signatures based on defines is always annoying.

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

@kouvel
Copy link
Author

kouvel commented Oct 17, 2018

@dotnet-bot test CentOS7.1 x64 Checked Innerloop Build and Test

kouvel and others added 5 commits October 22, 2018 10:00
Fixes https://github.com/dotnet/coreclr/issues/19954
- `SetTargetInterlocked` can be soon followed by `ResetTargetInterlocked`, so the assert at the end of `SetTargetInterlocked` is invalid
- Removed the assert and instead just verified that the specified target is not the default prestub target
The appropriate environment variables were not being set due to a name mismatch
…20009)

Add MethodImplOptions.AggressiveOptimization and use it for tiering

Part of fix for https://github.com/dotnet/corefx/issues/32235
Workaround for https://github.com/dotnet/coreclr/issues/19751
- Added and set CORJIT_FLAG_AGGRESSIVE_OPT to indicate that a method is flagged with AggressiveOptimization
- For a method flagged with AggressiveOptimization, tiering uses a foreground tier 1 JIT on first call to the method, skipping the tier 0 JIT and call counting
- When tiering is disabled, a method flagged with AggressiveOptimization does not use r2r-pregenerated code
- R2r crossgen does not generate code for a method flagged with AggressiveOptimization
@kouvel kouvel added Servicing-consider Issue for next servicing release review and removed Servicing-consider Issue for next servicing release review labels Oct 22, 2018
@kouvel
Copy link
Author

kouvel commented Oct 23, 2018

@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test
test Ubuntu arm64 Cross Debug Innerloop Build

@kouvel
Copy link
Author

kouvel commented Oct 23, 2018

@dotnet-bot test this please

@vivmishra vivmishra added Servicing-rejected and removed Servicing-consider Issue for next servicing release review labels Oct 23, 2018
@vivmishra
Copy link

Rejected for 2.2 but approved for 3.0.

@kouvel kouvel closed this Oct 23, 2018
@kouvel kouvel deleted the NoTierMethod22 branch October 23, 2018 18:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants