Subversion Repositories shark

Rev

Rev 1527 | 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
 
1527 trimarchi 15
mutex_object 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
 
1441 giacomo 114
  sys_end();
115
 
1366 giacomo 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
 
1529 giacomo 169
extern unsigned int clk_per_msec;
170
 
1266 giacomo 171
/* Set the zero_time and post the first activation event */
1254 giacomo 172
void start_simulation() {
173
 
1527 trimarchi 174
  int i, object;
1254 giacomo 175
  struct loader_task *l = loader_task_list;
176
  struct timespec end_time;
177
 
178
  i  = 0;
1527 trimarchi 179
  object = 0;
1254 giacomo 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
 
1529 giacomo 191
   TRACER_LOGEVENT(FTrace_EVT_trace_start,proc_table[exec_shadow].context,clk_per_msec);
192
 
193
  for (i=0;i<10;i++)
194
    if (proc_table[i].context != 0) TRACER_LOGEVENT(FTrace_EVT_id,
195
                                (unsigned short int)proc_table[i].context,i);
1298 giacomo 196
 
1254 giacomo 197
  kern_gettime(&zero_time);
198
 
1529 giacomo 199
  i = 0;
1254 giacomo 200
  while (i < total_loader_task) {
201
 
1304 giacomo 202
    if (l->muxstatus == 1) {
1527 trimarchi 203
      fsf_init_shared_object(&(mutex_table[l->resource]).object,object);
204
      mutex_table[l->resource].operation.op_id=1;
205
      mutex_table[l->resource].operation.wcet.tv_sec=l->block[i].tv_sec;
206
      mutex_table[l->resource].operation.wcet.tv_nsec=l->block[i].tv_nsec;
207
      fsf_declare_shared_object_operation(&mutex_table[l->resource].object,
208
        &mutex_table[l->resource].object);
209
 
1304 giacomo 210
      l->muxstatus = 2;
211
    }
212
 
1254 giacomo 213
    if (l->act_number > 0) {
214
      ADDTIMESPEC(&zero_time, &l->act[0], &end_time);
215
      l->act_current++;
216
      kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);
217
    }
218
 
219
    i++;
220
    l=&loader_task_list[i];
221
 
222
  }
223
 
224
}
225
 
1266 giacomo 226
/* Activate task and post the new activation event */
1254 giacomo 227
void loader_task_activate(struct loader_task *l) {
228
 
229
  struct timespec actual_time,end_time;
230
 
231
  kern_gettime(&actual_time);
232
  group_activate(l->group);
233
 
234
  if (l->act_number > l->act_current) {
235
 
236
    ADDTIMESPEC(&actual_time, &l->act[l->act_current], &end_time);
237
 
238
    l->act_current++;
239
    kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);
240
 
241
  }
242
 
243
}