Subversion Repositories shark

Rev

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

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