예제 #1
0
static task_t* steal_task_prio(runqueue_t* rq,int cpu){
    task_t* t=tail_slist(&rq->tasks);
    
    if (t) {
        remove_slist(&rq->tasks,t);
        t->on_rq=FALSE;
        rq->nr_runnable--;
    }
    return t;    
}
예제 #2
0
파일: sched.c 프로젝트: ferreiro/C
sched_event_t* get_next_sched_event(int cpu, int timeout)
{

    sched_event_t* event=head_slist(&sched_events[cpu]);

    if (event!=NULL && timeout==event->timeout) {
        remove_slist(&sched_events[cpu],event);
        return event;
    } else
        return NULL;
}
예제 #3
0
static task_t* pick_next_task_prio(runqueue_t* rq,int cpu) {
    task_t* t=head_slist(&rq->tasks); //List sorted by CPU burst lenght (just pick the first one)
    
    if (t) {
        /* Current is not on the rq*/
        remove_slist(&rq->tasks,t);
        t->on_rq=FALSE;
        rq->cur_task=t;
    }
    
    return t;
}
예제 #4
0
static task_t* pick_next_task_fcfs(runqueue_t* rq,int cpu) {    //coge la siguiente tarea que trae el pipe.se ejecuta cada vez que el simulador necesota una tarea.
    task_t* t=head_slist(&rq->tasks); //List sorted by CPU burst lenght (just pick the first one)
    
    if (t) {
        /* Current is not on the rq*/
        remove_slist(&rq->tasks,t); // borra la tarea de la lista
        t->on_rq=FALSE; //sice que ya no esta en la lista
        rq->cur_task=t; // la tarea actual en el pipe es esa 't'
    }
    
    return t;
}
예제 #5
0
파일: sched.c 프로젝트: ferreiro/C
static void print_task_log_registers(task_t* task)
{
    sched_log_t* cur=head_slist(&task->sched_regs);
    sched_log_t* next;

    /* Disable debug mode for this */
    debug_mode=FALSE;

    while(!is_empty_slist(&task->sched_regs)) {
        write_cpu_log(cur->cpu,"%s\t%d\t%d\t%s\n",task->task_name,cur->when,cur->when+cur->how_long,strstate[cur->state]);
        /* Keep track of next, since we will remove cur from the list */
        next=next_slist(&task->sched_regs,cur);
        remove_slist(&task->sched_regs,cur);
        free(cur);
        cur=next;// Go to next item
    }
}
예제 #6
0
static task_t* pick_next_task_lote(runqueue_t* rq,int cpu) {
    task_t* t=head_slist(&rq->tasks); //List sorted by CPU burst lenght (just pick the first one)
    
    if (t) {
        /* Current is not on the rq*/
        remove_slist(&rq->tasks,t);
        t->on_rq=FALSE;
        rq->cur_task=t;
    }
    
    srand(time(NULL));

    int i;
    for(i=0; i<rq->nr_runnable; i++){
        next_slist(&rq->tasks, t);
        t->prio = i;
    }

    return t;
}
예제 #7
0
static task_t* steal_task_lote(runqueue_t* rq,int cpu){

    task_t* t=rq->cur_task;
    int loteria = rand()%100;
    int i=0, encontrado=0; 

    while(encontrado==0 && i<rq->nr_runnable){
        next_slist(&rq->tasks, t);
        if(t->prio == loteria)
            encontrado=1;
    }

    //task_t* t=tail_slist(&rq->tasks);
    
    if (t) {
        remove_slist(&rq->tasks,t);
        t->on_rq=FALSE;
        rq->nr_runnable--;
    }
    return t;    
}
예제 #8
0
파일: slist.c 프로젝트: ferreiro/C
void sort_slist(slist_t* slist, int ascending, int (*compare)(void*,void*))
{
    void *cur=NULL,*selected_node=NULL,*prev_selected=NULL;
    int i=0;

    /* Check if the list is already trivially sorted */
    if (slist->size<=1)
        return;

    cur=head_slist(slist);

    /* Insertion sort */
    for (i=0; i<slist->size-1 && cur!=NULL; i++) {

        /* Search */
        selected_node=cur;

        if (ascending) {
            // Search for min
            while(cur!=NULL) {
                if (compare(cur,selected_node)<0)
                    selected_node=cur;
                cur=next_slist(slist,cur);
            }
        } else {
            // Search for max
            while(cur!=NULL) {
                if (compare(cur,selected_node)>0)
                    selected_node=cur;
                cur=next_slist(slist,cur);
            }
        }

        remove_slist(slist,selected_node);
        insert_after_slist(slist,prev_selected,selected_node);
        prev_selected=selected_node;
        cur=next_slist(slist,selected_node);
    }
}