Skip to content

Commit 21d3425

Browse files
author
John Salem
authored
Minimal version of #67150 (#68876)
1 parent 3743f5e commit 21d3425

File tree

5 files changed

+43
-8
lines changed

5 files changed

+43
-8
lines changed

src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ private static class Messages
4949
{
5050
public const EventOpcode IOEnqueue = (EventOpcode)13;
5151
public const EventOpcode IODequeue = (EventOpcode)14;
52+
public const EventOpcode IOPack = (EventOpcode)15;
5253
public const EventOpcode Wait = (EventOpcode)90;
5354
public const EventOpcode Sample = (EventOpcode)100;
5455
public const EventOpcode Adjustment = (EventOpcode)101;
@@ -204,5 +205,17 @@ public unsafe void ThreadPoolWorkingThreadCount(uint Count, ushort ClrInstanceID
204205
}
205206
LogThreadPoolWorkingThreadCount(Count, ClrInstanceID);
206207
}
208+
209+
[Event(65, Level = EventLevel.Verbose, Message = Messages.IO, Task = Tasks.ThreadPool, Opcode = Opcodes.IOPack, Version = 0, Keywords = Keywords.ThreadingKeyword)]
210+
private unsafe void ThreadPoolIOPack(
211+
IntPtr NativeOverlapped,
212+
IntPtr Overlapped,
213+
ushort ClrInstanceID = DefaultClrInstanceId)
214+
{
215+
// In .NET 6, this event is exclusively fired in CoreCLR from a QCALL.
216+
// This function only needs to exist for the EventSource to generate metadata
217+
// for in-process EventListeners. It will not be called.
218+
throw new NotImplementedException();
219+
}
207220
}
208221
}

src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ private static class Messages
5151
{
5252
public const EventOpcode IOEnqueue = (EventOpcode)13;
5353
public const EventOpcode IODequeue = (EventOpcode)14;
54+
public const EventOpcode IOPack = (EventOpcode)15;
5455
public const EventOpcode Wait = (EventOpcode)90;
5556
public const EventOpcode Sample = (EventOpcode)100;
5657
public const EventOpcode Adjustment = (EventOpcode)101;

src/tests/issues.targets

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,10 @@
960960

961961
<!-- Known failures for mono runtime on *all* architectures/operating systems in *all* runtime modes -->
962962
<ItemGroup Condition="'$(RuntimeFlavor)' == 'mono'" >
963+
<ExcludeList Include = "$(XunitTestBinBase)/tracing/runtimeeventsource/nativeruntimeeventsource/*">
964+
<Issue>https://github.com/dotnet/runtime/issues/68032</Issue>
965+
</ExcludeList>
966+
963967
<ExcludeList Include = "$(XunitTestBinBase)/reflection/GenericAttribute/**">
964968
<Issue>https://github.com/dotnet/runtime/issues/56887</Issue>
965969
</ExcludeList>

src/tests/tracing/runtimeeventsource/NativeRuntimeEventSourceTest.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
using System.IO;
66
using System.Diagnostics.Tracing;
77
using System.Runtime.CompilerServices;
8+
using System.Runtime.InteropServices;
89
using System.Threading;
10+
using System.Threading.Tasks;
911
using Tracing.Tests.Common;
12+
using System.Collections.Generic;
1013

1114
namespace Tracing.Tests
1215
{
@@ -22,7 +25,11 @@ static int Main(string[] args)
2225
using (SimpleEventListener listener = new SimpleEventListener("Simple"))
2326
{
2427
// Trigger the allocator task.
25-
System.Threading.Tasks.Task.Run(new Action(Allocator));
28+
Task.Run(new Action(Allocator));
29+
30+
// If on Windows, attempt some Overlapped IO (triggers ThreadPool events)
31+
if (OperatingSystem.IsWindows())
32+
DoOverlappedIO();
2633

2734
// Wait for events.
2835
Thread.Sleep(1000);
@@ -34,7 +41,11 @@ static int Main(string[] args)
3441
Thread.Sleep(1000);
3542

3643
// Ensure that we've seen some events.
44+
foreach (string s in listener.SeenProvidersAndEvents)
45+
Console.WriteLine(s);
3746
Assert.True("listener.EventCount > 0", listener.EventCount > 0);
47+
if (OperatingSystem.IsWindows())
48+
Assert.True("Saw the ThreadPoolIOPack event", listener.SeenProvidersAndEvents.Contains("Microsoft-Windows-DotNETRuntime/EVENTID(65)"));
3849
}
3950

4051
// Generate some more GC events.
@@ -57,10 +68,19 @@ private static void Allocator()
5768
Thread.Sleep(10);
5869
}
5970
}
71+
72+
private static unsafe void DoOverlappedIO()
73+
{
74+
Console.WriteLine("DOOVERLAPPEDIO");
75+
Overlapped overlapped = new();
76+
NativeOverlapped* pOverlap = overlapped.Pack(null, null);
77+
Overlapped.Free(pOverlap);
78+
}
6079
}
6180

6281
internal sealed class SimpleEventListener : EventListener
6382
{
83+
public HashSet<string> SeenProvidersAndEvents { get; private set; } = new();
6484
private string m_name;
6585

6686
// Keep track of the set of keywords to be enabled.
@@ -108,6 +128,9 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData)
108128
}
109129
Console.WriteLine("\n");
110130

131+
SeenProvidersAndEvents.Add($"{eventData.EventSource.Name}");
132+
SeenProvidersAndEvents.Add($"{eventData.EventSource.Name}/EVENTID({eventData.EventId})");
133+
111134
EventCount++;
112135
}
113136
}

src/tests/tracing/runtimeeventsource/nativeruntimeeventsource.csproj

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,9 @@
77
<GCStressIncompatible>true</GCStressIncompatible>
88
<!-- This test has a secondary thread with an infinite loop -->
99
<UnloadabilityIncompatible>true</UnloadabilityIncompatible>
10-
<!--
11-
Test is blocking official build.
12-
Related failures: #18907, #19340, #22441, #22729.
13-
Issue tracking to re-enable: #22898.
14-
-->
15-
<DisableProjectBuild>true</DisableProjectBuild>
1610
</PropertyGroup>
1711
<ItemGroup>
18-
<Compile Include="RuntimeEventSourceTest.cs" />
12+
<Compile Include="NativeRuntimeEventSourceTest.cs" />
1913
<ProjectReference Include="../common/common.csproj" />
2014
</ItemGroup>
2115
</Project>

0 commit comments

Comments
 (0)