Exemple #1
0
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;
}
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;
}
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;
}
Exemple #4
0
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
    }
}
Exemple #5
0
void sorted_insert_slist_front(slist_t* slist, void* object, int ascending, int (*compare)(void*,void*)){
	void *cur=NULL;
	
	cur=head_slist(slist);
	/* Search */
	if (ascending){
		// Find 
		while(cur!=NULL && compare(cur,object)<0) {
			cur=next_slist(slist,cur);
		}
	}else{
		// Find 
		while(cur!=NULL && compare(cur,object)>0) {
			cur=next_slist(slist,cur);
		}
	}		
		
	insert_before_slist(slist,cur,object);
}
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;
}
Exemple #7
0
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);
    }
}
Exemple #8
0
/* This function enables to start up the simulator with
 * a given scheduling algorithm and specified task list.
 * */
void sched_start(slist_t* task_list, struct sched_class* sc)
{
    task_t *cur,*next;
    int task_cnt=0;
    pthread_t sim_cpu[MAX_CPUS];
    long cpu=0;
    int i=0;

    sched_init(sc);

    /* Traverse the task_list to wake up new tasks*/
    cur=head_slist(task_list);

    while(task_cnt<task_list->size) {
        cur->last_cpu=task_cnt%nr_cpus; /* Hack to automatize load balancing at the beginning */
        if (init_task_sched(cur)) {
            perror("Couldn't initialize class specific data for thread ");
            exit(1);
        }
        schedule_wake_up_new_task(cur);	/*Just inserts the sched_event in the event_queue */

        if (debug_mode)
            print_task(cur);

        cur=next_slist(task_list,cur);
        task_cnt++;
    }

    if (debug_mode) {
        printf("Scheduler initialized. Press ENTER to start simulation.\n");
        getchar();
    }

    /* Create per-CPU simulation threads */
    for (cpu=0; cpu<nr_cpus; cpu++)
        pthread_create(&sim_cpu[cpu],NULL,sched_cpu,(void*)cpu);

    /* Wait for completion of per-CPU simulation threads*/
    for (cpu=0; cpu<nr_cpus; cpu++)
        pthread_join(sim_cpu[cpu],NULL);

    /* Print log information to aid in
     * the construction of the gantt diagram
     * */
    cur=head_slist(task_list);

    for(i=0; i<task_cnt; i++) {
        print_task_log_registers(cur);
        cur=next_slist(task_list,cur);
    }

    /* Free up class-specific task data and task structures */
    cur=head_slist(task_list);

    for(i=0; i<task_cnt; i++) {
        next=next_slist(task_list,cur);
        if (active_sched_class->task_free)
            active_sched_class->task_free(cur);
        free(cur);
        cur=next;
    }

    /* Free up sched-class specific resources if necessary */
    if (active_sched_class->sched_destroy)
        active_sched_class->sched_destroy();

    printf("Simulation completed\n");
    sched_terminate(0);
}