scheduler: Improve should_rebalance
This commit is contained in:
@@ -84,14 +84,18 @@ should_rebalance(const ThreadData* threadData)
|
|||||||
if (threadData->GetLoad() >= coreLoad / 2)
|
if (threadData->GetLoad() >= coreLoad / 2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
int32 threadLoad = threadData->GetLoad();
|
||||||
|
int32 coreNewLoad = coreLoad - threadLoad;
|
||||||
|
|
||||||
// If there is high load on this core but this thread does not contribute
|
// If there is high load on this core but this thread does not contribute
|
||||||
// significantly consider giving it to someone less busy.
|
// significantly consider giving it to someone less busy.
|
||||||
if (coreLoad > kHighLoad) {
|
if (coreLoad > kHighLoad) {
|
||||||
ReadSpinLocker coreLocker(gCoreHeapsLock);
|
|
||||||
|
|
||||||
CoreEntry* other = gCoreLoadHeap.PeekMinimum();
|
CoreEntry* other = gCoreLoadHeap.PeekMinimum();
|
||||||
if (other != NULL && coreLoad - other->GetLoad() >= kLoadDifference)
|
if (other != NULL) {
|
||||||
return true;
|
int32 otherNewLoad = other->GetLoad() + threadLoad;
|
||||||
|
if (coreNewLoad - otherNewLoad >= kLoadDifference)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No cpu bound threads - the situation is quite good. Make sure it
|
// 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();
|
CoreEntry* other = gCoreLoadHeap.PeekMinimum();
|
||||||
if (other == NULL)
|
if (other == NULL)
|
||||||
other = gCoreHighLoadHeap.PeekMinimum();
|
other = gCoreHighLoadHeap.PeekMinimum();
|
||||||
ASSERT(other != NULL);
|
int32 otherNewLoad = other->GetLoad() + threadLoad;
|
||||||
return coreLoad - other->GetLoad() >= kLoadDifference * 2;
|
return coreNewLoad - otherNewLoad >= kLoadDifference * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -52,10 +52,7 @@ choose_small_task_core()
|
|||||||
{
|
{
|
||||||
SCHEDULER_ENTER_FUNCTION();
|
SCHEDULER_ENTER_FUNCTION();
|
||||||
|
|
||||||
ReadSpinLocker locker(gCoreHeapsLock);
|
|
||||||
CoreEntry* core = gCoreLoadHeap.PeekMaximum();
|
CoreEntry* core = gCoreLoadHeap.PeekMaximum();
|
||||||
locker.Unlock();
|
|
||||||
|
|
||||||
if (core == NULL)
|
if (core == NULL)
|
||||||
return sSmallTaskCore;
|
return sSmallTaskCore;
|
||||||
|
|
||||||
@@ -126,25 +123,28 @@ should_rebalance(const ThreadData* threadData)
|
|||||||
CoreEntry* core = threadData->Core();
|
CoreEntry* core = threadData->Core();
|
||||||
|
|
||||||
int32 coreLoad = core->GetLoad();
|
int32 coreLoad = core->GetLoad();
|
||||||
|
int32 threadLoad = threadData->GetLoad();
|
||||||
if (coreLoad > kHighLoad) {
|
if (coreLoad > kHighLoad) {
|
||||||
ReadSpinLocker coreLocker(gCoreHeapsLock);
|
|
||||||
if (sSmallTaskCore == core) {
|
if (sSmallTaskCore == core) {
|
||||||
sSmallTaskCore = NULL;
|
sSmallTaskCore = NULL;
|
||||||
choose_small_task_core();
|
choose_small_task_core();
|
||||||
|
|
||||||
if (threadData->GetLoad() > coreLoad / 3)
|
if (threadLoad > coreLoad / 3)
|
||||||
return false;
|
return false;
|
||||||
return coreLoad > kVeryHighLoad;
|
return coreLoad > kVeryHighLoad;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (threadData->GetLoad() >= coreLoad / 2)
|
if (threadLoad >= coreLoad / 2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
CoreEntry* other = gCoreLoadHeap.PeekMaximum();
|
CoreEntry* other = gCoreLoadHeap.PeekMaximum();
|
||||||
if (other == NULL)
|
if (other == NULL)
|
||||||
other = gCoreHighLoadHeap.PeekMinimum();
|
other = gCoreHighLoadHeap.PeekMinimum();
|
||||||
ASSERT(other != NULL);
|
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)
|
if (coreLoad >= kMediumLoad)
|
||||||
@@ -154,7 +154,7 @@ should_rebalance(const ThreadData* threadData)
|
|||||||
if (smallTaskCore == NULL)
|
if (smallTaskCore == NULL)
|
||||||
return false;
|
return false;
|
||||||
return smallTaskCore != core
|
return smallTaskCore != core
|
||||||
&& smallTaskCore->GetLoad() +threadData->GetLoad() < kHighLoad;
|
&& smallTaskCore->GetLoad() + threadLoad < kHighLoad;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user