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