source: rtems/cpukit/score/include/rtems/score/schedulercbs.h @ df2177ab

5
Last change on this file since df2177ab was df2177ab, checked in by Sebastian Huber <sebastian.huber@…>, on 07/01/16 at 12:47:07

score: Change scheduler node init and destroy

Provide the scheduler node to initialize or destroy to the corresponding
operations. This makes it possible to have more than one scheduler node
per thread.

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