scheduler: Encapsulate ThreadData fields
This commit is contained in:
@@ -38,7 +38,7 @@ has_cache_expired(const ThreadData* threadData)
|
|||||||
CoreEntry* core = threadData->Core();
|
CoreEntry* core = threadData->Core();
|
||||||
|
|
||||||
bigtime_t activeTime = core->GetActiveTime();
|
bigtime_t activeTime = core->GetActiveTime();
|
||||||
return activeTime - threadData->fWentSleepActive > kCacheExpire;
|
return activeTime - threadData->WentSleepActive() > kCacheExpire;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ has_cache_expired(const ThreadData* threadData)
|
|||||||
{
|
{
|
||||||
ASSERT(!gSingleCore);
|
ASSERT(!gSingleCore);
|
||||||
|
|
||||||
return system_time() - threadData->fWentSleep > kCacheExpire;
|
return system_time() - threadData->WentSleep() > kCacheExpire;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -476,8 +476,8 @@ reschedule(int32 nextState)
|
|||||||
ThreadData* oldThreadData = oldThread->scheduler_data;
|
ThreadData* oldThreadData = oldThread->scheduler_data;
|
||||||
|
|
||||||
// return time spent in interrupts
|
// return time spent in interrupts
|
||||||
oldThreadData->fStolenTime
|
oldThreadData->IncreaseStolenTime(
|
||||||
+= gCPU[thisCPU].interrupt_time - oldThreadData->fLastInterruptTime;
|
gCPU[thisCPU].interrupt_time - oldThreadData->LastInterruptTime());
|
||||||
|
|
||||||
bool enqueueOldThread = false;
|
bool enqueueOldThread = false;
|
||||||
bool putOldThreadAtBack = false;
|
bool putOldThreadAtBack = false;
|
||||||
@@ -520,7 +520,6 @@ reschedule(int32 nextState)
|
|||||||
|
|
||||||
nextThreadData = cpu->PeekIdleThread();
|
nextThreadData = cpu->PeekIdleThread();
|
||||||
cpu->Remove(nextThreadData);
|
cpu->Remove(nextThreadData);
|
||||||
nextThreadData->fEnqueued = false;
|
|
||||||
|
|
||||||
putOldThreadAtBack = oldThread->pinned_to_cpu == 0;
|
putOldThreadAtBack = oldThread->pinned_to_cpu == 0;
|
||||||
} else
|
} else
|
||||||
@@ -581,8 +580,7 @@ reschedule(int32 nextState)
|
|||||||
add_timer(quantumTimer, &reschedule_event, quantum,
|
add_timer(quantumTimer, &reschedule_event, quantum,
|
||||||
B_ONE_SHOT_RELATIVE_TIMER);
|
B_ONE_SHOT_RELATIVE_TIMER);
|
||||||
} else {
|
} else {
|
||||||
nextThreadData->fQuantumStart = system_time();
|
nextThreadData->StartQuantum();
|
||||||
|
|
||||||
gCurrentMode->rebalance_irqs(true);
|
gCurrentMode->rebalance_irqs(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ CPUEntry::PushBack(ThreadData* thread, int32 priority)
|
|||||||
void
|
void
|
||||||
CPUEntry::Remove(ThreadData* thread)
|
CPUEntry::Remove(ThreadData* thread)
|
||||||
{
|
{
|
||||||
|
ASSERT(thread->IsEnqueued());
|
||||||
|
thread->SetDequeued();
|
||||||
fRunQueue.Remove(thread);
|
fRunQueue.Remove(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,14 +205,11 @@ CPUEntry::ChooseNextThread(ThreadData* oldThread, bool putAtBack)
|
|||||||
return oldThread;
|
return oldThread;
|
||||||
|
|
||||||
if (sharedPriority > pinnedPriority) {
|
if (sharedPriority > pinnedPriority) {
|
||||||
sharedThread->fEnqueued = false;
|
fCore->Remove(sharedThread);
|
||||||
|
|
||||||
fCore->Remove(sharedThread, sharedThread->fWentSleepCount == 0);
|
|
||||||
return sharedThread;
|
return sharedThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
pinnedThread->fEnqueued = false;
|
Remove(pinnedThread);
|
||||||
fRunQueue.Remove(pinnedThread);
|
|
||||||
return pinnedThread;
|
return pinnedThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +242,7 @@ CPUEntry::TrackActivity(ThreadData* oldThreadData, ThreadData* nextThreadData)
|
|||||||
cpuEntry->last_kernel_time = nextThread->kernel_time;
|
cpuEntry->last_kernel_time = nextThread->kernel_time;
|
||||||
cpuEntry->last_user_time = nextThread->user_time;
|
cpuEntry->last_user_time = nextThread->user_time;
|
||||||
|
|
||||||
nextThreadData->fLastInterruptTime = cpuEntry->interrupt_time;
|
nextThreadData->SetLastInterruptTime(cpuEntry->interrupt_time);
|
||||||
|
|
||||||
_RequestPerformanceLevel(nextThreadData);
|
_RequestPerformanceLevel(nextThreadData);
|
||||||
}
|
}
|
||||||
@@ -349,13 +348,15 @@ CoreEntry::PushBack(ThreadData* thread, int32 priority)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CoreEntry::Remove(ThreadData* thread, bool starving)
|
CoreEntry::Remove(ThreadData* thread)
|
||||||
{
|
{
|
||||||
|
ASSERT(thread->IsEnqueued());
|
||||||
|
thread->SetDequeued();
|
||||||
if (thread_is_idle_thread(thread->GetThread())
|
if (thread_is_idle_thread(thread->GetThread())
|
||||||
|| fThreadList.Head() == thread) {
|
|| fThreadList.Head() == thread) {
|
||||||
atomic_add(&fStarvationCounter, 1);
|
atomic_add(&fStarvationCounter, 1);
|
||||||
}
|
}
|
||||||
if (starving)
|
if (thread->WentSleepCount() == 0)
|
||||||
fThreadList.Remove(thread);
|
fThreadList.Remove(thread);
|
||||||
fRunQueue.Remove(thread);
|
fRunQueue.Remove(thread);
|
||||||
atomic_add(&fThreadCount, -1);
|
atomic_add(&fThreadCount, -1);
|
||||||
@@ -459,20 +460,16 @@ CoreEntry::RemoveCPU(CPUEntry* cpu, ThreadProcessing& threadPostProcessing)
|
|||||||
// get rid of threads
|
// get rid of threads
|
||||||
thread_map(CoreEntry::_UnassignThread, this);
|
thread_map(CoreEntry::_UnassignThread, this);
|
||||||
|
|
||||||
fThreadCount = 0;
|
|
||||||
while (fRunQueue.PeekMaximum() != NULL) {
|
while (fRunQueue.PeekMaximum() != NULL) {
|
||||||
ThreadData* threadData = fRunQueue.PeekMaximum();
|
ThreadData* threadData = fRunQueue.PeekMaximum();
|
||||||
|
|
||||||
fRunQueue.Remove(threadData);
|
Remove(threadData);
|
||||||
threadData->fEnqueued = false;
|
|
||||||
|
|
||||||
if (threadData->fWentSleepCount == 0)
|
|
||||||
fThreadList.Remove(threadData);
|
|
||||||
threadData->fWentSleepCount = -1;
|
|
||||||
|
|
||||||
ASSERT(threadData->Core() == NULL);
|
ASSERT(threadData->Core() == NULL);
|
||||||
threadPostProcessing(threadData);
|
threadPostProcessing(threadData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fThreadCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fCPUHeap.ModifyKey(cpu, THREAD_MAX_SET_PRIORITY + 1);
|
fCPUHeap.ModifyKey(cpu, THREAD_MAX_SET_PRIORITY + 1);
|
||||||
|
|||||||
@@ -136,8 +136,7 @@ public:
|
|||||||
int32 priority);
|
int32 priority);
|
||||||
void PushBack(ThreadData* thread,
|
void PushBack(ThreadData* thread,
|
||||||
int32 priority);
|
int32 priority);
|
||||||
void Remove(ThreadData* thread,
|
void Remove(ThreadData* thread);
|
||||||
bool starving);
|
|
||||||
inline ThreadData* PeekThread() const;
|
inline ThreadData* PeekThread() const;
|
||||||
|
|
||||||
inline bigtime_t GetActiveTime() const;
|
inline bigtime_t GetActiveTime() const;
|
||||||
|
|||||||
@@ -38,7 +38,17 @@ public:
|
|||||||
bool ChooseCoreAndCPU(CoreEntry*& targetCore,
|
bool ChooseCoreAndCPU(CoreEntry*& targetCore,
|
||||||
CPUEntry*& targetCPU);
|
CPUEntry*& targetCPU);
|
||||||
|
|
||||||
|
inline bigtime_t LastInterruptTime() const
|
||||||
|
{ return fLastInterruptTime; }
|
||||||
|
inline void SetLastInterruptTime(bigtime_t interruptTime)
|
||||||
|
{ fLastInterruptTime = interruptTime; }
|
||||||
|
|
||||||
|
inline void IncreaseStolenTime(bigtime_t stolenTime);
|
||||||
|
|
||||||
inline void GoesAway();
|
inline void GoesAway();
|
||||||
|
inline bigtime_t WentSleep() const { return fWentSleep; }
|
||||||
|
inline bigtime_t WentSleepActive() const { return fWentSleepActive; }
|
||||||
|
inline bigtime_t WentSleepCount() const { return fWentSleepCount; }
|
||||||
|
|
||||||
inline void PutBack();
|
inline void PutBack();
|
||||||
inline void Enqueue();
|
inline void Enqueue();
|
||||||
@@ -49,6 +59,10 @@ public:
|
|||||||
|
|
||||||
inline bool HasQuantumEnded(bool wasPreempted, bool hasYielded);
|
inline bool HasQuantumEnded(bool wasPreempted, bool hasYielded);
|
||||||
bigtime_t ComputeQuantum();
|
bigtime_t ComputeQuantum();
|
||||||
|
inline void StartQuantum();
|
||||||
|
|
||||||
|
inline bool IsEnqueued() const { return fEnqueued; }
|
||||||
|
inline void SetDequeued() { fEnqueued = false; }
|
||||||
|
|
||||||
inline Thread* GetThread() const { return fThread; }
|
inline Thread* GetThread() const { return fThread; }
|
||||||
inline int32 GetLoad() const { return fLoad; }
|
inline int32 GetLoad() const { return fLoad; }
|
||||||
@@ -56,16 +70,6 @@ public:
|
|||||||
inline CoreEntry* Core() const { return fCore; }
|
inline CoreEntry* Core() const { return fCore; }
|
||||||
inline void UnassignCore() { fCore = NULL; }
|
inline void UnassignCore() { fCore = NULL; }
|
||||||
|
|
||||||
bigtime_t fStolenTime;
|
|
||||||
bigtime_t fQuantumStart;
|
|
||||||
bigtime_t fLastInterruptTime;
|
|
||||||
|
|
||||||
bigtime_t fWentSleep;
|
|
||||||
bigtime_t fWentSleepActive;
|
|
||||||
int32 fWentSleepCount;
|
|
||||||
|
|
||||||
bool fEnqueued;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline int32 _GetPenalty() const;
|
inline int32 _GetPenalty() const;
|
||||||
inline int32 _GetMinimalPriority() const;
|
inline int32 _GetMinimalPriority() const;
|
||||||
@@ -79,6 +83,16 @@ private:
|
|||||||
bigtime_t minQuantum, int32 maxPriority,
|
bigtime_t minQuantum, int32 maxPriority,
|
||||||
int32 minPriority, int32 priority);
|
int32 minPriority, int32 priority);
|
||||||
|
|
||||||
|
bigtime_t fStolenTime;
|
||||||
|
bigtime_t fQuantumStart;
|
||||||
|
bigtime_t fLastInterruptTime;
|
||||||
|
|
||||||
|
bigtime_t fWentSleep;
|
||||||
|
bigtime_t fWentSleepActive;
|
||||||
|
int32 fWentSleepCount;
|
||||||
|
|
||||||
|
bool fEnqueued;
|
||||||
|
|
||||||
Thread* fThread;
|
Thread* fThread;
|
||||||
|
|
||||||
int32 fPriorityPenalty;
|
int32 fPriorityPenalty;
|
||||||
@@ -178,6 +192,13 @@ ThreadData::ShouldCancelPenalty() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void
|
||||||
|
ThreadData::IncreaseStolenTime(bigtime_t stolenTime)
|
||||||
|
{
|
||||||
|
fStolenTime += stolenTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
ThreadData::GoesAway()
|
ThreadData::GoesAway()
|
||||||
{
|
{
|
||||||
@@ -240,7 +261,6 @@ ThreadData::Dequeue()
|
|||||||
if (!fEnqueued)
|
if (!fEnqueued)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
fEnqueued = false;
|
|
||||||
if (fThread->pinned_to_cpu > 0) {
|
if (fThread->pinned_to_cpu > 0) {
|
||||||
ASSERT(fThread->previous_cpu != NULL);
|
ASSERT(fThread->previous_cpu != NULL);
|
||||||
|
|
||||||
@@ -248,9 +268,10 @@ ThreadData::Dequeue()
|
|||||||
cpu->Remove(this);
|
cpu->Remove(this);
|
||||||
} else {
|
} else {
|
||||||
ASSERT(fWentSleepCount < 1);
|
ASSERT(fWentSleepCount < 1);
|
||||||
fCore->Remove(this, fWentSleepCount == 0);
|
fCore->Remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASSERT(!fEnqueued);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,6 +320,13 @@ ThreadData::HasQuantumEnded(bool wasPreempted, bool hasYielded)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void
|
||||||
|
ThreadData::StartQuantum()
|
||||||
|
{
|
||||||
|
fQuantumStart = system_time();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline int32
|
inline int32
|
||||||
ThreadData::_GetPenalty() const
|
ThreadData::_GetPenalty() const
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user