Subversion Repositories shark

Rev

Rev 1366 | Rev 1441 | 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"
1298 giacomo 3
#include <tracer.h>
1254 giacomo 4
 
1366 giacomo 5
#include "FTrace_udp.h"
6
#include "FTrace_chunk.h"
7
 
1254 giacomo 8
extern int cal_cycles;
9
extern struct timespec zero_time;
10
extern struct loader_task loader_task_list[];
11
extern struct loader_contract loader_contract_list[];
12
extern int total_loader_task;
13
extern int total_loader_contract;
14
 
1304 giacomo 15
mutex_t mutex_table[MAX_MUTEX];
1366 giacomo 16
int main_chunk;
1304 giacomo 17
 
1266 giacomo 18
/* Runtime Calibration */
1254 giacomo 19
int calibrate_cycle()
20
{
21
  long long i;
22
  struct timespec start,end,diff;
23
 
1255 giacomo 24
  if (cal_cycles != 0) return 0;
1254 giacomo 25
 
26
  kern_cli();
1303 giacomo 27
  __asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
28
                          "cpuid\n\t"
29
                          :::"eax","ebx","ecx","edx");
1254 giacomo 30
  kern_gettime(&start);
31
  for (i=0;i<CALIBRATION_DELTA;i++)
32
    __asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
33
                          "cpuid\n\t"
34
                          :::"eax","ebx","ecx","edx");
1303 giacomo 35
  __asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
36
                          "cpuid\n\t"
37
                          :::"eax","ebx","ecx","edx");
1254 giacomo 38
  kern_gettime(&end);
39
  kern_sti();
40
 
41
  SUBTIMESPEC(&end,&start,&diff);
42
  cal_cycles = TIMESPEC2USEC(&diff);
43
  cprintf("Calibration usec/[%d cycles] = %d\n",CALIBRATION_DELTA,cal_cycles);
44
 
45
  return 0;
46
 
47
}
48
 
49
int get_server_from_contract(int contract)
50
{
51
 
52
  int i;
53
 
54
  for(i=0;i<total_loader_contract;i++)
55
    if (loader_contract_list[i].number == contract)
56
      return loader_contract_list[i].server;
57
 
58
  return -1;
59
 
60
}
61
 
62
void *get_task_model(struct loader_task *current) {
63
  if (current->local_scheduler == PAR_POSIX) {
64
    static NRT_TASK_MODEL nrt;
65
 
66
    nrt_task_default_model(nrt);
67
    nrt_task_def_save_arrivals(nrt);
68
    nrt_task_def_ctrl_jet(nrt);
69
    nrt_task_def_group(nrt,current->group);
70
    nrt_task_def_usemath(nrt);
71
 
72
    return &nrt;
73
 
74
  }  
75
 
76
  if (current->local_scheduler == PAR_EDF) {
77
    static HARD_TASK_MODEL ht;
78
 
79
    hard_task_default_model(ht);
80
    hard_task_def_ctrl_jet(ht);          
81
    hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
82
    hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
83
    hard_task_def_group(ht,current->group);
1265 giacomo 84
    hard_task_def_aperiodic(ht);
1254 giacomo 85
    hard_task_def_usemath(ht);
86
    return &ht;
87
  }  
88
 
89
 
90
  if (current->local_scheduler == PAR_RM) {
91
    static HARD_TASK_MODEL ht;
92
 
93
    hard_task_default_model(ht);
94
    hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
95
    hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
96
    hard_task_def_ctrl_jet(ht);
97
    hard_task_def_group(ht,current->group);
98
    hard_task_def_usemath(ht);
99
    return &ht;
100
  }  
101
 
102
  return NULL;
103
 
1298 giacomo 104
}
1254 giacomo 105
 
1298 giacomo 106
TASK finish_task() {
1307 giacomo 107
 
108
  #ifdef __NEW_TRACER__
109
 
1370 giacomo 110
  FTrace_OSD_init_udp(1,"192.168.82.43","192.168.82.20");
1298 giacomo 111
 
1366 giacomo 112
  FTrace_send_chunk(main_chunk, 0, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
113
 
114
  #else
1307 giacomo 115
 
1298 giacomo 116
  sys_end();
117
 
1366 giacomo 118
  #endif
119
 
1298 giacomo 120
  return NULL;
121
 
122
}
123
 
124
void end_simulation() {
125
 
1348 giacomo 126
  #ifdef __NEW_TRACER__
127
 
1298 giacomo 128
  int i;
129
  struct loader_task *l = loader_task_list;
130
 
131
  NRT_TASK_MODEL nrt;
132
 
1348 giacomo 133
  TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0);
1307 giacomo 134
 
1366 giacomo 135
  FTrace_disable();
1298 giacomo 136
 
137
  i = 0;
138
  while (i < total_loader_task) {
139
 
140
    group_kill(l->group);
141
 
142
    i++;
143
    l=&loader_task_list[i];
144
 
145
  }
146
 
147
  nrt_task_default_model(nrt);
148
 
149
  task_activate(task_create("Finish",finish_task,&nrt,NULL));
150
 
1307 giacomo 151
  #else
152
 
153
  sys_end();
154
 
155
  #endif
156
 
1298 giacomo 157
}
158
 
1254 giacomo 159
void set_simulation_time (struct timespec *total) {
160
  struct timespec end_time;
161
 
162
  ADDTIMESPEC(&zero_time,total,&end_time);
1298 giacomo 163
  kern_event_post(&end_time,(void *)((void *)(end_simulation)),NULL);
1254 giacomo 164
 
1298 giacomo 165
}
1254 giacomo 166
 
1266 giacomo 167
/* Set the zero_time and post the first activation event */
1254 giacomo 168
void start_simulation() {
169
 
170
  int i;
171
  struct loader_task *l = loader_task_list;
172
  struct timespec end_time;
1304 giacomo 173
  PI_mutexattr_t a;
1254 giacomo 174
 
1304 giacomo 175
  PI_mutexattr_default(a);
176
 
1254 giacomo 177
  i  = 0;
178
 
1307 giacomo 179
  #ifdef __NEW_TRACER__
180
 
1366 giacomo 181
  main_chunk = FTrace_chunk_create(10000000, 1000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
182
 
183
  FTrace_actual_chunk_select(main_chunk);
184
 
185
  FTrace_enable();  
1298 giacomo 186
 
1307 giacomo 187
  #endif
188
 
1348 giacomo 189
  TRACER_LOGEVENT(FTrace_EVT_trace_start,0,0);
1298 giacomo 190
 
1254 giacomo 191
  kern_gettime(&zero_time);
192
 
193
  while (i < total_loader_task) {
194
 
1304 giacomo 195
    if (l->muxstatus == 1) {
196
      mutex_init(&mutex_table[l->resource],&a);
197
      l->muxstatus = 2;
198
    }
199
 
1254 giacomo 200
    if (l->act_number > 0) {
201
      ADDTIMESPEC(&zero_time, &l->act[0], &end_time);
202
      l->act_current++;
203
      kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);
204
    }
205
 
206
    i++;
207
    l=&loader_task_list[i];
208
 
209
  }
210
 
211
}
212
 
1266 giacomo 213
/* Activate task and post the new activation event */
1254 giacomo 214
void loader_task_activate(struct loader_task *l) {
215
 
216
  struct timespec actual_time,end_time;
217
 
218
  kern_gettime(&actual_time);
219
  group_activate(l->group);
220
 
221
  if (l->act_number > l->act_current) {
222
 
223
    ADDTIMESPEC(&actual_time, &l->act[l->act_current], &end_time);
224
 
225
    l->act_current++;
226
    kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);
227
 
228
  }
229
 
230
}