From: Lakshan Fernando Date: Tue, 8 Aug 2023 13:35:41 +0000 (-0700) Subject: Cleanup work (#89976) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~451 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3c5ad6c677b4a3d12bc6a776d654558cca2c36a9;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Cleanup work (#89976) * Cleanup work * FB * test fix * Implement per-thread activity_id * FB * Update src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp Co-authored-by: Elinor Fung * replace pThread with activityIdHandle * increase helix timeout for checked aot run --------- Co-authored-by: Elinor Fung --- diff --git a/eng/pipelines/runtime.yml b/eng/pipelines/runtime.yml index 7c138e3..0f1cc60 100644 --- a/eng/pipelines/runtime.yml +++ b/eng/pipelines/runtime.yml @@ -243,13 +243,13 @@ extends: - name: timeoutPerTestCollectionInMinutes value: 180 jobParameters: - timeoutInMinutes: 120 + timeoutInMinutes: 180 nameSuffix: NativeAOT buildArgs: -s clr.aot+host.native+libs -rc $(_BuildConfig) -lc Release -hc Release extraStepsTemplate: /eng/pipelines/coreclr/nativeaot-post-build-steps.yml extraStepsParameters: creator: dotnet-bot - testBuildArgs: 'nativeaot tree ";nativeaot;Loader;Interop;tracing/eventpipe/config;tracing/eventpipe/diagnosticport;tracing/eventpipe/reverse;tracing/eventpipe/processenvironment;tracing/eventpipe/simpleruntimeeventvalidation;tracing/eventpipe/processinfo2;" test tracing/eventcounter/runtimecounters.csproj /p:BuildNativeAotFrameworkObjects=true' + testBuildArgs: 'nativeaot tree ";nativeaot;Loader;Interop;tracing;" /p:BuildNativeAotFrameworkObjects=true' liveLibrariesBuildConfig: Release testRunNamePrefixSuffix: NativeAOT_$(_BuildConfig) extraVariablesTemplates: diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp index eea3489..0bf1eee 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp @@ -2993,6 +2993,7 @@ void InitDotNETRuntime(void) EventPipeEventThreadPoolWorkerThreadAdjustmentStats = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,56,65536,0,EP_EVENT_LEVEL_VERBOSE,true); EventPipeEventThreadPoolIOEnqueue = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,63,2147549184,0,EP_EVENT_LEVEL_VERBOSE,true); EventPipeEventThreadPoolIODequeue = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,64,2147549184,0,EP_EVENT_LEVEL_VERBOSE,true); + EventPipeEventThreadPoolIOPack = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,65,65536,0,EP_EVENT_LEVEL_VERBOSE,true); EventPipeEventThreadPoolWorkingThreadCount = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,60,65536,0,EP_EVENT_LEVEL_VERBOSE,true); EventPipeEventGCAllocationTick_V4 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,10,1,4,EP_EVENT_LEVEL_VERBOSE,true); EventPipeEventGCHeapStats_V2 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,4,1,2,EP_EVENT_LEVEL_INFORMATIONAL,false); diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp index d7e3460..43fad22 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp @@ -817,6 +817,13 @@ ep_rt_thread_handle_t ep_rt_aot_thread_get_handle (void) return ThreadStore::GetCurrentThreadIfAvailable(); } +ep_rt_thread_handle_t ep_rt_aot_setup_thread (void) +{ + // This is expensive but need a valid thread that will only be used by EventPipe + ThreadStore::AttachCurrentThread(); + return ThreadStore::GetCurrentThread(); +} + ep_rt_thread_id_t ep_rt_aot_thread_get_id (ep_rt_thread_handle_t thread_handle) { return thread_handle->GetPalThreadIdForLogging(); diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h index dcf0bff..ec315c0 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h @@ -726,10 +726,9 @@ EP_RT_DEFINE_THREAD_FUNC (ep_rt_thread_aot_start_session_or_sampling_thread) ep_rt_thread_params_t* thread_params = reinterpret_cast(data); - // The session and sampling threads both assert that the incoming thread handle is - // non-null, but do not necessarily rely on it otherwise; just pass a meaningless non-null - // value until testing shows that a meaningful value is needed. - thread_params->thread = reinterpret_cast(1); + // We will create a new thread. cannot call ep_rt_aot_thread_get_handle since that will return null + extern ep_rt_thread_handle_t ep_rt_aot_setup_thread (void); + thread_params->thread = ep_rt_aot_setup_thread (); size_t result = thread_params->thread_func (thread_params); delete thread_params; @@ -793,15 +792,7 @@ ep_rt_current_processor_get_number (void) { STATIC_CONTRACT_NOTHROW; -#ifndef TARGET_UNIX - extern uint32_t *_ep_rt_aot_proc_group_offsets; - if (_ep_rt_aot_proc_group_offsets) { - // PROCESSOR_NUMBER proc; - // GetCurrentProcessorNumberEx (&proc); - // return _ep_rt_aot_proc_group_offsets [proc.Group] + proc.Number; - // PalDebugBreak(); - } -#endif + // Follows the mono implementation return 0xFFFFFFFF; } @@ -1588,10 +1579,7 @@ bool ep_rt_thread_has_started (ep_rt_thread_handle_t thread_handle) { STATIC_CONTRACT_NOTHROW; - // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase - // TODO: Implement thread creation/management if needed - // return thread_handle != NULL && thread_handle->HasStarted (); - return true; + return thread_handle != NULL; } static diff --git a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp index d9e77f9..7cf502d 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp @@ -148,9 +148,67 @@ EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_DeleteProvider(intptr_t } } +// All the runtime redefine this enum, should move to commmon code. +// https://github.com/dotnet/runtime/issues/87069 +enum class ActivityControlCode +{ + EVENT_ACTIVITY_CONTROL_GET_ID = 1, + EVENT_ACTIVITY_CONTROL_SET_ID = 2, + EVENT_ACTIVITY_CONTROL_CREATE_ID = 3, + EVENT_ACTIVITY_CONTROL_GET_SET_ID = 4, + EVENT_ACTIVITY_CONTROL_CREATE_SET_ID = 5 +}; + EXTERN_C NATIVEAOT_API int __cdecl RhEventPipeInternal_EventActivityIdControl(uint32_t controlCode, GUID *pActivityId) { - return 0; + int retVal = 0; + ep_rt_thread_activity_id_handle_t activityIdHandle = ep_thread_get_activity_id_handle (); + if (activityIdHandle == NULL || pActivityId == NULL) + { + retVal = 1; + } + else + { + ActivityControlCode activityControlCode = (ActivityControlCode)controlCode; + GUID currentActivityId; + switch (activityControlCode) + { + case ActivityControlCode::EVENT_ACTIVITY_CONTROL_GET_ID: + + ep_rt_thread_get_activity_id (activityIdHandle, reinterpret_cast(pActivityId), EP_ACTIVITY_ID_SIZE); + break; + + case ActivityControlCode::EVENT_ACTIVITY_CONTROL_SET_ID: + + ep_rt_thread_set_activity_id (activityIdHandle, reinterpret_cast(pActivityId), EP_ACTIVITY_ID_SIZE); + break; + + case ActivityControlCode::EVENT_ACTIVITY_CONTROL_CREATE_ID: + + ep_rt_create_activity_id(reinterpret_cast(pActivityId), EP_ACTIVITY_ID_SIZE); + break; + + case ActivityControlCode::EVENT_ACTIVITY_CONTROL_GET_SET_ID: + + ep_rt_thread_get_activity_id (activityIdHandle, reinterpret_cast(¤tActivityId), EP_ACTIVITY_ID_SIZE); + ep_rt_thread_set_activity_id (activityIdHandle, reinterpret_cast(pActivityId), EP_ACTIVITY_ID_SIZE); + *pActivityId = currentActivityId; + + break; + + case ActivityControlCode::EVENT_ACTIVITY_CONTROL_CREATE_SET_ID: + + ep_rt_thread_get_activity_id (activityIdHandle, reinterpret_cast(pActivityId), EP_ACTIVITY_ID_SIZE); + ep_rt_create_activity_id(reinterpret_cast(¤tActivityId), EP_ACTIVITY_ID_SIZE); + ep_rt_thread_set_activity_id (activityIdHandle, reinterpret_cast(¤tActivityId), EP_ACTIVITY_ID_SIZE); + break; + + default: + retVal = 1; + } + } + + return retVal; } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_WriteEventData( diff --git a/src/coreclr/nativeaot/Runtime/eventtrace_gcheap.cpp b/src/coreclr/nativeaot/Runtime/eventtrace_gcheap.cpp index 7ee7d56..db6adc3 100644 --- a/src/coreclr/nativeaot/Runtime/eventtrace_gcheap.cpp +++ b/src/coreclr/nativeaot/Runtime/eventtrace_gcheap.cpp @@ -35,18 +35,16 @@ BOOL ETW::GCLog::ShouldWalkHeapObjectsForEtw() { - LIMITED_METHOD_CONTRACT; - return RUNTIME_PROVIDER_CATEGORY_ENABLED( - TRACE_LEVEL_INFORMATION, - CLR_GCHEAPDUMP_KEYWORD); + // @TODO: until the below issue is fixed correctly + // https://github.com/dotnet/runtime/issues/88491 + return FALSE; } BOOL ETW::GCLog::ShouldWalkHeapRootsForEtw() { - LIMITED_METHOD_CONTRACT; - return RUNTIME_PROVIDER_CATEGORY_ENABLED( - TRACE_LEVEL_INFORMATION, - CLR_GCHEAPDUMP_KEYWORD); + // @TODO: until the below issue is fixed correctly + // https://github.com/dotnet/runtime/issues/88491 + return FALSE; } BOOL ETW::GCLog::ShouldTrackMovementForEtw() diff --git a/src/tests/issues.targets b/src/tests/issues.targets index d1dc86c..3dd51b5 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -1036,74 +1036,17 @@ https://github.com/dotnet/runtimelab/issues/200 - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 + + https://github.com/dotnet/runtime/issues/83051: Waiting for PR_88894 to be merged - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 - - - https://github.com/dotnet/runtime/issues/83051 + https://github.com/dotnet/runtime/issues/83051: not supported in net8 - https://github.com/dotnet/runtime/issues/83051 + https://github.com/dotnet/runtime/issues/83051: not supported in net8 - - https://github.com/dotnet/runtime/issues/83051 + + https://github.com/dotnet/runtime/issues/90021 https://github.com/dotnet/runtimelab/issues/208 diff --git a/src/tests/tracing/eventactivityidcontrol/eventactivityidcontrol.csproj b/src/tests/tracing/eventactivityidcontrol/eventactivityidcontrol.csproj index 737e816..8d08f43 100644 --- a/src/tests/tracing/eventactivityidcontrol/eventactivityidcontrol.csproj +++ b/src/tests/tracing/eventactivityidcontrol/eventactivityidcontrol.csproj @@ -10,4 +10,7 @@ + + + diff --git a/src/tests/tracing/eventactivityidcontrol/rd.xml b/src/tests/tracing/eventactivityidcontrol/rd.xml new file mode 100644 index 0000000..0228bf1 --- /dev/null +++ b/src/tests/tracing/eventactivityidcontrol/rd.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/tests/tracing/eventpipe/pauseonstart/pauseonstart.cs b/src/tests/tracing/eventpipe/pauseonstart/pauseonstart.cs index 3ae5626..529589d 100644 --- a/src/tests/tracing/eventpipe/pauseonstart/pauseonstart.cs +++ b/src/tests/tracing/eventpipe/pauseonstart/pauseonstart.cs @@ -64,12 +64,16 @@ namespace Tracing.Tests.PauseOnStartValidation IpcAdvertise advertise = IpcAdvertise.Parse(stream); Logger.logger.Log(advertise.ToString()); + // Native AOT doesn't use the private provider / EEStartupStart event, so the subprocess + // writes a sentinel event to signal that the runtime has resumed and run the application + Provider provider = TestLibrary.Utilities.IsNativeAot ? new Provider(nameof(SentinelEventSource)) : new Provider("Microsoft-Windows-DotNETRuntimePrivate", 0x80000000, EventLevel.Verbose); var config = new SessionConfiguration( circularBufferSizeMB: 1000, format: EventPipeSerializationFormat.NetTrace, providers: new List { - new Provider("Microsoft-Windows-DotNETRuntimePrivate", 0x80000000, EventLevel.Verbose) + provider }); + Logger.logger.Log("Starting EventPipeSession over standard connection"); using Stream eventStream = EventPipeClient.CollectTracing(pid, config, out var sessionId); Logger.logger.Log($"Started EventPipeSession over standard connection with session id: 0x{sessionId:x}"); @@ -96,7 +100,14 @@ namespace Tracing.Tests.PauseOnStartValidation using var source = new EventPipeEventSource(memoryStream); var parser = new ClrPrivateTraceEventParser(source); bool isStartupEventPresent= false; - parser.StartupEEStartupStart += (eventData) => isStartupEventPresent = true; + if (TestLibrary.Utilities.IsNativeAot) + { + source.Dynamic.All += (eventData) => isStartupEventPresent = true; + } + else + { + parser.StartupEEStartupStart += (eventData) => isStartupEventPresent = true; + } source.Process(); Logger.logger.Log($"isStartupEventPresent: {isStartupEventPresent}"); @@ -122,11 +133,14 @@ namespace Tracing.Tests.PauseOnStartValidation IpcAdvertise advertise = IpcAdvertise.Parse(stream); Logger.logger.Log(advertise.ToString()); + // Native AOT doesn't use the private provider / EEStartupStart event, so the subprocess + // writes a sentinel event to signal that the runtime has resumed and run the application + Provider provider = TestLibrary.Utilities.IsNativeAot ? new Provider(nameof(SentinelEventSource)) : new Provider("Microsoft-Windows-DotNETRuntimePrivate", 0x80000000, EventLevel.Verbose); var config = new SessionConfiguration( circularBufferSizeMB: 1000, format: EventPipeSerializationFormat.NetTrace, providers: new List { - new Provider("Microsoft-Windows-DotNETRuntimePrivate", 0x80000000, EventLevel.Verbose) + provider }); Logger.logger.Log("Starting EventPipeSession over standard connection"); @@ -172,7 +186,18 @@ namespace Tracing.Tests.PauseOnStartValidation using (var source = new EventPipeEventSource(memoryStream1)) { var parser = new ClrPrivateTraceEventParser(source); - parser.StartupEEStartupStart += (eventData) => nStartupEventsSeen++; + if (TestLibrary.Utilities.IsNativeAot) + { + source.Dynamic.All += (eventData) => + { + if(eventData.EventName.Equals("SentinelEvent")) + nStartupEventsSeen++; + }; + } + else + { + parser.StartupEEStartupStart += (eventData) => nStartupEventsSeen++; + } source.Process(); } @@ -180,7 +205,18 @@ namespace Tracing.Tests.PauseOnStartValidation using (var source = new EventPipeEventSource(memoryStream2)) { var parser = new ClrPrivateTraceEventParser(source); - parser.StartupEEStartupStart += (eventData) => nStartupEventsSeen++; + if (TestLibrary.Utilities.IsNativeAot) + { + source.Dynamic.All += (eventData) => + { + if(eventData.EventName.Equals("SentinelEvent")) + nStartupEventsSeen++; + }; + } + else + { + parser.StartupEEStartupStart += (eventData) => nStartupEventsSeen++; + } source.Process(); } @@ -188,7 +224,18 @@ namespace Tracing.Tests.PauseOnStartValidation using (var source = new EventPipeEventSource(memoryStream3)) { var parser = new ClrPrivateTraceEventParser(source); - parser.StartupEEStartupStart += (eventData) => nStartupEventsSeen++; + if (TestLibrary.Utilities.IsNativeAot) + { + source.Dynamic.All += (eventData) => + { + if(eventData.EventName.Equals("SentinelEvent")) + nStartupEventsSeen++; + }; + } + else + { + parser.StartupEEStartupStart += (eventData) => nStartupEventsSeen++; + } source.Process(); } @@ -306,10 +353,21 @@ namespace Tracing.Tests.PauseOnStartValidation return fSuccess; } + public sealed class SentinelEventSource : EventSource + { + private SentinelEventSource() {} + public static SentinelEventSource Log = new SentinelEventSource(); + public void SentinelEvent() { WriteEvent(1, nameof(SentinelEvent)); } + } + public static async Task Main(string[] args) { if (args.Length >= 1) { + // Native AOT test uses this event source as a signal that the runtime has resumed and gone on to run the application + if (TestLibrary.Utilities.IsNativeAot) + SentinelEventSource.Log.SentinelEvent(); + Console.Out.WriteLine("Subprocess started! Waiting for input..."); var input = Console.In.ReadLine(); // will block until data is sent across stdin Console.Out.WriteLine($"Received '{input}'. Exiting..."); diff --git a/src/tests/tracing/eventpipe/pauseonstart/pauseonstart.csproj b/src/tests/tracing/eventpipe/pauseonstart/pauseonstart.csproj index c20471b..e266e49 100644 --- a/src/tests/tracing/eventpipe/pauseonstart/pauseonstart.csproj +++ b/src/tests/tracing/eventpipe/pauseonstart/pauseonstart.csproj @@ -11,5 +11,6 @@ + diff --git a/src/tests/tracing/eventpipe/processinfo3/processinfo3.cs b/src/tests/tracing/eventpipe/processinfo3/processinfo3.cs index a17659f..ec6591e 100644 --- a/src/tests/tracing/eventpipe/processinfo3/processinfo3.cs +++ b/src/tests/tracing/eventpipe/processinfo3/processinfo3.cs @@ -158,7 +158,9 @@ namespace Tracing.Tests.ProcessInfoValidation // /path/to/corerun /path/to/processinfo.dll // or // "C:\path\to\CoreRun.exe" C:\path\to\processinfo.dll - string currentProcessCommandLine = $"{currentProcess.MainModule.FileName} {System.Reflection.Assembly.GetExecutingAssembly().Location}"; + string currentProcessCommandLine = TestLibrary.Utilities.IsSingleFile + ? currentProcess.MainModule.FileName + : $"{currentProcess.MainModule.FileName} {System.Reflection.Assembly.GetExecutingAssembly().Location}"; string receivedCommandLine = NormalizeCommandLine(commandLine); Utils.Assert(currentProcessCommandLine.Equals(receivedCommandLine, StringComparison.OrdinalIgnoreCase), $"CommandLine must match current process. Expected: {currentProcessCommandLine}, Received: {receivedCommandLine} (original: {commandLine})"); } diff --git a/src/tests/tracing/eventpipe/processinfo3/processinfo3.csproj b/src/tests/tracing/eventpipe/processinfo3/processinfo3.csproj index d4947c7..2c913f4 100644 --- a/src/tests/tracing/eventpipe/processinfo3/processinfo3.csproj +++ b/src/tests/tracing/eventpipe/processinfo3/processinfo3.csproj @@ -15,5 +15,6 @@ +