Subversion Repositories shark

Rev

Rev 1348 | Rev 1370 | 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
 
1366 giacomo 110
  FTrace_OSD_init_udp(1,"192.168.0.123","192.168.0.12");
1298 giacomo 111
 
1366 giacomo 112
  FTrace_send_chunk(main_chunk, 0, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
113
 
114
  while(1);
115
 
116
  #else
1307 giacomo 117
 
1298 giacomo 118
  sys_end();
119
 
1366 giacomo 120
  #endif
121
 
1298 giacomo 122
  return NULL;
123
 
124
}
125
 
126
void end_simulation() {
127
 
1348 giacomo 128
  #ifdef __NEW_TRACER__
129
 
1298 giacomo 130
  int i;
131
  struct loader_task *l = loader_task_list;
132
 
133
  NRT_TASK_MODEL nrt;
134
 
1348 giacomo 135
  TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0);
1307 giacomo 136
 
1366 giacomo 137
  FTrace_disable();
1298 giacomo 138
 
139
  i = 0;
140
  while (i < total_loader_task) {
141
 
142
    group_kill(l->group);
143
 
144
    i++;
145
    l=&loader_task_list[i];
146
 
147
  }
148
 
149
  nrt_task_default_model(nrt);
150
 
151
  task_activate(task_create("Finish",finish_task,&nrt,NULL));
152
 
1307 giacomo 153
  #else
154
 
155
  sys_end();
156
 
157
  #endif
158
 
1298 giacomo 159
}
160
 
1254 giacomo 161
void set_simulation_time (struct timespec *total) {
162
  struct timespec end_time;
163
 
164
  ADDTIMESPEC(&zero_time,total,&end_time);
1298 giacomo 165
  kern_event_post(&end_time,(void *)((void *)(end_simulation)),NULL);
1254 giacomo 166
 
1298 giacomo 167
}
1254 giacomo 168
 
1266 giacomo 169
/* Set the zero_time and post the first activation event */
1254 giacomo 170
void start_simulation() {
171
 
172
  int i;
173
  struct loader_task *l = loader_task_list;
174
  struct timespec end_time;
1304 giacomo 175
  PI_mutexattr_t a;
1254 giacomo 176
 
1304 giacomo 177
  PI_mutexattr_default(a);
178
 
1254 giacomo 179
  i  = 0;
180
 
1307 giacomo 181
  #ifdef __NEW_TRACER__
182
 
1366 giacomo 183
  main_chunk = FTrace_chunk_create(10000000, 1000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
184
 
185
  FTrace_actual_chunk_select(main_chunk);
186
 
187
  FTrace_enable();  
1298 giacomo 188
 
1307 giacomo 189
  #endif
190
 
1348 giacomo 191
  TRACER_LOGEVENT(FTrace_EVT_trace_start,0,0);
1298 giacomo 192
 
1254 giacomo 193
  kern_gettime(&zero_time);
194
 
195
  while (i < total_loader_task) {
196
 
1304 giacomo 197
    if (l->muxstatus == 1) {
198
      mutex_init(&mutex_table[l->resource],&a);
199
      l->muxstatus = 2;
200
    }
201
 
1254 giacomo 202
    if (l->act_number > 0) {
203
      ADDTIMESPEC(&zero_time, &l->act[0], &end_time);
204
      l->act_current++;
205
      kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);
206
    }
207
 
208
    i++;
209
    l=&loader_task_list[i];
210
 
211
  }
212
 
213
}
214
 
1266 giacomo 215
/* Activate task and post the new activation event */
1254 giacomo 216
void loader_task_activate(struct loader_task *l) {
217
 
218
  struct timespec actual_time,end_time;
219
 
220
  kern_gettime(&actual_time);
221
  group_activate(l->group);
222
 
223
  if (l->act_number > l->act_current) {
224
 
225
    ADDTIMESPEC(&actual_time, &l->act[l->act_current], &end_time);
226
 
227
    l->act_current++;
228
    kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);
229
 
230
  }
231
 
232
}