scheduler: Keep thread effective priority cached

This commit is contained in:
Pawel Dziepak
2013-12-23 22:06:33 +01:00
parent b24ea642d7
commit ede552ab25
2 changed files with 29 additions and 13 deletions
@@ -22,6 +22,7 @@ ThreadData::Init()
{ {
fPriorityPenalty = 0; fPriorityPenalty = 0;
fAdditionalPenalty = 0; fAdditionalPenalty = 0;
fEffectivePriority = -1;
fTimeLeft = 0; fTimeLeft = 0;
fStolenTime = 0; fStolenTime = 0;
@@ -121,6 +122,23 @@ ThreadData::ComputeQuantum()
} }
void
ThreadData::_ComputeEffectivePriority() const
{
if (thread_is_idle_thread(fThread))
fEffectivePriority = B_IDLE_PRIORITY;
else if (fThread->priority >= B_FIRST_REAL_TIME_PRIORITY)
fEffectivePriority = fThread->priority;
else {
fEffectivePriority = fThread->priority;
fEffectivePriority -= _GetPenalty();
ASSERT(fEffectivePriority < B_FIRST_REAL_TIME_PRIORITY);
ASSERT(fEffectivePriority >= B_LOWEST_ACTIVE_PRIORITY);
}
}
inline CoreEntry* inline CoreEntry*
ThreadData::_ChooseCore() const ThreadData::_ChooseCore() const
{ {
+11 -13
View File
@@ -74,6 +74,8 @@ private:
inline int32 _GetPenalty() const; inline int32 _GetPenalty() const;
inline int32 _GetMinimalPriority() const; inline int32 _GetMinimalPriority() const;
void _ComputeEffectivePriority() const;
inline CoreEntry* _ChooseCore() const; inline CoreEntry* _ChooseCore() const;
inline CPUEntry* _ChooseCPU(CoreEntry* core, inline CPUEntry* _ChooseCPU(CoreEntry* core,
bool& rescheduleNeeded) const; bool& rescheduleNeeded) const;
@@ -98,6 +100,8 @@ private:
int32 fPriorityPenalty; int32 fPriorityPenalty;
int32 fAdditionalPenalty; int32 fAdditionalPenalty;
mutable int32 fEffectivePriority;
bigtime_t fTimeLeft; bigtime_t fTimeLeft;
bigtime_t fMeasureActiveTime; bigtime_t fMeasureActiveTime;
@@ -133,18 +137,9 @@ ThreadData::ShouldRebalance() const
inline int32 inline int32
ThreadData::GetEffectivePriority() const ThreadData::GetEffectivePriority() const
{ {
if (thread_is_idle_thread(fThread)) if (fEffectivePriority == -1)
return B_IDLE_PRIORITY; _ComputeEffectivePriority();
if (fThread->priority >= B_FIRST_REAL_TIME_PRIORITY) return fEffectivePriority;
return fThread->priority;
int32 effectivePriority = fThread->priority;
effectivePriority -= _GetPenalty();
ASSERT(effectivePriority < B_FIRST_REAL_TIME_PRIORITY);
ASSERT(effectivePriority >= B_LOWEST_ACTIVE_PRIORITY);
return effectivePriority;
} }
@@ -158,6 +153,7 @@ ThreadData::IncreasePenalty()
TRACE("increasing thread %ld penalty\n", fThread->id); TRACE("increasing thread %ld penalty\n", fThread->id);
fEffectivePriority = -1;
int32 oldPenalty = fPriorityPenalty++; int32 oldPenalty = fPriorityPenalty++;
ASSERT(fThread->priority - oldPenalty >= B_LOWEST_ACTIVE_PRIORITY); ASSERT(fThread->priority - oldPenalty >= B_LOWEST_ACTIVE_PRIORITY);
@@ -173,8 +169,10 @@ ThreadData::IncreasePenalty()
inline void inline void
ThreadData::CancelPenalty() ThreadData::CancelPenalty()
{ {
if (fPriorityPenalty != 0) if (fPriorityPenalty != 0) {
TRACE("cancelling thread %ld penalty\n", fThread->id); TRACE("cancelling thread %ld penalty\n", fThread->id);
fEffectivePriority = -1;
}
fAdditionalPenalty = 0; fAdditionalPenalty = 0;
fPriorityPenalty = 0; fPriorityPenalty = 0;