source: rtems/cpukit/score/include/rtems/score/schedulercbs.h @ 69aa3349

4.115
Last change on this file since 69aa3349 was 69aa3349, checked in by Sebastian Huber <sebastian.huber@…>, on 04/08/14 at 07:42:29

score: Simplify thread control initialization

The thread control block contains fields that point to application
configuration dependent memory areas, like the scheduler information,
the API control blocks, the user extension context table, the RTEMS
notepads and the Newlib re-entrancy support. Account for these areas in
the configuration and avoid extra workspace allocations for these areas.

This helps also to avoid heap fragementation and reduces the per thread
memory due to a reduced heap allocation overhead.

  • Property mode set to 100644
File size: 9.6 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_CBS_Allocate,         /* allocate entry point */ \
56    _Scheduler_default_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_default_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 const 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
119  /**
120   * @brief Indicates if this CBS server is initialized.
121   *
122   * @see _Scheduler_CBS_Create_server() and _Scheduler_CBS_Destroy_server().
123   */
124  bool initialized;
125} Scheduler_CBS_Server;
126
127/**
128 * This structure handles CBS specific data of a thread.
129 */
130typedef struct {
131  /** EDF scheduler specific data of a task. */
132  Scheduler_EDF_Per_thread      edf_per_thread;
133  /** CBS server specific data of a task. */
134  Scheduler_CBS_Server         *cbs_server;
135} Scheduler_CBS_Per_thread;
136
137
138/**
139 * List of servers. The @a Scheduler_CBS_Server is the index to the array
140 * of pointers to @a _Scheduler_CBS_Server_list.
141 */
142extern Scheduler_CBS_Server _Scheduler_CBS_Server_list[];
143
144/**
145 *  @brief Unblocks a thread from the queue.
146 *
147 *  This routine adds @a the_thread to the scheduling decision, that is,
148 *  adds it to the ready queue and updates any appropriate scheduling
149 *  variables, for example the heir thread. It is checked whether the
150 *  remaining budget is sufficient. If not, the thread continues as a
151 *  new job in order to protect concurrent threads.
152 *
153 *  @param[in] the_thread will be unblocked.
154 *
155 *  @note This has to be asessed as missed deadline of the current job.
156 */
157void _Scheduler_CBS_Unblock(
158  const Scheduler_Control *scheduler,
159  Thread_Control          *the_thread
160);
161
162/**
163 *  @brief Called when a new job of task is released.
164 *
165 *  This routine is called when a new job of task is released.
166 *  It is called only from Rate Monotonic manager in the beginning
167 *  of new period. Deadline has to be shifted and budget replenished.
168 *
169 *  @param[in] the_thread is the owner of the job.
170 *  @param[in] length of the new job from now. If equal to 0,
171 *             the job was cancelled or deleted.
172 */
173
174void _Scheduler_CBS_Release_job (
175  const Scheduler_Control *scheduler,
176  Thread_Control          *the_thread,
177  uint32_t                 length
178);
179
180/**
181 *  @brief _Scheduler_CBS_Initialize
182 *
183 *  Initializes the CBS library.
184 *
185 *  @retval status code.
186 */
187int _Scheduler_CBS_Initialize(void);
188
189/**
190 *  @brief Attach a task to an already existing server.
191 *
192 *  Attach a task to an already existing server.
193 *
194 *  @retval status code.
195 */
196int _Scheduler_CBS_Attach_thread (
197  Scheduler_CBS_Server_id server_id,
198  rtems_id                task_id
199);
200
201/**
202 *  @brief Detach from the CBS Server.
203 *
204 *  Detach from the CBS Server.
205 *
206 *  @retval status code.
207 */
208int _Scheduler_CBS_Detach_thread (
209  Scheduler_CBS_Server_id server_id,
210  rtems_id                task_id
211);
212
213/**
214 *  @brief Cleanup resources associated to the CBS Library.
215 *
216 *  Cleanup resources associated to the CBS Library.
217 *
218 *  @retval status code.
219 */
220int _Scheduler_CBS_Cleanup (void);
221
222/**
223 *  @brief Create a new server with specified parameters.
224 *
225 *  Create a new server with specified parameters.
226 *
227 *  @retval status code.
228 */
229int _Scheduler_CBS_Create_server (
230  Scheduler_CBS_Parameters     *params,
231  Scheduler_CBS_Budget_overrun  budget_overrun_callback,
232  rtems_id                     *server_id
233);
234
235/**
236 *  @brief Detach all tasks from a server and destroy it.
237 *
238 *  Detach all tasks from a server and destroy it.
239 *
240 *  @param[in] server_id is the ID of the server
241 *
242 *  @retval status code.
243 */
244int _Scheduler_CBS_Destroy_server (
245  Scheduler_CBS_Server_id server_id
246);
247
248/**
249 *  @brief Retrieve the approved budget.
250 *
251 *  Retrieve the budget that has been approved for the subsequent
252 *  server instances.
253 *
254 *  @retval status code.
255 */
256int _Scheduler_CBS_Get_approved_budget (
257  Scheduler_CBS_Server_id  server_id,
258  time_t                  *approved_budget
259);
260
261/**
262 *  @brief Retrieve remaining budget for the current server instance.
263 *
264 *  Retrieve remaining budget for the current server instance.
265 *
266 *  @retval status code.
267 */
268int _Scheduler_CBS_Get_remaining_budget (
269  Scheduler_CBS_Server_id  server_id,
270  time_t                  *remaining_budget
271);
272
273/**
274 *  @brief Get relative time info.
275 *
276 *  Retrieve time info relative to @a server_id. The server status code is returned.
277 *
278 *  @param[in] server_id is the server to get the status code from.
279 *  @param[in] exec_time is the execution time.
280 *  @param[in] abs_time is not apparently used.
281 *
282 *  @retval status code.
283 */
284int _Scheduler_CBS_Get_execution_time (
285  Scheduler_CBS_Server_id   server_id,
286  time_t                   *exec_time,
287  time_t                   *abs_time
288);
289
290/**
291 *  @brief Retrieve CBS scheduling parameters.
292 *
293 *  Retrieve CBS scheduling parameters.
294 *
295 *  @retval status code.
296 */
297int _Scheduler_CBS_Get_parameters (
298  Scheduler_CBS_Server_id   server_id,
299  Scheduler_CBS_Parameters *params
300);
301
302/**
303 *  @brief Get a thread server id.
304 *
305 *  Get a thread server id, or SCHEDULER_CBS_ERROR_NOT_FOUND if it is not
306 *  attached to any server.
307 *
308 *  @retval status code.
309 */
310int _Scheduler_CBS_Get_server_id (
311  rtems_id                 task_id,
312  Scheduler_CBS_Server_id *server_id
313);
314
315/**
316 *  @brief Set parameters for CBS scheduling.
317 *
318 *  Change CBS scheduling parameters.
319 *
320 *  @param[in] server_id is the ID of the server.
321 *  @param[in] parameters are the parameters to set.
322 *
323 *  @retval status code.
324 */
325int _Scheduler_CBS_Set_parameters (
326  Scheduler_CBS_Server_id   server_id,
327  Scheduler_CBS_Parameters *parameters
328);
329
330/**
331 *  @brief Invoked when a limited time quantum is exceeded.
332 *
333 *  This routine is invoked when a limited time quantum is exceeded.
334 */
335void _Scheduler_CBS_Budget_callout(
336  Thread_Control *the_thread
337);
338
339/**
340 *  @brief Allocates CBS specific information of @a the_thread.
341 *
342 *  This routine allocates CBS specific information of @a the_thread.
343 *
344 *  @param[in] the_thread is the thread the scheduler is allocating
345 *             management memory for.
346 */
347bool _Scheduler_CBS_Allocate(
348  const Scheduler_Control *scheduler,
349  Thread_Control          *the_thread
350);
351
352#ifdef __cplusplus
353}
354#endif
355
356/**@}*/
357
358#endif
359/* end of include file */
Note: See TracBrowser for help on using the repository browser.