scheduler: Introduce strong and weak priority penalties
This commit is contained in:
@@ -164,7 +164,7 @@ scheduler_mode_operations gSchedulerLowLatencyMode = {
|
|||||||
100,
|
100,
|
||||||
{ 2, 25 },
|
{ 2, 25 },
|
||||||
|
|
||||||
50000,
|
10000,
|
||||||
|
|
||||||
switch_to_mode,
|
switch_to_mode,
|
||||||
set_cpu_enabled,
|
set_cpu_enabled,
|
||||||
|
|||||||
@@ -217,14 +217,14 @@ ThreadData::ComputeQuantum()
|
|||||||
quantum += fStolenTime;
|
quantum += fStolenTime;
|
||||||
fStolenTime = 0;
|
fStolenTime = 0;
|
||||||
|
|
||||||
int32 threadCount = (fCore->ThreadCount() + 1) / fCore->CPUCount();
|
int32 threadCount = fCore->ThreadCount() / fCore->CPUCount();
|
||||||
threadCount = max_c(threadCount, 1);
|
if (threadCount >= 1) {
|
||||||
|
quantum
|
||||||
quantum = std::min(gCurrentMode->maximum_latency / threadCount, quantum);
|
= std::min(gCurrentMode->maximum_latency / threadCount, quantum);
|
||||||
quantum = std::max(quantum, gCurrentMode->minimal_quantum);
|
quantum = std::max(quantum, gCurrentMode->minimal_quantum);
|
||||||
|
}
|
||||||
|
|
||||||
fTimeLeft = quantum;
|
fTimeLeft = quantum;
|
||||||
|
|
||||||
return quantum;
|
return quantum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,11 +44,11 @@ public:
|
|||||||
|
|
||||||
inline int32 GetEffectivePriority() const;
|
inline int32 GetEffectivePriority() const;
|
||||||
|
|
||||||
|
inline bool IsCPUBound() const;
|
||||||
|
|
||||||
inline void CancelPenalty();
|
inline void CancelPenalty();
|
||||||
inline bool ShouldCancelPenalty() const;
|
inline bool ShouldCancelPenalty() const;
|
||||||
|
|
||||||
inline bool IsCPUBound() const { return fAdditionalPenalty != 0; }
|
|
||||||
|
|
||||||
bool ChooseCoreAndCPU(CoreEntry*& targetCore,
|
bool ChooseCoreAndCPU(CoreEntry*& targetCore,
|
||||||
CPUEntry*& targetCPU);
|
CPUEntry*& targetCPU);
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ public:
|
|||||||
static void ComputeQuantumLengths();
|
static void ComputeQuantumLengths();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline void _IncreasePenalty();
|
inline void _IncreasePenalty(bool strong);
|
||||||
inline int32 _GetPenalty() const;
|
inline int32 _GetPenalty() const;
|
||||||
|
|
||||||
void _ComputeEffectivePriority() const;
|
void _ComputeEffectivePriority() const;
|
||||||
@@ -175,7 +175,7 @@ ThreadData::GetEffectivePriority() const
|
|||||||
|
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
ThreadData::_IncreasePenalty()
|
ThreadData::_IncreasePenalty(bool strong)
|
||||||
{
|
{
|
||||||
SCHEDULER_ENTER_FUNCTION();
|
SCHEDULER_ENTER_FUNCTION();
|
||||||
|
|
||||||
@@ -187,12 +187,14 @@ ThreadData::_IncreasePenalty()
|
|||||||
TRACE("increasing thread %ld penalty\n", fThread->id);
|
TRACE("increasing thread %ld penalty\n", fThread->id);
|
||||||
|
|
||||||
fReceivedPenalty = true;
|
fReceivedPenalty = true;
|
||||||
int32 oldPenalty = fPriorityPenalty++;
|
int32 oldPenalty = fPriorityPenalty;
|
||||||
|
if (strong)
|
||||||
|
fPriorityPenalty++;
|
||||||
|
|
||||||
ASSERT(fThread->priority - oldPenalty >= B_LOWEST_ACTIVE_PRIORITY);
|
ASSERT(fThread->priority - oldPenalty >= B_LOWEST_ACTIVE_PRIORITY);
|
||||||
|
|
||||||
const int kMinimalPriority = _GetMinimalPriority();
|
const int kMinimalPriority = _GetMinimalPriority();
|
||||||
if (fThread->priority - oldPenalty <= kMinimalPriority) {
|
if (!strong || fThread->priority - oldPenalty <= kMinimalPriority) {
|
||||||
fPriorityPenalty = oldPenalty;
|
fPriorityPenalty = oldPenalty;
|
||||||
fAdditionalPenalty++;
|
fAdditionalPenalty++;
|
||||||
}
|
}
|
||||||
@@ -201,6 +203,14 @@ ThreadData::_IncreasePenalty()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
ThreadData::IsCPUBound() const
|
||||||
|
{
|
||||||
|
SCHEDULER_ENTER_FUNCTION();
|
||||||
|
return fAdditionalPenalty != 0 && fPriorityPenalty != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
ThreadData::CancelPenalty()
|
ThreadData::CancelPenalty()
|
||||||
{
|
{
|
||||||
@@ -255,7 +265,7 @@ ThreadData::GoesAway()
|
|||||||
SCHEDULER_ENTER_FUNCTION();
|
SCHEDULER_ENTER_FUNCTION();
|
||||||
|
|
||||||
if (!fReceivedPenalty)
|
if (!fReceivedPenalty)
|
||||||
_IncreasePenalty();
|
_IncreasePenalty(false);
|
||||||
fHasSlept = true;
|
fHasSlept = true;
|
||||||
|
|
||||||
fLastInterruptTime = 0;
|
fLastInterruptTime = 0;
|
||||||
@@ -400,7 +410,7 @@ ThreadData::HasQuantumEnded(bool wasPreempted, bool hasYielded)
|
|||||||
|
|
||||||
if (fTimeLeft == 0) {
|
if (fTimeLeft == 0) {
|
||||||
if (!fReceivedPenalty && !fHasSlept)
|
if (!fReceivedPenalty && !fHasSlept)
|
||||||
_IncreasePenalty();
|
_IncreasePenalty(true);
|
||||||
fReceivedPenalty = false;
|
fReceivedPenalty = false;
|
||||||
fHasSlept = false;
|
fHasSlept = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user