Subversion Repositories shark

Rev

Rev 1244 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include "func.h"

extern int cal_cycles;
extern struct timespec zero_time;
extern struct loader_task loader_task_list[];
extern struct loader_contract loader_contract_list[];
extern int total_loader_task;
extern int total_loader_contract;

/* Delay Calibration */
int calibrate_cycle()
{
  long long i;
  struct timespec start,end,diff;

  kern_cli();
  kern_gettime(&start);
  for (i=0;i<CALIBRATION_DELTA;i++)
    __asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
                          "cpuid\n\t"
                          :::"eax","ebx","ecx","edx");
  kern_gettime(&end);
  kern_sti();

  SUBTIMESPEC(&end,&start,&diff);
  cal_cycles = TIMESPEC2USEC(&diff);
  cprintf("Calibration usec/[%d cycles] = %d\n",CALIBRATION_DELTA,cal_cycles);

  return 0;

}

int get_server_from_contract(int contract)
{

  int i;

  for(i=0;i<total_loader_contract;i++)
    if (loader_contract_list[i].number == contract)
      return loader_contract_list[i].server;

  return -1;

}

void *get_task_model(struct loader_task *current) {
  if (current->local_scheduler == PAR_POSIX) {
    static NRT_TASK_MODEL nrt;
   
    nrt_task_default_model(nrt);
    nrt_task_def_save_arrivals(nrt);
    nrt_task_def_ctrl_jet(nrt);
    nrt_task_def_group(nrt,current->group);
    nrt_task_def_usemath(nrt);
   
    return &nrt;

  }  

  if (current->local_scheduler == PAR_EDF) {
    static HARD_TASK_MODEL ht;

    hard_task_default_model(ht);
    hard_task_def_ctrl_jet(ht);          
    hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
    hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
    hard_task_def_group(ht,current->group);
    hard_task_def_usemath(ht);
    return &ht;
  }  


  if (current->local_scheduler == PAR_RM) {
    static HARD_TASK_MODEL ht;
                                                                                                                             
    hard_task_default_model(ht);
    hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
    hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
    hard_task_def_ctrl_jet(ht);
    hard_task_def_group(ht,current->group);
    hard_task_def_usemath(ht);
    return &ht;
  }  

  return NULL;
                                                 
}  

void set_simulation_time (struct timespec *total) {
  struct timespec end_time;
 
  ADDTIMESPEC(&zero_time,total,&end_time);
  kern_event_post(&end_time,(void *)((void *)(sys_end)),NULL);

}

int calibration_func() {
  return kern_gettime(NULL);

}

void start_simulation() {
 
  int i;
  struct loader_task *l = loader_task_list;
  struct timespec end_time;

  i  = 0;

  kern_gettime(&zero_time);
 
  while (i < total_loader_task) {
   
    if (l->act_number > 0) {
      ADDTIMESPEC(&zero_time, &l->act[0], &end_time);
      l->act_current++;
      kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);
    }
   
    i++;
    l=&loader_task_list[i];

  }

}


void loader_task_activate(struct loader_task *l) {
 
  struct timespec actual_time,end_time;

  kern_gettime(&actual_time);
  group_activate(l->group);

  if (l->act_number > l->act_current) {

    ADDTIMESPEC(&actual_time, &l->act[l->act_current], &end_time);
 
    l->act_current++;
    kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);

  }

}