source: rtems/cpukit/score/include/rtems/score/schedulercbs.h @ 1072d53d

4.115
Last change on this file since 1072d53d was 1072d53d, checked in by Jennifer Averett <Jennifer.Averett@…>, on 10/04/11 at 15:18:59

2011-10-04 Sebastian Huber <sebastian.huber@…>

PR 1922

  • score/include/rtems/score/schedulercbs.h, score/src/schedulercbs.c: EDF and CBS scheduler: extern declarations fix.
  • Property mode set to 100644
File size: 8.3 KB
Line 
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 *  $Id$
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 *  @addtogroup ScoreScheduler
37 *
38 */
39/**@{*/
40
41/**
42 *  Entry points for the Constant Bandwidth Server Scheduler.
43 *
44 *  @note: The CBS scheduler is an enhancement of EDF scheduler,
45 *         therefor some routines are similar.
46 */
47#define SCHEDULER_CBS_ENTRY_POINTS \
48  { \
49    _Scheduler_EDF_Initialize,       /* initialize entry point */ \
50    _Scheduler_EDF_Schedule,         /* schedule entry point */ \
51    _Scheduler_EDF_Yield,            /* yield entry point */ \
52    _Scheduler_EDF_Block,            /* block entry point */ \
53    _Scheduler_CBS_Unblock,          /* unblock entry point */ \
54    _Scheduler_EDF_Allocate,         /* allocate entry point */ \
55    _Scheduler_EDF_Free,             /* free entry point */ \
56    _Scheduler_EDF_Update,           /* update entry point */ \
57    _Scheduler_EDF_Enqueue,          /* enqueue entry point */ \
58    _Scheduler_EDF_Enqueue_first,    /* enqueue_first entry point */ \
59    _Scheduler_EDF_Extract,          /* extract entry point */ \
60    _Scheduler_EDF_Priority_compare, /* compares two priorities */ \
61    _Scheduler_CBS_Release_job,      /* new period of task */ \
62    _Scheduler_priority_Tick         /* tick 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 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} Scheduler_CBS_Server;
117
118/**
119 * This structure handles CBS specific data of a thread.
120 */
121typedef struct {
122  /** EDF scheduler specific data of a task. */
123  Scheduler_EDF_Per_thread      edf_per_thread;
124  /** CBS server specific data of a task. */
125  Scheduler_CBS_Server         *cbs_server;
126} Scheduler_CBS_Per_thread;
127
128
129/**
130 * List of servers. The @a Scheduler_CBS_Server is the index to the array
131 * of pointers to @a _Scheduler_CBS_Server_list.
132 */
133extern Scheduler_CBS_Server **_Scheduler_CBS_Server_list;
134
135/**
136 *  @brief Scheduler CBS Unblock
137 *
138 *  This routine adds @a the_thread to the scheduling decision, that is,
139 *  adds it to the ready queue and updates any appropriate scheduling
140 *  variables, for example the heir thread.
141 *
142 *  It is checked whether the remaining budget is sufficient. If not, the
143 *  thread continues as a new job in order to protect concurrent threads.
144 *
145 *  @note This has to be asessed as missed deadline of the current job.
146 *
147 *  @param[in] the_thread will be unblocked.
148 */
149void _Scheduler_CBS_Unblock(
150  Thread_Control    *the_thread
151);
152
153/**
154 *  @brief Scheduler CBS Release job
155 *
156 *  This routine is called when a new job of task is released.
157 *  It is called only from Rate Monotonic manager in the beginning
158 *  of new period. Deadline has to be shifted and budget replenished.
159 *
160 *  @param[in] the_thread is the owner of the job.
161 *  @param[in] length of the new job from now. If equal to 0,
162 *             the job was cancelled or deleted.
163 */
164
165void _Scheduler_CBS_Release_job (
166  Thread_Control  *the_thread,
167  uint32_t         length
168);
169
170/**
171 *  @brief _Scheduler_CBS_Initialize
172 *
173 *  Initializes the CBS library.
174 *
175 *  @return status code.
176 */
177int _Scheduler_CBS_Initialize(void);
178
179/**
180 *  @brief _Scheduler_CBS_Attach_thread
181 *
182 *  Attach a task to an already existing server.
183 *
184 *  @return status code.
185 */
186int _Scheduler_CBS_Attach_thread (
187  Scheduler_CBS_Server_id server_id,
188  rtems_id                task_id
189);
190
191/**
192 *  @brief _Scheduler_CBS_Detach_thread
193 *
194 *  Detach from the CBS Server.
195 *
196 *  @return status code.
197 */
198int _Scheduler_CBS_Detach_thread (
199  Scheduler_CBS_Server_id server_id,
200  rtems_id                task_id
201);
202
203/**
204 *  @brief _Scheduler_CBS_Cleanup
205 *
206 *  Cleanup resources associated to the CBS Library.
207 *
208 *  @return status code.
209 */
210int _Scheduler_CBS_Cleanup (void);
211
212/**
213 *  @brief _Scheduler_CBS_Create_server
214 *
215 *  Create a new server with specified parameters.
216 *
217 *  @return status code.
218 */
219int _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 _Scheduler_CBS_Destroy_server
227 *
228 *  Detach all tasks from a server and destroy it.
229 *
230 *  @return status code.
231 */
232int _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 */
244int _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 */
256int _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 */
268int _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 */
281int _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 */
294int _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 */
306int _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 */
316void _Scheduler_CBS_Budget_callout(
317  Thread_Control *the_thread
318);
319
320#ifdef __cplusplus
321}
322#endif
323
324/**@}*/
325
326#endif
327/* end of include file */
Note: See TracBrowser for help on using the repository browser.