source: rtems/cpukit/score/include/rtems/score/schedulercbs.h @ 8e467384

4.115
Last change on this file since 8e467384 was 8e467384, checked in by Sebastian Huber <sebastian.huber@…>, on 06/03/14 at 08:29:30

score: Replace _Scheduler_Allocate/Free()

Replace _Scheduler_Allocate() with _Scheduler_Node_initialize(). Remove
the return status and thus the node initialization must be always
successful.

Rename _Scheduler_Free() to _Scheduler_Node_destroy().

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