diff --git a/src/system/kernel/scheduler/scheduler.cpp b/src/system/kernel/scheduler/scheduler.cpp index 557344dc73..2a4dbb12e7 100644 --- a/src/system/kernel/scheduler/scheduler.cpp +++ b/src/system/kernel/scheduler/scheduler.cpp @@ -388,7 +388,7 @@ reschedule(int32 nextState) case B_THREAD_READY: enqueueOldThread = true; - if (!thread_is_idle_thread(oldThread)) { + if (!oldThreadData->IsIdle()) { oldThreadData->Continues(); if (oldThreadData->HasQuantumEnded(oldThread->cpu->preempted, oldThread->has_yielded)) { @@ -425,7 +425,7 @@ reschedule(int32 nextState) // select thread with the biggest priority and enqueue back the old thread ThreadData* nextThreadData; if (gCPU[thisCPU].disabled) { - if (!thread_is_idle_thread(oldThread)) { + if (!oldThreadData->IsIdle()) { CPURunQueueLocker _(cpu); nextThreadData = cpu->PeekIdleThread(); @@ -446,7 +446,7 @@ reschedule(int32 nextState) } Thread* nextThread = nextThreadData->GetThread(); - ASSERT(!gCPU[thisCPU].disabled || thread_is_idle_thread(nextThread)); + ASSERT(!gCPU[thisCPU].disabled || nextThreadData->IsIdle()); if (nextThread != oldThread) { if (enqueueOldThread) { @@ -483,7 +483,7 @@ reschedule(int32 nextState) cancel_timer(quantumTimer); oldThread->cpu->preempted = false; - if (!thread_is_idle_thread(nextThread)) { + if (!nextThreadData->IsIdle()) { bigtime_t quantum = nextThreadData->GetQuantumLeft(); add_timer(quantumTimer, &reschedule_event, quantum, B_ONE_SHOT_RELATIVE_TIMER); diff --git a/src/system/kernel/scheduler/scheduler_thread.cpp b/src/system/kernel/scheduler/scheduler_thread.cpp index ca6fada228..795fd9f730 100644 --- a/src/system/kernel/scheduler/scheduler_thread.cpp +++ b/src/system/kernel/scheduler/scheduler_thread.cpp @@ -17,7 +17,7 @@ ThreadData::_InitBase() { fPriorityPenalty = 0; fAdditionalPenalty = 0; - fEffectivePriority = fThread->priority; + fEffectivePriority = GetPriority(); fTimeUsed = 0; fStolenTime = 0; @@ -107,9 +107,9 @@ ThreadData::Init() ThreadData* currentThreadData = currentThread->scheduler_data; fCore = currentThreadData->fCore; - if (fThread->priority < B_FIRST_REAL_TIME_PRIORITY) { + if (!IsRealTime()) { fPriorityPenalty = std::min(currentThreadData->fPriorityPenalty, - std::max(fThread->priority - _GetMinimalPriority(), int32(0))); + std::max(GetPriority() - _GetMinimalPriority(), int32(0))); fAdditionalPenalty = currentThreadData->fAdditionalPenalty; _ComputeEffectivePriority(); @@ -190,7 +190,7 @@ ThreadData::ComputeQuantum() const SCHEDULER_ENTER_FUNCTION(); bigtime_t quantum = _GetBaseQuantum(); - if (fThread->priority >= B_FIRST_REAL_TIME_PRIORITY) + if (IsRealTime()) return quantum; int32 threadCount = fCore->ThreadCount() / fCore->CPUCount(); @@ -260,12 +260,12 @@ ThreadData::_ComputeEffectivePriority() const { SCHEDULER_ENTER_FUNCTION(); - if (thread_is_idle_thread(fThread)) + if (IsIdle()) fEffectivePriority = B_IDLE_PRIORITY; - else if (fThread->priority >= B_FIRST_REAL_TIME_PRIORITY) - fEffectivePriority = fThread->priority; + else if (IsRealTime()) + fEffectivePriority = GetPriority(); else { - fEffectivePriority = fThread->priority; + fEffectivePriority = GetPriority(); fEffectivePriority -= _GetPenalty(); if (fEffectivePriority > 0) fEffectivePriority -= fAdditionalPenalty % fEffectivePriority; diff --git a/src/system/kernel/scheduler/scheduler_thread.h b/src/system/kernel/scheduler/scheduler_thread.h index af5cd25791..6e09314968 100644 --- a/src/system/kernel/scheduler/scheduler_thread.h +++ b/src/system/kernel/scheduler/scheduler_thread.h @@ -39,6 +39,12 @@ public: 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 ShouldRebalance() const; @@ -77,7 +83,6 @@ public: inline bool IsEnqueued() const { return fEnqueued; } inline void SetDequeued() { fEnqueued = false; } - inline Thread* GetThread() const { return fThread; } inline int32 GetLoad() const { return fNeededLoad; } inline CoreEntry* Core() const { return fCore; } @@ -145,11 +150,25 @@ ThreadData::_GetMinimalPriority() const const int32 kMaximalPriority = 25; const int32 kMinimalPriority = B_LOWEST_ACTIVE_PRIORITY; - int32 priority = fThread->priority / kDivisor; + int32 priority = GetPriority() / kDivisor; 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 ThreadData::HasCacheExpired() const { @@ -181,16 +200,14 @@ ThreadData::_IncreasePenalty() { SCHEDULER_ENTER_FUNCTION(); - if (fThread->priority < B_LOWEST_ACTIVE_PRIORITY) - return; - if (fThread->priority >= B_FIRST_REAL_TIME_PRIORITY) + if (IsIdle() || IsRealTime()) return; TRACE("increasing thread %ld penalty\n", fThread->id); int32 oldPenalty = fPriorityPenalty++; const int kMinimalPriority = _GetMinimalPriority(); - if (fThread->priority - oldPenalty <= kMinimalPriority) + if (GetPriority() - oldPenalty <= kMinimalPriority) fPriorityPenalty = oldPenalty; _ComputeEffectivePriority(); @@ -201,7 +218,7 @@ inline bool ThreadData::IsCPUBound() const { SCHEDULER_ENTER_FUNCTION(); - return GetThread()->priority - fPriorityPenalty == _GetMinimalPriority(); + return GetPriority() - fPriorityPenalty == _GetMinimalPriority(); }