Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.
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 @@ -88,8 +88,8 @@ private struct LogEntry
private readonly Random _randomIntervalGenerator = new Random();

private readonly LogEntry[] _log = new LogEntry[LogCapacity];
private int _logStart = 0;
private int _logSize = 0;
private int _logStart;
private int _logSize;

public HillClimbing(int wavePeriod, int maxWaveMagnitude, double waveMagnitudeMultiplier, int waveHistorySize, double targetThroughputRatio,
double targetSignalToNoiseRatio, double maxChangePerSecond, double maxChangePerSample, int sampleIntervalMsLow, int sampleIntervalMsHigh,
Expand Down Expand Up @@ -184,8 +184,11 @@ public HillClimbing(int wavePeriod, int maxWaveMagnitude, double waveMagnitudeMu
// Add the current thread count and throughput sample to our history
//
double throughput = numCompletions / sampleDurationSeconds;

PortableThreadPoolEventSource.Log.WorkerThreadAdjustmentSample(throughput);
PortableThreadPoolEventSource log = PortableThreadPoolEventSource.Log;
if (log.IsEnabled())
{
log.WorkerThreadAdjustmentSample(throughput);
}

int sampleIndex = (int)(_totalSamples % _samplesToMeasure);
_samples[sampleIndex] = throughput;
Expand Down Expand Up @@ -355,8 +358,11 @@ public HillClimbing(int wavePeriod, int maxWaveMagnitude, double waveMagnitudeMu
// Record these numbers for posterity
//

PortableThreadPoolEventSource.Log.WorkerThreadAdjustmentStats(sampleDurationSeconds, throughput, threadWaveComponent.Real, throughputWaveComponent.Real,
if (log.IsEnabled())
{
log.WorkerThreadAdjustmentStats(sampleDurationSeconds, throughput, threadWaveComponent.Real, throughputWaveComponent.Real,
throughputErrorEstimate, _averageThroughputNoise, ratio.Real, confidence, _currentControlSetting, (ushort)newThreadWaveMagnitude);
}


//
Expand Down Expand Up @@ -413,7 +419,11 @@ private void LogTransition(int newThreadCount, double throughput, StateOrTransit

_logSize++;

PortableThreadPoolEventSource.Log.WorkerThreadAdjustmentAdjustment(throughput, newThreadCount, (int)stateOrTransition);
PortableThreadPoolEventSource log = PortableThreadPoolEventSource.Log;
if (log.IsEnabled())
{
log.WorkerThreadAdjustmentAdjustment(throughput, newThreadCount, (int)stateOrTransition);
}
}

public void ForceChange(int newThreadCount, StateOrTransition state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public CompletedWaitHandle(RegisteredWaitHandle completedHandle, bool timedOut)
/// <summary>
/// The number of user-registered waits on this wait thread.
/// </summary>
private int _numUserWaits = 0;
private int _numUserWaits;

/// <summary>
/// A list of removals of wait handles that are waiting for the wait thread to process.
Expand All @@ -159,7 +159,7 @@ public CompletedWaitHandle(RegisteredWaitHandle completedHandle, bool timedOut)
/// <summary>
/// The number of pending removals.
/// </summary>
private int _numPendingRemoves = 0;
private int _numPendingRemoves;

/// <summary>
/// An event to notify the wait thread that there are pending adds or removals of wait handles so it needs to wake up.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ private static int SemaphoreSpinCount

private static void WorkerThreadStart()
{
PortableThreadPoolEventSource.Log.WorkerThreadStart(ThreadCounts.VolatileReadCounts(ref ThreadPoolInstance._separated.counts).numExistingThreads);
PortableThreadPoolEventSource log = PortableThreadPoolEventSource.Log;
if (log.IsEnabled())
{
log.WorkerThreadStart(ThreadCounts.VolatileReadCounts(ref ThreadPoolInstance._separated.counts).numExistingThreads);
}

while (true)
{
Expand Down Expand Up @@ -70,7 +74,11 @@ private static void WorkerThreadStart()
if (oldCounts == counts)
{
HillClimbing.ThreadPoolHillClimber.ForceChange(newCounts.numThreadsGoal, HillClimbing.StateOrTransition.ThreadTimedOut);
PortableThreadPoolEventSource.Log.WorkerThreadStop(newCounts.numExistingThreads);

if (log.IsEnabled())
{
log.WorkerThreadStop(newCounts.numExistingThreads);
}
return;
}
}
Expand All @@ -88,7 +96,11 @@ private static void WorkerThreadStart()
/// <returns>If this thread was woken up before it timed out.</returns>
private static bool WaitForRequest()
{
PortableThreadPoolEventSource.Log.WorkerThreadWait(ThreadCounts.VolatileReadCounts(ref ThreadPoolInstance._separated.counts).numExistingThreads);
PortableThreadPoolEventSource log = PortableThreadPoolEventSource.Log;
if (log.IsEnabled())
{
log.WorkerThreadWait(ThreadCounts.VolatileReadCounts(ref ThreadPoolInstance._separated.counts).numExistingThreads);
}
return s_semaphore.Wait(ThreadPoolThreadTimeoutMs);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal sealed partial class PortableThreadPool

private const int CpuUtilizationHigh = 95;
private const int CpuUtilizationLow = 80;
private int _cpuUtilization = 0;
private int _cpuUtilization;

private static readonly short s_forcedMinWorkerThreads = AppContextConfigHelper.GetInt16Config("System.Threading.ThreadPool.MinThreads", 0, false);
private static readonly short s_forcedMaxWorkerThreads = AppContextConfigHelper.GetInt16Config("System.Threading.ThreadPool.MaxThreads", 0, false);
Expand Down Expand Up @@ -63,7 +63,7 @@ private struct CacheLineSeparated

private readonly LowLevelLock _hillClimbingThreadAdjustmentLock = new LowLevelLock();

private volatile int _numRequestedWorkers = 0;
private volatile int _numRequestedWorkers;

private PortableThreadPool()
{
Expand Down