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

Allow JIT to know if dynamic pgo is active #101575

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/coreclr/inc/corjit.h
Original file line number Diff line number Diff line change
@@ -452,7 +452,8 @@ class ICorJitInfo : public ICorDynamicInfo
uint32_t * pCountSchemaItems, // OUT: pointer to the count of schema items in `pSchema` array.
uint8_t ** pInstrumentationData, // OUT: `*pInstrumentationData` is set to the address of the instrumentation data
// (pointer will not remain valid after jit completes).
PgoSource * pPgoSource // OUT: value describing source of pgo data
PgoSource * pPgoSource, // OUT: value describing source of pgo data
bool * pDynamicPgo // OUT: dynamic PGO is enabled (valid even when return value is failure)
) = 0;

// Allocate a profile buffer for use in the current process
3 changes: 2 additions & 1 deletion src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
@@ -711,7 +711,8 @@ JITINTERFACE_HRESULT getPgoInstrumentationResults(
ICorJitInfo::PgoInstrumentationSchema** pSchema,
uint32_t* pCountSchemaItems,
uint8_t** pInstrumentationData,
ICorJitInfo::PgoSource* pgoSource) override;
ICorJitInfo::PgoSource* pPgoSource,
bool* pDynamicPgo) override;

JITINTERFACE_HRESULT allocPgoInstrumentationBySchema(
CORINFO_METHOD_HANDLE ftnHnd,
10 changes: 5 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
@@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
#define GUID_DEFINED
#endif // !GUID_DEFINED

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

//////////////////////////////////////////////////////////////////////////////////////////////////////////
5 changes: 3 additions & 2 deletions src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp
Original file line number Diff line number Diff line change
@@ -1666,10 +1666,11 @@ JITINTERFACE_HRESULT WrapICorJitInfo::getPgoInstrumentationResults(
ICorJitInfo::PgoInstrumentationSchema** pSchema,
uint32_t* pCountSchemaItems,
uint8_t** pInstrumentationData,
ICorJitInfo::PgoSource* pgoSource)
ICorJitInfo::PgoSource* pPgoSource,
bool* pDynamicPgo)
{
API_ENTER(getPgoInstrumentationResults);
JITINTERFACE_HRESULT temp = wrapHnd->getPgoInstrumentationResults(ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pgoSource);
JITINTERFACE_HRESULT temp = wrapHnd->getPgoInstrumentationResults(ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pPgoSource, pDynamicPgo);
API_LEAVE(getPgoInstrumentationResults);
return temp;
}
7 changes: 5 additions & 2 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
@@ -2791,11 +2791,13 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
fgPgoHaveWeights = false;
fgPgoSynthesized = false;
fgPgoConsistent = false;
fgPgoDynamic = false;

if (jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT))
{
fgPgoQueryResult = info.compCompHnd->getPgoInstrumentationResults(info.compMethodHnd, &fgPgoSchema,
&fgPgoSchemaCount, &fgPgoData, &fgPgoSource);
fgPgoQueryResult =
info.compCompHnd->getPgoInstrumentationResults(info.compMethodHnd, &fgPgoSchema, &fgPgoSchemaCount,
&fgPgoData, &fgPgoSource, &fgPgoDynamic);

// a failed result that also has a non-NULL fgPgoSchema
// indicates that the ILSize for the method no longer matches
@@ -2818,6 +2820,7 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
fgPgoData = nullptr;
fgPgoSchema = nullptr;
fgPgoDisabled = true;
fgPgoDynamic = false;
}
#ifdef DEBUG
// Optionally, enable use of profile data for only some methods.
1 change: 1 addition & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
@@ -6285,6 +6285,7 @@ class Compiler
unsigned fgPgoInlineeNoPgoSingleBlock;
bool fgPgoHaveWeights;
bool fgPgoSynthesized;
bool fgPgoDynamic;
bool fgPgoConsistent;

#ifdef DEBUG
3 changes: 2 additions & 1 deletion src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
@@ -4260,7 +4260,7 @@ public static void ComputeJitPgoInstrumentationSchema(Func<object, IntPtr> objec
}

private HRESULT getPgoInstrumentationResults(CORINFO_METHOD_STRUCT_* ftnHnd, ref PgoInstrumentationSchema* pSchema, ref uint countSchemaItems, byte** pInstrumentationData,
ref PgoSource pPgoSource)
ref PgoSource pPgoSource, ref bool pDynamicPgo)
{
MethodDesc methodDesc = HandleToObject(ftnHnd);

@@ -4307,6 +4307,7 @@ private HRESULT getPgoInstrumentationResults(CORINFO_METHOD_STRUCT_* ftnHnd, ref
countSchemaItems = pgoResults.countSchemaItems;
*pInstrumentationData = pgoResults.pInstrumentationData;
pPgoSource = PgoSource.Static;
pDynamicPgo = false;
return pgoResults.hr;
}

Original file line number Diff line number Diff line change
@@ -2489,12 +2489,12 @@ private static void _reportFatalError(IntPtr thisHandle, IntPtr* ppException, Co
}

[UnmanagedCallersOnly]
private static HRESULT _getPgoInstrumentationResults(IntPtr thisHandle, IntPtr* ppException, CORINFO_METHOD_STRUCT_* ftnHnd, PgoInstrumentationSchema** pSchema, uint* pCountSchemaItems, byte** pInstrumentationData, PgoSource* pgoSource)
private static HRESULT _getPgoInstrumentationResults(IntPtr thisHandle, IntPtr* ppException, CORINFO_METHOD_STRUCT_* ftnHnd, PgoInstrumentationSchema** pSchema, uint* pCountSchemaItems, byte** pInstrumentationData, PgoSource* pPgoSource, bool* pDynamicPgo)
{
var _this = GetThis(thisHandle);
try
{
return _this.getPgoInstrumentationResults(ftnHnd, ref *pSchema, ref *pCountSchemaItems, pInstrumentationData, ref *pgoSource);
return _this.getPgoInstrumentationResults(ftnHnd, ref *pSchema, ref *pCountSchemaItems, pInstrumentationData, ref *pPgoSource, ref *pDynamicPgo);
}
catch (Exception ex)
{
@@ -2764,7 +2764,7 @@ private static IntPtr GetUnmanagedCallbacks()
callbacks[165] = (delegate* unmanaged<IntPtr, IntPtr*, uint, byte*, IntPtr, byte>)&_logMsg;
callbacks[166] = (delegate* unmanaged<IntPtr, IntPtr*, byte*, int, byte*, int>)&_doAssert;
callbacks[167] = (delegate* unmanaged<IntPtr, IntPtr*, CorJitResult, void>)&_reportFatalError;
callbacks[168] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_METHOD_STRUCT_*, PgoInstrumentationSchema**, uint*, byte**, PgoSource*, HRESULT>)&_getPgoInstrumentationResults;
callbacks[168] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_METHOD_STRUCT_*, PgoInstrumentationSchema**, uint*, byte**, PgoSource*, bool*, HRESULT>)&_getPgoInstrumentationResults;
callbacks[169] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_METHOD_STRUCT_*, PgoInstrumentationSchema*, uint, byte**, HRESULT>)&_allocPgoInstrumentationBySchema;
callbacks[170] = (delegate* unmanaged<IntPtr, IntPtr*, uint, CORINFO_SIG_INFO*, CORINFO_METHOD_STRUCT_*, void>)&_recordCallSite;
callbacks[171] = (delegate* unmanaged<IntPtr, IntPtr*, void*, void*, void*, ushort, int, void>)&_recordRelocation;
Original file line number Diff line number Diff line change
@@ -331,7 +331,7 @@ FUNCTIONS
bool logMsg(unsigned level, const char* fmt, va_list args)
int doAssert(const char* szFile, int iLine, const char* szExpr)
void reportFatalError(CorJitResult result)
JITINTERFACE_HRESULT getPgoInstrumentationResults(CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema** pSchema, uint32_t* pCountSchemaItems, uint8_t**pInstrumentationData, ICorJitInfo::PgoSource* pgoSource)
JITINTERFACE_HRESULT getPgoInstrumentationResults(CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema** pSchema, uint32_t* pCountSchemaItems, uint8_t**pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource, bool* pDynamicPgo)
JITINTERFACE_HRESULT allocPgoInstrumentationBySchema(CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema* pSchema, uint32_t countSchemaItems, uint8_t** pInstrumentationData)
void recordCallSite(uint32_t instrOffset, CORINFO_SIG_INFO* callSig, CORINFO_METHOD_HANDLE methodHandle)
void recordRelocation(void* location, void* locationRW, void* target, uint16_t fRelocType, int32_t addlDelta)
7 changes: 4 additions & 3 deletions src/coreclr/tools/aot/jitinterface/jitinterface_generated.h
Original file line number Diff line number Diff line change
@@ -179,7 +179,7 @@ struct JitInterfaceCallbacks
bool (* logMsg)(void * thisHandle, CorInfoExceptionClass** ppException, unsigned level, const char* fmt, va_list args);
int (* doAssert)(void * thisHandle, CorInfoExceptionClass** ppException, const char* szFile, int iLine, const char* szExpr);
void (* reportFatalError)(void * thisHandle, CorInfoExceptionClass** ppException, CorJitResult result);
JITINTERFACE_HRESULT (* getPgoInstrumentationResults)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema** pSchema, uint32_t* pCountSchemaItems, uint8_t** pInstrumentationData, ICorJitInfo::PgoSource* pgoSource);
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);
JITINTERFACE_HRESULT (* allocPgoInstrumentationBySchema)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema* pSchema, uint32_t countSchemaItems, uint8_t** pInstrumentationData);
void (* recordCallSite)(void * thisHandle, CorInfoExceptionClass** ppException, uint32_t instrOffset, CORINFO_SIG_INFO* callSig, CORINFO_METHOD_HANDLE methodHandle);
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
ICorJitInfo::PgoInstrumentationSchema** pSchema,
uint32_t* pCountSchemaItems,
uint8_t** pInstrumentationData,
ICorJitInfo::PgoSource* pgoSource)
ICorJitInfo::PgoSource* pPgoSource,
bool* pDynamicPgo)
{
CorInfoExceptionClass* pException = nullptr;
JITINTERFACE_HRESULT temp = _callbacks->getPgoInstrumentationResults(_thisHandle, &pException, ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pgoSource);
JITINTERFACE_HRESULT temp = _callbacks->getPgoInstrumentationResults(_thisHandle, &pException, ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pPgoSource, pDynamicPgo);
if (pException != nullptr) throw pException;
return temp;
}
1 change: 1 addition & 0 deletions src/coreclr/tools/superpmi/superpmi-shared/agnostic.h
Original file line number Diff line number Diff line change
@@ -519,6 +519,7 @@ struct Agnostic_GetPgoInstrumentationResults
DWORD dataByteCount;
DWORD result;
DWORD pgoSource;
DWORD dynamicPgo;
};

struct Agnostic_GetProfilingHandle
16 changes: 11 additions & 5 deletions src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp
Original file line number Diff line number Diff line change
@@ -5724,6 +5724,7 @@ void MethodContext::recGetPgoInstrumentationResults(CORINFO_METHOD_HANDLE ftnHnd
UINT32* pCountSchemaItems,
BYTE** pInstrumentationData,
ICorJitInfo::PgoSource* pPgoSource,
bool* pDynamicPgo,
HRESULT result)
{
if (GetPgoInstrumentationResults == nullptr)
@@ -5754,15 +5755,16 @@ void MethodContext::recGetPgoInstrumentationResults(CORINFO_METHOD_HANDLE ftnHnd
value.dataByteCount = (unsigned)maxOffset;
value.result = (DWORD)result;
value.pgoSource = (DWORD)*pPgoSource;
value.dynamicPgo = (DWORD)*pDynamicPgo;

DWORDLONG key = CastHandle(ftnHnd);
GetPgoInstrumentationResults->Add(key, value);
DEBUG_REC(dmpGetPgoInstrumentationResults(key, value));
}
void MethodContext::dmpGetPgoInstrumentationResults(DWORDLONG key, const Agnostic_GetPgoInstrumentationResults& value)
{
printf("GetPgoInstrumentationResults key ftn-%016" PRIX64 ", value res-%08X schemaCnt-%u profileBufSize-%u source-%u schema{",
key, value.result, value.countSchemaItems, value.dataByteCount, value.pgoSource);
printf("GetPgoInstrumentationResults key ftn-%016" PRIX64 ", value res-%08X schemaCnt-%u profileBufSize-%u source-%u dynamic-%u schema{",
key, value.result, value.countSchemaItems, value.dataByteCount, value.pgoSource, value.dynamicPgo);

if (value.countSchemaItems > 0)
{
@@ -5838,7 +5840,8 @@ HRESULT MethodContext::repGetPgoInstrumentationResults(CORINFO_METHOD_HANDLE ftn
ICorJitInfo::PgoInstrumentationSchema** pSchema,
UINT32* pCountSchemaItems,
BYTE** pInstrumentationData,
ICorJitInfo::PgoSource* pPgoSource)
ICorJitInfo::PgoSource* pPgoSource,
bool* pDynamicPgo)
{
DWORDLONG key = CastHandle(ftnHnd);
Agnostic_GetPgoInstrumentationResults tempValue = LookupByKeyOrMiss(GetPgoInstrumentationResults, key, ": key %016" PRIX64 "", key);
@@ -5848,6 +5851,7 @@ HRESULT MethodContext::repGetPgoInstrumentationResults(CORINFO_METHOD_HANDLE ftn
*pCountSchemaItems = (UINT32)tempValue.countSchemaItems;
*pInstrumentationData = (BYTE*)GetPgoInstrumentationResults->GetBuffer(tempValue.data_index);
*pPgoSource = (ICorJitInfo::PgoSource)tempValue.pgoSource;
*pDynamicPgo = (bool)tempValue.dynamicPgo;

ICorJitInfo::PgoInstrumentationSchema* pOutSchema = (ICorJitInfo::PgoInstrumentationSchema*)AllocJitTempBuffer(tempValue.countSchemaItems * sizeof(ICorJitInfo::PgoInstrumentationSchema));

@@ -7183,7 +7187,8 @@ int MethodContext::dumpMethodIdentityInfoToBuffer(char* buff, int len, bool igno
UINT32 schemaCount = 0;
BYTE* schemaData = nullptr;
ICorJitInfo::PgoSource pgoSource = ICorJitInfo::PgoSource::Unknown;
HRESULT pgoHR = repGetPgoInstrumentationResults(pInfo->ftn, &schema, &schemaCount, &schemaData, &pgoSource);
bool dynamicPgo = false;
HRESULT pgoHR = repGetPgoInstrumentationResults(pInfo->ftn, &schema, &schemaCount, &schemaData, &pgoSource, &dynamicPgo);

size_t minOffset = (size_t) ~0;
size_t maxOffset = 0;
@@ -7281,7 +7286,8 @@ bool MethodContext::hasPgoData(bool& hasEdgeProfile, bool& hasClassProfile, bool
ICorJitInfo::PgoInstrumentationSchema* schema = nullptr;
UINT32 schemaCount = 0;
BYTE* schemaData = nullptr;
HRESULT pgoHR = repGetPgoInstrumentationResults(info.ftn, &schema, &schemaCount, &schemaData, &pgoSource);
bool dynamicPgo;
HRESULT pgoHR = repGetPgoInstrumentationResults(info.ftn, &schema, &schemaCount, &schemaData, &pgoSource, &dynamicPgo);

if (SUCCEEDED(pgoHR))
{
4 changes: 2 additions & 2 deletions src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h
Original file line number Diff line number Diff line change
@@ -711,9 +711,9 @@ class MethodContext
HRESULT repAllocPgoInstrumentationBySchema(CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema* pSchema, UINT32 countSchemaItems, BYTE** pInstrumentationData);
bool repAllocPgoInstrumentationBySchemaRecorded(CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema* pSchema, UINT32 countSchemaItems, BYTE** pInstrumentationData);

void recGetPgoInstrumentationResults(CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema** pSchema, UINT32* pCountSchemaItems, BYTE** pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource, HRESULT result);
void recGetPgoInstrumentationResults(CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema** pSchema, UINT32* pCountSchemaItems, BYTE** pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource, bool* pDynamicPgo, HRESULT result);
void dmpGetPgoInstrumentationResults(DWORDLONG key, const Agnostic_GetPgoInstrumentationResults& value);
HRESULT repGetPgoInstrumentationResults(CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema** pSchema, UINT32* pCountSchemaItems, BYTE** pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource);
HRESULT repGetPgoInstrumentationResults(CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema** pSchema, UINT32* pCountSchemaItems, BYTE** pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource, bool* pDynamicPgo);

void recIsMoreSpecificType(CORINFO_CLASS_HANDLE cls1, CORINFO_CLASS_HANDLE cls2, bool result);
void dmpIsMoreSpecificType(DLDL key, DWORD value);
Original file line number Diff line number Diff line change
@@ -1947,11 +1947,12 @@ HRESULT interceptor_ICJI::getPgoInstrumentationResults(CORINFO_METHOD_HANDLE
PgoInstrumentationSchema **pSchema, // pointer to the schema table which describes the instrumentation results (pointer will not remain valid after jit completes)
uint32_t * pCountSchemaItems, // pointer to the count schema items
uint8_t ** pInstrumentationData, // pointer to the actual instrumentation data (pointer will not remain valid after jit completes)
PgoSource* pPgoSource)
PgoSource* pPgoSource,
bool* pDynamicPgo)
{
mc->cr->AddCall("getPgoInstrumentationResults");
HRESULT temp = original_ICorJitInfo->getPgoInstrumentationResults(ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pPgoSource);
mc->recGetPgoInstrumentationResults(ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pPgoSource, temp);
HRESULT temp = original_ICorJitInfo->getPgoInstrumentationResults(ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pPgoSource, pDynamicPgo);
mc->recGetPgoInstrumentationResults(ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pPgoSource, pDynamicPgo, temp);
return temp;
}

Original file line number Diff line number Diff line change
@@ -1374,10 +1374,11 @@ JITINTERFACE_HRESULT interceptor_ICJI::getPgoInstrumentationResults(
ICorJitInfo::PgoInstrumentationSchema** pSchema,
uint32_t* pCountSchemaItems,
uint8_t** pInstrumentationData,
ICorJitInfo::PgoSource* pgoSource)
ICorJitInfo::PgoSource* pPgoSource,
bool* pDynamicPgo)
{
mcs->AddCall("getPgoInstrumentationResults");
return original_ICorJitInfo->getPgoInstrumentationResults(ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pgoSource);
return original_ICorJitInfo->getPgoInstrumentationResults(ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pPgoSource, pDynamicPgo);
}

JITINTERFACE_HRESULT interceptor_ICJI::allocPgoInstrumentationBySchema(
Original file line number Diff line number Diff line change
@@ -1206,9 +1206,10 @@ JITINTERFACE_HRESULT interceptor_ICJI::getPgoInstrumentationResults(
ICorJitInfo::PgoInstrumentationSchema** pSchema,
uint32_t* pCountSchemaItems,
uint8_t** pInstrumentationData,
ICorJitInfo::PgoSource* pgoSource)
ICorJitInfo::PgoSource* pPgoSource,
bool* pDynamicPgo)
{
return original_ICorJitInfo->getPgoInstrumentationResults(ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pgoSource);
return original_ICorJitInfo->getPgoInstrumentationResults(ftnHnd, pSchema, pCountSchemaItems, pInstrumentationData, pPgoSource, pDynamicPgo);
}

JITINTERFACE_HRESULT interceptor_ICJI::allocPgoInstrumentationBySchema(
Loading