Subversion Repositories shark

Rev

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

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