Cleanups and some changes to avoid looping to compute the quantum average as suggested by Axel.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32484 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Rene Gollent 2009-08-17 23:26:22 +00:00
parent 65411f56b7
commit 494fe97976
1 changed files with 16 additions and 19 deletions

View File

@ -58,19 +58,27 @@ struct scheduler_thread_data {
void Init()
{
memset(fLastThreadQuantums, 0, sizeof(fLastThreadQuantums));
fLastQuantumSlot = 0;
fLastQueue = -1;
}
int32 GetAverageQuantumUsage() const
inline void SetQuantum(int32 quantum)
{
int32 quantumAverage = 0;
for (int32 i = 0; i < kMaxTrackingQuantums; i++)
quantumAverage += fLastThreadQuantums[i];
return quantumAverage / kMaxTrackingQuantums;
fQuantumAverage -= fLastThreadQuantums[fLastQuantumSlot];
fLastThreadQuantums[fLastQuantumSlot] = quantum;
fQuantumAverage += quantum;
if (fLastQuantumSlot < kMaxTrackingQuantums - 1)
++fLastQuantumSlot;
else
fLastQuantumSlot = 0;
}
inline int32 GetAverageQuantumUsage() const
{
return fQuantumAverage / kMaxTrackingQuantums;
}
int32 fQuantumAverage;
int32 fLastThreadQuantums[kMaxTrackingQuantums];
int16 fLastQuantumSlot;
int32 fLastQueue;
@ -305,9 +313,6 @@ affine_set_thread_priority(struct thread *thread, int32 priority)
thread);
// search run queues for the thread
// TODO: keep track of the queue a thread is in (perhaps in a
// data pointer on the thread struct) so we only have to walk
// that exact queue to find it.
struct thread *item = NULL, *prev = NULL;
targetCPU = thread->scheduler_data->fLastQueue;
@ -406,10 +411,6 @@ affine_reschedule(void)
if (nextThread->priority >= B_FIRST_REAL_TIME_PRIORITY)
break;
// never skip last non-idle normal thread
if (nextThread->queue_next && nextThread->queue_next->priority == B_IDLE_PRIORITY)
break;
// skip normal threads sometimes (roughly 20%)
if (_rand() > 0x1a00)
break;
@ -465,11 +466,7 @@ affine_reschedule(void)
+ (oldThread->user_time - oldThread->cpu->last_user_time);
oldThread->cpu->active_time += activeTime;
scheduler_thread_data *data = oldThread->scheduler_data;
data->fLastThreadQuantums[data->fLastQuantumSlot] = activeTime;
if (data->fLastQuantumSlot == kMaxTrackingQuantums - 1)
data->fLastQuantumSlot = 0;
else
data->fLastQuantumSlot++;
data->SetQuantum(activeTime);
}
if (!thread_is_idle_thread(nextThread)) {