Subversion Repositories shark

Rev

Rev 1298 | Rev 1304 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include "func.h"
#include "calibrate.h"
#include <tracer.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;

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

  if (cal_cycles != 0) return 0;

  kern_cli();
  __asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
                          "cpuid\n\t"
                          :::"eax","ebx","ecx","edx");
  kern_gettime(&start);
  for (i=0;i<CALIBRATION_DELTA;i++)
    __asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
                          "cpuid\n\t"
                          :::"eax","ebx","ecx","edx");
  __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_aperiodic(ht);
    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;
                                                 
}

TASK finish_task() {
             
  extern __volatile__ unsigned int TracerEventsPresent;
  unsigned int k;                
               
  SYS_FLAGS f;
                                                                               
  tracer_init_udp(1,"192.168.1.10","192.168.1.1");

  tracer_create_udp_task(NULL,80);
 
  f = kern_fsave();
  k = TracerEventsPresent;
  kern_frestore(f);
  while(k > 0) {
    f = kern_fsave();
    printf_xy(0,5,WHITE,"REM = %08d",k);
    k = TracerEventsPresent;
    kern_frestore(f);
  }
                                                                                                                           
  tracer_flush_sent_events();
                                                                                                                             
  sys_end();

  return NULL;
                                                                                                                             
}

void end_simulation() {

  int i;
  struct loader_task *l = loader_task_list;

  NRT_TASK_MODEL nrt;

  TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0,0);

  tracer_disable();

  i = 0;
  while (i < total_loader_task) {
                                                                                                                             
    group_kill(l->group);

    i++;
    l=&loader_task_list[i];
                                                                                                                             
  }

  nrt_task_default_model(nrt);

  task_activate(task_create("Finish",finish_task,&nrt,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 *)(end_simulation)),NULL);

}

/* Set the zero_time and post the first activation event */
void start_simulation() {
 
  int i;
  struct loader_task *l = loader_task_list;
  struct timespec end_time;

  i  = 0;

  tracer_initialize(10000000);

  tracer_enable();

  TRACER_LOGEVENT(FTrace_EVT_trace_start,0,0,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];

  }

}

/* Activate task and post the new activation event */
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);

  }

}