From 6875fab0a4e7b8aa92fc1ed67ece3277588b20ef Mon Sep 17 00:00:00 2001 From: Sung Yoon Whang Date: Mon, 7 Dec 2020 01:25:39 -0800 Subject: [PATCH] Make PortableThreadPool to check events correctly before firing them --- .../System/Threading/PortableThreadPool.HillClimbing.cs | 7 ++++--- .../src/System/Threading/PortableThreadPool.WaitThread.cs | 5 +++-- .../System/Threading/PortableThreadPool.WorkerThread.cs | 8 +++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.HillClimbing.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.HillClimbing.cs index c7ed0ee800c934..0275e617f15428 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.HillClimbing.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.HillClimbing.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.Tracing; namespace System.Threading { @@ -169,7 +170,7 @@ public HillClimbing() // Add the current thread count and throughput sample to our history // double throughput = numCompletions / sampleDurationSeconds; - if (PortableThreadPoolEventSource.Log.IsEnabled()) + if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Informational, PortableThreadPoolEventSource.Keywords.ThreadingKeyword)) { PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadAdjustmentSample(throughput); } @@ -343,7 +344,7 @@ public HillClimbing() // Record these numbers for posterity // - if (PortableThreadPoolEventSource.Log.IsEnabled()) + if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Verbose, PortableThreadPoolEventSource.Keywords.ThreadingKeyword)) { PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadAdjustmentStats(sampleDurationSeconds, throughput, threadWaveComponent.Real, throughputWaveComponent.Real, throughputErrorEstimate, _averageThroughputNoise, ratio.Real, confidence, _currentControlSetting, (ushort)newThreadWaveMagnitude); @@ -404,7 +405,7 @@ private void LogTransition(int newThreadCount, double throughput, StateOrTransit _logSize++; - if (PortableThreadPoolEventSource.Log.IsEnabled()) + if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Informational, PortableThreadPoolEventSource.Keywords.ThreadingKeyword)) { PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadAdjustmentAdjustment( throughput, diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs index ed091b9d8fa921..2eb692706419d6 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.Tracing; using Microsoft.Win32.SafeHandles; namespace System.Threading @@ -36,7 +37,7 @@ internal partial class PortableThreadPool /// A description of the requested registration. internal void RegisterWaitHandle(RegisteredWaitHandle handle) { - if (PortableThreadPoolEventSource.Log.IsEnabled()) + if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Verbose, PortableThreadPoolEventSource.Keywords.ThreadingKeyword)) { PortableThreadPoolEventSource.Log.ThreadPoolIOEnqueue(handle); } @@ -75,7 +76,7 @@ internal void RegisterWaitHandle(RegisteredWaitHandle handle) internal static void CompleteWait(RegisteredWaitHandle handle, bool timedOut) { - if (PortableThreadPoolEventSource.Log.IsEnabled()) + if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Verbose, PortableThreadPoolEventSource.Keywords.ThreadingKeyword)) { PortableThreadPoolEventSource.Log.ThreadPoolIODequeue(handle); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs index 4b7e3694c43dcb..ef1b905cf3bd98 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.Tracing; + namespace System.Threading { internal partial class PortableThreadPool @@ -20,7 +22,7 @@ private static class WorkerThread AppContextConfigHelper.GetInt32Config("System.Threading.ThreadPool.UnfairSemaphoreSpinLimit", 70, false), onWait: () => { - if (PortableThreadPoolEventSource.Log.IsEnabled()) + if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Informational, PortableThreadPoolEventSource.Keywords.ThreadingKeyword)) { PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadWait( (uint)ThreadPoolInstance._separated.counts.VolatileRead().NumExistingThreads); @@ -33,7 +35,7 @@ private static void WorkerThreadStart() PortableThreadPool threadPoolInstance = ThreadPoolInstance; - if (PortableThreadPoolEventSource.Log.IsEnabled()) + if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Informational, PortableThreadPoolEventSource.Keywords.ThreadingKeyword)) { PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadStart( (uint)threadPoolInstance._separated.counts.VolatileRead().NumExistingThreads); @@ -105,7 +107,7 @@ private static void WorkerThreadStart() { HillClimbing.ThreadPoolHillClimber.ForceChange(newNumThreadsGoal, HillClimbing.StateOrTransition.ThreadTimedOut); - if (PortableThreadPoolEventSource.Log.IsEnabled()) + if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Informational, PortableThreadPoolEventSource.Keywords.ThreadingKeyword)) { PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadStop((uint)newNumExistingThreads); }