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

Commit 590166a

Browse files
authored
Merge pull request #19691 from kouvel/Tier22_4
This is a port of several changes that went into master after 2.2 forked, including dependencies for, and enabling tiered compilation by default in 2.2. Quick summary of commits is below, see the commit descriptions and PRs for more info. - Commit 1 - Fix nested spin locks in thread pool etw firing (#17677) - Fixes a lock nesting issue when there is an ETW listener, which can occur without tiering, but is almost deterministic with tiering enabled because the first event that is fired typically hits this code path - Commit 2 - Don't close the JIT func info file on shutdown (#18060) - Fixes a crash during shutdown that only occurs when JIT logging is enabled (typically in the coreclr tests and CI). More frequent with tiering enabled because of different JIT timing and background jitting. - Commit 3 - Apply tiering's call counting delay more broadly (#18610) - Fixes a perf issue when tiering is enabled in server first-request scenarios where there is a significant gap between process startup and first request - Commit 4 - Changes only affect debug builds - Eliminate arm64 contract asserts (#19015) - Fixes some incorrect asserts that trigger more frequently with tiering - Commit 5 - Use 16 bytes to spill SIMD12 (#19237) - Fixes a crash in corefx System.Numerics.Tests.Vector3Tests.Vector3EqualsTest. Occurs with minopt JIT or with tiering. - Commit 6 - Fix an apartment state issue (partial port of #19384) - This is a partial port of this PR (only the portion that addresses issue #17822) - This is a breaking change, though a minor one that we have concluded is an acceptable risk to take for 2.2 - Fixes a behavioral difference that can be seen more easily tiering enabled in APIs on the `Thread` class relevant to apartment state. The issue can also be seen in some cases when tiering is disabled. - Commit 7 - Enable Tiered Compilation by default (#19525) - Enables tiering by default, can be disabled through environment, or through .csproj/.json when using dotnet - Removes deprecated config variable (EXPERIMENTAL_TieredCompilation) that was previously exposed in 2.1 along with the current config variable (TieredCompilation), along with miscellaneous test fixes - Commit 8 - Changes only affect tests - Fix tiered compilation option for case-sensitive systems (#19567) - Fixes tiering environment variable casing for non-Windows platforms - Commit 9 - Disable tiered compilation on arm64 - There is an open issue that may be partly related to minopts on arm64 (https://github.com/dotnet/coreclr/issues/18895). Disabling tiering by default on arm64 to limit exposing new issues. This change would be followed up with dotnet/corefx#31822 - Adds tests for Commit 6 - Fix an apartment state issue (partial port of #19384) - Changes only affect tests Closes https://github.com/dotnet/coreclr/issues/18973
2 parents ef4c376 + e0fbb77 commit 590166a

28 files changed

+586
-296
lines changed

Documentation/project-docs/clr-configuration-knobs.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,7 @@ Name | Description | Type | Class | Default Value | Flags
770770

771771
Name | Description | Type | Class | Default Value | Flags
772772
-----|-------------|------|-------|---------------|-------
773-
`EXPERIMENTAL_TieredCompilation` | Deprecated - Use COMPLUS_TieredCompilation | `DWORD` | `UNSUPPORTED` | `0` |
774-
`TieredCompilation` | Enables tiered compilation | `DWORD` | `EXTERNAL` | `0` |
773+
`TieredCompilation` | Enables tiered compilation | `DWORD` | `EXTERNAL` | `1` |
775774
`TieredCompilation_Test_CallCounting` | Enabled by default (only activates when TieredCompilation is also enabled). If disabled immediately backpatches prestub, and likely prevents any tier1 promotion | `DWORD` | `UNSUPPORTED` | `1` |
776775
`TieredCompilation_Test_OptimizeTier0` | Use optimized codegen (normally used by tier1) in tier0 | `DWORD` | `UNSUPPORTED` | `0` |
777776
`TieredCompilation_Tier1CallCountingDelayMs` | Delay in milliseconds since process startup or the last tier 0 JIT before call counting begins for tier 1 promotion. | `DWORD` | `UNSUPPORTED` | `100` |

src/inc/CrstTypes.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,3 +787,7 @@ End
787787
Crst ReadyToRunEntryPointToMethodDescMap
788788
AcquiredBefore ExecuteManRangeLock
789789
End
790+
791+
Crst TieredCompilation
792+
AcquiredBefore ThreadpoolTimerQueue
793+
End

src/inc/clrconfigvalues.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,14 @@ RETAIL_CONFIG_DWORD_INFO(INTERNAL_HillClimbing_GainExponent,
650650
/// Tiered Compilation
651651
///
652652
#ifdef FEATURE_TIERED_COMPILATION
653+
#ifdef _TARGET_ARM64_
653654
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_TieredCompilation, W("TieredCompilation"), 0, "Enables tiered compilation")
654-
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_LEGACY_TieredCompilation, W("EXPERIMENTAL_TieredCompilation"), 0, "Deprecated - Use COMPLUS_TieredCompilation")
655+
#else // !_TARGET_ARM64_
656+
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_TieredCompilation, W("TieredCompilation"), 1, "Enables tiered compilation")
657+
#endif // _TARGET_ARM64_
655658
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_TieredCompilation_Tier1CallCountThreshold, W("TieredCompilation_Tier1CallCountThreshold"), 30, "Number of times a method must be called after which it is promoted to tier 1.")
656-
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_TieredCompilation_Tier1CallCountingDelayMs, W("TieredCompilation_Tier1CallCountingDelayMs"), 100, "Delay in milliseconds since process startup or the last tier 0 JIT before call counting begins for tier 1 promotion.")
659+
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_TieredCompilation_Tier1CallCountingDelayMs, W("TieredCompilation_Tier1CallCountingDelayMs"), 100, "A perpetual delay in milliseconds that is applied to tier 1 call counting and jitting, while there is tier 0 activity.")
660+
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_TieredCompilation_Tier1DelaySingleProcMultiplier, W("TieredCompilation_Tier1DelaySingleProcMultiplier"), 10, "Multiplier for TieredCompilation_Tier1CallCountingDelayMs that is applied on a single-processor machine or when the process is affinitized to a single processor.")
657661

658662
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_TieredCompilation_Test_CallCounting, W("TieredCompilation_Test_CallCounting"), 1, "Enabled by default (only activates when TieredCompilation is also enabled). If disabled immediately backpatches prestub, and likely prevents any tier1 promotion")
659663
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_TieredCompilation_Test_OptimizeTier0, W("TieredCompilation_Test_OptimizeTier0"), 0, "Use optimized codegen (normally used by tier1) in tier0")

src/inc/crsttypes.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,19 @@ enum CrstType
176176
CrstThreadpoolWorker = 157,
177177
CrstThreadStaticDataHashTable = 158,
178178
CrstThreadStore = 159,
179-
CrstTPMethodTable = 160,
180-
CrstTypeEquivalenceMap = 161,
181-
CrstTypeIDMap = 162,
182-
CrstUMEntryThunkCache = 163,
183-
CrstUMThunkHash = 164,
184-
CrstUniqueStack = 165,
185-
CrstUnresolvedClassLock = 166,
186-
CrstUnwindInfoTableLock = 167,
187-
CrstVSDIndirectionCellLock = 168,
188-
CrstWinRTFactoryCache = 169,
189-
CrstWrapperTemplate = 170,
190-
kNumberOfCrstTypes = 171
179+
CrstTieredCompilation = 160,
180+
CrstTPMethodTable = 161,
181+
CrstTypeEquivalenceMap = 162,
182+
CrstTypeIDMap = 163,
183+
CrstUMEntryThunkCache = 164,
184+
CrstUMThunkHash = 165,
185+
CrstUniqueStack = 166,
186+
CrstUnresolvedClassLock = 167,
187+
CrstUnwindInfoTableLock = 168,
188+
CrstVSDIndirectionCellLock = 169,
189+
CrstWinRTFactoryCache = 170,
190+
CrstWrapperTemplate = 171,
191+
kNumberOfCrstTypes = 172
191192
};
192193

193194
#endif // __CRST_TYPES_INCLUDED
@@ -358,6 +359,7 @@ int g_rgCrstLevelMap[] =
358359
11, // CrstThreadpoolWorker
359360
4, // CrstThreadStaticDataHashTable
360361
10, // CrstThreadStore
362+
9, // CrstTieredCompilation
361363
9, // CrstTPMethodTable
362364
3, // CrstTypeEquivalenceMap
363365
7, // CrstTypeIDMap
@@ -534,6 +536,7 @@ LPCSTR g_rgCrstNameMap[] =
534536
"CrstThreadpoolWorker",
535537
"CrstThreadStaticDataHashTable",
536538
"CrstThreadStore",
539+
"CrstTieredCompilation",
537540
"CrstTPMethodTable",
538541
"CrstTypeEquivalenceMap",
539542
"CrstTypeIDMap",

src/inc/utilcode.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,7 @@ class CPUGroupInfo
14311431
static BOOL m_threadUseAllCpuGroups;
14321432
static WORD m_initialGroup;
14331433
static CPU_Group_Info *m_CPUGroupInfoArray;
1434+
static bool s_hadSingleProcessorAtStartup;
14341435

14351436
static BOOL InitCPUGroupInfoAPI();
14361437
static BOOL InitCPUGroupInfoArray();
@@ -1485,6 +1486,13 @@ class CPUGroupInfo
14851486
static void ChooseCPUGroupAffinity(GROUP_AFFINITY *gf);
14861487
static void ClearCPUGroupAffinity(GROUP_AFFINITY *gf);
14871488
#endif
1489+
1490+
public:
1491+
static bool HadSingleProcessorAtStartup()
1492+
{
1493+
LIMITED_METHOD_CONTRACT;
1494+
return s_hadSingleProcessorAtStartup;
1495+
}
14881496
};
14891497

14901498
int GetCurrentProcessCpuCount();

src/jit/compiler.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,14 +1437,6 @@ void Compiler::compShutdown()
14371437
}
14381438
#endif // FEATURE_JIT_METHOD_PERF
14391439

1440-
#if FUNC_INFO_LOGGING
1441-
if (compJitFuncInfoFile != nullptr)
1442-
{
1443-
fclose(compJitFuncInfoFile);
1444-
compJitFuncInfoFile = nullptr;
1445-
}
1446-
#endif // FUNC_INFO_LOGGING
1447-
14481440
#if COUNT_RANGECHECKS
14491441
if (optRangeChkAll > 0)
14501442
{

src/jit/compiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ class LclVarDsc
708708
// For 32-bit architectures, we make local variable SIMD12 types 16 bytes instead of just 12. We can't do
709709
// this for arguments, which must be passed according the defined ABI. We don't want to do this for
710710
// dependently promoted struct fields, but we don't know that here. See lvaMapSimd12ToSimd16().
711+
// (Note that for 64-bits, we are already rounding up to 16.)
711712
if ((lvType == TYP_SIMD12) && !lvIsParam)
712713
{
713714
assert(lvExactSize == 12);

src/jit/regset.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3274,10 +3274,11 @@ var_types Compiler::tmpNormalizeType(var_types type)
32743274

32753275
type = genActualType(type);
32763276

3277-
#if defined(FEATURE_SIMD) && !defined(_TARGET_64BIT_)
3278-
// For SIMD on 32-bit platforms, we always spill SIMD12 to a 16-byte SIMD16 temp.
3279-
// This is because we don't have a single instruction to store 12 bytes. We also
3280-
// allocate non-argument locals as 16 bytes; see lvSize().
3277+
#if defined(FEATURE_SIMD)
3278+
// We always spill SIMD12 to a 16-byte SIMD16 temp.
3279+
// This is because we don't have a single instruction to store 12 bytes, so we want
3280+
// to ensure that we always have the full 16 bytes for loading & storing the value.
3281+
// We also allocate non-argument locals as 16 bytes; see lvSize().
32813282
if (type == TYP_SIMD12)
32823283
{
32833284
type = TYP_SIMD16;

src/utilcode/util.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -852,13 +852,14 @@ BYTE * ClrVirtualAllocWithinRange(const BYTE *pMinAddr,
852852
}
853853
#endif
854854

855-
/*static*/ BOOL CPUGroupInfo::m_enableGCCPUGroups = FALSE;
856-
/*static*/ BOOL CPUGroupInfo::m_threadUseAllCpuGroups = FALSE;
857-
/*static*/ WORD CPUGroupInfo::m_nGroups = 0;
858-
/*static*/ WORD CPUGroupInfo::m_nProcessors = 0;
859-
/*static*/ WORD CPUGroupInfo::m_initialGroup = 0;
855+
/*static*/ BOOL CPUGroupInfo::m_enableGCCPUGroups = FALSE;
856+
/*static*/ BOOL CPUGroupInfo::m_threadUseAllCpuGroups = FALSE;
857+
/*static*/ WORD CPUGroupInfo::m_nGroups = 0;
858+
/*static*/ WORD CPUGroupInfo::m_nProcessors = 0;
859+
/*static*/ WORD CPUGroupInfo::m_initialGroup = 0;
860860
/*static*/ CPU_Group_Info *CPUGroupInfo::m_CPUGroupInfoArray = NULL;
861-
/*static*/ LONG CPUGroupInfo::m_initialization = 0;
861+
/*static*/ LONG CPUGroupInfo::m_initialization = 0;
862+
/*static*/ bool CPUGroupInfo::s_hadSingleProcessorAtStartup = false;
862863

863864
// Check and setup function pointers for >64 LP Support
864865
/*static*/ BOOL CPUGroupInfo::InitCPUGroupInfoAPI()
@@ -1066,6 +1067,18 @@ DWORD LCM(DWORD u, DWORD v)
10661067
m_enableGCCPUGroups = enableGCCPUGroups && hasMultipleGroups;
10671068
m_threadUseAllCpuGroups = threadUseAllCpuGroups && hasMultipleGroups;
10681069
#endif // _TARGET_AMD64_ || _TARGET_ARM64_
1070+
1071+
// Determine if the process is affinitized to a single processor (or if the system has a single processor)
1072+
DWORD_PTR processAffinityMask, systemAffinityMask;
1073+
if (GetProcessAffinityMask(GetCurrentProcess(), &processAffinityMask, &systemAffinityMask))
1074+
{
1075+
processAffinityMask &= systemAffinityMask;
1076+
if (processAffinityMask != 0 && // only one CPU group is involved
1077+
(processAffinityMask & (processAffinityMask - 1)) == 0) // only one bit is set
1078+
{
1079+
s_hadSingleProcessorAtStartup = true;
1080+
}
1081+
}
10691082
}
10701083

10711084
/*static*/ BOOL CPUGroupInfo::IsInitialized()

src/vm/appdomain.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3078,8 +3078,9 @@ void SystemDomain::SetThreadAptState (Thread::ApartmentState state)
30783078
Thread::ApartmentState pState = pThread->SetApartment(Thread::AS_InSTA, TRUE);
30793079
_ASSERTE(pState == Thread::AS_InSTA);
30803080
}
3081-
else if (state == Thread::AS_InMTA)
3081+
else
30823082
{
3083+
// If an apartment state was not explicitly requested, default to MTA
30833084
Thread::ApartmentState pState = pThread->SetApartment(Thread::AS_InMTA, TRUE);
30843085
_ASSERTE(pState == Thread::AS_InMTA);
30853086
}

0 commit comments

Comments
 (0)