Skip to content

Commit a4c765d

Browse files
authored
JIT: update jit config defaults for PGO (#49267)
Enable edge profiling by default, when jitting, or when prejitting for R2R. Keep block profiling there for classic ngen (so there is an entry probe). Enable minimal probing by default, when jitting. Keep full probing there for prejitting so presence of counts in a method implies method was executed. Enable class profiling by default when jitting. Still TBD if we will also do this when prejitting. Enable guarded devirtualization by default (will only kick in for PGO). Adjust experimental CI legs to reflect the above. Net effect is that when jitting, COMPlus_TieredPGO=1 turns on dynamic PGO with the expected set of behaviors, without any other options. We'll still need to set COMPlus_TC_QuickJitForLoops=1 to have methods with loops pass through Tier0.
1 parent 0c20962 commit a4c765d

File tree

4 files changed

+55
-25
lines changed

4 files changed

+55
-25
lines changed

eng/pipelines/common/templates/runtimes/run-test-job.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,10 @@ jobs:
471471
scenarios:
472472
- jitosr
473473
- jitosr_stress
474-
- jitguardeddevirtualization
475474
- jitehwritethru
476475
- jitobjectstackallocation
477476
- jitpgo
478477
- jitpgo_inline
479-
- jitpgo_classes
480-
- jitpgo_edgeinstrumentation
481478
${{ if in(parameters.testGroup, 'ilasm') }}:
482479
scenarios:
483480
- ilasmroundtrip

src/coreclr/jit/fgprofile.cpp

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,35 +1487,54 @@ PhaseStatus Compiler::fgPrepareToInstrumentMethod()
14871487

14881488
// Choose instrumentation technology.
14891489
//
1490+
// We enable edge profiling by default, except when:
1491+
// * disabled by option
1492+
// * we are prejitting via classic ngen
1493+
// * we are jitting osr methods
1494+
//
14901495
// Currently, OSR is incompatible with edge profiling. So if OSR is enabled,
14911496
// always do block profiling.
14921497
//
14931498
// Note this incompatibility only exists for methods that actually have
14941499
// patchpoints, but we won't know that until we import.
14951500
//
1496-
const bool methodMayHavePatchpoints =
1497-
(opts.jitFlags->IsSet(JitFlags::JIT_FLAG_TIER0) && (JitConfig.TC_OnStackReplacement() > 0));
1501+
CLANG_FORMAT_COMMENT_ANCHOR;
14981502

1499-
if ((JitConfig.JitEdgeProfiling() > 0) && !methodMayHavePatchpoints)
1503+
#ifdef FEATURE_READYTORUN_COMPILER
1504+
const bool r2r = opts.IsReadyToRun();
1505+
#else
1506+
const bool r2r = false;
1507+
#endif
1508+
const bool prejit = opts.jitFlags->IsSet(JitFlags::JIT_FLAG_PREJIT);
1509+
const bool classicNgen = prejit && !r2r;
1510+
const bool osr = (opts.jitFlags->IsSet(JitFlags::JIT_FLAG_TIER0) && (JitConfig.TC_OnStackReplacement() > 0));
1511+
const bool useEdgeProfiles = (JitConfig.JitEdgeProfiling() > 0) && !classicNgen && !osr;
1512+
1513+
if (useEdgeProfiles)
15001514
{
15011515
fgCountInstrumentor = new (this, CMK_Pgo) EfficientEdgeCountInstrumentor(this);
15021516
}
15031517
else
15041518
{
1505-
if (JitConfig.JitEdgeProfiling() > 0)
1506-
{
1507-
JITDUMP("OSR and edge profiling not yet compatible; using block profiling\n");
1508-
}
1519+
JITDUMP("Using block profiling, because %s\n",
1520+
(JitConfig.JitEdgeProfiling() > 0) ? "edge profiles disabled" : classicNgen ? "classic Ngen" : "OSR");
15091521

15101522
fgCountInstrumentor = new (this, CMK_Pgo) BlockCountInstrumentor(this);
15111523
}
15121524

1513-
if (JitConfig.JitClassProfiling() > 0)
1525+
// Enable class profiling by default, when jitting.
1526+
// Todo: we may also want this on by default for prejitting.
1527+
//
1528+
const bool useClassProfiles = (JitConfig.JitClassProfiling() > 0) && !prejit;
1529+
if (useClassProfiles)
15141530
{
15151531
fgClassInstrumentor = new (this, CMK_Pgo) ClassProbeInstrumentor(this);
15161532
}
15171533
else
15181534
{
1535+
JITDUMP("Not doing class profiling, because %s\n",
1536+
(JitConfig.JitClassProfiling() > 0) ? "class profiles disabled" : "prejit");
1537+
15191538
fgClassInstrumentor = new (this, CMK_Pgo) NonInstrumentor(this);
15201539
}
15211540

@@ -1575,13 +1594,29 @@ PhaseStatus Compiler::fgInstrumentMethod()
15751594
//
15761595
assert(fgClassInstrumentor->SchemaCount() == info.compClassProbeCount);
15771596

1578-
// Optionally, if there were no class probes and only one count probe,
1597+
// Optionally, when jitting, if there were no class probes and only one count probe,
15791598
// suppress instrumentation.
15801599
//
1581-
if ((JitConfig.JitMinimalProfiling() > 0) && (fgCountInstrumentor->SchemaCount() == 1) &&
1582-
(fgClassInstrumentor->SchemaCount() == 0))
1600+
// We leave instrumentation in place when prejitting as the sample hits in the method
1601+
// may be used to determine if the method should be prejitted or not.
1602+
//
1603+
// For jitting, no information is conveyed by the count in a single=block method.
1604+
//
1605+
bool minimalProbeMode = false;
1606+
1607+
if (opts.jitFlags->IsSet(JitFlags::JIT_FLAG_PREJIT))
1608+
{
1609+
minimalProbeMode = (JitConfig.JitMinimalPrejitProfiling() > 0);
1610+
}
1611+
else
1612+
{
1613+
minimalProbeMode = (JitConfig.JitMinimalJitProfiling() > 0);
1614+
}
1615+
1616+
if (minimalProbeMode && (fgCountInstrumentor->SchemaCount() == 1) && (fgClassInstrumentor->SchemaCount() == 0))
15831617
{
1584-
JITDUMP("Not instrumenting method: only one counter, and no class probes\n");
1618+
JITDUMP(
1619+
"Not instrumenting method: minimal probing enabled, and method has only one counter and no class probes\n");
15851620
return PhaseStatus::MODIFIED_NOTHING;
15861621
}
15871622

src/coreclr/jit/jitconfigvalues.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ CONFIG_INTEGER(JitEnableFinallyCloning, W("JitEnableFinallyCloning"), 1)
439439
CONFIG_INTEGER(JitEnableRemoveEmptyTry, W("JitEnableRemoveEmptyTry"), 1)
440440
#endif // DEBUG
441441

442-
// Overall master enable for Guarded Devirtualization. Currently not enabled by default.
443-
CONFIG_INTEGER(JitEnableGuardedDevirtualization, W("JitEnableGuardedDevirtualization"), 0)
442+
// Overall master enable for Guarded Devirtualization.
443+
CONFIG_INTEGER(JitEnableGuardedDevirtualization, W("JitEnableGuardedDevirtualization"), 1)
444444

445445
#if defined(DEBUG)
446446
// Various policies for GuardedDevirtualization
@@ -453,9 +453,10 @@ CONFIG_INTEGER(TC_OnStackReplacement, W("TC_OnStackReplacement"), 0)
453453
CONFIG_INTEGER(TC_OnStackReplacement_InitialCounter, W("TC_OnStackReplacement_InitialCounter"), 1000)
454454

455455
// Profile instrumentation options
456-
CONFIG_INTEGER(JitMinimalProfiling, W("JitMinimalProfiling"), 0)
457-
CONFIG_INTEGER(JitClassProfiling, W("JitClassProfiling"), 0)
458-
CONFIG_INTEGER(JitEdgeProfiling, W("JitEdgeProfiling"), 0)
456+
CONFIG_INTEGER(JitMinimalJitProfiling, W("JitMinimalJitProfiling"), 1)
457+
CONFIG_INTEGER(JitMinimalPrejitProfiling, W("JitMinimalPrejitProfiling"), 0)
458+
CONFIG_INTEGER(JitClassProfiling, W("JitClassProfiling"), 1)
459+
CONFIG_INTEGER(JitEdgeProfiling, W("JitEdgeProfiling"), 1)
459460

460461
// Control when Virtual Calls are expanded
461462
CONFIG_INTEGER(JitExpandCallsEarly, W("JitExpandCallsEarly"), 1) // Expand Call targets early (in the global morph

src/tests/Common/testenvironment.proj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,8 @@
147147
<TestEnvironment Include="gcstress0xc_jitminopts_heapverify1" GCStress="0xC" JITMinOpts="1" HeapVerify="1" />
148148
<TestEnvironment Include="jitosr" TC_OnStackReplacement="1" TC_QuickJitForLoops="1" TieredCompilation="1" />
149149
<TestEnvironment Include="jitosr_stress" TC_OnStackReplacement="1" TC_QuickJitForLoops="1" TC_OnStackReplacement_InitialCounter="1" OSR_HitLimit="1" TieredCompilation="1" />
150-
<TestEnvironment Include="jitpgo" TieredPGO="1" TieredCompilation="1" />
151-
<TestEnvironment Include="jitpgo_inline" TieredPGO="1" TieredCompilation="1" JitInlinePolicyProfile="1"/>
152-
<TestEnvironment Include="jitpgo_classes" TieredPGO="1" TieredCompilation="1" JitEnableGuardedDevirtualization="1" JitClassProfiling="1"/>
153-
<TestEnvironment Include="jitpgo_edgeinstrumentation" TieredPGO="1" TieredCompilation="1" JitEdgeProfiling="1"/>
154-
<TestEnvironment Include="jitguardeddevirtualization" JitEnableGuardedDevirtualization="1" TieredCompilation="0" />
150+
<TestEnvironment Include="jitpgo" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" />
151+
<TestEnvironment Include="jitpgo_inline" TieredPGO="1" TieredCompilation="1" JitInlinePolicyProfile="1" TC_QuickJitForLoops="1" />
155152
<TestEnvironment Include="jitehwritethru" EnableEhWriteThru="1" TieredCompilation="0" />
156153
<TestEnvironment Include="jitobjectstackallocation" JitObjectStackAllocation="1" TieredCompilation="0" />
157154
<TestEnvironment Include="ilasmroundtrip" RunningIlasmRoundTrip="1" />

0 commit comments

Comments
 (0)