Subversion Repositories shark

Rev

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