Subversion Repositories shark

Rev

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