Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1672 | tullio | 1 | #include "func.h" |
2 | #include "calibrate.h" |
||
3 | #include <tracer.h> |
||
4 | |||
5 | #include "FTrace_udp.h" |
||
6 | #include "FTrace_chunk.h" |
||
7 | |||
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 | extern unsigned int clk_per_msec; |
||
15 | |||
16 | mutex_t mutex_table[MAX_MUTEX]; |
||
17 | int main_chunk; |
||
18 | |||
19 | /* Runtime Calibration */ |
||
20 | int calibrate_cycle() |
||
21 | { |
||
22 | long long i; |
||
23 | struct timespec start,end,diff; |
||
24 | |||
25 | if (cal_cycles != 0) return 0; |
||
26 | |||
27 | kern_cli(); |
||
28 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
||
29 | "cpuid\n\t" |
||
30 | :::"eax","ebx","ecx","edx"); |
||
31 | kern_gettime(&start); |
||
32 | for (i=0;i<CALIBRATION_DELTA;i++) |
||
33 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
||
34 | "cpuid\n\t" |
||
35 | :::"eax","ebx","ecx","edx"); |
||
36 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
||
37 | "cpuid\n\t" |
||
38 | :::"eax","ebx","ecx","edx"); |
||
39 | kern_gettime(&end); |
||
40 | kern_sti(); |
||
41 | |||
42 | SUBTIMESPEC(&end,&start,&diff); |
||
43 | cal_cycles = TIMESPEC2USEC(&diff); |
||
44 | cprintf("Calibration usec/[%d cycles] = %d\n",CALIBRATION_DELTA,cal_cycles); |
||
45 | |||
46 | return 0; |
||
47 | |||
48 | } |
||
49 | |||
50 | int get_server_from_contract(int contract) |
||
51 | { |
||
52 | |||
53 | int i; |
||
54 | |||
55 | for(i=0;i<total_loader_contract;i++) |
||
56 | if (loader_contract_list[i].number == contract) |
||
57 | return loader_contract_list[i].server; |
||
58 | |||
59 | return -1; |
||
60 | |||
61 | } |
||
62 | |||
63 | void *get_task_model(struct loader_task *current) { |
||
64 | if (current->local_scheduler == PAR_POSIX) { |
||
65 | static NRT_TASK_MODEL nrt; |
||
66 | static fsf_sched_params_t pr; |
||
67 | |||
68 | pr.policy=FSF_RR; |
||
69 | pr.params=&nrt; |
||
70 | |||
71 | nrt_task_default_model(nrt); |
||
72 | nrt_task_def_save_arrivals(nrt); |
||
73 | nrt_task_def_ctrl_jet(nrt); |
||
74 | nrt_task_def_group(nrt,current->group); |
||
75 | nrt_task_def_usemath(nrt); |
||
76 | |||
77 | return ≺ |
||
78 | |||
79 | } |
||
80 | |||
81 | if (current->local_scheduler == PAR_EDF) { |
||
82 | static HARD_TASK_MODEL ht; |
||
83 | static fsf_sched_params_t pr; |
||
84 | |||
85 | pr.policy=FSF_EDF; |
||
86 | pr.params=&ht; |
||
87 | |||
88 | hard_task_default_model(ht); |
||
89 | hard_task_def_ctrl_jet(ht); |
||
90 | hard_task_def_mit(ht,TIMESPEC2USEC(¤t->deadline)); |
||
91 | hard_task_def_wcet(ht,TIMESPEC2USEC(¤t->wcet)); |
||
92 | hard_task_def_group(ht,current->group); |
||
93 | hard_task_def_aperiodic(ht); |
||
94 | hard_task_def_usemath(ht); |
||
95 | return ≺ |
||
96 | } |
||
97 | |||
98 | if (current->local_scheduler == PAR_NONE) { |
||
99 | static DUMMY_TASK_MODEL d; |
||
100 | static fsf_sched_params_t pr; |
||
101 | |||
102 | pr.policy=FSF_NONE; |
||
103 | pr.params=&d; |
||
104 | |||
105 | dummy_task_default_model(d); |
||
106 | dummy_task_def_group(d,current->group); |
||
107 | |||
108 | return ≺ |
||
109 | } |
||
110 | |||
111 | |||
112 | if (current->local_scheduler == PAR_RM) { |
||
113 | static HARD_TASK_MODEL ht; |
||
114 | static fsf_sched_params_t pr; |
||
115 | |||
116 | pr.policy=FSF_FP; |
||
117 | pr.params=&ht; |
||
118 | |||
119 | hard_task_default_model(ht); |
||
120 | hard_task_def_mit(ht,TIMESPEC2USEC(¤t->deadline)); |
||
121 | hard_task_def_wcet(ht,TIMESPEC2USEC(¤t->wcet)); |
||
122 | hard_task_def_ctrl_jet(ht); |
||
123 | hard_task_def_group(ht,current->group); |
||
124 | hard_task_def_usemath(ht); |
||
125 | |||
126 | return ≺ |
||
127 | } |
||
128 | |||
129 | return NULL; |
||
130 | |||
131 | } |
||
132 | |||
133 | TASK finish_task() { |
||
134 | |||
135 | #ifdef __NEW_TRACER__ |
||
136 | |||
137 | //FTrace_OSD_init_udp(1,"192.168.82.43","192.168.82.205"); |
||
138 | FTrace_OSD_init_udp(1, "192.168.82.205", "192.168.82.43"); |
||
139 | |||
140 | FTrace_send_chunk(main_chunk, 0, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC); |
||
141 | |||
142 | exit(0); |
||
143 | |||
144 | #else |
||
145 | |||
146 | exit(0); |
||
147 | |||
148 | #endif |
||
149 | |||
150 | return NULL; |
||
151 | |||
152 | } |
||
153 | |||
154 | void end_simulation() { |
||
155 | |||
156 | #ifdef __NEW_TRACER__ |
||
157 | |||
158 | int i; |
||
159 | struct loader_task *l = loader_task_list; |
||
160 | |||
161 | NRT_TASK_MODEL nrt; |
||
162 | |||
163 | TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0); |
||
164 | |||
165 | FTrace_disable(); |
||
166 | |||
167 | i = 0; |
||
168 | while (i < total_loader_task) { |
||
169 | |||
170 | group_kill(l->group); |
||
171 | |||
172 | i++; |
||
173 | l=&loader_task_list[i]; |
||
174 | |||
175 | } |
||
176 | |||
177 | nrt_task_default_model(nrt); |
||
178 | |||
179 | task_activate(task_create("Finish",finish_task,&nrt,NULL)); |
||
180 | |||
181 | #else |
||
182 | |||
183 | exit(0); |
||
184 | |||
185 | #endif |
||
186 | |||
187 | } |
||
188 | |||
189 | void set_simulation_time (struct timespec *total) { |
||
190 | struct timespec end_time; |
||
191 | |||
192 | ADDTIMESPEC(&zero_time,total,&end_time); |
||
193 | kern_event_post(&end_time,(void *)((void *)(end_simulation)),NULL); |
||
194 | |||
195 | } |
||
196 | |||
197 | /* Set the zero_time and post the first activation event */ |
||
198 | void start_simulation() { |
||
199 | |||
200 | int i; |
||
201 | struct loader_task *l = loader_task_list; |
||
202 | struct timespec end_time; |
||
203 | PISTAR_mutexattr_t a; |
||
204 | |||
205 | PISTAR_mutexattr_default(a); |
||
206 | |||
207 | i = 0; |
||
208 | |||
209 | #ifdef __NEW_TRACER__ |
||
210 | |||
211 | main_chunk = FTrace_chunk_create(10000000, 1000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC); |
||
212 | |||
213 | FTrace_actual_chunk_select(main_chunk); |
||
214 | |||
215 | FTrace_enable(); |
||
216 | |||
217 | #endif |
||
218 | |||
219 | //TRACER_LOGEVENT(FTrace_EVT_trace_start,0,0); |
||
220 | |||
221 | TRACER_LOGEVENT(FTrace_EVT_trace_start,proc_table[exec_shadow].context,clk_per_msec); |
||
222 | |||
223 | for (i=0;i<10;i++) |
||
224 | if (proc_table[i].context != 0) TRACER_LOGEVENT(FTrace_EVT_id, |
||
225 | (unsigned short int)proc_table[i].context,i); |
||
226 | i = 0; |
||
227 | |||
228 | kern_gettime(&zero_time); |
||
229 | |||
230 | while (i < total_loader_task) { |
||
231 | |||
232 | if (l->muxstatus == 1) { |
||
233 | mutex_init(&mutex_table[l->resource],&a); |
||
234 | l->muxstatus = 2; |
||
235 | } |
||
236 | |||
237 | if (l->act_number > 0) { |
||
238 | ADDTIMESPEC(&zero_time, &l->act[0], &end_time); |
||
239 | l->act_current++; |
||
240 | kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l); |
||
241 | } |
||
242 | |||
243 | i++; |
||
244 | l=&loader_task_list[i]; |
||
245 | |||
246 | } |
||
247 | |||
248 | } |
||
249 | |||
250 | /* Activate task and post the new activation event */ |
||
251 | void loader_task_activate(struct loader_task *l) { |
||
252 | |||
253 | struct timespec actual_time,end_time; |
||
254 | |||
255 | kern_gettime(&actual_time); |
||
256 | group_activate(l->group); |
||
257 | |||
258 | if (l->act_number > l->act_current) { |
||
259 | |||
260 | ADDTIMESPEC(&actual_time, &l->act[l->act_current], &end_time); |
||
261 | |||
262 | l->act_current++; |
||
263 | kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l); |
||
264 | |||
265 | } |
||
266 | |||
267 | } |