Subversion Repositories shark

Rev

Rev 983 | Rev 993 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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