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