void insert_before_slist(slist_t *slist, void *object, void *nobject) { struct list_head* prev_node=((struct list_head*)(((char*)object) + slist->node_offset)); struct list_head* new_node=((struct list_head*)(((char*)nobject) + slist->node_offset)); if (!object){ insert_slist(slist,nobject); } else{ list_add_tail(new_node,prev_node); slist->size++; } }
//encolar tarea static void enqueue_task_fcfs(task_t* t,int cpu, int runnable) { runqueue_t* rq=get_runqueue_cpu(cpu); if (t->on_rq || is_idle_task(t)) //si esta en la lista o es idle return; insert_slist(&rq->tasks,t); //se inserta en la lista y actualizamos a true t->on_rq=TRUE; //numero de elementos en la lista if(!runnable){ rq->nr_runnable++; // incrementar numero de elementos en la lista t->last_cpu=cpu; } }
// Insert a directory entry if it is not a hidden file. void insert (slist_ref slist, char *path, char *ename) { char buffer[MAX_BUFFER_SIZE]; pathstr (buffer, path, ename); struct stat fs; int stat_rc = stat (buffer, &fs); if (stat_rc >= 0) { slist_node node = new_slistnode (&fs, ename); if (! is_hidden (node)) insert_slist (slist, node); else free_slistnode (node); }else { print_error (ename, strerror (errno)); } }
/* Add a log register for the post simulation analysis */ static void add_log_register(task_t* task, task_state_t state, int cpu, int when, int how_long) { sched_log_t* log_reg=tail_slist(&task->sched_regs); sched_log_t* new_reg; /* Do not insert empty registers */ if (how_long==0) return; if (!log_reg || log_reg->state!=state || log_reg->cpu!=cpu ) { new_reg=(sched_log_t*)malloc(sizeof(sched_log_t)); new_reg->state=state; new_reg->cpu=cpu; new_reg->when=when; new_reg->how_long=how_long; insert_slist(&task->sched_regs,new_reg); } else { /* If thread was runnable and now it's ONPROC -> Update the previous register */ log_reg->how_long+=how_long; } }
/* This function parses an input file describing the various tasks. * On success, it returns a task list (task_t). * */ slist_t read_task_list_from_file(FILE *file) { slist_t slist; char line[MAX_CHARS_TASK_LINE]=""; char cpbuf[MAX_CHARS_TASK_LINE]=""; char* parsed_line; char* token=NULL; int idx_token=0; task_t* cur_task=NULL; exec_phase_t* phase=NULL; int cnt_tasks=0; int line_counter=0; int error=0; init_slist (&slist, offsetof(task_t,ts_links)); /*- Formato del cada linea: NombreTarea Prio startTime <CPU1> <IO1> <CPU2> <IO2> ... */ while(!feof(file) && fgets(line, MAX_CHARS_TASK_LINE, file)) { line_counter++; if (strcmp(line, "\n")) { /* Copy line in temporary storage */ parsed_line=cpbuf; strcpy(parsed_line,line); /* Allocate memory for task descriptor */ cur_task=(task_t*)malloc(sizeof(task_t)); memset(cur_task,0,sizeof(task_t)); cur_task->task_id=cnt_tasks++; idx_token=0; while(!error && (token= strsep(&parsed_line," "))!=NULL) { switch(idx_token) { case 0: strcpy(cur_task->task_name,token); break; case 1: if (sscanf(token,"%d",&cur_task->prio)!=1) error=1; break; case 2: if (sscanf(token,"%d",&cur_task->task_profile.arrival_time)!=1) error=1; break; default: phase=&cur_task->task_profile.phase[cur_task->task_profile.nr_phases]; if (cur_task->task_profile.nr_phases & 0x1) //odd == IO phase->type=IO_PHASE; else phase->type=CPU_PHASE; /* Ignore blank spaces */ if (sscanf(token,"%d",&phase->len)==1) { //Add phase cur_task->task_profile.nr_phases++; } break; } idx_token++; } if (error) { fprintf(stderr,"Syntax error in input file (line %d) -> %s \n",line_counter,line); exit(1); } if (cur_task->task_profile.nr_phases==0) { fprintf(stderr,"Error parsing CPU/IO pattern for task (line %d) -> %s \n",line_counter,line); exit(1); } //Add task to the list insert_slist(&slist,cur_task); } } return slist; }