Rev 928 | Rev 974 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
929 | lipari | 1 | /** |
2 | @file This file contains the functions and definitions for the core |
||
3 | module. |
||
4 | |||
5 | The file contains all fuinctions and data structures for the core |
||
6 | module of the FSF. |
||
7 | */ |
||
8 | |||
881 | trimarchi | 9 | //fsf_core.h |
10 | //================================================================= |
||
11 | // FFFFFFIII RRRRR SSTTTTTTT |
||
12 | // FF IIR RR SS |
||
13 | // FF IR SS |
||
14 | // FFFFFF RRRR SSSSST |
||
15 | // FF FI RRR SS |
||
16 | // FF II RRR SS |
||
17 | // FF IIIIIR RS |
||
18 | // |
||
19 | // Basic FSF(FIRST Scheduling Framework) contract management |
||
20 | //================================================================ |
||
21 | |||
929 | lipari | 22 | |
881 | trimarchi | 23 | #include <time.h> |
24 | #include <pthread.h> |
||
25 | #include <sys/types.h> |
||
928 | trimarchi | 26 | #include <stdbool.h> |
881 | trimarchi | 27 | |
28 | #include "fsf_configuration_parameters.h" |
||
29 | #include "fsf_opaque_types.h" |
||
30 | #include "fsf_basic_types.h" |
||
31 | |||
32 | #ifndef _FSF_CORE_H_ |
||
33 | #define _FSF_CORE_H_ |
||
34 | |||
35 | |||
928 | trimarchi | 36 | ////////////////////////////////////////////////////////////////////// |
37 | // INITIALIZATION SERVICES |
||
38 | ////////////////////////////////////////////////////////////////////// |
||
881 | trimarchi | 39 | |
928 | trimarchi | 40 | /** |
41 | \ingroup coremodule |
||
881 | trimarchi | 42 | |
928 | trimarchi | 43 | \defgroup core_init Initialization and utilities |
44 | |||
45 | @{ |
||
46 | */ |
||
47 | |||
48 | /** |
||
49 | We cannot call any fsf functions before fsf_init. After calling |
||
50 | fsf_init, the main will be executing in the background. Then, it |
||
51 | can do the negotiations, create the threads and, if needed, |
||
52 | activate them via some user-specified synchronization mechanism. It |
||
53 | may also create a contract for itself. The second time this |
||
54 | function is called it fails. |
||
55 | |||
56 | @retval 0 if the system is initialized |
||
57 | @retval FSF_ERR_SYSTEM_ALREADY_INITIALIZED if the function has already |
||
58 | been called before |
||
59 | |||
60 | @retval others It may also return any of the errors that may be |
||
61 | returned by the underlying operating system primitives |
||
62 | required to perform the FSF system start up |
||
63 | */ |
||
64 | int fsf_init(); |
||
65 | |||
881 | trimarchi | 66 | /** |
67 | This function converts an error code to an error message that is |
||
68 | stored in the buffer starting at the location pointed to by |
||
69 | message. The size of this buffer is specified by the size |
||
70 | argument. If the error message is longer than size-1, it is |
||
71 | truncated to that length. Regardless of whether the message is |
||
72 | truncated or not, a final zero character that marks the end of the |
||
73 | string is stored in the buffer. The function fails if the error |
||
74 | code passed does not correspond to any of the fsf error codes. |
||
928 | trimarchi | 75 | |
76 | @retval FSF_ERR_BAD_ARGUMENT error is not a valid value |
||
881 | trimarchi | 77 | */ |
78 | int fsf_strerror (int error, char *message, size_t size); |
||
79 | |||
928 | trimarchi | 80 | /* @} */ |
81 | |||
881 | trimarchi | 82 | ///////////////////////////////////////////////////////////// |
83 | // CONTRACT PARAMETERS |
||
84 | ///////////////////////////////////////////////////////////// |
||
85 | |||
86 | /** |
||
928 | trimarchi | 87 | \ingroup coremodule |
88 | \defgroup core_contract Contract Creation and Initialization. |
||
881 | trimarchi | 89 | |
90 | These functions are used to create and initialize a contract, and |
||
91 | set its parameters. |
||
92 | */ |
||
93 | /*@{*/ |
||
94 | /** |
||
95 | Contract parameters type; it is an opaque type (i.e. the internal |
||
96 | structure of this data type is implementation dependent). The user |
||
97 | can access and modify the parameters of a contract only with the |
||
98 | proper functions, and should never access the data directly. |
||
99 | */ |
||
100 | typedef FSF_CONTRACT_PARAMETERS_T_OPAQUE fsf_contract_parameters_t; |
||
101 | |||
102 | /** |
||
103 | The operation receives a pointer to a contract parameters object |
||
104 | and initializes it, setting it to the default values. |
||
105 | The default values are: |
||
928 | trimarchi | 106 | - budget min and max are set to 0; |
107 | - period min and max are set to 0; |
||
108 | - the workload is unbounded (FSF_INDETERMINATE); |
||
109 | - the server deadline is equal to the period; |
||
110 | - the budget and deadline overrun are not notified; |
||
111 | - the granularity is set to "continuous"; |
||
112 | - the quality and importance are set to the default values; |
||
113 | - the scheduling policy is FSF_NONE. |
||
881 | trimarchi | 114 | |
115 | @param contract the pointer to the contract variable. |
||
928 | trimarchi | 116 | @retval FSF_ERR_BAD_ARGUMENT contract is NULL |
881 | trimarchi | 117 | */ |
118 | int fsf_initialize_contract (fsf_contract_parameters_t *contract); |
||
119 | |||
120 | // budget_min => {0,0}; |
||
121 | // period_max => {0,0}; |
||
122 | // budget_max => {0,0}; |
||
123 | // period_min => {0,0}; |
||
124 | // workload => DEFAULT_WORKLOAD; |
||
125 | |||
126 | // d_equals_t => DEFAULT_D_EQUALS_T; (false or true) |
||
127 | // deadline => DEFAULT_DEADLINE; |
||
128 | // budget_overrun_sig_notify => 0; (signal number) |
||
129 | // budget_overrun_sig_value => {0, NULL}; |
||
130 | // deadline_miss_sig_notify => 0; (signal number) |
||
131 | // deadline_miss_sig_value => {0, NULL}; |
||
132 | // |
||
133 | // granularity => DEFAULT_GRANULARITY; |
||
134 | // utilization_set; => size = 0 |
||
135 | // quality => DEFAULT_QUALITY; (range 0..100) |
||
136 | // importance => DEFAULT_IMPORTANCE; (range 1..5) |
||
137 | // |
||
138 | // preemption_level => 0; (range 1..2**32-1) |
||
139 | // critical_sections; => size = 0 |
||
140 | |||
141 | // sched_policy => DEFAULT_SCHED_POLICY |
||
142 | // (FSF_NONE) |
||
143 | |||
144 | |||
145 | /** |
||
146 | The operation updates the specified contract parameters object by |
||
147 | setting its budget, period, and workload to the specified input |
||
148 | parameters. (Note: the workload is a basic parameter because |
||
149 | bounded tasks are triggered by the scheduler (see the |
||
150 | fsf_schedule_timed_job() operation), while indeterminate tasks are |
||
151 | not; therefore, their programming model is quite different). |
||
152 | |||
928 | trimarchi | 153 | @param contract the pointer to the contract object |
881 | trimarchi | 154 | @param [in] budget_min the minimum budget for the contract |
155 | @param [in] period_max the maximum period for the contract |
||
928 | trimarchi | 156 | @param [in] workload the kind of workload (can be FSF_BOUNDED or |
157 | FSF_INDETERMINATE) |
||
881 | trimarchi | 158 | |
928 | trimarchi | 159 | @retval 0 if the operation is succesful |
160 | @retval FSF_ERR_BAD_ARGUMENT if any of the pointers is NULL |
||
881 | trimarchi | 161 | or if only one of the timespec values is 0, and also if the workload |
928 | trimarchi | 162 | is not a proper value (FSF_INDETERMINATE or FSF_BOUNDED) |
881 | trimarchi | 163 | */ |
164 | int |
||
165 | fsf_set_contract_basic_parameters |
||
166 | (fsf_contract_parameters_t *contract, |
||
167 | const struct timespec *budget_min, |
||
168 | const struct timespec *period_max, |
||
169 | fsf_workload_t workload); |
||
170 | |||
171 | /** |
||
172 | This operation obtains from the specified contract parameters |
||
173 | object its budget, period, and workload, and copies them to the |
||
174 | places pointed to by the corresponding input parameters. |
||
175 | |||
176 | @param [in] contract the pointer to the contract object |
||
177 | @param[out] budget_min pointer to the variable that will contain |
||
178 | the minimum budget |
||
179 | @param[out] period_max pointer to the variable that will contain the |
||
180 | max_period |
||
181 | @param[out] workload pointer to the variable that will contain the |
||
182 | workload type |
||
183 | |||
928 | trimarchi | 184 | @retval FSF_ERR_BAD_ARGUMENT : if contract is NULL |
881 | trimarchi | 185 | */ |
186 | int |
||
187 | fsf_get_contract_basic_parameters |
||
188 | (const fsf_contract_parameters_t *contract, |
||
189 | struct timespec *budget_min, |
||
190 | struct timespec *period_max, |
||
191 | fsf_workload_t *workload); |
||
192 | |||
193 | |||
194 | /** |
||
195 | The operation updates the specified contract parameters |
||
196 | object, specifying the additional parameters requirements of |
||
197 | a contract. |
||
198 | |||
199 | @param contract The pointer to the contract object |
||
200 | |||
201 | @param [in] d_equals_t It is a boolean value, set to true (1) if the |
||
202 | we want to specify a deadline different from the period |
||
203 | for the contract. |
||
204 | @param [in] deadline If the previous parameter is set to true, |
||
205 | this parameter should be set to NULL_DEADLINE. Otherwise, |
||
206 | it contains the desired deadline value. |
||
207 | (PEPPE: should be return with error otherwise?) |
||
208 | @param [in] budget_overrun_sig_notify contains the number of posix signal |
||
209 | that must be raised if the budget of the server is overrun. |
||
210 | If the value of this parameter is NULL_SIGNAL, no signal will |
||
211 | be raised. |
||
212 | @param [in] budget_overrun_sig_value contains the value that will be |
||
213 | passed to the signal "catcher" when the signal is raised. |
||
214 | This parameters is not used if the budget_overrun_sig_notify |
||
215 | parameters is set to NULL_SIGNAL. |
||
216 | @param [in] deadline_miss_sig_notify contains the number of posix |
||
217 | signal that must be raised if the deadline of the server |
||
218 | is missed. If the value of this parameter is NULL_SIGNAL, |
||
219 | no signal is raised. |
||
220 | @param [in] deadline_miss_sig_value contains the value that will be |
||
221 | passed to the signal "catcher" when the signal is raised. |
||
222 | This parameters is not used if the budget_overrun_sig_notify |
||
223 | parameters is set to NULL_SIGNAL |
||
224 | |||
928 | trimarchi | 225 | @retval 0 if the operation is succesful |
226 | @retval FSF_BAD_ARGUMENT if contract is NULL or |
||
881 | trimarchi | 227 | (d_equals_t is true and deadline is not FSF_NULL_DEADLINE) or |
228 | (budget_overrun_sig_notify is not a valid signal) or |
||
229 | (deadline_miss_sig_notify is not a valid signal) or |
||
230 | (d_equals_t is false but (deadline is FSF_NULL_DEADLINE or its value |
||
928 | trimarchi | 231 | is grater than the contract´s maximum period)) |
881 | trimarchi | 232 | |
233 | @see sigexplanation |
||
234 | */ |
||
235 | int |
||
236 | fsf_set_contract_timing_requirements |
||
237 | (fsf_contract_parameters_t *contract, |
||
238 | bool d_equals_t, |
||
239 | const struct timespec *deadline, |
||
240 | int budget_overrun_sig_notify, |
||
241 | union sigval budget_overrun_sig_value, |
||
242 | int deadline_miss_sig_notify, |
||
243 | union sigval deadline_miss_sig_value); |
||
244 | |||
245 | /** |
||
246 | The operation obtains the corresponding input parameters from the |
||
247 | specified contract parameters object. If d_equals_t is true, the |
||
248 | deadline will not be updated. |
||
249 | |||
928 | trimarchi | 250 | @retval FSF_ERR_BAD_ARGUMENT if contract is NULL |
251 | |||
252 | @see fsf_set_contract_timing_requirements |
||
881 | trimarchi | 253 | */ |
254 | int |
||
255 | fsf_get_contract_timing_requirements |
||
256 | (const fsf_contract_parameters_t *contract, |
||
257 | bool *d_equals_t, |
||
258 | struct timespec *deadline, |
||
259 | int *budget_overrun_sig_notify, |
||
260 | union sigval *budget_overrun_sig_value, |
||
261 | int *deadline_miss_sig_notify, |
||
262 | union sigval *deadline_miss_sig_value); |
||
263 | |||
264 | /*@}*/ |
||
265 | |||
266 | ////////////////////////////////////////////////////////////////// |
||
267 | // SYNCHRONIZATION OBJECTS |
||
268 | ////////////////////////////////////////////////////////////////// |
||
269 | |||
270 | |||
271 | /** |
||
928 | trimarchi | 272 | \ingroup coremodule |
273 | |||
274 | \defgroup core_synch Synchronization objects |
||
275 | |||
276 | These objects are used to synchronize threads belonging to bounded |
||
277 | workload servers. |
||
278 | |||
279 | In the future we may add a broadcast operation that would signal a |
||
280 | group of synchronization objects. We have not included a broadcast |
||
281 | service in this version because it can be easily created by the |
||
282 | user by signalling individual synchronization objects inside a |
||
283 | loop. |
||
284 | |||
285 | Notice that for synchronization objects there is no naming service |
||
286 | like in shared objects because tasks that use synchronization are |
||
287 | not developed independently, as they are closely coupled. |
||
288 | |||
881 | trimarchi | 289 | */ |
290 | /*@{*/ |
||
291 | /** |
||
292 | An abstract synchronization object is defined by the application. |
||
293 | This object can be used by an application to wait for an event to |
||
294 | arrive by invoking the fsf_schedule_triggered_job() operation. It |
||
295 | can also be used to signal the event either causing a waiting |
||
296 | server to wake up, or the event to be queued if no server is |
||
297 | waiting for it. |
||
298 | */ |
||
299 | typedef FSF_SYNCH_OBJ_HANDLE_T_OPAQUE fsf_synch_obj_handle_t; |
||
300 | |||
301 | |||
302 | /** |
||
303 | This operation creates and initializes a synchronization object |
||
304 | variable managed by the scheduler, and returns a handle to it in |
||
305 | the variable pointed to by synch_handle. |
||
306 | |||
929 | lipari | 307 | @param[out] synch_handle pointer to the variable that will contain |
308 | the handle to the newly created synchronization object |
||
881 | trimarchi | 309 | |
928 | trimarchi | 310 | @retval 0 if the operation is succesful |
311 | @retval FSF_ERR_BAD_ARGUMENT if synch_handle is 0 |
||
312 | @retval FSF_ERR_TOO_MANY_SYNCH_OBJS if the number of synchronization |
||
313 | objects in the system has already exceeded the maximum |
||
314 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is not |
||
315 | scheduled under the FSF |
||
316 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong |
||
317 | or not running |
||
881 | trimarchi | 318 | */ |
319 | int |
||
320 | fsf_create_synch_obj |
||
321 | (fsf_synch_obj_handle_t *synch_handle); |
||
322 | |||
928 | trimarchi | 323 | /** |
889 | trimarchi | 324 | |
881 | trimarchi | 325 | This function sends a notification to the synchronization object |
928 | trimarchi | 326 | specified as parameter. If there is at least one server waiting on |
327 | the synchronization object, the corresponding thread is unblocked, |
||
328 | and the server rules for budget recharging apply. |
||
881 | trimarchi | 329 | |
928 | trimarchi | 330 | If more than one server is waiting, just one of them is woken. |
331 | However, which one is woken is implementation dependent. |
||
332 | |||
333 | If no thread is waiting on the synchronization object, the |
||
334 | notification is queued. |
||
335 | |||
881 | trimarchi | 336 | @param [in] synch_handle the handle of the synchronization object to |
337 | notify. |
||
338 | |||
928 | trimarchi | 339 | @retval 0 if the operation is completed succesfully |
340 | @retval FSF_ERR_BAD_ARGUMENT if synch_handle is 0 |
||
341 | @retval FSF_ERR_INVALID_SYNCH_OBJ_HANDLE if the handle is not valid |
||
342 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread |
||
343 | is not scheduled under the FSF |
||
344 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or |
||
345 | not running |
||
346 | @retval FSF_ERR_TOO_MANY_EVENTS_IN_SYNCH_OBJ if the number of |
||
347 | events stored in the synchronization object reaches the |
||
348 | maximum defined in the configuration parameter header file |
||
881 | trimarchi | 349 | |
928 | trimarchi | 350 | @see fsf_schedule_triggered_job, fsf_timed_schedule_triggered_job |
881 | trimarchi | 351 | */ |
352 | int |
||
353 | fsf_signal_synch_obj |
||
354 | (fsf_synch_obj_handle_t synch_handle); |
||
355 | |||
356 | /** |
||
357 | This operation destroys the synchronization object (created by a |
||
358 | previous call to fsf_create_synch_obj) that is referenced by the |
||
359 | synch_handle variable. After calling this operation, the |
||
360 | synch_handle variable can not be used until it is initialized again |
||
361 | by a call to fsf_create_synch_obj. |
||
362 | |||
363 | @param synch_handle the handle to the synchronization object |
||
364 | to be destroyed |
||
365 | |||
928 | trimarchi | 366 | @retval 0 if the operation is succesful |
367 | @retval FSF_ERR_INVALID_SYNCH_OBJ_HANDLE is the handle is not valid |
||
368 | @retval FSF_ERR_BAD_ARGUMENT if synch_handle is 0 |
||
369 | @retval FSF_ERR_INVALID_SYNCH_OBJ_HANDLE if the handle is not valid |
||
370 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is not |
||
881 | trimarchi | 371 | scheduled under the FSF |
928 | trimarchi | 372 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or |
373 | not running |
||
881 | trimarchi | 374 | |
928 | trimarchi | 375 | @see fsf_create_synch_obj |
881 | trimarchi | 376 | */ |
377 | int |
||
378 | fsf_destroy_synch_obj |
||
379 | (fsf_synch_obj_handle_t synch_handle); |
||
380 | |||
381 | |||
382 | //////////////////////////////////////////////////// |
||
383 | // SCHEDULING BOUNDED WORKLOADS |
||
384 | //////////////////////////////////////////////////// |
||
385 | |||
386 | /** |
||
387 | This operation is invoked by threads associated with bounded |
||
388 | workload servers to indicate that a job has been completed (and |
||
389 | that the scheduler may reassign the unused capacity of the current |
||
390 | job to other servers). It is also invoked when the first job of |
||
391 | such threads has to be scheduled. (PEPPE: I have a question, what |
||
392 | happens to the budget? if I do not get it wrong, the replenishment |
||
393 | time is set to abs_time and the bandwidth of the server up to time |
||
394 | abs_time can be reassigned. Is it true? what is the exact |
||
395 | relationship between this abs_time and the server period? What if |
||
396 | the user specifies an abs_time less than the end of the current |
||
397 | server period??) |
||
398 | |||
399 | As an effect, the system will make the current server's budget zero |
||
400 | for the remainder of the server's period, and will not replenish |
||
401 | the budget until the specified absolute time. At that time, all |
||
402 | pending budget replenishments (if any) are made effective. Once the |
||
403 | server has a positive budget and the scheduler schedules the |
||
404 | calling thread again, the call returns and at that time, except for |
||
405 | those parameters equal to NULL pointers, the system reports the |
||
406 | current period and budget for the current job, whether the deadline |
||
407 | of the previous job was missed or not, and whether the budget of |
||
408 | the previous job was overrun or not. |
||
409 | |||
410 | In a system with hierarchical scheduling, since this call makes the |
||
411 | budget zero, the other threads in the same server are not run. As |
||
412 | mentioned abobe, only when the call finishes the budget may be |
||
413 | replenished. |
||
414 | |||
415 | @param [in] abs_time absolute time at which the budget will be |
||
416 | replenished |
||
417 | |||
418 | @param [out] next_budget upon return of this function, the variable |
||
419 | pointed by this function will be equal to |
||
420 | the current server budget. If this parameter is |
||
421 | set to NULL, no action is taken. |
||
422 | |||
423 | @param [out] next_period upon return of this function, the variable |
||
424 | pointed by this function will be equal to |
||
425 | the current server period. If this parameter is |
||
426 | set to NULL, no action is taken. |
||
427 | |||
428 | @param [out] was_deadline_missed upon return of this function, the |
||
429 | variable pointed by this function will be |
||
430 | equal to true if the previous server deadline |
||
431 | was missed, to false otherwise. If this |
||
432 | parameter is set to NULL, no action is |
||
433 | taken. |
||
434 | |||
929 | lipari | 435 | @param [out] was_budget_overran upon return of this function, the |
881 | trimarchi | 436 | variable pointed by this function will be |
437 | equal to true if the previous server budget was |
||
438 | overrun, to false otherwise. If this |
||
439 | parameter is set to NULL, no action is |
||
440 | taken. |
||
441 | |||
928 | trimarchi | 442 | @retval 0 if the operation is succesful |
443 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or |
||
444 | not running |
||
445 | @retval FSF_ERR_INTERNAL_ERROR erroneous binding or malfunction of the FSF |
||
881 | trimarchi | 446 | main scheduler |
928 | trimarchi | 447 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is |
448 | not scheduled under the FSF |
||
449 | @retval FSF_ERR_UNBOUND if the calling thread does not have a valid |
||
881 | trimarchi | 450 | server bound to it |
928 | trimarchi | 451 | @retval FSF_ERR_BAD_ARGUMENT if the workload of the server is not |
452 | FSF_BOUNDED |
||
881 | trimarchi | 453 | |
454 | @sa fsf_schedule_triggered_job, fsf_timed_schedule_triggered_job |
||
455 | */ |
||
456 | int |
||
457 | fsf_schedule_timed_job |
||
458 | (const struct timespec *abs_time, |
||
459 | struct timespec *next_budget, |
||
460 | struct timespec *next_period, |
||
461 | bool *was_deadline_missed, |
||
462 | bool *was_budget_overran); |
||
463 | |||
464 | /** |
||
465 | This operation is invoked by threads associated with bounded |
||
466 | workload servers to indicate that a job has been completed (and |
||
467 | that the scheduler may reassign the unused capacity of the current |
||
468 | job to other servers). It is also invoked when the first job of |
||
469 | such threads has to be scheduled. If the specified synchronization |
||
470 | object has events queued, one of them is dequeued; otherwise the |
||
471 | server will wait upon the specified synchronization object, the |
||
472 | server's budget will be made zero for the remainder of the server's |
||
473 | period, and the implementation will not replenish the budget until |
||
928 | trimarchi | 474 | the specified synchronization object is signalled. |
881 | trimarchi | 475 | |
928 | trimarchi | 476 | At that time, all pending budget replenishments (if any) are made |
477 | effective. Once the server has a positive budget and the scheduler |
||
478 | schedules the calling thread again, the call returns and at that |
||
479 | time, except for those parameters equal to NULL pointers, the |
||
480 | system reports the current period and budget for the current job, |
||
481 | whether the deadline of the previous job was missed or not, and |
||
482 | whether the budget of the previous job was overrun or not. |
||
483 | |||
881 | trimarchi | 484 | In a system with hierarchical scheduling, since this call makes the |
485 | budget zero, the other threads in the same server are not run. As |
||
486 | mentioned above, only when the call finishes the budget may be |
||
487 | replenished. |
||
488 | |||
928 | trimarchi | 489 | @param [in] synch_handle handle of the synchronization object |
881 | trimarchi | 490 | |
928 | trimarchi | 491 | @param [out] next_budget upon return of this function, the variable |
492 | pointed by this function will be equal |
||
493 | to the current server budget. If this |
||
494 | parameter is set to NULL, no action is |
||
495 | taken. |
||
496 | @param [out] next_period upon return of this function, the variable |
||
497 | pointed by this function will be equal to |
||
498 | the current server period. If this parameter is |
||
499 | set to NULL, no action is taken. |
||
881 | trimarchi | 500 | |
928 | trimarchi | 501 | @param [out] was_deadline_missed upon return of this function, the |
502 | variable pointed by this function will be |
||
503 | equal to true if the previous server deadline |
||
504 | was missed, to false otherwise. If this |
||
505 | parameter is set to NULL, no action is |
||
506 | taken. |
||
507 | |||
929 | lipari | 508 | @param [out] was_budget_overran upon return of this function, the |
928 | trimarchi | 509 | variable pointed by this function will be |
510 | equal to true if the previous server budget was |
||
511 | overrun, to false otherwise. If this |
||
512 | parameter is set to NULL, no action is |
||
513 | taken. |
||
514 | |||
515 | @retval 0 if the operation is succesful |
||
516 | @retval FSF_ERR_INVALID_SYNCH_OBJ_HANDLE if the handle is not valid |
||
517 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or not |
||
518 | running |
||
519 | @retval FSF_ERR_INTERNAL_ERROR erroneous binding or malfunction of |
||
520 | the FSF main scheduler |
||
521 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread |
||
522 | is not scheduled under the FSF |
||
523 | @retval FSF_ERR_UNBOUND if the calling thread does not have |
||
524 | a valid server bound to it |
||
525 | @retval FSF_ERR_BAD_ARGUMENT if the workload of the server is not |
||
526 | FSF_BOUNDED or the synch_handle given is not valid |
||
527 | |||
528 | @sa fsf_schedule_triggered_job, fsf_schedule_timed_job |
||
529 | |||
881 | trimarchi | 530 | */ |
531 | int |
||
532 | fsf_schedule_triggered_job |
||
533 | (fsf_synch_obj_handle_t synch_handle, |
||
534 | struct timespec *next_budget, |
||
535 | struct timespec *next_period, |
||
536 | bool *was_deadline_missed, |
||
537 | bool *was_budget_overran); |
||
538 | |||
539 | |||
540 | /** |
||
541 | This call is the same as fsf_schedule_triggered_job, but with an |
||
542 | absolute timeout. The timed_out argument, indicates whether the |
||
543 | function returned because of a timeout or not |
||
544 | |||
928 | trimarchi | 545 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or |
546 | not running |
||
547 | @retval FSF_ERR_INTERNAL_ERROR erroneous binding or malfunction |
||
548 | of the FSF main scheduler |
||
549 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is |
||
550 | not scheduled under the FSF |
||
551 | @retval FSF_ERR_UNBOUND if the calling thread does not have a valid |
||
881 | trimarchi | 552 | server bound to it |
928 | trimarchi | 553 | @retval FSF_ERR_BAD_ARGUMENT if the workload of the server is not |
554 | FSF_BOUNDED, the synch_handle given is not valid or the abs_timeout |
||
555 | argument is NULL or its value is in the past |
||
881 | trimarchi | 556 | |
928 | trimarchi | 557 | @see fsf_schedule_triggered_job |
881 | trimarchi | 558 | */ |
559 | int |
||
560 | fsf_timed_schedule_triggered_job |
||
561 | (fsf_synch_obj_handle_t synch_handle, |
||
562 | const struct timespec *abs_timeout, |
||
563 | bool *timed_out, |
||
564 | struct timespec *next_budget, |
||
565 | struct timespec *next_period, |
||
566 | bool *was_deadline_missed, |
||
567 | bool *was_budget_overran); |
||
568 | |||
569 | /*@}*/ |
||
570 | |||
571 | /////////////////////////////////////////////////////////////////// |
||
572 | // CONTRACT NEGOCIATION OPERATIONS |
||
573 | /////////////////////////////////////////////////////////////////// |
||
574 | |||
575 | /** |
||
928 | trimarchi | 576 | \ingroup coremodule |
881 | trimarchi | 577 | |
928 | trimarchi | 578 | \defgroup core_negotiate Negotiate contract functions |
579 | |||
881 | trimarchi | 580 | The following functions are used to create servers for a contract |
581 | parameters specification and also to assign one or more threads to |
||
929 | lipari | 582 | a server. |
881 | trimarchi | 583 | */ |
584 | /*@{*/ |
||
585 | |||
586 | /** |
||
587 | Server Id type, that identifies a server created to manage a given |
||
588 | contract |
||
589 | */ |
||
590 | typedef int fsf_server_id_t; // => 0 |
||
591 | |||
592 | /** |
||
593 | The type references a function that may become a thread's |
||
594 | code |
||
595 | */ |
||
596 | typedef void * (*fsf_thread_code_t) (void *); |
||
597 | |||
598 | /** |
||
599 | The operation negotiates a contract for a new server. If the |
||
600 | on-line admission test is enabled it determines whether the |
||
601 | contract can be admitted or not based on the current contracts |
||
602 | established in the system. Then it creates the server and |
||
603 | recalculates all necessary parameters for the contracts already |
||
928 | trimarchi | 604 | present in the system. |
881 | trimarchi | 605 | |
928 | trimarchi | 606 | This is a potentially blocking operation; it returns when the |
607 | system has either rejected the contract, or admitted it and made it |
||
608 | effective. It returns zero and places the server identification |
||
609 | number in the location pointed to by the server input parameter if |
||
610 | accepted, or an error if rejected. No thread is bound to the newly |
||
611 | created server, which will be idle until a thread is bound to |
||
612 | it. This operation can only be executed by threads that are already |
||
613 | bound to an active server and therefore are being scheduled by the |
||
614 | fsf scheduler. |
||
881 | trimarchi | 615 | |
928 | trimarchi | 616 | @param [in] contract pointer to the contract |
617 | @param [out] server server id |
||
618 | |||
619 | @retval 0 if the call is succesful |
||
620 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or not |
||
621 | running |
||
622 | @retval FSF_ERR_INTERNAL_ERROR erroneous binding or malfunction of the FSF |
||
623 | main scheduler |
||
624 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD |
||
625 | if the calling thread is not scheduled |
||
626 | under the FSF |
||
627 | @retval FSF_ERR_BAD_ARGUMENT if the contract or server arguments |
||
628 | are NULL |
||
881 | trimarchi | 629 | */ |
630 | int |
||
631 | fsf_negotiate_contract |
||
632 | (const fsf_contract_parameters_t *contract, |
||
633 | fsf_server_id_t *server); |
||
634 | |||
635 | /** |
||
636 | This operation negotiates a contract for a new server, creates a |
||
637 | thread and binds it to the server. If the contract is accepted, the |
||
638 | operation creates a thread with the arguments thread, attr, |
||
639 | thread_code and arg as they are defined for the pthread_create() |
||
640 | POSIX function call, and attaches it to the fsf scheduler. Then, it |
||
641 | binds the created thread to the new server. It returns zero and |
||
642 | puts the server identification number in the location pointed to by |
||
928 | trimarchi | 643 | the server input parameter. |
881 | trimarchi | 644 | |
928 | trimarchi | 645 | The attr parameter is overwritten as necessary to introduce the |
646 | adequate scheduling attributes, according to the information given |
||
647 | in the contract. |
||
648 | |||
881 | trimarchi | 649 | The server is created with the FSF_NONE scheduling policy, which |
650 | means no hierarchical scheduling, and only one thread per server, |
||
651 | except for the case of background tasks (see below) |
||
652 | |||
928 | trimarchi | 653 | If the contract is rejected, the thread is not created and the |
654 | corresponding error is returned. |
||
655 | |||
656 | @param [in] contract pointer to the contract |
||
657 | @param [out] server server id |
||
658 | @param [out] thread thread id |
||
659 | @param [in] attr threads attributes |
||
660 | @param [in] thread_code pointer to the function that implements |
||
661 | the thread |
||
662 | @param [in] arg arguments for the thread |
||
663 | |||
664 | @retval FSF_ERR_BAD_ARGUMENT if the contract or server arguments are NULL |
||
665 | @retval FSF_ERR_CONTRACT_REJECTED if the contract is rejected |
||
881 | trimarchi | 666 | |
928 | trimarchi | 667 | @retval others it may also return all the errors that may be returned |
668 | by the pthread_create()POSIX function call |
||
881 | trimarchi | 669 | |
670 | */ |
||
671 | int |
||
672 | fsf_negotiate_contract_for_new_thread |
||
673 | (const fsf_contract_parameters_t *contract, |
||
674 | fsf_server_id_t *server, |
||
675 | pthread_t *thread, |
||
676 | pthread_attr_t *attr, |
||
677 | fsf_thread_code_t thread_code, |
||
678 | void *arg); |
||
679 | |||
680 | /** |
||
681 | This operation negotiates a contract for a new server, and binds |
||
682 | the calling thread to it. If the contract is accepted it returns |
||
683 | zero and copies the server identification number in the location |
||
684 | pointed to by the server input parameter. If it is rejected, an |
||
685 | error is returned. |
||
686 | |||
687 | The server is created with the FSF_NONE scheduling policy, which |
||
688 | means no hierarchical scheduling, and only one thread per server, |
||
689 | except for the case of background tasks (see below) |
||
690 | |||
691 | Implementation dependent issue: In order to allow the usage of |
||
692 | application defined schedulers, the calling thread must not have |
||
693 | the SCHED_APP scheduling policy and at the same time be attached to |
||
694 | an application scheduler different than the fsf scheduler; in such |
||
695 | case, an error is returned. After a successful call the calling |
||
696 | thread will have the SCHED_APP scheduling policy and will be |
||
697 | attached to the fsf scheduler. |
||
698 | |||
928 | trimarchi | 699 | @param [in] contract pointer to the contract |
700 | @param [out] server id |
||
701 | |||
702 | @retval 0 if the contract negotation is succesful |
||
703 | @retval FSF_ERR_UNKNOWN_APPSCHEDULED_THREAD if the thread is attached to |
||
881 | trimarchi | 704 | an application defined scheduler different than the fsf scheduler |
928 | trimarchi | 705 | @retval FSF_ERR_BAD_ARGUMENT if the contract or server arguments |
706 | are NULL |
||
707 | @retval FSF_ERR_CONTRACT_REJECTED if the contract is rejected. |
||
881 | trimarchi | 708 | */ |
709 | int |
||
710 | fsf_negotiate_contract_for_myself |
||
711 | (const fsf_contract_parameters_t *contract, |
||
712 | fsf_server_id_t *server); |
||
713 | |||
714 | |||
715 | /** |
||
928 | trimarchi | 716 | This operation associates a thread with a server, which means that |
717 | it starts consuming the server's budget and is executed according |
||
718 | to the contract established for that server. If the thread is |
||
719 | already bound to another server, and error is returned. |
||
881 | trimarchi | 720 | |
721 | It fails if the server's policy is different than FSF_NONE, or if |
||
722 | there is already a thread bound to this server |
||
723 | |||
724 | Implementation dependent issue: In order to allow the usage of |
||
725 | application defined schedulers, the given thread must not have the |
||
726 | scheduling policy SCHED_APP and at the same time be attached to an |
||
727 | application scheduler different than the fsf scheduler. |
||
728 | |||
928 | trimarchi | 729 | @param [in] server id |
730 | @param [in] thread id |
||
731 | |||
732 | @retval FSF_ERR_INTERNAL_ERROR erroneous binding or malfunction |
||
733 | of the FSF main scheduler |
||
734 | @retval FSF_ERR_UNKNOWN_APPSCHEDULED_THREAD if the thread is attached to |
||
881 | trimarchi | 735 | an application defined scheduler different than the fsf scheduler |
928 | trimarchi | 736 | @retval FSF_ERR_BAD_ARGUMENT if the server value does not complain with the |
881 | trimarchi | 737 | expected format or valid range or the given thread does not exist |
928 | trimarchi | 738 | @retval FSF_ERR_NOT_CONTRACTED_SERVER if the referenced server |
739 | is not valid |
||
740 | @retval FSF_ERR_ALREADY_BOUND if the thread is already bound to |
||
741 | another server. |
||
881 | trimarchi | 742 | |
743 | */ |
||
744 | int |
||
745 | fsf_bind_thread_to_server |
||
746 | (fsf_server_id_t server, |
||
747 | pthread_t thread); |
||
748 | |||
749 | |||
750 | /** |
||
751 | This operation unbinds a thread from a server. Since threads with |
||
752 | no server associated are not allow to execute, they remain in a |
||
753 | dormant state until they are either eliminated or bound again. |
||
754 | |||
755 | If the thread is inside a critical section the effects of this call |
||
756 | are deferred until the critical section is ended |
||
757 | |||
758 | Implementation dependent issue: in the implementation with an |
||
759 | application scheduler, the thread is still attached to the fsf |
||
760 | scheduler, but suspended. |
||
761 | |||
928 | trimarchi | 762 | @param [in] thread thread id |
763 | |||
764 | @retval 0 if the operation is succesful |
||
765 | @retval FSF_ERR_INTERNAL_ERROR erroneous binding or malfunction of the FSF |
||
881 | trimarchi | 766 | main scheduler |
928 | trimarchi | 767 | @retval FSF_ERR_BAD_ARGUMENT if the given thread does not exist |
768 | @retval FSF_ERR_NOT_SCHEDULED_THREAD if the given thread is not scheduled |
||
881 | trimarchi | 769 | under the FSF |
928 | trimarchi | 770 | @retval FSF_ERR_UNKNOWN_APPSCHEDULED_THREAD if the thread is attached to |
881 | trimarchi | 771 | an application defined scheduler different than the fsf scheduler |
928 | trimarchi | 772 | @retval FSF_ERR_NOT_BOUND if the given thread does not have a valid |
881 | trimarchi | 773 | server bound to it |
774 | */ |
||
775 | int |
||
776 | fsf_unbind_thread_from_server (pthread_t thread); |
||
777 | |||
778 | /** |
||
779 | This operation stores the Id of the server associated with the |
||
780 | specified thread in the variable pointed to by server. It returns |
||
781 | an error if the thread does not exist, it is not under the control |
||
782 | of the scheduling framework, or is not bound. |
||
783 | |||
928 | trimarchi | 784 | @param [in] thread thread id |
785 | @param [out] server server |
||
786 | |||
787 | @retval 0 if the operation is succesful |
||
929 | lipari | 788 | @return FSF_ERR_NOT_SCHEDULED_THREAD if the given thread is not scheduled |
881 | trimarchi | 789 | under the FSF |
929 | lipari | 790 | @return FSF_ERR_UNBOUND if the given thread does not have a valid |
881 | trimarchi | 791 | server bound to it |
929 | lipari | 792 | @return FSF_ERR_BAD_ARGUMENT if the given thread does not exist or the |
881 | trimarchi | 793 | server argument is NULL |
794 | */ |
||
795 | int |
||
796 | fsf_get_server |
||
797 | (pthread_t thread, |
||
798 | fsf_server_id_t *server); |
||
799 | |||
800 | /** |
||
801 | This operation stores the contract parameters currently associated |
||
802 | with the specified server in the variable pointed to by |
||
803 | contract. It returns an error if the server id is incorrect. |
||
804 | |||
928 | trimarchi | 805 | @param [in] server server id |
806 | @param [out] contract pointer to the contract structure |
||
807 | |||
808 | @retval 0 if the operation is succesful |
||
809 | @retval FSF_ERR_BAD_ARGUMENT if the contract argument is |
||
810 | NULL or the value of the server argument is not in range |
||
811 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is not |
||
881 | trimarchi | 812 | scheduled under the FSF |
928 | trimarchi | 813 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or |
814 | not running |
||
815 | @retval FSF_ERR_NOT_CONTRACTED_SERVER if the server of the calling thread |
||
881 | trimarchi | 816 | has been cancelled or it is not valid |
817 | */ |
||
818 | int |
||
819 | fsf_get_contract |
||
820 | (fsf_server_id_t server, |
||
821 | fsf_contract_parameters_t *contract); |
||
822 | |||
823 | /** |
||
824 | The operation eliminates the specified server |
||
825 | and recalculates all necessary parameters for the contracts |
||
826 | remaining in the system. This is a potentially blocking operation; |
||
827 | it returns when the system has made the changes effective. |
||
828 | |||
928 | trimarchi | 829 | @param [in] server server id |
881 | trimarchi | 830 | |
928 | trimarchi | 831 | @retval 0 if the operation is succesful |
832 | @retval FSF_ERR_BAD_ARGUMENT if the value of server is not in range |
||
833 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is not |
||
834 | scheduled under the FSF |
||
835 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or not |
||
836 | running |
||
837 | @retval FSF_ERR_NOT_CONTRACTED_SERVER if the server of the calling thread |
||
838 | has been cancelled or it is not valid |
||
881 | trimarchi | 839 | */ |
840 | int |
||
841 | fsf_cancel_contract (fsf_server_id_t server); |
||
842 | |||
843 | |||
844 | /** |
||
845 | The operation renegotiates a contract for an existing server. If |
||
846 | the on-line admission test is enabled it determines whether the |
||
847 | contract can be admitted or not based on the current contracts |
||
848 | established in the system. If it cannot be admitted, the old |
||
849 | contract remains in effect and an error is returned. If it can be |
||
850 | admitted, it recalculates all necessary parameters for the |
||
851 | contracts already present in the system anr returns zero. This is a |
||
852 | potentially blocking operation; it returns when the system has |
||
853 | either rejected the new contract, or admitted it and made it |
||
854 | effective. |
||
855 | |||
928 | trimarchi | 856 | @param [in] new_contract a pointer to the new contract |
857 | @param [in] server server id |
||
858 | |||
859 | @retval 0 if the operation is succesful |
||
860 | @retval FSF_ERR_BAD_ARGUMENT if the new_contract argument is NULL or the |
||
881 | trimarchi | 861 | value of the server argument is not in range |
928 | trimarchi | 862 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is not |
881 | trimarchi | 863 | scheduled under the FSF |
928 | trimarchi | 864 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or not |
865 | running |
||
866 | @retval FSF_ERR_NOT_CONTRACTED_SERVER if the server of the calling thread |
||
881 | trimarchi | 867 | has been cancelled or it is not valid |
868 | */ |
||
869 | int |
||
870 | fsf_renegotiate_contract |
||
871 | (const fsf_contract_parameters_t *new_contract, |
||
872 | fsf_server_id_t server); |
||
873 | |||
874 | /** |
||
875 | The operation enqueues a renegotiate operation for an existing |
||
876 | server, and returns immediately. The renegotiate operation is |
||
928 | trimarchi | 877 | performed asynchronously and the calling thread may continue |
878 | executing normally. Of course, wheter the operation is performed |
||
879 | immediately or not depends on the relative priority of the service |
||
880 | thread and the calling thread, on the scheduler used, etc. |
||
881 | trimarchi | 881 | |
928 | trimarchi | 882 | When the renegotiation is completed, if the on-line admission test |
883 | is enabled it determines whether the contract can be admitted or |
||
884 | not based on the current contracts established in the system. If it |
||
885 | cannot be admitted, the old contract remains in effect. If it can |
||
886 | be admitted, it recalculates all necessary parameters for the |
||
887 | contracts already present in the system. When the operation is |
||
888 | completed, notification is made to the caller, if requested, via a |
||
889 | signal. The status of the operation (in progress, admitted, |
||
890 | rejected) can be checked with the get_renegotiation_status |
||
891 | operation. The argument sig_notify can be NULL_SIGNAL (no |
||
892 | notification), or any POSIX signal; and in this case sig_value is |
||
893 | to be sent with the signal. |
||
894 | |||
895 | @param [in] new_contract pointer to the new contract to be negotiated |
||
896 | @param [in] server server id |
||
897 | @param [in] sig_notify NULL (no signal) or any POSIX signal |
||
929 | lipari | 898 | @param [in] sig_value a sigval structure that contains values to be |
928 | trimarchi | 899 | passed to the signal handler. Valid only if sig_notify |
900 | is different from NULL. |
||
901 | |||
902 | @retval 0 if the call is succesful |
||
903 | @retval FSF_ERR_BAD_ARGUMENT if the new_contract argument is NULL, the |
||
881 | trimarchi | 904 | value of the server argument is not in range or sig_notify is |
905 | neither NULL nor a valid POSIX signal |
||
928 | trimarchi | 906 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is not |
881 | trimarchi | 907 | scheduled under the FSF |
928 | trimarchi | 908 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or not |
909 | running |
||
910 | @retval FSF_ERR_NOT_CONTRACTED_SERVER if the server of the calling thread |
||
881 | trimarchi | 911 | has been cancelled or it is not valid |
912 | |||
913 | */ |
||
914 | int |
||
915 | fsf_request_contract_renegotiation |
||
916 | (const fsf_contract_parameters_t *new_contract, |
||
917 | fsf_server_id_t server, |
||
918 | int sig_notify, |
||
919 | union sigval sig_value); |
||
920 | |||
921 | /** |
||
922 | Possible values returned by fsf_get_renegotiation_status |
||
923 | */ |
||
924 | typedef enum {FSF_IN_PROGRESS, |
||
925 | FSF_REJECTED, |
||
926 | FSF_ADMITTED} |
||
927 | fsf_renegotiation_status_t; |
||
928 | |||
929 | /** |
||
930 | The operation reports on the status of the last renegotiation |
||
931 | operation enqueued for the specified server. It is callable even |
||
932 | after notification of the completion of such operation, if |
||
933 | requested. |
||
934 | |||
928 | trimarchi | 935 | @param [in] server server id |
936 | @param [out] renegotiation_status the status of the renegotiation; |
||
937 | |||
938 | @retval 0 if succesful completion; |
||
939 | @retval FSF_ERR_BAD_ARGUMENT if the renegotiation_status argument is |
||
881 | trimarchi | 940 | NULL or the value of the server argument is not in range |
928 | trimarchi | 941 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is not |
881 | trimarchi | 942 | scheduled under the FSF |
928 | trimarchi | 943 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or not |
944 | running |
||
945 | @retval FSF_ERR_NOT_CONTRACTED_SERVER if the server of the calling thread |
||
881 | trimarchi | 946 | has been cancelled or it is not valid |
947 | */ |
||
948 | int |
||
949 | fsf_get_renegotiation_status |
||
950 | (fsf_server_id_t server, |
||
951 | fsf_renegotiation_status_t *renegotiation_status); |
||
952 | |||
928 | trimarchi | 953 | |
954 | //Data types |
||
955 | |||
956 | /// List of contracts to negotiate |
||
957 | typedef struct { |
||
958 | int size; |
||
959 | fsf_contract_parameters_t* contracts[FSF_MAX_N_SERVERS]; |
||
960 | } fsf_contracts_group_t; |
||
961 | |||
962 | /// List of servers to cancel |
||
963 | typedef struct { |
||
964 | int size; |
||
965 | fsf_server_id_t servers[FSF_MAX_N_SERVERS]; |
||
966 | } fsf_servers_group_t; |
||
967 | |||
968 | |||
969 | /** |
||
970 | This operation analizes the schedulability of the context that |
||
971 | results from negitiating the contracts specified in the |
||
972 | contracts_up list and cacelling the contracts referenced by the |
||
973 | servers_down list. If the overall negotiation is successful, a new |
||
974 | server will be created for each of the elements of the contracts_up |
||
975 | group, the servers in servers_down will be cancelled, the list of |
||
976 | new server ids will be returned in the variable pointed to by |
||
977 | servers_up, and the variable pointed to by accepted will be made |
||
978 | true. Otherwise, this variable will be made false, and no other |
||
979 | effect will take place. The function returns the corresponding |
||
980 | error code if any of the contracts is not correct or any of the |
||
981 | server is is not valid. |
||
982 | |||
983 | @param [in] contracts_up list of contracts to negotiate |
||
929 | lipari | 984 | @param [in] servers_down list of contracts to be canceled |
928 | trimarchi | 985 | @param [out] servers_up list of server ids that have been created, they are |
986 | given in the same order as the contract_up list of contracts; |
||
987 | @param [out] accepted if the operation is succesful; |
||
988 | |||
989 | @retval 0 if succesful completion; |
||
990 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or |
||
991 | not running |
||
992 | @retval FSF_ERR_INTERNAL_ERROR erroneous binding or malfunction of the FSF |
||
993 | main scheduler |
||
994 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is |
||
995 | not scheduled under the FSF |
||
996 | @retval FSF_ERR_BAD_ARGUMENT if any of the servers_up or accepted arguments |
||
997 | is NULL, if the contracts_up and servers_down arguments are both NULL, |
||
998 | or any of them has erroneous size or its elements are NULL or not in the |
||
999 | valid range respectively |
||
1000 | */ |
||
1001 | int |
||
1002 | fsf_negotiate_group |
||
1003 | (const fsf_contracts_group_t *contracts_up, |
||
929 | lipari | 1004 | const fsf_servers_group_t *servers_down, |
1005 | fsf_servers_group_t *servers_up, |
||
928 | trimarchi | 1006 | bool *accepted); |
1007 | |||
1008 | |||
881 | trimarchi | 1009 | /*@}*/ |
1010 | |||
1011 | |||
1012 | //////////////////////////////////////////////////// |
||
1013 | // OBTAINING INFORMATION FROM THE SCHEDULER |
||
1014 | //////////////////////////////////////////////////// |
||
1015 | |||
1016 | |||
1017 | /** |
||
928 | trimarchi | 1018 | \ingroup coremodule |
1019 | |||
1020 | \defgroup core_sched_info Obtaining information from the scheduler. |
||
1021 | |||
1022 | This group of function is used to get informations from the |
||
1023 | scheduler, like execution time of a task, remaining budget of a |
||
1024 | server, etc. |
||
1025 | |||
1026 | @{ |
||
1027 | */ |
||
1028 | |||
1029 | /** |
||
1030 | Returns true if the system is configured with the on-line admission |
||
1031 | test enabled, or false otherwise. |
||
881 | trimarchi | 1032 | */ |
1033 | bool |
||
1034 | fsf_is_admission_test_enabled(); |
||
1035 | |||
1036 | /** |
||
1037 | This function stores the current execution time spent by the |
||
1038 | threads bound to the specified server in the variable pointed to by |
||
1039 | cpu_time. |
||
1040 | |||
928 | trimarchi | 1041 | @param [in] server server id |
1042 | @param [out] cpu_time pointer to a timespec structure that will contain |
||
1043 | the cpu time consumed by the threads that are bound to the |
||
1044 | specific server, since its creation. |
||
1045 | |||
1046 | @retval 0 if succesful completion |
||
1047 | @retval FSF_ERR_BAD_ARGUMENT if the value of the server argument is |
||
1048 | not in range or cpu_time is NULL |
||
1049 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is not |
||
881 | trimarchi | 1050 | scheduled under the FSF |
928 | trimarchi | 1051 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or |
1052 | not running |
||
1053 | @retval FSF_ERR_NOT_CONTRACTED_SERVER if the server of the calling thread |
||
881 | trimarchi | 1054 | has been cancelled or it is not valid |
1055 | */ |
||
1056 | int |
||
1057 | fsf_get_cpu_time |
||
1058 | (fsf_server_id_t server, |
||
1059 | struct timespec *cpu_time); |
||
1060 | |||
1061 | /** |
||
1062 | This function stores in the variable pointed to by budget the |
||
1063 | remaining execution-time budget associated with the specified |
||
928 | trimarchi | 1064 | server. |
881 | trimarchi | 1065 | |
928 | trimarchi | 1066 | @param [in] server server id |
1067 | @param [out] budget pointer to a timespec structure that will |
||
1068 | contain the remaining budget |
||
1069 | |||
1070 | @retval 0 if succesful completion |
||
1071 | @retval FSF_ERR_BAD_ARGUMENT if the value of the server argument is |
||
1072 | not in range or budget is NULL |
||
1073 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is not |
||
881 | trimarchi | 1074 | scheduled under the FSF |
928 | trimarchi | 1075 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or |
1076 | not running |
||
1077 | @retval FSF_ERR_NOT_CONTRACTED_SERVER if the server of the calling thread |
||
881 | trimarchi | 1078 | has been cancelled or it is not valid |
1079 | */ |
||
1080 | int |
||
1081 | fsf_get_remaining_budget |
||
1082 | (fsf_server_id_t server, |
||
1083 | struct timespec *budget); |
||
1084 | |||
1085 | |||
1086 | /** |
||
928 | trimarchi | 1087 | This function stores in the variables pointed to by budget and |
1088 | period, the execution-time budget and the period respectively |
||
1089 | associated with the specified server. If any of these pointers is |
||
1090 | NULL, the corresponding information is not stored. |
||
881 | trimarchi | 1091 | |
928 | trimarchi | 1092 | @param [in] server server id |
1093 | @param [out] budget budget available for the current server instance |
||
1094 | @param [out] period period available for the current server instance |
||
1095 | |||
1096 | @retval 0 if succesful completion |
||
1097 | @retval FSF_ERR_BAD_ARGUMENT if the value of the server argument is |
||
1098 | not in range, budget is NULL or period is NULL |
||
1099 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is not |
||
881 | trimarchi | 1100 | scheduled under the FSF |
928 | trimarchi | 1101 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or not |
1102 | running |
||
1103 | @retval FSF_ERR_NOT_CONTRACTED_SERVER if the server of the calling thread |
||
881 | trimarchi | 1104 | has been cancelled or it is not valid |
1105 | */ |
||
1106 | int |
||
1107 | fsf_get_budget_and_period |
||
1108 | (fsf_server_id_t server, |
||
1109 | struct timespec *budget, |
||
1110 | struct timespec *period); |
||
1111 | |||
928 | trimarchi | 1112 | /* @} */ |
881 | trimarchi | 1113 | |
1114 | ///////////////////////////////////////////////////////////////////// |
||
1115 | // SERVICE THREAD TUNING |
||
1116 | ///////////////////////////////////////////////////////////////////// |
||
1117 | |||
1118 | /** |
||
928 | trimarchi | 1119 | \ingroup coremodule |
1120 | |||
1121 | \defgroup core_service_thread Service Thread |
||
1122 | |||
1123 | These functions are to the initialization and tuning of the service |
||
1124 | thread. |
||
1125 | |||
1126 | Implementation dependency: in the fixed priority implementation of |
||
1127 | fsf, the default priority is lower than the priority of any server, |
||
1128 | but higher than the background. According to the |
||
1129 | implementation-dependent module the priority is adjustable by means |
||
1130 | of a function that changes its preemption level. |
||
1131 | |||
1132 | @{ |
||
1133 | */ |
||
1134 | |||
1135 | |||
1136 | /** |
||
1137 | This function allows the application to change the period and |
||
1138 | budget of the service thread that makes the |
||
881 | trimarchi | 1139 | negotiations. Increasing the utilization of this thread makes the |
1140 | negotiations faster, but introduces additional load in the system |
||
1141 | that may decrease the bandwidth available for the servers. For this |
||
928 | trimarchi | 1142 | call, the system will make a schedulability analysis to determine |
1143 | if the new situation is acceptable or not. This is reported back in |
||
1144 | the variable pointed to by accepted. If the new service thread data |
||
1145 | is accepted, the system will reassign budgets and periods to the |
||
1146 | servers according to the new bandwidth available, in the same way |
||
1147 | as it does for a regular contract negotiation. |
||
881 | trimarchi | 1148 | |
1149 | When its budget is exhausted, the service thread may run in the |
||
928 | trimarchi | 1150 | background. |
881 | trimarchi | 1151 | |
1152 | The service thread starts with a default budget and period that are |
||
928 | trimarchi | 1153 | configurable. |
881 | trimarchi | 1154 | |
928 | trimarchi | 1155 | @param [in] budget budget for the service thread |
1156 | @param [in] period for the service thread |
||
1157 | @param [out] accepted true is the change has been accepted |
||
881 | trimarchi | 1158 | |
928 | trimarchi | 1159 | |
1160 | @retval 0 is the operation is succesful |
||
1161 | @retval FSF_ERR_BAD_ARGUMENT if any of the pointer arguments is NULL or |
||
881 | trimarchi | 1162 | the budget value is greater than the period value |
928 | trimarchi | 1163 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is not |
881 | trimarchi | 1164 | scheduled under the FSF |
928 | trimarchi | 1165 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or |
1166 | not running |
||
1167 | @retval FSF_ERR_NOT_CONTRACTED_SERVER if the server of the calling thread |
||
881 | trimarchi | 1168 | has been cancelled or it is not valid |
1169 | */ |
||
1170 | int |
||
1171 | fsf_set_service_thread_data |
||
1172 | (const struct timespec *budget, |
||
1173 | const struct timespec *period, |
||
1174 | bool *accepted); |
||
1175 | |||
1176 | /** |
||
1177 | this function returns in the variables pointed by budget and |
||
1178 | period, respectively, the current budget and period of the service |
||
1179 | thread. |
||
928 | trimarchi | 1180 | |
1181 | @param [out] budget current budget of the service thread |
||
1182 | @param [out] period current period of the service thread |
||
881 | trimarchi | 1183 | |
928 | trimarchi | 1184 | @retval FSF_ERR_BAD_ARGUMENT if any of the pointer arguments is NULL |
1185 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is not |
||
881 | trimarchi | 1186 | scheduled under the FSF |
928 | trimarchi | 1187 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong |
1188 | or not running |
||
1189 | @retval FSF_ERR_NOT_CONTRACTED_SERVER if the server of the calling thread |
||
881 | trimarchi | 1190 | has been cancelled or it is not valid |
1191 | */ |
||
1192 | int |
||
1193 | fsf_get_service_thread_data |
||
1194 | (struct timespec *budget, |
||
1195 | struct timespec *period); |
||
1196 | |||
928 | trimarchi | 1197 | /* @} */ |
881 | trimarchi | 1198 | |
1199 | //////////////////////////////////////////////////////////////////////// |
||
1200 | // BACKGROUND MANAGEMENT |
||
1201 | //////////////////////////////////////////////////////////////////////// |
||
1202 | |||
1203 | /** |
||
1204 | |||
928 | trimarchi | 1205 | A round-robin background scheduling policy is available for those |
1206 | threads that do not have real-time requirements. Because some of |
||
1207 | these threads may require sharing information with other threads |
||
1208 | run by regular servers, special background contracts may be created |
||
1209 | for specifying the synchronization requirements. |
||
881 | trimarchi | 1210 | |
928 | trimarchi | 1211 | The way of specifying a background contract is by setting |
1212 | budget_min = period_max = 0. Negotiation may fail if the contract |
||
1213 | uses shared_objects. If the contract has no shared_objects the |
||
1214 | returned server id represents the background and may be used to |
||
1215 | bind more than one thread. If the contract has shared objects a |
||
1216 | server is created to keep track of them, but the associated threads |
||
1217 | are executed in the background, together with the other background |
||
1218 | threads |
||
881 | trimarchi | 1219 | |
928 | trimarchi | 1220 | @todo [PEPPE: this will be put in the general description of the core |
1221 | module] |
||
881 | trimarchi | 1222 | */ |
1223 | |||
1224 | |||
1225 | #endif // _FSF_CORE_H_ |