Skip to content

Commit 671aead

Browse files
AndyAyersMSmichaelgsharp
authored andcommitted
Allow JIT to know if dynamic pgo is active (dotnet#101575)
When dynamic PGO is active we would like for all methods to have some profile data, so we don't have to handle a mixture of profiled and unprofiled methods during or after inlining. But to reduce profiling overhead, the JIT will not instrument methods that have straight-line control flow, or flow where all branches lead to throws (aka "minimal profiling"). When the JIT tries to recover profile data for these methods it won't get any data back. SO there is a fairly high volume of these profiled/unprofiled mixtures today and they lead to various poor decisions in the JIT. This change enables the JIT to see if dynamic PGO is active. The JIT does not yet do anything with the information. A subsequent change will have the JIT synthesize data for methods with no profile data in this case. We could also solve this by creating a placeholder PGO schema for theswith no data, but it seems simpler and less resource intensive to have the runtime tell the JIT that dynamic PGO is active. This also changes the JIT GUID for the new API surface. Contributes to dotnet#93020.
1 parent ae171a5 commit 671aead

File tree

19 files changed

+62
-38
lines changed

19 files changed

+62
-38
lines changed

src/coreclr/inc/corjit.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ class ICorJitInfo : public ICorDynamicInfo
452452
uint32_t * pCountSchemaItems, // OUT: pointer to the count of schema items in `pSchema` array.
453453
uint8_t ** pInstrumentationData, // OUT: `*pInstrumentationData` is set to the address of the instrumentation data
454454
// (pointer will not remain valid after jit completes).
455-
PgoSource * pPgoSource // OUT: value describing source of pgo data
455+
PgoSource * pPgoSource, // OUT: value describing source of pgo data
456+
bool * pDynamicPgo // OUT: dynamic PGO is enabled (valid even when return value is failure)
456457
) = 0;
457458

458459
// Allocate a profile buffer for use in the current process

src/coreclr/inc/icorjitinfoimpl_generated.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,8 @@ JITINTERFACE_HRESULT getPgoInstrumentationResults(
711711
ICorJitInfo::PgoInstrumentationSchema** pSchema,
712712
uint32_t* pCountSchemaItems,
713713
uint8_t** pInstrumentationData,
714-
ICorJitInfo::PgoSource* pgoSource) override;
714+
ICorJitInfo::PgoSource* pPgoSource,
715+
bool* pDynamicPgo) override;
715716

716717
JITINTERFACE_HRESULT allocPgoInstrumentationBySchema(
717718
CORINFO_METHOD_HANDLE ftnHnd,

src/coreclr/inc/jiteeversionguid.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
4343
#define GUID_DEFINED
4444
#endif // !GUID_DEFINED
4545

46-
constexpr GUID JITEEVersionIdentifier = { /* 8f046bcb-ca5f-4692-9277-898b71cb7938 */
47-
0x8f046bcb,
48-
0xca5f,
49-
0x4692,
50-
{0x92, 0x77, 0x89, 0x8b, 0x71, 0xcb, 0x79, 0x38}
46+
constexpr GUID JITEEVersionIdentifier = { /* 32d71f8e-c1f5-41cb-88cc-4e8504cabf40 */
47+
0x32d71f8e,
48+
0xc1f5,
49+
0x41cb,
50+
{0x88, 0xcc, 0x4e, 0x85, 0x04, 0xca, 0xbf, 0x40}
5151
};
5252

5353
//////////////////////////////////////////////////////////////////////////////////////////////////////////

src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,10 +1666,11 @@ JITINTERFACE_HRESULT WrapICorJitInfo::getPgoInstrumentationResults(
16661666
ICorJitInfo::PgoInstrumentationSchema** pSchema,
16671667
uint32_t* pCountSchemaItems,
16681668
uint8_t** pInstrumentationData,
1669-
ICorJitInfo::PgoSource* pgoSource)
1669+
ICorJitInfo::PgoSource* pPgoSource,
1670+
bool* pDynamicPgo)
16701671
{
16711672
API_ENTER(getPgoInstrumentationResults);
1672-
JITINTERFACE_HRESULT temp = wrapHnd->getPgoInstrumentationResults(ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pgoSource);
1673+
JITINTERFACE_HRESULT temp = wrapHnd->getPgoInstrumentationResults(ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pPgoSource, pDynamicPgo);
16731674
API_LEAVE(getPgoInstrumentationResults);
16741675
return temp;
16751676
}

src/coreclr/jit/compiler.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2791,11 +2791,13 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
27912791
fgPgoHaveWeights = false;
27922792
fgPgoSynthesized = false;
27932793
fgPgoConsistent = false;
2794+
fgPgoDynamic = false;
27942795

27952796
if (jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT))
27962797
{
2797-
fgPgoQueryResult = info.compCompHnd->getPgoInstrumentationResults(info.compMethodHnd, &fgPgoSchema,
2798-
&fgPgoSchemaCount, &fgPgoData, &fgPgoSource);
2798+
fgPgoQueryResult =
2799+
info.compCompHnd->getPgoInstrumentationResults(info.compMethodHnd, &fgPgoSchema, &fgPgoSchemaCount,
2800+
&fgPgoData, &fgPgoSource, &fgPgoDynamic);
27992801

28002802
// a failed result that also has a non-NULL fgPgoSchema
28012803
// indicates that the ILSize for the method no longer matches
@@ -2818,6 +2820,7 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
28182820
fgPgoData = nullptr;
28192821
fgPgoSchema = nullptr;
28202822
fgPgoDisabled = true;
2823+
fgPgoDynamic = false;
28212824
}
28222825
#ifdef DEBUG
28232826
// Optionally, enable use of profile data for only some methods.

src/coreclr/jit/compiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6285,6 +6285,7 @@ class Compiler
62856285
unsigned fgPgoInlineeNoPgoSingleBlock;
62866286
bool fgPgoHaveWeights;
62876287
bool fgPgoSynthesized;
6288+
bool fgPgoDynamic;
62886289
bool fgPgoConsistent;
62896290

62906291
#ifdef DEBUG

src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4261,7 +4261,7 @@ public static void ComputeJitPgoInstrumentationSchema(Func<object, IntPtr> objec
42614261
}
42624262

42634263
private HRESULT getPgoInstrumentationResults(CORINFO_METHOD_STRUCT_* ftnHnd, ref PgoInstrumentationSchema* pSchema, ref uint countSchemaItems, byte** pInstrumentationData,
4264-
ref PgoSource pPgoSource)
4264+
ref PgoSource pPgoSource, ref bool pDynamicPgo)
42654265
{
42664266
MethodDesc methodDesc = HandleToObject(ftnHnd);
42674267

@@ -4308,6 +4308,7 @@ private HRESULT getPgoInstrumentationResults(CORINFO_METHOD_STRUCT_* ftnHnd, ref
43084308
countSchemaItems = pgoResults.countSchemaItems;
43094309
*pInstrumentationData = pgoResults.pInstrumentationData;
43104310
pPgoSource = PgoSource.Static;
4311+
pDynamicPgo = false;
43114312
return pgoResults.hr;
43124313
}
43134314

src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,12 +2489,12 @@ private static void _reportFatalError(IntPtr thisHandle, IntPtr* ppException, Co
24892489
}
24902490

24912491
[UnmanagedCallersOnly]
2492-
private static HRESULT _getPgoInstrumentationResults(IntPtr thisHandle, IntPtr* ppException, CORINFO_METHOD_STRUCT_* ftnHnd, PgoInstrumentationSchema** pSchema, uint* pCountSchemaItems, byte** pInstrumentationData, PgoSource* pgoSource)
2492+
private static HRESULT _getPgoInstrumentationResults(IntPtr thisHandle, IntPtr* ppException, CORINFO_METHOD_STRUCT_* ftnHnd, PgoInstrumentationSchema** pSchema, uint* pCountSchemaItems, byte** pInstrumentationData, PgoSource* pPgoSource, bool* pDynamicPgo)
24932493
{
24942494
var _this = GetThis(thisHandle);
24952495
try
24962496
{
2497-
return _this.getPgoInstrumentationResults(ftnHnd, ref *pSchema, ref *pCountSchemaItems, pInstrumentationData, ref *pgoSource);
2497+
return _this.getPgoInstrumentationResults(ftnHnd, ref *pSchema, ref *pCountSchemaItems, pInstrumentationData, ref *pPgoSource, ref *pDynamicPgo);
24982498
}
24992499
catch (Exception ex)
25002500
{
@@ -2764,7 +2764,7 @@ private static IntPtr GetUnmanagedCallbacks()
27642764
callbacks[165] = (delegate* unmanaged<IntPtr, IntPtr*, uint, byte*, IntPtr, byte>)&_logMsg;
27652765
callbacks[166] = (delegate* unmanaged<IntPtr, IntPtr*, byte*, int, byte*, int>)&_doAssert;
27662766
callbacks[167] = (delegate* unmanaged<IntPtr, IntPtr*, CorJitResult, void>)&_reportFatalError;
2767-
callbacks[168] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_METHOD_STRUCT_*, PgoInstrumentationSchema**, uint*, byte**, PgoSource*, HRESULT>)&_getPgoInstrumentationResults;
2767+
callbacks[168] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_METHOD_STRUCT_*, PgoInstrumentationSchema**, uint*, byte**, PgoSource*, bool*, HRESULT>)&_getPgoInstrumentationResults;
27682768
callbacks[169] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_METHOD_STRUCT_*, PgoInstrumentationSchema*, uint, byte**, HRESULT>)&_allocPgoInstrumentationBySchema;
27692769
callbacks[170] = (delegate* unmanaged<IntPtr, IntPtr*, uint, CORINFO_SIG_INFO*, CORINFO_METHOD_STRUCT_*, void>)&_recordCallSite;
27702770
callbacks[171] = (delegate* unmanaged<IntPtr, IntPtr*, void*, void*, void*, ushort, int, void>)&_recordRelocation;

src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ FUNCTIONS
331331
bool logMsg(unsigned level, const char* fmt, va_list args)
332332
int doAssert(const char* szFile, int iLine, const char* szExpr)
333333
void reportFatalError(CorJitResult result)
334-
JITINTERFACE_HRESULT getPgoInstrumentationResults(CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema** pSchema, uint32_t* pCountSchemaItems, uint8_t**pInstrumentationData, ICorJitInfo::PgoSource* pgoSource)
334+
JITINTERFACE_HRESULT getPgoInstrumentationResults(CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema** pSchema, uint32_t* pCountSchemaItems, uint8_t**pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource, bool* pDynamicPgo)
335335
JITINTERFACE_HRESULT allocPgoInstrumentationBySchema(CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema* pSchema, uint32_t countSchemaItems, uint8_t** pInstrumentationData)
336336
void recordCallSite(uint32_t instrOffset, CORINFO_SIG_INFO* callSig, CORINFO_METHOD_HANDLE methodHandle)
337337
void recordRelocation(void* location, void* locationRW, void* target, uint16_t fRelocType, int32_t addlDelta)

src/coreclr/tools/aot/jitinterface/jitinterface_generated.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ struct JitInterfaceCallbacks
179179
bool (* logMsg)(void * thisHandle, CorInfoExceptionClass** ppException, unsigned level, const char* fmt, va_list args);
180180
int (* doAssert)(void * thisHandle, CorInfoExceptionClass** ppException, const char* szFile, int iLine, const char* szExpr);
181181
void (* reportFatalError)(void * thisHandle, CorInfoExceptionClass** ppException, CorJitResult result);
182-
JITINTERFACE_HRESULT (* getPgoInstrumentationResults)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema** pSchema, uint32_t* pCountSchemaItems, uint8_t** pInstrumentationData, ICorJitInfo::PgoSource* pgoSource);
182+
JITINTERFACE_HRESULT (* getPgoInstrumentationResults)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema** pSchema, uint32_t* pCountSchemaItems, uint8_t** pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource, bool* pDynamicPgo);
183183
JITINTERFACE_HRESULT (* allocPgoInstrumentationBySchema)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema* pSchema, uint32_t countSchemaItems, uint8_t** pInstrumentationData);
184184
void (* recordCallSite)(void * thisHandle, CorInfoExceptionClass** ppException, uint32_t instrOffset, CORINFO_SIG_INFO* callSig, CORINFO_METHOD_HANDLE methodHandle);
185185
void (* recordRelocation)(void * thisHandle, CorInfoExceptionClass** ppException, void* location, void* locationRW, void* target, uint16_t fRelocType, int32_t addlDelta);
@@ -1843,10 +1843,11 @@ class JitInterfaceWrapper : public ICorJitInfo
18431843
ICorJitInfo::PgoInstrumentationSchema** pSchema,
18441844
uint32_t* pCountSchemaItems,
18451845
uint8_t** pInstrumentationData,
1846-
ICorJitInfo::PgoSource* pgoSource)
1846+
ICorJitInfo::PgoSource* pPgoSource,
1847+
bool* pDynamicPgo)
18471848
{
18481849
CorInfoExceptionClass* pException = nullptr;
1849-
JITINTERFACE_HRESULT temp = _callbacks->getPgoInstrumentationResults(_thisHandle, &pException, ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pgoSource);
1850+
JITINTERFACE_HRESULT temp = _callbacks->getPgoInstrumentationResults(_thisHandle, &pException, ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pPgoSource, pDynamicPgo);
18501851
if (pException != nullptr) throw pException;
18511852
return temp;
18521853
}

0 commit comments

Comments
 (0)