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

4.115
Last change on this file since 8568341 was 8568341, checked in by Sebastian Huber <sebastian.huber@…>, on 06/11/14 at 12:31:03

score: Need for help indicator for scheduler ops

Return a thread in need for help for the following scheduler operations

  • unblock,
  • change priority, and
  • yield.

A thread in need for help is a thread that encounters a scheduler state
change from scheduled to ready or a thread that cannot be scheduled in
an unblock operation. Such a thread can ask threads which depend on
resources owned by this thread for help.

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