Rev 1264 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1254 | giacomo | 1 | /* FSF Loader |
2 | * |
||
3 | * Load and run a specific set of tasks/contracts |
||
4 | * |
||
5 | * This is the system indipendent part |
||
6 | * |
||
7 | * Giacomo Guidi <giacomo@gandalf.sssup.it> |
||
8 | * Michael Timarchi <trimarchi@gandalf.sssup.it> |
||
9 | * |
||
10 | */ |
||
11 | |||
12 | #include "fsf_contract.h" //Framework main header |
||
13 | #include "calibrate.h" |
||
14 | #include "func.h" //Generic function definitions |
||
1255 | giacomo | 15 | #include "lconst.h" |
1254 | giacomo | 16 | |
17 | /* Activate task output debug */ |
||
18 | #define TASK_OUTPUT |
||
19 | |||
1255 | giacomo | 20 | int cal_cycles = CALIBRATION_RESULT; //Calibration const, it converts usec to cycles |
1254 | giacomo | 21 | struct timespec zero_time; //Zero time of the simulation |
22 | extern struct loader_task loader_task_list[]; //Loader task array |
||
23 | extern int total_loader_task; //Loader task number |
||
24 | |||
25 | /* OS: Oneshot Task: |
||
26 | begin |
||
27 | - execution |
||
28 | end |
||
29 | */ |
||
30 | void *oneshot_task(void *arg) |
||
31 | { |
||
32 | long long i,exec_cycles = 0; |
||
33 | struct loader_task *l = (struct loader_task *)(arg); |
||
1262 | giacomo | 34 | #ifdef TASK_OUTPUT |
35 | #ifdef OS_SHARK |
||
36 | char tmp[20]; |
||
37 | #endif |
||
38 | #endif |
||
1254 | giacomo | 39 | |
1264 | giacomo | 40 | start_oneshot_task(); |
41 | |||
42 | /* to avoid problem if the task start inside the create function */ |
||
1254 | giacomo | 43 | if (l->act_current == 0) l->act_current = 1; |
44 | #ifdef TASK_OUTPUT |
||
1262 | giacomo | 45 | #ifdef OS_SHARK |
46 | sprintf(tmp,"[ONESHOT]"); |
||
47 | printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp); |
||
48 | #endif |
||
1254 | giacomo | 49 | #endif |
50 | |||
51 | exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles; |
||
52 | |||
53 | /* Execution delay */ |
||
54 | for (i=0;i<exec_cycles;i++) |
||
55 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
||
56 | "cpuid\n\t" |
||
57 | :::"eax","ebx","ecx","edx"); |
||
58 | |||
1264 | giacomo | 59 | end_oneshot_task(); |
1266 | giacomo | 60 | |
61 | #ifdef TASK_OUTPUT |
||
62 | #ifdef OS_SHARK |
||
63 | sprintf(tmp,"[--END--]"); |
||
64 | printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp); |
||
65 | #endif |
||
66 | #endif |
||
1264 | giacomo | 67 | |
1254 | giacomo | 68 | return NULL; |
69 | |||
70 | } |
||
71 | |||
72 | /* CT: Cyclical Task: |
||
73 | begin |
||
74 | while (1) { |
||
75 | - execution |
||
76 | - end_cycle |
||
77 | } |
||
78 | end (never end) |
||
79 | */ |
||
80 | void *periodic_task(void *arg) |
||
81 | { |
||
82 | long long i,exec_cycles = 0; |
||
83 | int act = 0; |
||
84 | struct loader_task *l = (struct loader_task *)(arg); |
||
85 | |||
1262 | giacomo | 86 | #ifdef TASK_OUTPUT |
87 | #ifdef OS_SHARK |
||
88 | char tmp[20]; |
||
89 | #endif |
||
90 | #endif |
||
91 | |||
1264 | giacomo | 92 | start_periodic_task(); |
93 | |||
1254 | giacomo | 94 | if (l->act_current == 0) l->act_current = 1; |
95 | |||
96 | while(1) { |
||
97 | |||
1264 | giacomo | 98 | start_job_periodic_task(); |
99 | |||
1254 | giacomo | 100 | #ifdef TASK_OUTPUT |
1262 | giacomo | 101 | #ifdef OS_SHARK |
102 | sprintf(tmp,"C[%06d]",act); |
||
103 | printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp); |
||
104 | #endif |
||
1254 | giacomo | 105 | #endif |
106 | |||
107 | exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles; |
||
108 | |||
109 | /* Execution delay */ |
||
110 | for (i=0;i<exec_cycles;i++) |
||
111 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
||
112 | "cpuid\n\t" |
||
113 | :::"eax","ebx","ecx","edx"); |
||
114 | |||
1264 | giacomo | 115 | end_job_periodic_task(); |
116 | |||
1254 | giacomo | 117 | generic_task_endcycle(); |
118 | |||
119 | act++; |
||
120 | |||
121 | } |
||
1264 | giacomo | 122 | |
123 | end_periodic_task(); |
||
1266 | giacomo | 124 | |
125 | #ifdef TASK_OUTPUT |
||
126 | #ifdef OS_SHARK |
||
127 | sprintf(tmp,"[--END--]"); |
||
128 | printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp); |
||
129 | #endif |
||
130 | #endif |
||
1254 | giacomo | 131 | |
132 | return NULL; |
||
133 | |||
134 | } |
||
135 | |||
136 | /* BT: Background Task: |
||
137 | begin |
||
138 | while (1) { |
||
139 | - execution |
||
140 | } |
||
141 | end (never end) |
||
142 | */ |
||
143 | void *back_task(void *arg) |
||
144 | { |
||
145 | long long i,exec_cycles = 0; |
||
146 | int act = 0; |
||
147 | struct loader_task *l = (struct loader_task *)(arg); |
||
1262 | giacomo | 148 | #ifdef TASK_OUTPUT |
149 | #ifdef OS_SHARK |
||
150 | char tmp[20]; |
||
151 | #endif |
||
152 | #endif |
||
1254 | giacomo | 153 | |
1264 | giacomo | 154 | start_back_task(); |
155 | |||
1254 | giacomo | 156 | if (l->act_current == 0) l->act_current = 1; |
157 | |||
158 | while(1) { |
||
159 | |||
1264 | giacomo | 160 | start_job_back_task(); |
161 | |||
1254 | giacomo | 162 | #ifdef TASK_OUTPUT |
1262 | giacomo | 163 | #ifdef OS_SHARK |
164 | sprintf(tmp,"B[%06d]",act); |
||
165 | printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp); |
||
166 | #endif |
||
1254 | giacomo | 167 | #endif |
168 | |||
169 | exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles; |
||
170 | |||
171 | /* Execution delay */ |
||
172 | for (i=0;i<exec_cycles;i++) |
||
173 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
||
174 | "cpuid\n\t" |
||
175 | :::"eax","ebx","ecx","edx"); |
||
176 | |||
1264 | giacomo | 177 | end_job_back_task(); |
178 | |||
1254 | giacomo | 179 | act++; |
180 | |||
1264 | giacomo | 181 | } |
182 | |||
183 | end_back_task(); |
||
1266 | giacomo | 184 | |
185 | #ifdef TASK_OUTPUT |
||
186 | #ifdef OS_SHARK |
||
187 | sprintf(tmp,"[--END--]"); |
||
188 | printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp); |
||
189 | #endif |
||
190 | #endif |
||
191 | |||
1254 | giacomo | 192 | return NULL; |
193 | |||
194 | } |
||
195 | |||
196 | /* Task create */ |
||
197 | /* this function create the task struct in memory */ |
||
198 | void loader_task_create() |
||
199 | { |
||
200 | |||
201 | struct loader_task *current = loader_task_list; |
||
202 | int i=0, k=0; |
||
203 | |||
204 | while (k <total_loader_task) { |
||
205 | k++; |
||
206 | |||
207 | for (i=0; i < current->number; i++) { |
||
208 | |||
209 | pthread_t j; |
||
210 | int err = 0; |
||
211 | |||
212 | switch(current->task_type) { |
||
213 | case PAR_TASK_OS: |
||
214 | err = generic_create_thread(generic_get_server_from_contract(current->contract),&j,NULL, |
||
215 | oneshot_task,(void *)current,generic_get_task_model(current)); |
||
216 | break; |
||
217 | case PAR_TASK_BT: |
||
218 | err = generic_create_thread(generic_get_server_from_contract(current->contract),&j,NULL, |
||
219 | back_task,(void *)current,generic_get_task_model(current)); |
||
220 | break; |
||
221 | case PAR_TASK_CT: |
||
222 | err = generic_create_thread(generic_get_server_from_contract(current->contract),&j,NULL, |
||
223 | periodic_task,(void *)current,generic_get_task_model(current)); |
||
224 | break; |
||
225 | } |
||
226 | if (err) { |
||
227 | printf("Error fsf task creating\n"); |
||
228 | generic_end_simulation(); |
||
229 | } |
||
230 | |||
231 | } |
||
232 | |||
233 | current = &loader_task_list[k]; |
||
234 | |||
235 | } |
||
236 | |||
237 | printf("Created %d loader tasks\n",k); |
||
238 | |||
239 | |||
240 | } |
||
241 | |||
242 | /* Main Function */ |
||
243 | int start_environment() |
||
244 | { |
||
245 | |||
246 | extern struct timespec total_time; |
||
247 | |||
248 | /* Calibrate the exec time */ |
||
249 | generic_calibrate_cycle(); |
||
250 | |||
251 | /* Create the servers usign defined contracts */ |
||
252 | generic_fsfinit(); |
||
253 | |||
254 | /* Create the tasks */ |
||
255 | loader_task_create(); |
||
256 | |||
257 | /* Start the simulation */ |
||
258 | generic_start_simulation(); |
||
259 | |||
260 | /* Set the simulation end time */ |
||
261 | generic_set_simulation_time(&total_time); |
||
262 | |||
263 | return 0; |
||
264 | |||
265 | } |