1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup RTEMSScoreSchedulerCBS |
---|
5 | * |
---|
6 | * @brief Thread manipulation for the CBS scheduler |
---|
7 | * |
---|
8 | * This include file contains all the constants and structures associated |
---|
9 | * with the manipulation of threads for the CBS scheduler. |
---|
10 | */ |
---|
11 | |
---|
12 | /* |
---|
13 | * Copryight (c) 2011 Petr Benes. |
---|
14 | * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). |
---|
15 | * |
---|
16 | * The license and distribution terms for this file may be |
---|
17 | * found in the file LICENSE in this distribution or at |
---|
18 | * http://www.rtems.org/license/LICENSE. |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef _RTEMS_SCORE_SCHEDULERCBS_H |
---|
22 | #define _RTEMS_SCORE_SCHEDULERCBS_H |
---|
23 | |
---|
24 | #include <rtems/score/chain.h> |
---|
25 | #include <rtems/score/priority.h> |
---|
26 | #include <rtems/score/scheduler.h> |
---|
27 | #include <rtems/score/rbtree.h> |
---|
28 | #include <rtems/score/scheduleredf.h> |
---|
29 | #include <rtems/rtems/signal.h> |
---|
30 | #include <rtems/rtems/timer.h> |
---|
31 | #include <rtems/score/thread.h> |
---|
32 | |
---|
33 | #ifdef __cplusplus |
---|
34 | extern "C" { |
---|
35 | #endif |
---|
36 | |
---|
37 | /** |
---|
38 | * @defgroup RTEMSScoreSchedulerCBS CBS Scheduler |
---|
39 | * |
---|
40 | * @ingroup RTEMSScoreScheduler |
---|
41 | * |
---|
42 | * @brief CBS Scheduler. |
---|
43 | * |
---|
44 | * @{ |
---|
45 | */ |
---|
46 | |
---|
47 | #define SCHEDULER_CBS_MAXIMUM_PRIORITY SCHEDULER_EDF_MAXIMUM_PRIORITY |
---|
48 | |
---|
49 | /** |
---|
50 | * Entry points for the Constant Bandwidth Server Scheduler. |
---|
51 | * |
---|
52 | * @note: The CBS scheduler is an enhancement of EDF scheduler, |
---|
53 | * therefor some routines are similar. |
---|
54 | */ |
---|
55 | #define SCHEDULER_CBS_ENTRY_POINTS \ |
---|
56 | { \ |
---|
57 | _Scheduler_EDF_Initialize, /* initialize entry point */ \ |
---|
58 | _Scheduler_EDF_Schedule, /* schedule entry point */ \ |
---|
59 | _Scheduler_EDF_Yield, /* yield entry point */ \ |
---|
60 | _Scheduler_EDF_Block, /* block entry point */ \ |
---|
61 | _Scheduler_CBS_Unblock, /* unblock entry point */ \ |
---|
62 | _Scheduler_EDF_Update_priority, /* update priority entry point */ \ |
---|
63 | _Scheduler_EDF_Map_priority, /* map priority entry point */ \ |
---|
64 | _Scheduler_EDF_Unmap_priority, /* unmap priority entry point */ \ |
---|
65 | SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP \ |
---|
66 | _Scheduler_CBS_Node_initialize, /* node initialize entry point */ \ |
---|
67 | _Scheduler_default_Node_destroy, /* node destroy entry point */ \ |
---|
68 | _Scheduler_CBS_Release_job, /* new period of task */ \ |
---|
69 | _Scheduler_CBS_Cancel_job, /* cancel period of task */ \ |
---|
70 | _Scheduler_default_Tick, /* tick entry point */ \ |
---|
71 | _Scheduler_default_Start_idle /* start idle entry point */ \ |
---|
72 | SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \ |
---|
73 | } |
---|
74 | |
---|
75 | /* Return values for CBS server. */ |
---|
76 | #define SCHEDULER_CBS_OK 0 |
---|
77 | #define SCHEDULER_CBS_ERROR_GENERIC -16 |
---|
78 | #define SCHEDULER_CBS_ERROR_NO_MEMORY -17 |
---|
79 | #define SCHEDULER_CBS_ERROR_INVALID_PARAMETER -18 |
---|
80 | #define SCHEDULER_CBS_ERROR_UNAUTHORIZED -19 |
---|
81 | #define SCHEDULER_CBS_ERROR_UNIMPLEMENTED -20 |
---|
82 | #define SCHEDULER_CBS_ERROR_MISSING_COMPONENT -21 |
---|
83 | #define SCHEDULER_CBS_ERROR_INCONSISTENT_STATE -22 |
---|
84 | #define SCHEDULER_CBS_ERROR_SYSTEM_OVERLOAD -23 |
---|
85 | #define SCHEDULER_CBS_ERROR_INTERNAL_ERROR -24 |
---|
86 | #define SCHEDULER_CBS_ERROR_NOT_FOUND -25 |
---|
87 | #define SCHEDULER_CBS_ERROR_FULL -26 |
---|
88 | #define SCHEDULER_CBS_ERROR_EMPTY -27 |
---|
89 | #define SCHEDULER_CBS_ERROR_NOSERVER SCHEDULER_CBS_ERROR_NOT_FOUND |
---|
90 | |
---|
91 | /** Maximum number of simultaneous servers. */ |
---|
92 | extern const uint32_t _Scheduler_CBS_Maximum_servers; |
---|
93 | |
---|
94 | /** Server id. */ |
---|
95 | typedef uint32_t Scheduler_CBS_Server_id; |
---|
96 | |
---|
97 | /** Callback function invoked when a budget overrun of a task occurs. */ |
---|
98 | typedef void (*Scheduler_CBS_Budget_overrun)( |
---|
99 | Scheduler_CBS_Server_id server_id |
---|
100 | ); |
---|
101 | |
---|
102 | /** |
---|
103 | * This structure handles server parameters. |
---|
104 | */ |
---|
105 | typedef struct { |
---|
106 | /** Relative deadline of the server. */ |
---|
107 | time_t deadline; |
---|
108 | /** Budget (computation time) of the server. */ |
---|
109 | time_t budget; |
---|
110 | } Scheduler_CBS_Parameters; |
---|
111 | |
---|
112 | /** |
---|
113 | * This structure represents a time server. |
---|
114 | */ |
---|
115 | typedef struct { |
---|
116 | /** |
---|
117 | * Task id. |
---|
118 | * |
---|
119 | * @note: The current implementation of CBS handles only one task per server. |
---|
120 | */ |
---|
121 | rtems_id task_id; |
---|
122 | /** Server paramenters. */ |
---|
123 | Scheduler_CBS_Parameters parameters; |
---|
124 | /** Callback function invoked when a budget overrun occurs. */ |
---|
125 | Scheduler_CBS_Budget_overrun cbs_budget_overrun; |
---|
126 | |
---|
127 | /** |
---|
128 | * @brief Indicates if this CBS server is initialized. |
---|
129 | * |
---|
130 | * @see _Scheduler_CBS_Create_server() and _Scheduler_CBS_Destroy_server(). |
---|
131 | */ |
---|
132 | bool initialized; |
---|
133 | } Scheduler_CBS_Server; |
---|
134 | |
---|
135 | /** |
---|
136 | * This structure handles CBS specific data of a thread. |
---|
137 | */ |
---|
138 | typedef struct { |
---|
139 | /** EDF scheduler specific data of a task. */ |
---|
140 | Scheduler_EDF_Node Base; |
---|
141 | /** CBS server specific data of a task. */ |
---|
142 | Scheduler_CBS_Server *cbs_server; |
---|
143 | |
---|
144 | Priority_Node *deadline_node; |
---|
145 | } Scheduler_CBS_Node; |
---|
146 | |
---|
147 | |
---|
148 | /** |
---|
149 | * List of servers. The @a Scheduler_CBS_Server is the index to the array |
---|
150 | * of pointers to @a _Scheduler_CBS_Server_list. |
---|
151 | */ |
---|
152 | extern Scheduler_CBS_Server _Scheduler_CBS_Server_list[]; |
---|
153 | |
---|
154 | /** |
---|
155 | * @brief Unblocks a thread. |
---|
156 | * |
---|
157 | * @param scheduler The scheduler control. |
---|
158 | * @param the_thread The thread to unblock. |
---|
159 | * @param node The scheduler node. |
---|
160 | */ |
---|
161 | void _Scheduler_CBS_Unblock( |
---|
162 | const Scheduler_Control *scheduler, |
---|
163 | Thread_Control *the_thread, |
---|
164 | Scheduler_Node *node |
---|
165 | ); |
---|
166 | |
---|
167 | /** |
---|
168 | * @brief Releases a job. |
---|
169 | * |
---|
170 | * @param scheduler The scheduler for the operation. |
---|
171 | * @param the_thread The corresponding thread. |
---|
172 | * @param priority_node The priority node for the operation. |
---|
173 | * @param deadline The deadline for the job. |
---|
174 | * @param queue_context The thread queue context. |
---|
175 | */ |
---|
176 | void _Scheduler_CBS_Release_job( |
---|
177 | const Scheduler_Control *scheduler, |
---|
178 | Thread_Control *the_thread, |
---|
179 | Priority_Node *priority_node, |
---|
180 | uint64_t deadline, |
---|
181 | Thread_queue_Context *queue_context |
---|
182 | ); |
---|
183 | |
---|
184 | /** |
---|
185 | * @brief Cancels a job. |
---|
186 | * |
---|
187 | * @param scheduler The scheduler for the operation. |
---|
188 | * @param the_thread The corresponding thread. |
---|
189 | * @param priority_node The priority node for the operation. |
---|
190 | * @param queue_context The thread queue context. |
---|
191 | */ |
---|
192 | void _Scheduler_CBS_Cancel_job( |
---|
193 | const Scheduler_Control *scheduler, |
---|
194 | Thread_Control *the_thread, |
---|
195 | Priority_Node *priority_node, |
---|
196 | Thread_queue_Context *queue_context |
---|
197 | ); |
---|
198 | |
---|
199 | /** |
---|
200 | * @brief _Scheduler_CBS_Initialize |
---|
201 | * |
---|
202 | * Initializes the CBS library. |
---|
203 | * |
---|
204 | * @return SCHEDULER_CBS_OK This method always returns this status. |
---|
205 | */ |
---|
206 | int _Scheduler_CBS_Initialize(void); |
---|
207 | |
---|
208 | /** |
---|
209 | * @brief Attaches a task to an already existing server. |
---|
210 | * |
---|
211 | * Attach a task to an already existing server. |
---|
212 | * |
---|
213 | * @param server_id The id of the existing server. |
---|
214 | * @param task_id The id of the task to attach. |
---|
215 | * |
---|
216 | * @retval SCHEDULER_CBS_OK The operation was successful. |
---|
217 | * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is so big |
---|
218 | * or there is no thread for this task id. |
---|
219 | * @retval SCHEDULER_CBS_ERROR_NOSERVER The server is not yet initialized. |
---|
220 | * @retval SCHEDULER_CBS_ERROR_FULL The server already has a task. |
---|
221 | */ |
---|
222 | int _Scheduler_CBS_Attach_thread ( |
---|
223 | Scheduler_CBS_Server_id server_id, |
---|
224 | rtems_id task_id |
---|
225 | ); |
---|
226 | |
---|
227 | /** |
---|
228 | * @brief Detaches from the CBS Server. |
---|
229 | * |
---|
230 | * Detach from the CBS Server. |
---|
231 | * |
---|
232 | * @param server_id The id of the existing server. |
---|
233 | * @param task_id The id of the task to attach. |
---|
234 | * |
---|
235 | * @retval SCHEDULER_CBS_OK The operation was successful. |
---|
236 | * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is to big, |
---|
237 | * or the task with this id is not attached to this server or there is |
---|
238 | * no thread with this task. |
---|
239 | * @retval SCHEDULER_CBS_ERROR_NOSERVER The server is not yet initialized. |
---|
240 | */ |
---|
241 | int _Scheduler_CBS_Detach_thread ( |
---|
242 | Scheduler_CBS_Server_id server_id, |
---|
243 | rtems_id task_id |
---|
244 | ); |
---|
245 | |
---|
246 | /** |
---|
247 | * @brief Cleans up resources associated to the CBS Library. |
---|
248 | * |
---|
249 | * Cleanup resources associated to the CBS Library. |
---|
250 | * |
---|
251 | * @return This method always returns SCHEDULER_CBS_OK. |
---|
252 | */ |
---|
253 | int _Scheduler_CBS_Cleanup (void); |
---|
254 | |
---|
255 | /** |
---|
256 | * @brief Creates a new server with specified parameters. |
---|
257 | * |
---|
258 | * Create a new server with specified parameters. |
---|
259 | * |
---|
260 | * @param params The parameters for the server. |
---|
261 | * @param budget_overrun_callback The budget overrun for the new server. |
---|
262 | * @param[out] server_id In the case of success, this parameter contains the |
---|
263 | * id of the newly created server. |
---|
264 | * |
---|
265 | * @retval SCHEDULER_CBS_OK The operation succeeded. |
---|
266 | * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The given parameters are invalid. |
---|
267 | * @retval SCHEDULER_CBS_ERROR_FULL The maximum number of servers was already |
---|
268 | * created, a new server cannot be created. |
---|
269 | */ |
---|
270 | int _Scheduler_CBS_Create_server ( |
---|
271 | Scheduler_CBS_Parameters *params, |
---|
272 | Scheduler_CBS_Budget_overrun budget_overrun_callback, |
---|
273 | rtems_id *server_id |
---|
274 | ); |
---|
275 | |
---|
276 | /** |
---|
277 | * @brief Detaches all tasks from a server and destroys it. |
---|
278 | * |
---|
279 | * Detach all tasks from a server and destroy it. |
---|
280 | * |
---|
281 | * @param server_id The id of the server to destroy. |
---|
282 | * |
---|
283 | * @retval SCHEDULER_CBS_OK The operation was successful. |
---|
284 | * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is too big. |
---|
285 | * @retval SCHEDULER_CBS_ERROR_NOSERVER There is no initialized server with this id. |
---|
286 | */ |
---|
287 | int _Scheduler_CBS_Destroy_server ( |
---|
288 | Scheduler_CBS_Server_id server_id |
---|
289 | ); |
---|
290 | |
---|
291 | /** |
---|
292 | * @brief Retrieves the approved budget. |
---|
293 | * |
---|
294 | * Retrieve the budget that has been approved for the subsequent |
---|
295 | * server instances. |
---|
296 | * |
---|
297 | * @param server_id The id of the server instance of which the budget is wanted. |
---|
298 | * @param[out] approved_budget Contains the approved budget after a successful method call. |
---|
299 | * |
---|
300 | * @retval SCHEDULER_CBS_OK The operation was successful. |
---|
301 | * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is too big. |
---|
302 | * @retval SCHEDULER_CBS_ERROR_NOSERVER There is no initialized server with this id. |
---|
303 | */ |
---|
304 | int _Scheduler_CBS_Get_approved_budget ( |
---|
305 | Scheduler_CBS_Server_id server_id, |
---|
306 | time_t *approved_budget |
---|
307 | ); |
---|
308 | |
---|
309 | /** |
---|
310 | * @brief Retrieves remaining budget for the current server instance. |
---|
311 | * |
---|
312 | * Retrieve remaining budget for the current server instance. |
---|
313 | * |
---|
314 | * @param server_id The id of the server instance of which the remaining budget is wanted. |
---|
315 | * @param[out] remaining_budget Contains the remaining budget after a successful method call. |
---|
316 | * |
---|
317 | * @retval SCHEDULER_CBS_OK The operation was successful. |
---|
318 | * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is too big. |
---|
319 | * @retval SCHEDULER_CBS_ERROR_NOSERVER There is no initialized server with this id. |
---|
320 | */ |
---|
321 | int _Scheduler_CBS_Get_remaining_budget ( |
---|
322 | Scheduler_CBS_Server_id server_id, |
---|
323 | time_t *remaining_budget |
---|
324 | ); |
---|
325 | |
---|
326 | /** |
---|
327 | * @brief Gets relative time info. |
---|
328 | * |
---|
329 | * Retrieve time info relative to @a server_id. The server status code is returned. |
---|
330 | * |
---|
331 | * @param server_id is the server to get the status code from. |
---|
332 | * @param[out] exec_time Contains the execution time after a successful method call. |
---|
333 | * @param abs_time Not apparently used. |
---|
334 | * |
---|
335 | * @retval SCHEDULER_CBS_OK The operation was successful. |
---|
336 | * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is too big. |
---|
337 | * @retval SCHEDULER_CBS_ERROR_NOSERVER There is no initialized server with this id. |
---|
338 | */ |
---|
339 | int _Scheduler_CBS_Get_execution_time ( |
---|
340 | Scheduler_CBS_Server_id server_id, |
---|
341 | time_t *exec_time, |
---|
342 | time_t *abs_time |
---|
343 | ); |
---|
344 | |
---|
345 | /** |
---|
346 | * @brief Retrieves CBS scheduling parameters. |
---|
347 | * |
---|
348 | * Retrieve CBS scheduling parameters. |
---|
349 | * |
---|
350 | * @param server_id The id of the server to get the scheduling parameters from. |
---|
351 | * @param[out] params Will contain the scheduling parameters after successful method call. |
---|
352 | * |
---|
353 | * @retval SCHEDULER_CBS_OK The operation was successful. |
---|
354 | * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is too big. |
---|
355 | * @retval SCHEDULER_CBS_ERROR_NOSERVER There is no initialized server with this id. |
---|
356 | */ |
---|
357 | int _Scheduler_CBS_Get_parameters ( |
---|
358 | Scheduler_CBS_Server_id server_id, |
---|
359 | Scheduler_CBS_Parameters *params |
---|
360 | ); |
---|
361 | |
---|
362 | /** |
---|
363 | * @brief Gets a thread server id. |
---|
364 | * |
---|
365 | * Get a thread server id, or SCHEDULER_CBS_ERROR_NOT_FOUND if it is not |
---|
366 | * attached to any server. |
---|
367 | * |
---|
368 | * @param task_id The id of the task to get the corresponding server. |
---|
369 | * @param[out] server_id Will contain the server id after successful method call. |
---|
370 | * @retval SCHEDULER_CBS_OK The operation was successful |
---|
371 | * @retval SCHEDULER_CBS_ERROR_NOSERVER There is no server with this task attached. |
---|
372 | */ |
---|
373 | int _Scheduler_CBS_Get_server_id ( |
---|
374 | rtems_id task_id, |
---|
375 | Scheduler_CBS_Server_id *server_id |
---|
376 | ); |
---|
377 | |
---|
378 | /** |
---|
379 | * @brief Sets parameters for CBS scheduling. |
---|
380 | * |
---|
381 | * Change CBS scheduling parameters. |
---|
382 | * |
---|
383 | * @param server_id The id of the server. |
---|
384 | * @param parameters The parameters to set. |
---|
385 | * |
---|
386 | * @retval SCHEDULER_CBS_OK The operation was successful. |
---|
387 | * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is too big or the |
---|
388 | * given parameters are invalid. |
---|
389 | * @retval SCHEDULER_CBS_ERROR_NOSERVER There is no server with this id. |
---|
390 | */ |
---|
391 | int _Scheduler_CBS_Set_parameters ( |
---|
392 | Scheduler_CBS_Server_id server_id, |
---|
393 | Scheduler_CBS_Parameters *parameters |
---|
394 | ); |
---|
395 | |
---|
396 | /** |
---|
397 | * @brief Invoked when a limited time quantum is exceeded. |
---|
398 | * |
---|
399 | * This routine is invoked when a limited time quantum is exceeded. |
---|
400 | * |
---|
401 | * @param the_thread The thread that exceeded a limited time quantum. |
---|
402 | */ |
---|
403 | void _Scheduler_CBS_Budget_callout( |
---|
404 | Thread_Control *the_thread |
---|
405 | ); |
---|
406 | |
---|
407 | /** |
---|
408 | * @brief Initializes a CBS specific scheduler node of @a the_thread. |
---|
409 | * |
---|
410 | * @param scheduler The scheduler control for the operation. |
---|
411 | * @param[out] node The scheduler node to initalize. |
---|
412 | * @param the_thread The thread to initialize a scheduler node for. |
---|
413 | * @param priority The priority for the node. |
---|
414 | */ |
---|
415 | void _Scheduler_CBS_Node_initialize( |
---|
416 | const Scheduler_Control *scheduler, |
---|
417 | Scheduler_Node *node, |
---|
418 | Thread_Control *the_thread, |
---|
419 | Priority_Control priority |
---|
420 | ); |
---|
421 | |
---|
422 | #ifdef __cplusplus |
---|
423 | } |
---|
424 | #endif |
---|
425 | |
---|
426 | /** @} */ |
---|
427 | |
---|
428 | #endif |
---|
429 | /* end of include file */ |
---|