* Changed the simple scheduler's next thread selection in the same way as the

affine scheduler to avoid possible latency issues.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34634 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2009-12-11 17:40:15 +00:00
parent 59967f764e
commit edc69377fa
1 changed files with 26 additions and 17 deletions

View File

@ -1,6 +1,6 @@
/*
* Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2002-2007, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2002, Angelo Mottola, a.mottola@libero.it.
* Distributed under the terms of the MIT License.
*
@ -239,23 +239,32 @@ simple_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;
// skip until next lower priority
// find next thread with lower priority
struct thread *lowerNextThread = nextThread->queue_next;
struct thread *lowerPrevThread = nextThread;
int32 priority = nextThread->priority;
do {
prevThread = nextThread;
nextThread = nextThread->queue_next;
} while (nextThread->queue_next != NULL
&& priority == nextThread->queue_next->priority
&& nextThread->queue_next->priority > B_IDLE_PRIORITY);
while (lowerNextThread != NULL
&& priority == lowerNextThread->priority) {
lowerPrevThread = lowerNextThread;
lowerNextThread = lowerNextThread->queue_next;
}
// never skip last non-idle normal thread
if (lowerNextThread == NULL
|| lowerNextThread->priority == B_IDLE_PRIORITY)
break;
int32 priorityDiff = priority - lowerNextThread->priority;
if (priorityDiff > 15)
break;
// skip normal threads sometimes
// (twice as probable per priority level)
if ((_rand() >> (15 - priorityDiff)) != 0)
break;
nextThread = lowerNextThread;
prevThread = lowerPrevThread;
}
break;