From 0012ba6a87f1286164160b6d14516e4bad0f63c3 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Sun, 9 Mar 2014 15:52:59 +0100 Subject: [PATCH] scheduler/low_latency: Try harder to balance load In low latency mode the scheduler would not attempt to balance load on not heavily loaded cores unless difference in load exceeded kLoadDifference * 2 (i.e. 40 percentage points), which does not seem to be good enough. --- src/system/kernel/scheduler/low_latency.cpp | 23 +++++++++------------ 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/system/kernel/scheduler/low_latency.cpp b/src/system/kernel/scheduler/low_latency.cpp index af286997e2..bca90fd0b5 100644 --- a/src/system/kernel/scheduler/low_latency.cpp +++ b/src/system/kernel/scheduler/low_latency.cpp @@ -85,29 +85,26 @@ should_rebalance(const ThreadData* threadData) if (threadLoad >= coreLoad / 2) return false; - int32 coreNewLoad = coreLoad - threadLoad; - + // Get the least loaded core. ReadSpinLocker coreLocker(gCoreHeapsLock); CoreEntry* other = gCoreLoadHeap.PeekMinimum(); if (other == NULL) other = gCoreHighLoadHeap.PeekMinimum(); coreLocker.Unlock(); - ASSERT(other != NULL); - int32 otherNewLoad = other->GetLoad() + threadLoad; - // If there is high load on this core but this thread does not contribute - // significantly consider giving it to someone less busy. - if (coreLoad > kHighLoad) { - if (coreNewLoad - otherNewLoad >= kLoadDifference) - return true; - } + if (other == threadData->Core()) + return false; - // No cpu bound threads - the situation is quite good. Make sure it - // won't get much worse... + // If there are idle cores give them some work unless that will cause + // the current core to become idle. + int32 coreNewLoad = coreLoad - threadLoad; if (other->GetLoad() == 0 && coreNewLoad != 0) return true; - return coreNewLoad - otherNewLoad >= kLoadDifference * 2; + + // Attempt to keep load balanced. + int32 otherNewLoad = other->GetLoad() + threadLoad; + return coreNewLoad - otherNewLoad >= kLoadDifference; }