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

Fixes for text-based PGO #56986

Merged
merged 2 commits into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 3 additions & 0 deletions src/coreclr/jit/fgprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,9 @@ PhaseStatus Compiler::fgIncorporateProfileData()
break;

default:
JITDUMP("Unknown PGO record type 0x%x in schema entry %u (offset 0x%x count 0x%x other 0x%x)\n",
fgPgoSchema[iSchema].InstrumentationKind, iSchema, fgPgoSchema[iSchema].ILOffset,
fgPgoSchema[iSchema].Count, fgPgoSchema[iSchema].Other);
otherRecords++;
break;
}
Expand Down
6 changes: 4 additions & 2 deletions src/coreclr/jit/inlinepolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,8 @@ void ExtendedDefaultPolicy::NoteInt(InlineObservation obs, int value)
unsigned maxCodeSize = static_cast<unsigned>(JitConfig.JitExtDefaultPolicyMaxIL());

// TODO: Enable for PgoSource::Static as well if it's not the generic profile we bundle.
if (m_HasProfile && (m_RootCompiler->fgPgoSource == ICorJitInfo::PgoSource::Dynamic))
if (m_HasProfile && ((m_RootCompiler->fgPgoSource == ICorJitInfo::PgoSource::Dynamic) ||
(m_RootCompiler->fgPgoSource == ICorJitInfo::PgoSource::Text)))
{
maxCodeSize = static_cast<unsigned>(JitConfig.JitExtDefaultPolicyMaxILProf());
}
Expand Down Expand Up @@ -1684,7 +1685,8 @@ double ExtendedDefaultPolicy::DetermineMultiplier()
const double profileTrustCoef = (double)JitConfig.JitExtDefaultPolicyProfTrust() / 10.0;
const double profileScale = (double)JitConfig.JitExtDefaultPolicyProfScale() / 10.0;

if (m_RootCompiler->fgPgoSource == ICorJitInfo::PgoSource::Dynamic)
if ((m_RootCompiler->fgPgoSource == ICorJitInfo::PgoSource::Dynamic) ||
(m_RootCompiler->fgPgoSource == ICorJitInfo::PgoSource::Text))
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a IsPgoSourceTrustworthy (or similar) function for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, seems like a good idea.

{
// For now we only "trust" dynamic profiles.
multiplier *= (1.0 - profileTrustCoef) + min(m_ProfileFrequency, 1.0) * profileScale;
Expand Down
42 changes: 25 additions & 17 deletions src/coreclr/vm/pgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,24 +718,11 @@ HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, BYTE** pAlloca
*pCountSchemaItems = 0;
*pPgoSource = ICorJitInfo::PgoSource::Unknown;

PgoManager *mgr;
if (!pMD->IsDynamicMethod())
{
mgr = pMD->GetLoaderAllocator()->GetPgoManager();
}
else
{
mgr = pMD->AsDynamicMethodDesc()->GetResolver()->GetDynamicPgoManager();
}

HRESULT hr = E_NOTIMPL;
if (mgr != NULL)
{
hr = mgr->getPgoInstrumentationResultsInstance(pMD, pAllocatedData, ppSchema, pCountSchemaItems, pInstrumentationData, pPgoSource);
}

// If not found in the data from the current run, look in the data from the text file
if (FAILED(hr) && s_textFormatPgoData.GetCount() > 0)
// If there is text format PGO data, prefer that over any dynamic or static data.
//
if (s_textFormatPgoData.GetCount() > 0)
{
COUNT_T methodhash = pMD->GetStableHash();
int codehash;
Expand Down Expand Up @@ -796,11 +783,12 @@ HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, BYTE** pAlloca
*pAllocatedData = new BYTE[schemaArray.GetCount() * sizeof(ICorJitInfo::PgoInstrumentationSchema)];
memcpy(*pAllocatedData, schemaArray.OpenRawBuffer(), schemaArray.GetCount() * sizeof(ICorJitInfo::PgoInstrumentationSchema));
schemaArray.CloseRawBuffer();
*ppSchema = (ICorJitInfo::PgoInstrumentationSchema*)pAllocatedData;
*ppSchema = (ICorJitInfo::PgoInstrumentationSchema*)*pAllocatedData;

*pCountSchemaItems = schemaArray.GetCount();
*pInstrumentationData = found->GetData();
*pPgoSource = ICorJitInfo::PgoSource::Text;

hr = S_OK;
}
EX_CATCH
Expand All @@ -818,6 +806,26 @@ HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, BYTE** pAlloca
}
}

// If we didn't find any text format data, look for dynamic or static data.
//
if (FAILED(hr))
{
PgoManager *mgr;
if (!pMD->IsDynamicMethod())
{
mgr = pMD->GetLoaderAllocator()->GetPgoManager();
}
else
{
mgr = pMD->AsDynamicMethodDesc()->GetResolver()->GetDynamicPgoManager();
}

if (mgr != NULL)
{
hr = mgr->getPgoInstrumentationResultsInstance(pMD, pAllocatedData, ppSchema, pCountSchemaItems, pInstrumentationData, pPgoSource);
}
}

return hr;
}

Expand Down