scheduler: Add ThreadData::{GetPriority, IsIdle, IsRealTime}()

This commit is contained in:
Pawel Dziepak
2014-01-16 23:26:09 +01:00
parent 093c220267
commit b7d404c2df
3 changed files with 36 additions and 19 deletions
+4 -4
View File
@@ -388,7 +388,7 @@ reschedule(int32 nextState)
case B_THREAD_READY: case B_THREAD_READY:
enqueueOldThread = true; enqueueOldThread = true;
if (!thread_is_idle_thread(oldThread)) { if (!oldThreadData->IsIdle()) {
oldThreadData->Continues(); oldThreadData->Continues();
if (oldThreadData->HasQuantumEnded(oldThread->cpu->preempted, if (oldThreadData->HasQuantumEnded(oldThread->cpu->preempted,
oldThread->has_yielded)) { oldThread->has_yielded)) {
@@ -425,7 +425,7 @@ reschedule(int32 nextState)
// select thread with the biggest priority and enqueue back the old thread // select thread with the biggest priority and enqueue back the old thread
ThreadData* nextThreadData; ThreadData* nextThreadData;
if (gCPU[thisCPU].disabled) { if (gCPU[thisCPU].disabled) {
if (!thread_is_idle_thread(oldThread)) { if (!oldThreadData->IsIdle()) {
CPURunQueueLocker _(cpu); CPURunQueueLocker _(cpu);
nextThreadData = cpu->PeekIdleThread(); nextThreadData = cpu->PeekIdleThread();
@@ -446,7 +446,7 @@ reschedule(int32 nextState)
} }
Thread* nextThread = nextThreadData->GetThread(); Thread* nextThread = nextThreadData->GetThread();
ASSERT(!gCPU[thisCPU].disabled || thread_is_idle_thread(nextThread)); ASSERT(!gCPU[thisCPU].disabled || nextThreadData->IsIdle());
if (nextThread != oldThread) { if (nextThread != oldThread) {
if (enqueueOldThread) { if (enqueueOldThread) {
@@ -483,7 +483,7 @@ reschedule(int32 nextState)
cancel_timer(quantumTimer); cancel_timer(quantumTimer);
oldThread->cpu->preempted = false; oldThread->cpu->preempted = false;
if (!thread_is_idle_thread(nextThread)) { if (!nextThreadData->IsIdle()) {
bigtime_t quantum = nextThreadData->GetQuantumLeft(); bigtime_t quantum = nextThreadData->GetQuantumLeft();
add_timer(quantumTimer, &reschedule_event, quantum, add_timer(quantumTimer, &reschedule_event, quantum,
B_ONE_SHOT_RELATIVE_TIMER); B_ONE_SHOT_RELATIVE_TIMER);
@@ -17,7 +17,7 @@ ThreadData::_InitBase()
{ {
fPriorityPenalty = 0; fPriorityPenalty = 0;
fAdditionalPenalty = 0; fAdditionalPenalty = 0;
fEffectivePriority = fThread->priority; fEffectivePriority = GetPriority();
fTimeUsed = 0; fTimeUsed = 0;
fStolenTime = 0; fStolenTime = 0;
@@ -107,9 +107,9 @@ ThreadData::Init()
ThreadData* currentThreadData = currentThread->scheduler_data; ThreadData* currentThreadData = currentThread->scheduler_data;
fCore = currentThreadData->fCore; fCore = currentThreadData->fCore;
if (fThread->priority < B_FIRST_REAL_TIME_PRIORITY) { if (!IsRealTime()) {
fPriorityPenalty = std::min(currentThreadData->fPriorityPenalty, fPriorityPenalty = std::min(currentThreadData->fPriorityPenalty,
std::max(fThread->priority - _GetMinimalPriority(), int32(0))); std::max(GetPriority() - _GetMinimalPriority(), int32(0)));
fAdditionalPenalty = currentThreadData->fAdditionalPenalty; fAdditionalPenalty = currentThreadData->fAdditionalPenalty;
_ComputeEffectivePriority(); _ComputeEffectivePriority();
@@ -190,7 +190,7 @@ ThreadData::ComputeQuantum() const
SCHEDULER_ENTER_FUNCTION(); SCHEDULER_ENTER_FUNCTION();
bigtime_t quantum = _GetBaseQuantum(); bigtime_t quantum = _GetBaseQuantum();
if (fThread->priority >= B_FIRST_REAL_TIME_PRIORITY) if (IsRealTime())
return quantum; return quantum;
int32 threadCount = fCore->ThreadCount() / fCore->CPUCount(); int32 threadCount = fCore->ThreadCount() / fCore->CPUCount();
@@ -260,12 +260,12 @@ ThreadData::_ComputeEffectivePriority() const
{ {
SCHEDULER_ENTER_FUNCTION(); SCHEDULER_ENTER_FUNCTION();
if (thread_is_idle_thread(fThread)) if (IsIdle())
fEffectivePriority = B_IDLE_PRIORITY; fEffectivePriority = B_IDLE_PRIORITY;
else if (fThread->priority >= B_FIRST_REAL_TIME_PRIORITY) else if (IsRealTime())
fEffectivePriority = fThread->priority; fEffectivePriority = GetPriority();
else { else {
fEffectivePriority = fThread->priority; fEffectivePriority = GetPriority();
fEffectivePriority -= _GetPenalty(); fEffectivePriority -= _GetPenalty();
if (fEffectivePriority > 0) if (fEffectivePriority > 0)
fEffectivePriority -= fAdditionalPenalty % fEffectivePriority; fEffectivePriority -= fAdditionalPenalty % fEffectivePriority;
+24 -7
View File
@@ -39,6 +39,12 @@ public:
void Dump() const; void Dump() const;
inline int32 GetPriority() const { return fThread->priority; }
inline Thread* GetThread() const { return fThread; }
inline bool IsRealTime() const;
inline bool IsIdle() const;
inline bool HasCacheExpired() const; inline bool HasCacheExpired() const;
inline bool ShouldRebalance() const; inline bool ShouldRebalance() const;
@@ -77,7 +83,6 @@ public:
inline bool IsEnqueued() const { return fEnqueued; } inline bool IsEnqueued() const { return fEnqueued; }
inline void SetDequeued() { fEnqueued = false; } inline void SetDequeued() { fEnqueued = false; }
inline Thread* GetThread() const { return fThread; }
inline int32 GetLoad() const { return fNeededLoad; } inline int32 GetLoad() const { return fNeededLoad; }
inline CoreEntry* Core() const { return fCore; } inline CoreEntry* Core() const { return fCore; }
@@ -145,11 +150,25 @@ ThreadData::_GetMinimalPriority() const
const int32 kMaximalPriority = 25; const int32 kMaximalPriority = 25;
const int32 kMinimalPriority = B_LOWEST_ACTIVE_PRIORITY; const int32 kMinimalPriority = B_LOWEST_ACTIVE_PRIORITY;
int32 priority = fThread->priority / kDivisor; int32 priority = GetPriority() / kDivisor;
return std::max(std::min(priority, kMaximalPriority), kMinimalPriority); return std::max(std::min(priority, kMaximalPriority), kMinimalPriority);
} }
inline bool
ThreadData::IsRealTime() const
{
return GetPriority() >= B_FIRST_REAL_TIME_PRIORITY;
}
inline bool
ThreadData::IsIdle() const
{
return GetPriority() == B_IDLE_PRIORITY;
}
inline bool inline bool
ThreadData::HasCacheExpired() const ThreadData::HasCacheExpired() const
{ {
@@ -181,16 +200,14 @@ ThreadData::_IncreasePenalty()
{ {
SCHEDULER_ENTER_FUNCTION(); SCHEDULER_ENTER_FUNCTION();
if (fThread->priority < B_LOWEST_ACTIVE_PRIORITY) if (IsIdle() || IsRealTime())
return;
if (fThread->priority >= B_FIRST_REAL_TIME_PRIORITY)
return; return;
TRACE("increasing thread %ld penalty\n", fThread->id); TRACE("increasing thread %ld penalty\n", fThread->id);
int32 oldPenalty = fPriorityPenalty++; int32 oldPenalty = fPriorityPenalty++;
const int kMinimalPriority = _GetMinimalPriority(); const int kMinimalPriority = _GetMinimalPriority();
if (fThread->priority - oldPenalty <= kMinimalPriority) if (GetPriority() - oldPenalty <= kMinimalPriority)
fPriorityPenalty = oldPenalty; fPriorityPenalty = oldPenalty;
_ComputeEffectivePriority(); _ComputeEffectivePriority();
@@ -201,7 +218,7 @@ inline bool
ThreadData::IsCPUBound() const ThreadData::IsCPUBound() const
{ {
SCHEDULER_ENTER_FUNCTION(); SCHEDULER_ENTER_FUNCTION();
return GetThread()->priority - fPriorityPenalty == _GetMinimalPriority(); return GetPriority() - fPriorityPenalty == _GetMinimalPriority();
} }