scheduler: Introduce strong and weak priority penalties

This commit is contained in:
Pawel Dziepak 2014-01-08 07:03:22 +01:00
parent d36098e043
commit 772331c7cd
3 changed files with 25 additions and 15 deletions

View File

@ -164,7 +164,7 @@ scheduler_mode_operations gSchedulerLowLatencyMode = {
100,
{ 2, 25 },
50000,
10000,
switch_to_mode,
set_cpu_enabled,

View File

@ -217,14 +217,14 @@ ThreadData::ComputeQuantum()
quantum += fStolenTime;
fStolenTime = 0;
int32 threadCount = (fCore->ThreadCount() + 1) / fCore->CPUCount();
threadCount = max_c(threadCount, 1);
quantum = std::min(gCurrentMode->maximum_latency / threadCount, quantum);
quantum = std::max(quantum, gCurrentMode->minimal_quantum);
int32 threadCount = fCore->ThreadCount() / fCore->CPUCount();
if (threadCount >= 1) {
quantum
= std::min(gCurrentMode->maximum_latency / threadCount, quantum);
quantum = std::max(quantum, gCurrentMode->minimal_quantum);
}
fTimeLeft = quantum;
return quantum;
}

View File

@ -44,11 +44,11 @@ public:
inline int32 GetEffectivePriority() const;
inline bool IsCPUBound() const;
inline void CancelPenalty();
inline bool ShouldCancelPenalty() const;
inline bool IsCPUBound() const { return fAdditionalPenalty != 0; }
bool ChooseCoreAndCPU(CoreEntry*& targetCore,
CPUEntry*& targetCPU);
@ -85,7 +85,7 @@ public:
static void ComputeQuantumLengths();
private:
inline void _IncreasePenalty();
inline void _IncreasePenalty(bool strong);
inline int32 _GetPenalty() const;
void _ComputeEffectivePriority() const;
@ -175,7 +175,7 @@ ThreadData::GetEffectivePriority() const
inline void
ThreadData::_IncreasePenalty()
ThreadData::_IncreasePenalty(bool strong)
{
SCHEDULER_ENTER_FUNCTION();
@ -187,12 +187,14 @@ ThreadData::_IncreasePenalty()
TRACE("increasing thread %ld penalty\n", fThread->id);
fReceivedPenalty = true;
int32 oldPenalty = fPriorityPenalty++;
int32 oldPenalty = fPriorityPenalty;
if (strong)
fPriorityPenalty++;
ASSERT(fThread->priority - oldPenalty >= B_LOWEST_ACTIVE_PRIORITY);
const int kMinimalPriority = _GetMinimalPriority();
if (fThread->priority - oldPenalty <= kMinimalPriority) {
if (!strong || fThread->priority - oldPenalty <= kMinimalPriority) {
fPriorityPenalty = oldPenalty;
fAdditionalPenalty++;
}
@ -201,6 +203,14 @@ ThreadData::_IncreasePenalty()
}
inline bool
ThreadData::IsCPUBound() const
{
SCHEDULER_ENTER_FUNCTION();
return fAdditionalPenalty != 0 && fPriorityPenalty != 0;
}
inline void
ThreadData::CancelPenalty()
{
@ -255,7 +265,7 @@ ThreadData::GoesAway()
SCHEDULER_ENTER_FUNCTION();
if (!fReceivedPenalty)
_IncreasePenalty();
_IncreasePenalty(false);
fHasSlept = true;
fLastInterruptTime = 0;
@ -400,7 +410,7 @@ ThreadData::HasQuantumEnded(bool wasPreempted, bool hasYielded)
if (fTimeLeft == 0) {
if (!fReceivedPenalty && !fHasSlept)
_IncreasePenalty();
_IncreasePenalty(true);
fReceivedPenalty = false;
fHasSlept = false;
}