Subversion Repositories shark

Rev

Rev 1245 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1233 giacomo 1
#include "func.h"
1232 giacomo 2
 
1239 giacomo 3
extern int cal_cycles;
4
extern struct timespec zero_time;
1243 giacomo 5
extern struct loader_task loader_task_list[];
1245 giacomo 6
extern struct loader_contract loader_contract_list[];
1242 giacomo 7
extern int total_loader_task;
1245 giacomo 8
extern int total_loader_contract;
1233 giacomo 9
 
1232 giacomo 10
/* Delay Calibration */
11
int calibrate_cycle()
12
{
13
  long long i;
14
  struct timespec start,end,diff;
15
 
1252 giacomo 16
  if (cal_cycles != 0) return;
17
 
1232 giacomo 18
  kern_cli();
19
  kern_gettime(&start);
1245 giacomo 20
  for (i=0;i<CALIBRATION_DELTA;i++)
21
    __asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
22
                          "cpuid\n\t"
23
                          :::"eax","ebx","ecx","edx");
1232 giacomo 24
  kern_gettime(&end);
25
  kern_sti();
26
 
27
  SUBTIMESPEC(&end,&start,&diff);
28
  cal_cycles = TIMESPEC2USEC(&diff);
29
  cprintf("Calibration usec/[%d cycles] = %d\n",CALIBRATION_DELTA,cal_cycles);
30
 
31
  return 0;
32
 
33
}
34
 
1245 giacomo 35
int get_server_from_contract(int contract)
36
{
37
 
38
  int i;
39
 
40
  for(i=0;i<total_loader_contract;i++)
41
    if (loader_contract_list[i].number == contract)
42
      return loader_contract_list[i].server;
43
 
44
  return -1;
45
 
46
}
47
 
1233 giacomo 48
void *get_task_model(struct loader_task *current) {
1239 giacomo 49
  if (current->local_scheduler == PAR_POSIX) {
1232 giacomo 50
    static NRT_TASK_MODEL nrt;
51
 
52
    nrt_task_default_model(nrt);
53
    nrt_task_def_save_arrivals(nrt);
54
    nrt_task_def_ctrl_jet(nrt);
1242 giacomo 55
    nrt_task_def_group(nrt,current->group);
1232 giacomo 56
    nrt_task_def_usemath(nrt);
57
 
58
    return &nrt;
59
 
60
  }  
61
 
1239 giacomo 62
  if (current->local_scheduler == PAR_EDF) {
1232 giacomo 63
    static HARD_TASK_MODEL ht;
64
 
65
    hard_task_default_model(ht);
66
    hard_task_def_ctrl_jet(ht);          
67
    hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
68
    hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
1242 giacomo 69
    hard_task_def_group(ht,current->group);
1232 giacomo 70
    hard_task_def_usemath(ht);
71
    return &ht;
72
  }  
73
 
74
 
1239 giacomo 75
  if (current->local_scheduler == PAR_RM) {
1232 giacomo 76
    static HARD_TASK_MODEL ht;
77
 
78
    hard_task_default_model(ht);
79
    hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
80
    hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
81
    hard_task_def_ctrl_jet(ht);
1242 giacomo 82
    hard_task_def_group(ht,current->group);
1232 giacomo 83
    hard_task_def_usemath(ht);
84
    return &ht;
85
  }  
1234 giacomo 86
 
87
  return NULL;
1232 giacomo 88
 
89
}  
90
 
91
void set_simulation_time (struct timespec *total) {
92
  struct timespec end_time;
93
 
94
  ADDTIMESPEC(&zero_time,total,&end_time);
95
  kern_event_post(&end_time,(void *)((void *)(sys_end)),NULL);
96
 
97
}
98
 
1239 giacomo 99
int calibration_func() {
100
  return kern_gettime(NULL);
101
 
102
}
103
 
104
void start_simulation() {
105
 
1242 giacomo 106
  int i;
1243 giacomo 107
  struct loader_task *l = loader_task_list;
1232 giacomo 108
  struct timespec end_time;
1239 giacomo 109
 
110
  i  = 0;
1243 giacomo 111
 
112
  kern_gettime(&zero_time);
1239 giacomo 113
 
1242 giacomo 114
  while (i < total_loader_task) {
1243 giacomo 115
 
116
    if (l->act_number > 0) {
1239 giacomo 117
      ADDTIMESPEC(&zero_time, &l->act[0], &end_time);
118
      l->act_current++;
1243 giacomo 119
      kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);
1239 giacomo 120
    }
121
 
1243 giacomo 122
    i++;
1244 giacomo 123
    l=&loader_task_list[i];
1243 giacomo 124
 
1239 giacomo 125
  }
126
 
1232 giacomo 127
}
1233 giacomo 128
 
129
 
1239 giacomo 130
void loader_task_activate(struct loader_task *l) {
131
 
132
  struct timespec actual_time,end_time;
133
 
134
  kern_gettime(&actual_time);
135
  group_activate(l->group);
136
 
137
  if (l->act_number > l->act_current) {
138
 
139
    ADDTIMESPEC(&actual_time, &l->act[l->act_current], &end_time);
140
 
141
    l->act_current++;
1243 giacomo 142
    kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);
1239 giacomo 143
 
144
  }
145
 
1233 giacomo 146
}