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

Fix Missing Metadata for ThreadPool Event #67150

Merged
merged 11 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,12 @@ internal static partial void LogThreadPoolWorkingThreadCount(
uint Count,
ushort ClrInstanceID
);

[NonEvent]
[LibraryImport(RuntimeHelpers.QCall)]
internal static partial void LogThreadPoolIOPack(
IntPtr NativeOverlapped,
IntPtr Overlapped,
ushort ClrInstanceID);
}
}
10 changes: 10 additions & 0 deletions src/coreclr/vm/nativeeventsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,14 @@ extern "C" void QCALLTYPE LogThreadPoolWorkingThreadCount(_In_z_ uint count, _In

END_QCALL;
}

extern "C" void QCALLTYPE LogThreadPoolIOPack(_In_z_ void* nativeOverlapped, _In_z_ void* overlapped, _In_z_ short ClrInstanceID)
{
QCALL_CONTRACT;
BEGIN_QCALL;

FireEtwThreadPoolIOPack(nativeOverlapped, overlapped, ClrInstanceID);

END_QCALL;
}
#endif // FEATURE_PERFTRACING
1 change: 1 addition & 0 deletions src/coreclr/vm/nativeeventsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern "C" void QCALLTYPE LogThreadPoolWorkerThreadAdjustmentStats(_In_z_ double
extern "C" void QCALLTYPE LogThreadPoolIOEnqueue(_In_z_ void* nativeOverlapped, _In_z_ void* overlapped, _In_z_ bool multiDequeues, _In_z_ short ClrInstanceID);
extern "C" void QCALLTYPE LogThreadPoolIODequeue(_In_z_ void* nativeOverlapped, _In_z_ void* overlapped, _In_z_ short ClrInstanceID);
extern "C" void QCALLTYPE LogThreadPoolWorkingThreadCount(_In_z_ uint count, _In_z_ short ClrInstanceID);
extern "C" void QCALLTYPE LogThreadPoolIOPack(_In_z_ void* nativeOverlapped, _In_z_ void* overlapped, _In_z_ short ClrInstanceID);
#endif // defined(FEATURE_PERFTRACING)

#endif //_NATIVEEVENTSOURCE_H_
1 change: 1 addition & 0 deletions src/coreclr/vm/qcallentrypoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ static const Entry s_QCall[] =
DllImportEntry(LogThreadPoolWorkerThreadAdjustmentStats)
DllImportEntry(LogThreadPoolIOEnqueue)
DllImportEntry(LogThreadPoolIODequeue)
DllImportEntry(LogThreadPoolIOPack)
DllImportEntry(LogThreadPoolWorkingThreadCount)
DllImportEntry(EventPipeInternal_Enable)
DllImportEntry(EventPipeInternal_Disable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace System.Diagnostics.Tracing
// FireEtw* methods auto-generated from ClrEtwAll.man. This ensures that corresponding event sinks are being used
// for the native platform.
// For implementation of these events not supporting native sinks, refer to NativeRuntimeEventSource.PortableThreadPool.cs.
[CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "NativeRuntimeEventSource is a special case where event methods don't use WriteEvent/WriteEventCore but still need to be instance methods.")]
internal sealed partial class NativeRuntimeEventSource : EventSource
{
// This value does not seem to be used, leaving it as zero for now. It may be useful for a scenario that may involve
Expand Down Expand Up @@ -46,6 +47,7 @@ private static class Messages
{
public const EventOpcode IOEnqueue = (EventOpcode)13;
public const EventOpcode IODequeue = (EventOpcode)14;
public const EventOpcode IOPack = (EventOpcode)15;
public const EventOpcode Wait = (EventOpcode)90;
public const EventOpcode Sample = (EventOpcode)100;
public const EventOpcode Adjustment = (EventOpcode)101;
Expand Down Expand Up @@ -225,5 +227,26 @@ public unsafe void ThreadPoolWorkingThreadCount(uint Count, ushort ClrInstanceID
}
LogThreadPoolWorkingThreadCount(Count, ClrInstanceID);
}

[NonEvent]
[MethodImpl(MethodImplOptions.NoInlining)]
public unsafe void ThreadPoolIOPack(NativeOverlapped* nativeOverlapped)
{
if (IsEnabled(EventLevel.Verbose, Keywords.ThreadingKeyword))
{
ThreadPoolIOPack(
(IntPtr)nativeOverlapped,
(IntPtr)OverlappedData.GetOverlappedFromNative(nativeOverlapped).GetHashCode());
}
}

[Event(65, Level = EventLevel.Verbose, Message = Messages.IO, Task = Tasks.ThreadPool, Opcode = Opcodes.IOPack, Version = 0, Keywords = Keywords.ThreadingKeyword)]
private unsafe void ThreadPoolIOPack(
IntPtr NativeOverlapped,
IntPtr Overlapped,
ushort ClrInstanceID = DefaultClrInstanceId)
{
LogThreadPoolIOPack(NativeOverlapped, Overlapped, ClrInstanceID);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private static class Messages
{
public const EventOpcode IOEnqueue = (EventOpcode)13;
public const EventOpcode IODequeue = (EventOpcode)14;
public const EventOpcode IOPack = (EventOpcode)15;
public const EventOpcode Wait = (EventOpcode)90;
public const EventOpcode Sample = (EventOpcode)100;
public const EventOpcode Adjustment = (EventOpcode)101;
Expand Down Expand Up @@ -362,5 +363,40 @@ public unsafe void ThreadPoolWorkingThreadCount(uint Count, ushort ClrInstanceID
data[1].Reserved = 0;
WriteEventCore(60, 2, data);
}

[NonEvent]
[MethodImpl(MethodImplOptions.NoInlining)]
public unsafe void ThreadPoolIOPack(NativeOverlapped* nativeOverlapped)
{
if (IsEnabled(EventLevel.Verbose, Keywords.ThreadingKeyword))
{
ThreadPoolIOPack(
(IntPtr)nativeOverlapped,
(IntPtr)OverlappedData.GetOverlappedFromNative(nativeOverlapped).GetHashCode());
}
}

#if !ES_BUILD_STANDALONE
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern",
Justification = EventSourceSuppressMessage)]
#endif
[Event(65, Level = EventLevel.Verbose, Message = Messages.IO, Task = Tasks.ThreadPool, Opcode = Opcodes.IOPack, Version = 0, Keywords = Keywords.ThreadingKeyword)]
private unsafe void ThreadPoolIOPack(
IntPtr NativeOverlapped,
IntPtr Overlapped,
ushort ClrInstanceID = DefaultClrInstanceId)
{
EventData* data = stackalloc EventData[3];
data[0].DataPointer = NativeOverlapped;
data[0].Size = sizeof(IntPtr);
data[0].Reserved = 0;
data[1].DataPointer = Overlapped;
data[1].Size = sizeof(IntPtr);
data[1].Reserved = 0;
data[2].DataPointer = (IntPtr)(&ClrInstanceID);
data[2].Size = sizeof(ushort);
data[2].Reserved = 0;
WriteEventCore(65, 3, data);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,12 @@ internal static extern void LogThreadPoolWorkingThreadCount(
uint Count,
ushort ClrInstanceID
);

[NonEvent]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern void LogThreadPoolIOPack(
IntPtr NativeOverlapped,
IntPtr Overlapped,
ushort ClrInstanceID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Runtime.InteropServices;

namespace System.Threading
Expand Down Expand Up @@ -98,6 +99,10 @@ internal sealed unsafe class OverlappedData
*(GCHandle*)(_pNativeOverlapped + 1) = GCHandle.Alloc(this);

success = true;
#if FEATURE_PERFTRACING
if (NativeRuntimeEventSource.Log.IsEnabled())
NativeRuntimeEventSource.Log.ThreadPoolIOPack(pNativeOverlapped);
#endif
return _pNativeOverlapped;
}
finally
Expand Down
18 changes: 17 additions & 1 deletion src/mono/mono/component/event_pipe-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ event_pipe_stub_write_event_threadpool_working_thread_count (
uint16_t count,
uint16_t clr_instance_id);

static bool
event_pipe_stub_write_event_threadpool_io_pack (
intptr_t native_overlapped,
intptr_t overlapped,
uint16_t clr_instance_id);

MonoComponentEventPipe *
component_event_pipe_stub_init (void);

Expand Down Expand Up @@ -203,7 +209,8 @@ static MonoComponentEventPipe fn_table = {
&event_pipe_stub_write_event_threadpool_worker_thread_adjustment_stats,
&event_pipe_stub_write_event_threadpool_io_enqueue,
&event_pipe_stub_write_event_threadpool_io_dequeue,
&event_pipe_stub_write_event_threadpool_working_thread_count
&event_pipe_stub_write_event_threadpool_working_thread_count,
&event_pipe_stub_write_event_threadpool_io_pack
};

static bool
Expand Down Expand Up @@ -443,6 +450,15 @@ event_pipe_stub_write_event_threadpool_working_thread_count (
return true;
}

static bool
event_pipe_stub_write_event_threadpool_io_pack (
intptr_t native_overlapped,
intptr_t overlapped,
uint16_t clr_instance_id)
{
return true;
}

MonoComponentEventPipe *
component_event_pipe_stub_init (void)
{
Expand Down
3 changes: 2 additions & 1 deletion src/mono/mono/component/event_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ static MonoComponentEventPipe fn_table = {
&ep_rt_write_event_threadpool_worker_thread_adjustment_stats,
&ep_rt_write_event_threadpool_io_enqueue,
&ep_rt_write_event_threadpool_io_dequeue,
&ep_rt_write_event_threadpool_working_thread_count
&ep_rt_write_event_threadpool_working_thread_count,
&ep_rt_write_event_threadpool_io_pack
};

static bool
Expand Down
7 changes: 7 additions & 0 deletions src/mono/mono/component/event_pipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ typedef bool
uint16_t count,
uint16_t clr_instance_id);

typedef bool
(*event_pipe_component_write_event_threadpool_io_pack_func)(
intptr_t native_overlapped,
intptr_t overlapped,
uint16_t clr_instance_id);

/*
* MonoComponentEventPipe function table.
*/
Expand Down Expand Up @@ -235,6 +241,7 @@ typedef struct _MonoComponentEventPipe {
event_pipe_component_write_event_threadpool_io_enqueue_func write_event_threadpool_io_enqueue;
event_pipe_component_write_event_threadpool_io_dequeue_func write_event_threadpool_io_dequeue;
event_pipe_component_write_event_threadpool_working_thread_count_func write_event_threadpool_working_thread_count;
event_pipe_component_write_event_threadpool_io_pack_func write_event_threadpool_io_pack;
} MonoComponentEventPipe;

MONO_COMPONENT_EXPORT_ENTRYPOINT
Expand Down
14 changes: 14 additions & 0 deletions src/mono/mono/eventpipe/ep-rt-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -3802,6 +3802,20 @@ ep_rt_write_event_threadpool_working_thread_count (
NULL) == 0 ? true : false;
}

bool
ep_rt_write_event_threadpool_io_pack (
intptr_t native_overlapped,
intptr_t overlapped,
uint16_t clr_instance_id)
{
return FireEtwThreadPoolIOPack (
(const void *)native_overlapped,
(const void *)overlapped,
clr_instance_id,
NULL,
NULL) == 0 ? true : false;
}

static
void
runtime_profiler_jit_begin (
Expand Down
6 changes: 6 additions & 0 deletions src/mono/mono/eventpipe/ep-rt-mono.h
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,12 @@ ep_rt_write_event_threadpool_working_thread_count (
uint16_t count,
uint16_t clr_instance_id);

bool
ep_rt_write_event_threadpool_io_pack (
intptr_t native_overlapped,
intptr_t overlapped,
uint16_t clr_instance_id);

/*
* EventPipe provider callbacks.
*/
Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/eventpipe/gen-eventing-event-inc.lst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ThreadPoolWorkerThreadStart
ThreadPoolWorkerThreadStop
ThreadPoolWorkerThreadWait
ThreadPoolWorkingThreadCount
ThreadPoolIOPack
ThreadTerminated
TypeLoadStart
TypeLoadStop
Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/metadata/icall-decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ ICALL_EXPORT void ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_
ICALL_EXPORT void ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_LogThreadPoolWorkerThreadStop (uint32_t active_thread_count, uint32_t retired_worker_thread_count, uint16_t clr_instance_id);
ICALL_EXPORT void ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_LogThreadPoolWorkerThreadWait (uint32_t active_thread_count, uint32_t retired_worker_thread_count, uint16_t clr_instance_id);
ICALL_EXPORT void ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_LogThreadPoolWorkingThreadCount (uint16_t count, uint16_t clr_instance_id);
ICALL_EXPORT void ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_LogThreadPoolIOPack (intptr_t native_overlapped, intptr_t overlapped, uint16_t clr_instance_id);

ICALL_EXPORT void ves_icall_Mono_RuntimeGPtrArrayHandle_GPtrArrayFree (GPtrArray *ptr_array);
ICALL_EXPORT void ves_icall_Mono_RuntimeMarshal_FreeAssemblyName (MonoAssemblyName *aname, MonoBoolean free_struct);
Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/metadata/icall-def.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ NOHANDLES(ICALL(EVENTPIPE_12, "WriteEventData", ves_icall_System_Diagnostics_Tra
ICALL_TYPE(NATIVE_RUNTIME_EVENT_SOURCE, "System.Diagnostics.Tracing.NativeRuntimeEventSource", NATIVE_RUNTIME_EVENT_SOURCE_1)
NOHANDLES(ICALL(NATIVE_RUNTIME_EVENT_SOURCE_1, "LogThreadPoolIODequeue", ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_LogThreadPoolIODequeue))
NOHANDLES(ICALL(NATIVE_RUNTIME_EVENT_SOURCE_2, "LogThreadPoolIOEnqueue", ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_LogThreadPoolIOEnqueue))
NOHANDLES(ICALL(NATIVE_RUNTIME_EVENT_SOURCE_10, "LogThreadPoolIOPack", ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_LogThreadPoolIOPack))
NOHANDLES(ICALL(NATIVE_RUNTIME_EVENT_SOURCE_3, "LogThreadPoolWorkerThreadAdjustmentAdjustment", ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_LogThreadPoolWorkerThreadAdjustmentAdjustment))
NOHANDLES(ICALL(NATIVE_RUNTIME_EVENT_SOURCE_4, "LogThreadPoolWorkerThreadAdjustmentSample", ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_LogThreadPoolWorkerThreadAdjustmentSample))
NOHANDLES(ICALL(NATIVE_RUNTIME_EVENT_SOURCE_5, "LogThreadPoolWorkerThreadAdjustmentStats", ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_LogThreadPoolWorkerThreadAdjustmentStats))
Expand Down
23 changes: 23 additions & 0 deletions src/mono/mono/metadata/icall-eventpipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,18 @@ ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_LogThreadPoolWorki
clr_instance_id);
}

void
ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_LogThreadPoolIOPack (
intptr_t native_overlapped,
intptr_t overlapped,
uint16_t clr_instance_id)
{
mono_component_event_pipe ()->write_event_threadpool_io_pack (
native_overlapped,
overlapped,
clr_instance_id);
}

#else /* ENABLE_PERFTRACING */

gconstpointer
Expand Down Expand Up @@ -703,4 +715,15 @@ ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_LogThreadPoolWorki
mono_error_set_pending_exception (error);
}

void
ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_LogThreadPoolIOPack (
intptr_t native_overlapped,
intptr_t overlapped,
uint16_t clr_instance_id)
{
ERROR_DECL (error);
mono_error_set_not_implemented (error, "System.Diagnostics.Tracing.NativeRuntimeEventSource.LogThreadPoolIOPack");
mono_error_set_pending_exception (error);
}

#endif /* ENABLE_PERFTRACING */
5 changes: 3 additions & 2 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1426,8 +1426,9 @@
<ExcludeList Include = "$(XunitTestBinBase)/JIT/HardwareIntrinsics/X86/Sse42.X64/Crc32_*/**">
<Issue>https://github.com/dotnet/runtime/issues/54185</Issue>
</ExcludeList>


<ExcludeList Include = "$(XunitTestBinBase)/tracing/runtimeeventsource/nativeruntimeeventsource/*">
<Issue>https://github.com/dotnet/runtime/issues/68032</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Directed/Convert/out_of_range_fp_to_int_conversions/*">
<Issue>Mono does not define out of range fp to int conversions</Issue>
</ExcludeList>
Expand Down
Loading