scheduler: Encapsulate ThreadData fields

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