source: rtems/cpukit/score/include/rtems/score/schedulercbs.h @ 1ccb64e1

4.115
Last change on this file since 1ccb64e1 was 1ccb64e1, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 6, 2013 at 1:28:41 PM

scheduler: Add start idle thread operation

Add and use _Scheduler_Start_idle().

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