void recompute_priority(void) { int i; thread_t *t1, *t2; // For all the queues qs[], select one thread at a time, // compute its pririty, insert it into tqs[] queue for (i=0; i<32; i++) { while (qs[i] != NULL) { t1 = qs[i]; dequeue_thread(i, t1, qs); t1->thr_cpupri /= 2; //edited t1->thr_pri = t1->thr_usrpri + (t1-> thr_cpupri / 4) + (2 * t1->thr_nice); enqueue_thread(t1, tqs); } } for (i=0; i<32; i++) qs[i] = tqs[i]; }
void reschedule(void) { int hwthread = __builtin_nyuzi_read_control_reg(CR_CURRENT_THREAD); struct thread *old_thread; struct thread *next_thread; // Put current thread back on ready queue acquire_spinlock(&thread_q_lock); old_thread = cur_thread[hwthread]; enqueue_thread(&ready_q, old_thread); next_thread = dequeue_thread(&ready_q); if (old_thread != next_thread) { cur_thread[hwthread] = next_thread; context_switch(&old_thread->current_stack, next_thread->current_stack, next_thread->map->page_dir, next_thread->map->asid); } release_spinlock(&thread_q_lock); }
void schedule() { int id; thread_t *t, *t1; ucontext_t dummy; // Select the first thread in first non-empty queue // dequeue it and context switch for (id=0; id < 32; id++) if (whichqs & (1 << id)) break; // Check if non-empty queue is found? if (id < 32) { t = qs[id]; dequeue_thread(id, t, qs); // If current thread is active then enqueue it. if (current_thread != NULL) { enqueue_thread(current_thread, qs); t1 = current_thread; current_thread = t; swapcontext(&t1->thr_context, &t->thr_context); } else { current_thread = t; swapcontext(&dummy, &t->thr_context); } } else { // Deadlock situtation is not addressed. // Assuming that at least one runnable thread must be available. if (current_thread != NULL) return; else exit(0); } }