1 // -----------------------------------------------------------------------
2 // Copyright (C) 2006 - 2009 FRESCOR consortium partners:
4 // Universidad de Cantabria, SPAIN
5 // University of York, UK
6 // Scuola Superiore Sant'Anna, ITALY
7 // Kaiserslautern University, GERMANY
8 // Univ. Politécnica Valencia, SPAIN
9 // Czech Technical University in Prague, CZECH REPUBLIC
11 // Thales Communication S.A. FRANCE
12 // Visual Tools S.A. SPAIN
13 // Rapita Systems Ltd UK
16 // See http://www.frescor.org for a link to partners' websites
18 // FRESCOR project (FP6/2005/IST/5-034026) is funded
19 // in part by the European Union Sixth Framework Programme
20 // The European Union is not liable of any use that may be
24 // based on previous work (FSF) done in the FIRST project
26 // Copyright (C) 2005 Mälardalen University, SWEDEN
27 // Scuola Superiore S.Anna, ITALY
28 // Universidad de Cantabria, SPAIN
29 // University of York, UK
31 // FSF API web pages: http://marte.unican.es/fsf/docs
32 // http://shark.sssup.it/contrib/first/docs/
34 // This file is part of FRSH (FRescor ScHeduler)
36 // FRSH is free software; you can redistribute it and/or modify it
37 // under terms of the GNU General Public License as published by the
38 // Free Software Foundation; either version 2, or (at your option) any
39 // later version. FRSH is distributed in the hope that it will be
40 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
41 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
42 // General Public License for more details. You should have received a
43 // copy of the GNU General Public License along with FRSH; see file
44 // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
45 // Cambridge, MA 02139, USA.
47 // As a special exception, including FRSH header files in a file,
48 // instantiating FRSH generics or templates, or linking other files
49 // with FRSH objects to produce an executable application, does not
50 // by itself cause the resulting executable application to be covered
51 // by the GNU General Public License. This exception does not
52 // however invalidate any other reasons why the executable file might be
53 // covered by the GNU Public License.
54 // -----------------------------------------------------------------------
56 //==============================================
57 // ******** ******* ******** ** **
58 // **///// /**////** **////// /** /**
59 // ** /** /** /** /** /**
60 // ******* /******* /********* /**********
61 // **//// /**///** ////////** /**//////**
62 // ** /** //** /** /** /**
63 // ** /** //** ******** /** /**
64 // // // // //////// // //
66 // FRSH(FRescor ScHeduler), pronounced "fresh"
67 //==============================================
79 #include <sys/types.h>
81 #include "frsh_core_types.h"
82 #include "frsh_spare_capacity.h"
88 * @defgroup core Core module
90 * This module includes the basic functions and services that are
91 * provided by any FRSH implementation. This module includes basic type
92 * definitions, and functions to
94 * - create a contract and initialize it
95 * - set/get the basic parameters of a contract
96 * - negotiate a service contract, obtaining a vres id
97 * - create and bind threads to vres
98 * - create/destroy a synchronization object
99 * - manage bounded workloads
104 //////////////////////////////////////////////////////////////////////
105 // INITIALIZATION SERVICES
106 //////////////////////////////////////////////////////////////////////
109 * @defgroup initialization Initialization services
112 * These functions need to be called before doing any FRSH operation
113 * (including contract initialization).
122 * We cannot call any frsh functions before frsh_init. After calling
123 * frsh_init, the main will be executing in the background. Then, it
124 * can do the negotiations and create new threads if needed. The
125 * second time this function is called it fails.
127 * @return 0 if no error. \n
128 * FRSH_ERR_SYSTEM_ALREADY_INITIALIZED : if the function has already
129 * been called before\n
131 * It may also return any of the errors that may be returned by the
132 * underlying operating system primitives required to perform the
133 * FRSH system start up
141 /////////////////////////////////////////////////////////////
142 // CONTRACT PARAMETERS
143 /////////////////////////////////////////////////////////////
145 * @defgroup contract Contract Creation and Initialization.
148 * These functions are used to create and initialize a contract, and
149 * set its parameters.
156 * frsh_contract_init()
158 * The operation receives a pointer to a contract object
159 * and initializes it, setting it to the default values.
161 * The default values are:
164 * - ressource_type => FRSH_CRT_PROCESSOR
165 * - contract_label => ""
166 * - budget_min => {0,0};
167 * - period_max => {0,0};
168 * - budget_max => {0,0};
169 * - period_min => {0,0};
170 * - workload => FRSH_WT_INDETERMINATE
171 * - d_equals_t => true
172 * - contract_type => FRSH_CT_REGULAR;
173 * - deadline => {0,0};
174 * - budget_overrun_signal => 0; (signal number)
175 * - budget_overrun_siginfo => {0, NULL};
176 * - deadline_miss_signal => 0; (signal number)
177 * - deadline_miss_siginfo => {0, NULL};
179 * - granularity => DEFAULT_GRANULARITY;
180 * - utilization_set; => size = 0
181 * - quality => DEFAULT_QUALITY; (range 0..100)
182 * - importance => DEFAULT_IMPORTANCE; (range 1..5)
183 * - preemption_level => 0; (range 1..2**32-1)
184 * - critical_sections; => size = 0
186 * - sched_policy => DEFAULT_SCHED_POLICY (FRSH_NONE)
188 * @param contract the pointer to the contract variable.
190 * @return 0 if no error \n
191 * FRSH_ERR_BAD_ARGUMENT : contract is NULL
194 int frsh_contract_init(frsh_contract_t *contract);
198 * frsh_contract_set_basic_params()
200 * The operation updates the specified contract parameters object by
201 * setting its budget, period, workload and type to the specified
202 * input parameters. (Note: the workload is a basic parameter because
203 * bounded tasks are triggered by the scheduler (see the
204 * frsh_timed_wait() and frsh_synchobj_wait* operations), while
205 * indeterminate tasks are not; therefore, their programming model is
208 * @param contract the pointer to the contract object
209 * @param[in] budget_min the minimum budget for the contract
210 * @param[in] period_max the maximum period for the contract
211 * @param[in] workload the kind of workload (can be FRSH_WT_BOUNDED,
212 * FRSH_WT_INDETERMINATE or FRSH_OVERHEAD)
213 * @param[in] contract_type can be FRSH_CT_REGULAR,
214 * FRSH_CT_BACKGROUND, FRSH_CT_DUMMY.
216 * @return 0 if no error \n
217 * FRSH_ERR_BAD_ARGUMENT : if any of the pointers is NULL
218 * or if only one of the time values is 0, and also if the
219 * workload or the contract type values are unknown in the
222 int frsh_contract_set_basic_params
223 (frsh_contract_t *contract,
224 const frsh_rel_time_t *budget_min,
225 const frsh_rel_time_t *period_max,
226 const frsh_workload_t workload,
227 const frsh_contract_type_t contract_type);
230 * frsh_contract_get_basic_params()
232 * This operation obtains from the specified contract object its
233 * budget, period, and workload, and copies them to the places pointed
234 * to by the corresponding output parameters.
236 * @param[in] contract the pointer to the contract object
237 * @param[out] budget_min pointer to preallocated space
238 * @param[out] period_max pointer to preallocated space
239 * @param[out] workload pointer to preallocated space
240 * @param[out] contract_type pointer to preallocated space
242 * @return 0 if no error \n
243 * FRSH_ERR_BAD_ARGUMENT : if one of the contract or
247 int frsh_contract_get_basic_params
248 (const frsh_contract_t *contract,
249 frsh_rel_time_t *budget_min,
250 frsh_rel_time_t *period_max,
251 frsh_workload_t *workload,
252 frsh_contract_type_t *contract_type);
255 * frsh_contract_set_resource_and_label()
257 * Specify resource_id and type, and the contract label. Otherwise
258 * default values will apply. If the contract label is too long it is truncated
260 * @return 0 if no error \n
261 * FRSH_ERR_BAD_ARGUMENT : if the contract pointer is NULL.
263 int frsh_contract_set_resource_and_label
264 (frsh_contract_t *contract,
265 const frsh_resource_type_t resource_type,
266 const frsh_resource_id_t resource_id,
267 const char *contract_label);
271 * frsh_contract_get_resource_and_label()
273 * Obtain the resource_id and type, and the contract label.
275 * @return 0 if no error \n
276 * FRSH_ERR_BAD_ARGUMENT : if the contract or the contract_label
279 int frsh_contract_get_resource_and_label
280 (const frsh_contract_t *contract,
281 frsh_resource_type_t *resource_type,
282 frsh_resource_id_t *resource_id,
283 char *contract_label);
287 * frsh_contract_set_timing_reqs()
289 * The operation updates the specified contract object, specifying
290 * additional time-related requirements.
292 * @param contract The pointer to the contract object
294 * @param [in] d_equals_t It is a boolean value, set to true (1) if
295 * we want to specify a deadline different from
296 * the period for the contract.
297 * @param [in] deadline If the previous parameter is set to true,
298 * this parameter is ignored (the contract value
299 * will be NULL_DEADLINE internally). Otherwise, it
300 * contains the desired deadline value.
301 * @param [in] budget_overrun_signal contains the number of the signal
302 * that must be raised if the budget of the vres is overrun.
303 * If the value of this parameter is FRSH_NULL_SIGNAL, no signal will
305 * @param [in] budget_overrun_siginfo contains the value that will be
306 * passed to the signal "catcher" when the signal is raised.
307 * This parameters is not used if the budget_overrun_signal
308 * parameter is set to FRSH_NULL_SIGNAL.
309 * @param [in] deadline_miss_signal contains the number of the
310 * signal that must be raised if the deadline of the
311 * vres is missed. If the value of this parameter is
312 * FRSH_NULL_SIGNAL, no signal is raised.
313 * @param [in] deadline_miss_siginfo contains the value that will be
314 * passed to the signal "catcher" when the signal is
315 * raised. This parameter is not used if the
316 * deadline_signal parameter is set to NULL_SIGNAL
318 * @return 0 if successful\n
319 * FRSH_ERR_BAD_ARGUMENT : if contract is NULL \b or \n
320 * (d_equals_t is true and deadline is not FRSH_NULL_DEADLINE) \b or \n
321 * (budget_overrun_signal is not a valid signal) \b or \n
322 * (deadline_miss_signal is not a valid signal) \b or \n
323 * (d_equals_t is false but (deadline is FRSH_NULL_DEADLINE or its value
324 * is grater than the contract's maximum period))
327 int frsh_contract_set_timing_reqs
328 (frsh_contract_t *contract,
329 const bool d_equals_t,
330 const frsh_rel_time_t *deadline,
331 const frsh_signal_t budget_overrun_signal,
332 const frsh_signal_info_t budget_overrun_siginfo,
333 const frsh_signal_t deadline_miss_signal,
334 const frsh_signal_info_t deadline_miss_siginfo);
337 * frsh_contract_get_timing_reqs()
339 * The operation obtains the corresponding input parameters from the
340 * specified contract object. If d_equals_t is true, the deadline will
341 * be set to FRSH_NULL_DEADLINE.
343 * @return 0 if no error \n
344 * FRSH_ERR_BAD_ARGUMENT : if contract is NULL
347 int frsh_contract_get_timing_reqs
348 (const frsh_contract_t *contract,
350 frsh_rel_time_t *deadline,
351 frsh_signal_t *budget_overrun_signal,
352 frsh_signal_info_t *budget_overrun_siginfo,
353 frsh_signal_t *deadline_miss_signal,
354 frsh_signal_info_t *deadline_miss_siginfo);
359 //////////////////////////////////////////////////////////////////
360 // SYNCHRONIZATION OBJECTS
361 //////////////////////////////////////////////////////////////////
363 * @defgroup synch Synchronization objects
366 * Synchronisation objects provide an alternative to timers for
367 * bounded-workload vres to signal the end of their current job and
368 * return their remaining budget to FRSH.
370 * Instead of asking to be reactivated based on an absolute time, they
371 * queue themselves in a synchronisation object and will wait there
372 * until another vres (bounded-workload or indeterminate-workload)
373 * wakes them up with a signal call the earliest at the beginning of
376 * Indeterminate-workload vres cannot queue themselves here because
377 * they don't have any budget to return. However they can signal on
378 * the objects to activate a waiting workload vres.
380 * For classical signal/wait synchronisation paradigms the application
381 * must use whatever mechanism the underlying OS provides.
383 * In the future we may add a broadcast operation that would signal a
384 * group of synchronization objects. We have not included a broadcast
385 * service in this version because it can be easily created by the
386 * user by signalling individual synchronization objects inside a
389 * Notice that for synchronization objects there is no naming service
390 * like in shared objects because tasks that use synchronization are
391 * not developed independently, as they are closely coupled.
398 * frsh_synchobj_create()
400 * This operation creates and initializes a synchronization object
401 * variable managed by the scheduler, and returns a handle to it in
402 * the variable pointed to by synch_handle.
404 * @param[out] synch_handle pointer to the variable that will contain
405 * the handle to the newly created synchronization object
407 * @return 0 if the operation is succesful
408 * FRSH_ERR_TOO_MANY_SYNCH_OBJS if the number of synchronization
409 * objects in the system has already exceeded the maximum
411 * FRSH_ERR_TOO_MANY_SYNCH_OBJS : if the number of synchronization
412 * objects in the system has already exceeded the maximum\n
414 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
415 * scheduled under FRSH\n
417 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not running
420 int frsh_synchobj_create
421 (frsh_synchobj_handle_t *synch_handle);
425 * frsh_synchobj_destroy()
427 * This operation destroys the synchronization object (created by a
428 * previous call to frsh_synchobj_create) that is referenced by the
429 * synch_handle variable. After calling this operation, the
430 * synch_handle variable can not be used until it is initialized again
431 * by a call to frsh_synchobj_create.
433 * @param synch_handle the handle to the synchronization object
436 * @return 0 if no error \n
437 * FRSH_ERR_BAD_ARGUMENT : if synch_handle is 0\n
438 * FRSH_ERR_INVALID_SYNCH_OBJ_HANDLE if the handle is not valid\n
439 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
440 * scheduled under FRSH \n
441 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
444 * @sa frsh_synchobj_create
446 int frsh_synchobj_destroy
447 (const frsh_synchobj_handle_t synchobj_handle);
450 * frsh_synchobj_wait()
452 * This operation is invoked by threads associated with bounded
453 * workload vres to indicate that a job has been completed (and
454 * that the scheduler may reassign the unused capacity of the current
455 * job to other vres).
457 * As a difference with frsh_timed_wait(), here the vres
458 * specifies to be awakened by the arrival of a signal operation
459 * instead of at a precise point of time.
461 * This function can also be called to schedule the first job of a
462 * recently created vres and make it start when a signal operation
463 * has been sent from another thread.
465 * The vres' budget will be made zero for the remainder of the vres'
466 * period, and FRSH will not replenish it until an event has been
467 * notified to the synchronisation object by another vres.
469 * It can happen that the synchronisation object has notification
470 * events queued from the past, in this case one of the events is
471 * dequeued immediately and the vres won't have to wait for another
474 * At the time of reception of a notification event (wether in the
475 * future or in the past), all pending budget replenishments (if any)
476 * are made effective. Once the vres has a positive budget and the
477 * scheduler schedules the calling thread again, the call returns and
478 * the vres continues executing.
480 * If the synchronisation object is destroyed while the vres was
481 * waiting on it, the vres will be awaken and the function will
482 * return with a code FRSH_ERR_INVALID_SYNCH_OBJ_HANDLE
484 * Except for those parameters equal to NULL pointers, the system
485 * reports the current period and budget for the current job, it informs
486 * if the deadline of the previous job was missed or not, and whether the
487 * budget of the previous job was overrun or not.
489 * In a system with hierarchical scheduling, since this call makes the
490 * budget of the current period zero, the other threads in the same
491 * vres are not run. As mentioned above, only when the call finishes
492 * the budget may be replenished.
494 * @param synch_handle Synchronisation object upon which the vres
496 * @param next_budget[out] Upon return of this function, the variable
497 * pointed by this function will be equal to
498 * the current vres budget. If this parameter is
499 * set to NULL, no action is taken
500 * @param next_period[out] The vres period upon return (ignored if NULL).
501 * @param was_deadline_missed Upon return whether the deadline was
502 * missed in the previous period.
503 * @param was_budget_overran
506 * @return 0 if success \n
507 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
509 * FRSH_ERR_INTERNAL_ERROR : erroneous binding or malfunction of the FRSH
511 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not scheduled
513 * FRSH_ERR_NOT_BOUND : if the calling thread does not have a valid
514 * vres bound to it \n
515 * FRSH_ERR_BAD_ARGUMENT : if synch_handle is 0 \n
516 * FRSH_ERR_INVALID_SYNCH_OBJ_HANDLE if the synch_handle is not
517 * valid or was destroyed while the vres was waiting on it. \n
518 * FRSH_ERR_VRES_WORKLOAD_NOT_COMPATIBLE: if the kind of workload of the vres
519 * is not FRSH_BOUNDED
522 int frsh_synchobj_wait
523 (const frsh_synchobj_handle_t synch_handle,
524 frsh_rel_time_t *next_budget,
525 frsh_rel_time_t *next_period,
526 bool *was_deadline_missed,
527 bool *was_budget_overran);
531 * frsh_synchobj_wait_with_timeout()
533 * This call is the same as frsh_synchobj_wait() but with an extra
534 * absolute timeout. The timed_out argument, indicates whether the
535 * function returned because of the expiration of the timeout or not.
537 * @return 0 if no error \n
538 * FRSH_ERR_INVALID_SYNCH_OBJ_HANDLE if the synch_handle is not
540 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
542 * FRSH_ERR_INTERNAL_ERROR : erroneous binding or malfunction of the FRSH
544 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not scheduled
546 * FRSH_ERR_NOT_BOUND : if the calling thread does not have a valid
547 * vres bound to it \n
548 * FRSH_ERR_BAD_ARGUMENT : if the synch_handle given is not valid or the
549 * abs_timeout argument is NULL or its value is in the past\n
550 * FRSH_ERR_VRES_WORKLOAD_NOT_COMPATIBLE: if the kind of workload of the vres
551 * is not FRSH_BOUNDED
554 int frsh_synchobj_wait_with_timeout
555 (const frsh_synchobj_handle_t synch_handle,
556 const frsh_abs_time_t *abs_timeout,
558 frsh_rel_time_t *next_budget,
559 frsh_rel_time_t *next_period,
560 bool *was_deadline_missed,
561 bool *was_budget_overran);
564 * frsh_synchobj_signal()
566 * This function sends a notification event to the synchronization object
567 * specified as parameter. If there is at least one vres waiting on
568 * the synchronization object, it is awaken. If more than one vres
569 * are waiting, just one of them is awaken. However, which one is
570 * awaken is implementation dependent. If no vres is waiting on the
571 * synchronization object, the notification event is queued.
573 * @param [in] synch_handle the handle of the synchronization object to
576 * @return 0 if no error \n
577 * FRSH_ERR_BAD_ARGUMENT : if synch_handle is 0 \n
578 * FRSH_ERR_INVALID_SYNCH_OBJ_HANDLE if the handle is not valid \n
579 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
580 * scheduled under FRSH \n
581 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
583 * FRSH_ERR_TOO_MANY_EVENTS_IN_SYNCH_OBJ : if the number of events stored
584 * in the synchronization object reaches the maximum defined in the
585 * configuration parameter header file
587 * @sa frsh_synchobj_wait, frsh_synchobj_wait_with_timeout
589 int frsh_synchobj_signal
590 (const frsh_synchobj_handle_t synch_handle);
595 * This operation is invoked by threads associated with bounded
596 * workload vres to indicate that a job has been completed (and
597 * that the scheduler may reassign the unused capacity of the current
598 * job to other vres). It is also invoked when the first job of
599 * such threads has to be scheduled.
601 * As an effect, the system will make the current vres's budget zero
602 * for the remainder of the vres's period, and will not replenish
603 * the budget until the specified absolute time. At that time, all
604 * pending budget replenishments (if any) are made effective. Once the
605 * vres has a positive budget and the scheduler schedules the
606 * calling thread again, the call returns and at that time, except for
607 * those parameters equal to NULL pointers, the system reports the
608 * current period and budget for the current job, whether the deadline
609 * of the previous job was missed or not, and whether the budget of
610 * the previous job was overrun or not.
612 * In a system with hierarchical scheduling, since this call makes the
613 * budget zero, the other threads in the same vres are not run. As
614 * mentioned abobe, only when the call finishes the budget may be
617 * @param [in] abs_time absolute time at which the budget will be
620 * @param [out] next_budget upon return of this function, the variable
621 * pointed by this function will be equal to
622 * the current vres budget. If this parameter is
623 * set to NULL, no action is taken.
625 * @param [out] next_period upon return of this function, the variable
626 * pointed by this function will be equal to
627 * the current vres period. If this parameter is
628 * set to NULL, no action is taken.
630 * @param [out] was_deadline_missed upon return of this function, the
631 * variable pointed by this function will be
632 * equal to true if the previous vres deadline
633 * was missed, to false otherwise. If this
634 * parameter is set to NULL, no action is
637 * @param [out] was_budget_overrun upon return of this function, the
638 * variable pointed by this function will be
639 * equal to true if the previous vres budget was
640 * overrun, to false otherwise. If this
641 * parameter is set to NULL, no action is
644 * @return 0 if the operation is successful \n
645 * FRSH_ERR_TIME_SPEC_IN_THE_PAST if the absolute time specification
647 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong
649 * FRSH_ERR_INTERNAL_ERROR : erroneous binding or malfunction of the FRSH
651 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling
652 * thread is not scheduled under FRSH \n
653 * FRSH_ERR_NOT_BOUND : if the calling thread does not have a valid
654 * vres bound to it \n
655 * FRSH_ERR_BAD_ARGUMENT : if abs_time is NULL \n
656 * FRSH_ERR_VRES_WORKLOAD_NOT_COMPATIBLE: if the kind of workload of the vres
657 * is not FRSH_BOUNDED
660 * @sa frsh_synchobj_wait, frsh_synchobj_wait_with_timeout
663 (const frsh_abs_time_t *abs_time,
664 frsh_rel_time_t *next_budget,
665 frsh_rel_time_t *next_period,
666 bool *was_deadline_missed,
667 bool *was_budget_overran);
672 * frsh_vresperiod_wait()
674 * Suspend the calling thread until the start of the specified virtual
675 * resource period of a vres_id, for a synchronized workload.
677 * Virtual resource periods are numbered. The number of the current
678 * period can be obtained through the frsh_vres_get_period_number()
681 int frsh_vresperiod_wait(unsigned long period_num,
682 frsh_rel_time_t *next_budget,
683 frsh_rel_time_t *next_period,
684 bool *was_deadline_missed,
685 bool *was_budget_overran);
689 * frsh_vres_get_period()
691 * Return the current period number, for a virtual resource of
692 * synchronized workload.
694 int frsh_vres_get_period_number
695 (const frsh_vres_id_t vres,
703 ///////////////////////////////////////////////////////////////////
704 // CONTRACT NEGOCIATION OPERATIONS
705 ///////////////////////////////////////////////////////////////////
708 * @defgroup negotiate Negotiate contract functions
711 * The following functions are used to negotiate contracts and thus
712 * creating vres which are the execution image of a contract.
713 * Besides, these functions allow to assign and unassign threads to
716 * In the case of more than one thread per vres please refer to the
717 * hierarchical module.
725 * frsh_contract_negotiate()
727 * The operation negotiates a contract and if accepted it will return
728 * a vres_id. It will also check that the given contract_label is unique
731 * If the on-line admission test is enabled, it determines whether the
732 * contract can be admitted or not based on the current contracts
733 * established in the system. Then it creates the vres and
734 * recalculates all necessary parameters for the contracts already
735 * present in the system.
737 * This is a potentially blocking operation, it returns when the
738 * system has either rejected the contract, or admitted it and made it
739 * effective. No thread is bound to the newly created vres, which
740 * will be idle until a thread is bound to it via frsh_thread_bind()
741 * or frsh_thread_create_and_bind().
743 * This operation can only be executed by threads that are already
744 * bound to an active vres and therefore are being scheduled by the
747 * @return 0 if successful \n
748 * FRSH_ERR_CONTRACT_REJECTED: The contract is not accepted.\n
749 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
751 * FRSH_ERR_INTERNAL_ERROR : erroneous binding or malfunction of the FRSH
753 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not scheduled
754 * under FRSH scheduler \n
755 * FRSH_ERR_BAD_ARGUMENT : if the contract or vres arguments are NULL \n
756 * FRSH_ERR_TOO_MANY_VRES : if there is no space for more vres
757 * (the maximum number of them is already reached) \n
758 * FRSH_ERR_CONTRACT_LABEL_ALREADY_EXISTS : contract_label is not unique.
761 int frsh_contract_negotiate
762 (const frsh_contract_t *contract,
763 frsh_vres_id_t *vres);
766 * frsh_thread_create_and_bind()
768 * This operation creates a thread and binds it to an existing vres.
770 * This is the preferred way to add threads to the application because
771 * we make sure that the thread won't become unbound.
773 * The vres must not have any thread binded to it. If you want to
774 * bind more than one thread to the vres you must use the
775 * hierarchical module.
777 * The frsh_thread_attr_t parameter is overwritten as necessary to
778 * introduce the adequate scheduling policy and priority, according
779 * to the preemption level given in the contract and the
780 * frsh_priority_map() function defined by the user.
782 * @param[in] vres_id vres with which the thread will be bound.
783 * @param[out] thread frsh_thread_id returned by the system.
784 * @param attr pthread_attr taken and maybe corrected
785 * by the system. Ignored if NULL
786 * @param[in] thread_code Thread function (void func(void *) )
787 * that will constitute the main of the
789 * @param[in] arg Argument for data to be passed at the
790 * thread. Set to NUL if you don't want
791 * to do anything like this.
793 * @return 0 if successful \n
794 * FRSH_ERR_BAD_ARGUMENT : if the contract or vres arguments are
796 * FRSH_ERR_CONTRACT_REJECTED : if the contract is rejected. \n
798 * It may also return all the errors that may be returned by the
799 * fosa_thread_create() function call
802 int frsh_thread_create_and_bind
803 (const frsh_vres_id_t vres,
804 frsh_thread_id_t *thread,
805 frsh_thread_attr_t *attr,
806 frsh_thread_code_t thread_code,
811 * frsh_thread_create_in_background()
813 * This function creates a "background contract" that does not need to
814 * be negotiated, creates a threads and binds to the new vres.
816 * This method is suggested as a way to initate components and
817 * plugins. The event that triggers the component activation should
818 * arrive to an application thread that could use this function to
819 * create a thread used in its initialisation.
821 * The attribute parameter is overwritten as necessary to introduce
822 * the adequate scheduling policy and priority.
824 * @param[in] thread_code Function to be executed by the new
826 * @param[in] thread_arg General pointer that will be passed to
827 * the new thread as initialisation data.
828 * @param attr Pthread attribute with thread params
829 * @param[in] contract_label Contract label for the new vres.
830 * @param[out] thread_id Id of the new thread.
831 * @param[out] vres_id vres_id of the new vres.
833 * @return 0 if successful \n
834 * FRSH_ERR_BAD_ARGUMENT : Any problems with the argument \n
835 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is
836 * not scheduled under FRSH \n
837 * FRSH_ERR_CONTRACT_LABEL_ALREADY_EXISTS : contract_label is not unique \n
838 * FRSH_ERR_TOO_MANY_VRES : if there is no space for more vres
839 * (the maximum number of them is already reached)
842 int frsh_thread_create_in_background
843 (frsh_thread_code_t thread_code,
844 const void *thread_arg,
845 const char *contract_label,
846 frsh_thread_attr_t *attr,
847 frsh_thread_id_t *thread_id,
848 frsh_vres_id_t *vres_id);
853 * frsh_thread_join_in_background()
855 * This function is aimed for external threads to join FRSH in the
856 * least disturbing possible mode.
858 * Upon calling this function by a thread which has been created
859 * natively in the OS, it joins the framework and gets inmediately
860 * bound to an on-the-fly generated background contract.
862 * In order to gain a higher priority then it can renegotiate a
863 * contract for its vres with the needed parameters.
865 * @param[in] resource_id: Resource (CPU) in which the vres will
868 * @param[in] resource_type: Resource type (should be CPU) for the
871 * @param[in] label: Label to be added to the contract.
873 * @param[out] vres_id: Resulting vres_id from the on-the-fly
874 * generated background contract.
876 * @return 0 if successful\n
877 * FRSH_ERR_NOT_CONTRACTED_VRES if the thread is already
880 int frsh_thread_join_in_background(frsh_resource_id_t resource_id,
881 frsh_resource_type_t resource_type,
883 frsh_vres_id_t *vres_id);
890 * This operation associates a thread with a vres, which means that
891 * it starts consuming the vres's budget and is executed according
892 * to the contract established for that vres. If the thread is
893 * already bound to another vres, it is effectively unbound from it
894 * and bound to the specified one.
896 * It fails if the vres's policy is different than FRSH_NONE, or if
897 * there is already a thread bound to this vres. In order to bind
898 * more than one vres to the same thread you must use the
899 * hierarchical module.
901 * Implementation dependent issue: In order to allow the usage of
902 * application defined schedulers, the given thread must not have the
903 * scheduling policy SCHED_APP and at the same time be attached to an
904 * application scheduler different than the frsh scheduler.
906 * @return 0 if successful \n
907 * FRSH_ERR_INTERNAL_ERROR : erroneous binding or malfunction of the FRSH
909 * FRSH_ERR_UNKNOWN_APPSCHEDULED_THREAD : if the thread is attached to
910 * an application defined scheduler different than the frsh
912 * FRSH_ERR_BAD_ARGUMENT : if the vres value does not complain with the
913 * expected format or valid range or the given thread does not
915 * FRSH_ERR_NOT_CONTRACTED_VRES : if the referenced vres is not
917 * FRSH_ERR_VRES_WORKLOAD_NOT_COMPATIBLE: if the kind of workload
918 * of the vres is FRSH_OVERHEAD \n
919 * FRSH_ERR_ALREADY_BOUND : if the given vres has a thread already
924 (const frsh_vres_id_t vres,
925 const frsh_thread_id_t thread);
929 * frsh_thread_unbind()
931 * This operation unbinds a thread from a vres. Since threads with
932 * no vres associated are not allowed to execute, they remain in a
933 * dormant state until they are either eliminated or bound again.
935 * If the thread is inside a critical section the effects of this call
936 * are deferred until the critical section is ended
938 * Implementation dependent issue: in the implementation with an
939 * application scheduler, the thread is still attached to the frsh
940 * scheduler, but suspended.
942 * @return 0 if successful \n
943 * FRSH_ERR_INTERNAL_ERROR : erroneous binding or malfunction of the FRSH
945 * FRSH_ERR_BAD_ARGUMENT : if the given thread does not exist \n
946 * FRSH_ERR_NOT_SCHEDULED_THREAD : if the given thread is not scheduled
948 * FRSH_ERR_UNKNOWN_APPSCHEDULED_THREAD : if the thread is attached to
949 * an application defined scheduler different than the frsh
951 * FRSH_ERR_NOT_BOUND : if the given thread does not have a valid
954 int frsh_thread_unbind(const frsh_thread_id_t thread);
957 * frsh_thread_get_vres_id()
959 * This operation stores the Id of the vres associated with the
960 * specified thread in the variable pointed to by vres. It returns
961 * an error if the thread does not exist, it is not under the control
962 * of the scheduling framework, or is not bound.
964 * @return 0 if no error \n
965 * FRSH_ERR_NOT_SCHEDULED_THREAD : if the given thread is not scheduled
967 * FRSH_ERR_NOT_BOUND : if the given thread does not have a valid
968 * vres bound to it \n
969 * FRSH_ERR_BAD_ARGUMENT : if the given thread does not exist or the
970 * vres argument is NULL
973 int frsh_thread_get_vres_id(const frsh_thread_id_t thread,
974 frsh_vres_id_t *vres_id);
977 * frsh_vres_get_priority()
979 * This operation stores the priority currently associated
980 * with the specified vres in the variable pointed to by
981 * priority. It returns an error if the vres_id is not recognised.
983 * @return 0 if no error \n
984 * FRSH_ERR_BAD_ARGUMENT : if the contract argument is NULL or the value
985 * of the vres argument is not in range \n
986 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
987 * scheduled under FRSH \n
988 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
990 * FRSH_ERR_NOT_CONTRACTED_VRES: if the vres of the calling thread
991 * has been cancelled or it is not valid
994 int frsh_vres_get_priority
995 (frsh_vres_id_t vres_id,
999 * frsh_vres_get_contract()
1001 * This operation stores the contract parameters currently associated
1002 * with the specified vres in the variable pointed to by
1003 * contract. It returns an error if the vres_id is not recognised.
1005 * @return 0 if no error \n
1006 * FRSH_ERR_BAD_ARGUMENT : if the contract argument is NULL or the value
1007 * of the vres argument is not in range \n
1008 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
1009 * scheduled under FRSH \n
1010 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
1012 * FRSH_ERR_NOT_CONTRACTED_VRES: if the vres of the calling thread
1013 * has been cancelled or it is not valid
1016 int frsh_vres_get_contract
1017 (const frsh_vres_id_t vres,
1018 frsh_contract_t *contract);
1021 * frsh_resource_get_vres_from_label()
1023 * This operation retrieves the vres_id whose contract_label
1024 * corresponds to the parameter in the resource_id and resource_type
1027 * The contract label must refer to a contract negotiated
1028 * in the same processing node in which the call is being
1029 * made. Otherwise an error is returned.
1031 * @return 0 if no error \n
1032 * FRSH_ERR_BAD_ARGUMENT : if the contract argument is NULL or the
1033 * contract_label is NULL \n
1034 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
1035 * scheduled under FRSH \n
1036 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
1038 * FRSH_ERR_CONTRACT_LABEL_UNKNOWN: if the contract_label is not known
1040 int frsh_resource_get_vres_from_label
1041 (const char *contract_label,
1042 const frsh_resource_type_t resource_type,
1043 const frsh_resource_id_t resource_id,
1044 frsh_vres_id_t *vres);
1049 * frsh_contract_cancel()
1051 * The operation eliminates the specified vres
1052 * and recalculates all necessary parameters for the contracts
1053 * remaining in the system. This is a potentially blocking operation;
1054 * it returns when the system has made the changes effective.
1056 * Note that the thread is not eliminated. We leave the application
1057 * the option to either freeze it for a later use or bind it to
1060 * @return 0 if successful \n
1061 * FRSH_ERR_BAD_ARGUMENT : if the value of vres is not in range \n
1062 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
1063 * scheduled under FRSH \n
1064 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
1066 * FRSH_ERR_NOT_CONTRACTED_VRES : if the vres of the calling thread
1067 * has been cancelled or it is not valid
1070 int frsh_contract_cancel (const frsh_vres_id_t vres);
1074 * frsh_contract_renegotiate_sync()
1076 * The operation renegotiates a contract for an existing vres. If
1077 * the on-line admission test is enabled it determines whether the
1078 * contract can be admitted or not based on the current contracts
1079 * established in the system. If it cannot be admitted, the old
1080 * contract remains in effect and an error is returned. If it can be
1081 * admitted, it recalculates all necessary parameters for the
1082 * contracts already present in the system and returns zero. This is a
1083 * potentially blocking operation; it returns when the system has
1084 * either rejected the new contract, or admitted it and made it
1087 * @return 0 if successful \n
1088 * FRSH_ERR_BAD_ARGUMENT : if the new_contract argument is NULL or the
1089 * value of the vres argument is not in range \n
1090 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
1091 * scheduled under FRSH \n
1092 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
1094 * FRSH_ERR_NOT_CONTRACTED_VRES : if the vres of the calling thread
1095 * has been cancelled or it is not valid \n
1096 * FRSH_ERR_CONTRACT_REJECTED : if the renegotiation fails
1099 int frsh_contract_renegotiate_sync
1100 (const frsh_contract_t *new_contract,
1101 const frsh_vres_id_t vres);
1105 * frsh_contract_renegotiate_async()
1107 * The operation enqueues a renegotiate operation for an existing
1108 * vres, and returns immediately. The renegotiate operation is
1109 * performed asynchronously, as soon as it is practical; meanwhile the
1110 * system operation will continue normally. When the renegotiation is
1111 * made, if the on-line admission test is enabled it determines
1112 * whether the contract can be admitted or not based on the current
1113 * contracts established in the system. If it cannot be admitted, the
1114 * old contract remains in effect. If it can be admitted, it
1115 * recalculates all necessary parameters for the contracts already
1116 * present in the system.
1118 * When the operation is completed, notification is made to the
1119 * caller, if requested, via a signal. The status of the operation (in
1120 * progress, admitted, rejected) can be checked with the
1121 * frsh_vres_get_renegotiation_status() operation. The argument
1122 * sig_notify can be FRSH_NULL_SIGNAL (no notification), or any FRSH
1123 * signal value and in this case signal_info is to be sent with the signal.
1125 * @param[in] new_contract New contract parameters for the new
1126 * situation if approved.
1127 * @param[in] vres vres_id on which to do the renegotiation.
1128 * @param[in] signal_to_notify Signal number to use to notify vres of
1129 * the negotiation result. If
1130 * FRSH_NULL_SIGNAL, no signal will be raised.
1131 * @param[in] signal_info: Associated info that will come with the
1132 * signal. This parameter will be ignored
1133 * if signal_to_notify == FRSH_NULL_SIGNAL.
1135 * @return 0 if no error \n
1136 * FRSH_ERR_BAD_ARGUMENT : if the new_contract argument is NULL, the
1137 * value of the vres argument is not in range or sig_notify is
1138 * neither NULL nor a valid POSIX signal \n
1139 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
1140 * scheduled under FRSH \n
1141 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
1143 * FRSH_ERR_NOT_CONTRACTED_VRES : if the vres of the calling thread
1144 * has been cancelled or it is not valid
1147 int frsh_contract_renegotiate_async
1148 (const frsh_contract_t *new_contract,
1149 const frsh_vres_id_t vres,
1150 const frsh_signal_t signal_to_notify,
1151 const frsh_signal_info_t signal_info);
1155 * frsh_vres_get_renegotiation_status()
1157 * The operation reports on the status of the last renegotiation
1158 * operation enqueued for the specified vres. It is callable even
1159 * after notification of the completion of such operation, if
1162 * If the vres is not and has not been involved in any of the
1163 * frsh_contract_renegotiate_async() or frsh_group_change_mode_async()
1164 * operations, the status returned is FRSH_RS_NOT_REQUESTED
1166 * @return 0 if no error \n
1167 * FRSH_ERR_BAD_ARGUMENT : if the renegotiation_status argument is
1168 * NULL or the value of the vres argument is not in range \n
1169 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
1170 * scheduled under FRSH \n
1171 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
1173 * FRSH_ERR_NOT_CONTRACTED_VRES : if the vres of the calling thread
1174 * has been cancelled or it is not valid
1177 int frsh_vres_get_renegotiation_status
1178 (const frsh_vres_id_t vres,
1179 frsh_renegotiation_status_t *renegotiation_status);
1183 ////////////////////////////////////////////////////////////////////////
1184 // CHANGE OF MODE: GROUPS OF CONTRACTS
1185 ////////////////////////////////////////////////////////////////////////
1187 * @defgroup groupofcontracts Group of contracts
1190 * The following functions are used to negotiate atomically more than
1191 * one contract. This allows to build complex applications by
1192 * splitting them in individual contracts that are negotiated
1193 * simultaneously and atomically.
1199 * frsh_group_change_mode_sync()
1201 * This function performs a set of negotiation operations which can
1202 * include: adding new contracts (neg), modifying existing vres (reneg)
1203 * or cancelling existing vres (cancel).
1205 * If one of the group operations has a NULL value, unless it causes an
1206 * inconsistency the system will suppose that no operation of that
1207 * type (neg, reneg or cancel) should be done.
1209 * The virtual resources resulting from negotiations of new contracts are
1210 * returned in the parameter 'new_vres' which must be provided by the user.
1212 * If the on-line admission test is enabled, FRSH analizes the
1213 * schedulability of the context that would result in the new
1214 * contract situation with removed, changed and added contracts.
1216 * A successful return code will mean that all contracts have been
1217 * accepted and all required operations (creation, cancellation or
1218 * update of vres) have been carried out to reach the new running
1221 * If any of the contracts is not accepted a corresponding error shall be
1222 * returned and no changes will be made to the previously running context.
1224 * This call is a synchronous, potentially blocking operation. It
1225 * returns when the system has rejected the contracts or accepted
1226 * and made them effective.
1228 * @param[in] contracts_to_neg List of new contracts to negotiate
1229 * @param[in] contracts_to_reneg List of contracts to renegotiate
1230 * @param[in] vres_to_reneg List of vres to renegotiate
1231 * @param[in] vres_to_cancel List of vres to cancel
1232 * @param[out] new_vres List of vres of new contracts.
1234 * @return 0 if no error \n
1235 * FRSH_ERR_BAD_ARGUMENT Invalid pointer or group identifier. \n
1236 * FRSH_ERR_CONTRACT_LABEL_ALREADY_EXISTS contract_label not unique. \n
1237 * FRSH_ERR_NOT_CONTRACTED_VRES: One of the provided vres_ids
1238 * is not recognised. \n
1239 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD The calling thread
1240 * is not scheduled under FRSH. \n
1241 * FRSH_ERR_INVALID_SCHEDULER_REPLY: The scheduler is wrong or
1243 * FRSH_ERR_INTERNAL_ERROR: Erroneous binding or malfunction of
1244 * FRSH main scheduler. \n
1245 * FRSH_ERR_REJECTED_CONTRACT: The negotiation of one of the
1246 * proposed contracts has failed.
1248 int frsh_group_change_mode_sync
1249 (const frsh_contracts_group_t *contracts_to_neg,
1250 const frsh_contracts_group_t *contracts_to_reneg,
1251 const frsh_vres_group_t *vres_to_reneg,
1252 const frsh_vres_group_t *vres_to_cancel,
1253 frsh_vres_group_t *new_vres);
1256 * frsh_group_change_mode_async()
1258 * This is an asynchronous (non-blocking) version of the previous function,
1259 * frsh_group_change_mode_sync() and thus, it returns inmediately.
1261 * The status of the change of mode and the identifiers for new virtual
1262 * resources must be requested with the function 'frsh_group_get_status'
1263 * by using the return parameter 'group'.
1265 * As in the asynchronous renegotiations, when the operation is completed,
1266 * the user is notified with a signal so he can check the final result with
1267 * 'frsh_group_get_status'. In case that FRSH_NULL_SIGNAL is used, no
1268 * signal will be sent to the user.
1270 * @param[in] contracts_to_neg List of new contracts to negotiate
1271 * @param[in] contracts_to_reneg List of contracts to renegotiate
1272 * @param[in] vres_to_reneg List of vres to renegotiate
1273 * @param[in] vres_to_cancel List of vres to cancel
1274 * @param[in] signal Signal number to notify completion of
1275 * the change of mode. If FRSH_NULL_SIGNAL,
1276 * no signal will be raised.
1277 * @param[in] signal_info Data associated to the signal
1278 * @param[out] group The group identifier to get the status
1280 * @return 0 if no error \n
1281 * FRSH_ERR_BAD_ARGUMENT Invalid pointer, signal or group identifier. \n
1282 * FRSH_ERR_CONTRACT_LABEL_ALREADY_EXISTS contract_label not unique. \n
1283 * FRSH_ERR_NOT_CONTRACTED_VRES: One of the provided vres_ids
1284 * is not recognised. \n
1285 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD The calling thread
1286 * is not scheduled under FRSH. \n
1287 * FRSH_ERR_INVALID_SCHEDULER_REPLY: The scheduler is wrong or
1289 * FRSH_ERR_INTERNAL_ERROR: Erroneous binding or malfunction of
1290 * FRSH main scheduler.
1292 int frsh_group_change_mode_async
1293 (const frsh_contracts_group_t *contracts_to_neg,
1294 const frsh_contracts_group_t *contracts_to_reneg,
1295 const frsh_vres_group_t *vres_to_reneg,
1296 const frsh_vres_group_t *vres_to_cancel,
1297 const frsh_signal_t signal,
1298 const frsh_signal_info_t signal_info,
1299 frsh_group_id_t *group);
1302 * frsh_group_get_status()
1304 * This function is similar to 'frsh_vres_get_renegotiation_status' but it
1305 * is intented for group negotiations (changes of mode).
1307 * The operation reports on the status of the last negotiation
1308 * operation enqueued for the specified group identifier.
1310 * The status value can be one of the following values:
1312 * - FRSH_RS_IN_PROGRESS: the change of mode is in progress
1313 * - FRSH_RS_REJECTED: the change of mode was not accepted
1314 * - FRSH_RS_ADMITTED: the change of mode was accepted
1315 * - FRSH_RS_NOT_REQUESTED: no change of mode has been requested yet
1317 * When status returns 'FRSH_RS_ADMITTED', the array 'new_vres' contains
1318 * the values for the new virtual resources (if there was any).
1320 * This function frees the group identifier when status returns something
1321 * different than FRSH_RS_IN_PROGRESS so further calls to this function may
1322 * return inconsistent values.
1324 * @param[in] group The group identifier
1325 * @param[out] status The status of the change of mode
1326 * @param[out] new_vres List of vres for the negotiation of new contracts.
1328 * @return 0 if no error \n
1329 * FRSH_ERR_BAD_ARGUMENT Invalid pointer, signal or group identifier. \n
1330 * FRSH_ERR_CONTRACT_LABEL_ALREADY_EXISTS contract_label not unique. \n
1331 * FRSH_ERR_NOT_CONTRACTED_VRES: One of the provided vres_ids
1332 * is not recognised. \n
1333 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD The calling thread
1334 * is not scheduled under FRSH. \n
1335 * FRSH_ERR_INVALID_SCHEDULER_REPLY: The scheduler is wrong or
1337 * FRSH_ERR_INTERNAL_ERROR: Erroneous binding or malfunction of
1338 * FRSH main scheduler.
1340 int frsh_group_get_status(const frsh_group_id_t group,
1341 frsh_renegotiation_status_t *status,
1342 frsh_vres_group_t *new_vres);
1348 ////////////////////////////////////////////////////
1349 // OBTAINING INFORMATION FROM THE SCHEDULER
1350 ////////////////////////////////////////////////////
1353 * @defgroup getschedinfo Obtaining information from the scheduler
1357 * The following functions are used to obtain available budget and
1358 * resource usage in the system. They can be used to adapt the
1359 * execution of threads according to the load of the system.
1366 * frsh_config_is_admission_test_enabled()
1368 * Returns true if the system is
1369 * configured with the on-line admission test enabled, or false
1370 * otherwise. This situation can only be changed at compile time.
1372 bool frsh_config_is_admission_test_enabled();
1375 * frsh_vres_get_usage()
1377 * This function stores the current execution time spent by the
1378 * threads bound to the specified vres in the variable pointed to by
1381 * @return 0 if successful \n
1382 * FRSH_ERR_BAD_ARGUMENT : if the value of the vres argument is not in range or
1383 * cpu_time is NULL \n
1384 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
1385 * scheduled under FRSH \n
1386 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
1388 * FRSH_ERR_NOT_CONTRACTED_VRESR : if the vres of the calling thread
1389 * has been cancelled or it is not valid
1392 int frsh_vres_get_usage
1393 (const frsh_vres_id_t vres,
1394 frsh_rel_time_t *spent);
1398 * frsh_vres_get_job_usage()
1400 * Get the execution time of the current job of the specified virtual
1401 * resource for a bounded or synchronized workload.
1403 int frsh_vres_get_job_usage
1404 (const frsh_vres_id_t vres,
1405 frsh_rel_time_t *spent);
1409 * frsh_vres_get_remaining_budget()
1411 * This function stores in the variable pointed to by budget the
1412 * remaining execution-time budget associated with the specified
1415 * @return 0 if successful \n
1416 * FRSH_ERR_BAD_ARGUMENT : if the value of the vres argument is not in range or
1418 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
1419 * scheduled under FRSH \n
1420 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
1422 * FRSH_ERR_NOT_CONTRACTED_VRES : if the vres of the calling thread
1423 * has been cancelled or it is not valid
1426 int frsh_vres_get_remaining_budget
1427 (const frsh_vres_id_t vres,
1428 frsh_rel_time_t *budget);
1432 * frsh_vres_get_budget_and_period()
1434 * This function stores in the variables
1435 * pointed to by budget and period, the execution-time budget and the
1436 * period respectively associated with the specified vres. If any of
1437 * these pointers is NULL, the corresponding information is not stored.
1439 * @return 0 if successful \n
1440 * FRSH_ERR_BAD_ARGUMENT : if the value of the vres argument is not in range,
1441 * or budget and period are both NULL \n
1442 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
1443 * scheduled under FRSH \n
1444 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
1446 * FRSH_ERR_NOT_CONTRACTED_VRES : if the vres of the calling thread
1447 * has been cancelled or it is not valid
1450 int frsh_vres_get_budget_and_period
1451 (const frsh_vres_id_t vres,
1452 frsh_rel_time_t *budget,
1453 frsh_rel_time_t *period);
1457 /////////////////////////////////////////////////////////////////////
1458 // SERVICE THREAD TUNING
1459 /////////////////////////////////////////////////////////////////////
1461 * @defgroup servthtuning Service thread tuning
1465 * The following functions are used to obtain available budget and
1466 * resource usage in the system. They can be used to adapt the
1467 * execution of threads to the load of the system.
1473 * frsh_service_thread_set_data()
1475 * This function allows the application to change the period and
1476 * budget of the service thread that makes the
1477 * negotiations. Increasing the utilization of this thread makes the
1478 * negotiations faster, but introduces additional load in the system
1479 * that may decrease the bandwidth available for the vres. For this
1480 * call, the system will make a schedulability analysis to determine
1481 * if the new situation is acceptable or not. This is reported back in
1482 * the variable pointed to by accepted. If the new service thread data
1483 * is accepted, the system will reassign budgets and periods to the
1484 * vres according to the new bandwidth available, in the same way
1485 * as it does for a regular contract negotiation.
1487 * When its budget is exhausted, the service thread may run in the
1490 * The service thread starts with a default budget and period that are
1493 * Implementation dependency: in the fixed priority implementtaion of
1494 * frsh, the default priority is lower than the priority of any vres,
1495 * but higher than the background. According to the
1496 * implementation-dependent module the priority is adjustable by means
1497 * of a function that changes its preemption level
1499 * @return 0 if successful \n
1500 * FRSH_ERR_BAD_ARGUMENT : if any of the pointer arguments is NULL or
1501 * the budget value is greater than the period value \n
1502 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
1503 * scheduled under FRSH \n
1504 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
1506 * FRSH_ERR_NOT_CONTRACTED_VRES : if the vres of the calling thread
1507 * has been cancelled or it is not valid
1510 int frsh_service_thread_set_data (const frsh_rel_time_t *budget,
1511 const frsh_rel_time_t *period,
1515 * frsh_service_thread_get_data()
1517 * this function returns in the variables pointed by budget and
1518 * period, respectively, the current budget and period of the service
1521 * @return 0 if successful \n
1522 * FRSH_ERR_BAD_ARGUMENT : if any of the pointer arguments is NULL \n
1523 * FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
1524 * scheduled under FRSH \n
1525 * FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not
1527 * FRSH_ERR_NOT_CONTRACTED_VRES : if the vres of the calling thread
1528 * has been cancelled or it is not valid
1531 int frsh_service_thread_get_data
1532 (frsh_rel_time_t *budget,
1533 frsh_rel_time_t *period);
1539 ////////////////////////////////////////////////////////////////////////
1540 // BACKGROUND MANAGEMENT
1541 ////////////////////////////////////////////////////////////////////////
1543 //A round-robin background scheduling policy is available for those
1544 //threads that do not have real-time requirements. Because some of
1545 //these threads may require sharing information with other threads run
1546 //by regular vres. Special background contracts may be created for
1547 //specifying the synchronization requirements.
1549 //The way of specifying a background contract is by setting
1550 //contract_type to FRSH_CT_BACKGROUND. Negotiation may fail if the contract uses
1551 //shared_objects. If the contract has no shared_objects the returned
1552 //vres id represents the background and may be used to bind more
1553 //than one thread. If the contract has shared objects a vres is
1554 //created to keep track of them, but the associated threads are
1555 //executed in the background, together with the other background
1561 #endif // _FRSH_CORE_H_