Skip to content

Commit

Permalink
Enable DotNETRuntimePrivate provider (#93245)
Browse files Browse the repository at this point in the history
* Enable dotnruntimeprivate provider

* Linux fix

* private provider fix

* cleaning up the event list

* release build fix

* Update src/coreclr/scripts/genEventing.py

Co-authored-by: Elinor Fung <[email protected]>

* FB

---------

Co-authored-by: Elinor Fung <[email protected]>
  • Loading branch information
LakshanF and elinor-fung authored Oct 11, 2023
1 parent 604b38d commit 791e7a4
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 50 deletions.
36 changes: 33 additions & 3 deletions src/coreclr/nativeaot/Runtime/eventpipe/gen-eventing-event-inc.lst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

BGC1stConEnd
BGC1stNonConEnd
BGC1stSweepEnd
BGC2ndConBegin
BGC2ndConEnd
BGC2ndNonConBegin
Expand All @@ -10,14 +11,26 @@ BGCAllocWaitBegin
BGCAllocWaitEnd
BGCBegin
BGCDrainMark
BGCOverflow
BGCOverflow_V1
BGCPlanEnd
BGCRevisit
BGCSweepEnd
Contention
ContentionLockCreated
ContentionStart_V2
ContentionStop_V1
DecreaseMemoryPressure
DestroyGCHandle
ExceptionCatchStart
ExceptionCatchStop
ExceptionFilterStart
ExceptionFilterStop
ExceptionFinallyStart
ExceptionFinallyStop
ExceptionThrown_V1
ExceptionThrownStop
ExecutionCheckpoint
FailFast
FinalizeObject
GCAllocationTick_V4
GCBulkEdge
Expand All @@ -31,15 +44,16 @@ GCBulkRootStaticVar
GCBulkSurvivingObjectRanges
GCCreateConcurrentThread_V1
GCCreateSegment_V1
GCDecision_V1
GCEnd_V1
GCFinalizersBegin_V1
GCFinalizersEnd_V1
GCFitBucketInfo
GCFreeSegment_V1
GCFullNotify_V1
GCGenerationRange
GCGlobalHeapHistory
GCGlobalHeapHistory_V4
GCHeapStats_V1
GCHeapStats_V2
GCJoin_V2
GCLOHCompact
Expand All @@ -48,12 +62,13 @@ GCMarkHandles
GCMarkOlderGenerationRoots
GCMarkStackRoots
GCMarkWithType
GCOptimized_V1
GCPerHeapHistory_V3
GCRestartEEBegin_V1
GCRestartEEEnd_V1
GCSampledObjectAllocationHigh
GCSampledObjectAllocationLow
GCSettings
GCSettings_V1
GCStart_V2
GCSuspendEEBegin_V1
GCSuspendEEEnd_V1
Expand All @@ -62,20 +77,35 @@ GCTriggered
GenAwareBegin
GenAwareEnd
IncreaseMemoryPressure
LockCreated
ModuleLoad_V2
PinObjectAtGCTime
PinPlugAtGCTime
PrvDestroyGCHandle
PrvFinalizeObject
PrvGCMarkCards_V1
PrvGCMarkFinalizeQueueRoots_V1
PrvGCMarkHandles_V1
PrvGCMarkStackRoots_V1
PrvSetGCHandle
SetGCHandle
ThreadCreated
ThreadCreating
ThreadPoolDequeue
ThreadPoolEnqueue
ThreadPoolIODequeue
ThreadPoolIOEnqueue
ThreadPoolIOPack
ThreadPoolMinMaxThreads
ThreadpoolSuspensionResumeThread
ThreadpoolSuspensionSuspendThread
ThreadPoolWorkerThreadAdjustmentAdjustment
ThreadPoolWorkerThreadAdjustmentSample
ThreadPoolWorkerThreadAdjustmentStats
ThreadPoolWorkerThreadRetirementStart
ThreadPoolWorkerThreadRetirementStop
ThreadPoolWorkerThreadStart
ThreadPoolWorkerThreadStop
ThreadPoolWorkerThreadWait
ThreadPoolWorkingThreadCount
ThreadRunning
19 changes: 17 additions & 2 deletions src/coreclr/nativeaot/Runtime/eventtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ void EtwCallbackCommon(
case DotNETRuntime:
ctxToUpdate = &MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_DOTNET_Context;
break;
case DotNETRuntimePrivate:
ctxToUpdate = &MICROSOFT_WINDOWS_DOTNETRUNTIME_PRIVATE_PROVIDER_DOTNET_Context;
break;
default:
_ASSERTE(!"EtwCallbackCommon was called with invalid context");
return;
Expand Down Expand Up @@ -212,9 +215,9 @@ void EtwCallback(
(context->RegistrationHandle == Microsoft_Windows_DotNETRuntimePrivateHandle) &&
GCHeapUtilities::IsGCHeapInitialized())
{
FireEtwGCSettings(GCHeapUtilities::GetGCHeap()->GetValidSegmentSize(FALSE),
FireEtwGCSettings_V1(GCHeapUtilities::GetGCHeap()->GetValidSegmentSize(FALSE),
GCHeapUtilities::GetGCHeap()->GetValidSegmentSize(TRUE),
GCHeapUtilities::IsServerHeap());
GCHeapUtilities::IsServerHeap(), GetClrInstanceId());
GCHeapUtilities::GetGCHeap()->DiagTraceGCSegments();
}
}
Expand All @@ -231,3 +234,15 @@ void EventPipeEtwCallbackDotNETRuntime(
{
EtwCallbackCommon(DotNETRuntime, ControlCode, Level, MatchAnyKeyword, FilterData, /*isEventPipeCallback*/ true);
}

void EventPipeEtwCallbackDotNETRuntimePrivate(
_In_ GUID * SourceId,
_In_ ULONG ControlCode,
_In_ unsigned char Level,
_In_ ULONGLONG MatchAnyKeyword,
_In_ ULONGLONG MatchAllKeyword,
_In_opt_ EventFilterDescriptor* FilterData,
_Inout_opt_ PVOID CallbackContext)
{
EtwCallbackCommon(DotNETRuntimePrivate, ControlCode, Level, MatchAnyKeyword, FilterData, true);
}
9 changes: 9 additions & 0 deletions src/coreclr/nativeaot/Runtime/eventtrace_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,14 @@ void EventPipeEtwCallbackDotNETRuntime(
_In_opt_ EventFilterDescriptor* FilterData,
_Inout_opt_ PVOID CallbackContext);

void EventPipeEtwCallbackDotNETRuntimePrivate(
_In_ GUID * SourceId,
_In_ ULONG ControlCode,
_In_ unsigned char Level,
_In_ ULONGLONG MatchAnyKeyword,
_In_ ULONGLONG MatchAllKeyword,
_In_opt_ EventFilterDescriptor* FilterData,
_Inout_opt_ PVOID CallbackContext);

#endif // FEATURE_EVENT_TRACE
#endif // EVENTTRACE_CONTEXT_H
4 changes: 2 additions & 2 deletions src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ void GCToCLREventSink::FireBGCRevisit(uint64_t pages, uint64_t objects, uint32_t

void GCToCLREventSink::FireBGCOverflow_V1(uint64_t min, uint64_t max, uint64_t objects, uint32_t isLarge, uint32_t genNumber)
{
// TODO: FireBGCOverflow_V1
FireEtwBGCOverflow(min, max, objects, isLarge, GetClrInstanceId());
FireEtwBGCOverflow_V1(min, max, objects, isLarge, GetClrInstanceId(), genNumber);

}

void GCToCLREventSink::FireBGCAllocWaitBegin(uint32_t reason)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/scripts/genEventPipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ def generateEventPipeImplFiles(
eventpipeImpl.write(getCoreCLREventPipeImplFileSuffix())
elif runtimeFlavor.mono:
eventpipeImpl.write(getMonoEventPipeImplFileSuffix())
elif runtimeFlavor.nativeaot:
elif runtimeFlavor.nativeaot and providerName=="Microsoft-Windows-DotNETRuntime":
eventpipeImpl.write(getAotEventPipeImplFileSuffix())

def generateEventPipeFiles(
Expand Down
53 changes: 12 additions & 41 deletions src/coreclr/scripts/genEventing.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def getPalDataTypeMapping(runtimeFlavor):
def includeProvider(providerName, runtimeFlavor):
if (runtimeFlavor.coreclr or runtimeFlavor.nativeaot) and providerName == "Microsoft-DotNETRuntimeMonoProfiler":
return False
elif runtimeFlavor.nativeaot and (providerName == "Microsoft-Windows-DotNETRuntimeRundown" or providerName == "Microsoft-Windows-DotNETRuntimeStress" or providerName == "Microsoft-Windows-DotNETRuntimePrivate"):
elif runtimeFlavor.nativeaot and (providerName == "Microsoft-Windows-DotNETRuntimeRundown" or providerName == "Microsoft-Windows-DotNETRuntimeStress"):
return False
else:
return True
Expand Down Expand Up @@ -455,18 +455,12 @@ def generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, wr
#generate FireEtw functions
fnptype = []
fnbody = []
# native AOT vars that ifdef's on Etw for the clretwallmainHeader
fnptypeAotNotWindowsName = ""
fnptypeAotNotWindowsSignature = ""

if not target_cpp:
clrallEvents.append("static ")
if generatedFileType == "header" and providerName=="Microsoft-Windows-DotNETRuntimePrivate":
fnptype.append("#ifdef FEATURE_ETW\n")
if not runtimeFlavor.nativeaot:
fnptype.append("inline ")
fnptype.append("%s FireEtw" % (getEventPipeDataTypeMapping(runtimeFlavor)["ULONG"]))
fnptypeAotNotWindowsName = fnptypeAotNotWindowsName + "#define FireEtw" + eventName + "("

fnptype.append(eventName)
fnptype.append("(\n")
Expand Down Expand Up @@ -495,7 +489,6 @@ def generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, wr
fnptypeline.append(" ")
fnptypeline.append(fnparam.name)
fnptypeline.append(",\n")
fnptypeAotNotWindowsSignature = fnptypeAotNotWindowsSignature + fnparam.name + ","

#fnsignature
for params in fnSig.paramlist:
Expand All @@ -511,7 +504,6 @@ def generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, wr
#remove trailing commas
if len(line) > 0:
del line[-1]
fnptypeAotNotWindowsSignature = fnptypeAotNotWindowsSignature[:-1]

#add activity IDs
fnptypeline.append(lindent)
Expand All @@ -528,46 +520,36 @@ def generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, wr
fnptype.append("\n)")
if generatedFileType == "header":
fnptype.append(";\n")
if providerName=="Microsoft-Windows-DotNETRuntimePrivate":
fnptype.append("#else\n")
fnptype.append(fnptypeAotNotWindowsName)
fnptype.append(fnptypeAotNotWindowsSignature)
fnptype.append(")")
fnptype.append("\n")
fnptype.append("#endif // FEATURE_ETW\n")
else:
fnptype.append("\n")
fnptype.append("\n")
elif generatedFileType == "source-impl-noop":
fnptype.append("\n{ return ERROR_SUCCESS; }\n\n")
else:
else: # source-impl
fnptype.append("\n{\n")
fnbody.append(lindent)

if not (runtimeFlavor.nativeaot and not providerName == "Microsoft-Windows-DotNETRuntime"):
fnbody.append("%s status = EventPipeWriteEvent" % (getEventPipeDataTypeMapping(runtimeFlavor)["ULONG"]) + eventName + "(" + ''.join(line))
if len(line) > 0:
fnbody.append(",")
fnbody.append("%s status = EventPipeWriteEvent" % (getEventPipeDataTypeMapping(runtimeFlavor)["ULONG"]) + eventName + "(" + ''.join(line))
if len(line) > 0:
fnbody.append(",")

fnbody.append("ActivityId,RelatedActivityId);\n")
fnbody.append("ActivityId,RelatedActivityId);\n")

if runtimeFlavor.coreclr or write_xplatheader:
fnbody.append(lindent)
fnbody.append("status &= FireEtXplat" + eventName + "(" + ''.join(line) + ");\n")

if runtimeFlavor.nativeaot:
if providerName == "Microsoft-Windows-DotNETRuntime":
if providerName == "Microsoft-Windows-DotNETRuntime" or providerName == "Microsoft-Windows-DotNETRuntimePrivate":
fnbody.append("#ifndef TARGET_UNIX\n")
fnbody.append(lindent)
fnbody.append("status &= ")
else:
fnbody.append("return ")
fnbody.append("FireEtXplat" + eventName + "(" + ''.join(line) + ");\n")
if providerName == "Microsoft-Windows-DotNETRuntime":
if providerName == "Microsoft-Windows-DotNETRuntime" or providerName == "Microsoft-Windows-DotNETRuntimePrivate":
fnbody.append("#endif\n")

if not (runtimeFlavor.nativeaot and not providerName == "Microsoft-Windows-DotNETRuntime"):
fnbody.append(lindent)
fnbody.append("return status;\n")
fnbody.append(lindent)
fnbody.append("return status;\n")
fnbody.append("}\n\n")

clrallEvents.extend(fnptype)
Expand Down Expand Up @@ -792,6 +774,7 @@ def updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, eventpipe_
elif generatedFileType == "source-impl-noop":
Clrallevents.write('#include <CommonTypes.h>\n')
Clrallevents.write('#include <CommonMacros.h>\n\n')
Clrallevents.write('#include <PalRedhawk.h>\n\n')
Clrallevents.write('#ifndef ERROR_SUCCESS\n')
Clrallevents.write('#define ERROR_SUCCESS 0L\n')
Clrallevents.write('#endif\n\n')
Expand All @@ -809,21 +792,12 @@ def updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, eventpipe_
Clrallevents.write("\n")

# Hack to write etw specific information to nativeaot
nativeaotEtwflag = False
for providerNode in tree.getElementsByTagName('provider'):
providerName = providerNode.getAttribute('name')
templateNodes = providerNode.getElementsByTagName('template')
allTemplates = parseTemplateNodes(templateNodes)
eventNodes = providerNode.getElementsByTagName('event')

if generatedFileType == "source-impl" and providerName == "Microsoft-Windows-DotNETRuntimePrivate" and not nativeaotEtwflag:
nativeaotEtwflag = True
Clrallevents.write("\n#ifdef FEATURE_ETW\n\n")
Clrallevents.write("// ==================================================================\n")
Clrallevents.write("// Events currently only fired via ETW (private runtime provider)\n")
Clrallevents.write("// ==================================================================\n\n")
nativeaotEtwflag = False

#vm header:
Clrallevents.write(generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, write_xplatheader, providerName, inclusion_list, generatedFileType))

Expand All @@ -837,9 +811,6 @@ def updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, eventpipe_
if not is_windows and not write_xplatheader and not runtimeFlavor.nativeaot:
Clrallevents.write('__attribute__((weak)) EVENTPIPE_TRACE_CONTEXT ' + eventpipeProviderCtxName + ' = { W("' + providerName + '"), 0, false, 0 };\n')

if runtimeFlavor.nativeaot and providerName == "Microsoft-Windows-DotNETRuntimePrivate" and generatedFileType == "source-impl":
Clrallevents.write("#endif // FEATURE_ETW\n")

if generatedFileType == "header":
Clrallevents.write("#endif // __CLR_ETW_ALL_MAIN_H__\n")

Expand Down
3 changes: 2 additions & 1 deletion src/tests/GC/Stress/Tests/concurrentspin2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CLRTestKind>BuildOnly</CLRTestKind>
<CLRTestKind Condition="'$(TestBuildMode)' != 'nativeaot'">BuildOnly</CLRTestKind>
<EventSourceSupport Condition="'$(TestBuildMode)' == 'nativeaot'">true</EventSourceSupport>
</PropertyGroup>
<ItemGroup>
<Compile Include="concurrentspin2.cs" />
Expand Down

0 comments on commit 791e7a4

Please sign in to comment.