* Added an extra check as requested by CID 1567, but also added a comment why

this (and other checks) should not be necessary in the first place.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38229 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2010-08-18 11:39:39 +00:00
parent d74f5f5bb5
commit 3e86abbd71

View File

@ -234,7 +234,7 @@ estimate_max_scheduling_latency(struct thread* thread)
// TODO: This is probably meant to be called periodically to return the // TODO: This is probably meant to be called periodically to return the
// current estimate depending on the system usage; we return fixed estimates // current estimate depending on the system usage; we return fixed estimates
// per thread priority, though. // per thread priority, though.
if (thread->priority >= B_REAL_TIME_DISPLAY_PRIORITY) if (thread->priority >= B_REAL_TIME_DISPLAY_PRIORITY)
return kThreadQuantum / 4; return kThreadQuantum / 4;
if (thread->priority >= B_DISPLAY_PRIORITY) if (thread->priority >= B_DISPLAY_PRIORITY)
@ -298,13 +298,15 @@ reschedule(void)
} }
} }
TRACE(("reschedule(): cpu %ld, cur_thread = %ld\n", smp_get_current_cpu(), thread_get_current_thread()->id)); TRACE(("reschedule(): cpu %ld, cur_thread = %ld\n", smp_get_current_cpu(),
thread_get_current_thread()->id));
oldThread->state = oldThread->next_state; oldThread->state = oldThread->next_state;
switch (oldThread->next_state) { switch (oldThread->next_state) {
case B_THREAD_RUNNING: case B_THREAD_RUNNING:
case B_THREAD_READY: case B_THREAD_READY:
TRACE(("enqueueing thread %ld into run q. pri = %ld\n", oldThread->id, oldThread->priority)); TRACE(("enqueueing thread %ld into run q. pri = %ld\n",
oldThread->id, oldThread->priority));
enqueue_in_run_queue(oldThread); enqueue_in_run_queue(oldThread);
break; break;
case B_THREAD_SUSPENDED: case B_THREAD_SUSPENDED:
@ -313,7 +315,8 @@ reschedule(void)
case THREAD_STATE_FREE_ON_RESCHED: case THREAD_STATE_FREE_ON_RESCHED:
break; break;
default: default:
TRACE(("not enqueueing thread %ld into run q. next_state = %ld\n", oldThread->id, oldThread->next_state)); TRACE(("not enqueueing thread %ld into run q. next_state = %ld\n",
oldThread->id, oldThread->next_state));
break; break;
} }
@ -323,17 +326,20 @@ reschedule(void)
if (oldThread->cpu->disabled) { if (oldThread->cpu->disabled) {
// CPU is disabled - service any threads we may have that are pinned, // CPU is disabled - service any threads we may have that are pinned,
// otherwise just select the idle thread // otherwise just select the idle thread
while (nextThread && nextThread->priority > B_IDLE_PRIORITY) { while (nextThread != NULL && nextThread->priority > B_IDLE_PRIORITY) {
if (nextThread->pinned_to_cpu > 0 && if (nextThread->pinned_to_cpu > 0
nextThread->previous_cpu == oldThread->cpu) && nextThread->previous_cpu == oldThread->cpu)
break; break;
prevThread = nextThread; prevThread = nextThread;
nextThread = nextThread->queue_next; nextThread = nextThread->queue_next;
} }
} else { } else {
while (nextThread) { while (nextThread != NULL) {
// select next thread from the run queue // select next thread from the run queue
while (nextThread && nextThread->priority > B_IDLE_PRIORITY) { // TODO: nextThread cannot really be NULL here, so we should be able
// to remove the check, as well as the panic later on.
while (nextThread != NULL
&& nextThread->priority > B_IDLE_PRIORITY) {
#if 0 #if 0
if (oldThread == nextThread && nextThread->was_yielded) { if (oldThread == nextThread && nextThread->was_yielded) {
// ignore threads that called thread_yield() once // ignore threads that called thread_yield() once
@ -383,7 +389,7 @@ reschedule(void)
prevThread = lowerPrevThread; prevThread = lowerPrevThread;
} }
if (nextThread->cpu if (nextThread != NULL && nextThread->cpu
&& nextThread->cpu->cpu_num != oldThread->cpu->cpu_num) { && nextThread->cpu->cpu_num != oldThread->cpu->cpu_num) {
panic("thread in run queue that's still running on another CPU!\n"); panic("thread in run queue that's still running on another CPU!\n");
// TODO: remove this check completely when we're sure that this // TODO: remove this check completely when we're sure that this
@ -397,11 +403,11 @@ reschedule(void)
} }
} }
if (!nextThread) if (nextThread == NULL)
panic("reschedule(): run queue is empty!\n"); panic("reschedule(): run queue is empty!\n");
// extract selected thread from the run queue // extract selected thread from the run queue
if (prevThread) if (prevThread != NULL)
prevThread->queue_next = nextThread->queue_next; prevThread->queue_next = nextThread->queue_next;
else else
sRunQueue = nextThread->queue_next; sRunQueue = nextThread->queue_next;
@ -409,8 +415,8 @@ reschedule(void)
T(ScheduleThread(nextThread, oldThread)); T(ScheduleThread(nextThread, oldThread));
// notify listeners // notify listeners
NotifySchedulerListeners(&SchedulerListener::ThreadScheduled, NotifySchedulerListeners(&SchedulerListener::ThreadScheduled, oldThread,
oldThread, nextThread); nextThread);
nextThread->state = B_THREAD_RUNNING; nextThread->state = B_THREAD_RUNNING;
nextThread->next_state = B_THREAD_READY; nextThread->next_state = B_THREAD_READY;
@ -423,9 +429,9 @@ reschedule(void)
// track CPU activity // track CPU activity
if (!thread_is_idle_thread(oldThread)) { if (!thread_is_idle_thread(oldThread)) {
oldThread->cpu->active_time += oldThread->cpu->active_time
(oldThread->kernel_time - oldThread->cpu->last_kernel_time) += (oldThread->kernel_time - oldThread->cpu->last_kernel_time)
+ (oldThread->user_time - oldThread->cpu->last_user_time); + (oldThread->user_time - oldThread->cpu->last_user_time);
} }
if (!thread_is_idle_thread(nextThread)) { if (!thread_is_idle_thread(nextThread)) {