Skip to content

Commit

Permalink
[release/8.0-staging] Handle NativeOverlapped* coming from both the W…
Browse files Browse the repository at this point in the history
…indows or Portable thread pool in NativeRuntimeEventSource (#99656)
  • Loading branch information
github-actions[bot] authored Mar 16, 2024
1 parent 50c3c86 commit ff80834
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public unsafe void ThreadPoolWorkerThreadAdjustmentStats(
[Event(63, Level = EventLevel.Verbose, Message = Messages.IOEnqueue, Task = Tasks.ThreadPool, Opcode = Opcodes.IOEnqueue, Version = 0, Keywords = Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword)]
private unsafe void ThreadPoolIOEnqueue(
IntPtr NativeOverlapped,
IntPtr Overlapped,
IntPtr Overlapped, // 0 if the Windows thread pool is used, the relevant info could be obtained from the NativeOverlapped* if necessary
bool MultiDequeues,
ushort ClrInstanceID = DefaultClrInstanceId)
{
Expand All @@ -207,9 +207,14 @@ public unsafe void ThreadPoolIOEnqueue(NativeOverlapped* nativeOverlapped)
{
if (IsEnabled(EventLevel.Verbose, Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword))
{
#if TARGET_WINDOWS
IntPtr overlapped = ThreadPool.UseWindowsThreadPool ? 0 : (IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode();
#else
IntPtr overlapped = (IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode();
#endif
ThreadPoolIOEnqueue(
(IntPtr)nativeOverlapped,
(IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode(),
overlapped,
false);
}
}
Expand All @@ -231,7 +236,7 @@ public void ThreadPoolIOEnqueue(RegisteredWaitHandle registeredWaitHandle)
[Event(64, Level = EventLevel.Verbose, Message = Messages.IO, Task = Tasks.ThreadPool, Opcode = Opcodes.IODequeue, Version = 0, Keywords = Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword)]
private unsafe void ThreadPoolIODequeue(
IntPtr NativeOverlapped,
IntPtr Overlapped,
IntPtr Overlapped, // 0 if the Windows thread pool is used, the relevant info could be obtained from the NativeOverlapped* if necessary
ushort ClrInstanceID = DefaultClrInstanceId)
{
LogThreadPoolIODequeue(NativeOverlapped, Overlapped, ClrInstanceID);
Expand All @@ -243,9 +248,14 @@ public unsafe void ThreadPoolIODequeue(NativeOverlapped* nativeOverlapped)
{
if (IsEnabled(EventLevel.Verbose, Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword))
{
#if TARGET_WINDOWS
IntPtr overlapped = ThreadPool.UseWindowsThreadPool ? 0 : (IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode();
#else
IntPtr overlapped = (IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode();
#endif
ThreadPoolIODequeue(
(IntPtr)nativeOverlapped,
(IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode());
overlapped);
}
}

Expand Down Expand Up @@ -277,16 +287,21 @@ public unsafe void ThreadPoolIOPack(NativeOverlapped* nativeOverlapped)
{
if (IsEnabled(EventLevel.Verbose, Keywords.ThreadingKeyword))
{
#if TARGET_WINDOWS
IntPtr overlapped = ThreadPool.UseWindowsThreadPool ? 0 : (IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode();
#else
IntPtr overlapped = (IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode();
#endif
ThreadPoolIOPack(
(IntPtr)nativeOverlapped,
(IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode());
overlapped);
}
}

[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,
IntPtr Overlapped, // 0 if the Windows thread pool is used, the relevant info could be obtained from the NativeOverlapped* if necessary
ushort ClrInstanceID = DefaultClrInstanceId)
{
LogThreadPoolIOPack(NativeOverlapped, Overlapped, ClrInstanceID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public unsafe void ThreadPoolWorkerThreadAdjustmentStats(
[Event(63, Level = EventLevel.Verbose, Message = Messages.IOEnqueue, Task = Tasks.ThreadPool, Opcode = Opcodes.IOEnqueue, Version = 0, Keywords = Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword)]
private unsafe void ThreadPoolIOEnqueue(
IntPtr NativeOverlapped,
IntPtr Overlapped,
IntPtr Overlapped, // 0 if the Windows thread pool is used, the relevant info could be obtained from the NativeOverlapped* if necessary
bool MultiDequeues,
ushort ClrInstanceID = DefaultClrInstanceId)
{
Expand All @@ -343,9 +343,14 @@ public unsafe void ThreadPoolIOEnqueue(NativeOverlapped* nativeOverlapped)
{
if (IsEnabled(EventLevel.Verbose, Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword))
{
#if TARGET_WINDOWS
IntPtr overlapped = ThreadPool.UseWindowsThreadPool ? 0 : (IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode();
#else
IntPtr overlapped = (IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode();
#endif
ThreadPoolIOEnqueue(
(IntPtr)nativeOverlapped,
(IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode(),
overlapped,
false);
}
}
Expand All @@ -368,7 +373,7 @@ public void ThreadPoolIOEnqueue(RegisteredWaitHandle registeredWaitHandle)
[Event(64, Level = EventLevel.Verbose, Message = Messages.IO, Task = Tasks.ThreadPool, Opcode = Opcodes.IODequeue, Version = 0, Keywords = Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword)]
private unsafe void ThreadPoolIODequeue(
IntPtr NativeOverlapped,
IntPtr Overlapped,
IntPtr Overlapped, // 0 if the Windows thread pool is used, the relevant info could be obtained from the NativeOverlapped* if necessary
ushort ClrInstanceID = DefaultClrInstanceId)
{
EventData* data = stackalloc EventData[3];
Expand All @@ -390,9 +395,14 @@ public unsafe void ThreadPoolIODequeue(NativeOverlapped* nativeOverlapped)
{
if (IsEnabled(EventLevel.Verbose, Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword))
{
#if TARGET_WINDOWS
IntPtr overlapped = ThreadPool.UseWindowsThreadPool ? 0 : (IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode();
#else
IntPtr overlapped = (IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode();
#endif
ThreadPoolIODequeue(
(IntPtr)nativeOverlapped,
(IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode());
overlapped);
}
}

Expand Down Expand Up @@ -432,17 +442,22 @@ public unsafe void ThreadPoolIOPack(NativeOverlapped* nativeOverlapped)
{
if (IsEnabled(EventLevel.Verbose, Keywords.ThreadingKeyword))
{
#if TARGET_WINDOWS
IntPtr overlapped = ThreadPool.UseWindowsThreadPool ? 0 : (IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode();
#else
IntPtr overlapped = (IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode();
#endif
ThreadPoolIOPack(
(IntPtr)nativeOverlapped,
(IntPtr)Overlapped.GetOverlappedFromNative(nativeOverlapped).GetHashCode());
overlapped);
}
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
[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,
IntPtr Overlapped, // 0 if the Windows thread pool is used, the relevant info could be obtained from the NativeOverlapped* if necessary
ushort ClrInstanceID = DefaultClrInstanceId)
{
EventData* data = stackalloc EventData[3];
Expand Down

0 comments on commit ff80834

Please sign in to comment.