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