Rev 879 | Rev 881 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
221 | giacomo | 1 | //===================================================================== |
2 | // FFFFFFIII RRRRR SSTTTTTTT |
||
3 | // FF IIR RR SS |
||
4 | // FF IR SS |
||
5 | // FFFFFF RRRR SSSSST |
||
6 | // FF FI RRR SS |
||
7 | // FF II RRR SS |
||
8 | // FF IIIIIR RS |
||
9 | // |
||
10 | // Basic FSF(FIRST Scheduling Framework) contract management |
||
11 | // S.Ha.R.K. Implementation |
||
12 | //===================================================================== |
||
13 | |||
405 | trimarchi | 14 | #include "ll/i386/64bit.h" |
679 | trimarchi | 15 | #include <kernel/kern.h> |
16 | #include <modules/sem.h> |
||
17 | #include <modules/hartport.h> |
||
18 | #include <modules/cabs.h> |
||
405 | trimarchi | 19 | |
868 | trimarchi | 20 | #include "fsf_basic_types.h" |
21 | #include "fsf_configuration_parameters.h" |
||
22 | #include "fsf_core.h" |
||
241 | giacomo | 23 | #include "fsf_server.h" |
679 | trimarchi | 24 | #include "fsf_service_task.h" |
868 | trimarchi | 25 | #include "fsf_hierarchical.h" |
679 | trimarchi | 26 | #include "message.h" |
221 | giacomo | 27 | |
868 | trimarchi | 28 | #include "posixstar.h" |
29 | #include "edfstar.h" |
||
30 | #include "nonestar.h" |
||
31 | #include "rmstar.h" |
||
32 | |||
221 | giacomo | 33 | #include <pthread.h> |
34 | #include <stdlib.h> |
||
808 | trimarchi | 35 | #include "pistar.h" |
868 | trimarchi | 36 | #include <modules/comm_message.h> |
221 | giacomo | 37 | |
417 | giacomo | 38 | //#define FSF_DEBUG |
221 | giacomo | 39 | |
410 | trimarchi | 40 | int current_server=0; |
407 | giacomo | 41 | server_elem server_list[FSF_MAX_N_SERVERS]; |
406 | giacomo | 42 | bandwidth_t fsf_max_bw = 0; |
405 | trimarchi | 43 | |
241 | giacomo | 44 | int fsf_server_level; |
868 | trimarchi | 45 | int fsf_posix_level = -1; |
808 | trimarchi | 46 | int shared_object_level; |
679 | trimarchi | 47 | PID server_task; |
868 | trimarchi | 48 | fsf_contract_parameters_t contract; |
221 | giacomo | 49 | |
868 | trimarchi | 50 | |
679 | trimarchi | 51 | PORT channel[2]; |
52 | |||
868 | trimarchi | 53 | fsf_server_id_t service_server = -1; |
54 | fsf_contract_parameters_t service_contract; |
||
55 | |||
808 | trimarchi | 56 | int FSF_register_shared_object_module(void) { |
811 | trimarchi | 57 | fsf_register_shared_object(); |
808 | trimarchi | 58 | return PISTAR_register_module(); |
59 | } |
||
60 | |||
61 | |||
810 | trimarchi | 62 | int FSF_get_shared_object_level() { |
63 | return shared_object_level; |
||
64 | } |
||
65 | |||
868 | trimarchi | 66 | int FSF_register_module(int posix_level, int server_level, bandwidth_t max_bw) |
224 | giacomo | 67 | { |
68 | printk("FSF Module\n"); |
||
410 | trimarchi | 69 | current_server=0; |
241 | giacomo | 70 | fsf_server_level = server_level; |
868 | trimarchi | 71 | fsf_posix_level = posix_level; |
406 | giacomo | 72 | fsf_max_bw = max_bw; |
811 | trimarchi | 73 | shared_object_level = FSF_register_shared_object_module(); |
679 | trimarchi | 74 | |
224 | giacomo | 75 | return 0; |
76 | |||
77 | } |
||
78 | |||
868 | trimarchi | 79 | void FSF_start_service_task(void) { |
679 | trimarchi | 80 | |
868 | trimarchi | 81 | int err; |
82 | struct timespec default_period = {0,50000000}; |
||
83 | struct timespec default_budget = {0,1000000}; |
||
84 | DUMMY_TASK_MODEL m; |
||
85 | |||
86 | dummy_task_default_model(m); |
||
87 | |||
679 | trimarchi | 88 | // create the service task |
89 | // create the communication channel for negotiation and renegotiation |
||
90 | |||
91 | channel[1] = port_create("CHANW",sizeof(struct mess),1,STREAM,WRITE); |
||
92 | |||
93 | channel[0] = port_create("CHANR",sizeof(struct mess),1,STREAM,READ); |
||
94 | |||
868 | trimarchi | 95 | fsf_initialize_contract(&service_contract); |
96 | |||
97 | fsf_set_contract_basic_parameters(&service_contract,&default_budget,&default_period,FSF_DEFAULT_WORKLOAD); |
||
98 | negotiate_contract(&service_contract,&service_server); |
||
99 | |||
100 | //server_task = task_create("stask",service_task,model,NULL); |
||
101 | err = fsf_create_thread(service_server,&server_task,NULL,service_task,NULL,&m); |
||
102 | if (err) { |
||
679 | trimarchi | 103 | cprintf("error creating service task\n"); |
104 | sys_shutdown_message("Could not create service_task"); |
||
105 | sys_end(); |
||
106 | return; |
||
107 | } |
||
108 | |||
109 | task_activate(server_task); |
||
110 | |||
111 | } |
||
112 | |||
113 | |||
221 | giacomo | 114 | /* Convert the contract specification to |
115 | * budget parameters |
||
116 | */ |
||
241 | giacomo | 117 | int set_SERVER_budget_from_contract |
221 | giacomo | 118 | (const fsf_contract_parameters_t *contract, |
119 | int *budget) |
||
120 | { |
||
121 | |||
122 | int local_scheduler_level = 0; |
||
123 | |||
868 | trimarchi | 124 | switch (contract->policy) { |
125 | case FSF_POSIX: |
||
241 | giacomo | 126 | local_scheduler_level = POSIXSTAR_register_level(fsf_server_level,5000,32); |
221 | giacomo | 127 | break; |
868 | trimarchi | 128 | case FSF_EDF: |
241 | giacomo | 129 | local_scheduler_level = EDFSTAR_register_level(fsf_server_level); |
221 | giacomo | 130 | break; |
868 | trimarchi | 131 | case FSF_RM: |
241 | giacomo | 132 | local_scheduler_level = RMSTAR_register_level(fsf_server_level); |
221 | giacomo | 133 | break; |
868 | trimarchi | 134 | case FSF_NONE: |
855 | trimarchi | 135 | local_scheduler_level = NONESTAR_register_level(fsf_server_level); |
334 | giacomo | 136 | break; |
221 | giacomo | 137 | } |
405 | trimarchi | 138 | |
661 | giacomo | 139 | if (contract->d_equals_t == TRUE) { |
241 | giacomo | 140 | *budget = SERVER_setbudget(fsf_server_level, |
221 | giacomo | 141 | TIMESPEC2USEC(&(contract->budget_min)), |
142 | TIMESPEC2USEC(&(contract->period_max)), |
||
661 | giacomo | 143 | TIMESPEC2USEC(&(contract->period_max)), |
868 | trimarchi | 144 | local_scheduler_level,contract->policy); |
661 | giacomo | 145 | } else { |
146 | *budget = SERVER_setbudget(fsf_server_level, |
||
147 | TIMESPEC2USEC(&(contract->budget_min)), |
||
148 | TIMESPEC2USEC(&(contract->period_max)), |
||
149 | TIMESPEC2USEC(&(contract->deadline)), |
||
868 | trimarchi | 150 | local_scheduler_level,contract->policy); |
661 | giacomo | 151 | } |
221 | giacomo | 152 | |
153 | return 0; |
||
154 | |||
155 | } |
||
156 | |||
405 | trimarchi | 157 | int adjust_SERVER_budget |
158 | (int budget, const TIME budget_actual, |
||
661 | giacomo | 159 | const TIME period_actual, const TIME dline_actual) |
221 | giacomo | 160 | { |
161 | |||
241 | giacomo | 162 | SERVER_adjust_budget(fsf_server_level, |
405 | trimarchi | 163 | budget_actual, |
164 | period_actual, |
||
661 | giacomo | 165 | dline_actual, |
241 | giacomo | 166 | budget); |
221 | giacomo | 167 | |
168 | return 0; |
||
169 | |||
170 | } |
||
171 | |||
172 | /* Admission Test function */ |
||
173 | int add_contract(const fsf_contract_parameters_t *contract) |
||
174 | { |
||
175 | return 0; |
||
176 | |||
177 | } |
||
178 | |||
687 | trimarchi | 179 | void contract_to_server(const fsf_contract_parameters_t *contract, int i) { |
180 | |||
410 | trimarchi | 181 | TIME T,Q; |
182 | #ifdef FSF_DEBUG |
||
183 | int temp; |
||
184 | #endif |
||
185 | |||
186 | T=TIMESPEC2USEC(&contract->period_min); |
||
187 | Q=TIMESPEC2USEC(&contract->budget_max); |
||
188 | mul32div32to32(MAX_BANDWIDTH,Q,T,server_list[current_server].Umax); |
||
189 | |||
417 | giacomo | 190 | T=TIMESPEC2USEC(&contract->period_min); |
191 | server_list[i].Tmin=T; |
||
192 | |||
410 | trimarchi | 193 | T=TIMESPEC2USEC(&contract->period_max); |
194 | server_list[i].Tmax=T; |
||
417 | giacomo | 195 | |
410 | trimarchi | 196 | Q=TIMESPEC2USEC(&contract->budget_min); |
197 | server_list[i].Cmin=Q; |
||
198 | |||
199 | mul32div32to32(MAX_BANDWIDTH,Q,T,server_list[i].Umin); |
||
416 | trimarchi | 200 | server_list[i].U=server_list[i].Umin; |
661 | giacomo | 201 | |
202 | if (contract->d_equals_t == TRUE) { |
||
203 | server_list[i].deadline = 0; |
||
204 | server_list[i].d_equals_t = TRUE; |
||
205 | } else { |
||
206 | server_list[i].deadline = TIMESPEC2USEC(&contract->deadline);; |
||
207 | server_list[i].d_equals_t = FALSE; |
||
208 | } |
||
209 | |||
843 | trimarchi | 210 | server_list[i].Qs = contract->quality; |
211 | server_list[i].Is = contract->importance; |
||
212 | |||
410 | trimarchi | 213 | #ifdef FSF_DEBUG |
214 | mul32div32to32(server_list[i].Umax,100, MAX_BANDWIDTH, temp); |
||
215 | kern_printf("(Umax %d)",temp); |
||
216 | mul32div32to32(server_list[i].Umin,100, MAX_BANDWIDTH, temp); |
||
217 | kern_printf("(Umin %d)",temp); |
||
218 | #endif |
||
219 | |||
687 | trimarchi | 220 | } |
221 | |||
222 | int relink_contract_to_server(const fsf_contract_parameters_t *contract, |
||
223 | fsf_server_id_t server) |
||
224 | { |
||
225 | int i=0; |
||
226 | #ifdef FSF_DEBUG |
||
227 | kern_printf("(Relink Server %d)",server); |
||
228 | #endif |
||
229 | // find contract |
||
230 | while(i<current_server) { |
||
231 | if (server_list[i].server==server) break; |
||
232 | i++; |
||
233 | } |
||
234 | |||
235 | server_list[i].server=server; |
||
843 | trimarchi | 236 | // server_list[i].Qs=1; |
687 | trimarchi | 237 | |
238 | contract_to_server(contract, i); |
||
239 | |||
240 | |||
410 | trimarchi | 241 | return 0; |
242 | |||
243 | } |
||
244 | |||
221 | giacomo | 245 | int link_contract_to_server(const fsf_contract_parameters_t *contract, |
246 | fsf_server_id_t server) |
||
247 | { |
||
407 | giacomo | 248 | #ifdef FSF_DEBUG |
405 | trimarchi | 249 | kern_printf("(Link Server %d)",server); |
250 | #endif |
||
251 | |||
410 | trimarchi | 252 | server_list[current_server].server=server; |
843 | trimarchi | 253 | //server_list[current_server].Qs=1; |
405 | trimarchi | 254 | |
687 | trimarchi | 255 | contract_to_server(contract,current_server); |
405 | trimarchi | 256 | |
410 | trimarchi | 257 | current_server++; |
221 | giacomo | 258 | return 0; |
259 | |||
260 | } |
||
261 | |||
262 | int remove_contract(fsf_server_id_t server) |
||
263 | { |
||
405 | trimarchi | 264 | int i=0; |
265 | // find the contract |
||
410 | trimarchi | 266 | while(i<current_server) { |
405 | trimarchi | 267 | if (server_list[i].server==server) break; |
268 | i++; |
||
269 | } |
||
221 | giacomo | 270 | |
405 | trimarchi | 271 | // compress the array; |
410 | trimarchi | 272 | while (i<(current_server-1)) { |
405 | trimarchi | 273 | server_list[i].server=server_list[i+1].server; |
274 | server_list[i].Umin=server_list[i+1].Umin; |
||
416 | trimarchi | 275 | server_list[i].U=server_list[i+1].Umin; |
405 | trimarchi | 276 | server_list[i].Umax=server_list[i+1].Umax; |
277 | server_list[i].Cmin=server_list[i+1].Cmin; |
||
417 | giacomo | 278 | server_list[i].Tmin=server_list[i+1].Tmin; |
405 | trimarchi | 279 | server_list[i].Tmax=server_list[i+1].Tmax; |
280 | server_list[i].Qs=server_list[i+1].Qs; |
||
661 | giacomo | 281 | server_list[i].deadline = server_list[i+1].deadline; |
282 | server_list[i].d_equals_t = server_list[i+1].d_equals_t; |
||
843 | trimarchi | 283 | server_list[i].Is = server_list[i+1].Is; |
417 | giacomo | 284 | |
405 | trimarchi | 285 | i++; |
286 | } |
||
410 | trimarchi | 287 | current_server--; |
405 | trimarchi | 288 | |
289 | |||
221 | giacomo | 290 | return 0; |
291 | |||
292 | } |
||
293 | |||
868 | trimarchi | 294 | int |
295 | fsf_get_renegotiation_status |
||
296 | (fsf_server_id_t server, |
||
297 | fsf_renegotiation_status_t *renegotiation_status) |
||
298 | { |
||
221 | giacomo | 299 | |
868 | trimarchi | 300 | if (SERVER_get_renegotiation_status(fsf_server_level,server)) |
301 | *renegotiation_status=FSF_IN_PROGRESS; |
||
302 | else |
||
303 | *renegotiation_status=FSF_ADMITTED; |
||
304 | |||
305 | return 0; |
||
306 | |||
307 | |||
308 | } |
||
309 | |||
310 | |||
221 | giacomo | 311 | int fsf_negotiate_contract |
312 | (const fsf_contract_parameters_t *contract, |
||
313 | fsf_server_id_t *server) |
||
314 | { |
||
880 | trimarchi | 315 | struct mess m; |
221 | giacomo | 316 | |
679 | trimarchi | 317 | // send response server is -1 if the operation fail |
880 | trimarchi | 318 | m.type=NEGOTIATE_CONTRACT; |
319 | memmove(&m.contract,contract, sizeof(fsf_contract_parameters_t)); |
||
320 | //kern_printf("(SN:%d)",*server); |
||
321 | port_send(channel[1],&m,BLOCK); |
||
322 | //kern_printf("BR:%d)", *server); |
||
323 | port_receive(channel[0], &m, BLOCK); |
||
324 | //kern_printf("(EN:%d)", *server); |
||
325 | if (m.server==-1) |
||
679 | trimarchi | 326 | return FSF_ERR_CONTRACT_REJECTED; |
221 | giacomo | 327 | |
880 | trimarchi | 328 | *server=m.server; |
679 | trimarchi | 329 | |
221 | giacomo | 330 | return 0; |
331 | |||
332 | } |
||
333 | |||
872 | trimarchi | 334 | int |
335 | fsf_negotiate_contract_for_new_thread |
||
336 | (const fsf_contract_parameters_t *contract, |
||
337 | fsf_server_id_t *server, |
||
338 | pthread_t *thread, |
||
339 | pthread_attr_t *attr, |
||
340 | fsf_thread_code_t thread_code, |
||
341 | void *arg) { |
||
342 | |||
343 | int err=0; |
||
344 | |||
345 | err = fsf_negotiate_contract(contract,server); |
||
346 | if (!err) { |
||
347 | err = pthread_create(thread, attr, thread_code, arg); |
||
348 | if (!err) |
||
349 | err = fsf_bind_thread_to_server(*server,*thread); |
||
350 | } else return err; |
||
351 | |||
352 | return err; |
||
353 | } |
||
354 | |||
355 | int |
||
356 | fsf_negotiate_contract_for_myself |
||
357 | (const fsf_contract_parameters_t *contract, |
||
358 | fsf_server_id_t *server) { |
||
359 | |||
360 | int err=0; |
||
361 | |||
362 | err = fsf_negotiate_contract(contract,server); |
||
880 | trimarchi | 363 | //kern_printf("ENMyS:%d", *server); |
872 | trimarchi | 364 | if (!err) { |
365 | err = fsf_bind_thread_to_server(*server,exec_shadow); |
||
880 | trimarchi | 366 | //kern_printf("EMMyE:%d:%d",*server,err); |
872 | trimarchi | 367 | } else return err; |
368 | |||
369 | return err; |
||
370 | } |
||
371 | |||
868 | trimarchi | 372 | int fsf_unbind_thread_from_server |
373 | (pthread_t thread) |
||
374 | { |
||
375 | |||
376 | int local_scheduler_level, scheduler_id; |
||
377 | |||
378 | /* Move thread from the local scheduler module to posix level */ |
||
379 | |||
380 | #ifdef FSF_DEBUG |
||
381 | kern_printf("(UnBind thread = %d)",thread); |
||
382 | #endif |
||
383 | |||
384 | /* Check if thread exsists */ |
||
385 | if (thread == -1) |
||
386 | return FSF_ERR_BAD_ARGUMENT; |
||
387 | |||
388 | local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level,thread); |
||
389 | scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level,thread); |
||
390 | |||
391 | /* Check if thread is already bind */ |
||
392 | if (scheduler_id == FSF_NONE) { |
||
393 | /* Check if it is bind to a server */ |
||
394 | if (NONESTAR_getbudget(local_scheduler_level,thread) == -1) |
||
395 | return FSF_ERR_BAD_ARGUMENT; |
||
396 | else { |
||
397 | |||
398 | STD_command_message *msg; |
||
399 | NRT_TASK_MODEL nrt; |
||
400 | |||
401 | nrt_task_default_model(nrt); |
||
402 | nrt_task_def_save_arrivals(nrt); |
||
403 | |||
404 | /* Send change level command to local scheduler */ |
||
405 | msg = (STD_command_message *)malloc(sizeof(STD_command_message)); |
||
406 | |||
407 | msg->command = STD_SET_NEW_MODEL; |
||
408 | msg->param = (void *)(&nrt); |
||
409 | level_table[fsf_posix_level]->public_message(fsf_posix_level,thread,msg); |
||
410 | |||
411 | msg->command = STD_SET_NEW_LEVEL; |
||
412 | msg->param = (void *)(fsf_posix_level); |
||
413 | task_message(msg,thread,0); |
||
414 | |||
415 | free(msg); |
||
416 | } |
||
417 | } |
||
418 | |||
419 | return 0; |
||
420 | |||
421 | } |
||
422 | |||
873 | trimarchi | 423 | int |
424 | fsf_bind_local_thread_to_server |
||
425 | (fsf_server_id_t server, |
||
426 | pthread_t thread, |
||
427 | fsf_sched_params_t *sched_params) |
||
428 | { |
||
868 | trimarchi | 429 | |
873 | trimarchi | 430 | STD_command_message *msg; |
431 | int local_scheduler_level,scheduler_id; |
||
432 | |||
433 | /* Move thread from the posix module to local scheduler */ |
||
434 | |||
435 | #ifdef FSF_DEBUG |
||
436 | kern_printf("(Bind thread = %d to Server = %d)",thread,server); |
||
437 | #endif |
||
438 | |||
439 | /* Check if server and thread exsist */ |
||
440 | if (server == -1 || thread == -1) |
||
441 | return FSF_ERR_BAD_ARGUMENT; |
||
442 | |||
443 | local_scheduler_level = SERVER_get_local_scheduler_level_from_budget(fsf_server_level,server); |
||
444 | if (local_scheduler_level==-1) |
||
445 | return FSF_ERR_UNKNOWN_APPSCHEDULED_THREAD; |
||
446 | |||
447 | scheduler_id = SERVER_get_local_scheduler_id_from_budget(fsf_server_level,server); |
||
448 | |||
449 | /* Check if thread is already bind */ |
||
450 | switch(scheduler_id) { |
||
451 | |||
452 | case FSF_RM: |
||
453 | { |
||
454 | TASK_MODEL *m=(TASK_MODEL*)sched_params; |
||
455 | HARD_TASK_MODEL *h=(HARD_TASK_MODEL *)sched_params; |
||
456 | |||
457 | if (m->pclass != HARD_PCLASS) |
||
458 | return FSF_ERR_SCHED_POLICY_NOT_COMPATIBLE; |
||
459 | |||
460 | h = (HARD_TASK_MODEL *)m; |
||
461 | |||
462 | if (!h->wcet || !h->mit) return FSF_ERR_SCHED_POLICY_NOT_COMPATIBLE; |
||
463 | |||
464 | /* now we know that m is a valid model */ |
||
465 | if (RMSTAR_getbudget(local_scheduler_level,thread) != -1) |
||
466 | return FSF_ERR_BAD_ARGUMENT; |
||
467 | |||
468 | /* Set server on local scheduler */ |
||
469 | RMSTAR_setbudget(local_scheduler_level,thread,(int)(server)); |
||
470 | |||
471 | /* Send change level command to posix level */ |
||
472 | } |
||
877 | trimarchi | 473 | break; |
474 | |||
873 | trimarchi | 475 | case FSF_EDF: |
476 | { |
||
477 | TASK_MODEL *m=(TASK_MODEL*)sched_params; |
||
478 | HARD_TASK_MODEL *h=(HARD_TASK_MODEL *)sched_params; |
||
479 | |||
480 | if (m->pclass != HARD_PCLASS) |
||
481 | return FSF_ERR_SCHED_POLICY_NOT_COMPATIBLE; |
||
482 | |||
483 | h = (HARD_TASK_MODEL *)m; |
||
484 | |||
485 | if (!h->wcet || !h->mit) return FSF_ERR_SCHED_POLICY_NOT_COMPATIBLE; |
||
486 | |||
487 | if (EDFSTAR_getbudget(local_scheduler_level,thread) != -1) |
||
488 | return FSF_ERR_BAD_ARGUMENT; |
||
489 | |||
490 | /* Set server on local scheduler */ |
||
491 | EDFSTAR_setbudget(local_scheduler_level,thread,(int)(server)); |
||
492 | |||
493 | } |
||
494 | break; |
||
495 | |||
496 | case FSF_POSIX: |
||
497 | { |
||
498 | TASK_MODEL *m=(TASK_MODEL*)sched_params; |
||
499 | |||
500 | if (m->pclass != NRT_PCLASS) |
||
501 | return FSF_ERR_SCHED_POLICY_NOT_COMPATIBLE; |
||
502 | |||
503 | if (POSIXSTAR_getbudget(local_scheduler_level,thread) != -1) |
||
504 | return FSF_ERR_BAD_ARGUMENT; |
||
505 | |||
506 | /* Set server on local scheduler */ |
||
507 | POSIXSTAR_setbudget(local_scheduler_level,thread,(int)(server)); |
||
508 | } |
||
877 | trimarchi | 509 | break; |
873 | trimarchi | 510 | |
877 | trimarchi | 511 | default: |
512 | |||
873 | trimarchi | 513 | return FSF_ERR_BAD_ARGUMENT; |
877 | trimarchi | 514 | |
873 | trimarchi | 515 | } |
516 | |||
517 | msg = (STD_command_message *)malloc(sizeof(STD_command_message)); |
||
877 | trimarchi | 518 | if (msg) { |
519 | SYS_FLAGS f; |
||
520 | f=kern_fsave(); |
||
873 | trimarchi | 521 | msg->command = STD_SET_NEW_MODEL; |
522 | msg->param = (void *)(sched_params); |
||
523 | level_table[local_scheduler_level]->public_message(local_scheduler_level,thread,msg); |
||
524 | |||
525 | msg->command = STD_SET_NEW_LEVEL; |
||
526 | msg->param = (void *)(local_scheduler_level); |
||
527 | task_message(msg,thread,0); |
||
877 | trimarchi | 528 | kern_frestore(f); |
873 | trimarchi | 529 | free(msg); |
530 | } else return FSF_ERR_INTERNAL_ERROR; |
||
531 | |||
532 | return 0; |
||
533 | |||
534 | } |
||
535 | |||
536 | |||
868 | trimarchi | 537 | int fsf_bind_thread_to_server |
538 | (fsf_server_id_t server, |
||
539 | pthread_t thread) |
||
540 | { |
||
541 | |||
542 | STD_command_message *msg; |
||
543 | int local_scheduler_level,scheduler_id; |
||
544 | |||
545 | /* Move thread from the posix module to local scheduler */ |
||
546 | |||
547 | #ifdef FSF_DEBUG |
||
880 | trimarchi | 548 | kern_printf("(Bthr=%d to Sr=%d)",thread,server); |
868 | trimarchi | 549 | #endif |
550 | |||
551 | /* Check if server and thread exsist */ |
||
552 | if (server == -1 || thread == -1) |
||
553 | return FSF_ERR_BAD_ARGUMENT; |
||
554 | |||
555 | local_scheduler_level = SERVER_get_local_scheduler_level_from_budget(fsf_server_level,server); |
||
873 | trimarchi | 556 | if (local_scheduler_level==-1) |
557 | return FSF_ERR_UNKNOWN_APPSCHEDULED_THREAD; |
||
558 | |||
868 | trimarchi | 559 | scheduler_id = SERVER_get_local_scheduler_id_from_budget(fsf_server_level,server); |
560 | |||
561 | /* Check if thread is already bind */ |
||
562 | if (scheduler_id == FSF_NONE) { |
||
563 | DUMMY_TASK_MODEL rt_arg; |
||
564 | |||
565 | if (NONESTAR_getbudget(local_scheduler_level,thread) != -1) |
||
566 | return FSF_ERR_BAD_ARGUMENT; |
||
567 | |||
568 | /* Set server on local scheduler */ |
||
569 | NONESTAR_setbudget(local_scheduler_level,thread,(int)(server)); |
||
570 | |||
571 | /* Send change level command to posix level */ |
||
572 | msg = (STD_command_message *)malloc(sizeof(STD_command_message)); |
||
573 | |||
574 | msg->command = STD_SET_NEW_MODEL; |
||
575 | msg->param = (void *)(&rt_arg); |
||
576 | level_table[local_scheduler_level]->public_message(local_scheduler_level,thread,msg); |
||
577 | |||
578 | msg->command = STD_SET_NEW_LEVEL; |
||
579 | msg->param = (void *)(local_scheduler_level); |
||
580 | task_message(msg,thread,0); |
||
581 | free(msg); |
||
582 | } else return FSF_ERR_BAD_ARGUMENT; |
||
583 | |||
584 | return 0; |
||
585 | } |
||
586 | |||
241 | giacomo | 587 | int fsf_create_thread |
588 | (fsf_server_id_t server, |
||
589 | pthread_t *thread, |
||
590 | pthread_attr_t *attr, |
||
591 | fsf_thread_code_t thread_code, |
||
592 | void *arg, |
||
593 | void *local_scheduler_arg) |
||
221 | giacomo | 594 | { |
595 | |||
596 | int local_scheduler_level,scheduler_id; |
||
597 | |||
598 | /* Check if server and thread exsist */ |
||
241 | giacomo | 599 | if (server == NIL) |
873 | trimarchi | 600 | return FSF_ERR_BAD_ARGUMENT; |
221 | giacomo | 601 | |
241 | giacomo | 602 | local_scheduler_level = SERVER_get_local_scheduler_level_from_budget(fsf_server_level,server); |
603 | scheduler_id = SERVER_get_local_scheduler_id_from_budget(fsf_server_level,server); |
||
868 | trimarchi | 604 | #ifdef FSF_DEBUG |
605 | kern_printf("sched policy %d", scheduler_id); |
||
606 | #endif |
||
221 | giacomo | 607 | /* Check if thread is already bind */ |
608 | switch (scheduler_id) { |
||
873 | trimarchi | 609 | case FSF_POSIX: |
221 | giacomo | 610 | |
298 | giacomo | 611 | nrt_task_def_arg(*(NRT_TASK_MODEL *)(local_scheduler_arg),arg); |
612 | nrt_task_def_level(*(NRT_TASK_MODEL *)(local_scheduler_arg),local_scheduler_level); |
||
221 | giacomo | 613 | |
298 | giacomo | 614 | *thread = task_create("POSIXSTAR", thread_code, local_scheduler_arg, NULL); |
267 | giacomo | 615 | if (*thread == NIL) { |
616 | #ifdef FSF_DEBUG |
||
617 | kern_printf("(FSF:Error creating thread)"); |
||
618 | #endif |
||
873 | trimarchi | 619 | return FSF_ERR_INTERNAL_ERROR; |
267 | giacomo | 620 | } |
221 | giacomo | 621 | |
241 | giacomo | 622 | POSIXSTAR_setbudget(local_scheduler_level, *thread, (int)(server)); |
234 | giacomo | 623 | |
221 | giacomo | 624 | break; |
868 | trimarchi | 625 | case FSF_EDF: |
221 | giacomo | 626 | |
250 | giacomo | 627 | hard_task_def_arg(*(HARD_TASK_MODEL *)(local_scheduler_arg),arg); |
628 | hard_task_def_level(*(HARD_TASK_MODEL *)(local_scheduler_arg),local_scheduler_level); |
||
629 | |||
630 | *thread = task_create("EDFSTAR", thread_code, local_scheduler_arg, NULL); |
||
631 | if (*thread == NIL) |
||
873 | trimarchi | 632 | return FSF_ERR_INTERNAL_ERROR; |
250 | giacomo | 633 | |
634 | EDFSTAR_setbudget(local_scheduler_level, *thread, (int)(server)); |
||
635 | |||
221 | giacomo | 636 | break; |
235 | giacomo | 637 | |
868 | trimarchi | 638 | case FSF_RM: |
235 | giacomo | 639 | |
273 | giacomo | 640 | hard_task_def_arg(*(HARD_TASK_MODEL *)(local_scheduler_arg),arg); |
641 | hard_task_def_level(*(HARD_TASK_MODEL *)(local_scheduler_arg),local_scheduler_level); |
||
642 | |||
643 | *thread = task_create("RMSTAR", thread_code, local_scheduler_arg, NULL); |
||
644 | if (*thread == NIL) |
||
873 | trimarchi | 645 | return FSF_ERR_INTERNAL_ERROR; |
273 | giacomo | 646 | |
647 | RMSTAR_setbudget(local_scheduler_level, *thread, (int)(server)); |
||
648 | |||
649 | break; |
||
868 | trimarchi | 650 | case FSF_NONE: |
334 | giacomo | 651 | |
868 | trimarchi | 652 | //dummy_task_def_arg(*( DUMMY_TASK_MODEL *)(local_scheduler_arg),arg); |
653 | dummy_task_def_level(*( DUMMY_TASK_MODEL *)(local_scheduler_arg),local_scheduler_level); |
||
879 | trimarchi | 654 | #ifdef FSF_DEBUG |
655 | kern_printf("(None Server create task)"); |
||
656 | #endif |
||
855 | trimarchi | 657 | *thread = task_create("NONESTAR", thread_code, local_scheduler_arg, NULL); |
334 | giacomo | 658 | if (*thread == NIL) |
873 | trimarchi | 659 | return FSF_ERR_INTERNAL_ERROR; |
334 | giacomo | 660 | |
855 | trimarchi | 661 | NONESTAR_setbudget(local_scheduler_level, *thread, (int)(server)); |
334 | giacomo | 662 | |
663 | break; |
||
664 | |||
221 | giacomo | 665 | default: |
873 | trimarchi | 666 | return FSF_ERR_INTERNAL_ERROR; |
221 | giacomo | 667 | break; |
668 | } |
||
811 | trimarchi | 669 | |
670 | #ifdef FSF_DEBUG |
||
671 | kern_printf("(FSF:Insert thread = %d to Server = %d)",*thread,server); |
||
672 | #endif |
||
221 | giacomo | 673 | |
674 | return 0; |
||
675 | |||
676 | } |
||
677 | |||
808 | trimarchi | 678 | int fsf_settask_nopreemptive |
221 | giacomo | 679 | (fsf_server_id_t *server, |
680 | pthread_t thread) |
||
681 | { |
||
682 | int local_scheduler_level, scheduler_id; |
||
683 | |||
241 | giacomo | 684 | local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level,thread); |
685 | scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level, thread); |
||
221 | giacomo | 686 | |
687 | switch (scheduler_id) { |
||
868 | trimarchi | 688 | case FSF_POSIX: |
816 | trimarchi | 689 | POSIXSTAR_set_nopreemtive_current(local_scheduler_level); |
690 | return 1; |
||
808 | trimarchi | 691 | break; |
868 | trimarchi | 692 | case FSF_EDF: |
808 | trimarchi | 693 | EDFSTAR_set_nopreemtive_current(local_scheduler_level); |
694 | return 1; |
||
695 | break; |
||
868 | trimarchi | 696 | case FSF_RM: |
812 | trimarchi | 697 | RMSTAR_set_nopreemtive_current(local_scheduler_level); |
698 | return 1; |
||
808 | trimarchi | 699 | break; |
868 | trimarchi | 700 | case FSF_NONE: |
808 | trimarchi | 701 | break; |
702 | default: |
||
703 | return -1; |
||
704 | } |
||
705 | return -1; |
||
706 | } |
||
707 | |||
708 | |||
709 | int fsf_settask_preemptive |
||
710 | (fsf_server_id_t *server, |
||
711 | pthread_t thread) |
||
712 | { |
||
713 | int local_scheduler_level, scheduler_id; |
||
714 | |||
715 | local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level,thread); |
||
716 | scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level, thread); |
||
717 | |||
718 | switch (scheduler_id) { |
||
868 | trimarchi | 719 | case FSF_POSIX: |
823 | trimarchi | 720 | POSIXSTAR_unset_nopreemtive_current(local_scheduler_level); |
816 | trimarchi | 721 | return 1; |
808 | trimarchi | 722 | break; |
868 | trimarchi | 723 | case FSF_EDF: |
808 | trimarchi | 724 | EDFSTAR_unset_nopreemtive_current(local_scheduler_level); |
725 | return 1; |
||
726 | break; |
||
868 | trimarchi | 727 | case FSF_RM: |
812 | trimarchi | 728 | RMSTAR_unset_nopreemtive_current(local_scheduler_level); |
729 | return 1; |
||
808 | trimarchi | 730 | break; |
868 | trimarchi | 731 | case FSF_NONE: |
808 | trimarchi | 732 | break; |
733 | default: |
||
734 | return -1; |
||
735 | } |
||
736 | |||
737 | return -1; |
||
738 | |||
739 | } |
||
740 | |||
741 | |||
742 | int fsf_get_server |
||
868 | trimarchi | 743 | (pthread_t thread, |
744 | fsf_server_id_t *server) |
||
808 | trimarchi | 745 | { |
746 | int local_scheduler_level, scheduler_id; |
||
747 | |||
748 | local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level,thread); |
||
749 | scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level, thread); |
||
750 | |||
751 | switch (scheduler_id) { |
||
868 | trimarchi | 752 | case FSF_POSIX: |
829 | giacomo | 753 | *server = POSIXSTAR_getbudget(local_scheduler_level,thread); |
754 | return 0; |
||
868 | trimarchi | 755 | case FSF_EDF: |
829 | giacomo | 756 | *server = EDFSTAR_getbudget(local_scheduler_level,thread); |
757 | return 0; |
||
868 | trimarchi | 758 | case FSF_RM: |
829 | giacomo | 759 | *server = RMSTAR_getbudget(local_scheduler_level,thread); |
760 | return 0; |
||
868 | trimarchi | 761 | case FSF_NONE: |
855 | trimarchi | 762 | *server = NONESTAR_getbudget(local_scheduler_level,thread); |
829 | giacomo | 763 | return 0; |
235 | giacomo | 764 | default: |
221 | giacomo | 765 | return -1; |
766 | } |
||
767 | |||
768 | return -1; |
||
769 | |||
770 | } |
||
771 | |||
339 | giacomo | 772 | int fsf_get_server_level(void) |
773 | { |
||
774 | |||
775 | return fsf_server_level; |
||
776 | |||
777 | } |
||
778 | |||
221 | giacomo | 779 | int fsf_cancel_contract |
868 | trimarchi | 780 | (fsf_server_id_t server) |
221 | giacomo | 781 | { |
782 | |||
783 | int local_scheduler_level, scheduler_id; |
||
411 | trimarchi | 784 | SYS_FLAGS f; |
785 | TIME T,Q; |
||
786 | int i=0; |
||
221 | giacomo | 787 | |
788 | #ifdef FSF_DEBUG |
||
868 | trimarchi | 789 | kern_printf("(Remove server %d)",server); |
221 | giacomo | 790 | #endif |
791 | |||
792 | /* Check server id */ |
||
868 | trimarchi | 793 | if (server < 0) |
873 | trimarchi | 794 | return FSF_ERR_BAD_ARGUMENT; |
221 | giacomo | 795 | |
868 | trimarchi | 796 | local_scheduler_level = SERVER_get_local_scheduler_level_from_budget(fsf_server_level,server); |
797 | scheduler_id = SERVER_get_local_scheduler_id_from_budget(fsf_server_level,server); |
||
221 | giacomo | 798 | |
799 | switch (scheduler_id) { |
||
868 | trimarchi | 800 | case FSF_POSIX: |
221 | giacomo | 801 | |
802 | /* Check if some thread use the server */ |
||
868 | trimarchi | 803 | if(POSIXSTAR_budget_has_thread(local_scheduler_level,server)) |
873 | trimarchi | 804 | return FSF_ERR_NOT_CONTRACTED_SERVER; |
221 | giacomo | 805 | |
806 | break; |
||
868 | trimarchi | 807 | case FSF_EDF: |
235 | giacomo | 808 | /* Check if some thread use the server */ |
868 | trimarchi | 809 | if(EDFSTAR_budget_has_thread(local_scheduler_level,server)) |
873 | trimarchi | 810 | return FSF_ERR_NOT_CONTRACTED_SERVER; |
235 | giacomo | 811 | break; |
812 | |||
868 | trimarchi | 813 | case FSF_RM: |
235 | giacomo | 814 | /* Check if some thread use the server */ |
868 | trimarchi | 815 | if(RMSTAR_budget_has_thread(local_scheduler_level,server)) |
873 | trimarchi | 816 | return FSF_ERR_NOT_CONTRACTED_SERVER; |
235 | giacomo | 817 | |
221 | giacomo | 818 | break; |
334 | giacomo | 819 | |
868 | trimarchi | 820 | case FSF_NONE: |
334 | giacomo | 821 | /* Check if some thread use the server */ |
868 | trimarchi | 822 | if(NONESTAR_budget_has_thread(local_scheduler_level,server)) |
873 | trimarchi | 823 | return FSF_ERR_NOT_CONTRACTED_SERVER; |
334 | giacomo | 824 | |
825 | break; |
||
826 | |||
221 | giacomo | 827 | } |
828 | |||
868 | trimarchi | 829 | SERVER_removebudget(fsf_server_level,server); |
221 | giacomo | 830 | |
831 | level_free_descriptor(local_scheduler_level); |
||
405 | trimarchi | 832 | |
868 | trimarchi | 833 | remove_contract(server); |
411 | trimarchi | 834 | |
835 | f=kern_fsave(); |
||
836 | if (recalculate_contract(fsf_max_bw)==-1) { |
||
837 | kern_frestore(f); |
||
873 | trimarchi | 838 | return FSF_ERR_INTERNAL_ERROR; |
411 | trimarchi | 839 | } |
840 | #ifdef FSF_DEBUG |
||
841 | kern_printf("(Adjust budget)"); |
||
842 | #endif |
||
843 | for (i=0; i<current_server; i++) { |
||
844 | mul32div32to32(MAX_BANDWIDTH,server_list[i].Cmin,server_list[i].U,T); |
||
417 | giacomo | 845 | if (T > server_list[i].Tmin ) { |
411 | trimarchi | 846 | server_list[i].actual_budget = server_list[i].Cmin; |
847 | server_list[i].actual_period = T; |
||
417 | giacomo | 848 | #ifdef FSF_DEBUG |
849 | kern_printf("(1 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
850 | #endif |
||
661 | giacomo | 851 | |
852 | if (server_list[i].d_equals_t == TRUE) |
||
853 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, T); |
||
854 | else |
||
855 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, server_list[i].deadline); |
||
856 | |||
411 | trimarchi | 857 | } else { |
417 | giacomo | 858 | mul32div32to32(server_list[i].Tmin,server_list[i].U,MAX_BANDWIDTH,Q); |
411 | trimarchi | 859 | server_list[i].actual_budget = Q; |
417 | giacomo | 860 | server_list[i].actual_period = server_list[i].Tmin; |
861 | #ifdef FSF_DEBUG |
||
862 | kern_printf("(2 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
863 | #endif |
||
661 | giacomo | 864 | |
865 | if (server_list[i].d_equals_t == TRUE) |
||
866 | adjust_SERVER_budget(server_list[i].server,Q, server_list[i].Tmin, server_list[i].Tmin); |
||
867 | else |
||
868 | adjust_SERVER_budget(server_list[i].server,Q, server_list[i].Tmin, server_list[i].deadline); |
||
869 | |||
411 | trimarchi | 870 | } |
416 | trimarchi | 871 | server_list[i].U=server_list[i].Umin; |
411 | trimarchi | 872 | |
873 | } |
||
221 | giacomo | 874 | |
405 | trimarchi | 875 | |
411 | trimarchi | 876 | kern_frestore(f); |
221 | giacomo | 877 | |
878 | return 0; |
||
411 | trimarchi | 879 | |
221 | giacomo | 880 | } |
881 | |||
405 | trimarchi | 882 | int recalculate_contract(bandwidth_t U) { |
416 | trimarchi | 883 | bandwidth_t current_bandwidth; |
418 | giacomo | 884 | unsigned int temp_U; |
416 | trimarchi | 885 | int Qt; |
405 | trimarchi | 886 | int isok=0; |
887 | int i=0; |
||
868 | trimarchi | 888 | int target_importance=FSF_DEFAULT_IMPORTANCE; |
889 | |||
890 | #define MAX_IMPORTANCE 5 |
||
405 | trimarchi | 891 | |
407 | giacomo | 892 | #ifdef FSF_DEBUG |
893 | int temp; |
||
894 | |||
895 | kern_printf("(Recalculate contract)"); |
||
896 | #endif |
||
405 | trimarchi | 897 | |
898 | /* The current bandwidth is the min bandwidth */ |
||
899 | //current_bandwidth=SERVER_return_bandwidth(fsf_server_level); |
||
900 | #ifdef FSF_DEBUG |
||
410 | trimarchi | 901 | kern_printf("(nserver %d)", current_server); |
405 | trimarchi | 902 | #endif |
880 | trimarchi | 903 | //kern_printf("(CS:%d)", current_server); |
405 | trimarchi | 904 | do { |
905 | current_bandwidth=0; |
||
906 | Qt=0; |
||
410 | trimarchi | 907 | for (i=0; i<current_server; i++) { |
843 | trimarchi | 908 | if (server_list[i].Is==target_importance |
909 | && server_list[i].U<server_list[i].Umax && server_list[i].Qs>0) |
||
405 | trimarchi | 910 | Qt+=server_list[i].Qs; |
416 | trimarchi | 911 | current_bandwidth+=server_list[i].U; |
868 | trimarchi | 912 | #ifdef FSF_DEBUG |
843 | trimarchi | 913 | kern_printf("(Qs %d, Qt %d, Is %d)", server_list[i].Qs, Qt,server_list[i].Is); |
868 | trimarchi | 914 | #endif |
405 | trimarchi | 915 | } |
413 | trimarchi | 916 | |
868 | trimarchi | 917 | #ifdef FSF_DEBUG |
405 | trimarchi | 918 | kern_printf("(Total Quality %d)", Qt); |
868 | trimarchi | 919 | #endif |
405 | trimarchi | 920 | isok=1; |
410 | trimarchi | 921 | for (i=0; i<current_server; i++) { |
843 | trimarchi | 922 | if (server_list[i].Is==target_importance && server_list[i].U<server_list[i].Umax && server_list[i].Qs>0) { |
416 | trimarchi | 923 | temp_U=server_list[i].U; |
924 | server_list[i].U=U-current_bandwidth; |
||
925 | mul32div32to32(server_list[i].U, server_list[i].Qs, Qt, server_list[i].U); |
||
926 | temp_U+=server_list[i].U; |
||
927 | |||
928 | if (temp_U<=server_list[i].Umin) { |
||
405 | trimarchi | 929 | server_list[i].U=server_list[i].Umin; |
416 | trimarchi | 930 | } else if (temp_U>server_list[i].Umax) { |
931 | server_list[i].U=server_list[i].Umax; |
||
405 | trimarchi | 932 | isok=0; |
933 | } else server_list[i].U=temp_U; |
||
934 | |||
935 | #ifdef FSF_DEBUG |
||
936 | mul32div32to32(server_list[i].U,100, MAX_BANDWIDTH, temp); |
||
937 | kern_printf("(Server %d bw %d)", server_list[i].server, temp); |
||
938 | #endif |
||
939 | } |
||
940 | } |
||
843 | trimarchi | 941 | target_importance++; |
880 | trimarchi | 942 | } while (!isok || target_importance<=MAX_IMPORTANCE); |
943 | //kern_printf("(RNDNL)"); |
||
405 | trimarchi | 944 | return 0; |
945 | } |
||
946 | |||
221 | giacomo | 947 | int fsf_renegotiate_contract |
948 | (const fsf_contract_parameters_t *new_contract, |
||
949 | fsf_server_id_t server) |
||
950 | { |
||
679 | trimarchi | 951 | |
952 | struct mess message; |
||
221 | giacomo | 953 | |
679 | trimarchi | 954 | // send response server is -1 if the operation fail |
955 | message.type=RENEGOTIATE_CONTRACT; |
||
956 | memmove(&message.contract,new_contract, sizeof(fsf_contract_parameters_t)); |
||
957 | message.server = server; |
||
221 | giacomo | 958 | |
859 | trimarchi | 959 | port_send(channel[1],&message,BLOCK); |
960 | |||
961 | port_receive(channel[0], &message, BLOCK); |
||
962 | |||
679 | trimarchi | 963 | if (message.server==-1) return FSF_ERR_CONTRACT_REJECTED; |
964 | |||
405 | trimarchi | 965 | return 0; |
221 | giacomo | 966 | } |
241 | giacomo | 967 | |
868 | trimarchi | 968 | int fsf_request_contract_renegotiation |
969 | (const fsf_contract_parameters_t *new_contract, |
||
970 | fsf_server_id_t server, |
||
971 | int sig_notify, |
||
972 | union sigval sig_value) |
||
973 | { |
||
974 | |||
975 | struct mess message; |
||
976 | |||
977 | // send response server is -1 if the operation fail |
||
978 | message.type=REQUEST_RENEGOTIATE_CONTRACT; |
||
979 | memmove(&message.contract,new_contract, sizeof(fsf_contract_parameters_t)); |
||
980 | message.server = server; |
||
981 | |||
982 | port_send(channel[1],&message,BLOCK); |
||
983 | |||
984 | port_receive(channel[0], &message, BLOCK); |
||
985 | |||
986 | if (message.server==-1) return FSF_ERR_CONTRACT_REJECTED; |
||
987 | |||
988 | return 0; |
||
989 | } |
||
990 | |||
407 | giacomo | 991 | void print_server_list() |
992 | { |
||
993 | |||
994 | int i; |
||
995 | |||
996 | kern_printf("Server List\n"); |
||
997 | |||
410 | trimarchi | 998 | for(i=0;i<current_server;i++) { |
407 | giacomo | 999 | |
662 | giacomo | 1000 | kern_printf("[%d] Q:%d T:%d D:%d [DeT = %d]\n",server_list[i].server,(int)server_list[i].actual_budget,(int)server_list[i].actual_period,(int)server_list[i].deadline,(int)server_list[i].d_equals_t); |
407 | giacomo | 1001 | |
1002 | } |
||
1003 | |||
1004 | } |
||
808 | trimarchi | 1005 | |
1006 | |||
1007 | int fsf_get_remain_budget(fsf_server_id_t server) { |
||
1008 | |||
825 | trimarchi | 1009 | return SERVER_get_remain_capacity(fsf_server_level, server); |
808 | trimarchi | 1010 | } |
868 | trimarchi | 1011 | |
1012 | int fsf_get_budget_and_period |
||
1013 | (fsf_server_id_t server, |
||
1014 | struct timespec *budget, |
||
1015 | struct timespec *period) { |
||
1016 | TIME bg; |
||
1017 | TIME pd; |
||
1018 | |||
1019 | if (!SERVER_getbudgetinfo(fsf_server_level, &bg, &pd, NULL, server)) { |
||
1020 | if (budget) { |
||
1021 | NULL_TIMESPEC(budget); |
||
1022 | ADDUSEC2TIMESPEC(bg, budget); |
||
1023 | } |
||
1024 | if (period) { |
||
1025 | NULL_TIMESPEC(period); |
||
1026 | ADDUSEC2TIMESPEC(pd, period); |
||
1027 | } |
||
1028 | |||
1029 | return 0; |
||
1030 | } |
||
1031 | return FSF_ERR_BAD_ARGUMENT; |
||
1032 | } |
||
1033 | |||
1034 | int |
||
1035 | fsf_set_service_thread_data |
||
1036 | (const struct timespec *budget, |
||
1037 | const struct timespec *period, |
||
1038 | bool *accepted) { |
||
1039 | |||
1040 | if (budget==NULL && period==NULL) return FSF_ERR_BAD_ARGUMENT; |
||
1041 | fsf_set_contract_basic_parameters(&service_contract,budget,period,FSF_DEFAULT_WORKLOAD); |
||
1042 | *accepted = !fsf_renegotiate_contract(&service_contract,service_server)?true:false; |
||
1043 | return 0; |
||
1044 | |||
1045 | } |
||
1046 | |||
1047 | |||
1048 | |||
1049 | int fsf_get_service_thread_data |
||
1050 | (struct timespec *budget, |
||
1051 | struct timespec *period) { |
||
1052 | |||
1053 | return fsf_get_budget_and_period(service_server, budget, period); |
||
1054 | |||
1055 | } |
||
1056 |