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:
@@ -58,19 +58,27 @@ struct scheduler_thread_data {
|
|||||||
|
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
memset(fLastThreadQuantums, 0, sizeof(fLastThreadQuantums));
|
|
||||||
fLastQuantumSlot = 0;
|
fLastQuantumSlot = 0;
|
||||||
fLastQueue = -1;
|
fLastQueue = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 GetAverageQuantumUsage() const
|
inline void SetQuantum(int32 quantum)
|
||||||
{
|
{
|
||||||
int32 quantumAverage = 0;
|
fQuantumAverage -= fLastThreadQuantums[fLastQuantumSlot];
|
||||||
for (int32 i = 0; i < kMaxTrackingQuantums; i++)
|
fLastThreadQuantums[fLastQuantumSlot] = quantum;
|
||||||
quantumAverage += fLastThreadQuantums[i];
|
fQuantumAverage += quantum;
|
||||||
return quantumAverage / kMaxTrackingQuantums;
|
if (fLastQuantumSlot < kMaxTrackingQuantums - 1)
|
||||||
|
++fLastQuantumSlot;
|
||||||
|
else
|
||||||
|
fLastQuantumSlot = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int32 GetAverageQuantumUsage() const
|
||||||
|
{
|
||||||
|
return fQuantumAverage / kMaxTrackingQuantums;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 fQuantumAverage;
|
||||||
int32 fLastThreadQuantums[kMaxTrackingQuantums];
|
int32 fLastThreadQuantums[kMaxTrackingQuantums];
|
||||||
int16 fLastQuantumSlot;
|
int16 fLastQuantumSlot;
|
||||||
int32 fLastQueue;
|
int32 fLastQueue;
|
||||||
@@ -305,9 +313,6 @@ affine_set_thread_priority(struct thread *thread, int32 priority)
|
|||||||
thread);
|
thread);
|
||||||
|
|
||||||
// search run queues for the 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;
|
struct thread *item = NULL, *prev = NULL;
|
||||||
targetCPU = thread->scheduler_data->fLastQueue;
|
targetCPU = thread->scheduler_data->fLastQueue;
|
||||||
|
|
||||||
@@ -406,10 +411,6 @@ affine_reschedule(void)
|
|||||||
if (nextThread->priority >= B_FIRST_REAL_TIME_PRIORITY)
|
if (nextThread->priority >= B_FIRST_REAL_TIME_PRIORITY)
|
||||||
break;
|
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%)
|
// skip normal threads sometimes (roughly 20%)
|
||||||
if (_rand() > 0x1a00)
|
if (_rand() > 0x1a00)
|
||||||
break;
|
break;
|
||||||
@@ -465,11 +466,7 @@ affine_reschedule(void)
|
|||||||
+ (oldThread->user_time - oldThread->cpu->last_user_time);
|
+ (oldThread->user_time - oldThread->cpu->last_user_time);
|
||||||
oldThread->cpu->active_time += activeTime;
|
oldThread->cpu->active_time += activeTime;
|
||||||
scheduler_thread_data *data = oldThread->scheduler_data;
|
scheduler_thread_data *data = oldThread->scheduler_data;
|
||||||
data->fLastThreadQuantums[data->fLastQuantumSlot] = activeTime;
|
data->SetQuantum(activeTime);
|
||||||
if (data->fLastQuantumSlot == kMaxTrackingQuantums - 1)
|
|
||||||
data->fLastQuantumSlot = 0;
|
|
||||||
else
|
|
||||||
data->fLastQuantumSlot++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!thread_is_idle_thread(nextThread)) {
|
if (!thread_is_idle_thread(nextThread)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user