Subversion Repositories shark

Rev

Rev 1540 | 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
 
1538 trimarchi 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;
1543 trimarchi 65
    static fsf_sched_params_t pr;
1254 giacomo 66
 
1543 trimarchi 67
    pr.policy=FSF_POSIX;
68
    pr.params=&nrt;
69
 
1254 giacomo 70
    nrt_task_default_model(nrt);
71
    nrt_task_def_save_arrivals(nrt);
72
    nrt_task_def_ctrl_jet(nrt);
73
    nrt_task_def_group(nrt,current->group);
74
    nrt_task_def_usemath(nrt);
75
 
1543 trimarchi 76
    return &pr;
1254 giacomo 77
 
78
  }  
79
 
80
  if (current->local_scheduler == PAR_EDF) {
81
    static HARD_TASK_MODEL ht;
1543 trimarchi 82
    static fsf_sched_params_t pr;
1254 giacomo 83
 
1543 trimarchi 84
    pr.policy=FSF_EDF;
85
    pr.params=&ht;
86
 
1254 giacomo 87
    hard_task_default_model(ht);
88
    hard_task_def_ctrl_jet(ht);          
89
    hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
90
    hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
91
    hard_task_def_group(ht,current->group);
1265 giacomo 92
    hard_task_def_aperiodic(ht);
1254 giacomo 93
    hard_task_def_usemath(ht);
1543 trimarchi 94
    return &pr;
1254 giacomo 95
  }  
96
 
1540 trimarchi 97
  if (current->local_scheduler == PAR_NONE) {
98
    static DUMMY_TASK_MODEL d;
1543 trimarchi 99
    static fsf_sched_params_t pr;
1254 giacomo 100
 
1543 trimarchi 101
    pr.policy=FSF_NONE;
102
    pr.params=&d;
103
 
1540 trimarchi 104
    dummy_task_default_model(d);
105
    dummy_task_def_group(d,current->group);
106
 
1543 trimarchi 107
    return &pr;
1540 trimarchi 108
  }
109
 
110
 
1254 giacomo 111
  if (current->local_scheduler == PAR_RM) {
112
    static HARD_TASK_MODEL ht;
1543 trimarchi 113
    static fsf_sched_params_t pr;
114
 
115
    pr.policy=FSF_RM;
116
    pr.params=&ht;
117
 
1254 giacomo 118
    hard_task_default_model(ht);
119
    hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
120
    hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
121
    hard_task_def_ctrl_jet(ht);
122
    hard_task_def_group(ht,current->group);
123
    hard_task_def_usemath(ht);
1543 trimarchi 124
 
125
    return &pr;
1254 giacomo 126
  }  
127
 
128
  return NULL;
129
 
1298 giacomo 130
}
1254 giacomo 131
 
1298 giacomo 132
TASK finish_task() {
1307 giacomo 133
 
134
  #ifdef __NEW_TRACER__
135
 
1539 trimarchi 136
  FTrace_OSD_init_udp(1,"192.168.82.43","192.168.82.41");
1298 giacomo 137
 
1366 giacomo 138
  FTrace_send_chunk(main_chunk, 0, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
139
 
1441 giacomo 140
  sys_end();
141
 
1366 giacomo 142
  #else
1307 giacomo 143
 
1298 giacomo 144
  sys_end();
145
 
1366 giacomo 146
  #endif
147
 
1298 giacomo 148
  return NULL;
149
 
150
}
151
 
152
void end_simulation() {
153
 
1348 giacomo 154
  #ifdef __NEW_TRACER__
155
 
1298 giacomo 156
  int i;
157
  struct loader_task *l = loader_task_list;
158
 
159
  NRT_TASK_MODEL nrt;
160
 
1348 giacomo 161
  TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0);
1307 giacomo 162
 
1366 giacomo 163
  FTrace_disable();
1298 giacomo 164
 
165
  i = 0;
166
  while (i < total_loader_task) {
167
 
168
    group_kill(l->group);
169
 
170
    i++;
171
    l=&loader_task_list[i];
172
 
173
  }
174
 
175
  nrt_task_default_model(nrt);
176
 
177
  task_activate(task_create("Finish",finish_task,&nrt,NULL));
178
 
1307 giacomo 179
  #else
180
 
181
  sys_end();
182
 
183
  #endif
184
 
1298 giacomo 185
}
186
 
1254 giacomo 187
void set_simulation_time (struct timespec *total) {
188
  struct timespec end_time;
189
 
190
  ADDTIMESPEC(&zero_time,total,&end_time);
1298 giacomo 191
  kern_event_post(&end_time,(void *)((void *)(end_simulation)),NULL);
1254 giacomo 192
 
1298 giacomo 193
}
1254 giacomo 194
 
1266 giacomo 195
/* Set the zero_time and post the first activation event */
1254 giacomo 196
void start_simulation() {
197
 
1538 trimarchi 198
  int i;
1254 giacomo 199
  struct loader_task *l = loader_task_list;
200
  struct timespec end_time;
1540 trimarchi 201
  PISTAR_mutexattr_t a;
1254 giacomo 202
 
1540 trimarchi 203
  PISTAR_mutexattr_default(a);
1538 trimarchi 204
 
1254 giacomo 205
  i  = 0;
206
 
1307 giacomo 207
  #ifdef __NEW_TRACER__
208
 
1366 giacomo 209
  main_chunk = FTrace_chunk_create(10000000, 1000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
210
 
211
  FTrace_actual_chunk_select(main_chunk);
212
 
213
  FTrace_enable();  
1298 giacomo 214
 
1307 giacomo 215
  #endif
216
 
1538 trimarchi 217
  TRACER_LOGEVENT(FTrace_EVT_trace_start,0,0);
1298 giacomo 218
 
1254 giacomo 219
  kern_gettime(&zero_time);
220
 
221
  while (i < total_loader_task) {
222
 
1304 giacomo 223
    if (l->muxstatus == 1) {
1538 trimarchi 224
      mutex_init(&mutex_table[l->resource],&a);
1304 giacomo 225
      l->muxstatus = 2;
226
    }
227
 
1254 giacomo 228
    if (l->act_number > 0) {
229
      ADDTIMESPEC(&zero_time, &l->act[0], &end_time);
230
      l->act_current++;
231
      kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);
232
    }
233
 
234
    i++;
235
    l=&loader_task_list[i];
236
 
237
  }
238
 
239
}
240
 
1266 giacomo 241
/* Activate task and post the new activation event */
1254 giacomo 242
void loader_task_activate(struct loader_task *l) {
243
 
244
  struct timespec actual_time,end_time;
245
 
246
  kern_gettime(&actual_time);
247
  group_activate(l->group);
248
 
249
  if (l->act_number > l->act_current) {
250
 
251
    ADDTIMESPEC(&actual_time, &l->act[l->act_current], &end_time);
252
 
253
    l->act_current++;
254
    kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);
255
 
256
  }
257
 
258
}