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