Пример #1
0
void
schedule(void) {
  if (list_empty(&readyhead)) {
    current = &idle;
    return;
  }
  current=leaveProcQ(&readyhead, &readylen);
  enterProcQ(false, current, &readyhead);
  write_cr3(&(current->cr3));
  set_tss_esp0((uint32_t)(current->kstack+4095));
}
Пример #2
0
void
schedule(void) {
	/* implement process/thread schedule here */
	//PCB *last = current;
	//PCB *next = NULL;
	//printk("schedule\n");
	/*
	if(current->state == TASK_BLOCKED) {
	    list_add_after(block.prev,&current->head);
        current = NULL;
    }else if(current->state != TASK_DEAD && current != &idle) {
	    list_add_after(ready.prev,&current->head);
    } else if(current->state == TASK_DEAD) {
        list_add_after(free.prev,&current->head);
        current->state = TASK_EMPTY;
    }


    if(ready.next == &ready) 
        current = &idle;
    else {
        current = list_entry(ready.next,PCB,head);
        list_del(&current->head);
    }
    */
    //new scheduling here
    //printk("new scheduler, pid = %d\n",current->pid);
    //printk("new scheduler, state=%d\n",current->state);
    if(current == &idle) {
        current = NULL;
    }else if(current->state == TASK_DEAD) {
        list_add_after(free.prev,&current->head);
        printk("task_dead, pid = %d\n",current->pid);
        current->state = TASK_EMPTY;
        current = NULL;
    }else if(current->state == TASK_BLOCKED) {
	    list_add_after(block.prev,&current->head);
        current = NULL;
    }else if(current == &idle) {
        current->state = TASK_READY;
        current = NULL;
    }else {
        //current->state == TASK_RUNNING
       // printk("state = %d\n",current->state);
        if (current->state != TASK_RUNNING) {
            printk("state = %x\n",current->state);
        }
        assert(current->state == TASK_RUNNING);
        current->counter -= 1;
        if(current->counter == 0) {
            current->state = TASK_READY;
            current->counter = MAX_TIME_SLOT;
            list_add_after(ready.prev,&current->head);
            current = NULL;
        }else 
            //no scheduling, just return
            return ;
    }

    if(ready.next == &ready)
        current = &idle;
    else {
        current = list_entry(ready.next,PCB,head);
        list_del(&current->head);
        
    }
    current->state = TASK_RUNNING;
	
    if(current->cr3.val == 0) {
	    write_cr3(get_kcr3()); //kernel page dir
    }else {
	    write_cr3(&current->cr3);
    }


    uint32_t esp0 = (uint32_t)current->tf;
    esp0 += sizeof(struct TrapFrame);
    

    set_tss_esp0(esp0);

    //printk("after new scheduler, pid = %d\n",current->pid);
   // printk("after new scheduler, state=%d\n",current->state);


}