Subversion Repositories shark

Rev

Rev 1063 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1063 tullio 1
 
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program; if not, write to the Free Software
15
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 *
17
 */
18
 
881 trimarchi 19
//fsf_hierarchical.h
20
//====================================================================
21
//       FFFFFFIII   RRRRR      SSTTTTTTT
22
//      FF         IIR   RR    SS
23
//     FF           IR        SS
24
//    FFFFFF         RRRR    SSSSST
25
//   FF       FI       RRR  SS
26
//  FF         II     RRR  SS
27
// FF           IIIIIR    RS
28
//
29
// FSF(FIRST Scheduling Framework) 
30
// hierarchical scheduling management
31
//===================================================================
32
 
33
#include <time.h>
34
#include "fsf_basic_types.h"
35
#include "fsf_core.h"
36
 
37
#ifndef _FSF_HIERARCHICAL_H_
38
#define _FSF_HIERARCHICAL_H_
39
 
40
#define FSF_HIERARCHICAL_MODULE_SUPPORTED       1
41
 
42
//// The definition of this types is in fsf_basic_types.h
43
//
44
//// Scheduling policies
45
//typedef enum {FSF_FP, FSF_EDF, FSF_TABLE_DRIVEN, FSF_NONE} 
46
//    fsf_sched_policy_t;
47
//
48
//// Scheduling policy and parameters
49
//typedef struct {
50
//  fsf_sched_policy_t    policy;
51
//  void *                params;
52
//} fsf_sched_params_t;
53
//// The params member is a pointer to one of the 
54
//// following:
55
////    FP:  int (priority)
56
////    EDF: struct timespec (deadline)
57
////    TABLE_DRIVEN : struct fsf_table_driven_params_t
58
//
59
//
60
////Scheduling parameters for the table-driven policy (t.b.d)
61
//typedef struct {
62
//  // list of target windows (t.b.d.) 
63
//  // deadline (for the API): end of september
64
//} fsf_table_driven_params_t;
65
//
66
//
67
////Initialization information for a scheduling policy
68
//typedef void * fsf_sched_init_info_t;
69
//// It shall be one of the following:
70
////    FP:  none
71
////    EDF: none
72
////    TABLE_DRIVEN : struct timespec (schedule duration)
73
//
74
 
928 trimarchi 75
 
76
/**
77
   \ingroup hiermodule  
78
 
79
   This call has the following effects:
993 lipari 80
 
81
    - FP: none
82
 
928 trimarchi 83
    - EDF: none
84
 
993 lipari 85
    - TABLE_DRIVEN : Records the schedule duration, and starts the
86
       schedule at the time of the call. After the schedule duration
87
       has elapsed, the schedule in the table is repeated.
88
 
89
    - RR : TBD
90
 
928 trimarchi 91
     @param [in] server server id
993 lipari 92
 
928 trimarchi 93
     @param [in] info TBD
94
 
95
     @retval FSF_ERR_BAD_ARGUMENT if the value of the server argument
96
            is not in range or info is NULL
97
     @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD if the calling thread is not
98
            scheduled under the FSF
99
     @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or not
100
             running
101
     @retval FSF_ERR_NOT_CONTRACTED_SERVER if the server of the calling
102
             thread has been cancelled or it is not valid
881 trimarchi 103
*/
104
int fsf_init_local_scheduler(
105
   fsf_server_id_t       server,
106
   fsf_sched_init_info_t info);
107
 
108
 
109
/////////////////////////////////////////////////
110
//                       CONTRACT PARAMETERS
111
////////////////////////////////////////////////
112
 
928 trimarchi 113
/**
114
   \ingroup hiermodule
115
 
116
   The operation updates the specified contract parameters object by
117
   setting its scheduling policy to the specified input parameter.
118
   The default policy is FSF_NONE, which means that only one thread
119
   may be bound to the server
120
 
121
   @param [in] contract pointer to the contract
122
   @param [in] sched_policy local scheduling policy for this server.
123
     Can be FSF_FP, FSF_EDF, FSF_TABLE_DRIVEN, FSF_NONE.
124
 
125
   @retval 0 if the operation is succesful
126
   @retval FSF_ERR_BAD_ARGUMENT if sched_policy is not one of the supported
127
       ones, or contract is NULL
128
 
889 trimarchi 129
*/
881 trimarchi 130
int
131
fsf_set_contract_scheduling_policy
132
  (fsf_contract_parameters_t *contract,
133
   fsf_sched_policy_t         sched_policy);
134
 
135
 
928 trimarchi 136
/**
137
   \ingroup hiermodule
138
 
139
   This operation obtains from the specified contract parameters
140
   object its scheduling policy, and copies it to the place pointed to
141
   by the corresponding input parameter.
142
 
143
   @param [in] contract pointer to the contract
144
   @param [out] sched_policy pointer to a variable that will contain
145
                the scheduling policy
146
 
147
   @retval 0 if the operation is succesful
148
   @retval FSF_ERR_BAD_ARGUMENT if sched_policy or contract are NULL
149
 
889 trimarchi 150
*/
881 trimarchi 151
int
152
fsf_get_contract_scheduling_policy
153
  (const fsf_contract_parameters_t *contract,
154
   fsf_sched_policy_t              *sched_policy);
155
 
156
 
928 trimarchi 157
/**
158
   \ingroup hiermodule
159
 
160
   This operation creates a thread and binds it to the specified
993 lipari 161
   server that has a local scheduler, i.e. policy different than FSF_NONE. The new
928 trimarchi 162
   thread is created with the arguments thread, attr, thread_code and
163
   arg as they are defined for the pthread_create() POSIX function
164
   call, and its local scheduling parameters are set to the value
165
   stored in the variable pointed to by sched_params, which must be
166
   compatible with the server's scheduling policy. Then, the function
167
   binds the created thread to the new server. The attr parameter is
168
   overwritten as necessary to introduce the adequate scheduling
169
   policy and priority, according to the preemption level given in the
170
   contract and the fsf_priority_map() function defined by the user.
171
 
172
   @param [in] server server id
173
   @param [in] sched_params scheduling parameters for the thread
174
   @param [out] thread the thread id after creation
175
   @param [in] attr attributes for the task (see pthread_create())
176
   @param [in] thread_code pointer to a function that implements the
177
       thread code
178
   @param [in] arg arguments for the thread
179
 
180
   @retval 0 if the operation is succesful
181
   @retval FSF_ERR_BAD_ARGUMENT if the value of the server argument
182
           is not in range, or sched_params is NULL
183
   @retval FSF_ERR_SCHED_POLICY_NOT_COMPATIBLE if the scheduling policy
881 trimarchi 184
       in sched_params is not compatible to the server's one.
928 trimarchi 185
   @retval FSF_ERR_INTERNAL_ERROR erroneous binding or malfunction of the FSF
881 trimarchi 186
       main scheduler
928 trimarchi 187
   @retval FSF_ERR_NOT_CONTRACTED_SERVER if the referenced server is not valid
881 trimarchi 188
 
928 trimarchi 189
   @retval others It may also return any of  the errors that may be
190
       returned by the pthread_create()POSIX function call
881 trimarchi 191
*/
192
 
193
int
194
fsf_create_local_thread
195
  (fsf_server_id_t        server,
196
   fsf_sched_params_t    *sched_params,
197
   pthread_t             *thread,
198
   pthread_attr_t        *attr,
199
   fsf_thread_code_t      thread_code,
200
   void                  *arg);
201
 
928 trimarchi 202
/**
203
   \ingroup hiermodule
204
 
993 lipari 205
   This operation associates a thread with a server that has a local
206
   scheduler, i.e. with a policy different than FSF_NONE. The thread's
207
   local scheduling parameters are set to the value stored in the
208
   variable pointed to by sched_params, which must be compatible with
209
   the server's scheduling policy. After the call the thread starts
210
   consuming the server's budget and is executed according to the
211
   contract established for that server and to its scheduling
212
   policy. If the thread was already bound to another server, it is
213
   effectively unbound from it and bound to the specified one.
881 trimarchi 214
 
993 lipari 215
   <i>Implementation dependent issue for MARTE OS: In order to allow the
216
   usage of application defined schedulers, the given thread must not
217
   have the scheduling policy SCHED_APP and at the same time be
218
   attached to an application scheduler different than the fsf
219
   scheduler.</i>
881 trimarchi 220
 
928 trimarchi 221
   @param [in] server server id
222
   @param [in] thread thread id
223
   @param [in] sched_params scheduling parameters for the thread
224
 
225
   @retval 0 if the operation is succesful
993 lipari 226
   @retval FSF_ERR_BAD_ARGUMENT if the server argument does not comply with
881 trimarchi 227
       the expected format or valid range, the given thread does not exist,
228
       or sched_params is NULL
928 trimarchi 229
   @retval FSF_ERR_SCHED_POLICY_NOT_COMPATIBLE if the scheduling policy
881 trimarchi 230
       in sched_params is not compatible to the server's one.
928 trimarchi 231
   @retval FSF_ERR_INTERNAL_ERROR erroneous binding or malfunction of the FSF
881 trimarchi 232
       main scheduler
928 trimarchi 233
   @retval FSF_ERR_UNKNOWN_APPSCHEDULED_THREAD if the thread is attached to
881 trimarchi 234
       an application defined scheduler different than the fsf scheduler
928 trimarchi 235
   @retval FSF_ERR_NOT_CONTRACTED_SERVER if the referenced server is not valid
985 julio 236
   @retval FSF_ERR_SERVER_WORKLOAD_NOT_COMPATIBLE: if the kind of workload
237
       of the server is FSF_OVERHEAD
881 trimarchi 238
*/
239
int  
240
fsf_bind_local_thread_to_server
241
  (fsf_server_id_t      server,
242
   pthread_t            thread,
243
   fsf_sched_params_t  *sched_params);
244
 
245
 
928 trimarchi 246
/**
247
   \ingroup hiermodule
248
 
249
   This function changes the local scheduling parameters of the thread
250
   to the value pointed to by sched_params. This value must be
251
   compatible with the scheduling policy of the server to which the
252
   thread is bound.
253
 
254
   @param [in] thread thread id
993 lipari 255
 
928 trimarchi 256
   @param [in] sched_params scheduling parameters
257
 
258
   @retval 0 if the operation is succesful
259
   @retval FSF_ERR_BAD_ARGUMENT if the given thread does not exist,
881 trimarchi 260
       or sched_params is NULL
928 trimarchi 261
   @retval FSF_ERR_SCHED_POLICY_NOT_COMPATIBLE if the thread is already bound
881 trimarchi 262
       and the scheduling policy in sched_params is not compatible to the
263
       one of the thread's server.
928 trimarchi 264
   @retval FSF_ERR_NOT_SCHEDULED_THREAD if the given thread is not scheduled
881 trimarchi 265
       under the FSF
928 trimarchi 266
   @retval FSF_ERR_INTERNAL_ERROR erroneous binding or malfunction of the FSF
881 trimarchi 267
       main scheduler
928 trimarchi 268
   @retval FSF_ERR_UNKNOWN_APPSCHEDULED_THREAD if the thread is attached to
881 trimarchi 269
       an application defined scheduler different than the fsf scheduler
928 trimarchi 270
   @retval FSF_ERR_NOT_CONTRACTED_SERVER if the thread is bound and its server
881 trimarchi 271
       is not valid
272
*/
273
int  
274
fsf_set_local_thread_sched_parameters
275
  (pthread_t                     thread,
276
   const fsf_sched_params_t  *sched_params);
277
 
278
 
928 trimarchi 279
/**
280
   \ingroup hiermodule
281
 
282
   This function stores the local scheduling parameters of the
283
   specified thread in the variable pointed to by sched_params
284
 
285
   @param [in] thread thread id
286
   @param [out] sched_params scheduling parameters
287
 
288
   @retval 0 if the operation is succesful
289
   @retval FSF_ERR_BAD_ARGUMENT if sched_params is NULL or the thread does
290
           not exist
291
   @retval FSF_ERR_NOT_SCHEDULED_THREAD if the given thread is not scheduled
881 trimarchi 292
       under the FSF
293
*/
294
int  
295
fsf_get_local_thread_sched_parameters
296
  (pthread_t            thread,
297
   fsf_sched_params_t  *sched_params);
298
 
299
 
300
#endif // _FSF_HIERARCHICAL_H_