From c37c2aa45fd02af0fa4941751bdabf5cbcc664d6 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Tue, 7 Jan 2014 01:09:56 +0100 Subject: [PATCH] scheduler: Improve should_rebalance --- src/system/kernel/scheduler/low_latency.cpp | 16 ++++++++++------ src/system/kernel/scheduler/power_saving.cpp | 16 ++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/system/kernel/scheduler/low_latency.cpp b/src/system/kernel/scheduler/low_latency.cpp index 42baee3325..09c6f719e8 100644 --- a/src/system/kernel/scheduler/low_latency.cpp +++ b/src/system/kernel/scheduler/low_latency.cpp @@ -84,14 +84,18 @@ should_rebalance(const ThreadData* threadData) if (threadData->GetLoad() >= coreLoad / 2) return false; + int32 threadLoad = threadData->GetLoad(); + int32 coreNewLoad = coreLoad - 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) { - ReadSpinLocker coreLocker(gCoreHeapsLock); - CoreEntry* other = gCoreLoadHeap.PeekMinimum(); - if (other != NULL && coreLoad - other->GetLoad() >= kLoadDifference) - return true; + if (other != NULL) { + int32 otherNewLoad = other->GetLoad() + threadLoad; + if (coreNewLoad - otherNewLoad >= kLoadDifference) + return true; + } } // No cpu bound threads - the situation is quite good. Make sure it @@ -101,8 +105,8 @@ should_rebalance(const ThreadData* threadData) CoreEntry* other = gCoreLoadHeap.PeekMinimum(); if (other == NULL) other = gCoreHighLoadHeap.PeekMinimum(); - ASSERT(other != NULL); - return coreLoad - other->GetLoad() >= kLoadDifference * 2; + int32 otherNewLoad = other->GetLoad() + threadLoad; + return coreNewLoad - otherNewLoad >= kLoadDifference * 2; } diff --git a/src/system/kernel/scheduler/power_saving.cpp b/src/system/kernel/scheduler/power_saving.cpp index 3b36add0c9..b41bbe7007 100644 --- a/src/system/kernel/scheduler/power_saving.cpp +++ b/src/system/kernel/scheduler/power_saving.cpp @@ -52,10 +52,7 @@ choose_small_task_core() { SCHEDULER_ENTER_FUNCTION(); - ReadSpinLocker locker(gCoreHeapsLock); CoreEntry* core = gCoreLoadHeap.PeekMaximum(); - locker.Unlock(); - if (core == NULL) return sSmallTaskCore; @@ -126,25 +123,28 @@ should_rebalance(const ThreadData* threadData) CoreEntry* core = threadData->Core(); int32 coreLoad = core->GetLoad(); + int32 threadLoad = threadData->GetLoad(); if (coreLoad > kHighLoad) { - ReadSpinLocker coreLocker(gCoreHeapsLock); if (sSmallTaskCore == core) { sSmallTaskCore = NULL; choose_small_task_core(); - if (threadData->GetLoad() > coreLoad / 3) + if (threadLoad > coreLoad / 3) return false; return coreLoad > kVeryHighLoad; } - if (threadData->GetLoad() >= coreLoad / 2) + if (threadLoad >= coreLoad / 2) return false; CoreEntry* other = gCoreLoadHeap.PeekMaximum(); if (other == NULL) other = gCoreHighLoadHeap.PeekMinimum(); ASSERT(other != NULL); - return coreLoad - other->GetLoad() >= kLoadDifference / 2; + + int32 coreNewLoad = coreLoad - threadLoad; + int32 otherNewLoad = other->GetLoad() + threadLoad; + return coreNewLoad - otherNewLoad >= kLoadDifference / 2; } if (coreLoad >= kMediumLoad) @@ -154,7 +154,7 @@ should_rebalance(const ThreadData* threadData) if (smallTaskCore == NULL) return false; return smallTaskCore != core - && smallTaskCore->GetLoad() +threadData->GetLoad() < kHighLoad; + && smallTaskCore->GetLoad() + threadLoad < kHighLoad; }